diff --git a/src/main/java/cat/nyaa/HamsterEcoHelper/CommandHandler.java b/src/main/java/cat/nyaa/HamsterEcoHelper/CommandHandler.java index 29941f3..36f2372 100644 --- a/src/main/java/cat/nyaa/HamsterEcoHelper/CommandHandler.java +++ b/src/main/java/cat/nyaa/HamsterEcoHelper/CommandHandler.java @@ -15,6 +15,7 @@ import cat.nyaa.nyaacore.cmdreceiver.Arguments; import cat.nyaa.nyaacore.cmdreceiver.CommandReceiver; import cat.nyaa.nyaacore.cmdreceiver.SubCommand; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.YamlConfiguration; @@ -124,7 +125,12 @@ public void userRetrieve(CommandSender sender, Arguments args) { return; } for (ItemStack s : items) { - p.getWorld().dropItem(p.getEyeLocation(), s); + try{ + p.getWorld().dropItem(p.getEyeLocation(), s); + }catch (Exception e){ + Bukkit.getLogger().warning("exception retrieving items."); + e.printStackTrace(); + } } plugin.database.clearTemporaryStorage(p); } diff --git a/src/main/java/cat/nyaa/HamsterEcoHelper/requisition/RequisitionCommands.java b/src/main/java/cat/nyaa/HamsterEcoHelper/requisition/RequisitionCommands.java index f77e88a..9878cf8 100644 --- a/src/main/java/cat/nyaa/HamsterEcoHelper/requisition/RequisitionCommands.java +++ b/src/main/java/cat/nyaa/HamsterEcoHelper/requisition/RequisitionCommands.java @@ -11,9 +11,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; +import java.util.*; public class RequisitionCommands extends CommandReceiver { private HamsterEcoHelper plugin; @@ -135,8 +133,10 @@ public void Requisition(CommandSender sender, Arguments args) { return; } if (args.remains() != 3) { - msg(sender, "manual.requisition.req.usage"); - return; + if ((args.remains() != 4 || !args.getRawArgs()[3].equalsIgnoreCase("true")) && !args.getRawArgs()[3].equalsIgnoreCase("false")) { + msg(sender, "manual.requisition.req.usage"); + return; + } } Player player = asPlayer(sender); @@ -144,6 +144,9 @@ public void Requisition(CommandSender sender, Arguments args) { ItemStack item = null; double unitPrice = args.nextDouble("#.##"); int amount = args.nextInt(); + boolean hasStrictArg = args.top() != null; + boolean argStrict = hasStrictArg && args.nextBoolean(); + if (plugin.reqManager.cooldown.containsKey(player.getUniqueId()) && plugin.reqManager.cooldown.get(player.getUniqueId()) > System.currentTimeMillis()) { msg(sender, "user.info.cooldown", (plugin.reqManager.cooldown.get(player.getUniqueId()) - System.currentTimeMillis()) / 1000); @@ -167,17 +170,48 @@ public void Requisition(CommandSender sender, Arguments args) { return; } } + boolean isStrict = (!hasStrictArg && isShulkerBox(item)) || argStrict; + if (!plugin.eco.enoughMoney(player, unitPrice * amount)) { msg(sender, "user.warn.no_enough_money"); return; } - boolean success = plugin.reqManager.newPlayerRequisition(player, item, unitPrice, amount); + boolean success = plugin.reqManager.newPlayerRequisition(player, item, unitPrice, amount, isStrict); if (success) { plugin.eco.withdraw(player, amount * unitPrice); plugin.reqManager.cooldown.put(player.getUniqueId(), System.currentTimeMillis() + (plugin.config.playerRequisitionCooldownTicks * 50)); } } + + private static final Set SHULKER_BOXES = new HashSet<>(); + static { + Collections.addAll(SHULKER_BOXES, + Material.SHULKER_BOX, + Material.WHITE_SHULKER_BOX, + Material.ORANGE_SHULKER_BOX, + Material.MAGENTA_SHULKER_BOX, + Material.YELLOW_SHULKER_BOX, + Material.LIME_SHULKER_BOX, + Material.PINK_SHULKER_BOX, + Material.GRAY_SHULKER_BOX, + Material.LIGHT_BLUE_SHULKER_BOX, + Material.LIGHT_GRAY_SHULKER_BOX, + Material.CYAN_SHULKER_BOX, + Material.PURPLE_SHULKER_BOX, + Material.BLUE_SHULKER_BOX, + Material.BROWN_SHULKER_BOX, + Material.GREEN_SHULKER_BOX, + Material.RED_SHULKER_BOX, + Material.BLACK_SHULKER_BOX + ); + } + + private boolean isShulkerBox(ItemStack item) { + if (item == null)return false; + return SHULKER_BOXES.contains(item.getType()); + } + public List reqTabComplete(CommandSender sender, Arguments args) { List list = new ArrayList<>(); if (args.remains() == 1) { diff --git a/src/main/java/cat/nyaa/HamsterEcoHelper/requisition/RequisitionInstance.java b/src/main/java/cat/nyaa/HamsterEcoHelper/requisition/RequisitionInstance.java index bc630f6..8da93ff 100644 --- a/src/main/java/cat/nyaa/HamsterEcoHelper/requisition/RequisitionInstance.java +++ b/src/main/java/cat/nyaa/HamsterEcoHelper/requisition/RequisitionInstance.java @@ -53,7 +53,7 @@ public RequisitionInstance( public RequisitionInstance(Player player, ItemStack item, double unitPrice, int reqAmount, - HamsterEcoHelper plugin, Runnable finishCallback) { + boolean isStrict, HamsterEcoHelper plugin, Runnable finishCallback) { this.owner = player; this.plugin = plugin; this.finishCallback = finishCallback; @@ -61,6 +61,7 @@ public RequisitionInstance(Player player, this.templateItem = new RequisitionSpecification(); this.templateItem.itemTemplate = item; this.templateItem.timeoutTicks = plugin.config.playerRequisitionTimeoutTicks; + this.templateItem.matchRule.requireExact = isStrict; this.templateItem.matchRule.enchantMatch = RequisitionSpecification.MatchingMode.EXACT; this.templateItem.matchRule.nameMatch = RequisitionSpecification.MatchingMode.EXACT; this.templateItem.matchRule.loreMatch = RequisitionSpecification.MatchingMode.EXACT; @@ -115,11 +116,6 @@ public double purchase(Player p, int amount) { if (!templateItem.matchRule.matches(itemHand)) return -2; if (amountRemains < amount && amountRemains >= 0) amount = amountRemains; int new_amount = itemHand.getAmount() - amount; - if (new_amount == 0) { - p.getInventory().setItemInMainHand(new ItemStack(Material.AIR)); - } else { - itemHand.setAmount(new_amount); - } if (owner != null) { ItemStack tmp = itemHand.clone(); @@ -127,6 +123,12 @@ public double purchase(Player p, int amount) { MiscUtils.giveItem(owner, tmp); } + if (new_amount == 0) { + p.getInventory().setItemInMainHand(new ItemStack(Material.AIR)); + } else { + itemHand.setAmount(new_amount); + } + if (amountRemains >= 0) amountRemains -= amount; soldAmount += amount; new Message(I18n.format("user.req.sold_amount_0", p.getName(), amount)) diff --git a/src/main/java/cat/nyaa/HamsterEcoHelper/requisition/RequisitionManager.java b/src/main/java/cat/nyaa/HamsterEcoHelper/requisition/RequisitionManager.java index 18e5af8..7a9de48 100644 --- a/src/main/java/cat/nyaa/HamsterEcoHelper/requisition/RequisitionManager.java +++ b/src/main/java/cat/nyaa/HamsterEcoHelper/requisition/RequisitionManager.java @@ -68,10 +68,10 @@ public boolean newRequisition(RequisitionSpecification item) { return true; } - public boolean newPlayerRequisition(Player player, ItemStack item, double unitPrice, int amount) { + public boolean newPlayerRequisition(Player player, ItemStack item, double unitPrice, int amount, boolean isStrict) { if (currentReq != null) return false; if (item == null) return false; - currentReq = new RequisitionInstance(player, item, unitPrice, amount, plugin, () -> this.currentReq = null); + currentReq = new RequisitionInstance(player, item, unitPrice, amount, isStrict, plugin, () -> this.currentReq = null); if (plugin.config.requisitionHintInterval > 0) { currentReq.new RequisitionHintTimer(this, plugin.config.requisitionHintInterval, plugin); }