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