diff --git a/src/cn/citycraft/SimpleEssential/SimpleEssential.java b/src/cn/citycraft/SimpleEssential/SimpleEssential.java index eecae09..d876aec 100644 --- a/src/cn/citycraft/SimpleEssential/SimpleEssential.java +++ b/src/cn/citycraft/SimpleEssential/SimpleEssential.java @@ -10,9 +10,11 @@ import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandException; import org.bukkit.command.CommandSender; +import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; import cn.citycraft.SimpleEssential.command.CommandBack; +import cn.citycraft.SimpleEssential.command.CommandTop; import cn.citycraft.SimpleEssential.command.CommandTpa; import cn.citycraft.SimpleEssential.command.CommandTpaccept; import cn.citycraft.SimpleEssential.command.CommandTpdeny; @@ -45,10 +47,9 @@ public class SimpleEssential extends JavaPlugin { sender.sendMessage(e.getMessage()); } } - sender.sendMessage("命令参数错误!"); + return false; } } - sender.sendMessage("循环结束!"); return true; } @@ -59,16 +60,17 @@ public class SimpleEssential extends JavaPlugin { @Override public void onEnable() { - commandlist = new ArrayList(); - // registerSubCommand(new AddlineCommand()); - registerSubCommand(new CommandTpa(this)); - registerSubCommand(new CommandTpaccept(this)); - registerSubCommand(new CommandTpdeny(this)); - registerSubCommand(new CommandTphere(this)); - registerSubCommand(new CommandBack(this)); - + this.registerCommands(); + this.registerEvents(); tpcontrol = new TeleportControl(this); - getServer().getPluginManager().registerEvents(new PlayerLocationListen(this), this); + + } + + /** + * 注册监听 + */ + private void registerEvents() { + registerEvent(new PlayerLocationListen(this)); } @Override @@ -76,13 +78,36 @@ public class SimpleEssential extends JavaPlugin { Config.load(this, "1.0"); } + /** + * 注册命令 + */ + public void registerCommands() { + commandlist = new ArrayList(); + registerCommand(new CommandTpa(this)); + registerCommand(new CommandTop(this)); + registerCommand(new CommandTpaccept(this)); + registerCommand(new CommandTpdeny(this)); + registerCommand(new CommandTphere(this)); + registerCommand(new CommandBack(this)); + } + /** * 注册命令 * - * @param subCommand + * @param command * - 被注册的命令类 */ - public void registerSubCommand(SimpleEssentialCommand subCommand) { - commandlist.add(subCommand); + public void registerCommand(SimpleEssentialCommand command) { + commandlist.add(command); + } + + /** + * 注册事件 + * + * @param listener + * - 被注册的事件类 + */ + public void registerEvent(Listener listener) { + getServer().getPluginManager().registerEvents(listener, this); } } diff --git a/src/cn/citycraft/SimpleEssential/command/CommandHome.java b/src/cn/citycraft/SimpleEssential/command/CommandHome.java new file mode 100644 index 0000000..ea29807 --- /dev/null +++ b/src/cn/citycraft/SimpleEssential/command/CommandHome.java @@ -0,0 +1,45 @@ +/** + * + */ +package cn.citycraft.SimpleEssential.command; + +import org.bukkit.Location; +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 + * TODO + */ +public class CommandHome extends SimpleEssentialCommand { + SimpleEssential plugin; + + /** + * @param name + */ + public CommandHome(SimpleEssential main) { + super("home", "eshome"); + 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; + Location loc = p.getBedSpawnLocation(); + plugin.tpcontrol.magicTeleport(p, loc); + } +} diff --git a/src/cn/citycraft/SimpleEssential/command/CommandSetHome.java b/src/cn/citycraft/SimpleEssential/command/CommandSetHome.java new file mode 100644 index 0000000..a4da9a4 --- /dev/null +++ b/src/cn/citycraft/SimpleEssential/command/CommandSetHome.java @@ -0,0 +1,50 @@ +/** + * + */ +package cn.citycraft.SimpleEssential.command; + +import org.bukkit.Material; +import org.bukkit.block.Block; +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 + * TODO + */ +public class CommandSetHome extends SimpleEssentialCommand { + SimpleEssential plugin; + + /** + * @param name + */ + public CommandSetHome(SimpleEssential main) { + super("sethome", "essethome"); + 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; + Block b = p.getLocation().add(0, -1, 0).getBlock(); + if (b.getType() == Material.BED_BLOCK) { + + } else { + + } + } +} diff --git a/src/cn/citycraft/SimpleEssential/command/CommandTop.java b/src/cn/citycraft/SimpleEssential/command/CommandTop.java new file mode 100644 index 0000000..15df0cf --- /dev/null +++ b/src/cn/citycraft/SimpleEssential/command/CommandTop.java @@ -0,0 +1,48 @@ +/** + * + */ +package cn.citycraft.SimpleEssential.command; + +import org.bukkit.Location; +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 + * TODO + */ +public class CommandTop extends SimpleEssentialCommand { + SimpleEssential plugin; + + /** + * @param name + */ + public CommandTop(SimpleEssential main) { + super("top", "estop"); + 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; + Location loc = p.getLocation(); + int top = loc.getWorld().getHighestBlockYAt(loc); + loc.setY(top); + p.teleport(loc); + p.sendMessage("&a已传送至当前位置最高方块!"); + } +} diff --git a/src/cn/citycraft/SimpleEssential/command/CommandTpa.java b/src/cn/citycraft/SimpleEssential/command/CommandTpa.java index eebc7e9..914d1a5 100644 --- a/src/cn/citycraft/SimpleEssential/command/CommandTpa.java +++ b/src/cn/citycraft/SimpleEssential/command/CommandTpa.java @@ -41,11 +41,11 @@ public class CommandTpa extends SimpleEssentialCommand { public void execute(CommandSender sender, String label, String[] args) throws CommandException { Player target = Bukkit.getPlayer(args[0]); if (target == null) { - sender.sendMessage("玩家 " + args[0] + " 不存在或不在线!"); + sender.sendMessage("§c玩家 " + args[0] + " 不存在或不在线!"); return; } plugin.tpcontrol.addtp((Player) sender, Bukkit.getPlayer(args[0]), TeleportType.TPA); - sender.sendMessage("已经向玩家 " + target.getDisplayName() + " 发送传送请求!"); + sender.sendMessage("§a已经向玩家 " + target.getDisplayName() + " §a发送传送请求!"); target.sendMessage(new String[] { "§a玩家: " + sender.getName() + "§a请求传送到你这里!", "§a输入命令/tpaccept 或 /tpok 接受传送", diff --git a/src/cn/citycraft/SimpleEssential/command/CommandTphere.java b/src/cn/citycraft/SimpleEssential/command/CommandTphere.java index f48a43e..bb00a4f 100644 --- a/src/cn/citycraft/SimpleEssential/command/CommandTphere.java +++ b/src/cn/citycraft/SimpleEssential/command/CommandTphere.java @@ -26,13 +26,16 @@ public class CommandTphere extends SimpleEssentialCommand { public void execute(CommandSender sender, String label, String[] args) throws CommandException { Player target = Bukkit.getPlayer(args[0]); if (target == null) { - sender.sendMessage("玩家 " + args[0] + " 不存在或不在线!"); + sender.sendMessage("§c玩家 " + args[0] + " 不存在或不在线!"); return; } plugin.tpcontrol.addtp((Player) sender, Bukkit.getPlayer(args[0]), TeleportType.TPH); - sender.sendMessage("已经向玩家 " + target.getDisplayName() + " 发送传送请求!"); - target.sendMessage(new String[] { "§b玩家: " + sender.getName() + "§b请求你传送到他那里!", - "§a输入命令/tpaccept 或 /tpok 接受传送", "§c输入命令/tpdeny 或 /tpno 拒绝传送" }); + sender.sendMessage("§a已经向玩家 " + target.getDisplayName() + " §a发送传送请求!"); + target.sendMessage(new String[] { + "§b玩家: " + sender.getName() + "§b请求你传送到他那里!", + "§a输入命令/tpaccept 或 /tpok 接受传送", + "§c输入命令/tpdeny 或 /tpno 拒绝传送" + }); } @Override diff --git a/src/cn/citycraft/SimpleEssential/config/PlayerConfig.java b/src/cn/citycraft/SimpleEssential/config/PlayerConfig.java new file mode 100644 index 0000000..cdacc45 --- /dev/null +++ b/src/cn/citycraft/SimpleEssential/config/PlayerConfig.java @@ -0,0 +1,48 @@ +package cn.citycraft.SimpleEssential.config; + +import java.io.File; +import java.io.IOException; + +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +public class PlayerConfig extends ConfigLoader { + private static String CONFIG_FOLDER = "userdate"; + private static FileConfig instance; + private static File file; + + public PlayerConfig(Plugin p, String player) { + super(p, CONFIG_FOLDER + File.separator + player + ".yml", false); + file = new File(p.getDataFolder(), CONFIG_FOLDER + File.separator + + player + ".yml"); + instance = super.getInstance(); + } + + public static FileConfig getInstance(Plugin p, Player player) { + new PlayerConfig(p, player.getName()); + return instance; + } + + public static FileConfig getInstance(Plugin p, String player) { + new PlayerConfig(p, player); + return instance; + } + + public static String getMessage(String path) { + String message = instance.getString(path).replaceAll("&", "§"); + return message; + } + + public static String[] getStringArray(String path) { + return instance.getStringList(path).toArray(new String[0]); + } + + public static void save() { + try { + instance.save(file); + } catch (IOException e) { + saveError(file); + e.printStackTrace(); + } + } +} diff --git a/src/cn/citycraft/SimpleEssential/teleport/TeleportControl.java b/src/cn/citycraft/SimpleEssential/teleport/TeleportControl.java index 0511619..fcf522d 100644 --- a/src/cn/citycraft/SimpleEssential/teleport/TeleportControl.java +++ b/src/cn/citycraft/SimpleEssential/teleport/TeleportControl.java @@ -126,6 +126,18 @@ public class TeleportControl { player.sendMessage("§c未找到需要处理的队列!"); } + /** + * 魔法传送 + * + * @param player + * - 被传送的玩家 + * @param loc + * - 传送的地点 + */ + public void magicTeleport(final Player player, final Location loc) { + magicTeleport(player, loc, TpDelay); + } + /** * 魔法传送 * @@ -143,6 +155,7 @@ public class TeleportControl { + " §3X: " + loc.getBlockX() + " Z: " + loc.getBlockZ() + "!"); List pe = new ArrayList(); pe.add(new PotionEffect(PotionEffectType.SLOW, petime, 255)); + pe.add(new PotionEffect(PotionEffectType.CONFUSION, petime, 255)); player.addPotionEffects(pe); plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() { long timeoutmark = System.currentTimeMillis() + delay * 1000; diff --git a/src/plugin.yml b/src/plugin.yml index 2f1c462..b2d3321 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -39,7 +39,18 @@ commands: usage: §b使用/back 回到上一个TP地点! permission: se.back permission-message: §c你没有 的权限来执行此命令! + top: + description: 回到上一个TP地点 + aliases: [setop] + usage: §b使用/top 传送到当前位置最高方块! + permission: se.top + permission-message: §c你没有 的权限来执行此命令! permissions: + se.*: + description: 简单基础插件所有权限! + default: op + children: + se.user: true se.user: description: 简单基础插件玩家权限! default: true