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);
}
public static boolean inWater(World world, TNTPosition tntPosition) {
Material material = tntPosition.getLocation().toLocation(world).getBlock().getType();
public static boolean inWater(World world, Vector tntPosition) {
Material material = tntPosition.toLocation(world).getBlock().getType();
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.util.Vector;
import java.lang.reflect.Field;
class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity {
private Vector position;
@ -39,33 +41,31 @@ class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity {
this.dropItem = false;
this.setCustomNameVisible(true);
if (exploded) {
this.setCustomName("Bum");
this.setCustomName("Bumm");
}
display(player);
}
@Override
public void move(EnumMoveType enummovetype, double dx, double dy, double dz) {
}
@Override
public AbstractTraceEntity display(Player player) {
PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(this, 0);
ReflectionUtils.setValue("c", packetPlayOutSpawnEntity, position.getX());
ReflectionUtils.setValue("d", packetPlayOutSpawnEntity, position.getY());
ReflectionUtils.setValue("e", packetPlayOutSpawnEntity, position.getZ());
ReflectionUtils.setValue("f", packetPlayOutSpawnEntity, 0);
ReflectionUtils.setValue("g", packetPlayOutSpawnEntity, 0);
ReflectionUtils.setValue("h", packetPlayOutSpawnEntity, 0);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutSpawnEntity);
// Todo:
// Reflection needed?
setValue("c", packetPlayOutSpawnEntity, position.getX());
setValue("d", packetPlayOutSpawnEntity, position.getY());
setValue("e", packetPlayOutSpawnEntity, position.getZ());
setValue("f", packetPlayOutSpawnEntity, 0);
setValue("g", packetPlayOutSpawnEntity, 0);
setValue("h", packetPlayOutSpawnEntity, 0);
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
playerConnection.sendPacket(packetPlayOutSpawnEntity);
PacketPlayOutEntityTeleport packetPlayOutEntityTeleport = new PacketPlayOutEntityTeleport(this);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityTeleport);
playerConnection.sendPacket(packetPlayOutEntityTeleport);
PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityMetadata);
playerConnection.sendPacket(packetPlayOutEntityMetadata);
return this;
}
@ -78,9 +78,14 @@ class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity {
return this;
}
@Override
public void remove() {
killEntity();
private 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

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

Datei anzeigen

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

Datei anzeigen

@ -27,6 +27,6 @@ public interface AbstractTraceEntity {
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 ClipboardListener(), this);
new AFKStopper();
// TNTTracer.init();
autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 1200);
}
@ -166,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);
}

Datei anzeigen

