mirror of
https://github.com/CarmJos/UltraDepository.git
synced 2026-06-04 08:38:25 +08:00
修复maven构建
This commit is contained in:
@@ -22,4 +22,5 @@ items:
|
|||||||
original: true #只允许无任何特殊属性的物品被收入
|
original: true #只允许无任何特殊属性的物品被收入
|
||||||
slot: 5
|
slot: 5
|
||||||
price: 10
|
price: 10
|
||||||
|
limit: 100
|
||||||
name: "&b&l钻石"
|
name: "&b&l钻石"
|
||||||
@@ -30,14 +30,14 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
rm -rf docs
|
rm -rf docs
|
||||||
mkdir -vp docs
|
mkdir -vp docs
|
||||||
cp -vrf ultrabackpack-api/target/apidocs/* docs/
|
cp -vrf target/apidocs/* docs/
|
||||||
cp -vrf .documentation/JAVADOC-README.md docs/README.md
|
cp -vrf .documentation/JAVADOC-README.md docs/README.md
|
||||||
|
|
||||||
- name: Generate the sitemap
|
- name: Generate the sitemap
|
||||||
id: sitemap
|
id: sitemap
|
||||||
uses: cicirello/generate-sitemap@v1
|
uses: cicirello/generate-sitemap@v1
|
||||||
with:
|
with:
|
||||||
base-url-path: https://carmjos.github.io/UltraBackpack
|
base-url-path: https://carmjos.github.io/UltraDepository
|
||||||
path-to-root: docs
|
path-to-root: docs
|
||||||
|
|
||||||
- name: Output stats
|
- name: Output stats
|
||||||
@@ -62,7 +62,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
cd docs
|
cd docs
|
||||||
git init
|
git init
|
||||||
git remote add origin git@github.com:CarmJos/UltraBackpack.git
|
git remote add origin git@github.com:CarmJos/UltraDepository.git
|
||||||
git checkout -b gh-pages
|
git checkout -b gh-pages
|
||||||
git add -A
|
git add -A
|
||||||
git commit -m "API Document generated."
|
git commit -m "API Document generated."
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ jobs:
|
|||||||
MAVEN_USERNAME: ${{ github.repository_owner }}
|
MAVEN_USERNAME: ${{ github.repository_owner }}
|
||||||
MAVEN_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
MAVEN_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
||||||
- name: "Target Stage"
|
- name: "Target Stage"
|
||||||
run: mkdir staging && cp */target/*.jar staging
|
run: mkdir staging && cp target/*.jar staging
|
||||||
- name: "Upload artifact"
|
- name: "Upload artifact"
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v2
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -36,6 +36,13 @@
|
|||||||
|
|
||||||
## 特殊优势
|
## 特殊优势
|
||||||
|
|
||||||
|
- 详细的变量与指令!
|
||||||
|
- 支持多种存储方式!
|
||||||
|
- 可自定义程度高,配置任何想要的仓库!
|
||||||
|
- 仓库容量权限配置,可给予特殊用户更大的仓库容量!
|
||||||
|
- 仓库自动收集物品,提供API操作玩家数据!
|
||||||
|
- ...
|
||||||
|
|
||||||
## 插件指令
|
## 插件指令
|
||||||
|
|
||||||
指令主指令为 /UltraDepository (/ud | /Depository)
|
指令主指令为 /UltraDepository (/ud | /Depository)
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package cc.carm.plugin.ultradepository.configuration.depository;
|
package cc.carm.plugin.ultradepository.configuration.depository;
|
||||||
|
|
||||||
import cc.carm.plugin.ultradepository.configuration.gui.GUIConfiguration;
|
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 org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -61,4 +63,21 @@ public class Depository {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(identifier);
|
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.GUI;
|
||||||
import cc.carm.plugin.ultradepository.util.gui.GUIItem;
|
import cc.carm.plugin.ultradepository.util.gui.GUIItem;
|
||||||
import cc.carm.plugin.ultradepository.util.gui.GUIType;
|
import cc.carm.plugin.ultradepository.util.gui.GUIType;
|
||||||
|
import com.google.common.collect.ArrayListMultimap;
|
||||||
import com.google.common.collect.Multimap;
|
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 {
|
public class GUIConfiguration {
|
||||||
|
|
||||||
@@ -52,4 +60,64 @@ public class GUIConfiguration {
|
|||||||
getGuiItems().forEach((gui::setItem));
|
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();
|
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;
|
package cc.carm.plugin.ultradepository.manager;
|
||||||
|
|
||||||
import cc.carm.plugin.ultradepository.Main;
|
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.Depository;
|
||||||
import cc.carm.plugin.ultradepository.configuration.depository.DepositoryItem;
|
import cc.carm.plugin.ultradepository.configuration.depository.DepositoryItem;
|
||||||
import cc.carm.plugin.ultradepository.data.UserData;
|
import cc.carm.plugin.ultradepository.data.UserData;
|
||||||
import com.google.common.collect.HashMultimap;
|
import com.google.common.collect.HashMultimap;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
public class DepositoryManager {
|
public class DepositoryManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,6 +37,32 @@ public class DepositoryManager {
|
|||||||
this.itemMap = HashMultimap.create();
|
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() {
|
public @NotNull HashMap<@NotNull String, @NotNull Depository> getDepositories() {
|
||||||
return depositories;
|
return depositories;
|
||||||
}
|
}
|
||||||
@@ -99,9 +130,11 @@ public class DepositoryManager {
|
|||||||
Depository depository = usableDepositories.stream().findFirst().orElse(null);
|
Depository depository = usableDepositories.stream().findFirst().orElse(null);
|
||||||
|
|
||||||
String typeID = getItemTypeID(item);
|
String typeID = getItemTypeID(item);
|
||||||
|
String itemName = depository.getItems().get(typeID).getName();
|
||||||
UserData data = Main.getUserManager().getData(player);
|
UserData data = Main.getUserManager().getData(player);
|
||||||
int itemAmount = item.getAmount();
|
int itemAmount = item.getAmount();
|
||||||
data.addItemAmount(depository.getIdentifier(), typeID, itemAmount);
|
data.addItemAmount(depository.getIdentifier(), typeID, itemAmount);
|
||||||
|
PluginMessages.COLLECTED.send(player, new Object[]{itemName, itemAmount, depository.getName()});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import cc.carm.plugin.ultradepository.configuration.gui.GUIActionType;
|
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.bukkit.event.inventory.ClickType;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ public class ActionReadTest {
|
|||||||
GUIActionType actionType;
|
GUIActionType actionType;
|
||||||
if (prefix.contains(":")) {
|
if (prefix.contains(":")) {
|
||||||
String[] args = prefix.split(":");
|
String[] args = prefix.split(":");
|
||||||
clickType = ConfigManager.readClickType(args[0]);
|
clickType = GUIConfiguration.readClickType(args[0]);
|
||||||
actionType = GUIActionType.readActionType(args[1]);
|
actionType = GUIActionType.readActionType(args[1]);
|
||||||
} else {
|
} else {
|
||||||
actionType = GUIActionType.readActionType(prefix);
|
actionType = GUIActionType.readActionType(prefix);
|
||||||
|
|||||||
Reference in New Issue
Block a user