SteamWar/BauSystem
Archiviert
13
0
Add Version Dependant Call for water check
Remove TraceShowManager argument parsing
Remove ReflectionUtils.java
Remove BauSystem comments
Move RoundedTNTPosition
Move TNTPosition
Fix Advanced
Simplify Basic.createEntity
Dieser Commit ist enthalten in:
jojo 2020-12-27 00:13:20 +01:00
Ursprung 7da829eae5
Commit e4f874a4bb
16 geänderte Dateien mit 97 neuen und 150 gelöschten Zeilen

Datei anzeigen

@ -30,8 +30,8 @@ public class TNTTracer_12 {
return new TraceEntity_12(world, tntPosition, player, exploded, tnt); return new TraceEntity_12(world, tntPosition, player, exploded, tnt);
} }
public static boolean inWater(World world, TNTPosition tntPosition) { public static boolean inWater(World world, Vector tntPosition) {
Material material = tntPosition.getLocation().toLocation(world).getBlock().getType(); Material material = tntPosition.toLocation(world).getBlock().getType();
return material == Material.WATER || material == Material.STATIONARY_WATER; return material == Material.WATER || material == Material.STATIONARY_WATER;
} }

Datei anzeigen

@ -26,6 +26,8 @@ import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.lang.reflect.Field;
class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity { class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity {
private Vector position; private Vector position;
@ -39,33 +41,31 @@ class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity {
this.dropItem = false; this.dropItem = false;
this.setCustomNameVisible(true); this.setCustomNameVisible(true);
if (exploded) { if (exploded) {
this.setCustomName("Bum"); this.setCustomName("Bumm");
} }
display(player); display(player);
} }
@Override
public void move(EnumMoveType enummovetype, double dx, double dy, double dz) {
}
@Override @Override
public AbstractTraceEntity display(Player player) { public AbstractTraceEntity display(Player player) {
PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(this, 0); PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(this, 0);
ReflectionUtils.setValue("c", packetPlayOutSpawnEntity, position.getX()); // Todo:
ReflectionUtils.setValue("d", packetPlayOutSpawnEntity, position.getY()); // Reflection needed?
ReflectionUtils.setValue("e", packetPlayOutSpawnEntity, position.getZ()); setValue("c", packetPlayOutSpawnEntity, position.getX());
ReflectionUtils.setValue("f", packetPlayOutSpawnEntity, 0); setValue("d", packetPlayOutSpawnEntity, position.getY());
ReflectionUtils.setValue("g", packetPlayOutSpawnEntity, 0); setValue("e", packetPlayOutSpawnEntity, position.getZ());
ReflectionUtils.setValue("h", packetPlayOutSpawnEntity, 0); setValue("f", packetPlayOutSpawnEntity, 0);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutSpawnEntity); setValue("g", packetPlayOutSpawnEntity, 0);
setValue("h", packetPlayOutSpawnEntity, 0);
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
playerConnection.sendPacket(packetPlayOutSpawnEntity);
PacketPlayOutEntityTeleport packetPlayOutEntityTeleport = new PacketPlayOutEntityTeleport(this); PacketPlayOutEntityTeleport packetPlayOutEntityTeleport = new PacketPlayOutEntityTeleport(this);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityTeleport); playerConnection.sendPacket(packetPlayOutEntityTeleport);
PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityMetadata); playerConnection.sendPacket(packetPlayOutEntityMetadata);
return this; return this;
} }
@ -78,9 +78,14 @@ class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity {
return this; return this;
} }
@Override private static void setValue(String field, Object object, Object value) {
public void remove() { try {
killEntity(); Field f = object.getClass().getDeclaredField(field);
f.setAccessible(true);
f.set(object, value);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new SecurityException(e);
}
} }
} }

Datei anzeigen

@ -30,8 +30,8 @@ public class TNTTracer_15 {
return new TraceEntity_15(world, tntPosition, player, exploded, tnt); return new TraceEntity_15(world, tntPosition, player, exploded, tnt);
} }
public static boolean inWater(World world, TNTPosition tntPosition) { public static boolean inWater(World world, Vector tntPosition) {
Material material = tntPosition.getLocation().toLocation(world).getBlock().getType(); Material material = tntPosition.toLocation(world).getBlock().getType();
return material == Material.WATER; return material == Material.WATER;
} }

Datei anzeigen

