SteamWar/BauSystem2.0
Archiviert
12
0

Add TraceCommand.isolate

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2022-10-03 18:06:26 +02:00
Ursprung ad8cd86338
Commit f438b4aa77
6 geänderte Dateien mit 89 neuen und 14 gelöschten Zeilen

Datei anzeigen

@ -23,6 +23,7 @@ import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.features.tracer.gui.TraceGui;
import de.steamwar.bausystem.features.tracer.record.*;
import de.steamwar.bausystem.features.tracer.show.Record;
import de.steamwar.bausystem.features.tracer.show.ShowModeParameter;
import de.steamwar.bausystem.features.tracer.show.ShowModeParameterType;
import de.steamwar.bausystem.features.tracer.show.StoredRecords;
@ -107,6 +108,7 @@ public class TraceCommand extends SWCommand {
@Register(value = {"hide"}, description = "TRACE_COMMAND_HELP_HIDE")
public void hideCommand(@Validator Player p) {
TraceShowManager.hide(p);
StoredRecords.hideIsolated(Region.getRegion(p.getLocation()), p);
BauSystem.MESSAGE.send("TRACE_MESSAGE_HIDE", p);
}
@ -115,6 +117,7 @@ public class TraceCommand extends SWCommand {
public void deleteCommand(@Validator Player p) {
Region region = Region.getRegion(p.getLocation());
StoredRecords.clear(region);
StoredRecords.hideIsolated(region);
BauSystem.MESSAGE.send("TRACE_MESSAGE_DELETE", p);
}
@ -123,6 +126,17 @@ public class TraceCommand extends SWCommand {
TraceGui.openGui(p);
}
@Register(value = "isolate", noTabComplete = true)
public void isolate(Player p, String s) {
try {
UUID uuid = UUID.fromString(s);
Record.TNTRecord tntRecord = StoredRecords.getRecord(uuid);
StoredRecords.toggleIsolate(p, tntRecord);
} catch (Exception e) {
// Ignore
}
}
@AllArgsConstructor
private enum ShowModeType {
ENTITY(TraceEntityShowMode::new, new ShowModeParameterType[]{}),

Datei anzeigen

@ -26,6 +26,7 @@ import de.steamwar.bausystem.features.tracer.show.TraceShowManager;
import de.steamwar.bausystem.utils.RayTraceUtils;
import de.steamwar.linkage.Linked;
import de.steamwar.linkage.api.Plain;
import net.md_5.bungee.api.chat.ClickEvent;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.util.RayTraceResult;
@ -58,7 +59,7 @@ public class TraceTNTClickListener implements Plain {
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_VELOCITY_X", player, tntPosition.getVelocity().getX() + "");
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_VELOCITY_Y", player, tntPosition.getVelocity().getY() + "");
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_VELOCITY_Z", player, tntPosition.getVelocity().getZ() + "");
// BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_ISOLATE", player, BauSystem.MESSAGE.parse("TRACE_MESSAGE_CLICK_ISOLATE", player), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/trace isolate " + tntPosition.getRecord().getId()));
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_ISOLATE", player, BauSystem.MESSAGE.parse("TRACE_MESSAGE_CLICK_ISOLATE", player), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/trace isolate " + tntPosition.getRecord().getId()));
}, 1);
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
playerSet.remove(player);

Datei anzeigen

