mirror of
https://github.com/CarmJos/UltraDepository.git
synced 2026-06-04 16:48:21 +08:00
功能测试完成,剩余指令部分
This commit is contained in:
@@ -138,30 +138,30 @@
|
|||||||
<useSystemClassLoader>false</useSystemClassLoader>
|
<useSystemClassLoader>false</useSystemClassLoader>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<!-- <plugin>-->
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<!-- <groupId>org.apache.maven.plugins</groupId>-->
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
<!-- <artifactId>maven-javadoc-plugin</artifactId>-->
|
||||||
<version>3.2.0</version>
|
<!-- <version>3.2.0</version>-->
|
||||||
<configuration>
|
<!-- <configuration>-->
|
||||||
<classifier>javadoc</classifier>
|
<!-- <classifier>javadoc</classifier>-->
|
||||||
<links>
|
<!-- <links>-->
|
||||||
<link>https://javadoc.io/doc/org.jetbrains/annotations/</link>
|
<!-- <link>https://javadoc.io/doc/org.jetbrains/annotations/</link>-->
|
||||||
</links>
|
<!-- </links>-->
|
||||||
<detectJavaApiLink>false</detectJavaApiLink>
|
<!-- <detectJavaApiLink>false</detectJavaApiLink>-->
|
||||||
<encoding>UTF-8</encoding>
|
<!-- <encoding>UTF-8</encoding>-->
|
||||||
<charset>UTF-8</charset>
|
<!-- <charset>UTF-8</charset>-->
|
||||||
<docencoding>UTF-8</docencoding>
|
<!-- <docencoding>UTF-8</docencoding>-->
|
||||||
<locale>zh_CN</locale>
|
<!-- <locale>zh_CN</locale>-->
|
||||||
</configuration>
|
<!-- </configuration>-->
|
||||||
<executions>
|
<!-- <executions>-->
|
||||||
<execution>
|
<!-- <execution>-->
|
||||||
<id>attach-javadocs</id>
|
<!-- <id>attach-javadocs</id>-->
|
||||||
<goals>
|
<!-- <goals>-->
|
||||||
<goal>jar</goal>
|
<!-- <goal>jar</goal>-->
|
||||||
</goals>
|
<!-- </goals>-->
|
||||||
</execution>
|
<!-- </execution>-->
|
||||||
</executions>
|
<!-- </executions>-->
|
||||||
</plugin>
|
<!-- </plugin>-->
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ public class Main extends JavaPlugin {
|
|||||||
private static EconomyManager economyManager;
|
private static EconomyManager economyManager;
|
||||||
private static DepositoryManager depositoryManager;
|
private static DepositoryManager depositoryManager;
|
||||||
|
|
||||||
|
boolean initialized = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
instance = this;
|
instance = this;
|
||||||
@@ -91,12 +93,14 @@ public class Main extends JavaPlugin {
|
|||||||
log("检测到未安装PlaceholderAPI,跳过变量注册。");
|
log("检测到未安装PlaceholderAPI,跳过变量注册。");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initialized = true;
|
||||||
log("加载完成 ,共耗时 " + (System.currentTimeMillis() - startTime) + " ms 。");
|
log("加载完成 ,共耗时 " + (System.currentTimeMillis() - startTime) + " ms 。");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
if (!initialized) return;
|
||||||
log(getName() + " " + getDescription().getVersion() + " 开始卸载...");
|
log(getName() + " " + getDescription().getVersion() + " 开始卸载...");
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import cc.carm.plugin.ultradepository.configuration.message.ConfigMessage;
|
|||||||
import cc.carm.plugin.ultradepository.configuration.message.ConfigMessageList;
|
import cc.carm.plugin.ultradepository.configuration.message.ConfigMessageList;
|
||||||
import cc.carm.plugin.ultradepository.configuration.values.ConfigStringCast;
|
import cc.carm.plugin.ultradepository.configuration.values.ConfigStringCast;
|
||||||
import cc.carm.plugin.ultradepository.configuration.values.ConfigValue;
|
import cc.carm.plugin.ultradepository.configuration.values.ConfigValue;
|
||||||
|
import cc.carm.plugin.ultradepository.manager.ConfigManager;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|
||||||
public class PluginConfig {
|
public class PluginConfig {
|
||||||
@@ -44,7 +45,8 @@ public class PluginConfig {
|
|||||||
* 将添加到背包界面内的物品上,避免重复配置
|
* 将添加到背包界面内的物品上,避免重复配置
|
||||||
*/
|
*/
|
||||||
public static final ConfigMessageList ADDITIONAL_LORE = new ConfigMessageList(
|
public static final ConfigMessageList ADDITIONAL_LORE = new ConfigMessageList(
|
||||||
"general.additional-lore", new String[]{
|
ConfigManager.getPluginConfig(), "general.additional-lore", new String[]{},
|
||||||
|
new String[]{
|
||||||
"%(item_name)", "%(amount)", "%(price)", "%(sold)", "%(limit)"
|
"%(item_name)", "%(amount)", "%(price)", "%(sold)", "%(limit)"
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -53,7 +55,7 @@ public class PluginConfig {
|
|||||||
* 将添加到背包界面内的物品上,避免重复配置
|
* 将添加到背包界面内的物品上,避免重复配置
|
||||||
*/
|
*/
|
||||||
public static final ConfigMessageList CLICK_LORE = new ConfigMessageList(
|
public static final ConfigMessageList CLICK_LORE = new ConfigMessageList(
|
||||||
"general.click-lore", new String[]{
|
ConfigManager.getPluginConfig(), "general.click-lore", new String[]{}, new String[]{
|
||||||
"%(item_name)", "%(amount)", "%(price)"
|
"%(item_name)", "%(amount)", "%(price)"
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -64,8 +66,8 @@ public class PluginConfig {
|
|||||||
|
|
||||||
|
|
||||||
public static final ConfigMessage TITLE = new ConfigMessage(
|
public static final ConfigMessage TITLE = new ConfigMessage(
|
||||||
"general.sell-gui.title", "&a&l出售",
|
ConfigManager.getPluginConfig(), "general.sell-gui.title",
|
||||||
new String[]{
|
"&a&l出售", new String[]{
|
||||||
"%(item_name)", "%(backpack_name)"
|
"%(item_name)", "%(backpack_name)"
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -86,16 +88,16 @@ public class PluginConfig {
|
|||||||
|
|
||||||
|
|
||||||
public static final ConfigMessage NAME = new ConfigMessage(
|
public static final ConfigMessage NAME = new ConfigMessage(
|
||||||
"general.sell-gui.items.add.name", "&a添加物品 %(amount) 个",
|
ConfigManager.getPluginConfig(), "general.sell-gui.items.add.name",
|
||||||
new String[]{
|
"&a添加物品 %(amount) 个", new String[]{
|
||||||
"%(item_name)", "%(amount)"
|
"%(item_name)", "%(amount)"
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
public static final ConfigMessageList LORE = new ConfigMessageList(
|
public static final ConfigMessageList LORE = new ConfigMessageList(
|
||||||
"general.sell-gui.items.add.lore", null,
|
ConfigManager.getPluginConfig(), "general.sell-gui.items.add.lore",
|
||||||
new String[]{
|
new String[]{}, new String[]{
|
||||||
"%(item_name)", "%(amount)"
|
"%(item_name)", "%(amount)"
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -116,16 +118,16 @@ public class PluginConfig {
|
|||||||
|
|
||||||
|
|
||||||
public static final ConfigMessage NAME = new ConfigMessage(
|
public static final ConfigMessage NAME = new ConfigMessage(
|
||||||
"general.sell-gui.items.remove.name", "&c減少物品 %(amount) 个",
|
ConfigManager.getPluginConfig(), "general.sell-gui.items.remove.name",
|
||||||
new String[]{
|
"&c減少物品 %(amount) 个", new String[]{
|
||||||
"%(item_name)", "%(amount)"
|
"%(item_name)", "%(amount)"
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
public static final ConfigMessageList LORE = new ConfigMessageList(
|
public static final ConfigMessageList LORE = new ConfigMessageList(
|
||||||
"general.sell-gui.items.remove.lore", null,
|
ConfigManager.getPluginConfig(), "general.sell-gui.items.remove.lore",
|
||||||
new String[]{
|
new String[]{}, new String[]{
|
||||||
"%(item_name)", "%(amount)"
|
"%(item_name)", "%(amount)"
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -146,16 +148,16 @@ public class PluginConfig {
|
|||||||
|
|
||||||
|
|
||||||
public static final ConfigMessage NAME = new ConfigMessage(
|
public static final ConfigMessage NAME = new ConfigMessage(
|
||||||
"general.sell-gui.items.confirm.name", "&2确认售出",
|
ConfigManager.getPluginConfig(), "general.sell-gui.items.confirm.name",
|
||||||
new String[]{
|
"&2确认售出", new String[]{
|
||||||
"%(item_name)", "%(amount)", "%(money)"
|
"%(item_name)", "%(amount)", "%(money)"
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
public static final ConfigMessageList LORE = new ConfigMessageList(
|
public static final ConfigMessageList LORE = new ConfigMessageList(
|
||||||
"general.sell-gui.items.confirm.lore", null,
|
ConfigManager.getPluginConfig(), "general.sell-gui.items.confirm.lore",
|
||||||
new String[]{
|
new String[]{}, new String[]{
|
||||||
"%(item_name)", "%(amount)", "%(money)"
|
"%(item_name)", "%(amount)", "%(money)"
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -176,11 +178,12 @@ public class PluginConfig {
|
|||||||
|
|
||||||
|
|
||||||
public static final ConfigMessage NAME = new ConfigMessage(
|
public static final ConfigMessage NAME = new ConfigMessage(
|
||||||
"general.sell-gui.items.cancel.name", "&4取消售出"
|
ConfigManager.getPluginConfig(), "general.sell-gui.items.cancel.name",
|
||||||
|
"&4取消售出", null
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final ConfigMessageList LORE = new ConfigMessageList(
|
public static final ConfigMessageList LORE = new ConfigMessageList(
|
||||||
"general.sell-gui.items.cancel.lore"
|
ConfigManager.getPluginConfig(), "general.sell-gui.items.cancel.lore", new String[0], new String[0]
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -14,6 +14,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class GUIItemConfiguration {
|
public class GUIItemConfiguration {
|
||||||
|
|
||||||
@@ -51,7 +52,7 @@ public class GUIItemConfiguration {
|
|||||||
@Nullable
|
@Nullable
|
||||||
public static GUIItemConfiguration readFrom(@Nullable ConfigurationSection itemSection) {
|
public static GUIItemConfiguration readFrom(@Nullable ConfigurationSection itemSection) {
|
||||||
if (itemSection == null) return null;
|
if (itemSection == null) return null;
|
||||||
Material material = Material.matchMaterial(itemSection.getString("material", "STONE"));
|
Material material = Optional.ofNullable(Material.matchMaterial(itemSection.getString("material", "STONE"))).orElse(Material.STONE);
|
||||||
int data = itemSection.getInt("data", 0);
|
int data = itemSection.getInt("data", 0);
|
||||||
String name = itemSection.getString("name");
|
String name = itemSection.getString("name");
|
||||||
List<String> lore = itemSection.getStringList("lore");
|
List<String> lore = itemSection.getStringList("lore");
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package cc.carm.plugin.ultradepository.configuration.message;
|
package cc.carm.plugin.ultradepository.configuration.message;
|
||||||
|
|
||||||
|
|
||||||
|
import cc.carm.plugin.ultradepository.configuration.file.FileConfig;
|
||||||
import cc.carm.plugin.ultradepository.configuration.values.ConfigValue;
|
import cc.carm.plugin.ultradepository.configuration.values.ConfigValue;
|
||||||
import cc.carm.plugin.ultradepository.manager.ConfigManager;
|
import cc.carm.plugin.ultradepository.manager.ConfigManager;
|
||||||
import cc.carm.plugin.ultradepository.util.MessageUtil;
|
import cc.carm.plugin.ultradepository.util.MessageUtil;
|
||||||
@@ -26,6 +27,11 @@ public class ConfigMessage extends ConfigValue<String> {
|
|||||||
this.messageParams = messageParams;
|
this.messageParams = messageParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ConfigMessage(FileConfig config, String configSection, String defaultValue, String[] messageParams) {
|
||||||
|
super(config, configSection, String.class, defaultValue);
|
||||||
|
this.messageParams = messageParams;
|
||||||
|
}
|
||||||
|
|
||||||
public String get(CommandSender sender, Object[] values) {
|
public String get(CommandSender sender, Object[] values) {
|
||||||
if (messageParams != null) {
|
if (messageParams != null) {
|
||||||
return get(sender, messageParams, values);
|
return get(sender, messageParams, values);
|
||||||
|
|||||||
+8
@@ -1,9 +1,12 @@
|
|||||||
package cc.carm.plugin.ultradepository.configuration.message;
|
package cc.carm.plugin.ultradepository.configuration.message;
|
||||||
|
|
||||||
|
|
||||||
|
import cc.carm.plugin.ultradepository.Main;
|
||||||
|
import cc.carm.plugin.ultradepository.configuration.file.FileConfig;
|
||||||
import cc.carm.plugin.ultradepository.configuration.values.ConfigValueList;
|
import cc.carm.plugin.ultradepository.configuration.values.ConfigValueList;
|
||||||
import cc.carm.plugin.ultradepository.manager.ConfigManager;
|
import cc.carm.plugin.ultradepository.manager.ConfigManager;
|
||||||
import cc.carm.plugin.ultradepository.util.MessageUtil;
|
import cc.carm.plugin.ultradepository.util.MessageUtil;
|
||||||
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -26,6 +29,11 @@ public class ConfigMessageList extends ConfigValueList<String> {
|
|||||||
this.messageParams = messageParams;
|
this.messageParams = messageParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ConfigMessageList(FileConfig config, String configSection, String[] defaultValue, String[] messageParams) {
|
||||||
|
super(config, configSection, String.class, defaultValue);
|
||||||
|
this.messageParams = messageParams;
|
||||||
|
}
|
||||||
|
|
||||||
public List<String> get(@Nullable CommandSender sender) {
|
public List<String> get(@Nullable CommandSender sender) {
|
||||||
return MessageUtil.setPlaceholders(sender, get());
|
return MessageUtil.setPlaceholders(sender, get());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class DepositoryData {
|
public class DepositoryData {
|
||||||
|
|
||||||
@@ -37,14 +36,15 @@ public class DepositoryData {
|
|||||||
public @Nullable DepositoryItemData getItemData(@NotNull String itemType) {
|
public @Nullable DepositoryItemData getItemData(@NotNull String itemType) {
|
||||||
DepositoryItem item = getSource().getItems().get(itemType);
|
DepositoryItem item = getSource().getItems().get(itemType);
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
return getContents().putIfAbsent(item.getTypeID(), DepositoryItemData.emptyItemData(item, this));
|
return getItemData(item);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull DepositoryItemData getItemData(@NotNull DepositoryItem item) {
|
public @NotNull DepositoryItemData getItemData(@NotNull DepositoryItem item) {
|
||||||
return Objects.requireNonNull(getContents().putIfAbsent(item.getTypeID(), DepositoryItemData.emptyItemData(item, this)));
|
getContents().putIfAbsent(item.getTypeID(), DepositoryItemData.emptyItemData(item, this));
|
||||||
|
return getContents().get(item.getTypeID());
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getUsedCapacity() {
|
public int getUsedCapacity() {
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
import java.sql.Date;
|
import java.sql.Date;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class UserData {
|
public class UserData {
|
||||||
@@ -49,10 +48,8 @@ public class UserData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull DepositoryData getDepositoryData(Depository depository) {
|
public @NotNull DepositoryData getDepositoryData(Depository depository) {
|
||||||
return Objects.requireNonNull(getDepositories().putIfAbsent(
|
getDepositories().putIfAbsent(depository.getIdentifier(), DepositoryData.emptyContents(depository, this));
|
||||||
depository.getIdentifier(),
|
return getDepositories().get(depository.getIdentifier());
|
||||||
DepositoryData.emptyContents(depository, this))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable DepositoryItemData getItemData(@NotNull String depositoryID, @NotNull String typeID) {
|
public @Nullable DepositoryItemData getItemData(@NotNull String depositoryID, @NotNull String typeID) {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public class PAPIExpansion extends PlaceholderExpansion {
|
|||||||
"%UltraDepository_remain_<BackpackID>_<ItemTypeID>%",
|
"%UltraDepository_remain_<BackpackID>_<ItemTypeID>%",
|
||||||
"%UltraDepository_capacity_<BackpackID>%",
|
"%UltraDepository_capacity_<BackpackID>%",
|
||||||
"%UltraDepository_used_<BackpackID>%",
|
"%UltraDepository_used_<BackpackID>%",
|
||||||
"%UltraDepository_remain_<BackpackID>%"
|
"%UltraDepository_usable_<BackpackID>%"
|
||||||
);
|
);
|
||||||
|
|
||||||
Main main;
|
Main main;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package cc.carm.plugin.ultradepository.hooker;
|
package cc.carm.plugin.ultradepository.hooker;
|
||||||
|
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
import net.milkbowl.vault.economy.EconomyResponse;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -10,20 +9,17 @@ import org.bukkit.plugin.RegisteredServiceProvider;
|
|||||||
public class VaultHooker {
|
public class VaultHooker {
|
||||||
|
|
||||||
private Economy econ = null;
|
private Economy econ = null;
|
||||||
private EconomyResponse response;
|
|
||||||
|
|
||||||
public static boolean hasVault() {
|
public static boolean hasVault() {
|
||||||
return Bukkit.getServer().getPluginManager().getPlugin("Vault") != null;
|
return Bukkit.getServer().getPluginManager().getPlugin("Vault") != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setupEconomy() {
|
public boolean setupEconomy() {
|
||||||
if (!hasVault()) {
|
|
||||||
return false;
|
if (!hasVault()) return false;
|
||||||
}
|
|
||||||
RegisteredServiceProvider<Economy> rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
RegisteredServiceProvider<Economy> rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
||||||
if (rsp == null) {
|
if (rsp == null) return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
this.econ = rsp.getProvider();
|
this.econ = rsp.getProvider();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,44 +2,41 @@ package cc.carm.plugin.ultradepository.listener;
|
|||||||
|
|
||||||
import cc.carm.plugin.ultradepository.Main;
|
import cc.carm.plugin.ultradepository.Main;
|
||||||
import cc.carm.plugin.ultradepository.configuration.PluginConfig;
|
import cc.carm.plugin.ultradepository.configuration.PluginConfig;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.entity.Item;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockDropItemEvent;
|
||||||
import org.bukkit.event.entity.EntityDeathEvent;
|
import org.bukkit.event.entity.EntityDeathEvent;
|
||||||
import org.bukkit.event.entity.EntityPickupItemEvent;
|
import org.bukkit.event.entity.EntityPickupItemEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class CollectListener implements Listener {
|
public class CollectListener implements Listener {
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onBreak(BlockBreakEvent event) {
|
public void onBreak(BlockDropItemEvent event) {
|
||||||
if (event.isCancelled() || !event.isDropItems() || !PluginConfig.Collect.BREAK.get()) return;
|
if (event.isCancelled() || !PluginConfig.Collect.BREAK.get()) return;
|
||||||
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (!Main.getUserManager().isCollectEnabled(player)) return;
|
if (!Main.getUserManager().isCollectEnabled(player)) return;
|
||||||
|
if (event.getBlock().getType() == Material.CHEST || event.getBlock().getType() == Material.TRAPPED_CHEST) {
|
||||||
Location location = event.getBlock().getLocation();
|
return;
|
||||||
World world = event.getBlock().getWorld();
|
|
||||||
|
|
||||||
Collection<ItemStack> drops;
|
|
||||||
if (player.getItemInUse() == null) {
|
|
||||||
drops = event.getBlock().getDrops();
|
|
||||||
} else {
|
|
||||||
drops = event.getBlock().getDrops(player.getItemInUse(), player.getPlayer());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (drops.isEmpty()) return;
|
List<Item> droppedItems = event.getItems();
|
||||||
event.setDropItems(false);
|
if (droppedItems.isEmpty()) return;
|
||||||
|
|
||||||
Collection<ItemStack> finalDrops = Main.getDepositoryManager().collectItem(player, drops);
|
for (Item drop : droppedItems) {
|
||||||
finalDrops.forEach(finalDrop -> world.dropItemNaturally(location, finalDrop));
|
Main.debug("Dropped " + drop.getType().name() + " " + drop.getItemStack().getAmount());
|
||||||
|
}
|
||||||
|
|
||||||
|
event.getItems().removeIf(item -> Main.getDepositoryManager().collectItem(player, item.getItemStack()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +65,9 @@ public class CollectListener implements Listener {
|
|||||||
UUID thrower = event.getItem().getThrower();
|
UUID thrower = event.getItem().getThrower();
|
||||||
if (thrower != null && thrower.equals(player.getUniqueId())) return;
|
if (thrower != null && thrower.equals(player.getUniqueId())) return;
|
||||||
|
|
||||||
|
|
||||||
ItemStack item = event.getItem().getItemStack();
|
ItemStack item = event.getItem().getItemStack();
|
||||||
|
Main.debug("Picked up " + item.getType().name() + " " + item.getAmount());
|
||||||
if (Main.getDepositoryManager().collectItem(player, item)) {
|
if (Main.getDepositoryManager().collectItem(player, item)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
event.getItem().remove();
|
event.getItem().remove();
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public class ConfigManager {
|
|||||||
|
|
||||||
public static void initConfig() {
|
public static void initConfig() {
|
||||||
ConfigManager.config = new FileConfig(Main.getInstance(), "config.yml");
|
ConfigManager.config = new FileConfig(Main.getInstance(), "config.yml");
|
||||||
ConfigManager.messageConfig = new FileConfig(Main.getInstance(), "src/main/resources/messages.yml");
|
ConfigManager.messageConfig = new FileConfig(Main.getInstance(), "messages.yml");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FileConfig getPluginConfig() {
|
public static FileConfig getPluginConfig() {
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public class DepositoryManager {
|
|||||||
|
|
||||||
File[] files = folder.listFiles();
|
File[] files = folder.listFiles();
|
||||||
if (files == null) return;
|
if (files == null) return;
|
||||||
|
HashMultimap<@NotNull String, @NotNull String> items = HashMultimap.create();
|
||||||
HashMap<@NotNull String, @NotNull Depository> data = new HashMap<>();
|
HashMap<@NotNull String, @NotNull Depository> data = new HashMap<>();
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
String fileName = file.getName();
|
String fileName = file.getName();
|
||||||
@@ -59,12 +59,21 @@ public class DepositoryManager {
|
|||||||
FileConfiguration configuration = YamlConfiguration.loadConfiguration(file);
|
FileConfiguration configuration = YamlConfiguration.loadConfiguration(file);
|
||||||
Depository depository = Depository.loadFrom(identifier, configuration);
|
Depository depository = Depository.loadFrom(identifier, configuration);
|
||||||
if (depository.getItems().size() > 0) {
|
if (depository.getItems().size() > 0) {
|
||||||
|
depository.getItems().values().forEach(value -> items.put(value.getTypeID(), depository.getIdentifier()));
|
||||||
data.put(identifier, depository);
|
data.put(identifier, depository);
|
||||||
} else {
|
} else {
|
||||||
Main.error(" 仓库 " + depository.getName() + " 未配置任何物品,请检查相关配置!");
|
Main.error(" 仓库 " + depository.getName() + " 未配置任何物品,请检查相关配置!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (Map.Entry<String, Collection<String>> entry : items.asMap().entrySet()) {
|
||||||
|
Main.debug("# " + entry.getKey());
|
||||||
|
for (String depositoryID : entry.getValue()) {
|
||||||
|
Main.debug("- " + depositoryID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.depositories = data;
|
this.depositories = data;
|
||||||
|
this.itemMap = items;
|
||||||
Main.log(" 仓库配置加载完成,共加载 " + data.size() + " 个仓库,耗时 " + (System.currentTimeMillis() - start) + "ms 。");
|
Main.log(" 仓库配置加载完成,共加载 " + data.size() + " 个仓库,耗时 " + (System.currentTimeMillis() - start) + "ms 。");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,27 +128,37 @@ public class DepositoryManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Collection<ItemStack> collectItem(Player player, Collection<ItemStack> items) {
|
public Collection<ItemStack> collectItem(Player player, Collection<ItemStack> items) {
|
||||||
if (!Main.getUserManager().isCollectEnabled(player)) return new ArrayList<>();
|
if (!Main.getUserManager().isCollectEnabled(player)) {
|
||||||
else return items.stream().filter(item -> collectItem(player, item)).collect(Collectors.toList());
|
Main.debug("player " + player.getName() + " disabled collect, skipped.");
|
||||||
|
return items;
|
||||||
|
} else return items.stream().filter(item -> !collectItem(player, item)).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean collectItem(Player player, ItemStack item) {
|
public boolean collectItem(Player player, ItemStack item) {
|
||||||
if (!Main.getUserManager().isCollectEnabled(player)) return false;
|
String typeID = getItemTypeID(item);
|
||||||
|
Main.debug("Checking item " + typeID + " ...");
|
||||||
|
if (!Main.getUserManager().isCollectEnabled(player)) {
|
||||||
|
Main.debug("Player " + player.getName() + " disabled collect, skipped.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
if (meta != null && (meta.hasLore() || meta.hasDisplayName() || meta.hasEnchants())) {
|
if (meta != null && (meta.hasLore() || meta.hasDisplayName() || meta.hasEnchants())) {
|
||||||
// 不收集有特殊属性的物品
|
// 不收集有特殊属性的物品
|
||||||
|
Main.debug("Item has special meta, skipped.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Set<Depository> usableDepositories = getPlayerUsableDepository(player, item);
|
Set<Depository> usableDepositories = getPlayerUsableDepository(player, item);
|
||||||
if (usableDepositories.size() < 1) return false;
|
if (usableDepositories.size() < 1) {
|
||||||
|
Main.debug("Item doesn't has any depository, skipped.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Depository depository = usableDepositories.stream().findFirst().orElse(null);
|
Depository depository = usableDepositories.stream().findFirst().orElse(null);
|
||||||
|
|
||||||
String typeID = getItemTypeID(item);
|
|
||||||
String itemName = depository.getItems().get(typeID).getName();
|
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()});
|
PluginMessages.COLLECTED.send(player, new Object[]{itemName, itemAmount, depository.getName()});
|
||||||
|
Main.debug("Item collected successfully.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,10 +13,7 @@ public class EconomyManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean initialize() {
|
public boolean initialize() {
|
||||||
boolean success = this.hooker.setupEconomy();
|
return initialized = this.hooker.setupEconomy();
|
||||||
this.initialized = success;
|
|
||||||
|
|
||||||
return success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInitialized() {
|
public boolean isInitialized() {
|
||||||
|
|||||||
@@ -57,10 +57,13 @@ public class DepositoryGUI extends GUI {
|
|||||||
public void onClick(ClickType type) {
|
public void onClick(ClickType type) {
|
||||||
if (itemData.getAmount() < 1) return;
|
if (itemData.getAmount() < 1) return;
|
||||||
if (type == ClickType.LEFT) {
|
if (type == ClickType.LEFT) {
|
||||||
|
player.closeInventory();
|
||||||
SellItemGUI.open(player, userData, itemData, depository, item);
|
SellItemGUI.open(player, userData, itemData, depository, item);
|
||||||
} else if (type == ClickType.RIGHT) {
|
} else if (type == ClickType.RIGHT) {
|
||||||
|
player.closeInventory();
|
||||||
if (hasEmptySlot(player)) {
|
if (hasEmptySlot(player)) {
|
||||||
int pickupAmount = Math.min(itemData.getAmount(), item.getMaterial().getMaxStackSize());
|
int pickupAmount = Math.min(itemData.getAmount(), item.getMaterial().getMaxStackSize());
|
||||||
|
userData.removeItemAmount(item.getDepository().getIdentifier(), item.getTypeID(), pickupAmount);
|
||||||
player.getInventory().addItem(item.getRawItem(pickupAmount));
|
player.getInventory().addItem(item.getRawItem(pickupAmount));
|
||||||
PluginMessages.PICKUP.send(player, new Object[]{
|
PluginMessages.PICKUP.send(player, new Object[]{
|
||||||
item.getName(), pickupAmount
|
item.getName(), pickupAmount
|
||||||
@@ -68,7 +71,7 @@ public class DepositoryGUI extends GUI {
|
|||||||
} else {
|
} else {
|
||||||
PluginMessages.NO_SPACE.send(player);
|
PluginMessages.NO_SPACE.send(player);
|
||||||
}
|
}
|
||||||
player.closeInventory();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import cc.carm.plugin.ultradepository.util.ItemStackFactory;
|
|||||||
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 org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@@ -33,9 +34,11 @@ public class SellItemGUI extends GUI {
|
|||||||
|
|
||||||
public SellItemGUI(Player player, UserData userData, DepositoryItemData itemData,
|
public SellItemGUI(Player player, UserData userData, DepositoryItemData itemData,
|
||||||
Depository configuration, DepositoryItem item) {
|
Depository configuration, DepositoryItem item) {
|
||||||
|
|
||||||
super(GUIType.FOUR_BY_NINE, PluginConfig.General.SellGUI.TITLE.get(player, new String[]{
|
super(GUIType.FOUR_BY_NINE, PluginConfig.General.SellGUI.TITLE.get(player, new String[]{
|
||||||
configuration.getName(), item.getName()
|
configuration.getName(), item.getName()
|
||||||
}));
|
}));
|
||||||
|
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.userData = userData;
|
this.userData = userData;
|
||||||
this.itemData = itemData;
|
this.itemData = itemData;
|
||||||
@@ -48,41 +51,35 @@ public class SellItemGUI extends GUI {
|
|||||||
|
|
||||||
private void load(int amount) {
|
private void load(int amount) {
|
||||||
this.currentAmount = Math.max(1, amount); // 不可小于1
|
this.currentAmount = Math.max(1, amount); // 不可小于1
|
||||||
loadIcon();
|
|
||||||
loadButtons();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadIcon() {
|
|
||||||
ItemStackFactory factory = new ItemStackFactory(this.itemDisplay);
|
ItemStackFactory factory = new ItemStackFactory(this.itemDisplay);
|
||||||
List<String> additionalLore = PluginConfig.General.ADDITIONAL_LORE.get(player, new Object[]{
|
List<String> additionalLore = PluginConfig.General.ADDITIONAL_LORE.get(player, new Object[]{
|
||||||
getItemName(), getRemainAmount(), getItemPrice(), getSoldAmount(), getSellLimit()
|
getItemName(), getRemainAmount(), getItemPrice(), getSoldAmount(), getSellLimit()
|
||||||
});
|
});
|
||||||
additionalLore.forEach(factory::addLore);
|
additionalLore.forEach(factory::addLore);
|
||||||
setItem(4, new GUIItem(factory.toItemStack()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadButtons() {
|
setItem(9, getCurrentAmount() > 1000 ? getRemoveItem(1000) : null);
|
||||||
if (getCurrentAmount() > 1000) setItem(0, getRemoveItem(1000));
|
setItem(10, getCurrentAmount() > 100 ? getRemoveItem(100) : null);
|
||||||
if (getCurrentAmount() > 100) setItem(1, getRemoveItem(100));
|
setItem(11, getCurrentAmount() > 10 ? getRemoveItem(10) : null);
|
||||||
if (getCurrentAmount() > 10) setItem(2, getRemoveItem(10));
|
setItem(12, getCurrentAmount() > 1 ? getRemoveItem(1) : null);
|
||||||
if (getCurrentAmount() > 1) setItem(3, getRemoveItem(1));
|
setItem(13, new GUIItem(factory.toItemStack()));
|
||||||
if (getAddableAmount() > 1) setItem(5, getAddItem(1));
|
setItem(14, getAddableAmount() >= 1 ? getAddItem(1) : null);
|
||||||
if (getAddableAmount() > 10) setItem(6, getAddItem(10));
|
setItem(15, getAddableAmount() >= 10 ? getAddItem(10) : null);
|
||||||
if (getAddableAmount() > 100) setItem(7, getAddItem(100));
|
setItem(16, getAddableAmount() >= 100 ? getAddItem(100) : null);
|
||||||
if (getAddableAmount() > 1000) setItem(8, getAddItem(1000));
|
setItem(17, getAddableAmount() >= 1000 ? getAddItem(1000) : null);
|
||||||
|
|
||||||
if (getCurrentAmount() >= 1) setItem(getConfirmItem(), 27, 28, 29, 30);
|
if (getCurrentAmount() >= 1) setItem(getConfirmItem(), 27, 28, 29, 30);
|
||||||
setItem(getCancelItem(), 32, 33, 34, 35);
|
setItem(getCancelItem(), 32, 33, 34, 35);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private GUIItem getAddItem(int amount) {
|
private GUIItem getAddItem(int amount) {
|
||||||
ItemStackFactory factory = new ItemStackFactory(Add.TYPE.get());
|
ItemStackFactory factory = new ItemStackFactory(Add.TYPE.get());
|
||||||
factory.setDurability(Add.DATA.get());
|
factory.setDurability(Add.DATA.get());
|
||||||
factory.setDisplayName(Add.NAME.get(player, new Object[]{
|
factory.setDisplayName(Add.NAME.get(player, new Object[]{
|
||||||
getItemName(), getCurrentAmount()
|
getItemName(), amount
|
||||||
}));
|
}));
|
||||||
factory.setLore(Add.LORE.get(player, new Object[]{
|
factory.setLore(Add.LORE.get(player, new Object[]{
|
||||||
getItemName(), getCurrentAmount()
|
getItemName(), amount
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return new GUIItem(factory.toItemStack()) {
|
return new GUIItem(factory.toItemStack()) {
|
||||||
@@ -98,10 +95,10 @@ public class SellItemGUI extends GUI {
|
|||||||
ItemStackFactory factory = new ItemStackFactory(Remove.TYPE.get());
|
ItemStackFactory factory = new ItemStackFactory(Remove.TYPE.get());
|
||||||
factory.setDurability(Remove.DATA.get());
|
factory.setDurability(Remove.DATA.get());
|
||||||
factory.setDisplayName(Remove.NAME.get(player, new Object[]{
|
factory.setDisplayName(Remove.NAME.get(player, new Object[]{
|
||||||
getItemName(), getCurrentAmount()
|
getItemName(), amount
|
||||||
}));
|
}));
|
||||||
factory.setLore(Remove.LORE.get(player, new Object[]{
|
factory.setLore(Remove.LORE.get(player, new Object[]{
|
||||||
getItemName(), getCurrentAmount()
|
getItemName(), amount
|
||||||
}));
|
}));
|
||||||
return new GUIItem(factory.toItemStack()) {
|
return new GUIItem(factory.toItemStack()) {
|
||||||
@Override
|
@Override
|
||||||
@@ -126,6 +123,8 @@ public class SellItemGUI extends GUI {
|
|||||||
public void onClick(ClickType type) {
|
public void onClick(ClickType type) {
|
||||||
int amount = Math.min(getCurrentAmount(), Math.min(getRemainAmount(), getSellLimit() - getSoldAmount()));
|
int amount = Math.min(getCurrentAmount(), Math.min(getRemainAmount(), getSellLimit() - getSoldAmount()));
|
||||||
if (amount > 0) {
|
if (amount > 0) {
|
||||||
|
userData.removeItemAmount(item.getDepository().getIdentifier(), item.getTypeID(), amount);
|
||||||
|
userData.addItemSold(item.getDepository().getIdentifier(), item.getTypeID(), amount);
|
||||||
double money = Main.getEconomyManager().sell(player, getItemPrice(), amount);
|
double money = Main.getEconomyManager().sell(player, getItemPrice(), amount);
|
||||||
PluginMessages.SOLD.send(player, new Object[]{
|
PluginMessages.SOLD.send(player, new Object[]{
|
||||||
getItemName(), amount, money
|
getItemName(), amount, money
|
||||||
@@ -170,11 +169,11 @@ public class SellItemGUI extends GUI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int getRemainAmount() {
|
private int getRemainAmount() {
|
||||||
return this.itemData.getAmount();
|
return userData.getItemData(this.item).getAmount();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getSoldAmount() {
|
private int getSoldAmount() {
|
||||||
return this.itemData.getSold();
|
return userData.getItemData(this.item).getSold();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getAddableAmount() {
|
private int getAddableAmount() {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||||
|
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||||
|
|
||||||
public class GUIListener implements Listener {
|
public class GUIListener implements Listener {
|
||||||
|
|
||||||
@@ -93,4 +94,16 @@ public class GUIListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onOpen(InventoryOpenEvent event) {
|
||||||
|
Player p = (Player) event.getPlayer();
|
||||||
|
//开启新界面后 结束旧界面
|
||||||
|
if (!event.getInventory().equals(getCurrentGUI().inv)) {
|
||||||
|
HandlerList.unregisterAll(this);
|
||||||
|
getCurrentGUI().listener = null;
|
||||||
|
getCurrentGUI().onClose();
|
||||||
|
GUI.removeOpenedGUI(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ website: ${project.url}
|
|||||||
|
|
||||||
author: CarmJos
|
author: CarmJos
|
||||||
|
|
||||||
|
softdepend:
|
||||||
|
- PlaceholderAPI
|
||||||
|
- Vault
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
"UltraDepository":
|
"UltraDepository":
|
||||||
description: "超级仓库的主指令"
|
description: "超级仓库的主指令"
|
||||||
@@ -24,9 +28,11 @@ permissions:
|
|||||||
|
|
||||||
"UltraDepository.auto":
|
"UltraDepository.auto":
|
||||||
description: "超级仓库的自动收集权限"
|
description: "超级仓库的自动收集权限"
|
||||||
|
default: op
|
||||||
|
|
||||||
"UltraDepository.auto.enable":
|
"UltraDepository.auto.enable":
|
||||||
description: "用于判断是否启用了自动收集功能"
|
description: "用于判断是否启用了自动收集功能"
|
||||||
|
default: op
|
||||||
|
|
||||||
"UltraDepository.admin":
|
"UltraDepository.admin":
|
||||||
description: "超级仓库的管理权限"
|
description: "超级仓库的管理权限"
|
||||||
|
|||||||
Reference in New Issue
Block a user