@ -42,27 +42,20 @@ class TraceEntity_15 extends EntityFallingBlock implements AbstractTraceEntity {
this.dropItem = false; this.dropItem = false;
this.setCustomNameVisible(true); this.setCustomNameVisible(true);
if (exploded) { if (exploded) {
this.setCustomName(new ChatComponentText("Bum")); this.setCustomName(new ChatComponentText("Bumm"));
} }
display(player); display(player);
} }
@Override
public void move(EnumMoveType enummovetype, Vec3D vec3d) {
}
@Override @Override
public AbstractTraceEntity display(Player player) { public AbstractTraceEntity display(Player player) {
if (!tnt) {
System.out.println("DISPLAY");
}
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); 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);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutSpawnEntity); PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
playerConnection.sendPacket(packetPlayOutSpawnEntity);
PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityMetadata); playerConnection.sendPacket(packetPlayOutEntityMetadata);
return this; return this;
} }
@ -75,9 +68,4 @@ class TraceEntity_15 extends EntityFallingBlock implements AbstractTraceEntity {
return this; return this;
} }
@Override
public void remove() {
killEntity();
}
} }

Datei anzeigen

@ -27,6 +27,6 @@ public interface AbstractTraceEntity {
AbstractTraceEntity hide(Player player); AbstractTraceEntity hide(Player player);
void remove(); void killEntity();
} }

Datei anzeigen

@ -1,37 +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.lang.reflect.Field;
public class ReflectionUtils {
@SuppressWarnings({"java:S3011"})
static void setValue(String field, Object object, Object value) {
try {
Field f = object.getClass().getDeclaredField(field);
f.setAccessible(true);
f.set(object, value);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new SecurityException(e);
}
}
}

Datei anzeigen

@ -121,7 +121,6 @@ public class BauSystem extends JavaPlugin implements Listener {
Bukkit.getPluginManager().registerEvents(new BauScoreboard(), this); Bukkit.getPluginManager().registerEvents(new BauScoreboard(), this);
Bukkit.getPluginManager().registerEvents(new ClipboardListener(), this); Bukkit.getPluginManager().registerEvents(new ClipboardListener(), this);
new AFKStopper(); new AFKStopper();
// TNTTracer.init();
autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 1200); autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 1200);
} }
@ -166,8 +165,6 @@ public class BauSystem extends JavaPlugin implements Listener {
Player p = e.getPlayer(); Player p = e.getPlayer();
p.setOp(true); p.setOp(true);
// ShowManager.add(p);
if (Core.getVersion() == 15) if (Core.getVersion() == 15)
Bukkit.getWorlds().get(0).setGameRule(GameRule.REDUCED_DEBUG_INFO, false); Bukkit.getWorlds().get(0).setGameRule(GameRule.REDUCED_DEBUG_INFO, false);
} }

Datei anzeigen

@ -23,8 +23,13 @@ import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.tracer.record.RecordStateMachine; import de.steamwar.bausystem.tracer.record.RecordStateMachine;
import de.steamwar.bausystem.tracer.record.RecordStatus; import de.steamwar.bausystem.tracer.record.RecordStatus;
import de.steamwar.bausystem.tracer.show.ShowMode;
import de.steamwar.bausystem.tracer.show.StoredRecords; import de.steamwar.bausystem.tracer.show.StoredRecords;
import de.steamwar.bausystem.tracer.show.TraceShowManager; import de.steamwar.bausystem.tracer.show.TraceShowManager;
import de.steamwar.bausystem.tracer.show.mode.Advanced;
import de.steamwar.bausystem.tracer.show.mode.AdvancedNoWater;
import de.steamwar.bausystem.tracer.show.mode.Basic;
import de.steamwar.bausystem.tracer.show.mode.BasicNoWater;
import de.steamwar.bausystem.world.Welt; import de.steamwar.bausystem.world.Welt;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
@ -98,7 +103,31 @@ public class CommandTrace implements CommandExecutor {
player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen gelöscht"); player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen gelöscht");
break; break;
case "show": case "show":
TraceShowManager.show(player, args); ShowMode showMode;
if (args.length < 2) {
showMode = new Basic(player);
} else {
switch (args[1].toLowerCase()) {
case "nowater":
case "basic-nowater":
case "basicnowater":
showMode = new BasicNoWater(player);
break;
case "advanced":
showMode = new Advanced(player);
break;
case "advanced-nowater":
case "advancednowater":
showMode = new AdvancedNoWater(player);
break;
case "basic":
case "default":
default:
showMode = new Basic(player);
break;
}
}
TraceShowManager.show(player, showMode);
player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen angezeigt"); player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen angezeigt");
break; break;
case "hide": case "hide":

Datei anzeigen

