From a4381c39bc532e2111c1056dc121a6caedfc2d9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Mon, 19 Mar 2018 23:38:30 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=88=E6=9C=AC=E6=9B=B4=E6=96=B0=E8=87=B3?= =?UTF-8?q?=EF=BC=9A3.825?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增:/tlib tagprefix 设置头顶前缀称号 新增:/tlib tagsuffix 设置头顶后缀称号 新增:/tlib tagdelete 删除头顶称号 新增:TagManager 工具新增方法 removeData() 用于删除玩家数据 --- resources/plugin.yml | 2 +- .../skymc/taboolib/commands/MainCommands.java | 12 +++++ .../taboolib/commands/sub/HelpCommand.java | 4 ++ .../commands/sub/TagDeleteCommand.java | 41 +++++++++++++++++ .../commands/sub/TagPrefixCommand.java | 46 +++++++++++++++++++ .../commands/sub/TagSuffixCommand.java | 46 +++++++++++++++++++ .../me/skymc/taboolib/team/TagManager.java | 20 +++++++- 7 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 src/main/java/me/skymc/taboolib/commands/sub/TagDeleteCommand.java create mode 100644 src/main/java/me/skymc/taboolib/commands/sub/TagPrefixCommand.java create mode 100644 src/main/java/me/skymc/taboolib/commands/sub/TagSuffixCommand.java diff --git a/resources/plugin.yml b/resources/plugin.yml index 01ff73e..422e33e 100644 --- a/resources/plugin.yml +++ b/resources/plugin.yml @@ -6,7 +6,7 @@ website: http://www.15imc.com/index.html main: me.skymc.taboolib.Main -version: 3.81 +version: 3.825 commands: taboolib: diff --git a/src/main/java/me/skymc/taboolib/commands/MainCommands.java b/src/main/java/me/skymc/taboolib/commands/MainCommands.java index febe076..724d10d 100644 --- a/src/main/java/me/skymc/taboolib/commands/MainCommands.java +++ b/src/main/java/me/skymc/taboolib/commands/MainCommands.java @@ -22,6 +22,9 @@ import me.skymc.taboolib.commands.sub.ItemCommand; import me.skymc.taboolib.commands.sub.PotionCommand; import me.skymc.taboolib.commands.sub.SaveCommand; import me.skymc.taboolib.commands.sub.SlotCommand; +import me.skymc.taboolib.commands.sub.TagDeleteCommand; +import me.skymc.taboolib.commands.sub.TagPrefixCommand; +import me.skymc.taboolib.commands.sub.TagSuffixCommand; import me.skymc.taboolib.commands.sub.VariableGetCommand; import me.skymc.taboolib.commands.sub.VariableSetCommand; import me.skymc.taboolib.commands.sub.cycle.CycleCommand; @@ -88,6 +91,15 @@ public class MainCommands implements CommandExecutor{ else if (args[0].equalsIgnoreCase("sounds")) { new SoundsCommand(sender, args); } + else if (args[0].equalsIgnoreCase("tagprefix")) { + new TagPrefixCommand(sender, args); + } + else if (args[0].equalsIgnoreCase("tagsuffix")) { + new TagSuffixCommand(sender, args); + } + else if (args[0].equalsIgnoreCase("tagdelete")) { + new TagDeleteCommand(sender, args); + } else { MsgUtils.send(sender, "&4指令错误"); } diff --git a/src/main/java/me/skymc/taboolib/commands/sub/HelpCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/HelpCommand.java index 6831cb9..e877de1 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/HelpCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/HelpCommand.java @@ -44,6 +44,10 @@ public class HelpCommand extends SubCommand { helps.put("§f", null); helps.put("/taboolib shell load §8[§7名称§8]", "§e载入某个脚本"); helps.put("/taboolib shell unload §8[§7名称§8]", "§e卸载某个脚本"); + helps.put("§g", null); + helps.put("/taboolib tagprefix §8[§7名称§8] §8[§7文本§8]", "§e设置玩家头顶前缀"); + helps.put("/taboolib tagsuffix §8[§7名称§8] §8[§7文本§8]", "§e设置玩家头顶后缀"); + helps.put("/taboolib tagdelete §8[§7名称§8]", "§e删除玩家称号数据"); helps.put("§e", null); helps.put("/taboolib importdata", "§4向数据库导入本地数据 §8(该操作将会清空数据库)"); diff --git a/src/main/java/me/skymc/taboolib/commands/sub/TagDeleteCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/TagDeleteCommand.java new file mode 100644 index 0000000..36df869 --- /dev/null +++ b/src/main/java/me/skymc/taboolib/commands/sub/TagDeleteCommand.java @@ -0,0 +1,41 @@ +package me.skymc.taboolib.commands.sub; + +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import me.clip.placeholderapi.PlaceholderAPI; +import me.skymc.taboolib.commands.SubCommand; +import me.skymc.taboolib.message.MsgUtils; +import me.skymc.taboolib.team.TagManager; + +/** + * @author sky + * @since 2018-03-19 23:13:35 + */ +public class TagDeleteCommand extends SubCommand { + + /** + * @param sender + * @param args + */ + public TagDeleteCommand(CommandSender sender, String[] args) { + super(sender, args); + if (args.length < 2) { + MsgUtils.send(sender, "参数错误"); + return; + } + + Player player = Bukkit.getPlayerExact(args[1]); + if (player == null) { + MsgUtils.send(sender, "玩家 &f" + args[1] + " &7不在线"); + return; + } + + TagManager.getInst().removeData(player); + if (sender instanceof Player) { + MsgUtils.send(sender, "删除玩家 &f" + args[1] + " &7的称号数据"); + } + } + +} diff --git a/src/main/java/me/skymc/taboolib/commands/sub/TagPrefixCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/TagPrefixCommand.java new file mode 100644 index 0000000..3c3c927 --- /dev/null +++ b/src/main/java/me/skymc/taboolib/commands/sub/TagPrefixCommand.java @@ -0,0 +1,46 @@ +package me.skymc.taboolib.commands.sub; + +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import me.clip.placeholderapi.PlaceholderAPI; +import me.skymc.taboolib.commands.SubCommand; +import me.skymc.taboolib.message.MsgUtils; +import me.skymc.taboolib.team.TagManager; + +/** + * @author sky + * @since 2018-03-19 23:13:35 + */ +public class TagPrefixCommand extends SubCommand { + + /** + * @param sender + * @param args + */ + public TagPrefixCommand(CommandSender sender, String[] args) { + super(sender, args); + if (args.length < 3) { + MsgUtils.send(sender, "参数错误"); + return; + } + + Player player = Bukkit.getPlayerExact(args[1]); + if (player == null) { + MsgUtils.send(sender, "玩家 &f" + args[1] + " &7不在线"); + return; + } + + String value = getArgs(2).replace("&", "§"); + if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { + value = PlaceholderAPI.setPlaceholders(player, value); + } + + TagManager.getInst().setPrefix(player, value); + if (sender instanceof Player) { + MsgUtils.send(sender, "设置玩家 &f" + args[1] + " &7的前缀为 &f" + value); + } + } + +} diff --git a/src/main/java/me/skymc/taboolib/commands/sub/TagSuffixCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/TagSuffixCommand.java new file mode 100644 index 0000000..2b141ad --- /dev/null +++ b/src/main/java/me/skymc/taboolib/commands/sub/TagSuffixCommand.java @@ -0,0 +1,46 @@ +package me.skymc.taboolib.commands.sub; + +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import me.clip.placeholderapi.PlaceholderAPI; +import me.skymc.taboolib.commands.SubCommand; +import me.skymc.taboolib.message.MsgUtils; +import me.skymc.taboolib.team.TagManager; + +/** + * @author sky + * @since 2018-03-19 23:13:35 + */ +public class TagSuffixCommand extends SubCommand { + + /** + * @param sender + * @param args + */ + public TagSuffixCommand(CommandSender sender, String[] args) { + super(sender, args); + if (args.length < 3) { + MsgUtils.send(sender, "参数错误"); + return; + } + + Player player = Bukkit.getPlayerExact(args[1]); + if (player == null) { + MsgUtils.send(sender, "玩家 &f" + args[1] + " &7不在线"); + return; + } + + String value = getArgs(2).replace("&", "§"); + if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { + value = PlaceholderAPI.setPlaceholders(player, value); + } + + TagManager.getInst().setSuffix(player, value); + if (sender instanceof Player) { + MsgUtils.send(sender, "设置玩家 &f" + args[1] + " &7的后缀为 &f" + value); + } + } + +} diff --git a/src/main/java/me/skymc/taboolib/team/TagManager.java b/src/main/java/me/skymc/taboolib/team/TagManager.java index 79b5958..366fc81 100644 --- a/src/main/java/me/skymc/taboolib/team/TagManager.java +++ b/src/main/java/me/skymc/taboolib/team/TagManager.java @@ -96,6 +96,24 @@ public class TagManager implements Listener { return data; } + /** + * 删除该玩家的称号数据 + * + * @param player + */ + public void removeData(Player player) { + playerdata.remove(player.getName()); + for (Player _player : Bukkit.getOnlinePlayers()) { + Scoreboard scoreboard = _player.getScoreboard(); + if (scoreboard != null) { + Team team = scoreboard.getTeam(player.getName()); + if (team != null) { + team.unregister(); + } + } + } + } + /** * 将该玩家的数据向服务器所有玩家更新 * @@ -162,7 +180,7 @@ public class TagManager implements Listener { @EventHandler public void onQuit(PlayerQuitEvent e) { - playerdata.remove(e.getPlayer().getName()); + removeData(e.getPlayer()); } static class PlayerData {