SteamWar/BauSystem
Archiviert
13
0

Optimize TraceEntity_12

Optimize TraceEntity_15
Optimize CommandTraceTabCompleter
Optimize Recorder
Dieser Commit ist enthalten in:
jojo 2020-12-27 14:19:58 +01:00
Ursprung 6b23f88ea0
Commit df00896c93
6 geänderte Dateien mit 40 neuen und 31 gelöschten Zeilen

Datei anzeigen

@ -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");
}

Datei anzeigen

@ -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"));
}

Datei anzeigen

@ -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<TabComplete> 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<String> 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<String> tracerTabComplete(Player player, String[] args) {
List<String> 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<String> manageList(List<String> strings, String[] args, int index) {
private List<String> manageList(List<String> 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<Player, String[]> function;
private String[] tabCompletes;
private TabComplete(BiPredicate<Player, String[]> 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;
}
}
}

Datei anzeigen

@ -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() {

Datei anzeigen

@ -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),

Datei anzeigen

@ -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),