|
|
|
@ -1,244 +1,120 @@
|
|
|
|
|
/*
|
|
|
|
|
* This file is a part of the SteamWar software.
|
|
|
|
|
* 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
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
* 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
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
|
|
@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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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());
|
|
|
|
|
for(Trace trace : manager.get(region)){
|
|
|
|
|
trace.render(player, flags, filter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map<String, ShowModeParameterType> showModeParameterTypesMap = new HashMap<>();
|
|
|
|
|
showModeParameterTypeListMap.forEach((k, v) -> v.forEach(s -> showModeParameterTypesMap.put(s, k)));
|
|
|
|
|
BauSystem.MESSAGE.send("TRACE_MESSAGE_SHOW", player);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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);
|
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
public BundleFilter map(CommandSender commandSender, String[] previousArguments, String s) {
|
|
|
|
|
for(BundleFilter filter: BundleFilter.values()) {
|
|
|
|
|
if (s.equals(filter.toString()))
|
|
|
|
|
return filter;
|
|
|
|
|
}
|
|
|
|
|
return tabCompletes;
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|