Trace Refactor #233
@ -17,7 +17,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.tracer2;
|
||||
package de.steamwar.bausystem.features.tracer;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
|
@ -17,7 +17,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.tracer2;
|
||||
package de.steamwar.bausystem.features.tracer;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Location;
|
@ -17,13 +17,15 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.tracer2;
|
||||
package de.steamwar.bausystem.features.tracer;
|
||||
|
||||
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
|
||||
import de.steamwar.bausystem.features.tracer.rendering.BundleFilter;
|
||||
import de.steamwar.bausystem.features.tracer.rendering.TraceEntity;
|
||||
import de.steamwar.bausystem.features.tracer.rendering.ViewFlag;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
@ -65,7 +67,7 @@ public class Trace {
|
||||
/**
|
||||
* A map saving the view flags for rendered traces, for life rendering
|
||||
*/
|
||||
private final Map<Player, Collection<ViewFlag>> viewFlagMap = new HashMap<>();
|
||||
private final Map<Player, ViewFlag[]> viewFlagMap = new HashMap<>();
|
||||
|
||||
public Trace (Region region){
|
||||
this.region = region;
|
||||
@ -85,7 +87,7 @@ public class Trace {
|
||||
for(Player player: serverMap.keySet()){
|
||||
REntityServer server = serverMap.get(player);
|
||||
BundleFilter bundleFilter = bundleFilterMap.get(player);
|
||||
Collection<ViewFlag> viewFlags = viewFlagMap.get(player);
|
||||
ViewFlag[] viewFlags = viewFlagMap.get(player);
|
||||
|
||||
render(server, newRecords, viewFlags, bundleFilter);
|
||||
}
|
||||
@ -107,7 +109,7 @@ public class Trace {
|
||||
* @param flags Flags modefieing the rendering
|
||||
* @param bundleFilter Filter to determin bundeling of records
|
||||
*/
|
||||
public void render(Player player, Collection<ViewFlag> flags, BundleFilter bundleFilter){
|
||||
public void render(Player player, ViewFlag[] flags, BundleFilter bundleFilter){
|
||||
if(serverMap.containsKey(player)){
|
||||
REntityServer server = serverMap.get(player);
|
||||
server.close();
|
||||
@ -134,7 +136,7 @@ public class Trace {
|
||||
* @param flags Flags modefieing the rendering
|
||||
* @param bundleFilter Filter to determin bundeling of records
|
||||
*/
|
||||
private void render (REntityServer server, List<TNTRecord> records, Collection<ViewFlag> flags, BundleFilter bundleFilter){
|
||||
private void render (REntityServer server, List<TNTRecord> records, ViewFlag[] flags, BundleFilter bundleFilter){
|
||||
if(records.size() == 0) return;
|
||||
|
||||
List<TNTRecord> workingRecords = records;
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2022 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
@ -20,225 +20,101 @@
|
||||
package de.steamwar.bausystem.features.tracer;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.features.tracer.record.*;
|
||||
import de.steamwar.bausystem.features.tracer.show.*;
|
||||
import de.steamwar.bausystem.region.GlobalRegion;
|
||||
import de.steamwar.bausystem.features.tracer.rendering.BundleFilter;
|
||||
import de.steamwar.bausystem.features.tracer.rendering.ViewFlag;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.shared.ShowMode;
|
||||
import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar;
|
||||
import de.steamwar.bausystem.utils.bossbar.BossBarService;
|
||||
import de.steamwar.command.PreviousArguments;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.command.TypeMapper;
|
||||
import de.steamwar.command.TypeValidator;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.linkage.LinkedInstance;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.boss.BossBar;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Linked
|
||||
public class TraceCommand extends SWCommand {
|
||||
|
||||
public TraceCommand() {
|
||||
super("trace", "trail");
|
||||
}
|
||||
|
||||
@LinkedInstance
|
||||
public Recorder recorder;
|
||||
@LinkedInstance
|
||||
public TraceManager manager;
|
||||
public TraceCommand(){super("trace", "trail");}
|
||||
|
||||
@Register(value = {"start"}, description = "TRACE_COMMAND_HELP_START")
|
||||
public void startCommand(@Validator Player p) {
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
recorder.set(region, new SimpleTraceRecorder());
|
||||
BauSystem.MESSAGE.send("TRACE_MESSAGE_START", p);
|
||||
@Register(value = "start", description = "TRACE_COMMAND_HELP_START")
|
||||
public void start(Player player){
|
||||
Region region = Region.getRegion(player.getLocation());
|
||||
recorder.startRecording(region);
|
||||
BauSystem.MESSAGE.send("TRACE_MESSAGE_START", player);
|
||||
}
|
||||
|
||||
@Register(value = {"single"}, description = "TRACE_COMMAND_HELP_SINGLE")
|
||||
public void singleCommand(@Validator Player p) {
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
recorder.set(region, new SingleTraceRecorder());
|
||||
BauSystem.MESSAGE.send("TRACE_MESSAGE_SINGLE", p);
|
||||
@Register(value = "stop", description = "TRACE_COMMAND_HELP_STOP")
|
||||
public void stop(Player player){
|
||||
Region region = Region.getRegion(player.getLocation());
|
||||
recorder.stopRecording(region);
|
||||
BauSystem.MESSAGE.send("TRACE_MESSAGE_STOP", player);
|
||||
}
|
||||
|
||||
@Register(value = {"stop"}, description = "TRACE_COMMAND_HELP_STOP")
|
||||
public void stopCommand(@Validator Player p) {
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
recorder.remove(region);
|
||||
BauSystem.MESSAGE.send("TRACE_MESSAGE_STOP", p);
|
||||
@Register(value = "show", description = "TRACE_COMMAND_HELP_SHOW")
|
||||
public void show(Player player, @OptionalValue("STRICT") BundleFilter filter, ViewFlag... flags){
|
||||
Region region = Region.getRegion(player.getLocation());
|
||||
|
||||
for(Trace trace : manager.get(region)){
|
||||
trace.render(player, flags, filter);
|
||||
}
|
||||
|
||||
@Register(value = {"auto"}, description = "TRACE_COMMAND_HELP_AUTO")
|
||||
@Register({"toggleauto"})
|
||||
public void autoCommand(@Validator Player p) {
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
recorder.set(region, new AutoIgniteTraceRecorder());
|
||||
BauSystem.MESSAGE.send("TRACE_MESSAGE_AUTO_IDLE_IGNITE", p);
|
||||
BauSystem.MESSAGE.send("TRACE_MESSAGE_SHOW", player);
|
||||
}
|
||||
|
||||
@Register(value = {"autoremove"}, description = "TRACE_COMMAND_HELP_AUTO_REMOVE")
|
||||
@Register(value = {"autodelete"})
|
||||
public void setAutoDeleteMode(@Validator Player p, @StaticValue({"-always", "-never", "-no_build_destroy", "-build_destroy", "-no_testblock_destroy", "-testblock_destroy"}) String destroyMode) {
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
TraceRecorder recorder = this.recorder.get(region);
|
||||
if (!(recorder instanceof AutoTraceRecorder) || recorder instanceof SingleTraceRecorder) {
|
||||
BauSystem.MESSAGE.send("TRACE_MESSAGE_AUTO_DELETE_INVALID", p);
|
||||
return;
|
||||
}
|
||||
AutoTraceRecorder autoTraceRecorder = (AutoTraceRecorder) recorder;
|
||||
switch (destroyMode) {
|
||||
case "-always":
|
||||
autoTraceRecorder.setTraceRecordAutoDeletion(TraceRecordAutoDeletion.ALWAYS);
|
||||
break;
|
||||
case "-never":
|
||||
autoTraceRecorder.setTraceRecordAutoDeletion(TraceRecordAutoDeletion.NEVER);
|
||||
break;
|
||||
case "-no_build_destroy":
|
||||
autoTraceRecorder.setTraceRecordAutoDeletion(TraceRecordAutoDeletion.NO_BUILD_DESTROY);
|
||||
break;
|
||||
case "-build_destroy":
|
||||
autoTraceRecorder.setTraceRecordAutoDeletion(TraceRecordAutoDeletion.BUILD_DESTROY);
|
||||
break;
|
||||
case "-no_testblock_destroy":
|
||||
autoTraceRecorder.setTraceRecordAutoDeletion(TraceRecordAutoDeletion.NO_TESTBLOCK_DESTROY);
|
||||
break;
|
||||
case "-testblock_destroy":
|
||||
autoTraceRecorder.setTraceRecordAutoDeletion(TraceRecordAutoDeletion.TESTBLOCK_DESTROY);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
BauSystem.MESSAGE.send("TRACE_MESSAGE_AUTO_DELETE_" + autoTraceRecorder.getTraceRecordAutoDeletion().name(), p);
|
||||
}
|
||||
|
||||
@Register(value = {"show"}, description = "TRACE_COMMAND_HELP_SHOW_AT")
|
||||
public void showAtCommand(@Validator Player p, @OptionalValue("time") @StaticValue({"time", "fuse"}) String type, @StaticValue("at") String __, @Min(intValue = 0) int at) {
|
||||
internalSetShowFilter(p, "TRACE_MESSAGE_SHOW_AT", type, at, at);
|
||||
}
|
||||
|
||||
@Register(value = {"show"}, description = "TRACE_COMMAND_HELP_SHOW_FROM")
|
||||
public void showFromCommand(@Validator Player p, @OptionalValue("time") @StaticValue({"time", "fuse"}) String type, @StaticValue("from") String __, @Min(intValue = 0) int from) {
|
||||
if (from == 0) {
|
||||
TraceShowManager.setShowFilter(p, null);
|
||||
BauSystem.MESSAGE.send("TRACE_MESSAGE_SHOW", p);
|
||||
return;
|
||||
}
|
||||
internalSetShowFilter(p, "TRACE_MESSAGE_SHOW_FROM", type, from, Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Register(value = {"show"}, description = "TRACE_COMMAND_HELP_SHOW_FROM_TO")
|
||||
public void showFromToCommand(@Validator Player p, @OptionalValue("time") @StaticValue({"time", "fuse"}) String type, @StaticValue("from") String __, @Min(intValue = 0) int from, @StaticValue("to") String ___, @Min(intValue = 0) int to) {
|
||||
internalSetShowFilter(p, "TRACE_MESSAGE_SHOW_FROM_TO", type, from, to);
|
||||
}
|
||||
|
||||
private void internalSetShowFilter(Player p, String message, String type, int from, int to) {
|
||||
if (to < from) {
|
||||
BauSystem.MESSAGE.send("TRACE_MESSAGE_SHOW_TO_SMALLER", p);
|
||||
return;
|
||||
}
|
||||
TraceShowManager.setShowFilter(p, tntPosition -> {
|
||||
switch (type) {
|
||||
case "time":
|
||||
return tntPosition.getTimeTicks() >= from && tntPosition.getTimeTicks() <= to;
|
||||
case "fuse":
|
||||
return tntPosition.getFuseTicks() >= from && tntPosition.getFuseTicks() <= to;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
});
|
||||
BauSystem.MESSAGE.send(message, p, type, from, to);
|
||||
}
|
||||
|
||||
// /trace show at 0
|
||||
// /trace show raw -auto at 0
|
||||
@Register(value = {"show"}, description = "TRACE_COMMAND_HELP_SHOW")
|
||||
public void showCommand(@Validator Player p, ShowModeParameterType... showModeParameterTypes) {
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
ShowModeParameter showModeParameter = new ShowModeParameter();
|
||||
if (region.getWaterLevel() != 0) { // Enable Water by default for regions with WaterLevel e.g. WarShip
|
||||
showModeParameter.enableWater();
|
||||
}
|
||||
for (ShowModeParameterType showModeParameterType : showModeParameterTypes) {
|
||||
if (showModeParameterType == ShowModeParameterType.WATER && region.getWaterLevel() != 0) {
|
||||
showModeParameter.disableWater();
|
||||
} else {
|
||||
showModeParameterType.getShowModeParameterConsumer().accept(showModeParameter);
|
||||
}
|
||||
}
|
||||
TraceShowManager.show(p, new EntityShowMode(p, showModeParameter, 32));
|
||||
BauSystem.MESSAGE.send("TRACE_MESSAGE_SHOW", p);
|
||||
}
|
||||
|
||||
@Register(value = {"hide"}, description = "TRACE_COMMAND_HELP_HIDE")
|
||||
public void hideCommand(@Validator Player p) {
|
||||
TraceShowManager.hide(p);
|
||||
BauSystem.MESSAGE.send("TRACE_MESSAGE_HIDE", p);
|
||||
}
|
||||
|
||||
@Register(value = {"delete"}, description = "TRACE_COMMAND_HELP_DELETE")
|
||||
@Register({"clear"})
|
||||
public void deleteCommand(@Validator Player p) {
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
StoredRecords.clear(region);
|
||||
BauSystem.MESSAGE.send("TRACE_MESSAGE_DELETE", p);
|
||||
}
|
||||
|
||||
@ClassMapper(value = ShowModeParameterType.class, local = true)
|
||||
public TypeMapper<ShowModeParameterType> showModeParameterTypesTypeMapper() {
|
||||
Map<ShowModeParameterType, List<String>> showModeParameterTypeListMap = new EnumMap<>(ShowModeParameterType.class);
|
||||
for (ShowModeParameterType value : ShowModeParameterType.values()) {
|
||||
showModeParameterTypeListMap.put(value, value.getTabCompletes());
|
||||
}
|
||||
|
||||
Map<String, ShowModeParameterType> showModeParameterTypesMap = new HashMap<>();
|
||||
showModeParameterTypeListMap.forEach((k, v) -> v.forEach(s -> showModeParameterTypesMap.put(s, k)));
|
||||
|
||||
return new TypeMapper<ShowModeParameterType>() {
|
||||
@ClassMapper(value = BundleFilter.class, local = true)
|
||||
public TypeMapper<BundleFilter> bundleFilterClassMapper() {
|
||||
return new TypeMapper<BundleFilter>() {
|
||||
@Override
|
||||
public ShowModeParameterType map(CommandSender commandSender, PreviousArguments previousArguments, String s) {
|
||||
return showModeParameterTypesMap.get(s);
|
||||
public BundleFilter map(CommandSender commandSender, String[] previousArguments, String s) {
|
||||
for(BundleFilter filter: BundleFilter.values()) {
|
||||
if (s.equals(filter.toString()))
|
||||
return filter;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) {
|
||||
Set<ShowModeParameterType> showModeParameterTypeSet = new HashSet<>();
|
||||
Arrays.stream(previousArguments.userArgs).map(showModeParameterTypesMap::get).forEach(showModeParameterTypeSet::add);
|
||||
showModeParameterTypeSet.remove(null);
|
||||
public Collection<String> tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
|
||||
if(s.length() == 0)
|
||||
return new ArrayList<>();
|
||||
|
||||
return Arrays.stream(BundleFilter.values())
|
||||
.map(Enum::toString)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Set<ShowModeParameterType> removed = showModeParameterTypeSet.stream()
|
||||
.map(ShowModeParameterType::getRemoved)
|
||||
.map(Supplier::get)
|
||||
.flatMap(Arrays::stream)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
List<String> tabCompletes = new ArrayList<>();
|
||||
for (Map.Entry<ShowModeParameterType, List<String>> entry : showModeParameterTypeListMap.entrySet()) {
|
||||
if (removed.contains(entry.getKey()) || showModeParameterTypeSet.contains(entry.getKey())) {
|
||||
continue;
|
||||
}
|
||||
tabCompletes.addAll(entry.getValue());
|
||||
}
|
||||
return tabCompletes;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ClassValidator(value = Player.class, local = true)
|
||||
public TypeValidator<Player> validator() {
|
||||
return (commandSender, player, messageSender) -> {
|
||||
if (!Permission.hasPermission(player, Permission.WORLD)) {
|
||||
messageSender.send("TRACE_MESSAGE_DISALLOWED", player);
|
||||
return false;
|
||||
@ClassMapper(value = ViewFlag.class, local = true)
|
||||
public TypeMapper<ViewFlag> viewFlagClassMapper () {
|
||||
return new TypeMapper<ViewFlag>() {
|
||||
@Override
|
||||
public ViewFlag map(CommandSender commandSender, String[] previousArguments, String s) {
|
||||
for(ViewFlag filter: ViewFlag.values()) {
|
||||
if (s.equals("--" + filter.toString().toLowerCase()))
|
||||
return filter;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
|
||||
return Arrays.stream(ViewFlag.values())
|
||||
.map(Enum::toString)
|
||||
.map(string -> "--" + string.toLowerCase())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.tracer2;
|
||||
package de.steamwar.bausystem.features.tracer;
|
||||
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.linkage.Linked;
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2024 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
@ -17,7 +17,9 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.tracer2;
|
||||
package de.steamwar.bausystem.features.tracer.rendering;
|
||||
|
||||
import de.steamwar.bausystem.features.tracer.TNTRecord;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiFunction;
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2024 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
@ -17,8 +17,9 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.tracer2;
|
||||
package de.steamwar.bausystem.features.tracer.rendering;
|
||||
|
||||
import de.steamwar.bausystem.features.tracer.TNTRecord;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import de.steamwar.entity.RFallingBlockEntity;
|
||||
import lombok.Getter;
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2024 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
@ -17,14 +17,15 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.tracer2;
|
||||
package de.steamwar.bausystem.features.tracer.rendering;
|
||||
|
||||
import de.steamwar.bausystem.features.tracer.TNTRecord;
|
||||
import de.steamwar.bausystem.features.tracer.rendering.TraceEntity;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
public enum ViewFlag {
|
In neuem Issue referenzieren
Einen Benutzer sperren