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); } }