From c126d80a4190cde71cd8795b8476ea6f25608683 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Fri, 21 Aug 2015 20:48:27 +0800 Subject: [PATCH] add EnchantBench and WorkBench... Signed-off-by: 502647092 --- .../SimpleEssential/SimpleEssential.java | 4 + .../command/CommandEnchantBench.java | 103 ++++++++++++++++++ .../command/CommandWorkBench.java | 45 ++++++++ src/plugin.yml | 15 +++ 4 files changed, 167 insertions(+) create mode 100644 src/cn/citycraft/SimpleEssential/command/CommandEnchantBench.java create mode 100644 src/cn/citycraft/SimpleEssential/command/CommandWorkBench.java diff --git a/src/cn/citycraft/SimpleEssential/SimpleEssential.java b/src/cn/citycraft/SimpleEssential/SimpleEssential.java index 19c9392..6538248 100644 --- a/src/cn/citycraft/SimpleEssential/SimpleEssential.java +++ b/src/cn/citycraft/SimpleEssential/SimpleEssential.java @@ -15,6 +15,7 @@ import org.bukkit.plugin.java.JavaPlugin; import cn.citycraft.SimpleEssential.command.BaseCommand; import cn.citycraft.SimpleEssential.command.CommandBack; +import cn.citycraft.SimpleEssential.command.CommandEnchantBench; import cn.citycraft.SimpleEssential.command.CommandHat; import cn.citycraft.SimpleEssential.command.CommandHome; import cn.citycraft.SimpleEssential.command.CommandSetHome; @@ -24,6 +25,7 @@ import cn.citycraft.SimpleEssential.command.CommandTpa; import cn.citycraft.SimpleEssential.command.CommandTpaccept; import cn.citycraft.SimpleEssential.command.CommandTpdeny; 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.listen.PlayerLocationListen; @@ -117,6 +119,8 @@ public class SimpleEssential extends JavaPlugin { registerCommand(new CommandHome(this)); registerCommand(new CommandHat(this)); registerCommand(new CommandSuicide(this)); + registerCommand(new CommandEnchantBench(this)); + registerCommand(new CommandWorkBench(this)); } /** diff --git a/src/cn/citycraft/SimpleEssential/command/CommandEnchantBench.java b/src/cn/citycraft/SimpleEssential/command/CommandEnchantBench.java new file mode 100644 index 0000000..3951eb3 --- /dev/null +++ b/src/cn/citycraft/SimpleEssential/command/CommandEnchantBench.java @@ -0,0 +1,103 @@ +/** + * + */ +package cn.citycraft.SimpleEssential.command; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.command.CommandException; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import cn.citycraft.SimpleEssential.SimpleEssential; + +/** + * @author 蒋天蓓 2015年8月12日下午2:04:05 + */ +public class CommandEnchantBench extends BaseCommand { + SimpleEssential plugin; + + /** + * @param name + */ + public CommandEnchantBench(SimpleEssential main) { + super("enchantbench", "seenchantbench", "eb", "seeb"); + this.plugin = main; + } + + @Override + public boolean isOnlyPlayerExecutable() { + return true; + }; + + @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, true); + clearEnchatRange(loc); + break; + case 1: + switch (args[0]) { + case "set": + setEnchatRange(loc); + break; + case "clear": + clearEnchatRange(loc); + break; + } + break; + default: + break; + } + } + + protected void setRange(Location loc, Material 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); + } + + protected void clearEnchatRange(Location loc) { + setRange(loc, Material.AIR); + loc.getBlock().setType(Material.AIR); + } + + protected void setEnchatRange(Location loc) { + setRange(loc, Material.BOOKSHELF); + loc.getBlock().setType(Material.ENCHANTMENT_TABLE); + } + + 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); + } + + @Override + public int getMinimumArguments() { + return 0; + } + + @Override + public String getPossibleArguments() { + return ""; + } +} diff --git a/src/cn/citycraft/SimpleEssential/command/CommandWorkBench.java b/src/cn/citycraft/SimpleEssential/command/CommandWorkBench.java new file mode 100644 index 0000000..e5d77eb --- /dev/null +++ b/src/cn/citycraft/SimpleEssential/command/CommandWorkBench.java @@ -0,0 +1,45 @@ +/** + * + */ +package cn.citycraft.SimpleEssential.command; + +import org.bukkit.Bukkit; +import org.bukkit.command.CommandException; +import org.bukkit.command.CommandSender; + +import cn.citycraft.SimpleEssential.SimpleEssential; + +/** + * @author 蒋天蓓 2015年8月12日下午2:04:05 + */ +public class CommandWorkBench extends BaseCommand { + SimpleEssential plugin; + + /** + * @param name + */ + public CommandWorkBench(SimpleEssential main) { + super("workbench", "seworkbench", "wb", "sewb"); + this.plugin = main; + } + + @Override + public boolean isOnlyPlayerExecutable() { + return true; + }; + + @Override + public void execute(CommandSender sender, String label, String[] args) throws CommandException { + Bukkit.getPlayer(sender.getName()).openWorkbench(null, true); + } + + @Override + public int getMinimumArguments() { + return 0; + } + + @Override + public String getPossibleArguments() { + return ""; + } +} diff --git a/src/plugin.yml b/src/plugin.yml index faeea7c..7fc3d8d 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -69,6 +69,19 @@ commands: usage: §6使用§a/hat §6把手上的物品带在头上! permission: se.hat permission-message: §c你没有 的权限来执行此命令! + workbench: + description: 打开随身工作台 + aliases: [seworkbench,wb,sewb] + usage: §6使用§a/workbench §6打开随身工作台! + permission: se.workbench + permission-message: §c你没有 的权限来执行此命令! + enchantbench: + description: 打开随身附魔台(30级) + aliases: [seenchantbench,seeb,eb] + usage: §6使用§a/enchantbench §6打开随身附魔台(30级)! + permission: se.enchantbench + permission-message: §c你没有 的权限来执行此命令! + permissions: se.*: description: 简单基础插件所有权限! @@ -88,4 +101,6 @@ permissions: se.home: true se.suicide: true se.hat: true + se.workbench: true + se.enchantbench: true