From df00896c93348b30cbcb1f905e431886649a6871 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 27 Dec 2020 14:19:58 +0100 Subject: [PATCH] Optimize TraceEntity_12 Optimize TraceEntity_15 Optimize CommandTraceTabCompleter Optimize Recorder --- .../bausystem/tracer/TraceEntity_12.java | 3 +- .../bausystem/tracer/TraceEntity_15.java | 3 +- .../commands/CommandTraceTabCompleter.java | 59 +++++++++++-------- .../bausystem/tracer/record/Recorder.java | 4 +- .../tracer/show/mode/AdvancedNoWater.java | 1 + .../tracer/show/mode/BasicNoWater.java | 1 + 6 files changed, 40 insertions(+), 31 deletions(-) diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java index 18f3981..292d514 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java @@ -40,9 +40,8 @@ class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity { this.setNoGravity(true); this.ticksLived = -12000; - this.dropItem = false; - this.setCustomNameVisible(true); if (exploded) { + this.setCustomNameVisible(true); this.setCustomName("Bumm"); } diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java index 0c69184..e0aab38 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java @@ -39,9 +39,8 @@ class TraceEntity_15 extends EntityFallingBlock implements AbstractTraceEntity { this.setNoGravity(true); this.ticksLived = -12000; - this.dropItem = false; - this.setCustomNameVisible(true); if (exploded) { + this.setCustomNameVisible(true); this.setCustomName(new ChatComponentText("Bumm")); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java index 3e8279c..16d2970 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java @@ -29,9 +29,19 @@ import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.function.BiPredicate; public class CommandTraceTabCompleter implements TabCompleter { + private static List tabCompletes = new ArrayList<>(); + + static { + tabCompletes.add(new TabComplete((player, args) -> args.length == 1 && (RecordStateMachine.getRecordStatus() == RecordStatus.IDLE || RecordStateMachine.getRecordStatus() == RecordStatus.IDLE_AUTO), "start")); + tabCompletes.add(new TabComplete((player, args) -> args.length == 1 && (RecordStateMachine.getRecordStatus() != RecordStatus.IDLE && RecordStateMachine.getRecordStatus() != RecordStatus.IDLE_AUTO), "stop")); + tabCompletes.add(new TabComplete((player, args) -> args.length == 1, "toggleauto", "auto", "show", "hide", "delete", "clear")); + tabCompletes.add(new TabComplete((player, args) -> args.length == 2 && args[0].equalsIgnoreCase("show"), "nowater", "basic", "advanced", "advanced-nowater")); + } + @Override public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { if(!(sender instanceof Player)) return new ArrayList<>(); @@ -40,36 +50,37 @@ public class CommandTraceTabCompleter implements TabCompleter { private List tracerTabComplete(Player player, String[] args) { List tabComplete = new ArrayList<>(); - if (RecordStateMachine.getRecordStatus() == RecordStatus.IDLE || RecordStateMachine.getRecordStatus() == RecordStatus.IDLE_AUTO) { - tabComplete.add("start"); - } else { - tabComplete.add("stop"); + for (TabComplete tab : tabCompletes) { + if (tab.test(player, args)) tabComplete.addAll(Arrays.asList(tab.getTabCompletes())); } - tabComplete.add("toggleauto"); - tabComplete.add("auto"); - tabComplete.add("show"); - if (args[0].equalsIgnoreCase("show") && args.length == 2) { - return manageList(new ArrayList<>(Arrays.asList("nowater", "basic", "advanced", "advanced-nowater")), args, 1); - } - tabComplete.add("hide"); - tabComplete.add("delete"); - tabComplete.add("clear"); - //tabComplete.add("gui"); - //tabComplete.add("list"); - - if (args.length >= 2) { - return new ArrayList<>(); - } - return manageList(tabComplete, args, 0); + return manageList(tabComplete, args); } - private List manageList(List strings, String[] args, int index) { + private List manageList(List strings, String[] args) { for (int i = strings.size() - 1; i >= 0; i--) { - if (!strings.get(i).startsWith(args[index])) { - strings.remove(i); - } + if (!strings.get(i).startsWith(args[args.length - 1])) strings.remove(i); } return strings; } + private static class TabComplete { + + private BiPredicate function; + private String[] tabCompletes; + + private TabComplete(BiPredicate function, String... tabCompletes) { + this.function = function; + this.tabCompletes = tabCompletes; + } + + public boolean test(Player player, String[] args) { + return function.test(player, args); + } + + public String[] getTabCompletes() { + return tabCompletes; + } + + } + } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java index f682f6a..f330d81 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java @@ -47,9 +47,7 @@ public class Recorder implements Listener { record = new Record(); // To trace TNT initial positions with AutoTracer - if (RecordStateMachine.getRecordStatus() == RecordStatus.IDLE_AUTO) { - run(); - } + run(); } void stopRecording() { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/AdvancedNoWater.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/AdvancedNoWater.java index ce45bf0..afbde3f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/AdvancedNoWater.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/AdvancedNoWater.java @@ -37,6 +37,7 @@ public class AdvancedNoWater extends Advanced { super(player); } + @SuppressWarnings({"java:S5411"}) @Override public void show(TNTPosition position) { if (VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.inWater(world, position.getLocation()), 8), diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicNoWater.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicNoWater.java index 0eb94ce..fc19b8a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicNoWater.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicNoWater.java @@ -37,6 +37,7 @@ public class BasicNoWater extends Basic { super(player); } + @SuppressWarnings({"java:S5411"}) @Override public void show(TNTPosition position) { if (VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.inWater(world, position.getLocation()), 8),