@ -62,23 +62,17 @@ public class TraceGui {
Region region = Region.getRegion(player.getLocation());
List<SWListInv.SWListEntry<Record.TNTRecord>> recordList = new ArrayList<>();
record.getTnt().forEach(tntRecord -> {
SWItem swItem = new SWItem(Material.TNT_MINECART, BauSystem.MESSAGE.parse("TRACE_GUI_RECORD_ITEM", player, tntRecord.getPositions().size()), new ArrayList<>(), false, clickType -> {
SWItem swItem = new SWItem(Material.TNT_MINECART, BauSystem.MESSAGE.parse("TRACE_GUI_RECORD_ITEM", player, tntRecord.getPositions().size()), new ArrayList<>(), StoredRecords.isIsolated(player, tntRecord), clickType -> {
});
recordList.add(new SWListInv.SWListEntry<>(swItem, tntRecord));
});
SWListInv<Record.TNTRecord> tntRecordSWListInv = new SWListInv<>(player, BauSystem.MESSAGE.parse("TRACE_GUI_TITLE", player), false, recordList, (clickType, tntRecord) -> {
/*
if (clickType.isShiftClick()) {
if (TraceShowManager.isIsolated(player, tntRecord)) {
TraceShowManager.unisolate(player, tntRecord);
} else {
TraceShowManager.isolate(player, tntRecord);
}
StoredRecords.toggleIsolate(player, tntRecord);
openRecordGui(player, record);
} else {
openTntGui(player, record, tntRecord);
}
*/
openTntGui(player, record, tntRecord);
});
tntRecordSWListInv.setItem(48, new SWItem(Material.BUCKET, BauSystem.MESSAGE.parse("TRACE_GUI_RECORD_CLEAR", player), clickType -> {
StoredRecords.remove(region, record);

Datei anzeigen

@ -29,6 +29,7 @@ import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@RequiredArgsConstructor
public class Record {
@ -57,9 +58,15 @@ public class Record {
public static class TNTRecord {
@Getter
private final UUID id = UUID.randomUUID();
@Getter
private final long offset;
@Getter
private final Region region;
@Getter
private final List<TNTPosition> positions = new ArrayList<>(82);

Datei anzeigen

@ -24,6 +24,7 @@ import de.steamwar.bausystem.features.tracer.record.Recorder;
import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.shared.ShowMode;
import lombok.experimental.UtilityClass;
import org.bukkit.entity.Player;
import java.util.*;
import java.util.stream.Collectors;
@ -31,6 +32,7 @@ import java.util.stream.Collectors;
@UtilityClass
public class StoredRecords {
private static final Map<Region, Map<Player, List<Record.TNTRecord>>> isolatedTNT = new HashMap<>();
private static final Map<Region, List<Record>> records = new HashMap<>();
public static void add(Region region, Record record) {
@ -57,7 +59,51 @@ public class StoredRecords {
return records.getOrDefault(region, Collections.emptyList());
}
static void show(Region region, ShowMode<TNTPosition> traceShowMode) {
records.getOrDefault(region, new ArrayList<>()).forEach(record -> record.showAll(traceShowMode));
public Record.TNTRecord getRecord(UUID id) {
return records.values().stream()
.flatMap(Collection::stream)
.map(Record::getTnt)
.flatMap(Collection::stream)
.filter(tntRecord -> tntRecord.getId().equals(id))
.findFirst()
.orElse(null);
}
public static boolean isIsolated(Player p, Record.TNTRecord tntRecord) {
return isolatedTNT.values()
.stream()
.filter(map -> map.containsKey(p))
.anyMatch(map -> map.get(p).contains(tntRecord));
}
public static void toggleIsolate(Player p, Record.TNTRecord tntRecord) {
List<Record.TNTRecord> tntRecords = isolatedTNT.computeIfAbsent(tntRecord.getRegion(), k -> new HashMap<>())
.computeIfAbsent(p, k -> new ArrayList<>());
if (tntRecords.contains(tntRecord)) {
tntRecords.remove(tntRecord);
} else {
tntRecords.add(tntRecord);
}
TraceShowManager.reshow(tntRecord.getRegion(), p);
}
public static void hideIsolated(Region region) {
isolatedTNT.remove(region);
}
public static void hideIsolated(Region region, Player player) {
Map<Player, List<Record.TNTRecord>> regionalIsolatedTNT = isolatedTNT.get(region);
if (regionalIsolatedTNT == null) {
return;
}
regionalIsolatedTNT.remove(player);
}
static void show(Region region, Player player, ShowMode<TNTPosition> traceShowMode) {
if (isolatedTNT.containsKey(region) && isolatedTNT.get(region).containsKey(player)) {
isolatedTNT.get(region).get(player).forEach(record -> record.getPositions().forEach(traceShowMode::show));
} else {
records.getOrDefault(region, new ArrayList<>()).forEach(record -> record.showAll(traceShowMode));
}
}
}

Datei anzeigen

@ -50,7 +50,7 @@ public class TraceShowManager implements Listener {
}
Map<Player, ShowMode<TNTPosition>> regionalShowModes = showModes.computeIfAbsent(region, __ -> new HashMap<>());
regionalShowModes.put(player, traceShowMode);
StoredRecords.show(region, traceShowMode);
StoredRecords.show(region, player, traceShowMode);
}
public static void hide(Player player) {
@ -107,6 +107,19 @@ public class TraceShowManager implements Listener {
return null;
}
public static void reshow(Region region, Player p) {
Map<Player, ShowMode<TNTPosition>> regionalShowModes = showModes.get(region);
if (regionalShowModes == null) {
return;
}
ShowMode<TNTPosition> showMode = regionalShowModes.get(p);
if (showMode == null) {
return;
}
showMode.hide();
StoredRecords.show(region, p, showMode);
}
public static void reshow(Region region) {
Map<Player, ShowMode<TNTPosition>> regionalShowModes = showModes.get(region);
if (regionalShowModes == null) {
@ -114,7 +127,7 @@ public class TraceShowManager implements Listener {
}
for (Map.Entry<Player, ShowMode<TNTPosition>> entry : regionalShowModes.entrySet()) {
entry.getValue().hide();
StoredRecords.show(region, entry.getValue());
StoredRecords.show(region, entry.getKey(), entry.getValue());
}
}