diff --git a/src/de/steamwar/lobby/LobbySystem.java b/src/de/steamwar/lobby/LobbySystem.java
index 3385364..fd85f70 100644
--- a/src/de/steamwar/lobby/LobbySystem.java
+++ b/src/de/steamwar/lobby/LobbySystem.java
@@ -19,6 +19,7 @@
package de.steamwar.lobby;
+import de.steamwar.entity.REntityServer;
import de.steamwar.lobby.command.FlyCommand;
import de.steamwar.lobby.command.HologramCommand;
import de.steamwar.lobby.command.ModifyCommand;
@@ -35,6 +36,8 @@ public class LobbySystem extends JavaPlugin {
private static Message message;
private static LobbySystem plugin;
private static Config config;
+ private static REntityServer entityServer;
+ private static REntityServer debugEntityServer;
@Override
public void onLoad() {
@@ -44,6 +47,8 @@ public class LobbySystem extends JavaPlugin {
@Override
public void onEnable() {
message = new Message("de.steamwar.lobby.LobbySystem", getClassLoader());
+ entityServer = new REntityServer();
+ debugEntityServer = new REntityServer();
Fightserver.init();
new Portals();
@@ -89,4 +94,8 @@ public class LobbySystem extends JavaPlugin {
public static Message getMessage() {
return message;
}
+
+ public static REntityServer getEntityServer(boolean debug) {
+ return debug ? debugEntityServer : entityServer;
+ }
}
diff --git a/src/de/steamwar/lobby/command/ModifyCommand.java b/src/de/steamwar/lobby/command/ModifyCommand.java
index 2b698fb..cbd917c 100644
--- a/src/de/steamwar/lobby/command/ModifyCommand.java
+++ b/src/de/steamwar/lobby/command/ModifyCommand.java
@@ -53,6 +53,7 @@ public class ModifyCommand extends SWCommand implements Listener {
return;
modifying.add(player);
+ LobbySystem.getEntityServer(true).addPlayer(player);
player.setGameMode(GameMode.CREATIVE);
player.setOp(true);
}
diff --git a/src/de/steamwar/lobby/display/Displayable.java b/src/de/steamwar/lobby/display/Displayable.java
deleted file mode 100644
index 327b83d..0000000
--- a/src/de/steamwar/lobby/display/Displayable.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * This file is a part of the SteamWar software.
- *
- * Copyright (C) 2021 SteamWar.de-Serverteam
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-package de.steamwar.lobby.display;
-
-import de.steamwar.lobby.listener.BasicListener;
-import org.bukkit.Bukkit;
-import org.bukkit.Location;
-import org.bukkit.entity.Player;
-import org.bukkit.event.EventHandler;
-import org.bukkit.event.HandlerList;
-import org.bukkit.event.player.PlayerJoinEvent;
-import org.bukkit.event.player.PlayerMoveEvent;
-import org.bukkit.event.player.PlayerQuitEvent;
-
-import java.util.HashSet;
-import java.util.Set;
-import java.util.function.Consumer;
-import java.util.function.Function;
-
-public class Displayable extends BasicListener {
-
- private final Set visible = new HashSet<>();
-
- private int chunkX;
- private int chunkZ;
- private final Consumer show;
- private final Consumer hide;
- private final Consumer move;
- private final Function playerFilter;
-
- public Displayable(Location location, Consumer show, Consumer hide, Consumer move) {
- this(location, show, hide, move, player -> true);
- }
-
- public Displayable(Location location, Consumer show, Consumer hide, Function playerFilter) {
- this(location, show, hide, player -> {}, playerFilter);
- }
-
- public Displayable(Location location, Consumer show, Consumer hide, Consumer move, Function playerFilter) {
- this.show = show;
- this.hide = hide;
- this.move = move;
- this.playerFilter = playerFilter;
- setLocation(location);
- }
-
- public void setLocation(Location location) {
- chunkX = posToChunk(location.getX());
- chunkZ = posToChunk(location.getZ());
- Bukkit.getOnlinePlayers().forEach(this::checkLocation);
- visible.forEach(move);
- }
-
- public Set getVisitors() {
- return visible;
- }
-
- @EventHandler
- public void onJoin(PlayerJoinEvent e) {
- checkLocation(e.getPlayer());
- }
-
- @EventHandler
- public void onMove(PlayerMoveEvent e) {
- checkLocation(e.getPlayer());
- }
-
- public void checkLocation(Player player) {
- if(!playerFilter.apply(player))
- return;
-
- Location at = player.getLocation();
- boolean shown = visible.contains(player);
- int viewDistance = player.getClientViewDistance() / 2;
- boolean see = Math.abs(chunkX - posToChunk(at.getX())) < viewDistance && Math.abs(chunkZ - posToChunk(at.getZ())) < viewDistance;
-
- if(!shown && see) {
- show.accept(player);
- visible.add(player);
- }
-
- if(shown && !see) {
- hide.accept(player);
- visible.remove(player);
- }
- }
-
- @EventHandler
- public void onQuit(PlayerQuitEvent e) {
- visible.remove(e.getPlayer());
- }
-
- public void delete() {
- visible.forEach(hide);
- visible.clear();
- HandlerList.unregisterAll(this);
- }
-
- private int posToChunk(double coord) {
- return (int)(coord / 16) - (coord < 0 ? 1 : 0);
- }
-}
diff --git a/src/de/steamwar/lobby/display/Hologram.java b/src/de/steamwar/lobby/display/Hologram.java
index 5b0b519..556c7d0 100644
--- a/src/de/steamwar/lobby/display/Hologram.java
+++ b/src/de/steamwar/lobby/display/Hologram.java
@@ -19,100 +19,30 @@
package de.steamwar.lobby.display;
-import com.comphenix.tinyprotocol.Reflection;
-import com.comphenix.tinyprotocol.TinyProtocol;
-import de.steamwar.lobby.command.ModifyCommand;
+import de.steamwar.entity.RArmorStand;
+import de.steamwar.lobby.LobbySystem;
import org.bukkit.Location;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
-import org.bukkit.entity.Player;
-import java.lang.reflect.Field;
-import java.lang.reflect.ParameterizedType;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
public class Hologram implements ConfigurationSerializable {
- private static final Class> dataWatcherObject = Reflection.getClass("{nms}.DataWatcherObject");
- private static final Class> dataWatcherRegistry = Reflection.getClass("{nms}.DataWatcherRegistry");
- private static final Class> dataWatcherSerializer = Reflection.getClass("{nms}.DataWatcherSerializer");
- private static final Reflection.ConstructorInvoker dataWatcherObjectConstructor = Reflection.getConstructor(dataWatcherObject, int.class, dataWatcherSerializer);
- private static Object getDataWatcherObject(int index, Class> type) {
- for(Field field : dataWatcherRegistry.getFields()) {
- if(dataWatcherSerializer.isAssignableFrom(field.getType()) && type.equals(((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0])) {
- try {
- return dataWatcherObjectConstructor.invoke(index, field.get(null));
- } catch (IllegalAccessException e) {
- throw new SecurityException("Could not get field", e);
- }
- }
- }
- throw new SecurityException("Could not find Serializer for " + type.getName());
- }
- private static Object getDataWatcherObject(int index, int fieldIndex) {
- try {
- return dataWatcherObjectConstructor.invoke(index, dataWatcherRegistry.getFields()[fieldIndex].get(null));
- } catch (IllegalAccessException e) {
- throw new SecurityException("Could not get field", e);
- }
- }
-
- private static final Class> spawnLivingPacket = Reflection.getClass("{nms}.PacketPlayOutSpawnEntityLiving");
- private static final Reflection.ConstructorInvoker spawnLivingPacketConstructor = Reflection.getConstructor(spawnLivingPacket);
- private static final Reflection.FieldAccessor spawnLivingEntityId = Reflection.getField(spawnLivingPacket, int.class, 0);
- private static final Reflection.FieldAccessor spawnLivingUUID = Reflection.getField(spawnLivingPacket, UUID.class, 0);
- private static final Reflection.FieldAccessor spawnLivingEntityType = Reflection.getField(spawnLivingPacket, int.class, 1);
- private static final Reflection.FieldAccessor spawnLivingEntityX = Reflection.getField(spawnLivingPacket, double.class, 0);
- private static final Reflection.FieldAccessor spawnLivingEntityY = Reflection.getField(spawnLivingPacket, double.class, 1);
- private static final Reflection.FieldAccessor spawnLivingEntityZ = Reflection.getField(spawnLivingPacket, double.class, 2);
-
- private static final Class> metadataPacket = Reflection.getClass("{nms}.PacketPlayOutEntityMetadata");
- private static final Reflection.ConstructorInvoker metadataConstructor = Reflection.getConstructor(metadataPacket);
- private static final Reflection.FieldAccessor metadataEntity = Reflection.getField(metadataPacket, int.class, 0);
- private static final Reflection.FieldAccessor metadataMetadata = Reflection.getField(metadataPacket, List.class, 0);
- private static final Class> item = Reflection.getClass("{nms}.DataWatcher$Item");
- private static final Reflection.ConstructorInvoker itemConstructor = Reflection.getConstructor(item, dataWatcherObject, Object.class);
- private static final Object invisibleWatcher = getDataWatcherObject(0, Byte.class);
- private static final Object nameWatcher = getDataWatcherObject(2, 5);
- private static final Object nameVisibleWatcher = getDataWatcherObject(3, Boolean.class);
- private static final Object sizeWatcher = getDataWatcherObject(14, Byte.class);
- private static final Class> chatComponentText = Reflection.getClass("{nms}.ChatComponentText");
- private static final Reflection.ConstructorInvoker chatComponentTextConstructor = Reflection.getConstructor(chatComponentText, String.class);
-
- private static final Class> destroyPacket = Reflection.getClass("{nms}.PacketPlayOutEntityDestroy");
- private static final Reflection.ConstructorInvoker destoryPacketConstructor = Reflection.getConstructor(destroyPacket);
- private static final Reflection.FieldAccessor destroyIds = Reflection.getField(destroyPacket, int[].class, 0);
- public static Object destroyPacket(int entityId) {
- Object destroy = destoryPacketConstructor.invoke();
- destroyIds.set(destroy, new int[]{entityId});
- return destroy;
- }
-
- private static int entityIds = -1;
- public static int createEntityId() {
- return entityIds--;
- }
-
private static final Map holograms = new HashMap<>();
- private static final Random random = new Random();
-
public static List getHolograms() {
return new ArrayList<>(holograms.values());
}
public static Hologram getHologram(String id) {
return holograms.get(id);
}
- private final Displayable display;
- private final int entityId;
-
- private final Object spawnLiving;
- private Object metadata;
- private final Object destroy;
private final String id;
private final Location location;
-
- private String text;
+ private final RArmorStand entity;
public Hologram(Map map) {
this((String) map.get("id"), (Location) map.get("location"), (String) map.get("text"), false);
@@ -121,53 +51,17 @@ public class Hologram implements ConfigurationSerializable {
public Hologram(String id, Location location, String text, boolean debugHologram) {
this.id = id;
this.location = location;
- this.text = text;
- entityId = createEntityId();
+ this.entity = new RArmorStand(LobbySystem.getEntityServer(debugHologram), location, RArmorStand.Size.MARKER);
- spawnLiving = spawnLivingPacketConstructor.invoke();
- spawnLivingEntityId.set(spawnLiving, entityId);
- spawnLivingUUID.set(spawnLiving, new UUID(random.nextLong() & -61441L | 16384L, random.nextLong() & 4611686018427387903L | -9223372036854775808L));
- spawnLivingEntityType.set(spawnLiving, 1);
- spawnLivingEntityX.set(spawnLiving, location.getX());
- spawnLivingEntityY.set(spawnLiving, location.getY());
- spawnLivingEntityZ.set(spawnLiving, location.getZ());
-
- constructMetadataPacket();
-
- destroy = destroyPacket(entityId);
-
- display = new Displayable(location, this::show, this::hide, debugHologram ? ModifyCommand::modifying : player -> true);
+ entity.setInvisible(true);
+ entity.setDisplayName(text);
if(id != null)
holograms.put(id, this);
}
public void updateText(String text) {
- this.text = text;
- constructMetadataPacket();
- for(Player player : display.getVisitors()) {
- TinyProtocol.instance.sendPacket(player, metadata);
- }
- }
-
- private void constructMetadataPacket() {
- metadata = metadataConstructor.invoke();
- metadataEntity.set(metadata, entityId);
- List