mirror of
https://github.com/CarmJos/UltraDepository.git
synced 2026-06-04 16:48:21 +08:00
修复maven构建
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package cc.carm.plugin.ultradepository.configuration.depository;
|
||||
|
||||
import cc.carm.plugin.ultradepository.configuration.gui.GUIConfiguration;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -61,4 +63,21 @@ public class Depository {
|
||||
public int hashCode() {
|
||||
return Objects.hash(identifier);
|
||||
}
|
||||
|
||||
public static Depository loadFrom(String identifier, FileConfiguration configuration) {
|
||||
String name = configuration.getString("name");
|
||||
|
||||
GUIConfiguration guiConfiguration = GUIConfiguration.readConfiguration(configuration.getConfigurationSection("gui"));
|
||||
DepositoryCapacity capacity = new DepositoryCapacity(
|
||||
configuration.getInt("capacity.default", 0),
|
||||
configuration.getStringList("capacity.permissions")
|
||||
);
|
||||
|
||||
ConfigurationSection itemsSection = configuration.getConfigurationSection("items");
|
||||
if (itemsSection != null) {
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,15 @@ import cc.carm.plugin.ultradepository.util.ColorParser;
|
||||
import cc.carm.plugin.ultradepository.util.gui.GUI;
|
||||
import cc.carm.plugin.ultradepository.util.gui.GUIItem;
|
||||
import cc.carm.plugin.ultradepository.util.gui.GUIType;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class GUIConfiguration {
|
||||
|
||||
@@ -52,4 +60,64 @@ public class GUIConfiguration {
|
||||
getGuiItems().forEach((gui::setItem));
|
||||
}
|
||||
|
||||
|
||||
public static GUIConfiguration readConfiguration(@Nullable ConfigurationSection section) {
|
||||
if (section == null) {
|
||||
return new GUIConfiguration("name", 6, ArrayListMultimap.create());
|
||||
}
|
||||
String title = section.getString("title", "");
|
||||
int lines = section.getInt("lines", 6);
|
||||
Multimap<GUIItem, Integer> guiItemMap = ArrayListMultimap.create();
|
||||
ConfigurationSection itemsSection = section.getConfigurationSection("items");
|
||||
if (itemsSection != null) {
|
||||
itemsSection.getKeys(false).stream()
|
||||
.map(key -> readItem(itemsSection.getConfigurationSection(key)))
|
||||
.filter(Objects::nonNull)
|
||||
.forEach(entry -> guiItemMap.putAll(entry.getKey(), entry.getValue()));
|
||||
|
||||
}
|
||||
return new GUIConfiguration(title, lines, guiItemMap);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static AbstractMap.SimpleEntry<GUIItem, List<Integer>> readItem(@Nullable ConfigurationSection itemSection) {
|
||||
if (itemSection == null) return null;
|
||||
ItemStack icon = itemSection.getItemStack("icon", new ItemStack(Material.STONE));
|
||||
List<Integer> slots = itemSection.getIntegerList("slots");
|
||||
int slot = itemSection.getInt("slot", 0);
|
||||
|
||||
List<String> actionsString = itemSection.getStringList("actions");
|
||||
List<GUIActionConfiguration> actions = new ArrayList<>();
|
||||
for (String actionString : actionsString) {
|
||||
int prefixStart = actionString.indexOf("[");
|
||||
int prefixEnd = actionString.indexOf("]");
|
||||
if (prefixStart < 0 || prefixEnd < 0) continue;
|
||||
|
||||
String prefix = actionString.substring(prefixStart + 1, prefixEnd);
|
||||
ClickType clickType = null;
|
||||
GUIActionType actionType;
|
||||
if (prefix.contains(":")) {
|
||||
String[] args = prefix.split(":");
|
||||
clickType = readClickType(args[0]);
|
||||
actionType = GUIActionType.readActionType(args[1]);
|
||||
} else {
|
||||
actionType = GUIActionType.readActionType(prefix);
|
||||
}
|
||||
|
||||
if (actionType == null) continue;
|
||||
actions.add(new GUIActionConfiguration(clickType, actionType, actionString.substring(prefixEnd + 1).trim()));
|
||||
}
|
||||
GUIItem item = new GUIItem(icon);
|
||||
actions.stream().map(GUIActionConfiguration::toClickAction).forEach(item::addClickAction);
|
||||
|
||||
return new AbstractMap.SimpleEntry<>(item, slots.size() > 0 ? slots : Collections.singletonList(slot));
|
||||
}
|
||||
|
||||
|
||||
public static ClickType readClickType(String type) {
|
||||
return Arrays.stream(ClickType.values())
|
||||
.filter(click -> click.name().equalsIgnoreCase(type))
|
||||
.findFirst().orElse(null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,60 +45,4 @@ public class ConfigManager {
|
||||
getMessageConfig().save();
|
||||
}
|
||||
|
||||
public static GUIConfiguration readConfiguration(ConfigurationSection section) {
|
||||
String title = section.getString("title", "");
|
||||
int liens = section.getInt("lines", 6);
|
||||
Multimap<GUIItem, Integer> guiItemMap = ArrayListMultimap.create();
|
||||
ConfigurationSection itemsSection = section.getConfigurationSection("items");
|
||||
if (itemsSection != null) {
|
||||
itemsSection.getKeys(false).stream()
|
||||
.map(key -> readItem(itemsSection.getConfigurationSection(key)))
|
||||
.filter(Objects::nonNull)
|
||||
.forEach(entry -> guiItemMap.putAll(entry.getKey(), entry.getValue()));
|
||||
|
||||
}
|
||||
return new GUIConfiguration(title, liens, guiItemMap);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static AbstractMap.SimpleEntry<GUIItem, List<Integer>> readItem(@Nullable ConfigurationSection itemSection) {
|
||||
if (itemSection == null) return null;
|
||||
ItemStack icon = itemSection.getItemStack("icon", new ItemStack(Material.STONE));
|
||||
List<Integer> slots = itemSection.getIntegerList("slots");
|
||||
int slot = itemSection.getInt("slot", 0);
|
||||
|
||||
List<String> actionsString = itemSection.getStringList("actions");
|
||||
List<GUIActionConfiguration> actions = new ArrayList<>();
|
||||
for (String actionString : actionsString) {
|
||||
int prefixStart = actionString.indexOf("[");
|
||||
int prefixEnd = actionString.indexOf("]");
|
||||
if (prefixStart < 0 || prefixEnd < 0) continue;
|
||||
|
||||
String prefix = actionString.substring(prefixStart + 1, prefixEnd);
|
||||
ClickType clickType = null;
|
||||
GUIActionType actionType;
|
||||
if (prefix.contains(":")) {
|
||||
String[] args = prefix.split(":");
|
||||
clickType = readClickType(args[0]);
|
||||
actionType = GUIActionType.readActionType(args[1]);
|
||||
} else {
|
||||
actionType = GUIActionType.readActionType(prefix);
|
||||
}
|
||||
|
||||
if (actionType == null) continue;
|
||||
actions.add(new GUIActionConfiguration(clickType, actionType, actionString.substring(prefixEnd + 1).trim()));
|
||||
}
|
||||
GUIItem item = new GUIItem(icon);
|
||||
actions.stream().map(GUIActionConfiguration::toClickAction).forEach(item::addClickAction);
|
||||
|
||||
return new AbstractMap.SimpleEntry<>(item, slots.size() > 0 ? slots : Collections.singletonList(slot));
|
||||
}
|
||||
|
||||
public static ClickType readClickType(String type) {
|
||||
return Arrays.stream(ClickType.values())
|
||||
.filter(click -> click.name().equalsIgnoreCase(type))
|
||||
.findFirst().orElse(null);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,20 +1,25 @@
|
||||
package cc.carm.plugin.ultradepository.manager;
|
||||
|
||||
import cc.carm.plugin.ultradepository.Main;
|
||||
import cc.carm.plugin.ultradepository.configuration.PluginMessages;
|
||||
import cc.carm.plugin.ultradepository.configuration.depository.Depository;
|
||||
import cc.carm.plugin.ultradepository.configuration.depository.DepositoryItem;
|
||||
import cc.carm.plugin.ultradepository.data.UserData;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
public class DepositoryManager {
|
||||
|
||||
/**
|
||||
@@ -32,6 +37,32 @@ public class DepositoryManager {
|
||||
this.itemMap = HashMultimap.create();
|
||||
}
|
||||
|
||||
public void loadDepositories() {
|
||||
File folder = new File(Main.getInstance().getDataFolder(), "depositories");
|
||||
if (!folder.exists()) {
|
||||
folder.mkdir();
|
||||
} else if (folder.isDirectory()) {
|
||||
folder.delete();
|
||||
folder.mkdir();
|
||||
}
|
||||
|
||||
File[] files = folder.listFiles();
|
||||
if (files == null) return;
|
||||
|
||||
HashMap<@NotNull String, @NotNull Depository> data = new HashMap<>();
|
||||
for (File file : files) {
|
||||
String fileName = file.getName();
|
||||
if (!file.isFile() || !fileName.toLowerCase().endsWith(".yml")) continue;
|
||||
String identifier = fileName.substring(0, fileName.lastIndexOf("."));
|
||||
FileConfiguration configuration = YamlConfiguration.loadConfiguration(file);
|
||||
Depository depository = Depository.loadFrom(identifier, configuration);
|
||||
if (depository != null) {
|
||||
data.put(identifier, depository);
|
||||
}
|
||||
}
|
||||
this.depositories = data;
|
||||
}
|
||||
|
||||
public @NotNull HashMap<@NotNull String, @NotNull Depository> getDepositories() {
|
||||
return depositories;
|
||||
}
|
||||
@@ -99,9 +130,11 @@ public class DepositoryManager {
|
||||
Depository depository = usableDepositories.stream().findFirst().orElse(null);
|
||||
|
||||
String typeID = getItemTypeID(item);
|
||||
String itemName = depository.getItems().get(typeID).getName();
|
||||
UserData data = Main.getUserManager().getData(player);
|
||||
int itemAmount = item.getAmount();
|
||||
data.addItemAmount(depository.getIdentifier(), typeID, itemAmount);
|
||||
PluginMessages.COLLECTED.send(player, new Object[]{itemName, itemAmount, depository.getName()});
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import cc.carm.plugin.ultradepository.configuration.gui.GUIActionType;
|
||||
import cc.carm.plugin.ultradepository.manager.ConfigManager;
|
||||
import cc.carm.plugin.ultradepository.configuration.gui.GUIConfiguration;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -29,7 +29,7 @@ public class ActionReadTest {
|
||||
GUIActionType actionType;
|
||||
if (prefix.contains(":")) {
|
||||
String[] args = prefix.split(":");
|
||||
clickType = ConfigManager.readClickType(args[0]);
|
||||
clickType = GUIConfiguration.readClickType(args[0]);
|
||||
actionType = GUIActionType.readActionType(args[1]);
|
||||
} else {
|
||||
actionType = GUIActionType.readActionType(prefix);
|
||||
|
||||
Reference in New Issue
Block a user