From 681a65230b23f4b890d50d38c09dc32bef6fab0a Mon Sep 17 00:00:00 2001 From: Yurinann <1713574450@qq.com> Date: Thu, 23 Feb 2023 00:50:58 +0800 Subject: [PATCH] =?UTF-8?q?fix(version):=20=E9=80=82=E9=85=8D=201.10-=20?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E7=9A=84=E6=B6=88=E6=81=AF=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E5=8F=91=E9=80=81=20(#6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit feat(command): 添加了指令权限判断与重载时的奖励数量反馈 --- README.md | 2 +- .../java/cc/carm/plugin/timereward/Main.java | 2 +- .../timereward/command/TimeRewardCommand.java | 5 +-- .../timereward/conf/PluginMessages.java | 32 ++++++++----------- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 8b7e700..198168c 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ @ 管理指令 (TimeReward.admin) - 查看用户的在线时长信息与奖励领取情况。 -# list +# list @ 管理指令 (TimeReward.admin) - 列出所有奖励与条件。 diff --git a/src/main/java/cc/carm/plugin/timereward/Main.java b/src/main/java/cc/carm/plugin/timereward/Main.java index a611672..d7bb52c 100644 --- a/src/main/java/cc/carm/plugin/timereward/Main.java +++ b/src/main/java/cc/carm/plugin/timereward/Main.java @@ -61,7 +61,7 @@ protected boolean initialize() { log("加载奖励管理器..."); this.rewardManager = new RewardManager(this); - debug("加载了 " + this.rewardManager.listRewards().size() + " 个奖励配置。"); + log("成功加载了 " + this.rewardManager.listRewards().size() + " 个奖励配置。"); log("注册监听器..."); registerListener(new UserListener()); diff --git a/src/main/java/cc/carm/plugin/timereward/command/TimeRewardCommand.java b/src/main/java/cc/carm/plugin/timereward/command/TimeRewardCommand.java index 460743b..a391534 100644 --- a/src/main/java/cc/carm/plugin/timereward/command/TimeRewardCommand.java +++ b/src/main/java/cc/carm/plugin/timereward/command/TimeRewardCommand.java @@ -30,9 +30,10 @@ private boolean help(CommandSender sender) { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) { + if (sender instanceof Player && !sender.hasPermission("TimeReward.admin")) PluginMessages.NO_PERMISSION.send(sender); if (args.length < 1) return help(sender); - String aim = args[0]; + String aim = args[0]; if (aim.equalsIgnoreCase("reload")) { long s1 = System.currentTimeMillis(); PluginMessages.RELOAD.START.send(sender); @@ -41,7 +42,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command Main.getInstance().getConfigProvider().reload(); Main.getInstance().getMessageProvider().reload(); - PluginMessages.RELOAD.COMPLETE.send(sender, System.currentTimeMillis() - s1); + PluginMessages.RELOAD.COMPLETE.send(sender, System.currentTimeMillis() - s1, TimeRewardAPI.getRewardManager().listRewards().size()); } catch (Exception e) { PluginMessages.RELOAD.ERROR.send(sender); e.printStackTrace(); diff --git a/src/main/java/cc/carm/plugin/timereward/conf/PluginMessages.java b/src/main/java/cc/carm/plugin/timereward/conf/PluginMessages.java index b2be171..c0a99a5 100644 --- a/src/main/java/cc/carm/plugin/timereward/conf/PluginMessages.java +++ b/src/main/java/cc/carm/plugin/timereward/conf/PluginMessages.java @@ -4,15 +4,13 @@ import cc.carm.lib.configuration.core.annotation.HeaderComment; import cc.carm.lib.easyplugin.utils.ColorParser; import cc.carm.lib.mineconfiguration.bukkit.builder.message.CraftMessageListBuilder; -import cc.carm.lib.mineconfiguration.bukkit.builder.message.CraftMessageValueBuilder; -import cc.carm.lib.mineconfiguration.bukkit.builder.title.TitleConfigBuilder; -import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredMessage; import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredMessageList; -import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredTitle; import de.themoep.minedown.MineDown; import me.clip.placeholderapi.PlaceholderAPI; import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -22,23 +20,21 @@ @HeaderComment({ "TimeReward 在线奖励插件的消息配置文件", "如特定的消息不需要任何提示,可直接留下单行空内容消息。", - "支持 支持 &+颜色代码(原版颜色)、§(#XXXXXX)(RGB颜色) 与 &<#XXXXXX>(前后标注RGB颜色渐变)。", + "支持 &+颜色代码(原版颜色)、&(#XXXXXX)(RGB颜色) 与 &<#XXXXXX>(前后标注RGB颜色渐变)。", " " }) public class PluginMessages extends ConfigurationRoot { public static @NotNull CraftMessageListBuilder list() { return ConfiguredMessageList.create(getParser()) - .whenSend((sender, message) -> message.forEach(m -> sender.spigot().sendMessage(m))); - } - - public static @NotNull CraftMessageValueBuilder value() { - return ConfiguredMessage.create(getParser()) - .whenSend((sender, message) -> sender.spigot().sendMessage(message)); - } - - public static @NotNull TitleConfigBuilder title() { - return ConfiguredTitle.create().whenSend((player, in, stay, out, line1, line2) -> player.sendTitle(line1, line2, in, stay, out)); + .whenSend((sender, message) -> { + if (sender instanceof ConsoleCommandSender) { + message.forEach(m -> sender.sendMessage(TextComponent.toLegacyText(m))); + return; + } + Player player = (Player) sender; + message.forEach(m -> player.spigot().sendMessage(m)); + }); } public static @NotNull BiFunction getParser() { @@ -79,7 +75,7 @@ public class PluginMessages extends ConfigurationRoot { "&8-&7 重载插件配置文件。", "&8#&f user &6<玩家>", "&8-&7 查看用户的在线时长信息与奖励领取情况。", - "&8#&f listUserData", + "&8#&f list", "&8-&7 列出所有奖励与条件。", "&8#&f test &6<奖励ID>", "&8-&7 测试执行奖励配置的指令。" @@ -118,8 +114,8 @@ public static class RELOAD extends ConfigurationRoot { ).build(); public static final ConfiguredMessageList COMPLETE = list().defaults( - "&f配置文件重载完成,共耗时 &d%(time)&fms 。" - ).params("time").build(); + "&f配置文件重载完成!耗时 &d%(time)&fms,共加载了 &d(count) &f个奖励配置。" + ).params("time", "count").build(); }