1
0
mirror of https://e.coding.net/circlecloud/SimpleEssential.git synced 2024-11-17 01:18:47 +00:00

add auto clear enchantbench and save player item while close inv...

Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
j502647092 2015-08-23 13:21:41 +08:00
parent a2a5d2d8dd
commit 11bb746e62
3 changed files with 15 additions and 1 deletions

View File

@ -96,6 +96,7 @@ public class SimpleEssential extends JavaPlugin {
@Override
public void onDisable() {
invcontrol.clearAllEnchantBench();
}
@Override

View File

@ -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<String, Location> 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);
};

View File

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