@ -23,8 +23,13 @@ import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.tracer.record.RecordStateMachine;
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.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 org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@ -98,7 +103,31 @@ public class CommandTrace implements CommandExecutor {
player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen gelöscht");
break;
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");
break;
case "hide":

Datei anzeigen

@ -43,8 +43,13 @@ public class Recorder implements Listener {
Recorder() {
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();
// To trace TNT initial positions with AutoTracer
if (RecordStateMachine.getRecordStatus() == RecordStatus.IDLE_AUTO) {
run();
}
}
void stopRecording() {

Datei anzeigen

@ -17,34 +17,8 @@ public class TraceShowManager implements Listener {
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);
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);
StoredRecords.showAll(showMode);
}

Datei anzeigen

@ -21,9 +21,9 @@
package de.steamwar.bausystem.tracer.show.mode;
import de.steamwar.bausystem.tracer.*;
import de.steamwar.core.Core;
import de.steamwar.core.VersionedCallable;
import de.steamwar.bausystem.tracer.AbstractTraceEntity;
import de.steamwar.bausystem.tracer.RoundedTNTPosition;
import de.steamwar.bausystem.tracer.TNTPosition;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
@ -32,13 +32,10 @@ import java.util.Map;
public class Advanced extends Basic {
private final Player player;
private Map<RoundedTNTPosition, AbstractTraceEntity> updateEntityMap = new HashMap<>();
public Advanced(Player player) {
super(player);
this.player = player;
}
@Override
@ -46,11 +43,11 @@ public class Advanced extends Basic {
super.show(position);
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;
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());
} else {
updatePointXZ = updatePointY.clone().setZ(position.getLocation().getZ());
@ -61,16 +58,14 @@ public class Advanced extends Basic {
if (updateEntityMap.containsKey(updatePointPosition)) {
return;
}
updateEntityMap.put(updatePointPosition, VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.create(player.getWorld(), updatePointY, player, false, false), 8),
new VersionedCallable<>(() -> TNTTracer_15.create(player.getWorld(), updatePointY, player, false, false), 14)));
updateEntityMap.put(updatePointPosition, createEntity(updatePointY, false, false));
}
if (!position.getLocation().equals(updatePointXZ)) {
RoundedTNTPosition updatePointPosition = new RoundedTNTPosition(updatePointXZ);
if (updateEntityMap.containsKey(updatePointPosition)) {
return;
}
updateEntityMap.put(updatePointPosition, VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.create(player.getWorld(), updatePointXZ, player, false, false), 8),
new VersionedCallable<>(() -> TNTTracer_15.create(player.getWorld(), updatePointXZ, player, false, false), 14)));
updateEntityMap.put(updatePointPosition, createEntity(updatePointXZ, false, false));
}
}
@ -80,7 +75,7 @@ public class Advanced extends Basic {
updateEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> {
abstractTraceEntity.hide(player);
abstractTraceEntity.remove();
abstractTraceEntity.killEntity();
});
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.TNTTracer_12;
import de.steamwar.bausystem.tracer.TNTTracer_15;
import de.steamwar.core.Core;
import de.steamwar.core.VersionedCallable;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;
@ -39,18 +39,11 @@ public class AdvancedNoWater extends Advanced {
@Override
public void show(TNTPosition position) {
boolean b;
switch (Core.getVersion()) {
case 12:
b = TNTTracer_12.inWater(world, position);
break;
default:
b = TNTTracer_15.inWater(world, position);
break;
if (VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.inWater(world, position.getLocation()), 8),
new VersionedCallable<>(() -> TNTTracer_15.inWater(world, position.getLocation()), 14))) {
return;
}
if (!b) {
super.show(position);
}
}
}

Datei anzeigen

@ -4,13 +4,14 @@ import de.steamwar.bausystem.tracer.*;
import de.steamwar.bausystem.tracer.show.ShowMode;
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 {
private final Player player;
protected final Player player;
private Map<RoundedTNTPosition, AbstractTraceEntity> tntEntityMap = new HashMap<>();
@ -24,15 +25,19 @@ public class Basic implements ShowMode {
if (tntEntityMap.containsKey(roundedTNTPosition)) {
return;
}
tntEntityMap.put(roundedTNTPosition, VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.create(player.getWorld(), position.getLocation(), player, position.isExploded(), true), 8),
new VersionedCallable<>(() -> TNTTracer_15.create(player.getWorld(), position.getLocation(), player, position.isExploded(), true), 14)));
tntEntityMap.put(roundedTNTPosition, createEntity(position.getLocation(), position.isExploded(), true));
}
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.remove();
abstractTraceEntity.killEntity();
});
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.TNTTracer_12;
import de.steamwar.bausystem.tracer.TNTTracer_15;
import de.steamwar.core.Core;
import de.steamwar.core.VersionedCallable;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;
@ -39,18 +39,11 @@ public class BasicNoWater extends Basic {
@Override
public void show(TNTPosition position) {
boolean b;
switch (Core.getVersion()) {
case 12:
b = TNTTracer_12.inWater(world, position);
break;
default:
b = TNTTracer_15.inWater(world, position);
break;
if (VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.inWater(world, position.getLocation()), 8),
new VersionedCallable<>(() -> TNTTracer_15.inWater(world, position.getLocation()), 14))) {
return;
}
if (!b) {
super.show(position);
}
}
}