diff --git a/src/cn/citycraft/SimpleEssential/SimpleEssential.java b/src/cn/citycraft/SimpleEssential/SimpleEssential.java index a03db2a..16736f0 100644 --- a/src/cn/citycraft/SimpleEssential/SimpleEssential.java +++ b/src/cn/citycraft/SimpleEssential/SimpleEssential.java @@ -13,15 +13,17 @@ import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; +import cn.citycraft.SimpleEssential.command.BaseCommand; import cn.citycraft.SimpleEssential.command.CommandBack; +import cn.citycraft.SimpleEssential.command.CommandHat; import cn.citycraft.SimpleEssential.command.CommandHome; import cn.citycraft.SimpleEssential.command.CommandSetHome; +import cn.citycraft.SimpleEssential.command.CommandSuicide; import cn.citycraft.SimpleEssential.command.CommandTop; 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.SimpleEssentialCommand; import cn.citycraft.SimpleEssential.config.Config; import cn.citycraft.SimpleEssential.config.Language; import cn.citycraft.SimpleEssential.listen.PlayerLocationListen; @@ -42,11 +44,11 @@ public class SimpleEssential extends JavaPlugin { /** * 命令监听列表 */ - private List commandlist; + private List commandlist; @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - for (SimpleEssentialCommand command : commandlist) { + for (BaseCommand command : commandlist) { if (command.isValidTrigger(label)) { if (!command.hasPermission(sender)) { sender.sendMessage(Language.getMessage("Base.no-permission")); @@ -98,7 +100,7 @@ public class SimpleEssential extends JavaPlugin { * 注册命令 */ public void registerCommands() { - commandlist = new ArrayList(); + commandlist = new ArrayList(); registerCommand(new CommandTpa(this)); registerCommand(new CommandTop(this)); registerCommand(new CommandTpaccept(this)); @@ -107,7 +109,8 @@ public class SimpleEssential extends JavaPlugin { registerCommand(new CommandBack(this)); registerCommand(new CommandSetHome(this)); registerCommand(new CommandHome(this)); - + registerCommand(new CommandHat(this)); + registerCommand(new CommandSuicide(this)); } /** @@ -116,7 +119,7 @@ public class SimpleEssential extends JavaPlugin { * @param command * - 被注册的命令类 */ - public void registerCommand(SimpleEssentialCommand command) { + public void registerCommand(BaseCommand command) { commandlist.add(command); } diff --git a/src/cn/citycraft/SimpleEssential/command/SimpleEssentialCommand.java b/src/cn/citycraft/SimpleEssential/command/BaseCommand.java similarity index 88% rename from src/cn/citycraft/SimpleEssential/command/SimpleEssentialCommand.java rename to src/cn/citycraft/SimpleEssential/command/BaseCommand.java index 4edcf43..5bd824b 100644 --- a/src/cn/citycraft/SimpleEssential/command/SimpleEssentialCommand.java +++ b/src/cn/citycraft/SimpleEssential/command/BaseCommand.java @@ -12,16 +12,16 @@ import org.bukkit.command.CommandSender; * @author 蒋天蓓 * 2015年8月12日下午12:49:34 */ -public abstract class SimpleEssentialCommand { +public abstract class BaseCommand { private String name; private String permission; private String[] aliases; - public SimpleEssentialCommand(String name) { + public BaseCommand(String name) { this(name, new String[0]); } - public SimpleEssentialCommand(String name, String... aliases) { + public BaseCommand(String name, String... aliases) { this.name = name; this.aliases = aliases; } diff --git a/src/cn/citycraft/SimpleEssential/command/CommandBack.java b/src/cn/citycraft/SimpleEssential/command/CommandBack.java index 9f33ea0..1e94ecb 100644 --- a/src/cn/citycraft/SimpleEssential/command/CommandBack.java +++ b/src/cn/citycraft/SimpleEssential/command/CommandBack.java @@ -12,7 +12,7 @@ import cn.citycraft.SimpleEssential.SimpleEssential; /** * @author 蒋天蓓 2015年8月12日下午2:04:05 */ -public class CommandBack extends SimpleEssentialCommand { +public class CommandBack extends BaseCommand { SimpleEssential plugin; /** diff --git a/src/cn/citycraft/SimpleEssential/command/CommandHat.java b/src/cn/citycraft/SimpleEssential/command/CommandHat.java new file mode 100644 index 0000000..cf4697e --- /dev/null +++ b/src/cn/citycraft/SimpleEssential/command/CommandHat.java @@ -0,0 +1,59 @@ +package cn.citycraft.SimpleEssential.command; + +import org.bukkit.command.CommandException; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import cn.citycraft.SimpleEssential.SimpleEssential; +import cn.citycraft.SimpleEssential.config.Language; + +/** + * @Author 代小呆 created in 2015年8月16日下午1:44:22 + */ + +public class CommandHat extends BaseCommand { + + @SuppressWarnings("unused") + private SimpleEssential plugin; + + public CommandHat(SimpleEssential main) { + super("hat", "sehat"); + this.plugin = main; + } + + @Override + public String getPossibleArguments() { + return ""; + } + + @Override + public int getMinimumArguments() { + return 0; + } + + @Override + public void execute(CommandSender sender, String label, String[] args) throws CommandException { + Player p = (Player) sender; + if (p.getItemInHand() == null) { + sender.sendMessage(Language.getMessage("Hat.empty")); + return; + } else { + ItemStack hand = p.getItemInHand(); + p.setItemInHand(null); + ItemStack helmet = p.getInventory().getHelmet(); + if (!(helmet == null)) { + p.getInventory().addItem(helmet); + } + p.getInventory().setHelmet(hand); + sender.sendMessage(Language.getMessage("Hat.enjoy")); + } + + } + + @Override + public boolean isOnlyPlayerExecutable() { + return true; + } + +} diff --git a/src/cn/citycraft/SimpleEssential/command/CommandHome.java b/src/cn/citycraft/SimpleEssential/command/CommandHome.java index edb334c..364c02d 100644 --- a/src/cn/citycraft/SimpleEssential/command/CommandHome.java +++ b/src/cn/citycraft/SimpleEssential/command/CommandHome.java @@ -16,7 +16,7 @@ import cn.citycraft.SimpleEssential.config.Language; * * @author 蒋天蓓 2015年8月12日下午2:04:05 */ -public class CommandHome extends SimpleEssentialCommand { +public class CommandHome extends BaseCommand { SimpleEssential plugin; /** diff --git a/src/cn/citycraft/SimpleEssential/command/CommandSetHome.java b/src/cn/citycraft/SimpleEssential/command/CommandSetHome.java index f211828..732766b 100644 --- a/src/cn/citycraft/SimpleEssential/command/CommandSetHome.java +++ b/src/cn/citycraft/SimpleEssential/command/CommandSetHome.java @@ -17,7 +17,7 @@ import cn.citycraft.SimpleEssential.config.Language; * * @author 蒋天蓓 2015年8月12日下午2:04:05 */ -public class CommandSetHome extends SimpleEssentialCommand { +public class CommandSetHome extends BaseCommand { SimpleEssential plugin; public CommandSetHome(SimpleEssential main) { diff --git a/src/cn/citycraft/SimpleEssential/command/CommandSuicide.java b/src/cn/citycraft/SimpleEssential/command/CommandSuicide.java new file mode 100644 index 0000000..932eda3 --- /dev/null +++ b/src/cn/citycraft/SimpleEssential/command/CommandSuicide.java @@ -0,0 +1,66 @@ +package cn.citycraft.SimpleEssential.command; + +import java.util.Arrays; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.Effect; +import org.bukkit.command.CommandException; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +// import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.inventory.ItemStack; + +import cn.citycraft.SimpleEssential.SimpleEssential; +import cn.citycraft.SimpleEssential.config.Language; +// import cn.citycraft.SimpleEssential.config.Language; +import cn.citycraft.SimpleEssential.utils.EffectUtil; + +// import cn.citycraft.SimpleEssential.utils.Randomer; + +/** + * 自杀命令 + * + * @Author 代小呆 created in 2015年8月14日下午4:24:19 + */ + +public class CommandSuicide extends BaseCommand { + private SimpleEssential plugin; + + public CommandSuicide(SimpleEssential main) { + super("suicide", "sesuicide", "sd"); + this.plugin = main; + + } + + @Override + public String getPossibleArguments() { + return ""; + } + + @Override + public int getMinimumArguments() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void execute(CommandSender sender, String label, String[] args) throws CommandException { + Player p = (Player) sender; + List drops = Arrays.asList(p.getInventory().getContents()); + int deoppedexp = (int) Math.floor(p.getExp()); + String deathMessage = Language.getMessage("Suicide.msg"); + PlayerDeathEvent pd = new PlayerDeathEvent(p, drops, deoppedexp, deathMessage); + plugin.getServer().getPluginManager().callEvent(pd); + Bukkit.broadcastMessage(pd.getDeathMessage()); + EffectUtil.run(p.getLocation(), 10, Effect.POTION_BREAK); + p.setHealth(0); + } + + @Override + public boolean isOnlyPlayerExecutable() { + return true; + } + +} diff --git a/src/cn/citycraft/SimpleEssential/command/CommandTop.java b/src/cn/citycraft/SimpleEssential/command/CommandTop.java index 2b92d35..725b170 100644 --- a/src/cn/citycraft/SimpleEssential/command/CommandTop.java +++ b/src/cn/citycraft/SimpleEssential/command/CommandTop.java @@ -18,7 +18,7 @@ import cn.citycraft.SimpleEssential.config.Language; * 2015年8月12日下午2:04:05 * */ -public class CommandTop extends SimpleEssentialCommand { +public class CommandTop extends BaseCommand { SimpleEssential plugin; /** diff --git a/src/cn/citycraft/SimpleEssential/command/CommandTpa.java b/src/cn/citycraft/SimpleEssential/command/CommandTpa.java index 8e61f34..9cf7bb0 100644 --- a/src/cn/citycraft/SimpleEssential/command/CommandTpa.java +++ b/src/cn/citycraft/SimpleEssential/command/CommandTpa.java @@ -19,7 +19,7 @@ import cn.citycraft.SimpleEssential.teleport.TeleportType; * 2015年8月12日下午2:04:05 * */ -public class CommandTpa extends SimpleEssentialCommand { +public class CommandTpa extends BaseCommand { SimpleEssential plugin; /** diff --git a/src/cn/citycraft/SimpleEssential/command/CommandTpaccept.java b/src/cn/citycraft/SimpleEssential/command/CommandTpaccept.java index 932177c..17e4ddc 100644 --- a/src/cn/citycraft/SimpleEssential/command/CommandTpaccept.java +++ b/src/cn/citycraft/SimpleEssential/command/CommandTpaccept.java @@ -16,7 +16,7 @@ import cn.citycraft.SimpleEssential.SimpleEssential; * 2015年8月12日下午2:04:05 * */ -public class CommandTpaccept extends SimpleEssentialCommand { +public class CommandTpaccept extends BaseCommand { SimpleEssential plugin; /** diff --git a/src/cn/citycraft/SimpleEssential/command/CommandTpdeny.java b/src/cn/citycraft/SimpleEssential/command/CommandTpdeny.java index 1cba3d4..3cfa434 100644 --- a/src/cn/citycraft/SimpleEssential/command/CommandTpdeny.java +++ b/src/cn/citycraft/SimpleEssential/command/CommandTpdeny.java @@ -16,7 +16,7 @@ import cn.citycraft.SimpleEssential.SimpleEssential; * 2015年8月12日下午2:04:05 * */ -public class CommandTpdeny extends SimpleEssentialCommand { +public class CommandTpdeny extends BaseCommand { SimpleEssential plugin; public CommandTpdeny(SimpleEssential main) { diff --git a/src/cn/citycraft/SimpleEssential/command/CommandTphere.java b/src/cn/citycraft/SimpleEssential/command/CommandTphere.java index 8441cc3..16e37b4 100644 --- a/src/cn/citycraft/SimpleEssential/command/CommandTphere.java +++ b/src/cn/citycraft/SimpleEssential/command/CommandTphere.java @@ -17,7 +17,7 @@ import cn.citycraft.SimpleEssential.teleport.TeleportType; * * @author 蒋天蓓 2015年8月12日下午2:04:05 */ -public class CommandTphere extends SimpleEssentialCommand { +public class CommandTphere extends BaseCommand { SimpleEssential plugin; public CommandTphere(SimpleEssential main) { diff --git a/src/cn/citycraft/SimpleEssential/config/Config.java b/src/cn/citycraft/SimpleEssential/config/Config.java index aec8e3e..b1228ee 100644 --- a/src/cn/citycraft/SimpleEssential/config/Config.java +++ b/src/cn/citycraft/SimpleEssential/config/Config.java @@ -9,7 +9,7 @@ public class Config extends ConfigLoader { private static String CONFIG_NAME = "config.yml"; private static FileConfig instance; private static File file; - + public Config(Plugin p) { super(p, CONFIG_NAME); file = new File(p.getDataFolder(), CONFIG_NAME); @@ -20,7 +20,7 @@ public class Config extends ConfigLoader { super(p, CONFIG_NAME, ver); instance = super.getInstance(); } - + public static void load(Plugin p) { new Config(p); } @@ -28,14 +28,14 @@ public class Config extends ConfigLoader { public static void load(Plugin p, String ver) { new Config(p, ver); } - + public static FileConfig getInstance() { return instance; } public static String getMessage(String path) { String message = instance.getString(path); - if (message != null) + if (message != null && message.length() != 0) message = message.replaceAll("&", "§"); return message; } @@ -43,8 +43,8 @@ public class Config extends ConfigLoader { public static String[] getStringArray(String path) { return instance.getStringList(path).toArray(new String[0]); } - - public static void save(){ + + public static void save() { try { instance.save(file); } catch (IOException e) { diff --git a/src/cn/citycraft/SimpleEssential/config/Language.java b/src/cn/citycraft/SimpleEssential/config/Language.java index b14ebb9..eb20926 100644 --- a/src/cn/citycraft/SimpleEssential/config/Language.java +++ b/src/cn/citycraft/SimpleEssential/config/Language.java @@ -45,7 +45,7 @@ public class Language extends ConfigLoader { public static String getMessage(String path) { String message = instance.getString(path); - if (message != null) + if (message != null && message.length() != 0) message = message.replaceAll("&", "§"); return message; } diff --git a/src/cn/citycraft/SimpleEssential/utils/EffectUtil.java b/src/cn/citycraft/SimpleEssential/utils/EffectUtil.java index 01c689d..0ba07c4 100644 --- a/src/cn/citycraft/SimpleEssential/utils/EffectUtil.java +++ b/src/cn/citycraft/SimpleEssential/utils/EffectUtil.java @@ -14,13 +14,16 @@ import org.bukkit.Location; * */ public class EffectUtil { + /** * 粒子发生器 - * + * * @param loc - * - 粒子产生的地点 + * - 粒子产生地点 * @param range - * - 粒子的数量 + * - 粒子产生数量 + * @param effects + * - 粒子类型 */ public static void run(Location loc, long range, Effect... effects) { try { diff --git a/src/language.yml b/src/language.yml index 291e50f..6afabd0 100644 --- a/src/language.yml +++ b/src/language.yml @@ -23,4 +23,11 @@ Teleport: tphere: '§b玩家: %s§b请求你传送到他那里!' tpaccept: '§a输入命令/tpaccept 或 /tpok 接受传送' tpdeny: '§c输入命令/tpdeny 或 /tpno 拒绝传送' - nobackloc: '§c未找到可以Back的地点!' \ No newline at end of file + nobackloc: '§c未找到可以Back的地点!' +#自杀 +Suicide: + msg: '§6玩家: %s §c活不下去自杀了!' +#帽子 +Hat: + empty: '§c看上去你手上什么都没有啊!' + enjoy: '§2享受你的新帽子吧!' \ No newline at end of file