@ -43,8 +43,13 @@ public class Recorder implements Listener {
Recorder() { Recorder() {
Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin()); Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin());
task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), this::run, 0, 1); task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), this::run, 1, 1);
record = new Record(); record = new Record();
// To trace TNT initial positions with AutoTracer
if (RecordStateMachine.getRecordStatus() == RecordStatus.IDLE_AUTO) {
run();
}
} }
void stopRecording() { void stopRecording() {

Datei anzeigen

@ -17,34 +17,8 @@ public class TraceShowManager implements Listener {
private static final Map<Player, ShowMode> showModes = new HashMap<>(); private static final Map<Player, ShowMode> showModes = new HashMap<>();
public static void show(Player player, String[] args) { public static void show(Player player, ShowMode showMode) {
hide(player); hide(player);
ShowMode showMode;
if (args.length < 2) {
showMode = new Basic(player);
} else {
switch (args[1].toLowerCase()) {
case "nowater":
case "basic-nowater":
case "basicnowater":
showMode = new BasicNoWater(player);
break;
case "advanced":
showMode = new Advanced(player);
break;
case "advanced-nowater":
case "advancednowater":
showMode = new AdvancedNoWater(player);
break;
case "basic":
case "default":
default:
showMode = new Basic(player);
break;
}
}
showModes.put(player, showMode); showModes.put(player, showMode);
StoredRecords.showAll(showMode); StoredRecords.showAll(showMode);
} }

Datei anzeigen

@ -21,9 +21,9 @@
package de.steamwar.bausystem.tracer.show.mode; package de.steamwar.bausystem.tracer.show.mode;
import de.steamwar.bausystem.tracer.*; import de.steamwar.bausystem.tracer.AbstractTraceEntity;
import de.steamwar.core.Core; import de.steamwar.bausystem.tracer.RoundedTNTPosition;
import de.steamwar.core.VersionedCallable; import de.steamwar.bausystem.tracer.TNTPosition;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
@ -32,13 +32,10 @@ import java.util.Map;
public class Advanced extends Basic { public class Advanced extends Basic {
private final Player player;
private Map<RoundedTNTPosition, AbstractTraceEntity> updateEntityMap = new HashMap<>(); private Map<RoundedTNTPosition, AbstractTraceEntity> updateEntityMap = new HashMap<>();
public Advanced(Player player) { public Advanced(Player player) {
super(player); super(player);
this.player = player;
} }
@Override @Override
@ -46,11 +43,11 @@ public class Advanced extends Basic {
super.show(position); super.show(position);
if (position.getPreviousLocation() == null) return; if (position.getPreviousLocation() == null) return;
Vector previousLocation = position.getLocation().clone().subtract(position.getPreviousLocation()); Vector vector = position.getLocation().clone().subtract(position.getPreviousLocation());
Vector updatePointY = previousLocation.clone().setY(position.getLocation().getY()); Vector updatePointY = position.getPreviousLocation().clone().setY(position.getLocation().getY());
Vector updatePointXZ; Vector updatePointXZ;
if (Math.abs(position.getPreviousLocation().getX()) > Math.abs(position.getPreviousLocation().getZ())) { if (Math.abs(vector.getX()) > Math.abs(vector.getZ())) {
updatePointXZ = updatePointY.clone().setX(position.getLocation().getX()); updatePointXZ = updatePointY.clone().setX(position.getLocation().getX());
} else { } else {
updatePointXZ = updatePointY.clone().setZ(position.getLocation().getZ()); updatePointXZ = updatePointY.clone().setZ(position.getLocation().getZ());
@ -61,16 +58,14 @@ public class Advanced extends Basic {
if (updateEntityMap.containsKey(updatePointPosition)) { if (updateEntityMap.containsKey(updatePointPosition)) {
return; return;
} }
updateEntityMap.put(updatePointPosition, VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.create(player.getWorld(), updatePointY, player, false, false), 8), updateEntityMap.put(updatePointPosition, createEntity(updatePointY, false, false));
new VersionedCallable<>(() -> TNTTracer_15.create(player.getWorld(), updatePointY, player, false, false), 14)));
} }
if (!position.getLocation().equals(updatePointXZ)) { if (!position.getLocation().equals(updatePointXZ)) {
RoundedTNTPosition updatePointPosition = new RoundedTNTPosition(updatePointXZ); RoundedTNTPosition updatePointPosition = new RoundedTNTPosition(updatePointXZ);
if (updateEntityMap.containsKey(updatePointPosition)) { if (updateEntityMap.containsKey(updatePointPosition)) {
return; return;
} }
updateEntityMap.put(updatePointPosition, VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.create(player.getWorld(), updatePointXZ, player, false, false), 8), updateEntityMap.put(updatePointPosition, createEntity(updatePointXZ, false, false));
new VersionedCallable<>(() -> TNTTracer_15.create(player.getWorld(), updatePointXZ, player, false, false), 14)));
} }
} }
@ -80,7 +75,7 @@ public class Advanced extends Basic {
updateEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> { updateEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> {
abstractTraceEntity.hide(player); abstractTraceEntity.hide(player);
abstractTraceEntity.remove(); abstractTraceEntity.killEntity();
}); });
updateEntityMap.clear(); updateEntityMap.clear();
} }

