From de2bb73444ef9c92d1710cb64fcb015645369143 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 17 Apr 2021 22:27:28 +0200 Subject: [PATCH] Add TraceCommand Add everything for TraceCommand --- .../features/tracer/TNTTracer_15.java | 59 ++++++++ .../features/tracer/TraceEntity_15.java | 80 +++++++++++ .../features/tracer/AbstractTraceEntity.java | 34 +++++ .../features/tracer/RoundedTNTPosition.java | 65 +++++++++ .../features/tracer/TNTPosition.java | 63 +++++++++ .../features/tracer/TraceCommand.java | 133 ++++++++++++++++++ .../features/{other => tracer/gui}/.gitkeep | 0 .../tracer/record/RecordStateMachine.java | 94 +++++++++++++ .../features/tracer/record/RecordStatus.java | 55 ++++++++ .../features/tracer/record/Recorder.java | 96 +++++++++++++ .../tracer/record/TraceAutoHandler.java | 70 +++++++++ .../features/tracer/show/Record.java | 94 +++++++++++++ .../features/tracer/show/ShowMode.java | 28 ++++ .../tracer/show/ShowModeParameter.java | 57 ++++++++ .../tracer/show/ShowModeParameterType.java | 44 ++++++ .../features/tracer/show/StoredRecords.java | 45 ++++++ .../tracer/show/TraceShowManager.java | 59 ++++++++ .../tracer/show/mode/EntityShowMode.java | 120 ++++++++++++++++ .../steamwar/bausystem/features/util/.gitkeep | 0 19 files changed, 1196 insertions(+) create mode 100644 BauSystem_15/src/de/steamwar/bausystem/features/tracer/TNTTracer_15.java create mode 100644 BauSystem_15/src/de/steamwar/bausystem/features/tracer/TraceEntity_15.java create mode 100644 BauSystem_API/src/de/steamwar/bausystem/features/tracer/AbstractTraceEntity.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer/RoundedTNTPosition.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TNTPosition.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java rename BauSystem_Main/src/de/steamwar/bausystem/features/{other => tracer/gui}/.gitkeep (100%) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/RecordStateMachine.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/RecordStatus.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TraceAutoHandler.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/Record.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowMode.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameter.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameterType.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/StoredRecords.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/TraceShowManager.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/EntityShowMode.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/util/.gitkeep diff --git a/BauSystem_15/src/de/steamwar/bausystem/features/tracer/TNTTracer_15.java b/BauSystem_15/src/de/steamwar/bausystem/features/tracer/TNTTracer_15.java new file mode 100644 index 00000000..ae87e5a3 --- /dev/null +++ b/BauSystem_15/src/de/steamwar/bausystem/features/tracer/TNTTracer_15.java @@ -0,0 +1,59 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 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 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 . +*/ + +package de.steamwar.bausystem.features.tracer; + +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.Waterlogged; +import org.bukkit.util.Vector; + +public class TNTTracer_15 { + + public static AbstractTraceEntity create(World world, Vector tntPosition, boolean tnt) { + return new TraceEntity_15(world, tntPosition, tnt); + } + + public static boolean inWater(World world, Vector tntPosition) { + Block block = world.getBlockAt(tntPosition.getBlockX(), tntPosition.getBlockY(), tntPosition.getBlockZ()); + if (block.getType() == Material.WATER) + return true; + + BlockData data = block.getBlockData(); + if (!(data instanceof Waterlogged)) + return false; + + return ((Waterlogged) data).isWaterlogged(); + } + + public static Material getTraceShowMaterial() { + return Material.LIME_CONCRETE; + } + + public static Material getTraceHideMaterial() { + return Material.RED_CONCRETE; + } + + public static Material getTraceXZMaterial() { + return Material.QUARTZ_SLAB; + } + +} diff --git a/BauSystem_15/src/de/steamwar/bausystem/features/tracer/TraceEntity_15.java b/BauSystem_15/src/de/steamwar/bausystem/features/tracer/TraceEntity_15.java new file mode 100644 index 00000000..80f1bc46 --- /dev/null +++ b/BauSystem_15/src/de/steamwar/bausystem/features/tracer/TraceEntity_15.java @@ -0,0 +1,80 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 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 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 . +*/ + +package de.steamwar.bausystem.features.tracer; + +import net.minecraft.server.v1_15_R1.*; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +class TraceEntity_15 extends EntityFallingBlock implements AbstractTraceEntity { + + private static final Vec3D ZERO = new Vec3D(0, 0, 0); + private final Vector position; + private final boolean tnt; + + private boolean exploded = false; + private int references = 0; + + public TraceEntity_15(World world, Vector position, boolean tnt) { + super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), tnt ? Blocks.TNT.getBlockData() : Blocks.WHITE_STAINED_GLASS.getBlockData()); + this.position = position; + this.tnt = tnt; + + this.setNoGravity(true); + this.ticksLived = -12000; + } + + @Override + public void display(Player player, boolean exploded) { + if (!this.exploded && exploded) { + this.setCustomNameVisible(true); + this.setCustomName(new ChatComponentText("Bumm")); + this.exploded = true; + if (references++ > 0) + sendDestroy(player); + } else if (references++ > 0) + return; + + PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(getId(), getUniqueID(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.FALLING_BLOCK, tnt ? Block.getCombinedId(Blocks.TNT.getBlockData()) : Block.getCombinedId(Blocks.WHITE_STAINED_GLASS.getBlockData()), ZERO); + PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; + playerConnection.sendPacket(packetPlayOutSpawnEntity); + + PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); + playerConnection.sendPacket(packetPlayOutEntityMetadata); + } + + @Override + public boolean hide(Player player, boolean force) { + if (!force && --references > 0) + return false; + + sendDestroy(player); + die(); + return true; + } + + private void sendDestroy(Player player) { + PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(getId()); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityDestroy); + } +} diff --git a/BauSystem_API/src/de/steamwar/bausystem/features/tracer/AbstractTraceEntity.java b/BauSystem_API/src/de/steamwar/bausystem/features/tracer/AbstractTraceEntity.java new file mode 100644 index 00000000..82f012e9 --- /dev/null +++ b/BauSystem_API/src/de/steamwar/bausystem/features/tracer/AbstractTraceEntity.java @@ -0,0 +1,34 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 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 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 . +*/ + +package de.steamwar.bausystem.features.tracer; + +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + +public interface AbstractTraceEntity { + + void display(Player player, boolean exploded); + + boolean hide(Player player, boolean always); + + int getId(); + + Entity getBukkitEntity(); +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/RoundedTNTPosition.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/RoundedTNTPosition.java new file mode 100644 index 00000000..965448aa --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/RoundedTNTPosition.java @@ -0,0 +1,65 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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 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 . + * / + */ + +package de.steamwar.bausystem.features.tracer; + +import org.bukkit.util.Vector; + +import java.util.Objects; + +public class RoundedTNTPosition { + + private static final int factor = 10; + + private int x; + private int y; + private int z; + + public RoundedTNTPosition(TNTPosition tntPosition) { + this(tntPosition.getLocation().getX(), tntPosition.getLocation().getY(), tntPosition.getLocation().getZ()); + } + + public RoundedTNTPosition(Vector vector) { + this(vector.getX(), vector.getY(), vector.getZ()); + } + + public RoundedTNTPosition(double x, double y, double z) { + this.x = (int) (x * factor); + this.y = (int) (y * factor); + this.z = (int) (z * factor); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof RoundedTNTPosition)) return false; + RoundedTNTPosition that = (RoundedTNTPosition) o; + return x == that.x && + y == that.y && + z == that.z; + } + + @Override + public int hashCode() { + return Objects.hash(x, y, z); + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TNTPosition.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TNTPosition.java new file mode 100644 index 00000000..bc0a85c4 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TNTPosition.java @@ -0,0 +1,63 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 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 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 . +*/ + +package de.steamwar.bausystem.features.tracer; + +import de.steamwar.bausystem.features.tracer.show.Record; +import org.bukkit.entity.Entity; +import org.bukkit.util.Vector; + +public class TNTPosition { + + private final Record.TNTRecord record; + private final Vector location; + private final Vector previousLocation; + private final boolean exploded; + + public TNTPosition(Record.TNTRecord record, Entity entity, Vector previousLocation, boolean exploded) { + this.location = entity.getLocation().toVector(); + this.record = record; + this.previousLocation = previousLocation; + this.exploded = exploded; + } + + public Vector getLocation() { + return location; + } + + public Vector getPreviousLocation() { + return previousLocation; + } + + public boolean isExploded() { + return exploded; + } + + public Record.TNTRecord getRecord() { + return record; + } + + @Override + public String toString() { + return "Position{" + + "location=" + location + + '}'; + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java new file mode 100644 index 00000000..7b1bc961 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java @@ -0,0 +1,133 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 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 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 . +*/ + +package de.steamwar.bausystem.features.tracer; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.features.tracer.record.RecordStateMachine; +import de.steamwar.bausystem.features.tracer.show.ShowModeParameter; +import de.steamwar.bausystem.features.tracer.show.ShowModeParameterType; +import de.steamwar.bausystem.features.tracer.show.StoredRecords; +import de.steamwar.bausystem.features.tracer.show.TraceShowManager; +import de.steamwar.bausystem.features.tracer.show.mode.EntityShowMode; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.command.SWCommand; +import org.bukkit.entity.Player; + +@Linked(LinkageType.COMMAND) +public class TraceCommand extends SWCommand { + + public TraceCommand() { + super("trace", "trail"); + } + + @Register(help = true) + public void genericHelp(Player p, String... args) { + p.sendMessage("§8/§etrace start §8- §7Startet die Aufnahme aller TNT-Positionen"); + p.sendMessage("§8/§etrace stop §8- §7Stoppt den TNT-Tracer"); + p.sendMessage("§8/§etrace toggleauto §8- §7Automatischer Aufnahmenstart"); + // p.sendMessage("§8/§etrace show gui §8- §7Zeigt die Trace show gui"); + p.sendMessage("§8/§etrace show §8<§e-water§8|§e-interpolate-xz§8|§e-interpolate-y§8> §8- §7Zeigt alle TNT-Positionen"); + p.sendMessage("§8/§etrace hide §8- §7Versteckt alle TNT-Positionen"); + p.sendMessage("§8/§etrace delete §8- §7Löscht alle TNT-Positionen"); + // p.sendMessage("§8/§etrace list §8<§7FRAME-ID§8> §8- §7Listet alle TNT auf"); + // p.sendMessage("§8/§etrace gui §8- §7Zeigt die Trace Oberfläche an"); + // p.sendMessage("§7Optionale Parameter mit §8<>§7, Benötigte Parameter mit §8[]"); + } + + @Register({"start"}) + public void startCommand(Player p) { + if (!permissionCheck(p)) return; + RecordStateMachine.commandStart(); + p.sendMessage(BauSystem.PREFIX + "§aTNT-Tracer gestartet"); + } + + @Register({"stop"}) + public void stopCommand(Player p) { + if (!permissionCheck(p)) return; + RecordStateMachine.commandStop(); + p.sendMessage(BauSystem.PREFIX + "§cTNT-Tracer gestoppt"); + } + + @Register({"toggleauto"}) + public void toggleAutoCommand(Player p) { + autoCommand(p); + } + + @Register({"auto"}) + public void autoCommand(Player p) { + if (!permissionCheck(p)) return; + RecordStateMachine.commandAuto(); + p.sendMessage(BauSystem.PREFIX + RecordStateMachine.getRecordStatus().getAutoMessage()); + } + + @Register({"clear"}) + public void clearCommand(Player p) { + deleteCommand(p); + } + + @Register({"delete"}) + public void deleteCommand(Player p) { + if (!permissionCheck(p)) return; + StoredRecords.clear(); + p.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen gelöscht"); + } + + @Register({"show"}) + public void showCommand(Player p) { + if (!permissionCheck(p)) return; + TraceShowManager.show(p, new EntityShowMode(p, new ShowModeParameter())); + p.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen angezeigt"); + } + + @Register({"show"}) + public void showCommand(Player p, ShowModeParameterType... showModeParameterTypes) { + if (!permissionCheck(p)) return; + ShowModeParameter showModeParameter = new ShowModeParameter(); + for (ShowModeParameterType showModeParameterType : showModeParameterTypes) { + showModeParameterType.getShowModeParameterConsumer().accept(showModeParameter); + } + TraceShowManager.show(p, new EntityShowMode(p, showModeParameter)); + p.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen angezeigt"); + } + + @Register({"show", "gui"}) + public void showGuiCommand(Player p) { + if (!permissionCheck(p)) return; + // GuiTraceShow.openGui(p); + } + + @Register({"hide"}) + public void hideCommand(Player p) { + if (!permissionCheck(p)) return; + TraceShowManager.hide(p); + p.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen ausgeblendet"); + } + + + private boolean permissionCheck(Player player) { + if (!Permission.hasPermission(player, Permission.WORLD)) { + player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht den TNT-Tracer nutzen"); + return false; + } + return true; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/other/.gitkeep b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/gui/.gitkeep similarity index 100% rename from BauSystem_Main/src/de/steamwar/bausystem/features/other/.gitkeep rename to BauSystem_Main/src/de/steamwar/bausystem/features/tracer/gui/.gitkeep diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/RecordStateMachine.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/RecordStateMachine.java new file mode 100644 index 00000000..8cb5e245 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/RecordStateMachine.java @@ -0,0 +1,94 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 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 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 . +*/ + +package de.steamwar.bausystem.features.tracer.record; + +public class RecordStateMachine { + private RecordStateMachine() { + } + + private static final TraceAutoHandler autoHandler = new TraceAutoHandler(); + + private static RecordStatus recordStatus = RecordStatus.IDLE; + private static Recorder recorder = null; + + public static void commandStart() { + autoHandler.disable(); + recordStart(); + recordStatus = RecordStatus.RECORD; + } + + public static void commandStop() { + autoHandler.disable(); + recordStop(); + recordStatus = RecordStatus.IDLE; + } + + public static void commandAuto() { + if (recordStatus.isTracing()) + return; + + if (recordStatus == RecordStatus.IDLE_AUTO) { + recordStatus = RecordStatus.IDLE; + autoHandler.disable(); + } else { + recordStatus = RecordStatus.IDLE_AUTO; + autoHandler.enable(); + } + } + + static void autoRecord() { + recordStart(); + recordStatus = RecordStatus.RECORD_AUTO; + } + + static void autoIdle() { + recordStop(); + recordStatus = RecordStatus.IDLE_AUTO; + } + + private static void recordStart() { + if (recordStatus.isTracing()) return; + recorder = new Recorder(); + } + + private static void recordStop() { + if (!recordStatus.isTracing()) return; + recorder.stopRecording(); + } + + public static RecordStatus getRecordStatus() { + return recordStatus; + } + + public static int size() { + if (recorder == null) return 0; + return recorder.size(); + } + + public static long getStartTime() { + if (recorder == null) return 0; + return recorder.getStartTime(); + } + + public static void postClear() { + if (recorder == null) return; + recorder.postClear(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/RecordStatus.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/RecordStatus.java new file mode 100644 index 00000000..07e96f1f --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/RecordStatus.java @@ -0,0 +1,55 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 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 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 . +*/ + +package de.steamwar.bausystem.features.tracer.record; + +public enum RecordStatus { + + RECORD("§aan", true, "§cTNT-Tracer muss gestoppt werden"), + RECORD_AUTO("§aan", true, "§cTNT-Tracer darf nicht aufnehmen"), + IDLE("§caus", false, "§cAuto-Tracer gestoppt"), + IDLE_AUTO("§eauto", false, "§aAuto-Tracer gestartet"); + + String name; + boolean tracing; + String autoMessage; + + RecordStatus(String value, boolean tracing, String autoMessage) { + this.name = value; + this.tracing = tracing; + this.autoMessage = autoMessage; + } + + public String getName() { + return name; + } + + public boolean isTracing() { + return tracing; + } + + public boolean isAutoTrace() { + return this == RECORD_AUTO || this == IDLE_AUTO; + } + + public String getAutoMessage() { + return autoMessage; + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java new file mode 100644 index 00000000..ca49bb9e --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java @@ -0,0 +1,96 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 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 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 . +*/ + +package de.steamwar.bausystem.features.tracer.record; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.tracer.show.Record; +import de.steamwar.bausystem.features.tracer.show.StoredRecords; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.entity.TNTPrimed; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.scheduler.BukkitTask; + +import java.util.HashMap; +import java.util.Map; + +public class Recorder implements Listener { + + private static final World world = Bukkit.getWorlds().get(0); + + private final Map recordMap = new HashMap<>(); + private final BukkitTask task; + private final Record record; + + Recorder() { + Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance()); + task = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), this::run, 1, 1); + record = new Record(); + + // To trace TNT initial positions with AutoTracer + run(); + } + + void stopRecording() { + HandlerList.unregisterAll(this); + task.cancel(); + } + + int size() { + return record.size(); + } + + long getStartTime() { + return record.getStartTime(); + } + + void postClear() { + record.clear(); + recordMap.clear(); + StoredRecords.add(record); + } + + private void run() { + world.getEntitiesByClass(TNTPrimed.class).forEach(tntPrimed -> get(tntPrimed).add(tntPrimed)); + } + + @EventHandler + public void onEntityExplode(EntityExplodeEvent event) { + if (!(event.getEntity() instanceof TNTPrimed)) + return; + TNTPrimed tntPrimed = (TNTPrimed) event.getEntity(); + + get(tntPrimed).explode(tntPrimed); + recordMap.remove(tntPrimed); + } + + private Record.TNTRecord get(TNTPrimed tntPrimed) { + Record.TNTRecord tntRecord = recordMap.get(tntPrimed); + if (tntRecord != null) + return tntRecord; + + tntRecord = this.record.spawn(); + recordMap.put(tntPrimed, tntRecord); + return tntRecord; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TraceAutoHandler.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TraceAutoHandler.java new file mode 100644 index 00000000..f95a75a4 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TraceAutoHandler.java @@ -0,0 +1,70 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 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 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 . +*/ + +package de.steamwar.bausystem.features.tracer.record; + +import de.steamwar.bausystem.BauSystem; +import org.bukkit.Bukkit; +import org.bukkit.entity.TNTPrimed; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.scheduler.BukkitTask; + +public class TraceAutoHandler implements Listener { + /* This listener handles the en- and disabling of the Tracer in AUTO mode */ + + private BukkitTask task; + private int lastExplosion = 0; // Time since the last explosion in ticks + + public void enable() { + Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance()); + } + + public void disable() { + HandlerList.unregisterAll(this); + if (task != null) { + task.cancel(); + task = null; + } + } + + @EventHandler + public void onEntityExplode(EntityExplodeEvent event) { + if (!(event.getEntity() instanceof TNTPrimed)) + return; + + lastExplosion = 0; + if (task == null) { + RecordStateMachine.autoRecord(); + task = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), this::run, 1, 1); + } + } + + private void run() { + lastExplosion++; + + if (lastExplosion > 80) { + RecordStateMachine.autoIdle(); + task.cancel(); + task = null; + } + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/Record.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/Record.java new file mode 100644 index 00000000..3fdca202 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/Record.java @@ -0,0 +1,94 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 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 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 . +*/ + +package de.steamwar.bausystem.features.tracer.show; + +import de.steamwar.bausystem.features.tracer.TNTPosition; +import org.bukkit.entity.TNTPrimed; + +import java.util.ArrayList; +import java.util.List; + +public class Record { + + private final long startTime; + private final List tnt = new ArrayList<>(); + + public int size() { + return tnt.size(); + } + + public long getStartTime() { + return startTime; + } + + public void showAll(ShowMode mode) { + for (TNTRecord record : tnt) + record.showAll(mode); + } + + /* The following methods should only be called by a recorder */ + public Record() { + startTime = System.currentTimeMillis(); + StoredRecords.add(this); + } + + public TNTRecord spawn() { + TNTRecord record = new TNTRecord(); + tnt.add(record); + return record; + } + + public void clear() { + tnt.clear(); + } + + public static class TNTRecord { + private final List positions = new ArrayList<>(41); + + public void showAll(ShowMode mode) { + for (TNTPosition position : positions) + mode.show(position); + } + + /* The following methods should only be called by a recorder */ + public void add(TNTPrimed tntPrimed) { + add(tntPrimed, false); + } + + private void add(TNTPrimed tntPrimed, boolean exploded) { + TNTPosition position; + if (positions.isEmpty()) { + position = new TNTPosition(this, tntPrimed, null, exploded); + } else { + position = new TNTPosition(this, tntPrimed, positions.get(positions.size() - 1).getLocation(), exploded); + } + positions.add(position); + TraceShowManager.show(position); + } + + public void explode(TNTPrimed tntPrimed) { + add(tntPrimed, true); + } + + public List getPositions() { + return positions; + } + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowMode.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowMode.java new file mode 100644 index 00000000..c271b332 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowMode.java @@ -0,0 +1,28 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 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 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 . +*/ + +package de.steamwar.bausystem.features.tracer.show; + +import de.steamwar.bausystem.features.tracer.TNTPosition; + +public interface ShowMode { + void show(TNTPosition position); + + void hide(); +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameter.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameter.java new file mode 100644 index 00000000..810e146e --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameter.java @@ -0,0 +1,57 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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 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 . + * / + */ + +package de.steamwar.bausystem.features.tracer.show; + +public class ShowModeParameter { + + private boolean water = false; + private boolean interpolate_Y = false; + private boolean interpolate_XZ = false; + + public ShowModeParameter() { + + } + + public boolean isWater() { + return water; + } + + public boolean isInterpolate_Y() { + return interpolate_Y; + } + + public boolean isInterpolate_XZ() { + return interpolate_XZ; + } + + public void setWater(boolean water) { + this.water = water; + } + + public void setInterpolate_Y(boolean interpolate_Y) { + this.interpolate_Y = interpolate_Y; + } + + public void setInterpolate_XZ(boolean interpolate_XZ) { + this.interpolate_XZ = interpolate_XZ; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameterType.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameterType.java new file mode 100644 index 00000000..1d54a78a --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameterType.java @@ -0,0 +1,44 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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 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 . + */ + +package de.steamwar.bausystem.features.tracer.show; + +import java.util.function.Consumer; + +public enum ShowModeParameterType { + + WATER(showModeParameter -> showModeParameter.setWater(true)), + INTERPOLATE_Y(showModeParameter -> showModeParameter.setInterpolate_Y(true)), + INTERPOLATE_XZ(showModeParameter -> showModeParameter.setInterpolate_XZ(true)), + ADVANCED(showModeParameter -> { + showModeParameter.setInterpolate_Y(true); + showModeParameter.setInterpolate_XZ(true); + }); + + private final Consumer showModeParameterConsumer; + + public Consumer getShowModeParameterConsumer() { + return showModeParameterConsumer; + } + + ShowModeParameterType(Consumer showModeParameterConsumer) { + this.showModeParameterConsumer = showModeParameterConsumer; + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/StoredRecords.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/StoredRecords.java new file mode 100644 index 00000000..e1d69b2a --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/StoredRecords.java @@ -0,0 +1,45 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 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 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 . +*/ + +package de.steamwar.bausystem.features.tracer.show; + +import de.steamwar.bausystem.features.tracer.record.RecordStateMachine; + +import java.util.ArrayList; +import java.util.List; + +public class StoredRecords { + + private static final List records = new ArrayList<>(); + + public static void add(Record record) { + records.add(record); + } + + public static void showAll(ShowMode mode) { + for (Record record : records) record.showAll(mode); + } + + public static void clear() { + records.clear(); + TraceShowManager.clear(); + RecordStateMachine.postClear(); + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/TraceShowManager.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/TraceShowManager.java new file mode 100644 index 00000000..2a6d750c --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/TraceShowManager.java @@ -0,0 +1,59 @@ +package de.steamwar.bausystem.features.tracer.show; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.tracer.TNTPosition; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerQuitEvent; + +import java.util.HashMap; +import java.util.Map; + +public class TraceShowManager implements Listener { + private TraceShowManager() { + } + + private static final Map showModes = new HashMap<>(); + + public static void show(Player player, ShowMode showMode) { + hide(player); + showModes.put(player, showMode); + StoredRecords.showAll(showMode); + } + + public static void hide(Player player) { + ShowMode showMode = showModes.remove(player); + if (showMode == null) + return; + showMode.hide(); + } + + /* Only to be called by record */ + static void show(TNTPosition tnt) { + for (ShowMode mode : showModes.values()) + mode.show(tnt); + } + + /* Only to be called by StoredRecords */ + static void clear() { + for (ShowMode mode : showModes.values()) + mode.hide(); + } + + /* Internal if player leaves*/ + static { + Bukkit.getPluginManager().registerEvents(new TraceShowManager(), BauSystem.getInstance()); + } + + @EventHandler + public void onLeave(PlayerQuitEvent event) { + showModes.remove(event.getPlayer()); + } + + public static boolean hasActiveShow(Player player) { + return showModes.containsKey(player); + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/EntityShowMode.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/EntityShowMode.java new file mode 100644 index 00000000..57e33805 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/EntityShowMode.java @@ -0,0 +1,120 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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 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 . + * / + */ + +package de.steamwar.bausystem.features.tracer.show.mode; + +import de.steamwar.bausystem.features.tracer.AbstractTraceEntity; +import de.steamwar.bausystem.features.tracer.RoundedTNTPosition; +import de.steamwar.bausystem.features.tracer.TNTPosition; +import de.steamwar.bausystem.features.tracer.TNTTracer_15; +import de.steamwar.bausystem.features.tracer.show.ShowMode; +import de.steamwar.bausystem.features.tracer.show.ShowModeParameter; +import de.steamwar.core.VersionedCallable; +import org.bukkit.entity.Player; +import org.bukkit.util.Consumer; +import org.bukkit.util.Vector; + +import java.util.HashMap; +import java.util.Map; + +public class EntityShowMode implements ShowMode { + + protected final Player player; + protected final ShowModeParameter showModeParameter; + + private final Map tntEntityMap = new HashMap<>(); + private final Map updateEntityMap = new HashMap<>(); + + public EntityShowMode(Player player, ShowModeParameter showModeParameter) { + this.player = player; + this.showModeParameter = showModeParameter; + } + + @Override + public void show(TNTPosition position) { + if (!showModeParameter.isWater() && position.isExploded() && checkWater(position.getLocation())) { + // Basic + for (TNTPosition pos : position.getRecord().getPositions()) { + RoundedTNTPosition roundedTNTPosition = new RoundedTNTPosition(pos); + tntEntityMap.computeIfPresent(roundedTNTPosition, (p, tnt) -> { + return tnt.hide(player, false) ? null : tnt; + }); + } + // Advanced + for (TNTPosition pos : position.getRecord().getPositions()) { + applyOnPosition(pos, updatePointPosition -> { + updateEntityMap.computeIfPresent(new RoundedTNTPosition(updatePointPosition), (p, point) -> { + return point.hide(player, false) ? null : point; + }); + }); + } + return; + } + + RoundedTNTPosition roundedTNTPosition = new RoundedTNTPosition(position); + AbstractTraceEntity entity = tntEntityMap.computeIfAbsent(roundedTNTPosition, pos -> createEntity(player, position.getLocation(), true)); + entity.display(player, position.isExploded()); + + applyOnPosition(position, updatePointPosition -> { + updateEntityMap.computeIfAbsent(new RoundedTNTPosition(updatePointPosition), pos -> { + return createEntity(player, updatePointPosition, false); + }).display(player, position.isExploded()); + }); + } + + private boolean checkWater(Vector position) { + return VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_15.inWater(player.getWorld(), position), 15)); + } + + public static AbstractTraceEntity createEntity(Player player, Vector position, boolean tnt) { + return VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_15.create(player.getWorld(), position, tnt), 15)); + } + + private void applyOnPosition(TNTPosition position, Consumer function) { + if (position.getPreviousLocation() == null) return; + + if (showModeParameter.isInterpolate_Y()) { + Vector updatePointY = position.getPreviousLocation().clone().setY(position.getLocation().getY()); + if (!position.getLocation().equals(updatePointY)) { + function.accept(updatePointY); + } + } + + if (showModeParameter.isInterpolate_XZ()) { + Vector movement = position.getLocation().clone().subtract(position.getPreviousLocation()); + Vector updatePointXZ = Math.abs(movement.getX()) > Math.abs(movement.getZ()) + ? position.getLocation().clone().setZ(position.getPreviousLocation().getZ()) + : position.getLocation().clone().setX(position.getPreviousLocation().getX()); + if (!position.getLocation().equals(updatePointXZ)) { + function.accept(updatePointXZ); + } + } + } + + @Override + public void hide() { + tntEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> abstractTraceEntity.hide(player, true)); + tntEntityMap.clear(); + updateEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> abstractTraceEntity.hide(player, true)); + updateEntityMap.clear(); + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/.gitkeep b/BauSystem_Main/src/de/steamwar/bausystem/features/util/.gitkeep deleted file mode 100644 index e69de29b..00000000