Tracer-entity #147
@ -20,11 +20,20 @@
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
class TNTTracer_12 {
|
||||
private TNTTracer_12(){}
|
||||
public class TNTTracer_12 {
|
||||
|
||||
static Material getMaterial(){
|
||||
return Material.STAINED_GLASS;
|
||||
public static AbstractTraceEntity create(World world, Vector tntPosition, Player player, boolean exploded, boolean tnt) {
|
||||
return new TraceEntity_12(world, tntPosition, player, exploded, tnt);
|
||||
}
|
||||
|
||||
public static boolean inWater(World world, Vector tntPosition) {
|
||||
Material material = world.getBlockAt(tntPosition.getBlockX(), tntPosition.getBlockY(), tntPosition.getBlockZ()).getType();
|
||||
return material == Material.WATER || material == Material.STATIONARY_WATER;
|
||||
}
|
||||
|
||||
}
|
||||
|
69
BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java
Normale Datei
69
BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java
Normale Datei
@ -0,0 +1,69 @@
|
||||
/*
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
import net.minecraft.server.v1_12_R1.*;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity {
|
||||
|
||||
private boolean tnt;
|
||||
|
||||
public TraceEntity_12(World world, Vector position, Player player, boolean exploded, boolean tnt) {
|
||||
super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), tnt ? Blocks.TNT.getBlockData() : Blocks.STAINED_GLASS.getBlockData());
|
||||
this.tnt = tnt;
|
||||
|
||||
this.setNoGravity(true);
|
||||
this.ticksLived = -12000;
|
||||
if (exploded) {
|
||||
this.setCustomNameVisible(true);
|
||||
this.setCustomName("Bumm");
|
||||
}
|
||||
|
||||
display(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractTraceEntity display(Player player) {
|
||||
PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(this, 0, 0);
|
||||
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||
playerConnection.sendPacket(packetPlayOutSpawnEntity);
|
||||
|
||||
if (tnt) {
|
||||
PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true);
|
||||
playerConnection.sendPacket(packetPlayOutEntityMetadata);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractTraceEntity hide(Player player) {
|
||||
PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(new int[]{getId()});
|
||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityDestroy);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
@ -20,11 +20,29 @@
|
||||
package de.steamwar.bausystem.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.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
class TNTTracer_15 {
|
||||
private TNTTracer_15(){}
|
||||
public class TNTTracer_15 {
|
||||
|
||||
static Material getMaterial(boolean updatePoint){
|
||||
return updatePoint ? Material.LIME_STAINED_GLASS : Material.RED_STAINED_GLASS;
|
||||
public static AbstractTraceEntity create(World world, Vector tntPosition, Player player, boolean exploded, boolean tnt) {
|
||||
return new TraceEntity_15(world, tntPosition, player, exploded, 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
72
BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java
Normale Datei
72
BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java
Normale Datei
@ -0,0 +1,72 @@
|
||||
/*
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.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 Vector position;
|
||||
private boolean tnt;
|
||||
|
||||
public TraceEntity_15(World world, Vector position, Player player, boolean exploded, 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;
|
||||
if (exploded) {
|
||||
this.setCustomNameVisible(true);
|
||||
this.setCustomName(new ChatComponentText("Bumm"));
|
||||
}
|
||||
|
||||
display(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractTraceEntity display(Player player) {
|
||||
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);
|
||||
|
||||
if (tnt) {
|
||||
PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true);
|
||||
playerConnection.sendPacket(packetPlayOutEntityMetadata);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractTraceEntity hide(Player player) {
|
||||
PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(new int[]{getId()});
|
||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityDestroy);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface AbstractTraceEntity {
|
||||
|
||||
AbstractTraceEntity display(Player player);
|
||||
|
||||
AbstractTraceEntity hide(Player player);
|
||||
|
||||
void killEntity();
|
||||
|
||||
}
|
@ -20,9 +20,6 @@
|
||||
package de.steamwar.bausystem;
|
||||
|
||||
import de.steamwar.bausystem.commands.*;
|
||||
import de.steamwar.bausystem.tracer.ShowManager;
|
||||
import de.steamwar.bausystem.tracer.TNTTracer;
|
||||
import de.steamwar.bausystem.tracer.TraceListener;
|
||||
import de.steamwar.bausystem.world.*;
|
||||
import de.steamwar.core.CommandRemover;
|
||||
import de.steamwar.core.Core;
|
||||
@ -122,10 +119,8 @@ public class BauSystem extends JavaPlugin implements Listener {
|
||||
Bukkit.getPluginManager().registerEvents(new RegionListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new ScriptListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new BauScoreboard(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new TraceListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new ClipboardListener(), this);
|
||||
new AFKStopper();
|
||||
TNTTracer.init();
|
||||
|
||||
autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 1200);
|
||||
}
|
||||
@ -170,8 +165,6 @@ public class BauSystem extends JavaPlugin implements Listener {
|
||||
Player p = e.getPlayer();
|
||||
p.setOp(true);
|
||||
|
||||
ShowManager.add(p);
|
||||
|
||||
if (Core.getVersion() == 15)
|
||||
Bukkit.getWorlds().get(0).setGameRule(GameRule.REDUCED_DEBUG_INFO, false);
|
||||
}
|
||||
|
@ -21,9 +21,12 @@ package de.steamwar.bausystem.commands;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.tracer.ShowManager;
|
||||
import de.steamwar.bausystem.tracer.TraceManager;
|
||||
import de.steamwar.bausystem.tracer.recorder.RecordManager;
|
||||
import de.steamwar.bausystem.tracer.record.RecordStateMachine;
|
||||
import de.steamwar.bausystem.tracer.show.ShowModeParameter;
|
||||
import de.steamwar.bausystem.tracer.show.StoredRecords;
|
||||
import de.steamwar.bausystem.tracer.show.TraceShowManager;
|
||||
import de.steamwar.bausystem.tracer.show.mode.Advanced;
|
||||
import de.steamwar.bausystem.tracer.show.mode.Basic;
|
||||
import de.steamwar.bausystem.world.Welt;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@ -36,15 +39,12 @@ public class CommandTrace implements CommandExecutor {
|
||||
player.sendMessage("§8/§etrace start §8- §7Startet die Aufnahme aller TNT-Positionen");
|
||||
player.sendMessage("§8/§etrace stop §8- §7Stoppt den TNT-Tracer");
|
||||
player.sendMessage("§8/§etrace toggleauto §8- §7Automatischer Aufnahmenstart");
|
||||
player.sendMessage("§8/§etrace show §8<§eblock§8|§eparticle§8|§7TNT-ID§8> §8- §7Zeigt alle TNT-Positionen");
|
||||
player.sendMessage("§8/§etrace hide §8<§7TNT-ID§8> §8- §7Versteckt alle TNT-Positionen");
|
||||
player.sendMessage("§8/§etrace toggleshow §8<§7TNT-ID§8> §8- §7Zeigt/Versteckt ein TNT");
|
||||
player.sendMessage("§8/§etrace delete §8<§7TNT-ID§8> §8- §7Löscht alle TNT-Positionen");
|
||||
player.sendMessage("§8/§etrace interpolate §8[§eall§8|§eyaxis§8|§enone§8] §8- §7Interpolationsoptionen");
|
||||
player.sendMessage("§8/§etrace distance §8[§7distanz§8] §8- §7Distanzoptionen");
|
||||
player.sendMessage("§8/§etrace show §8<§edefault§8|§eadvanced§8> §8<§e-water§8|§e-interpolate-xz§8|§e-interpolate-y§8> §8- §7Zeigt alle TNT-Positionen");
|
||||
player.sendMessage("§8/§etrace hide §8- §7Versteckt alle TNT-Positionen");
|
||||
player.sendMessage("§8/§etrace delete §8- §7Löscht alle TNT-Positionen");
|
||||
// player.sendMessage("§8/§etrace list §8<§7FRAME-ID§8> §8- §7Listet alle TNT auf");
|
||||
// player.sendMessage("§8/§etrace gui §8- §7Zeigt die Trace Oberfläche an");
|
||||
player.sendMessage("§7Optionale Parameter mit §8<>§7, Benötigte Parameter mit §8[]");
|
||||
// player.sendMessage("§7Optionale Parameter mit §8<>§7, Benötigte Parameter mit §8[]");
|
||||
}
|
||||
|
||||
private boolean permissionCheck(Player player) {
|
||||
@ -69,176 +69,51 @@ public class CommandTrace implements CommandExecutor {
|
||||
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "start":
|
||||
RecordStateMachine.commandStart();
|
||||
player.sendMessage(BauSystem.PREFIX + "§aTNT-Tracer gestartet");
|
||||
break;
|
||||
case "stop":
|
||||
RecordStateMachine.commandStop();
|
||||
player.sendMessage(BauSystem.PREFIX + "§cTNT-Tracer gestoppt");
|
||||
break;
|
||||
case "toggleauto":
|
||||
case "auto":
|
||||
RecordManager.tracer(player, args);
|
||||
RecordStateMachine.commandAuto();
|
||||
player.sendMessage(BauSystem.PREFIX + RecordStateMachine.getRecordStatus().getAutoMessage());
|
||||
break;
|
||||
case "clear":
|
||||
case "delete":
|
||||
StoredRecords.clear();
|
||||
player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen gelöscht");
|
||||
break;
|
||||
case "show":
|
||||
case "hide":
|
||||
case "toggleshow":
|
||||
case "interpolate":
|
||||
case "distance":
|
||||
if (tracer(player, args)) {
|
||||
help(player);
|
||||
if (args.length < 2) {
|
||||
TraceShowManager.show(player, new Basic(player, new ShowModeParameter()));
|
||||
} else {
|
||||
ShowModeParameter showModeParameter = ShowModeParameter.parseArguments(args, 2);
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "advanced":
|
||||
TraceShowManager.show(player, new Advanced(player, showModeParameter));
|
||||
break;
|
||||
case "basic":
|
||||
case "default":
|
||||
default:
|
||||
TraceShowManager.show(player, new Basic(player, showModeParameter));
|
||||
break;
|
||||
}
|
||||
}
|
||||
player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen angezeigt");
|
||||
break;
|
||||
case "hide":
|
||||
TraceShowManager.hide(player);
|
||||
player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen ausgeblendet");
|
||||
break;
|
||||
case "list":
|
||||
case "gui":
|
||||
// player.sendMessage(BauSystem.PREFIX + "§cNoch in Bau");
|
||||
break;
|
||||
case "delete":
|
||||
if (delete(player, args)) {
|
||||
help(player);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
help(player);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean delete(Player player, String[] args) {
|
||||
if (args.length == 2) {
|
||||
try {
|
||||
TraceManager.delete(Integer.parseInt(args[1]));
|
||||
player.sendMessage(BauSystem.PREFIX + "§cTNT-Positionen mit ID " + args[1] + " gelöscht");
|
||||
ShowManager.globalDirty();
|
||||
return false;
|
||||
} catch (NumberFormatException e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
TraceManager.deleteAll();
|
||||
player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen gelöscht");
|
||||
ShowManager.globalDirty();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean tracer(Player player, String[] args) {
|
||||
ShowManager.ShowStatus showStatus = ShowManager.showMap.get(player.getUniqueId().toString());
|
||||
showStatus.dirty = true;
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "show":
|
||||
showStatus.show();
|
||||
if (args.length == 2) {
|
||||
return tracerShow(player, showStatus, args);
|
||||
}
|
||||
player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen angezeigt");
|
||||
break;
|
||||
case "distance":
|
||||
if (args.length != 2) {
|
||||
return true;
|
||||
}
|
||||
if (args[1].equalsIgnoreCase("default")) {
|
||||
ShowManager.get(player).setSlope(7.0);
|
||||
player.sendMessage(BauSystem.PREFIX + "§aAnzeige Distanz auf " + ShowManager.get(player).slopeHeight + " gesetzt");
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
double radius = Double.parseDouble(args[1]);
|
||||
radius = (double)(int)(radius * 10) / 10;
|
||||
ShowManager.get(player).setSlope(radius);
|
||||
player.sendMessage(BauSystem.PREFIX + "§aAnzeige Distanz auf " + ShowManager.get(player).slopeHeight + " gesetzt");
|
||||
return false;
|
||||
} catch (NumberFormatException e) {
|
||||
return true;
|
||||
}
|
||||
case "hide":
|
||||
showStatus.hide();
|
||||
if (args.length == 2) {
|
||||
return traceID(player, args[1], showStatus::removeSelection, new String[]{BauSystem.PREFIX + "§aTNT-Positionen des TNT mit ID {} versteckt"});
|
||||
}
|
||||
player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen versteckt");
|
||||
break;
|
||||
case "toggleshow":
|
||||
if (args.length == 2) {
|
||||
return traceID(player, args[1], showStatus::toggleSelection, new String[]{BauSystem.PREFIX + "§aTNT-Positionen des TNT mit ID {} angezeigt"}, new String[]{BauSystem.PREFIX + "§aTNT-Positionen des TNT mit ID {} versteckt"});
|
||||
}
|
||||
return true;
|
||||
case "interpolate":
|
||||
if (args.length == 2) {
|
||||
return tracerInterpolate(player, showStatus, args);
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean tracerShow(Player player, ShowManager.ShowStatus showStatus, String[] args) {
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "block":
|
||||
case "blocks":
|
||||
showStatus.displayType = ShowManager.DisplayType.Block;
|
||||
player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen, als Blöcke, angezeigt");
|
||||
break;
|
||||
case "particle":
|
||||
case "particles":
|
||||
case "default":
|
||||
showStatus.displayType = ShowManager.DisplayType.Particle;
|
||||
player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen, als Partikel, angezeigt");
|
||||
break;
|
||||
default:
|
||||
return traceID(player, args[1], showStatus::addSelection, new String[]{BauSystem.PREFIX + "§aTNT-Positionen des TNT mit ID {} angezeigt"});
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean tracerInterpolate(Player player, ShowManager.ShowStatus showStatus, String[] args) {
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "none":
|
||||
showStatus.displayMode = ShowManager.DisplayMode.NONE;
|
||||
player.sendMessage(BauSystem.PREFIX + "§aInterpolation auf §enone §agesetzt");
|
||||
break;
|
||||
case "yaxis":
|
||||
case "y":
|
||||
showStatus.displayMode = ShowManager.DisplayMode.Y_AXIS;
|
||||
player.sendMessage(BauSystem.PREFIX + "§aInterpolation auf §eyaxis §agesetzt");
|
||||
break;
|
||||
case "all":
|
||||
case "allaxis":
|
||||
case "xyz":
|
||||
case "default":
|
||||
showStatus.displayMode = ShowManager.DisplayMode.ALL;
|
||||
player.sendMessage(BauSystem.PREFIX + "§aInterpolation auf §eall §agesetzt");
|
||||
break;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private boolean traceID(Player player, String number, ShowManager.Mode mode, String[] messages) {
|
||||
try {
|
||||
mode.run(Integer.parseInt(number));
|
||||
for (String s : messages) {
|
||||
player.sendMessage(s.replace("{}", number));
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean traceID(Player player, String number, ShowManager.ModeChoose mode, String[] messagesTrue, String[] messagesFalse) {
|
||||
try {
|
||||
boolean result = mode.run(Integer.parseInt(number));
|
||||
if (result) {
|
||||
for (String s : messagesTrue) {
|
||||
player.sendMessage(s.replace("{}", number));
|
||||
}
|
||||
} else {
|
||||
for (String s : messagesFalse) {
|
||||
player.sendMessage(s.replace("{}", number));
|
||||
}
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,8 @@
|
||||
|
||||
package de.steamwar.bausystem.commands;
|
||||
|
||||
import de.steamwar.bausystem.tracer.recorder.RecordManager;
|
||||
import de.steamwar.bausystem.tracer.record.RecordStateMachine;
|
||||
import de.steamwar.bausystem.tracer.record.RecordStatus;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
@ -28,9 +29,21 @@ import org.bukkit.entity.Player;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
public class CommandTraceTabCompleter implements TabCompleter {
|
||||
|
||||
private static List<TabComplete> tabCompletes = new ArrayList<>();
|
||||
|
||||
static {
|
||||
tabCompletes.add(new TabComplete((player, args) -> args.length == 1 && (RecordStateMachine.getRecordStatus() == RecordStatus.IDLE || RecordStateMachine.getRecordStatus() == RecordStatus.IDLE_AUTO), "start"));
|
||||
tabCompletes.add(new TabComplete((player, args) -> args.length == 1 && (RecordStateMachine.getRecordStatus() != RecordStatus.IDLE && RecordStateMachine.getRecordStatus() != RecordStatus.IDLE_AUTO), "stop"));
|
||||
tabCompletes.add(new TabComplete((player, args) -> args.length == 1, "toggleauto", "auto", "show", "hide", "delete", "clear"));
|
||||
tabCompletes.add(new TabComplete((player, args) -> args.length == 2 && args[0].equalsIgnoreCase("show"), "basic", "advanced"));
|
||||
tabCompletes.add(new TabComplete((player, args) -> args.length > 2 && args[0].equalsIgnoreCase("show") && (args[1].equalsIgnoreCase("basic") || args[1].equalsIgnoreCase("advanced")), "-water"));
|
||||
tabCompletes.add(new TabComplete((player, args) -> args.length > 2 && args[0].equalsIgnoreCase("show") && args[1].equalsIgnoreCase("advanced"), "-interpolate-xz", "-interpolate-y"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player)) return new ArrayList<>();
|
||||
@ -39,44 +52,37 @@ public class CommandTraceTabCompleter implements TabCompleter {
|
||||
|
||||
private List<String> tracerTabComplete(Player player, String[] args) {
|
||||
List<String> tabComplete = new ArrayList<>();
|
||||
if (RecordManager.getStatus() == RecordManager.Status.IDLE || RecordManager.getStatus() == RecordManager.Status.IDLE_AUTO) {
|
||||
tabComplete.add("start");
|
||||
} else {
|
||||
tabComplete.add("stop");
|
||||
for (TabComplete tab : tabCompletes) {
|
||||
if (tab.test(player, args)) tabComplete.addAll(Arrays.asList(tab.getTabCompletes()));
|
||||
}
|
||||
tabComplete.add("toggleauto");
|
||||
tabComplete.add("auto");
|
||||
tabComplete.add("toggleshow");
|
||||
tabComplete.add("show");
|
||||
if (args[0].equalsIgnoreCase("show") && args.length == 2) {
|
||||
return manageList(new ArrayList<>(Arrays.asList("block", "particle")), args, 1);
|
||||
}
|
||||
tabComplete.add("hide");
|
||||
tabComplete.add("delete");
|
||||
tabComplete.add("interpolate");
|
||||
if (args[0].equalsIgnoreCase("interpolate") && args.length == 2) {
|
||||
return manageList(new ArrayList<>(Arrays.asList("all", "yaxis", "none")), args, 1);
|
||||
}
|
||||
tabComplete.add("distance");
|
||||
if (args[0].equalsIgnoreCase("distance") && args.length == 2) {
|
||||
return manageList(new ArrayList<>(Arrays.asList("3", "4", "5", "6", "7", "8", "9", "10", "11", "default")), args, 1);
|
||||
}
|
||||
//tabComplete.add("gui");
|
||||
//tabComplete.add("list");
|
||||
|
||||
if (args.length >= 2) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return manageList(tabComplete, args, 0);
|
||||
return manageList(tabComplete, args);
|
||||
}
|
||||
|
||||
private List<String> manageList(List<String> strings, String[] args, int index) {
|
||||
private List<String> manageList(List<String> strings, String[] args) {
|
||||
for (int i = strings.size() - 1; i >= 0; i--) {
|
||||
if (!strings.get(i).startsWith(args[index])) {
|
||||
strings.remove(i);
|
||||
}
|
||||
if (!strings.get(i).startsWith(args[args.length - 1])) strings.remove(i);
|
||||
}
|
||||
return strings;
|
||||
}
|
||||
|
||||
private static class TabComplete {
|
||||
|
||||
private BiPredicate<Player, String[]> function;
|
||||
private String[] tabCompletes;
|
||||
|
||||
private TabComplete(BiPredicate<Player, String[]> function, String... tabCompletes) {
|
||||
this.function = function;
|
||||
this.tabCompletes = tabCompletes;
|
||||
}
|
||||
|
||||
public boolean test(Player player, String[] args) {
|
||||
return function.test(player, args);
|
||||
}
|
||||
|
||||
public String[] getTabCompletes() {
|
||||
return tabCompletes;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
* /
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.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);
|
||||
}
|
||||
|
||||
}
|
@ -1,225 +0,0 @@
|
||||
/*
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class ShowManager {
|
||||
|
||||
public enum DisplayMode {
|
||||
NONE,
|
||||
Y_AXIS,
|
||||
ALL
|
||||
}
|
||||
|
||||
public enum DisplayType {
|
||||
Particle,
|
||||
Block
|
||||
}
|
||||
|
||||
public enum ShowSelection {
|
||||
NONE,
|
||||
SELECTIVE,
|
||||
ALL
|
||||
}
|
||||
|
||||
|
||||
public interface Mode {
|
||||
void run(int tntID);
|
||||
}
|
||||
|
||||
public interface ModeChoose {
|
||||
boolean run(int tntID);
|
||||
}
|
||||
|
||||
|
||||
public static class ShowStatus {
|
||||
|
||||
private ShowSelection showSelection = ShowSelection.NONE;
|
||||
public DisplayType displayType = DisplayType.Particle;
|
||||
public DisplayMode displayMode = DisplayMode.ALL;
|
||||
|
||||
public boolean dirty = true;
|
||||
private int count = 0;
|
||||
|
||||
private Set<Integer> selected = new HashSet<>();
|
||||
|
||||
private void clear() {
|
||||
if (showSelection == ShowSelection.NONE) return;
|
||||
selected.clear();
|
||||
}
|
||||
|
||||
public void show() {
|
||||
showSelection = ShowSelection.ALL;
|
||||
}
|
||||
|
||||
public void hide() {
|
||||
clear();
|
||||
showSelection = ShowSelection.NONE;
|
||||
}
|
||||
|
||||
public void addSelection(int id) {
|
||||
if (showSelection == ShowSelection.ALL) return;
|
||||
if (showSelection == ShowSelection.NONE) showSelection = ShowSelection.SELECTIVE;
|
||||
TraceManager.getFrame(id).forEach(i -> selected.add(i));
|
||||
if (selected.size() == TraceManager.getAllTraces().size()) {
|
||||
showSelection = ShowSelection.ALL;
|
||||
clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void removeSelection(int id) {
|
||||
if (showSelection == ShowSelection.NONE) return;
|
||||
if (showSelection == ShowSelection.ALL) selected = TraceManager.getAllTraces();
|
||||
TraceManager.getFrame(id).forEach(i -> selected.remove(i));
|
||||
showSelection = ShowSelection.SELECTIVE;
|
||||
if (selected.isEmpty()) showSelection = ShowSelection.NONE;
|
||||
}
|
||||
|
||||
public boolean toggleSelection(int id) {
|
||||
if (showSelection == ShowSelection.NONE) {
|
||||
addSelection(id);
|
||||
return true;
|
||||
}
|
||||
if (showSelection == ShowSelection.ALL) {
|
||||
removeSelection(id);
|
||||
return false;
|
||||
}
|
||||
if (selected.contains(id)) {
|
||||
removeSelection(id);
|
||||
return false;
|
||||
} else {
|
||||
addSelection(id);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public DisplayType getDisplayType() {
|
||||
return displayType;
|
||||
}
|
||||
|
||||
public DisplayMode getDisplayMode() {
|
||||
return displayMode;
|
||||
}
|
||||
|
||||
public LinkedList<TNTTrace> getTraces() {
|
||||
if (showSelection == ShowSelection.NONE) return new LinkedList<>();
|
||||
Set<Integer> tntIDs;
|
||||
if (showSelection == ShowSelection.ALL) {
|
||||
tntIDs = TraceManager.getAllTraces();
|
||||
} else {
|
||||
tntIDs = selected;
|
||||
}
|
||||
|
||||
LinkedList<TNTTrace> traces = new LinkedList<>();
|
||||
for (int traceId : tntIDs) {
|
||||
TNTTrace trace = TraceManager.getTrace(traceId);
|
||||
if (trace == null) continue;
|
||||
traces.add(trace);
|
||||
}
|
||||
return traces;
|
||||
}
|
||||
|
||||
public boolean isDirty() {
|
||||
if (displayType == DisplayType.Block) {
|
||||
count++;
|
||||
}
|
||||
if (count >= 10) {
|
||||
count = 0;
|
||||
return true;
|
||||
}
|
||||
if (dirty) {
|
||||
dirty = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public double slopeHeight = 7.0;
|
||||
|
||||
private int size = 0;
|
||||
|
||||
private TraceCache.Loc loc = null;
|
||||
|
||||
public double getShowRadius() {
|
||||
double maxRadius = 80.0;
|
||||
if (showSelection == ShowSelection.NONE) return maxRadius;
|
||||
if (showSelection == ShowSelection.ALL) size = TraceManager.getAllTraces().size();
|
||||
if (showSelection == ShowSelection.SELECTIVE) size = selected.size();
|
||||
if (size == 0) return maxRadius;
|
||||
double minRadius = 20.0;
|
||||
if (size >= 950) return minRadius;
|
||||
|
||||
double slope = -(size / slopeHeight) + 85;
|
||||
return Math.min(Math.max(slope, minRadius), maxRadius);
|
||||
}
|
||||
|
||||
public void setSlope(double slope) {
|
||||
double minSlope = 3.0;
|
||||
double maxSlope = 11.0;
|
||||
slopeHeight = Math.min(Math.max(slope, minSlope), maxSlope);
|
||||
}
|
||||
|
||||
public void move(Player player) {
|
||||
if (loc != null && !loc.remove(player, 4)) {
|
||||
return;
|
||||
}
|
||||
Location location = player.getLocation();
|
||||
loc = new TraceCache.Loc((float) location.getX(), (float) location.getY(), (float) location.getZ());
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Map<String, ShowStatus> showMap = new HashMap<>();
|
||||
|
||||
public static void add(Player p) {
|
||||
showMap.put(p.getUniqueId().toString(), new ShowStatus());
|
||||
}
|
||||
|
||||
public static ShowStatus get(Player p) {
|
||||
if (!showMap.containsKey(p.getUniqueId().toString())) add(p);
|
||||
return showMap.get(p.getUniqueId().toString());
|
||||
}
|
||||
|
||||
public static void traceAdd() {
|
||||
for (Map.Entry<String, ShowStatus> entry : showMap.entrySet()) {
|
||||
if (entry.getValue().showSelection == ShowSelection.ALL) {
|
||||
entry.getValue().dirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void traceRemove(int id) {
|
||||
for (Map.Entry<String, ShowStatus> entry : showMap.entrySet()) {
|
||||
entry.getValue().removeSelection(id);
|
||||
}
|
||||
}
|
||||
|
||||
public static void globalDirty() {
|
||||
for (Map.Entry<String, ShowStatus> entry : showMap.entrySet()) {
|
||||
entry.getValue().dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
61
BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTPosition.java
Normale Datei
61
BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTPosition.java
Normale Datei
@ -0,0 +1,61 @@
|
||||
/*
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class TNTPosition {
|
||||
|
||||
private Vector location;
|
||||
private Vector previousLocation = null;
|
||||
private boolean exploded;
|
||||
|
||||
public TNTPosition(Entity entity, Vector previousLocation, boolean exploded) {
|
||||
location = entity.getLocation().toVector();
|
||||
this.previousLocation = previousLocation;
|
||||
this.exploded = exploded;
|
||||
}
|
||||
|
||||
public TNTPosition(Vector vector) {
|
||||
location = vector;
|
||||
this.exploded = false;
|
||||
}
|
||||
|
||||
public Vector getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public Vector getPreviousLocation() {
|
||||
return previousLocation;
|
||||
}
|
||||
|
||||
public boolean isExploded() {
|
||||
return exploded;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Position{" +
|
||||
"location=" + location +
|
||||
'}';
|
||||
}
|
||||
|
||||
}
|
@ -1,112 +0,0 @@
|
||||
/*
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class TNTTrace {
|
||||
|
||||
private final int frameID;
|
||||
|
||||
private int index = 0;
|
||||
private float[] positions = new float[240];
|
||||
|
||||
private Set<TraceCache.Loc> posSet = new HashSet<>();
|
||||
private Set<TraceCache.Loc> posYSet = new HashSet<>();
|
||||
private Set<TraceCache.Loc> posXYZSet = new HashSet<>();
|
||||
|
||||
TNTTrace(int frameID) {
|
||||
this.frameID = frameID;
|
||||
}
|
||||
|
||||
void addLocation(Location location) {
|
||||
if (index >= positions.length) {
|
||||
positions = Arrays.copyOf(positions, positions.length + 3);
|
||||
}
|
||||
positions[index] = (float)location.getX();
|
||||
positions[index + 1] = (float)location.getY();
|
||||
positions[index + 2] = (float)location.getZ();
|
||||
index += 3;
|
||||
}
|
||||
|
||||
private int size() {
|
||||
return index / 3;
|
||||
}
|
||||
|
||||
public int length() {
|
||||
return size();
|
||||
}
|
||||
|
||||
private int realLength() {
|
||||
return positions.length;
|
||||
}
|
||||
|
||||
int getFrameID() {
|
||||
return frameID;
|
||||
}
|
||||
|
||||
void cleanUp() {
|
||||
positions = Arrays.copyOf(positions, index);
|
||||
ShowManager.traceAdd();
|
||||
|
||||
for (int i = 0; i < length(); i++) {
|
||||
posSet.add(new TraceCache.Loc(positions[i * 3], positions[i * 3 + 1], positions[i * 3 + 2]));
|
||||
}
|
||||
|
||||
for (int i = 0; i < realLength() - 3; i += 3) {
|
||||
float x1 = positions[i];
|
||||
float y1 = positions[i + 1];
|
||||
float z1 = positions[i + 2];
|
||||
|
||||
float x2 = positions[i + 3];
|
||||
float y2 = positions[i + 4];
|
||||
float z2 = positions[i + 5];
|
||||
|
||||
if (isDifferent(y2, y1)) {
|
||||
TraceCache.Loc loc = new TraceCache.Loc(x1, y2, z1);
|
||||
posYSet.add(loc);
|
||||
posXYZSet.add(loc);
|
||||
}
|
||||
if (Math.abs(x2 - x1) > Math.abs(z2 - z1)) {
|
||||
if (isDifferent(x2, x1)) posXYZSet.add(new TraceCache.Loc(x2, y2, z1));
|
||||
} else {
|
||||
if (isDifferent(z2, z1)) posXYZSet.add(new TraceCache.Loc(x1, y2, z2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Set<TraceCache.Loc> locs() {
|
||||
return posSet;
|
||||
}
|
||||
|
||||
Set<TraceCache.Loc> locsUpdate(ShowManager.DisplayMode displayMode) {
|
||||
if (displayMode == ShowManager.DisplayMode.NONE) return new HashSet<>();
|
||||
if (displayMode == ShowManager.DisplayMode.Y_AXIS) return posYSet;
|
||||
return posXYZSet;
|
||||
}
|
||||
|
||||
private static boolean isDifferent(float d1, float d2) {
|
||||
return (d2 - d1) * (d2 - d1) >= 0.01;
|
||||
}
|
||||
}
|
@ -1,125 +0,0 @@
|
||||
/*
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.core.Core;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class TNTTracer {
|
||||
private TNTTracer(){}
|
||||
|
||||
static final boolean DEBUG = false;
|
||||
|
||||
private static final Object synchronizer = new Object();
|
||||
private static final TraceCache traceCache = new TraceCache();
|
||||
|
||||
public static void init(){
|
||||
Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), TNTTracer::run, 0, 20);
|
||||
}
|
||||
|
||||
private static void run() {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
if (DEBUG) {
|
||||
String actionBar = "§e" + TraceManager.getAllTraces().size() + " §cTraces §e" + ShowManager.get(p).getShowRadius() + " §cRadius";
|
||||
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(actionBar));
|
||||
}
|
||||
|
||||
boolean dirty = ShowManager.get(p).isDirty();
|
||||
if (ShowManager.get(p).getDisplayType() == ShowManager.DisplayType.Block && !dirty) {
|
||||
continue;
|
||||
}
|
||||
Set<TraceCache.Loc> toHide = traceCache.update(p, dirty);
|
||||
Set<TraceCache.Loc> toShow = traceCache.get(p);
|
||||
|
||||
hideBlockTraces(toHide, p);
|
||||
showTraces(toShow, ShowManager.get(p).getDisplayType(), p);
|
||||
}
|
||||
}
|
||||
|
||||
private static void hideBlockTraces(Set<TraceCache.Loc> locs, Player player) {
|
||||
if (locs.isEmpty()) return;
|
||||
|
||||
for (TraceCache.Loc l : locs) {
|
||||
hideBlock(player, l.x, l.y - 0.49F, l.z);
|
||||
}
|
||||
}
|
||||
|
||||
private static void showTraces(Set<TraceCache.Loc> locs, ShowManager.DisplayType displayMode, Player player) {
|
||||
if (locs.isEmpty()) return;
|
||||
|
||||
for (TraceCache.Loc l : locs) {
|
||||
if (displayMode == ShowManager.DisplayType.Block) {
|
||||
showBlock(player, l.x, l.y - 0.49F, l.z, getMaterial(l), (l.updatePoint ? (byte) 5 : (byte) 14));
|
||||
} else {
|
||||
showCorner(player, l.x - 0.49F, l.y, l.z - 0.49F, (l.updatePoint ? Particle.FLAME : Particle.VILLAGER_HAPPY));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Material getMaterial(TraceCache.Loc l){
|
||||
switch(Core.getVersion()){
|
||||
case 15:
|
||||
return TNTTracer_15.getMaterial(l.updatePoint);
|
||||
default:
|
||||
return TNTTracer_12.getMaterial();
|
||||
}
|
||||
}
|
||||
|
||||
private static void showCorner(Player player, float x, float y, float z, Particle particle) {
|
||||
player.spawnParticle(particle, makeLocation(x + 0.00F, y + 0.00F, z + 0.00F), 1, 0F, 0F, 0F, 0.001);
|
||||
player.spawnParticle(particle, makeLocation(x + 0.98F, y + 0.00F, z + 0.00F), 1, 0F, 0F, 0F, 0.001);
|
||||
player.spawnParticle(particle, makeLocation(x + 0.00F, y + 0.00F, z + 0.98F), 1, 0F, 0F, 0F, 0.001);
|
||||
player.spawnParticle(particle, makeLocation(x + 0.98F, y + 0.00F, z + 0.98F), 1, 0F, 0F, 0F, 0.001);
|
||||
|
||||
player.spawnParticle(particle, makeLocation(x + 0.00F, y + 0.98F, z + 0.00F), 1, 0F, 0F, 0F, 0.001);
|
||||
player.spawnParticle(particle, makeLocation(x + 0.98F, y + 0.98F, z + 0.00F), 1, 0F, 0F, 0F, 0.001);
|
||||
player.spawnParticle(particle, makeLocation(x + 0.00F, y + 0.98F, z + 0.98F), 1, 0F, 0F, 0F, 0.001);
|
||||
player.spawnParticle(particle, makeLocation(x + 0.98F, y + 0.98F, z + 0.98F), 1, 0F, 0F, 0F, 0.001);
|
||||
}
|
||||
|
||||
private static void showBlock(Player p, float x, float y, float z, Material block, byte b) {
|
||||
if (makeLocation(x, y, z).getBlock().getType() == Material.AIR) {
|
||||
p.sendBlockChange(makeLocation(x, y, z), block, b);
|
||||
}
|
||||
}
|
||||
|
||||
private static void hideBlock(Player p, float x, float y, float z) {
|
||||
if (makeLocation(x, y, z).getBlock().getType() == Material.AIR) {
|
||||
p.sendBlockChange(makeLocation(x, y, z), Material.AIR, (byte) 0);
|
||||
}
|
||||
}
|
||||
|
||||
private static final Location location = new Location(Bukkit.getWorlds().get(0), 0, 0, 0);
|
||||
private static Location makeLocation(float x, float y, float z) {
|
||||
location.setX(x);
|
||||
location.setY(y);
|
||||
location.setZ(z);
|
||||
return location;
|
||||
}
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
/*
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
public class TNTTracerGUI {
|
||||
|
||||
/*private static GuiCallbackTNTFrame guiCallbackTNTFrame;
|
||||
private static GuiCallbackTNTTrace guiCallbackTNTTrace;
|
||||
private static GuiCallbackRecording guiCallbackRecording;
|
||||
|
||||
private static Inventory getEmpty(String title) {
|
||||
Inventory inventory = Bukkit.createInventory(null, 54, title);
|
||||
ItemStack i1 = createItem(Material.LIGHT_GRAY_STAINED_GLASS_PANE, false, "");
|
||||
for (int i = 0; i < 9; i++) {
|
||||
inventory.setItem(i, i1);
|
||||
}
|
||||
ItemStack i2 = createItem(Material.RED_STAINED_GLASS, false, "");
|
||||
for (int i = 9; i < 54; i++) {
|
||||
inventory.setItem(i, i2);
|
||||
}
|
||||
return inventory;
|
||||
}
|
||||
|
||||
public static ItemStack createItem(Material material, boolean selected, String name, String... lore) {
|
||||
ItemStack item = new ItemStack(material, 1);
|
||||
ItemMeta im = item.getItemMeta();
|
||||
|
||||
if (im == null) return item;
|
||||
if (name == null) name = "§f";
|
||||
if (name.isEmpty()) name = "§f";
|
||||
im.setDisplayName(name);
|
||||
if (selected) {
|
||||
im.addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 1, true);
|
||||
}
|
||||
im.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
|
||||
if (lore != null) {
|
||||
List<String> lorelist = Arrays.asList(lore);
|
||||
im.setLore(lorelist);
|
||||
}
|
||||
|
||||
item.setItemMeta(im);
|
||||
return item;
|
||||
}
|
||||
|
||||
private static void frameControls(Inventory inventory, int page, int allPages) {
|
||||
inventory.setItem(1, createItem(Material.HONEYCOMB, false, "§eShow§8/§eHide"));
|
||||
inventory.setItem(4, createItem(Material.BARRIER, false, "§eClear ausgewählte Positionen"));
|
||||
inventory.setItem(5, createItem(Material.OBSERVER, false, "§eToggle AUTO-Trace"));
|
||||
inventory.setItem(6, guiCallbackRecording.run());
|
||||
inventory.setItem(8, createItem(Material.PAPER, false, "§7PAGE §e§l" + page + "§8/§e§l" + allPages));
|
||||
}
|
||||
|
||||
private static Inventory getFrameInventory(Player p, int page) {
|
||||
ItemStack[] items = guiCallbackTNTFrame.run(p);
|
||||
|
||||
Inventory inventory = getEmpty("§7§lTRACE §8- §e§lAufnahmen");
|
||||
if (items.length == 0) {
|
||||
frameControls(inventory, page + 1, 1);
|
||||
} else {
|
||||
frameControls(inventory, page + 1, items.length / 45 + (items.length % 45 == 0 ? 0 : 1));
|
||||
}
|
||||
return inventory;
|
||||
}
|
||||
|
||||
public static void init(GuiCallbackTNTFrame guiCallbackTNTFrame, GuiCallbackTNTTrace guiCallbackTNTTrace, GuiCallbackRecording guiCallbackRecording) {
|
||||
TNTTracerGUI_15.guiCallbackTNTFrame = guiCallbackTNTFrame;
|
||||
TNTTracerGUI_15.guiCallbackTNTTrace = guiCallbackTNTTrace;
|
||||
TNTTracerGUI_15.guiCallbackRecording = guiCallbackRecording;
|
||||
}
|
||||
|
||||
public enum Menu {
|
||||
FRAME,
|
||||
TRACE,
|
||||
BLOCK
|
||||
}
|
||||
|
||||
public static void show(Player p, int page, Menu menu) {
|
||||
|
||||
}*/
|
||||
|
||||
}
|
@ -1,170 +0,0 @@
|
||||
/*
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class TraceCache {
|
||||
|
||||
private static final Set<Loc> empty = new HashSet<>();
|
||||
private Map<String, Set<Loc>> playerMap = new HashMap<>();
|
||||
private Map<String, ShowManager.DisplayType> playerDisplayMap = new HashMap<>();
|
||||
|
||||
public Set<Loc> get(Player player) {
|
||||
return playerMap.getOrDefault(player.getUniqueId().toString(), empty);
|
||||
}
|
||||
|
||||
Set<Loc> update(Player player, boolean dirty) {
|
||||
if (!dirty) return empty;
|
||||
String key = player.getUniqueId().toString();
|
||||
Set<Loc> locOld;
|
||||
ShowManager.DisplayType displayMode;
|
||||
if (!playerMap.containsKey(key)) {
|
||||
locOld = new HashSet<>();
|
||||
displayMode = getDisplayType(player);
|
||||
} else {
|
||||
locOld = playerMap.get(key);
|
||||
displayMode = playerDisplayMap.get(key);
|
||||
}
|
||||
|
||||
Set<Loc> locSet = new HashSet<>();
|
||||
updatePoints(player).forEach(loc -> {
|
||||
loc.updatePoint = true;
|
||||
locSet.add(loc);
|
||||
});
|
||||
updateLocations(player).forEach(loc -> {
|
||||
loc.updatePoint = false;
|
||||
locSet.add(loc);
|
||||
});
|
||||
|
||||
playerMap.put(key, locSet);
|
||||
ShowManager.DisplayType currentMode = getDisplayType(player);
|
||||
playerDisplayMap.put(key, currentMode);
|
||||
|
||||
if (currentMode == ShowManager.DisplayType.Particle && displayMode == ShowManager.DisplayType.Block) return locOld;
|
||||
if (currentMode == ShowManager.DisplayType.Block) return diff(locOld, locSet);
|
||||
return empty;
|
||||
}
|
||||
|
||||
public static class Loc {
|
||||
final float x;
|
||||
final float y;
|
||||
final float z;
|
||||
|
||||
private final float dx;
|
||||
private final float dy;
|
||||
private final float dz;
|
||||
|
||||
boolean updatePoint = false;
|
||||
|
||||
public Loc(float x, float y, float z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.dx = round(x);
|
||||
this.dy = round(y);
|
||||
this.dz = round(z);
|
||||
}
|
||||
|
||||
private static float round(float toRound) {
|
||||
final int roundNumber = 10;
|
||||
float r = (toRound * roundNumber);
|
||||
float t = r - (int) r;
|
||||
if (t >= 0.5) {
|
||||
return (((float)(int)r) + 1) / roundNumber;
|
||||
} else {
|
||||
return (((float)(int)r) + 0) / roundNumber;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Loc)) return false;
|
||||
Loc loc = (Loc) o;
|
||||
return Float.compare(loc.dx, dx) == 0 &&
|
||||
Float.compare(loc.dy, dy) == 0 &&
|
||||
Float.compare(loc.dz, dz) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(dx, dy, dz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Loc{" +
|
||||
"x=" + x +
|
||||
", y=" + y +
|
||||
", z=" + z +
|
||||
'}';
|
||||
}
|
||||
|
||||
public boolean remove(Player player, double radius) {
|
||||
double x = player.getLocation().getX();
|
||||
double y = player.getLocation().getY();
|
||||
double z = player.getLocation().getZ();
|
||||
|
||||
double dx = (this.x - x) * (this.x - x);
|
||||
double dy = (this.y - y) * (this.y - y);
|
||||
double dz = (this.z - z) * (this.z - z);
|
||||
|
||||
return (dx + dy + dz) > radius * radius;
|
||||
}
|
||||
}
|
||||
|
||||
private Set<Loc> diff(Set<Loc> locOld, Set<Loc> locNew) {
|
||||
if (locOld.isEmpty()) return empty;
|
||||
if (locNew.isEmpty()) return locOld;
|
||||
for (Loc l : locNew) {
|
||||
locOld.remove(l);
|
||||
}
|
||||
return locOld;
|
||||
}
|
||||
|
||||
private Set<TraceCache.Loc> updateLocations(Player player) {
|
||||
Iterator<TNTTrace> traces = ShowManager.get(player).getTraces().descendingIterator();
|
||||
Set<TraceCache.Loc> locSet = new HashSet<>();
|
||||
while (traces.hasNext()) {
|
||||
locSet.addAll(traces.next().locs());
|
||||
}
|
||||
double radius = ShowManager.get(player).getShowRadius();
|
||||
locSet.removeIf(loc -> loc.remove(player, radius));
|
||||
return locSet;
|
||||
}
|
||||
|
||||
private Set<TraceCache.Loc> updatePoints(Player player) {
|
||||
Iterator<TNTTrace> traces = ShowManager.get(player).getTraces().descendingIterator();
|
||||
Set<TraceCache.Loc> locSet = new HashSet<>();
|
||||
while (traces.hasNext()) {
|
||||
locSet.addAll(traces.next().locsUpdate(ShowManager.get(player).getDisplayMode()));
|
||||
}
|
||||
double radius = ShowManager.get(player).getShowRadius();
|
||||
locSet.removeIf(loc -> loc.remove(player, radius));
|
||||
return locSet;
|
||||
}
|
||||
|
||||
private ShowManager.DisplayType getDisplayType(Player player) {
|
||||
return ShowManager.get(player).getDisplayType();
|
||||
}
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
/*
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
import de.steamwar.bausystem.tracer.recorder.RecordManager;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class TraceListener implements Listener {
|
||||
|
||||
private static final Map<TNTPrimed, TNTTrace> tntMap = new HashMap<>();
|
||||
|
||||
public static void onTick(Stream<TNTPrimed> tntPrimedStream) {
|
||||
tntPrimedStream.forEach(tnt -> {
|
||||
TNTTrace trace;
|
||||
if (!tntMap.containsKey(tnt)) {
|
||||
trace = TraceManager.createTrace();
|
||||
if (trace == null) return;
|
||||
tntMap.put(tnt, trace);
|
||||
} else {
|
||||
trace = tntMap.get(tnt);
|
||||
}
|
||||
trace.addLocation(tnt.getLocation());
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
if (!(event.getEntity() instanceof TNTPrimed))
|
||||
return;
|
||||
|
||||
if (RecordManager.getStatus() == RecordManager.Status.IDLE_AUTO)
|
||||
RecordManager.startAuto();
|
||||
if (RecordManager.getStatus() == RecordManager.Status.RECORD_AUTO)
|
||||
RecordManager.updateAuto();
|
||||
|
||||
TNTTrace trace = tntMap.remove((TNTPrimed) event.getEntity());
|
||||
if (trace != null)
|
||||
trace.cleanUp();
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void playerMove(PlayerMoveEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
ShowManager.get(p).move(p);
|
||||
}
|
||||
}
|
@ -1,101 +0,0 @@
|
||||
/*
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class TraceManager {
|
||||
private TraceManager(){}
|
||||
|
||||
private static Map<Integer, List<Integer>> frameMap = new HashMap<>();
|
||||
private static Map<Integer, TNTTrace> traceMap = new HashMap<>();
|
||||
|
||||
private static int currentFrame;
|
||||
|
||||
private static int currentID = 0;
|
||||
private static synchronized int generateID() {
|
||||
return currentID++;
|
||||
}
|
||||
|
||||
public static void startFrame() {
|
||||
currentFrame = generateID();
|
||||
frameMap.put(currentFrame, new ArrayList<>());
|
||||
}
|
||||
|
||||
public static TNTTrace createTrace() {
|
||||
if (!frameMap.containsKey(currentFrame)) return null;
|
||||
TNTTrace trace = new TNTTrace(currentFrame);
|
||||
int id = generateID();
|
||||
traceMap.put(id, trace);
|
||||
frameMap.get(currentFrame).add(id);
|
||||
return trace;
|
||||
}
|
||||
|
||||
public static TNTTrace getTrace(int id) {
|
||||
return traceMap.get(id);
|
||||
}
|
||||
|
||||
public static Set<Integer> getAllTraces() {
|
||||
return traceMap.keySet();
|
||||
}
|
||||
|
||||
public static List<Integer> getFrame(int frameID) {
|
||||
return new ArrayList<>(frameMap.getOrDefault(frameID, new ArrayList<>()));
|
||||
}
|
||||
|
||||
public static int currentFrameSize() {
|
||||
if (!frameMap.containsKey(currentFrame)) return 0;
|
||||
return frameMap.get(currentFrame).size();
|
||||
}
|
||||
|
||||
public static void stopFrame() {
|
||||
testRemoveFrame(currentFrame);
|
||||
}
|
||||
|
||||
private static void testRemoveFrame(int frame){
|
||||
if (!frameMap.containsKey(frame) || !frameMap.get(frame).isEmpty())
|
||||
return;
|
||||
frameMap.remove(frame);
|
||||
}
|
||||
|
||||
public static void deleteAll() {
|
||||
for (Integer integer : new HashSet<>(traceMap.keySet())) {
|
||||
delete(integer);
|
||||
}
|
||||
}
|
||||
|
||||
public static void delete(int id) {
|
||||
TNTTrace trace = traceMap.remove(id);
|
||||
if(trace == null){
|
||||
List<Integer> frame = frameMap.get(id);
|
||||
if(frame == null)
|
||||
return;
|
||||
|
||||
for(int t : new HashSet<>(frame)){
|
||||
delete(t);
|
||||
}
|
||||
return;
|
||||
}
|
||||
int frameID = trace.getFrameID();
|
||||
ShowManager.traceRemove(id);
|
||||
if (frameMap.containsKey(frameID)) frameMap.get(frameID).remove((Integer) id);
|
||||
testRemoveFrame(frameID);
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
/*
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.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();
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.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 String getAutoMessage() {
|
||||
return autoMessage;
|
||||
}
|
||||
|
||||
}
|
89
BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java
Normale Datei
89
BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java
Normale Datei
@ -0,0 +1,89 @@
|
||||
/*
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.tracer.record;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.tracer.show.Record;
|
||||
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<TNTPrimed, Record.TNTRecord> recordMap = new HashMap<>();
|
||||
private final BukkitTask task;
|
||||
private final Record record;
|
||||
|
||||
Recorder() {
|
||||
Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin());
|
||||
task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), 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();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.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.getPlugin());
|
||||
}
|
||||
|
||||
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.getPlugin(), this::run, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
private void run(){
|
||||
lastExplosion++;
|
||||
|
||||
if (lastExplosion > 80) {
|
||||
RecordStateMachine.autoIdle();
|
||||
task.cancel();
|
||||
task = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,136 +0,0 @@
|
||||
/*
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.tracer.recorder;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.tracer.TraceManager;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import static de.steamwar.bausystem.tracer.recorder.TNTRecorder.*;
|
||||
|
||||
public class RecordManager {
|
||||
|
||||
static Status status = Status.IDLE;
|
||||
|
||||
static final World world = Bukkit.getWorlds().get(0);
|
||||
|
||||
public static void tracer(Player player, String[] args) {
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "start":
|
||||
start();
|
||||
player.sendMessage(BauSystem.PREFIX + "§aAufnahme gestartet");
|
||||
break;
|
||||
case "stop":
|
||||
stop();
|
||||
player.sendMessage(BauSystem.PREFIX + "§cTNT-Tracer gestoppt");
|
||||
break;
|
||||
case "auto":
|
||||
case "toggleauto":
|
||||
toggleAuto();
|
||||
if (status == Status.IDLE || status == Status.RECORD) {
|
||||
player.sendMessage(BauSystem.PREFIX + "§cAutomatischer TNT-Tracer deaktiviert");
|
||||
} else {
|
||||
player.sendMessage(BauSystem.PREFIX + "§aAutomatischer TNT-Tracer aktiviert");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void toggleAuto() {
|
||||
switch (status) {
|
||||
case IDLE:
|
||||
status = Status.IDLE_AUTO;
|
||||
break;
|
||||
case RECORD:
|
||||
status = Status.RECORD_AUTO;
|
||||
break;
|
||||
case IDLE_AUTO:
|
||||
status = Status.IDLE;
|
||||
break;
|
||||
case RECORD_AUTO:
|
||||
status = Status.RECORD;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static Status getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
private static void start() {
|
||||
status = Status.RECORD;
|
||||
TraceManager.startFrame();
|
||||
startRecording();
|
||||
}
|
||||
|
||||
public static void startAuto() {
|
||||
status = Status.RECORD_AUTO;
|
||||
Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§7Automatischer TNT-Tracer §8- §aAufnahme gestartet")));
|
||||
TraceManager.startFrame();
|
||||
startRecording();
|
||||
}
|
||||
|
||||
public static void updateAuto() {
|
||||
update();
|
||||
}
|
||||
|
||||
private static void stop() {
|
||||
status = Status.IDLE;
|
||||
stopRecording();
|
||||
TraceManager.stopFrame();
|
||||
}
|
||||
|
||||
static void stopAuto() {
|
||||
status = Status.IDLE_AUTO;
|
||||
Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§7Automatischer TNT-Tracer §8- §aAufnahme gestoppt")));
|
||||
stopRecording();
|
||||
TraceManager.stopFrame();
|
||||
}
|
||||
|
||||
public enum Status {
|
||||
RECORD("§aan", true),
|
||||
RECORD_AUTO("§aan", true),
|
||||
IDLE("§caus", false),
|
||||
IDLE_AUTO("§eauto", false);
|
||||
|
||||
String value;
|
||||
boolean tracing;
|
||||
|
||||
Status(String value, boolean tracing) {
|
||||
this.value = value;
|
||||
this.tracing = tracing;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public boolean isTracing() {
|
||||
return tracing;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
/*
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.tracer.recorder;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.tracer.TraceListener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static de.steamwar.bausystem.tracer.recorder.RecordManager.stopAuto;
|
||||
|
||||
public class TNTRecorder {
|
||||
|
||||
private static BukkitTask task = null;
|
||||
public static long recordStart = System.currentTimeMillis();
|
||||
public static long lastExplosion = System.currentTimeMillis();
|
||||
|
||||
static void update() {
|
||||
if (task == null) return;
|
||||
if (RecordManager.status != RecordManager.Status.RECORD_AUTO) return;
|
||||
lastExplosion = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
static void startRecording() {
|
||||
if (task != null) return;
|
||||
recordStart = System.currentTimeMillis();
|
||||
lastExplosion = System.currentTimeMillis();
|
||||
task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), TNTRecorder::run, 1, 1);
|
||||
run();
|
||||
}
|
||||
|
||||
static void stopRecording() {
|
||||
if (task == null) return;
|
||||
task.cancel();
|
||||
task = null;
|
||||
}
|
||||
|
||||
private static void run() {
|
||||
Stream<TNTPrimed> tntPrimedStream = RecordManager.world.getEntities()
|
||||
.stream()
|
||||
.filter(e -> e instanceof TNTPrimed)
|
||||
.map(e -> (TNTPrimed)e);
|
||||
TraceListener.onTick(tntPrimedStream);
|
||||
|
||||
if (RecordManager.status == RecordManager.Status.RECORD_AUTO && System.currentTimeMillis() - lastExplosion > 4500) {
|
||||
stopAuto();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
86
BauSystem_Main/src/de/steamwar/bausystem/tracer/show/Record.java
Normale Datei
86
BauSystem_Main/src/de/steamwar/bausystem/tracer/show/Record.java
Normale Datei
@ -0,0 +1,86 @@
|
||||
/*
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.tracer.show;
|
||||
|
||||
import de.steamwar.bausystem.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<TNTRecord> 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 static class TNTRecord {
|
||||
private final List<TNTPosition> 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(tntPrimed, null, exploded);
|
||||
} else {
|
||||
position = new TNTPosition(tntPrimed, positions.get(positions.size() - 1).getLocation(), exploded);
|
||||
}
|
||||
positions.add(position);
|
||||
TraceShowManager.show(position);
|
||||
}
|
||||
|
||||
public void explode(TNTPrimed tntPrimed) {
|
||||
add(tntPrimed, true);
|
||||
}
|
||||
}
|
||||
}
|
27
BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowMode.java
Normale Datei
27
BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowMode.java
Normale Datei
@ -0,0 +1,27 @@
|
||||
/*
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.tracer.show;
|
||||
|
||||
import de.steamwar.bausystem.tracer.TNTPosition;
|
||||
|
||||
public interface ShowMode {
|
||||
void show(TNTPosition position);
|
||||
void hide();
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
/*
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
* /
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.tracer.show;
|
||||
|
||||
public class ShowModeParameter {
|
||||
|
||||
private boolean water = false;
|
||||
private boolean interpolate_SET = false;
|
||||
private boolean interpolate_Y = true;
|
||||
private boolean interpolate_XZ = true;
|
||||
|
||||
public ShowModeParameter() {
|
||||
|
||||
}
|
||||
|
||||
public boolean isWater() {
|
||||
return water;
|
||||
}
|
||||
|
||||
public boolean isInterpolate_Y() {
|
||||
return interpolate_Y;
|
||||
}
|
||||
|
||||
public boolean isInterpolate_XZ() {
|
||||
return interpolate_XZ;
|
||||
}
|
||||
|
||||
public static ShowModeParameter parseArguments(String[] args, int index) {
|
||||
ShowModeParameter showModeParameter = new ShowModeParameter();
|
||||
for (int i = index; i < args.length; i++) {
|
||||
switch (args[i].toLowerCase()) {
|
||||
case "-water":
|
||||
showModeParameter.water = true;
|
||||
break;
|
||||
case "-interpolatey":
|
||||
case "-interpolate-y":
|
||||
case "-interpolate_y":
|
||||
case "-y":
|
||||
if (showModeParameter.interpolate_SET) {
|
||||
showModeParameter.interpolate_Y = true;
|
||||
} else {
|
||||
showModeParameter.interpolate_XZ = false;
|
||||
showModeParameter.interpolate_SET = true;
|
||||
}
|
||||
break;
|
||||
case "-interpolatex":
|
||||
case "-interpolate-x":
|
||||
case "-interpolate_x":
|
||||
case "-x":
|
||||
case "-interpolatez":
|
||||
case "-interpolate-z":
|
||||
case "-interpolate_z":
|
||||
case "-z":
|
||||
case "-interpolatexz":
|
||||
case "-interpolate-xz":
|
||||
case "-interpolate_xz":
|
||||
case "-xz":
|
||||
if (showModeParameter.interpolate_SET) {
|
||||
showModeParameter.interpolate_XZ = true;
|
||||
} else {
|
||||
showModeParameter.interpolate_Y = false;
|
||||
showModeParameter.interpolate_SET = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return showModeParameter;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.tracer.show;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class StoredRecords {
|
||||
|
||||
private static final List<Record> 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();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package de.steamwar.bausystem.tracer.show;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.tracer.TNTPosition;
|
||||
import de.steamwar.bausystem.tracer.show.mode.*;
|
||||
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<Player, ShowMode> 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.getPlugin());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onLeave(PlayerQuitEvent event) {
|
||||
showModes.remove(event.getPlayer());
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
/*
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
* /
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.tracer.show.mode;
|
||||
|
||||
import de.steamwar.bausystem.tracer.AbstractTraceEntity;
|
||||
import de.steamwar.bausystem.tracer.RoundedTNTPosition;
|
||||
import de.steamwar.bausystem.tracer.TNTPosition;
|
||||
import de.steamwar.bausystem.tracer.show.ShowModeParameter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Advanced extends Basic {
|
||||
|
||||
private Map<RoundedTNTPosition, AbstractTraceEntity> updateEntityMap = new HashMap<>();
|
||||
|
||||
public Advanced(Player player, ShowModeParameter showModeParameter) {
|
||||
super(player, showModeParameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show(TNTPosition position) {
|
||||
super.show(position);
|
||||
|
||||
if (position.getPreviousLocation() == null) return;
|
||||
Vector vector = position.getLocation().clone().subtract(position.getPreviousLocation());
|
||||
|
||||
Vector updatePointY = position.getPreviousLocation().clone().setY(position.getLocation().getY());
|
||||
Vector updatePointXZ;
|
||||
if (Math.abs(vector.getX()) > Math.abs(vector.getZ())) {
|
||||
updatePointXZ = updatePointY.clone().setX(position.getLocation().getX());
|
||||
} else {
|
||||
updatePointXZ = updatePointY.clone().setZ(position.getLocation().getZ());
|
||||
}
|
||||
|
||||
if (showModeParameter.isInterpolate_Y() && !position.getLocation().equals(updatePointY)) {
|
||||
RoundedTNTPosition updatePointPosition = new RoundedTNTPosition(updatePointY);
|
||||
if (!updateEntityMap.containsKey(updatePointPosition)) {
|
||||
updateEntityMap.put(updatePointPosition, createEntity(updatePointY, false, false));
|
||||
}
|
||||
}
|
||||
if (showModeParameter.isInterpolate_XZ() && !position.getLocation().equals(updatePointXZ)) {
|
||||
RoundedTNTPosition updatePointPosition = new RoundedTNTPosition(updatePointXZ);
|
||||
if (!updateEntityMap.containsKey(updatePointPosition)) {
|
||||
updateEntityMap.put(updatePointPosition, createEntity(updatePointXZ, false, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hide() {
|
||||
super.hide();
|
||||
|
||||
updateEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> {
|
||||
abstractTraceEntity.hide(player);
|
||||
abstractTraceEntity.killEntity();
|
||||
});
|
||||
updateEntityMap.clear();
|
||||
}
|
||||
|
||||
}
|
56
BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java
Normale Datei
56
BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java
Normale Datei
@ -0,0 +1,56 @@
|
||||
package de.steamwar.bausystem.tracer.show.mode;
|
||||
|
||||
import de.steamwar.bausystem.tracer.*;
|
||||
import de.steamwar.bausystem.tracer.show.ShowMode;
|
||||
import de.steamwar.bausystem.tracer.show.ShowModeParameter;
|
||||
import de.steamwar.core.VersionedCallable;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Basic implements ShowMode {
|
||||
|
||||
protected final Player player;
|
||||
protected final ShowModeParameter showModeParameter;
|
||||
|
||||
private Map<RoundedTNTPosition, AbstractTraceEntity> tntEntityMap = new HashMap<>();
|
||||
|
||||
public Basic(Player player, ShowModeParameter showModeParameter) {
|
||||
this.player = player;
|
||||
this.showModeParameter = showModeParameter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show(TNTPosition position) {
|
||||
if (showModeParameter.isWater() && checkWater(position.getLocation())) {
|
||||
return;
|
||||
}
|
||||
RoundedTNTPosition roundedTNTPosition = new RoundedTNTPosition(position);
|
||||
if (tntEntityMap.containsKey(roundedTNTPosition)) {
|
||||
return;
|
||||
}
|
||||
tntEntityMap.put(roundedTNTPosition, createEntity(position.getLocation(), position.isExploded(), true));
|
||||
}
|
||||
|
||||
protected boolean checkWater(Vector position) {
|
||||
return (VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.inWater(player.getWorld(), position), 8),
|
||||
new VersionedCallable<>(() -> TNTTracer_15.inWater(player.getWorld(), position), 14)));
|
||||
}
|
||||
|
||||
protected AbstractTraceEntity createEntity(Vector position, boolean exploded, boolean tnt) {
|
||||
return VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.create(player.getWorld(), position, player, exploded, tnt), 8),
|
||||
new VersionedCallable<>(() -> TNTTracer_15.create(player.getWorld(), position, player, exploded, tnt), 14));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hide() {
|
||||
tntEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> {
|
||||
abstractTraceEntity.hide(player);
|
||||
abstractTraceEntity.killEntity();
|
||||
});
|
||||
tntEntityMap.clear();
|
||||
}
|
||||
|
||||
}
|
@ -22,9 +22,7 @@ package de.steamwar.bausystem.world;
|
||||
import de.steamwar.bausystem.commands.CommandFreeze;
|
||||
import de.steamwar.bausystem.commands.CommandTNT;
|
||||
import de.steamwar.bausystem.commands.CommandTPSLimiter;
|
||||
import de.steamwar.bausystem.tracer.TraceManager;
|
||||
import de.steamwar.bausystem.tracer.recorder.RecordManager;
|
||||
import de.steamwar.bausystem.tracer.recorder.TNTRecorder;
|
||||
import de.steamwar.bausystem.tracer.record.RecordStateMachine;
|
||||
import de.steamwar.core.TPSWatcher;
|
||||
import de.steamwar.scoreboard.SWScoreboard;
|
||||
import de.steamwar.scoreboard.ScoreboardCallback;
|
||||
@ -34,7 +32,10 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class BauScoreboard implements Listener {
|
||||
|
||||
@ -62,14 +63,13 @@ public class BauScoreboard implements Listener {
|
||||
strings.add("§2");
|
||||
strings.add("§eTNT§8: " + (!CommandTNT.getInstance().isOn() ? "§aan" : "§caus"));
|
||||
strings.add("§eFreeze§8: " + (CommandFreeze.getInstance().isOn() ? "§aan" : "§caus"));
|
||||
strings.add("§eTrace§8: " + RecordManager.getStatus().getValue());
|
||||
strings.add("§eTrace§8: " + RecordStateMachine.getRecordStatus().getName());
|
||||
strings.add("§eLoader§8: " + (AutoLoader.hasLoader(p) ? "§aan" : "§caus"));
|
||||
|
||||
if (RecordManager.getStatus().isTracing()) {
|
||||
if (RecordStateMachine.getRecordStatus().isTracing()) {
|
||||
strings.add("§3");
|
||||
strings.add("§eTrace-Start§8: §7" + new SimpleDateFormat("HH:mm:ss").format(new Date(TNTRecorder.recordStart)));
|
||||
strings.add("§eTicks§8: §7" + traceTicks());
|
||||
strings.add("§eAnzahl TNT§8: §7" + TraceManager.currentFrameSize());
|
||||
strings.add("§eAnzahl TNT§8: §7" + RecordStateMachine.size());
|
||||
}
|
||||
|
||||
strings.add("§4");
|
||||
@ -83,7 +83,7 @@ public class BauScoreboard implements Listener {
|
||||
}
|
||||
|
||||
private long traceTicks() {
|
||||
return (System.currentTimeMillis() - TNTRecorder.recordStart) / 50;
|
||||
return (System.currentTimeMillis() - RecordStateMachine.getStartTime()) / 50;
|
||||
}
|
||||
|
||||
private String tpsColor() {
|
||||
@ -103,4 +103,5 @@ public class BauScoreboard implements Listener {
|
||||
}
|
||||
return "§8/§7" + CommandTPSLimiter.getCurrentTPSLimit();
|
||||
}
|
||||
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
Hier scheint eine Überprüfung auf Waterlogged-Blöcke zu fehlen (vgl. FightSystem isWater)
Ist nun eingebaut