From 11bb746e62c783f0ef2893f5a1358c95d8d66add Mon Sep 17 00:00:00 2001 From: j502647092 Date: Sun, 23 Aug 2015 13:21:41 +0800 Subject: [PATCH] add auto clear enchantbench and save player item while close inv... Signed-off-by: j502647092 --- src/cn/citycraft/SimpleEssential/SimpleEssential.java | 1 + .../SimpleEssential/inventory/InventoryControl.java | 9 ++++++++- .../listen/PlayerInventoryViewListen.java | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/cn/citycraft/SimpleEssential/SimpleEssential.java b/src/cn/citycraft/SimpleEssential/SimpleEssential.java index aeef58d..4c334a1 100644 --- a/src/cn/citycraft/SimpleEssential/SimpleEssential.java +++ b/src/cn/citycraft/SimpleEssential/SimpleEssential.java @@ -96,6 +96,7 @@ public class SimpleEssential extends JavaPlugin { @Override public void onDisable() { + invcontrol.clearAllEnchantBench(); } @Override diff --git a/src/cn/citycraft/SimpleEssential/inventory/InventoryControl.java b/src/cn/citycraft/SimpleEssential/inventory/InventoryControl.java index e78a4de..0fd58f8 100644 --- a/src/cn/citycraft/SimpleEssential/inventory/InventoryControl.java +++ b/src/cn/citycraft/SimpleEssential/inventory/InventoryControl.java @@ -4,6 +4,7 @@ package cn.citycraft.SimpleEssential.inventory; import java.util.HashMap; +import java.util.Map.Entry; import org.bukkit.Location; import org.bukkit.Material; @@ -23,6 +24,12 @@ public class InventoryControl { this.plugin = main; } + public void clearAllEnchantBench() { + for (Entry item : enchantbench.entrySet()) { + setRange(item.getValue(), Material.AIR); + } + } + public void clearEnchantBench(Player player) { if (!isOpenEnchantBench(player)) return; @@ -39,7 +46,7 @@ public class InventoryControl { Location loc = player.getLocation(); loc.setY(250); setEnchatRange(loc); - player.openEnchanting(loc, true); + player.openEnchanting(loc, false); enchantbench.put(player.getName(), loc); }; diff --git a/src/cn/citycraft/SimpleEssential/listen/PlayerInventoryViewListen.java b/src/cn/citycraft/SimpleEssential/listen/PlayerInventoryViewListen.java index faad633..89a0442 100644 --- a/src/cn/citycraft/SimpleEssential/listen/PlayerInventoryViewListen.java +++ b/src/cn/citycraft/SimpleEssential/listen/PlayerInventoryViewListen.java @@ -3,6 +3,7 @@ */ package cn.citycraft.SimpleEssential.listen; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -10,6 +11,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; import cn.citycraft.SimpleEssential.SimpleEssential; @@ -33,6 +35,10 @@ public class PlayerInventoryViewListen implements Listener { Player player = (Player) e.getPlayer(); Inventory inv = e.getInventory(); if (inv.getType() == InventoryType.ENCHANTING) { + ItemStack item = e.getInventory().getContents()[0]; + if (item.getType() != Material.AIR) { + player.getInventory().addItem(item); + } plugin.invcontrol.clearEnchantBench(player); } }