74 lines
1.8 KiB
Java
74 lines
1.8 KiB
Java
/**
|
|
*
|
|
*/
|
|
package cn.citycraft.SimpleEssential.inventory;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map.Entry;
|
|
|
|
import org.bukkit.Location;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.entity.Player;
|
|
|
|
import cn.citycraft.SimpleEssential.SimpleEssential;
|
|
|
|
/**
|
|
* @author 蒋天蓓
|
|
*
|
|
*/
|
|
public class InventoryControl {
|
|
SimpleEssential plugin;
|
|
HashMap<String, Location> enchantbench = new HashMap<String, Location>();
|
|
|
|
public InventoryControl(SimpleEssential main) {
|
|
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;
|
|
Location loc = enchantbench.get(player.getName());
|
|
setRange(loc, Material.AIR);
|
|
loc.getBlock().setType(Material.AIR);
|
|
}
|
|
|
|
public boolean isOpenEnchantBench(Player player) {
|
|
return enchantbench.containsKey(player.getName());
|
|
}
|
|
|
|
public void openEnchantBench(Player player) {
|
|
Location loc = player.getLocation();
|
|
loc.setY(250);
|
|
setEnchatRange(loc);
|
|
player.openEnchanting(loc, true);
|
|
enchantbench.put(player.getName(), loc);
|
|
};
|
|
|
|
protected void setBlock(Location loc, int x, int y, int z, Material ma) {
|
|
new Location(loc.getWorld(), loc.getBlockX() + x, loc.getBlockY() + y, loc.getBlockZ() + z).getBlock().setType(ma);
|
|
}
|
|
|
|
protected void setEnchatRange(Location loc) {
|
|
setRange(loc, Material.BOOKSHELF);
|
|
loc.getBlock().setType(Material.ENCHANTMENT_TABLE);
|
|
}
|
|
|
|
protected void setRange(Location loc, Material ma) {
|
|
for (int i = -2; i < 3; i++) {
|
|
for (int j = 0; j < 2; j++) {
|
|
for (int k = -2; k < 3; k++) {
|
|
if (!((i * k == 0) || (i * k * i * k == 1))) {
|
|
setBlock(loc, i, j, k, ma);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|