From 81801c5d8a650cb956f961efe9aa43ba2938afc0 Mon Sep 17 00:00:00 2001 From: Blank038 Date: Fri, 1 Dec 2023 23:00:37 +0800 Subject: [PATCH] perf: Optimize code logic for command --- .../servermarket/command/MainCommand.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/blank038/servermarket/command/MainCommand.java b/src/main/java/com/blank038/servermarket/command/MainCommand.java index d85cdc1..8e77342 100644 --- a/src/main/java/com/blank038/servermarket/command/MainCommand.java +++ b/src/main/java/com/blank038/servermarket/command/MainCommand.java @@ -50,7 +50,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St this.searchItemsAndOpenMarket(sender, args); break; case "show": - show(sender); + this.show(sender); break; case "box": if (sender instanceof Player) { @@ -96,9 +96,10 @@ private void searchItemsAndOpenMarket(CommandSender sender, String[] args) { sender.sendMessage(I18n.getStrAndHeader("wrong-key")); return; } - ServerMarket.getApi().openMarket((Player) sender, args[1], 1, new FilterBuilder() + FilterBuilder builder = new FilterBuilder() .addKeyFilter(new KeyFilterImpl(args[2])) - .setTypeFilter(new TypeFilterImpl(Lists.newArrayList("none")))); + .setTypeFilter(new TypeFilterImpl(Lists.newArrayList("none"))); + ServerMarket.getApi().openMarket((Player) sender, args[1], 1, builder); } /** @@ -109,15 +110,16 @@ private void show(CommandSender sender) { String last = line; for (Map.Entry entry : DataContainer.MARKET_DATA.entrySet()) { String value = "%" + entry.getValue().getMarketKey() + "%"; - if (last.contains(value)) { - // 开始设置变量 - String permission = entry.getValue().getPermission(); - if (permission != null && !permission.isEmpty() && !sender.hasPermission(permission)) { - last = last.replace(value, I18n.getOption("status-text.no-permission")); - continue; - } - last = last.replace(value, I18n.getOption("status-text." + entry.getValue().getMarketStatus().name().toLowerCase())); + if (!last.contains(value)) { + continue; + } + // 开始设置变量 + String permission = entry.getValue().getPermission(); + if (permission != null && !permission.isEmpty() && !sender.hasPermission(permission)) { + last = last.replace(value, I18n.getOption("status-text.no-permission")); + continue; } + last = last.replace(value, I18n.getOption("status-text." + entry.getValue().getMarketStatus().name().toLowerCase())); } sender.sendMessage(TextUtil.formatHexColor(last)); }