add Inventory Control...

Signed-off-by: j502647092 <jtb1@163.com>
pull/2/MERGE
j502647092 2015-08-23 00:04:01 +08:00
parent 66d5f92092
commit 7aa79c220c
4 changed files with 124 additions and 53 deletions

View File

@ -30,6 +30,8 @@ import cn.citycraft.SimpleEssential.command.CommandTphere;
import cn.citycraft.SimpleEssential.command.CommandWorkBench;
import cn.citycraft.SimpleEssential.config.Config;
import cn.citycraft.SimpleEssential.config.Language;
import cn.citycraft.SimpleEssential.inventory.InventoryControl;
import cn.citycraft.SimpleEssential.listen.PlayerInventoryViewListen;
import cn.citycraft.SimpleEssential.listen.PlayerLocationListen;
import cn.citycraft.SimpleEssential.teleport.TeleportControl;
import cn.citycraft.SimpleEssential.utils.VersionChecker;
@ -45,11 +47,22 @@ public class SimpleEssential extends JavaPlugin {
*
*/
public TeleportControl tpcontrol;
/**
*
*/
public InventoryControl invcontrol;
/**
*
*/
private List<BaseCommand> commandlist;
/**
*
*/
private void initInventoryControl() {
invcontrol = new InventoryControl(this);
}
private void initTeleportControl() {
int tpdelay = Config.getInstance().getInt("Teleport.delay", 3);
String tpcontorlname = Config.getMessage("Teleport.name");
@ -88,6 +101,7 @@ public class SimpleEssential extends JavaPlugin {
@Override
public void onEnable() {
this.initTeleportControl();
this.initInventoryControl();
this.registerCommands();
this.registerEvents();
new VersionChecker(this);
@ -145,5 +159,6 @@ public class SimpleEssential extends JavaPlugin {
*/
private void registerEvents() {
registerEvent(new PlayerLocationListen(this));
registerEvent(new PlayerInventoryViewListen(this));
}
}

View File

@ -5,7 +5,6 @@ package cn.citycraft.SimpleEssential.command;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -26,27 +25,20 @@ public class CommandEnchantBench extends BaseCommand {
this.plugin = main;
}
protected void clearEnchatRange(Location loc) {
setRange(loc, Material.AIR);
loc.getBlock().setType(Material.AIR);
};
@Override
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
Player p = (Player) sender;
final Location loc = p.getLocation();
switch (args.length) {
case 0:
setEnchatRange(loc);
p.openEnchanting(loc.clone().add(0, 255, 0), true);
Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
loc.setY(250);
Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
@Override
public void run() {
clearEnchatRange(loc);
}
}, 200);
}
}, 600);
break;
case 1:
switch (args[0]) {
@ -77,45 +69,4 @@ public class CommandEnchantBench extends BaseCommand {
public boolean isOnlyPlayerExecutable() {
return true;
}
protected void setBlock(Location loc, int x, int y, int z, Material ma) {
new Location(loc.getWorld(), loc.getBlockX() + x, loc.getBlockY() + y + 255, 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 < 3; j++) {
for (int k = -2; k < 3; k++) {
if (i != 0 && j != 0) {
setBlock(loc, i, j, k, ma);
}
}
}
}
// setBlock(loc, -2, 0, -2, ma);
// setBlock(loc, -2, 1, -1, ma);
// setBlock(loc, -2, 0, 1, ma);
// setBlock(loc, -1, 0, 2, ma);
//
// setBlock(loc, 2, 0, 2, ma);
// setBlock(loc, 2, 1, 2, ma);
// setBlock(loc, 1, 0, 2, ma);
// setBlock(loc, 2, 0, 1, ma);
//
// setBlock(loc, -2, 0, -2, ma);
// setBlock(loc, -2, 1, -2, ma);
// setBlock(loc, -1, 0, -2, ma);
// setBlock(loc, -2, 0, -1, ma);
//
// setBlock(loc, 2, 0, -2, ma);
// setBlock(loc, 2, 1, -2, ma);
// setBlock(loc, 1, 0, -2, ma);
// setBlock(loc, 2, 0, -1, ma);
}
}

View File

@ -0,0 +1,66 @@
/**
*
*/
package cn.citycraft.SimpleEssential.inventory;
import java.util.HashMap;
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 clearEnchatRange(Player player) {
if (!isOpen(player))
return;
Location loc = enchantbench.get(player.getName());
setRange(loc, Material.AIR);
loc.getBlock().setType(Material.AIR);
}
public boolean isOpen(Player player) {
return enchantbench.containsKey(player.getName());
}
public void open(Player player) {
Location loc = player.getLocation();
loc.setY(-5);
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);
}
}
}
}
}
}

View File

@ -0,0 +1,39 @@
/**
*
*/
package cn.citycraft.SimpleEssential.listen;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import cn.citycraft.SimpleEssential.SimpleEssential;
/**
*
*
* @author 20158128:19:33
*
*/
public class PlayerInventoryViewListen implements Listener {
SimpleEssential plugin;
public PlayerInventoryViewListen(SimpleEssential main) {
this.plugin = main;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onInventoryClose(InventoryCloseEvent e) {
if (!(e.getPlayer() instanceof Player))
return;
Player player = (Player) e.getPlayer();
Inventory inv = e.getInventory();
if (inv.getType() == InventoryType.ENCHANTING) {
plugin.invcontrol.clearEnchatRange(player);
}
}
}