SteamWar/BauSystem2.0
Archiviert
12
0

Moved Classes
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Reimplemented basic command
Dieser Commit ist enthalten in:
D4rkr34lm 2024-02-22 20:29:10 +01:00
Ursprung f62d9e626b
Commit 1644b96886
8 geänderte Dateien mit 97 neuen und 215 gelöschten Zeilen

Datei anzeigen

@ -17,7 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * 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.BauSystem;
import de.steamwar.bausystem.features.tpslimit.TPSUtils; import de.steamwar.bausystem.features.tpslimit.TPSUtils;

Datei anzeigen

@ -17,7 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * 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 lombok.Getter;
import org.bukkit.Location; import org.bukkit.Location;

Datei anzeigen

@ -17,13 +17,15 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * 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.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.bausystem.region.Region;
import de.steamwar.entity.REntityServer; import de.steamwar.entity.REntityServer;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.*; import java.util.*;
@ -65,7 +67,7 @@ public class Trace {
/** /**
* A map saving the view flags for rendered traces, for life rendering * 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){ public Trace (Region region){
this.region = region; this.region = region;
@ -85,7 +87,7 @@ public class Trace {
for(Player player: serverMap.keySet()){ for(Player player: serverMap.keySet()){
REntityServer server = serverMap.get(player); REntityServer server = serverMap.get(player);
BundleFilter bundleFilter = bundleFilterMap.get(player); BundleFilter bundleFilter = bundleFilterMap.get(player);
Collection<ViewFlag> viewFlags = viewFlagMap.get(player); ViewFlag[] viewFlags = viewFlagMap.get(player);
render(server, newRecords, viewFlags, bundleFilter); render(server, newRecords, viewFlags, bundleFilter);
} }
@ -107,7 +109,7 @@ public class Trace {
* @param flags Flags modefieing the rendering * @param flags Flags modefieing the rendering
* @param bundleFilter Filter to determin bundeling of records * @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)){ if(serverMap.containsKey(player)){
REntityServer server = serverMap.get(player); REntityServer server = serverMap.get(player);
server.close(); server.close();
@ -134,7 +136,7 @@ public class Trace {
* @param flags Flags modefieing the rendering * @param flags Flags modefieing the rendering
* @param bundleFilter Filter to determin bundeling of records * @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; if(records.size() == 0) return;
List<TNTRecord> workingRecords = records; List<TNTRecord> workingRecords = records;

Datei anzeigen

@ -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 * 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 * 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 * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * 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/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.bausystem.features.tracer; package de.steamwar.bausystem.features.tracer;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.features.tracer.rendering.BundleFilter;
import de.steamwar.bausystem.features.tracer.record.*; import de.steamwar.bausystem.features.tracer.rendering.ViewFlag;
import de.steamwar.bausystem.features.tracer.show.*;
import de.steamwar.bausystem.region.GlobalRegion;
import de.steamwar.bausystem.region.Region; 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.PreviousArguments;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeMapper;
import de.steamwar.command.TypeValidator;
import de.steamwar.linkage.Linked; import de.steamwar.linkage.Linked;
import de.steamwar.linkage.LinkedInstance; 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.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.*; import java.util.ArrayList;
import java.util.function.BiFunction; import java.util.Arrays;
import java.util.function.Supplier; import java.util.Collection;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Linked @Linked
public class TraceCommand extends SWCommand { public class TraceCommand extends SWCommand {
public TraceCommand() {
super("trace", "trail");
}
@LinkedInstance @LinkedInstance
public Recorder recorder; public Recorder recorder;
@LinkedInstance
public TraceManager manager;
public TraceCommand(){super("trace", "trail");}
@Register(value = {"start"}, description = "TRACE_COMMAND_HELP_START") @Register(value = "start", description = "TRACE_COMMAND_HELP_START")
public void startCommand(@Validator Player p) { public void start(Player player){
Region region = Region.getRegion(p.getLocation()); Region region = Region.getRegion(player.getLocation());
recorder.set(region, new SimpleTraceRecorder()); recorder.startRecording(region);
BauSystem.MESSAGE.send("TRACE_MESSAGE_START", p); BauSystem.MESSAGE.send("TRACE_MESSAGE_START", player);
} }
@Register(value = {"single"}, description = "TRACE_COMMAND_HELP_SINGLE") @Register(value = "stop", description = "TRACE_COMMAND_HELP_STOP")
public void singleCommand(@Validator Player p) { public void stop(Player player){
Region region = Region.getRegion(p.getLocation()); Region region = Region.getRegion(player.getLocation());
recorder.set(region, new SingleTraceRecorder()); recorder.stopRecording(region);
BauSystem.MESSAGE.send("TRACE_MESSAGE_SINGLE", p); BauSystem.MESSAGE.send("TRACE_MESSAGE_STOP", player);
} }
@Register(value = {"stop"}, description = "TRACE_COMMAND_HELP_STOP") @Register(value = "show", description = "TRACE_COMMAND_HELP_SHOW")
public void stopCommand(@Validator Player p) { public void show(Player player, @OptionalValue("STRICT") BundleFilter filter, ViewFlag... flags){
Region region = Region.getRegion(p.getLocation()); Region region = Region.getRegion(player.getLocation());
recorder.remove(region);
BauSystem.MESSAGE.send("TRACE_MESSAGE_STOP", p);
}
@Register(value = {"auto"}, description = "TRACE_COMMAND_HELP_AUTO") for(Trace trace : manager.get(region)){
@Register({"toggleauto"}) trace.render(player, flags, filter);
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());
} }
Map<String, ShowModeParameterType> showModeParameterTypesMap = new HashMap<>(); BauSystem.MESSAGE.send("TRACE_MESSAGE_SHOW", player);
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 @Override
public ShowModeParameterType map(CommandSender commandSender, PreviousArguments previousArguments, String s) { public BundleFilter map(CommandSender commandSender, String[] previousArguments, String s) {
return showModeParameterTypesMap.get(s); for(BundleFilter filter: BundleFilter.values()) {
} if (s.equals(filter.toString()))
return filter;
@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());
} }
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) @ClassMapper(value = ViewFlag.class, local = true)
public TypeValidator<Player> validator() { public TypeMapper<ViewFlag> viewFlagClassMapper () {
return (commandSender, player, messageSender) -> { return new TypeMapper<ViewFlag>() {
if (!Permission.hasPermission(player, Permission.WORLD)) { @Override
messageSender.send("TRACE_MESSAGE_DISALLOWED", player); public ViewFlag map(CommandSender commandSender, String[] previousArguments, String s) {
return false; 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;
}; };
} }
} }

Datei anzeigen

@ -17,7 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * 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.bausystem.region.Region;
import de.steamwar.linkage.Linked; import de.steamwar.linkage.Linked;

Datei anzeigen

@ -1,7 +1,7 @@
/* /*
* This file is a part of the SteamWar software. * 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 * 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 * 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/>. * 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.Optional;
import java.util.function.BiFunction; import java.util.function.BiFunction;

Datei anzeigen

@ -1,7 +1,7 @@
/* /*
* This file is a part of the SteamWar software. * 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 * 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 * 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/>. * 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.REntityServer;
import de.steamwar.entity.RFallingBlockEntity; import de.steamwar.entity.RFallingBlockEntity;
import lombok.Getter; import lombok.Getter;

Datei anzeigen

@ -1,7 +1,7 @@
/* /*
* This file is a part of the SteamWar software. * 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 * 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 * 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/>. * 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 de.steamwar.entity.REntityServer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.UnaryOperator; import java.util.function.UnaryOperator;
public enum ViewFlag { public enum ViewFlag {