Tracer-entity #147
@ -1,30 +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.Material;
|
||||
|
||||
class TNTTracer_12 {
|
||||
private TNTTracer_12(){}
|
||||
|
||||
static Material getMaterial(){
|
||||
return Material.STAINED_GLASS;
|
||||
}
|
||||
}
|
53
BauSystem_12/src/de/steamwar/bausystem/tracer/TraceTNT_12.java
Normale Datei
53
BauSystem_12/src/de/steamwar/bausystem/tracer/TraceTNT_12.java
Normale Datei
@ -0,0 +1,53 @@
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
import net.minecraft.server.v1_12_R1.PacketPlayOutEntityDestroy;
|
||||
import net.minecraft.server.v1_12_R1.PacketPlayOutSpawnEntity;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class TraceTNT_12 {
|
||||
|
||||
// public PacketPlayOutSpawnEntity(Entity var1, int var2, int var3) {
|
||||
// this.a = var1.getId();
|
||||
// this.b = var1.getUniqueID();
|
||||
// this.c = var1.locX;
|
||||
// this.d = var1.locY;
|
||||
// this.e = var1.locZ;
|
||||
// this.i = MathHelper.d(var1.pitch * 256.0F / 360.0F);
|
||||
// this.j = MathHelper.d(var1.yaw * 256.0F / 360.0F);
|
||||
// this.k = var2;
|
||||
// this.l = var3;
|
||||
// double var4 = 3.9D;
|
||||
// this.f = (int)(MathHelper.a(var1.motX, -3.9D, 3.9D) * 8000.0D);
|
||||
// this.g = (int)(MathHelper.a(var1.motY, -3.9D, 3.9D) * 8000.0D);
|
||||
// this.h = (int)(MathHelper.a(var1.motZ, -3.9D, 3.9D) * 8000.0D);
|
||||
// }
|
||||
|
||||
static void showTNT(int entityID, Player player, float... position) {
|
||||
PacketPlayOutSpawnEntity spawnEntity = new PacketPlayOutSpawnEntity();
|
||||
ReflectionsUtils.setField("a", spawnEntity, entityID);
|
||||
ReflectionsUtils.setField("b", spawnEntity, UUID.randomUUID());
|
||||
ReflectionsUtils.setField("c", spawnEntity, position[0]);
|
||||
ReflectionsUtils.setField("d", spawnEntity, position[1]);
|
||||
ReflectionsUtils.setField("e", spawnEntity, position[2]);
|
||||
ReflectionsUtils.setField("i", spawnEntity, 0);
|
||||
ReflectionsUtils.setField("j", spawnEntity, 0);
|
||||
// EntityType
|
||||
ReflectionsUtils.setField("k", spawnEntity, 0);
|
||||
ReflectionsUtils.setField("l", spawnEntity, 0);
|
||||
ReflectionsUtils.setField("f", spawnEntity, 0);
|
||||
ReflectionsUtils.setField("g", spawnEntity, 0);
|
||||
ReflectionsUtils.setField("h", spawnEntity, 0);
|
||||
|
||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(spawnEntity);
|
||||
}
|
||||
|
||||
static void hideTNT(int entityID, Player player, float... position) {
|
||||
PacketPlayOutEntityDestroy deleteEntity = new PacketPlayOutEntityDestroy(entityID);
|
||||
|
||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(deleteEntity);
|
||||
}
|
||||
|
||||
}
|
@ -1,30 +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.Material;
|
||||
|
||||
class TNTTracer_15 {
|
||||
private TNTTracer_15(){}
|
||||
|
||||
static Material getMaterial(boolean updatePoint){
|
||||
return updatePoint ? Material.LIME_STAINED_GLASS : Material.RED_STAINED_GLASS;
|
||||
}
|
||||
}
|
37
BauSystem_15/src/de/steamwar/bausystem/tracer/TraceTNT_15.java
Normale Datei
37
BauSystem_15/src/de/steamwar/bausystem/tracer/TraceTNT_15.java
Normale Datei
@ -0,0 +1,37 @@
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
import net.minecraft.server.v1_15_R1.EntityTypes;
|
||||
import net.minecraft.server.v1_15_R1.PacketPlayOutEntityDestroy;
|
||||
import net.minecraft.server.v1_15_R1.PacketPlayOutSpawnEntity;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class TraceTNT_15 {
|
||||
|
||||
static void showTNT(int entityID, Player player, float... position) {
|
||||
PacketPlayOutSpawnEntity spawnEntity = new PacketPlayOutSpawnEntity();
|
||||
ReflectionsUtils.setField("a", spawnEntity, entityID);
|
||||
ReflectionsUtils.setField("b", spawnEntity, UUID.randomUUID());
|
||||
ReflectionsUtils.setField("c", spawnEntity, position[0]);
|
||||
ReflectionsUtils.setField("d", spawnEntity, position[1]);
|
||||
ReflectionsUtils.setField("e", spawnEntity, position[2]);
|
||||
ReflectionsUtils.setField("i", spawnEntity, 0);
|
||||
ReflectionsUtils.setField("j", spawnEntity, 0);
|
||||
ReflectionsUtils.setField("k", spawnEntity, EntityTypes.FALLING_BLOCK);
|
||||
ReflectionsUtils.setField("l", spawnEntity, 0);
|
||||
ReflectionsUtils.setField("f", spawnEntity, 0);
|
||||
ReflectionsUtils.setField("g", spawnEntity, 0);
|
||||
ReflectionsUtils.setField("h", spawnEntity, 0);
|
||||
|
||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(spawnEntity);
|
||||
}
|
||||
|
||||
static void hideTNT(int entityID, Player player, float... position) {
|
||||
PacketPlayOutEntityDestroy deleteEntity = new PacketPlayOutEntityDestroy(entityID);
|
||||
|
||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(deleteEntity);
|
||||
}
|
||||
|
||||
}
|
39
BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionsUtils.java
Normale Datei
39
BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionsUtils.java
Normale Datei
@ -0,0 +1,39 @@
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ReflectionsUtils {
|
||||
|
||||
private static Map<String, Field> fieldMap = new LinkedHashMap<String, Field>() {
|
||||
@Override
|
||||
protected boolean removeEldestEntry(Map.Entry<String, Field> eldest) {
|
||||
return size() > 100;
|
||||
}
|
||||
};
|
||||
|
||||
@SuppressWarnings({"java:S3011"})
|
||||
static void setField(String fieldName, Object object, Object fieldValue) {
|
||||
String cacheName = object.getClass().getTypeName() + ":" + fieldName;
|
||||
Field field;
|
||||
if (fieldMap.containsKey(cacheName)) {
|
||||
field = fieldMap.get(cacheName);
|
||||
} else {
|
||||
try {
|
||||
field = object.getClass().getDeclaredField(fieldName);
|
||||
} catch (NoSuchFieldException e) {
|
||||
return;
|
||||
}
|
||||
fieldMap.put(cacheName, field);
|
||||
}
|
||||
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
field.set(object, fieldValue);
|
||||
} catch (IllegalAccessException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -20,9 +20,7 @@
|
||||
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.tracer.ExplodeListener;
|
||||
import de.steamwar.bausystem.world.*;
|
||||
import de.steamwar.core.CommandRemover;
|
||||
import de.steamwar.core.Core;
|
||||
@ -134,10 +132,10 @@ public class BauSystem extends JavaPlugin implements Listener {
|
||||
Bukkit.getPluginManager().registerEvents(this, this);
|
||||
Bukkit.getPluginManager().registerEvents(new RegionListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new BauScoreboard(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new TraceListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new ExplodeListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new ClipboardListener(), this);
|
||||
new AFKStopper();
|
||||
TNTTracer.init();
|
||||
// TNTTracer.init();
|
||||
|
||||
autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 1200);
|
||||
}
|
||||
@ -182,7 +180,7 @@ public class BauSystem extends JavaPlugin implements Listener {
|
||||
Player p = e.getPlayer();
|
||||
p.setOp(true);
|
||||
|
||||
ShowManager.add(p);
|
||||
// ShowManager.add(p);
|
||||
|
||||
if (Core.getVersion() == 15)
|
||||
Bukkit.getWorlds().get(0).setGameRule(GameRule.REDUCED_DEBUG_INFO, false);
|
||||
|
@ -21,9 +21,8 @@ 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.RecordManager;
|
||||
import de.steamwar.bausystem.tracer.TraceManager;
|
||||
import de.steamwar.bausystem.tracer.recorder.RecordManager;
|
||||
import de.steamwar.bausystem.world.Welt;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@ -69,19 +68,27 @@ public class CommandTrace implements CommandExecutor {
|
||||
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "start":
|
||||
RecordManager.commandStart();
|
||||
break;
|
||||
case "stop":
|
||||
RecordManager.commandStop();
|
||||
break;
|
||||
case "toggleauto":
|
||||
case "auto":
|
||||
RecordManager.tracer(player, args);
|
||||
RecordManager.commandAuto();
|
||||
break;
|
||||
case "show":
|
||||
TraceManager.commandShow(player);
|
||||
break;
|
||||
case "hide":
|
||||
TraceManager.commandHide(player);
|
||||
break;
|
||||
case "toggleshow":
|
||||
case "interpolate":
|
||||
case "distance":
|
||||
if (tracer(player, args)) {
|
||||
/*if (tracer(player, args)) {
|
||||
help(player);
|
||||
}
|
||||
}*/
|
||||
break;
|
||||
case "list":
|
||||
case "gui":
|
||||
@ -99,7 +106,7 @@ public class CommandTrace implements CommandExecutor {
|
||||
}
|
||||
|
||||
private boolean delete(Player player, String[] args) {
|
||||
if (args.length == 2) {
|
||||
/*if (args.length == 2) {
|
||||
try {
|
||||
TraceManager.delete(Integer.parseInt(args[1]));
|
||||
player.sendMessage(BauSystem.PREFIX + "§cTNT-Positionen mit ID " + args[1] + " gelöscht");
|
||||
@ -108,15 +115,16 @@ public class CommandTrace implements CommandExecutor {
|
||||
} catch (NumberFormatException e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
TraceManager.deleteAll();
|
||||
}*/
|
||||
TraceManager.commandDelete();
|
||||
// TraceManager.deleteAll();
|
||||
player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen gelöscht");
|
||||
ShowManager.globalDirty();
|
||||
// ShowManager.globalDirty();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean tracer(Player player, String[] args) {
|
||||
/*public boolean tracer(Player player, String[] args) {
|
||||
ShowManager.ShowStatus showStatus = ShowManager.showMap.get(player.getUniqueId().toString());
|
||||
showStatus.dirty = true;
|
||||
switch (args[0].toLowerCase()) {
|
||||
@ -240,5 +248,5 @@ public class CommandTrace implements CommandExecutor {
|
||||
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.RecordManager;
|
||||
import de.steamwar.bausystem.tracer.RecordStatus;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
@ -39,7 +40,7 @@ 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) {
|
||||
if (RecordManager.getRecordStatus() == RecordStatus.IDLE || RecordManager.getRecordStatus() == RecordStatus.IDLE_AUTO) {
|
||||
tabComplete.add("start");
|
||||
} else {
|
||||
tabComplete.add("stop");
|
||||
|
19
BauSystem_Main/src/de/steamwar/bausystem/tracer/ExplodeListener.java
Normale Datei
19
BauSystem_Main/src/de/steamwar/bausystem/tracer/ExplodeListener.java
Normale Datei
@ -0,0 +1,19 @@
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
|
||||
public class ExplodeListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
if (!(event.getEntity() instanceof TNTPrimed)) return;
|
||||
|
||||
RecordManager.tntExplode();
|
||||
TraceManager.tntExplode((TNTPrimed) event.getEntity());
|
||||
}
|
||||
|
||||
}
|
87
BauSystem_Main/src/de/steamwar/bausystem/tracer/RecordManager.java
Normale Datei
87
BauSystem_Main/src/de/steamwar/bausystem/tracer/RecordManager.java
Normale Datei
@ -0,0 +1,87 @@
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.commands.CommandTPSLimiter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class RecordManager {
|
||||
|
||||
private static final World world = Bukkit.getWorlds().get(0);
|
||||
|
||||
private static RecordStatus recordStatus = RecordStatus.IDLE;
|
||||
|
||||
private static BukkitTask recorder = null;
|
||||
private static long startTime = 0;
|
||||
private static long lastExplosion = 0;
|
||||
|
||||
public static void commandStart() {
|
||||
recordStatus = RecordStatus.RECORD;
|
||||
recordStart();
|
||||
}
|
||||
|
||||
public static void commandStop() {
|
||||
recordStatus = RecordStatus.IDLE;
|
||||
recordStop();
|
||||
}
|
||||
|
||||
public static void commandAuto() {
|
||||
if (recordStatus != RecordStatus.IDLE) {
|
||||
return;
|
||||
}
|
||||
if (recordStatus == RecordStatus.IDLE_AUTO) {
|
||||
recordStatus = RecordStatus.IDLE;
|
||||
} else {
|
||||
recordStatus = RecordStatus.IDLE_AUTO;
|
||||
}
|
||||
}
|
||||
|
||||
public static void tntExplode() {
|
||||
if (recordStatus == RecordStatus.RECORD_AUTO) {
|
||||
lastExplosion = System.currentTimeMillis();
|
||||
return;
|
||||
}
|
||||
if (recordStatus != RecordStatus.IDLE_AUTO) {
|
||||
return;
|
||||
}
|
||||
lastExplosion = System.currentTimeMillis();
|
||||
recordStatus = RecordStatus.RECORD_AUTO;
|
||||
recordStart();
|
||||
}
|
||||
|
||||
private static void recordStart() {
|
||||
if (recorder != null) return;
|
||||
startTime = System.currentTimeMillis();
|
||||
recorder = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> {
|
||||
world.getEntitiesByClass(TNTPrimed.class).forEach(TraceManager::tntAdd);
|
||||
recordAutoStop();
|
||||
}, 1, 1);
|
||||
}
|
||||
|
||||
private static void recordStop() {
|
||||
if (recorder == null) return;
|
||||
recorder.cancel();
|
||||
recorder = null;
|
||||
startTime = 0;
|
||||
TraceManager.recordStop();
|
||||
}
|
||||
|
||||
private static void recordAutoStop() {
|
||||
if (recordStatus != RecordStatus.RECORD_AUTO) return;
|
||||
if (System.currentTimeMillis() - lastExplosion > (20.0 / CommandTPSLimiter.getCurrentTPSLimit()) * 50 * 80) {
|
||||
recordStatus = RecordStatus.IDLE_AUTO;
|
||||
recordStop();
|
||||
}
|
||||
}
|
||||
|
||||
public static RecordStatus getRecordStatus() {
|
||||
return recordStatus;
|
||||
}
|
||||
|
||||
public static long getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package de.steamwar.bausystem.tracernew.data;
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
public enum RecordStatus {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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 +1,48 @@
|
||||
/*
|
||||
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.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class TraceManager {
|
||||
private TraceManager(){}
|
||||
|
||||
private static Map<Integer, List<Integer>> frameMap = new HashMap<>();
|
||||
private static Map<Integer, TNTTrace> traceMap = new HashMap<>();
|
||||
private static Map<TNTPrimed, TraceTNT> traceTNTMap = new HashMap<>();
|
||||
private static Set<TraceTNT> traceTNTSet = new HashSet<>();
|
||||
|
||||
private static int currentFrame;
|
||||
|
||||
private static int currentID = 0;
|
||||
private static synchronized int generateID() {
|
||||
return currentID++;
|
||||
public static void recordStop() {
|
||||
traceTNTMap.clear();
|
||||
}
|
||||
|
||||
public static void startFrame() {
|
||||
currentFrame = generateID();
|
||||
frameMap.put(currentFrame, new ArrayList<>());
|
||||
public static void tntExplode(TNTPrimed tntPrimed) {
|
||||
if (!traceTNTMap.containsKey(tntPrimed)) return;
|
||||
traceTNTMap.remove(tntPrimed).explosion(tntPrimed);
|
||||
}
|
||||
|
||||
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 void tntAdd(TNTPrimed tntPrimed) {
|
||||
TraceTNT traceTNT = new TraceTNT(tntPrimed);
|
||||
traceTNTMap.put(tntPrimed, traceTNT);
|
||||
traceTNTSet.add(traceTNT);
|
||||
}
|
||||
|
||||
public static TNTTrace getTrace(int id) {
|
||||
return traceMap.get(id);
|
||||
public static void commandDelete() {
|
||||
traceTNTMap.clear();
|
||||
traceTNTSet.clear();
|
||||
}
|
||||
|
||||
public static Set<Integer> getAllTraces() {
|
||||
return traceMap.keySet();
|
||||
public static int getRecordSize() {
|
||||
return traceTNTMap.size();
|
||||
}
|
||||
|
||||
public static List<Integer> getFrame(int frameID) {
|
||||
return new ArrayList<>(frameMap.getOrDefault(frameID, new ArrayList<>()));
|
||||
public static void commandShow(Player player) {
|
||||
traceTNTSet.forEach(traceTNT -> traceTNT.showTrace(player));
|
||||
}
|
||||
|
||||
public static int currentFrameSize() {
|
||||
if (!frameMap.containsKey(currentFrame)) return 0;
|
||||
return frameMap.get(currentFrame).size();
|
||||
public static void commandHide(Player player) {
|
||||
traceTNTSet.forEach(traceTNT -> traceTNT.hideTrace(player));
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
97
BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceTNT.java
Normale Datei
97
BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceTNT.java
Normale Datei
@ -0,0 +1,97 @@
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
import de.steamwar.core.Core;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class TraceTNT {
|
||||
|
||||
private static int traceID = 0;
|
||||
|
||||
private int id = traceID++;
|
||||
private float[] source = new float[3];
|
||||
private float[] explosion = new float[3];
|
||||
private int index = 0;
|
||||
private float[] position = new float[240];
|
||||
private float[] velocity = new float[240];
|
||||
|
||||
public TraceTNT(TNTPrimed tntPrimed) {
|
||||
source[0] = (float) tntPrimed.getLocation().getX();
|
||||
source[1] = (float) tntPrimed.getLocation().getY();
|
||||
source[2] = (float) tntPrimed.getLocation().getZ();
|
||||
}
|
||||
|
||||
public void explosion(TNTPrimed tntPrimed) {
|
||||
explosion[0] = (float) tntPrimed.getLocation().getX();
|
||||
explosion[1] = (float) tntPrimed.getLocation().getY();
|
||||
explosion[2] = (float) tntPrimed.getLocation().getZ();
|
||||
}
|
||||
|
||||
public void add(TNTPrimed tntPrimed) {
|
||||
if (index > position.length) return;
|
||||
position[index + 0] = (float) tntPrimed.getLocation().getX();
|
||||
position[index + 1] = (float) tntPrimed.getLocation().getY();
|
||||
position[index + 2] = (float) tntPrimed.getLocation().getZ();
|
||||
velocity[index + 0] = (float) tntPrimed.getVelocity().getX();
|
||||
velocity[index + 1] = (float) tntPrimed.getVelocity().getY();
|
||||
velocity[index + 2] = (float) tntPrimed.getVelocity().getZ();
|
||||
index += 3;
|
||||
}
|
||||
|
||||
public long size() {
|
||||
long size = 0;
|
||||
|
||||
// id:
|
||||
size += 32;
|
||||
|
||||
// index:
|
||||
size += 32;
|
||||
|
||||
// source:
|
||||
size += source.length * 32;
|
||||
|
||||
// explosion:
|
||||
size += explosion.length * 32;
|
||||
|
||||
// position:
|
||||
size += position.length * 32;
|
||||
|
||||
// velocity:
|
||||
size += velocity.length * 32;
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
public void showTrace(Player player) {
|
||||
int entityID = Integer.MAX_VALUE - id * 200;
|
||||
|
||||
tnt(entityID, player, source, TraceTNT_15::showTNT, TraceTNT_12::showTNT);
|
||||
}
|
||||
|
||||
public void hideTrace(Player player) {
|
||||
int entityID = Integer.MAX_VALUE - id * 200;
|
||||
|
||||
tnt(entityID, player, source, TraceTNT_15::hideTNT, TraceTNT_12::hideTNT);
|
||||
}
|
||||
|
||||
private void tnt(int entityID, Player player, float[] position, VersionConsumer<Integer, Player, float[]> version15, VersionConsumer<Integer, Player, float[]> versionDefault) {
|
||||
if (position.length != 3) return;
|
||||
switch (Core.getVersion()) {
|
||||
case 15:
|
||||
version15.accept(entityID, player, position);
|
||||
break;
|
||||
default:
|
||||
versionDefault.accept(entityID, player, position);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private interface VersionConsumer<K, V, S> {
|
||||
|
||||
void accept(K k, V v, S s);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package de.steamwar.bausystem.tracernew;
|
||||
|
||||
import de.steamwar.bausystem.commands.CommandTPSLimiter;
|
||||
import de.steamwar.bausystem.tracernew.data.RecordStatus;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
||||
public class DataHolder {
|
||||
|
||||
public static final World world = Bukkit.getWorlds().get(0);
|
||||
|
||||
public static RecordStatus status = RecordStatus.IDLE;
|
||||
public static long recordStart = System.currentTimeMillis();
|
||||
public static long lastExplosion = System.currentTimeMillis();
|
||||
|
||||
public static boolean isAutoStop() {
|
||||
if (!isRecordingAuto()) return false;
|
||||
return System.currentTimeMillis() - lastExplosion > (20.0 / CommandTPSLimiter.getCurrentTPSLimit()) * 50 * 80;
|
||||
}
|
||||
|
||||
public static boolean isRecording() {
|
||||
return status == RecordStatus.RECORD || status == RecordStatus.RECORD_AUTO;
|
||||
}
|
||||
|
||||
public static boolean isRecordingAuto() {
|
||||
return status == RecordStatus.RECORD_AUTO;
|
||||
}
|
||||
|
||||
public static boolean isRecordingNotAuto() {
|
||||
return status == RecordStatus.RECORD;
|
||||
}
|
||||
|
||||
public static boolean isIdle() {
|
||||
return status == RecordStatus.IDLE || status == RecordStatus.IDLE_AUTO;
|
||||
}
|
||||
|
||||
public static boolean isIdleAuto() {
|
||||
return status == RecordStatus.IDLE_AUTO;
|
||||
}
|
||||
|
||||
public static boolean isIdleNotAuto() {
|
||||
return status == RecordStatus.IDLE;
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
package de.steamwar.bausystem.tracernew;
|
||||
|
||||
public class TraceHolder {
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
package de.steamwar.bausystem.tracernew.data;
|
||||
|
||||
public class TNTTrace {
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package de.steamwar.bausystem.tracernew.recorder;
|
||||
|
||||
import de.steamwar.bausystem.tracernew.DataHolder;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
|
||||
public class ExplodeListener implements Listener {
|
||||
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
if (!(event.getEntity() instanceof TNTPrimed))
|
||||
return;
|
||||
|
||||
if (DataHolder.isRecordingAuto())
|
||||
RecordManager.stopAuto();
|
||||
if (DataHolder.isIdleAuto())
|
||||
RecordManager.updateAuto();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
package de.steamwar.bausystem.tracernew.recorder;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.tracer.TraceManager;
|
||||
import de.steamwar.bausystem.tracernew.DataHolder;
|
||||
import de.steamwar.bausystem.tracernew.data.RecordStatus;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import static de.steamwar.bausystem.tracernew.recorder.TNTRecorder.*;
|
||||
|
||||
public class RecordManager {
|
||||
|
||||
private RecordManager() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
public static void recordCommands(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 (DataHolder.isIdleNotAuto() || DataHolder.isRecordingNotAuto()) {
|
||||
player.sendMessage(BauSystem.PREFIX + "§cAutomatischer TNT-Tracer deaktiviert");
|
||||
} else {
|
||||
player.sendMessage(BauSystem.PREFIX + "§aAutomatischer TNT-Tracer aktiviert");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void toggleAuto() {
|
||||
switch (DataHolder.status) {
|
||||
case IDLE:
|
||||
DataHolder.status = RecordStatus.IDLE_AUTO;
|
||||
break;
|
||||
case RECORD:
|
||||
DataHolder.status = RecordStatus.RECORD_AUTO;
|
||||
break;
|
||||
case IDLE_AUTO:
|
||||
DataHolder.status = RecordStatus.IDLE;
|
||||
break;
|
||||
case RECORD_AUTO:
|
||||
DataHolder.status = RecordStatus.RECORD;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void start() {
|
||||
DataHolder.status = RecordStatus.RECORD;
|
||||
TraceManager.startFrame();
|
||||
startRecording();
|
||||
}
|
||||
|
||||
public static void startAuto() {
|
||||
DataHolder.status = RecordStatus.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();
|
||||
}
|
||||
|
||||
public static void stop() {
|
||||
DataHolder.status = RecordStatus.IDLE;
|
||||
stopRecording();
|
||||
TraceManager.stopFrame();
|
||||
}
|
||||
|
||||
static void stopAuto() {
|
||||
DataHolder.status = RecordStatus.IDLE_AUTO;
|
||||
Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§7Automatischer TNT-Tracer §8- §aAufnahme gestoppt")));
|
||||
stopRecording();
|
||||
TraceManager.stopFrame();
|
||||
}
|
||||
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package de.steamwar.bausystem.tracernew.recorder;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.tracer.TraceListener;
|
||||
import de.steamwar.bausystem.tracernew.DataHolder;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static de.steamwar.bausystem.tracernew.recorder.RecordManager.stopAuto;
|
||||
|
||||
public class TNTRecorder {
|
||||
|
||||
private static BukkitTask task = null;
|
||||
|
||||
static void update() {
|
||||
if (task == null) return;
|
||||
if (!DataHolder.isRecordingAuto()) return;
|
||||
DataHolder.lastExplosion = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
static void startRecording() {
|
||||
if (task != null) return;
|
||||
DataHolder.recordStart = System.currentTimeMillis();
|
||||
DataHolder.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() {
|
||||
DataHolder.world.getEntitiesByClass(TNTPrimed.class).stream()
|
||||
Stream<TNTPrimed> tntPrimedStream = DataHolder.world.getEntities()
|
||||
.stream()
|
||||
.filter(e -> e instanceof TNTPrimed)
|
||||
.map(e -> (TNTPrimed)e);
|
||||
TraceListener.onTick(tntPrimedStream);
|
||||
|
||||
if (DataHolder.isAutoStop()) {
|
||||
stopAuto();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -22,9 +22,8 @@ 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.RecordManager;
|
||||
import de.steamwar.bausystem.tracer.TraceManager;
|
||||
import de.steamwar.bausystem.tracer.recorder.RecordManager;
|
||||
import de.steamwar.bausystem.tracer.recorder.TNTRecorder;
|
||||
import de.steamwar.core.TPSWatcher;
|
||||
import de.steamwar.scoreboard.SWScoreboard;
|
||||
import de.steamwar.scoreboard.ScoreboardCallback;
|
||||
@ -62,14 +61,14 @@ 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: " + RecordManager.getRecordStatus().getName());
|
||||
strings.add("§eLoader§8: " + (AutoLoader.hasLoader(p) ? "§aan" : "§caus"));
|
||||
|
||||
if (RecordManager.getStatus().isTracing()) {
|
||||
if (RecordManager.getRecordStatus().isTracing()) {
|
||||
strings.add("§3");
|
||||
strings.add("§eTrace-Start§8: §7" + new SimpleDateFormat("HH:mm:ss").format(new Date(TNTRecorder.recordStart)));
|
||||
strings.add("§eTrace-Start§8: §7" + new SimpleDateFormat("HH:mm:ss").format(new Date(RecordManager.getStartTime())));
|
||||
strings.add("§eTicks§8: §7" + traceTicks());
|
||||
strings.add("§eAnzahl TNT§8: §7" + TraceManager.currentFrameSize());
|
||||
strings.add("§eAnzahl TNT§8: §7" + TraceManager.getRecordSize());
|
||||
}
|
||||
|
||||
strings.add("§4");
|
||||
@ -83,7 +82,7 @@ public class BauScoreboard implements Listener {
|
||||
}
|
||||
|
||||
private long traceTicks() {
|
||||
return (System.currentTimeMillis() - TNTRecorder.recordStart) / 50;
|
||||
return (System.currentTimeMillis() - RecordManager.getStartTime()) / 50;
|
||||
}
|
||||
|
||||
private String tpsColor() {
|
||||
@ -103,4 +102,5 @@ public class BauScoreboard implements Listener {
|
||||
}
|
||||
return "§8/§7" + CommandTPSLimiter.getCurrentTPSLimit();
|
||||
}
|
||||
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren