fix: 修复未设置时也可以打开附魔台的问题

Signed-off-by: 502647092 <admin@yumc.pw>
Custom
502647092 2016-09-04 17:23:52 +08:00
parent 0586c3642d
commit 6e761d5cbd
1 changed files with 63 additions and 62 deletions

View File

@ -18,73 +18,74 @@ import org.bukkit.plugin.java.JavaPlugin;
/** /**
* *
* *
* @author 20158243:48:42 * @author 20158243:48:42
*/ */
public class CarryEnchantBench extends JavaPlugin implements Listener { public class CarryEnchantBench extends JavaPlugin implements Listener {
Location loc = null; Location loc = null;
List<String> setList = new ArrayList<String>(); List<String> setList = new ArrayList<>();
@EventHandler @EventHandler
public void onClick(PlayerInteractEvent e) { public void onClick(final PlayerInteractEvent e) {
Block b = e.getClickedBlock(); final Block b = e.getClickedBlock();
Player p = e.getPlayer(); final Player p = e.getPlayer();
if (setList.contains(p.getName())) { if (setList.contains(p.getName())) {
if (b.getType() == Material.ENCHANTMENT_TABLE) { if (b.getType() == Material.ENCHANTMENT_TABLE) {
loc = b.getLocation(); loc = b.getLocation();
this.getConfig().set("Location.World", loc.getWorld().getName()); this.getConfig().set("Location.World", loc.getWorld().getName());
this.getConfig().set("Location.X", loc.getBlockX()); this.getConfig().set("Location.X", loc.getBlockX());
this.getConfig().set("Location.Y", loc.getBlockY()); this.getConfig().set("Location.Y", loc.getBlockY());
this.getConfig().set("Location.Z", loc.getBlockZ()); this.getConfig().set("Location.Z", loc.getBlockZ());
this.saveConfig(); this.saveConfig();
p.sendMessage("§a已成功配置随身附魔台的位置 §c请勿破坏 否则将会影响插件工作!"); p.sendMessage("§a已成功配置随身附魔台的位置 §c请勿破坏 否则将会影响插件工作!");
} else { } else {
p.sendMessage("§c请点击附魔台配置随身附魔台位置!"); p.sendMessage("§c请点击附魔台配置随身附魔台位置!");
} }
setList.remove(p.getName()); setList.remove(p.getName());
e.setCancelled(true); e.setCancelled(true);
} }
} }
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
if (!(sender instanceof Player)) { if (!(sender instanceof Player)) {
sender.sendMessage("§c控制台吃饱了撑着用毛线附魔台啊"); sender.sendMessage("§c控制台吃饱了撑着用毛线附魔台啊");
} }
switch (args.length) { switch (args.length) {
case 0: case 0:
Player p = (Player) sender; final Player p = (Player) sender;
if (loc.getBlock().getType() != Material.ENCHANTMENT_TABLE) { if (loc.getBlock().getType() != Material.ENCHANTMENT_TABLE) {
p.sendMessage("§c管理员尚未配置随身附魔台的位置或附魔台被破坏!"); p.sendMessage("§c管理员尚未配置随身附魔台的位置或附魔台被破坏!");
} return true;
p.openEnchanting(loc, true); }
p.sendMessage("§a已打开随身附魔台!"); p.openEnchanting(loc, true);
return true; p.sendMessage("§a已打开随身附魔台!");
case 1: return true;
if (args[0].equalsIgnoreCase("set")) { case 1:
if (sender.hasPermission("ceb.set")) { if (args[0].equalsIgnoreCase("set")) {
if (!setList.contains(sender.getName())) { if (sender.hasPermission("ceb.set")) {
sender.sendMessage("§b请点击目标附魔台配置为随身附魔台!"); if (!setList.contains(sender.getName())) {
setList.add(sender.getName()); sender.sendMessage("§b请点击目标附魔台配置为随身附魔台!");
} setList.add(sender.getName());
} }
return true; }
} return true;
break; }
} break;
return false; }
} return false;
}
@Override @Override
public void onEnable() { public void onEnable() {
this.saveDefaultConfig(); this.saveDefaultConfig();
String worldname = getConfig().getString("Location.World"); final String worldname = getConfig().getString("Location.World");
World world = Bukkit.getWorld(worldname); final World world = Bukkit.getWorld(worldname);
int x = getConfig().getInt("Location.X"); final int x = getConfig().getInt("Location.X");
int y = getConfig().getInt("Location.Y"); final int y = getConfig().getInt("Location.Y");
int z = getConfig().getInt("Location.Z"); final int z = getConfig().getInt("Location.Z");
loc = new Location(world, x, y, z); loc = new Location(world, x, y, z);
this.getServer().getPluginManager().registerEvents(this, this); this.getServer().getPluginManager().registerEvents(this, this);
} }
} }