Datei anzeigen

@ -24,7 +24,7 @@ package de.steamwar.bausystem.tracer.show.mode;
import de.steamwar.bausystem.tracer.TNTPosition; import de.steamwar.bausystem.tracer.TNTPosition;
import de.steamwar.bausystem.tracer.TNTTracer_12; import de.steamwar.bausystem.tracer.TNTTracer_12;
import de.steamwar.bausystem.tracer.TNTTracer_15; import de.steamwar.bausystem.tracer.TNTTracer_15;
import de.steamwar.core.Core; import de.steamwar.core.VersionedCallable;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -39,18 +39,11 @@ public class AdvancedNoWater extends Advanced {
@Override @Override
public void show(TNTPosition position) { public void show(TNTPosition position) {
boolean b; if (VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.inWater(world, position.getLocation()), 8),
switch (Core.getVersion()) { new VersionedCallable<>(() -> TNTTracer_15.inWater(world, position.getLocation()), 14))) {
case 12: return;
b = TNTTracer_12.inWater(world, position);
break;
default:
b = TNTTracer_15.inWater(world, position);
break;
}
if (!b) {
super.show(position);
} }
super.show(position);
} }
} }

Datei anzeigen

@ -4,13 +4,14 @@ import de.steamwar.bausystem.tracer.*;
import de.steamwar.bausystem.tracer.show.ShowMode; import de.steamwar.bausystem.tracer.show.ShowMode;
import de.steamwar.core.VersionedCallable; import de.steamwar.core.VersionedCallable;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class Basic implements ShowMode { public class Basic implements ShowMode {
private final Player player; protected final Player player;
private Map<RoundedTNTPosition, AbstractTraceEntity> tntEntityMap = new HashMap<>(); private Map<RoundedTNTPosition, AbstractTraceEntity> tntEntityMap = new HashMap<>();
@ -24,15 +25,19 @@ public class Basic implements ShowMode {
if (tntEntityMap.containsKey(roundedTNTPosition)) { if (tntEntityMap.containsKey(roundedTNTPosition)) {
return; return;
} }
tntEntityMap.put(roundedTNTPosition, VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.create(player.getWorld(), position.getLocation(), player, position.isExploded(), true), 8), tntEntityMap.put(roundedTNTPosition, createEntity(position.getLocation(), position.isExploded(), true));
new VersionedCallable<>(() -> TNTTracer_15.create(player.getWorld(), position.getLocation(), player, position.isExploded(), true), 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 @Override
public void hide() { public void hide() {
tntEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> { tntEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> {
abstractTraceEntity.hide(player); abstractTraceEntity.hide(player);
abstractTraceEntity.remove(); abstractTraceEntity.killEntity();
}); });
tntEntityMap.clear(); tntEntityMap.clear();
} }

Datei anzeigen

@ -24,7 +24,7 @@ package de.steamwar.bausystem.tracer.show.mode;
import de.steamwar.bausystem.tracer.TNTPosition; import de.steamwar.bausystem.tracer.TNTPosition;
import de.steamwar.bausystem.tracer.TNTTracer_12; import de.steamwar.bausystem.tracer.TNTTracer_12;
import de.steamwar.bausystem.tracer.TNTTracer_15; import de.steamwar.bausystem.tracer.TNTTracer_15;
import de.steamwar.core.Core; import de.steamwar.core.VersionedCallable;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -39,18 +39,11 @@ public class BasicNoWater extends Basic {
@Override @Override
public void show(TNTPosition position) { public void show(TNTPosition position) {
boolean b; if (VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.inWater(world, position.getLocation()), 8),
switch (Core.getVersion()) { new VersionedCallable<>(() -> TNTTracer_15.inWater(world, position.getLocation()), 14))) {
case 12: return;
b = TNTTracer_12.inWater(world, position);
break;
default:
b = TNTTracer_15.inWater(world, position);
break;
}
if (!b) {
super.show(position);
} }
super.show(position);
} }
} }