Large refactoring and cleanup
This commit is contained in:
parent
acd83a6fe6
commit
0ff3b28fdd
|
@ -18,9 +18,11 @@ import java.time.Instant;
|
|||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class DeathHolograms extends JavaPlugin implements Listener {
|
||||
|
||||
|
||||
private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("H:mm");
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
if (!Bukkit.getPluginManager().isPluginEnabled("HolographicDisplays")) {
|
||||
getLogger().severe("*** HolographicDisplays is not installed or not enabled. ***");
|
||||
getLogger().severe("*** This plugin will be disabled. ***");
|
||||
|
@ -29,17 +31,14 @@ public class DeathHolograms extends JavaPlugin implements Listener {
|
|||
}
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(this, this);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDeath(PlayerDeathEvent event) {
|
||||
|
||||
Hologram hologram = HologramsAPI.createHologram(this, event.getEntity().getEyeLocation());
|
||||
|
||||
hologram.appendTextLine(ChatColor.RED + "Player " + ChatColor.GOLD + event.getEntity().getName() + ChatColor.RED + " died here!");
|
||||
hologram.appendTextLine(ChatColor.GRAY + "Time of death: " + DateTimeFormatter.ofPattern("H:mm").format(Instant.now()));
|
||||
|
||||
hologram.appendTextLine(ChatColor.GRAY + "Time of death: " + TIME_FORMATTER.format(Instant.now()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ public class PowerUps extends JavaPlugin implements Listener {
|
|||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
if (!Bukkit.getPluginManager().isPluginEnabled("HolographicDisplays")) {
|
||||
getLogger().severe("*** HolographicDisplays is not installed or not enabled. ***");
|
||||
getLogger().severe("*** This plugin will be disabled. ***");
|
||||
|
@ -35,26 +34,22 @@ public class PowerUps extends JavaPlugin implements Listener {
|
|||
}
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(this, this);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onEntityDeath(EntityDeathEvent event) {
|
||||
|
||||
if (event.getEntityType() == EntityType.ZOMBIE) {
|
||||
|
||||
// Remove normal drops and exp.
|
||||
event.getDrops().clear();
|
||||
event.setDroppedExp(0);
|
||||
|
||||
// Spawn the floating item with a label.
|
||||
final Hologram hologram = HologramsAPI.createHologram(this, event.getEntity().getLocation().add(0.0, 0.9, 0.0));
|
||||
Hologram hologram = HologramsAPI.createHologram(this, event.getEntity().getLocation().add(0.0, 0.9, 0.0));
|
||||
hologram.appendTextLine(ChatColor.AQUA + "" + ChatColor.BOLD + "Speed PowerUp");
|
||||
ItemLine icon = hologram.appendItemLine(new ItemStack(Material.SUGAR));
|
||||
|
||||
icon.setPickupHandler((Player player) -> {
|
||||
|
||||
// Play an effect.
|
||||
player.playEffect(hologram.getLocation(), Effect.MOBSPAWNER_FLAMES, null);
|
||||
|
||||
|
@ -63,9 +58,7 @@ public class PowerUps extends JavaPlugin implements Listener {
|
|||
|
||||
// Delete the hologram.
|
||||
hologram.delete();
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ import java.util.Set;
|
|||
@Deprecated
|
||||
public class HolographicDisplaysAPI {
|
||||
|
||||
private static Set<String> notifiedPlugins = new HashSet<>();
|
||||
private static final Set<String> notifiedPlugins = new HashSet<>();
|
||||
|
||||
private static void notifyOldAPI(Plugin plugin) {
|
||||
Preconditions.notNull(plugin, "plugin");
|
||||
|
|
|
@ -23,11 +23,11 @@ import java.util.Map;
|
|||
@SuppressWarnings("deprecation")
|
||||
public class FloatingItemAdapter implements FloatingItem {
|
||||
|
||||
public static Map<Plugin, Collection<FloatingItemAdapter>> activeFloatingItems = new HashMap<>();
|
||||
public static final Map<Plugin, Collection<FloatingItemAdapter>> activeFloatingItems = new HashMap<>();
|
||||
|
||||
private Plugin plugin;
|
||||
public Hologram hologram;
|
||||
private ItemLine itemLine;
|
||||
private final Plugin plugin;
|
||||
private final Hologram hologram;
|
||||
private final ItemLine itemLine;
|
||||
private ItemTouchHandler touchHandler;
|
||||
private PickupHandler pickupHandler;
|
||||
|
||||
|
|
|
@ -22,10 +22,10 @@ import java.util.Map;
|
|||
@SuppressWarnings("deprecation")
|
||||
public class HologramAdapter implements Hologram {
|
||||
|
||||
public static Map<Plugin, Collection<HologramAdapter>> activeHolograms = new HashMap<>();
|
||||
public static final Map<Plugin, Collection<HologramAdapter>> activeHolograms = new HashMap<>();
|
||||
|
||||
private Plugin plugin;
|
||||
private me.filoghost.holographicdisplays.api.Hologram hologram;
|
||||
private final Plugin plugin;
|
||||
private final me.filoghost.holographicdisplays.api.Hologram hologram;
|
||||
private TouchHandler touchHandler;
|
||||
|
||||
public HologramAdapter(Plugin plugin, me.filoghost.holographicdisplays.api.Hologram delegate) {
|
||||
|
|
|
@ -12,8 +12,8 @@ import org.bukkit.entity.Player;
|
|||
@SuppressWarnings("deprecation")
|
||||
public class HologramTouchHandlerAdapter implements me.filoghost.holographicdisplays.api.handler.TouchHandler {
|
||||
|
||||
protected TouchHandler oldHandler;
|
||||
private Hologram hologram;
|
||||
private final TouchHandler oldHandler;
|
||||
private final Hologram hologram;
|
||||
|
||||
public HologramTouchHandlerAdapter(Hologram hologram, TouchHandler oldHandler) {
|
||||
this.hologram = hologram;
|
||||
|
|
|
@ -13,8 +13,8 @@ import org.bukkit.entity.Player;
|
|||
@SuppressWarnings("deprecation")
|
||||
public class ItemTouchHandlerAdapter implements TouchHandler {
|
||||
|
||||
protected ItemTouchHandler oldHandler;
|
||||
private FloatingItem item;
|
||||
private final ItemTouchHandler oldHandler;
|
||||
private final FloatingItem item;
|
||||
|
||||
public ItemTouchHandlerAdapter(FloatingItem item, ItemTouchHandler oldHandler) {
|
||||
this.item = item;
|
||||
|
|
|
@ -12,8 +12,8 @@ import org.bukkit.entity.Player;
|
|||
@SuppressWarnings("deprecation")
|
||||
public class PickupHandlerAdapter implements me.filoghost.holographicdisplays.api.handler.PickupHandler {
|
||||
|
||||
private PickupHandler oldHandler;
|
||||
private FloatingItem item;
|
||||
private final PickupHandler oldHandler;
|
||||
private final FloatingItem item;
|
||||
|
||||
public PickupHandlerAdapter(FloatingItem item, PickupHandler oldPickupHandler) {
|
||||
this.item = item;
|
||||
|
|
|
@ -5,12 +5,11 @@
|
|||
*/
|
||||
package me.filoghost.holographicdisplays.nms.interfaces;
|
||||
|
||||
import me.filoghost.holographicdisplays.api.Hologram;
|
||||
import me.filoghost.holographicdisplays.api.handler.PickupHandler;
|
||||
import me.filoghost.holographicdisplays.api.line.ItemLine;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface ItemPickupManager {
|
||||
|
||||
void handleItemLinePickup(Player player, PickupHandler pickupHandler, Hologram hologram);
|
||||
void handleItemLinePickup(Player player, ItemLine itemLine);
|
||||
|
||||
}
|
||||
|
|
|
@ -18,9 +18,9 @@ public interface NMSManager {
|
|||
// A method to register all the custom entities of the plugin, it may fail.
|
||||
void setup() throws Exception;
|
||||
|
||||
NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket);
|
||||
NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece);
|
||||
|
||||
NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager);
|
||||
NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack);
|
||||
|
||||
NMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramLine parentPiece);
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package me.filoghost.holographicdisplays.nms.interfaces;
|
||||
|
||||
public interface PacketController {
|
||||
|
||||
boolean shouldBroadcastLocationPacket();
|
||||
|
||||
}
|
|
@ -6,8 +6,5 @@
|
|||
package me.filoghost.holographicdisplays.nms.interfaces.entity;
|
||||
|
||||
public interface NMSArmorStand extends NMSNameable {
|
||||
|
||||
// Sets the location through NMS and optionally broadcast an additional teleport packet containing the location.
|
||||
void setLocationNMS(double x, double y, double z, boolean broadcastLocationPacket);
|
||||
|
||||
}
|
||||
|
|
|
@ -14,6 +14,9 @@ public interface NMSEntityBase {
|
|||
|
||||
// Returns the linked CraftHologramLine, all the entities are part of a piece. Should never be null.
|
||||
HologramLine getHologramLine();
|
||||
|
||||
// Sets the location through NMS.
|
||||
void setLocationNMS(double x, double y, double z);
|
||||
|
||||
// Returns if the entity is dead through NMS.
|
||||
boolean isDeadNMS();
|
||||
|
|
|
@ -9,9 +9,6 @@ import org.bukkit.inventory.ItemStack;
|
|||
|
||||
public interface NMSItem extends NMSEntityBase, NMSCanMount {
|
||||
|
||||
// Sets the location through NMS.
|
||||
void setLocationNMS(double x, double y, double z);
|
||||
|
||||
// Sets the bukkit ItemStack for this item.
|
||||
void setItemStackNMS(ItemStack stack);
|
||||
|
||||
|
|
|
@ -7,7 +7,4 @@ package me.filoghost.holographicdisplays.nms.interfaces.entity;
|
|||
|
||||
public interface NMSSlime extends NMSEntityBase, NMSCanMount {
|
||||
|
||||
// Sets the location through NMS.
|
||||
void setLocationNMS(double x, double y, double z);
|
||||
|
||||
}
|
||||
|
|
|
@ -6,8 +6,9 @@
|
|||
package me.filoghost.holographicdisplays.nms.v1_10_R1;
|
||||
|
||||
import me.filoghost.holographicdisplays.api.line.HologramLine;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.PacketController;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import net.minecraft.server.v1_10_R1.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_10_R1.DamageSource;
|
||||
import net.minecraft.server.v1_10_R1.EntityArmorStand;
|
||||
|
@ -26,10 +27,11 @@ import org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity;
|
|||
|
||||
public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand {
|
||||
|
||||
private HologramLine parentPiece;
|
||||
private final HologramLine parentPiece;
|
||||
private final PacketController packetController;
|
||||
private String customName;
|
||||
|
||||
public EntityNMSArmorStand(World world, HologramLine parentPiece) {
|
||||
public EntityNMSArmorStand(World world, HologramLine parentPiece, PacketController packetController) {
|
||||
super(world);
|
||||
super.setInvisible(true);
|
||||
super.setSmall(true);
|
||||
|
@ -38,9 +40,10 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||
super.setBasePlate(true);
|
||||
super.setMarker(true);
|
||||
super.collides = false;
|
||||
this.parentPiece = parentPiece;
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
|
||||
this.parentPiece = parentPiece;
|
||||
this.packetController = packetController;
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
}
|
||||
|
||||
|
@ -189,9 +192,9 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setLocationNMS(double x, double y, double z, boolean broadcastLocationPacket) {
|
||||
public void setLocationNMS(double x, double y, double z) {
|
||||
super.setPosition(x, y, z);
|
||||
if (broadcastLocationPacket) {
|
||||
if (packetController.shouldBroadcastLocationPacket()) {
|
||||
broadcastLocationPacketNMS();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,8 +33,8 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "au");
|
||||
|
||||
private ItemLine parentPiece;
|
||||
private ItemPickupManager itemPickupManager;
|
||||
private final ItemLine parentPiece;
|
||||
private final ItemPickupManager itemPickupManager;
|
||||
|
||||
private int resendMountPacketTicks;
|
||||
|
||||
|
@ -54,10 +54,11 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||
|
||||
if (resendMountPacketTicks++ > 20) {
|
||||
resendMountPacketTicks = 0;
|
||||
|
||||
if (bB() != null) {
|
||||
|
||||
Entity vehicle = bB();
|
||||
if (vehicle != null) {
|
||||
// Send a packet near to "remind" players that the item is riding the armor stand (Spigot bug or client bug)
|
||||
PacketPlayOutMount mountPacket = new PacketPlayOutMount(bB());
|
||||
PacketPlayOutMount mountPacket = new PacketPlayOutMount(vehicle);
|
||||
|
||||
for (Object obj : super.world.players) {
|
||||
if (obj instanceof EntityPlayer) {
|
||||
|
@ -84,14 +85,13 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||
// Method called when a player is near.
|
||||
@Override
|
||||
public void d(EntityHuman human) {
|
||||
|
||||
if (human.locY < super.locY - 1.5 || human.locY > super.locY + 1.0) {
|
||||
// Too low or too high, it's a bit weird.
|
||||
return;
|
||||
}
|
||||
|
||||
if (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) {
|
||||
itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent());
|
||||
itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece);
|
||||
// It is never added to the inventory.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
|||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "au");
|
||||
|
||||
private HologramLine parentPiece;
|
||||
private final HologramLine parentPiece;
|
||||
|
||||
private int resendMountPacketTicks;
|
||||
|
||||
|
@ -217,8 +217,8 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
|||
Entity entity = (Entity) vehicleBase;
|
||||
|
||||
try {
|
||||
if (super.bB() != null) {
|
||||
Entity oldVehicle = super.bB();
|
||||
Entity oldVehicle = super.bB();
|
||||
if (oldVehicle != null) {
|
||||
VEHICLE_FIELD.set(this, null);
|
||||
oldVehicle.passengers.remove(this);
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import me.filoghost.holographicdisplays.common.DebugLogger;
|
|||
import me.filoghost.holographicdisplays.nms.interfaces.CustomNameHelper;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.ItemPickupManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.PacketController;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSItem;
|
||||
|
@ -37,6 +38,14 @@ public class NmsManagerImpl implements NMSManager {
|
|||
|
||||
private static final ReflectMethod<?> VALIDATE_ENTITY_METHOD = ReflectMethod.lookup(Object.class, World.class, "b", Entity.class);
|
||||
|
||||
private final ItemPickupManager itemPickupManager;
|
||||
private final PacketController packetController;
|
||||
|
||||
public NmsManagerImpl(ItemPickupManager itemPickupManager, PacketController packetController) {
|
||||
this.itemPickupManager = itemPickupManager;
|
||||
this.packetController = packetController;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() throws Exception {
|
||||
registerCustomEntity(EntityNMSArmorStand.class, "ArmorStand", 30);
|
||||
|
@ -50,7 +59,7 @@ public class NmsManagerImpl implements NMSManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) {
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack) {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager);
|
||||
customItem.setLocationNMS(x, y, z);
|
||||
|
@ -73,10 +82,10 @@ public class NmsManagerImpl implements NMSManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) {
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece) {
|
||||
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket);
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
|
|
|
@ -6,8 +6,9 @@
|
|||
package me.filoghost.holographicdisplays.nms.v1_11_R1;
|
||||
|
||||
import me.filoghost.holographicdisplays.api.line.HologramLine;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.PacketController;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import net.minecraft.server.v1_11_R1.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_11_R1.DamageSource;
|
||||
import net.minecraft.server.v1_11_R1.EntityArmorStand;
|
||||
|
@ -26,10 +27,11 @@ import org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity;
|
|||
|
||||
public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand {
|
||||
|
||||
private HologramLine parentPiece;
|
||||
private final HologramLine parentPiece;
|
||||
private final PacketController packetController;
|
||||
private String customName;
|
||||
|
||||
public EntityNMSArmorStand(World world, HologramLine parentPiece) {
|
||||
public EntityNMSArmorStand(World world, HologramLine parentPiece, PacketController packetController) {
|
||||
super(world);
|
||||
super.setInvisible(true);
|
||||
super.setSmall(true);
|
||||
|
@ -38,9 +40,10 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||
super.setBasePlate(true);
|
||||
super.setMarker(true);
|
||||
super.collides = false;
|
||||
this.parentPiece = parentPiece;
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
|
||||
this.parentPiece = parentPiece;
|
||||
this.packetController = packetController;
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
}
|
||||
|
||||
|
@ -189,9 +192,9 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setLocationNMS(double x, double y, double z, boolean broadcastLocationPacket) {
|
||||
public void setLocationNMS(double x, double y, double z) {
|
||||
super.setPosition(x, y, z);
|
||||
if (broadcastLocationPacket) {
|
||||
if (packetController.shouldBroadcastLocationPacket()) {
|
||||
broadcastLocationPacketNMS();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,8 +31,8 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "au");
|
||||
|
||||
private ItemLine parentPiece;
|
||||
private ItemPickupManager itemPickupManager;
|
||||
private final ItemLine parentPiece;
|
||||
private final ItemPickupManager itemPickupManager;
|
||||
|
||||
public EntityNMSItem(World world, ItemLine piece, ItemPickupManager itemPickupManager) {
|
||||
super(world);
|
||||
|
@ -60,14 +60,13 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||
// Method called when a player is near.
|
||||
@Override
|
||||
public void d(EntityHuman human) {
|
||||
|
||||
if (human.locY < super.locY - 1.5 || human.locY > super.locY + 1.0) {
|
||||
// Too low or too high, it's a bit weird.
|
||||
return;
|
||||
}
|
||||
|
||||
if (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) {
|
||||
itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent());
|
||||
itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece);
|
||||
// It is never added to the inventory.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
|||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "au");
|
||||
|
||||
private HologramLine parentPiece;
|
||||
private final HologramLine parentPiece;
|
||||
|
||||
public EntityNMSSlime(World world, HologramLine parentPiece) {
|
||||
super(world);
|
||||
|
|
|
@ -15,6 +15,7 @@ import me.filoghost.holographicdisplays.common.DebugLogger;
|
|||
import me.filoghost.holographicdisplays.nms.interfaces.CustomNameHelper;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.ItemPickupManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.PacketController;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSItem;
|
||||
|
@ -36,6 +37,14 @@ public class NmsManagerImpl implements NMSManager {
|
|||
private static final ReflectField<Object[]> ID_TO_CLASS_MAP_FIELD = ReflectField.lookup(Object[].class, RegistryID.class, "d");
|
||||
|
||||
private static final ReflectMethod<?> VALIDATE_ENTITY_METHOD = ReflectMethod.lookup(Object.class, World.class, "b", Entity.class);
|
||||
|
||||
private final ItemPickupManager itemPickupManager;
|
||||
private final PacketController packetController;
|
||||
|
||||
public NmsManagerImpl(ItemPickupManager itemPickupManager, PacketController packetController) {
|
||||
this.itemPickupManager = itemPickupManager;
|
||||
this.packetController = packetController;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() throws Exception {
|
||||
|
@ -58,7 +67,7 @@ public class NmsManagerImpl implements NMSManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) {
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack) {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager);
|
||||
customItem.setLocationNMS(x, y, z);
|
||||
|
@ -81,10 +90,10 @@ public class NmsManagerImpl implements NMSManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) {
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece) {
|
||||
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket);
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
|
|
|
@ -6,8 +6,9 @@
|
|||
package me.filoghost.holographicdisplays.nms.v1_12_R1;
|
||||
|
||||
import me.filoghost.holographicdisplays.api.line.HologramLine;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.PacketController;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import net.minecraft.server.v1_12_R1.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_12_R1.DamageSource;
|
||||
import net.minecraft.server.v1_12_R1.EntityArmorStand;
|
||||
|
@ -26,10 +27,11 @@ import org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity;
|
|||
|
||||
public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand {
|
||||
|
||||
private HologramLine parentPiece;
|
||||
private final HologramLine parentPiece;
|
||||
private final PacketController packetController;
|
||||
private String customName;
|
||||
|
||||
public EntityNMSArmorStand(World world, HologramLine parentPiece) {
|
||||
public EntityNMSArmorStand(World world, HologramLine parentPiece, PacketController packetController) {
|
||||
super(world);
|
||||
super.setInvisible(true);
|
||||
super.setSmall(true);
|
||||
|
@ -38,9 +40,10 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||
super.setBasePlate(true);
|
||||
super.setMarker(true);
|
||||
super.collides = false;
|
||||
this.parentPiece = parentPiece;
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
|
||||
this.parentPiece = parentPiece;
|
||||
this.packetController = packetController;
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
}
|
||||
|
||||
|
@ -189,9 +192,9 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setLocationNMS(double x, double y, double z, boolean broadcastLocationPacket) {
|
||||
public void setLocationNMS(double x, double y, double z) {
|
||||
super.setPosition(x, y, z);
|
||||
if (broadcastLocationPacket) {
|
||||
if (packetController.shouldBroadcastLocationPacket()) {
|
||||
broadcastLocationPacketNMS();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,8 +31,8 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "au");
|
||||
|
||||
private ItemLine parentPiece;
|
||||
private ItemPickupManager itemPickupManager;
|
||||
private final ItemLine parentPiece;
|
||||
private final ItemPickupManager itemPickupManager;
|
||||
|
||||
public EntityNMSItem(World world, ItemLine piece, ItemPickupManager itemPickupManager) {
|
||||
super(world);
|
||||
|
@ -60,14 +60,13 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||
// Method called when a player is near.
|
||||
@Override
|
||||
public void d(EntityHuman human) {
|
||||
|
||||
if (human.locY < super.locY - 1.5 || human.locY > super.locY + 1.0) {
|
||||
// Too low or too high, it's a bit weird.
|
||||
return;
|
||||
}
|
||||
|
||||
if (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) {
|
||||
itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent());
|
||||
itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece);
|
||||
// It is never added to the inventory.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
|||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "au");
|
||||
|
||||
private HologramLine parentPiece;
|
||||
private final HologramLine parentPiece;
|
||||
|
||||
public EntityNMSSlime(World world, HologramLine parentPiece) {
|
||||
super(world);
|
||||
|
|
|
@ -15,6 +15,7 @@ import me.filoghost.holographicdisplays.common.DebugLogger;
|
|||
import me.filoghost.holographicdisplays.nms.interfaces.CustomNameHelper;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.ItemPickupManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.PacketController;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSItem;
|
||||
|
@ -36,6 +37,14 @@ public class NmsManagerImpl implements NMSManager {
|
|||
private static final ReflectField<Object[]> ID_TO_CLASS_MAP_FIELD = ReflectField.lookup(Object[].class, RegistryID.class, "d");
|
||||
|
||||
private static final ReflectMethod<?> VALIDATE_ENTITY_METHOD = ReflectMethod.lookup(Object.class, World.class, "b", Entity.class);
|
||||
|
||||
private final ItemPickupManager itemPickupManager;
|
||||
private final PacketController packetController;
|
||||
|
||||
public NmsManagerImpl(ItemPickupManager itemPickupManager, PacketController packetController) {
|
||||
this.itemPickupManager = itemPickupManager;
|
||||
this.packetController = packetController;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() throws Exception {
|
||||
|
@ -58,7 +67,7 @@ public class NmsManagerImpl implements NMSManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) {
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack) {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager);
|
||||
customItem.setLocationNMS(x, y, z);
|
||||
|
@ -81,10 +90,10 @@ public class NmsManagerImpl implements NMSManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) {
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece) {
|
||||
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket);
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
|
|
|
@ -6,8 +6,9 @@
|
|||
package me.filoghost.holographicdisplays.nms.v1_13_R1;
|
||||
|
||||
import me.filoghost.holographicdisplays.api.line.HologramLine;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.PacketController;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import net.minecraft.server.v1_13_R1.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_13_R1.DamageSource;
|
||||
import net.minecraft.server.v1_13_R1.EntityArmorStand;
|
||||
|
@ -28,10 +29,11 @@ import org.bukkit.craftbukkit.v1_13_R1.util.CraftChatMessage;
|
|||
|
||||
public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand {
|
||||
|
||||
private HologramLine parentPiece;
|
||||
private final HologramLine parentPiece;
|
||||
private final PacketController packetController;
|
||||
private String customName;
|
||||
|
||||
public EntityNMSArmorStand(World world, HologramLine parentPiece) {
|
||||
public EntityNMSArmorStand(World world, HologramLine parentPiece, PacketController packetController) {
|
||||
super(world);
|
||||
super.setInvisible(true);
|
||||
super.setSmall(true);
|
||||
|
@ -40,9 +42,10 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||
super.setBasePlate(true);
|
||||
super.setMarker(true);
|
||||
super.collides = false;
|
||||
this.parentPiece = parentPiece;
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
|
||||
this.parentPiece = parentPiece;
|
||||
this.packetController = packetController;
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
}
|
||||
|
||||
|
@ -191,9 +194,9 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setLocationNMS(double x, double y, double z, boolean broadcastLocationPacket) {
|
||||
public void setLocationNMS(double x, double y, double z) {
|
||||
super.setPosition(x, y, z);
|
||||
if (broadcastLocationPacket) {
|
||||
if (packetController.shouldBroadcastLocationPacket()) {
|
||||
broadcastLocationPacketNMS();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,8 +31,8 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "ax");
|
||||
|
||||
private ItemLine parentPiece;
|
||||
private ItemPickupManager itemPickupManager;
|
||||
private final ItemLine parentPiece;
|
||||
private final ItemPickupManager itemPickupManager;
|
||||
|
||||
public EntityNMSItem(World world, ItemLine piece, ItemPickupManager itemPickupManager) {
|
||||
super(world);
|
||||
|
@ -60,14 +60,13 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||
// Method called when a player is near.
|
||||
@Override
|
||||
public void d(EntityHuman human) {
|
||||
|
||||
if (human.locY < super.locY - 1.5 || human.locY > super.locY + 1.0) {
|
||||
// Too low or too high, it's a bit weird.
|
||||
return;
|
||||
}
|
||||
|
||||
if (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) {
|
||||
itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent());
|
||||
itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece);
|
||||
// It is never added to the inventory.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
|||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "ax");
|
||||
|
||||
private HologramLine parentPiece;
|
||||
private final HologramLine parentPiece;
|
||||
|
||||
public EntityNMSSlime(World world, HologramLine parentPiece) {
|
||||
super(world);
|
||||
|
|
|
@ -17,6 +17,7 @@ import me.filoghost.holographicdisplays.nms.interfaces.CustomNameHelper;
|
|||
import me.filoghost.holographicdisplays.nms.interfaces.ItemPickupManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSCommons;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.PacketController;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSItem;
|
||||
|
@ -43,6 +44,14 @@ public class NmsManagerImpl implements NMSManager {
|
|||
private static final ReflectField<List<Entity>> ENTITY_LIST_FIELD = ReflectField.lookup(new ClassToken<List<Entity>>(){}, World.class, "entityList");
|
||||
|
||||
private static final ReflectMethod<?> VALIDATE_ENTITY_METHOD = ReflectMethod.lookup(Object.class, World.class, "b", Entity.class);
|
||||
|
||||
private final ItemPickupManager itemPickupManager;
|
||||
private final PacketController packetController;
|
||||
|
||||
public NmsManagerImpl(ItemPickupManager itemPickupManager, PacketController packetController) {
|
||||
this.itemPickupManager = itemPickupManager;
|
||||
this.packetController = packetController;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() throws Exception {
|
||||
|
@ -65,7 +74,7 @@ public class NmsManagerImpl implements NMSManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) {
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack) {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager);
|
||||
customItem.setLocationNMS(x, y, z);
|
||||
|
@ -88,10 +97,10 @@ public class NmsManagerImpl implements NMSManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) {
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece) {
|
||||
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket);
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
|
@ -169,6 +178,7 @@ public class NmsManagerImpl implements NMSManager {
|
|||
|
||||
INSTANCE {
|
||||
|
||||
@Override
|
||||
public ChatComponentText cast(Object chatComponentObject) {
|
||||
return (ChatComponentText) chatComponentObject;
|
||||
}
|
||||
|
|
|
@ -6,8 +6,9 @@
|
|||
package me.filoghost.holographicdisplays.nms.v1_13_R2;
|
||||
|
||||
import me.filoghost.holographicdisplays.api.line.HologramLine;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.PacketController;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import net.minecraft.server.v1_13_R2.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_13_R2.DamageSource;
|
||||
import net.minecraft.server.v1_13_R2.EntityArmorStand;
|
||||
|
@ -28,10 +29,11 @@ import org.bukkit.craftbukkit.v1_13_R2.util.CraftChatMessage;
|
|||
|
||||
public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand {
|
||||
|
||||
private HologramLine parentPiece;
|
||||
private final HologramLine parentPiece;
|
||||
private final PacketController packetController;
|
||||
private String customName;
|
||||
|
||||
public EntityNMSArmorStand(World world, HologramLine parentPiece) {
|
||||
public EntityNMSArmorStand(World world, HologramLine parentPiece, PacketController packetController) {
|
||||
super(world);
|
||||
super.setInvisible(true);
|
||||
super.setSmall(true);
|
||||
|
@ -40,9 +42,10 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||
super.setBasePlate(true);
|
||||
super.setMarker(true);
|
||||
super.collides = false;
|
||||
this.parentPiece = parentPiece;
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
|
||||
this.parentPiece = parentPiece;
|
||||
this.packetController = packetController;
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
}
|
||||
|
||||
|
@ -191,9 +194,9 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setLocationNMS(double x, double y, double z, boolean broadcastLocationPacket) {
|
||||
public void setLocationNMS(double x, double y, double z) {
|
||||
super.setPosition(x, y, z);
|
||||
if (broadcastLocationPacket) {
|
||||
if (packetController.shouldBroadcastLocationPacket()) {
|
||||
broadcastLocationPacketNMS();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,8 +31,8 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle");
|
||||
|
||||
private ItemLine parentPiece;
|
||||
private ItemPickupManager itemPickupManager;
|
||||
private final ItemLine parentPiece;
|
||||
private final ItemPickupManager itemPickupManager;
|
||||
|
||||
public EntityNMSItem(World world, ItemLine piece, ItemPickupManager itemPickupManager) {
|
||||
super(world);
|
||||
|
@ -60,14 +60,13 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||
// Method called when a player is near.
|
||||
@Override
|
||||
public void d(EntityHuman human) {
|
||||
|
||||
if (human.locY < super.locY - 1.5 || human.locY > super.locY + 1.0) {
|
||||
// Too low or too high, it's a bit weird.
|
||||
return;
|
||||
}
|
||||
|
||||
if (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) {
|
||||
itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent());
|
||||
itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece);
|
||||
// It is never added to the inventory.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
|||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle");
|
||||
|
||||
private HologramLine parentPiece;
|
||||
private final HologramLine parentPiece;
|
||||
|
||||
public EntityNMSSlime(World world, HologramLine parentPiece) {
|
||||
super(world);
|
||||
|
|
|
@ -17,6 +17,7 @@ import me.filoghost.holographicdisplays.nms.interfaces.CustomNameHelper;
|
|||
import me.filoghost.holographicdisplays.nms.interfaces.ItemPickupManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSCommons;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.PacketController;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSItem;
|
||||
|
@ -44,6 +45,14 @@ public class NmsManagerImpl implements NMSManager {
|
|||
private static final ReflectField<List<Entity>> ENTITY_LIST_FIELD = ReflectField.lookup(new ClassToken<List<Entity>>(){}, World.class, "entityList");
|
||||
|
||||
private static final ReflectMethod<?> VALIDATE_ENTITY_METHOD = ReflectMethod.lookup(Object.class, World.class, "b", Entity.class);
|
||||
|
||||
private final ItemPickupManager itemPickupManager;
|
||||
private final PacketController packetController;
|
||||
|
||||
public NmsManagerImpl(ItemPickupManager itemPickupManager, PacketController packetController) {
|
||||
this.itemPickupManager = itemPickupManager;
|
||||
this.packetController = packetController;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() throws Exception {
|
||||
|
@ -66,7 +75,7 @@ public class NmsManagerImpl implements NMSManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) {
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack) {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager);
|
||||
customItem.setLocationNMS(x, y, z);
|
||||
|
@ -89,10 +98,10 @@ public class NmsManagerImpl implements NMSManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) {
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece) {
|
||||
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket);
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
|
@ -170,6 +179,7 @@ public class NmsManagerImpl implements NMSManager {
|
|||
|
||||
INSTANCE {
|
||||
|
||||
@Override
|
||||
public ChatComponentText cast(Object chatComponentObject) {
|
||||
return (ChatComponentText) chatComponentObject;
|
||||
}
|
||||
|
|
|
@ -6,8 +6,9 @@
|
|||
package me.filoghost.holographicdisplays.nms.v1_14_R1;
|
||||
|
||||
import me.filoghost.holographicdisplays.api.line.HologramLine;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.PacketController;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import net.minecraft.server.v1_14_R1.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||
import net.minecraft.server.v1_14_R1.EntityArmorStand;
|
||||
|
@ -29,11 +30,12 @@ import org.bukkit.craftbukkit.v1_14_R1.util.CraftChatMessage;
|
|||
|
||||
public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand {
|
||||
|
||||
private HologramLine parentPiece;
|
||||
private final HologramLine parentPiece;
|
||||
private final PacketController packetController;
|
||||
private CraftEntity customBukkitEntity;
|
||||
private String customName;
|
||||
|
||||
public EntityNMSArmorStand(World world, HologramLine parentPiece) {
|
||||
public EntityNMSArmorStand(World world, HologramLine parentPiece, PacketController packetController) {
|
||||
super(EntityTypes.ARMOR_STAND, world);
|
||||
super.setInvisible(true);
|
||||
super.setSmall(true);
|
||||
|
@ -42,9 +44,10 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||
super.setBasePlate(true);
|
||||
super.setMarker(true);
|
||||
super.collides = false;
|
||||
this.parentPiece = parentPiece;
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
|
||||
this.parentPiece = parentPiece;
|
||||
this.packetController = packetController;
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
}
|
||||
|
||||
|
@ -193,9 +196,9 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setLocationNMS(double x, double y, double z, boolean broadcastLocationPacket) {
|
||||
public void setLocationNMS(double x, double y, double z) {
|
||||
super.setPosition(x, y, z);
|
||||
if (broadcastLocationPacket) {
|
||||
if (packetController.shouldBroadcastLocationPacket()) {
|
||||
broadcastLocationPacketNMS();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,8 +32,8 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle");
|
||||
|
||||
private ItemLine parentPiece;
|
||||
private ItemPickupManager itemPickupManager;
|
||||
private final ItemLine parentPiece;
|
||||
private final ItemPickupManager itemPickupManager;
|
||||
private CraftEntity customBukkitEntity;
|
||||
|
||||
public EntityNMSItem(World world, ItemLine piece, ItemPickupManager itemPickupManager) {
|
||||
|
@ -62,14 +62,13 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||
// Method called when a player is near.
|
||||
@Override
|
||||
public void pickup(EntityHuman human) {
|
||||
|
||||
if (human.locY < super.locY - 1.5 || human.locY > super.locY + 1.0) {
|
||||
// Too low or too high, it's a bit weird.
|
||||
return;
|
||||
}
|
||||
|
||||
if (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) {
|
||||
itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent());
|
||||
itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece);
|
||||
// It is never added to the inventory.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
|||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle");
|
||||
|
||||
private HologramLine parentPiece;
|
||||
private final HologramLine parentPiece;
|
||||
private CraftEntity customBukkitEntity;
|
||||
|
||||
public EntityNMSSlime(World world, HologramLine parentPiece) {
|
||||
|
|
|
@ -16,6 +16,7 @@ import me.filoghost.holographicdisplays.nms.interfaces.ChatComponentAdapter;
|
|||
import me.filoghost.holographicdisplays.nms.interfaces.CustomNameHelper;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.ItemPickupManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.PacketController;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSItem;
|
||||
|
@ -31,6 +32,7 @@ import net.minecraft.server.v1_14_R1.RegistryID;
|
|||
import net.minecraft.server.v1_14_R1.RegistryMaterials;
|
||||
import net.minecraft.server.v1_14_R1.WorldServer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
@ -42,6 +44,14 @@ public class NmsManagerImpl implements NMSManager {
|
|||
private static final ReflectField<RegistryID<EntityTypes<?>>> REGISTRY_ID_FIELD = ReflectField.lookup(new ClassToken<RegistryID<EntityTypes<?>>>(){}, RegistryMaterials.class, "b");
|
||||
private static final ReflectField<Object[]> ID_TO_CLASS_MAP_FIELD = ReflectField.lookup(Object[].class, RegistryID.class, "d");
|
||||
private static final ReflectMethod<Void> REGISTER_ENTITY_METHOD = ReflectMethod.lookup(void.class, WorldServer.class, "registerEntity", Entity.class);
|
||||
|
||||
private final ItemPickupManager itemPickupManager;
|
||||
private final PacketController packetController;
|
||||
|
||||
public NmsManagerImpl(ItemPickupManager itemPickupManager, PacketController packetController) {
|
||||
this.itemPickupManager = itemPickupManager;
|
||||
this.packetController = packetController;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() throws Exception {
|
||||
|
@ -64,7 +74,7 @@ public class NmsManagerImpl implements NMSManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) {
|
||||
public NMSItem spawnNMSItem(World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack) {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager);
|
||||
customItem.setLocationNMS(x, y, z);
|
||||
|
@ -87,10 +97,10 @@ public class NmsManagerImpl implements NMSManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) {
|
||||
public NMSArmorStand spawnNMSArmorStand(World world, double x, double y, double z, HologramLine parentPiece) {
|
||||
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket);
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
|
@ -159,6 +169,7 @@ public class NmsManagerImpl implements NMSManager {
|
|||
private boolean useNewGetSiblingsMethod = true;
|
||||
private final ReflectField<List<IChatBaseComponent>> OLD_SIBLINGS_FIELD = ReflectField.lookup(new ClassToken<List<IChatBaseComponent>>(){}, ChatBaseComponent.class, "a");
|
||||
|
||||
@Override
|
||||
public ChatComponentText cast(Object chatComponentObject) {
|
||||
return (ChatComponentText) chatComponentObject;
|
||||
}
|
||||
|
|
|
@ -6,8 +6,9 @@
|
|||
package me.filoghost.holographicdisplays.nms.v1_15_R1;
|
||||
|
||||
import me.filoghost.holographicdisplays.api.line.HologramLine;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.PacketController;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import net.minecraft.server.v1_15_R1.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_15_R1.DamageSource;
|
||||
import net.minecraft.server.v1_15_R1.EntityArmorStand;
|
||||
|
@ -29,11 +30,12 @@ import org.bukkit.craftbukkit.v1_15_R1.util.CraftChatMessage;
|
|||
|
||||
public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand {
|
||||
|
||||
private HologramLine parentPiece;
|
||||
private final HologramLine parentPiece;
|
||||
private final PacketController packetController;
|
||||
private CraftEntity customBukkitEntity;
|
||||
private String customName;
|
||||
|
||||
public EntityNMSArmorStand(World world, HologramLine parentPiece) {
|
||||
public EntityNMSArmorStand(World world, HologramLine parentPiece, PacketController packetController) {
|
||||
super(EntityTypes.ARMOR_STAND, world);
|
||||
super.setInvisible(true);
|
||||
super.setSmall(true);
|
||||
|
@ -42,9 +44,10 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||
super.setBasePlate(true);
|
||||
super.setMarker(true);
|
||||
super.collides = false;
|
||||
this.parentPiece = parentPiece;
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
|
||||
this.parentPiece = parentPiece;
|
||||
this.packetController = packetController;
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
}
|
||||
|
||||
|
@ -193,9 +196,9 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setLocationNMS(double x, double y, double z, boolean broadcastLocationPacket) {
|
||||
public void setLocationNMS(double x, double y, double z) {
|
||||
super.setPosition(x, y, z);
|
||||
if (broadcastLocationPacket) {
|
||||
if (packetController.shouldBroadcastLocationPacket()) {
|
||||
broadcastLocationPacketNMS();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,8 +32,8 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle");
|
||||
|
||||
private ItemLine parentPiece;
|
||||
private ItemPickupManager itemPickupManager;
|
||||
private final ItemLine parentPiece;
|
||||
private final ItemPickupManager itemPickupManager;
|
||||
private CraftEntity customBukkitEntity;
|
||||
|
||||
public EntityNMSItem(World world, ItemLine piece, ItemPickupManager itemPickupManager) {
|
||||
|
@ -62,14 +62,13 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||
// Method called when a player is near.
|
||||
@Override
|
||||
public void pickup(EntityHuman human) {
|
||||
|
||||
if (human.locY() < super.locY() - 1.5 || human.locY() > super.locY() + 1.0) {
|
||||
// Too low or too high, it's a bit weird./
|
||||
return;
|
||||
}
|
||||
|
||||
if (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) {
|
||||
itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent());
|
||||
itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece);
|
||||
// It is never added to the inventory.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
|||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle");
|
||||
|
||||
private HologramLine parentPiece;
|
||||
private final HologramLine parentPiece;
|
||||
private CraftEntity customBukkitEntity;
|
||||
|
||||
public EntityNMSSlime(World world, HologramLine parentPiece) {
|
||||
|
|
|
@ -16,6 +16,7 @@ import me.filoghost.holographicdisplays.nms.interfaces.ChatComponentAdapter;
|
|||
import me.filoghost.holographicdisplays.nms.interfaces.CustomNameHelper;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.ItemPickupManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.PacketController;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSItem;
|
||||
|
@ -30,6 +31,7 @@ import net.minecraft.server.v1_15_R1.RegistryID;
|
|||
import net.minecraft.server.v1_15_R1.RegistryMaterials;
|
||||
import net.minecraft.server.v1_15_R1.WorldServer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
@ -41,6 +43,14 @@ public class NmsManagerImpl implements NMSManager {
|
|||
private static final ReflectField<RegistryID<EntityTypes<?>>> REGISTRY_ID_FIELD = ReflectField.lookup(new ClassToken<RegistryID<EntityTypes<?>>>(){}, RegistryMaterials.class, "b");
|
||||
private static final ReflectField<Object[]> ID_TO_CLASS_MAP_FIELD = ReflectField.lookup(Object[].class, RegistryID.class, "d");
|
||||
private static final ReflectMethod<Void> REGISTER_ENTITY_METHOD = ReflectMethod.lookup(void.class, WorldServer.class, "registerEntity", Entity.class);
|
||||
|
||||
private final ItemPickupManager itemPickupManager;
|
||||
private final PacketController packetController;
|
||||
|
||||
public NmsManagerImpl(ItemPickupManager itemPickupManager, PacketController packetController) {
|
||||
this.itemPickupManager = itemPickupManager;
|
||||
this.packetController = packetController;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() throws Exception {
|
||||
|
@ -63,7 +73,7 @@ public class NmsManagerImpl implements NMSManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) {
|
||||
public NMSItem spawnNMSItem(World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack) {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager);
|
||||
customItem.setLocationNMS(x, y, z);
|
||||
|
@ -86,10 +96,10 @@ public class NmsManagerImpl implements NMSManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) {
|
||||
public NMSArmorStand spawnNMSArmorStand(World world, double x, double y, double z, HologramLine parentPiece) {
|
||||
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket);
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
|
@ -155,6 +165,7 @@ public class NmsManagerImpl implements NMSManager {
|
|||
|
||||
INSTANCE {
|
||||
|
||||
@Override
|
||||
public ChatComponentText cast(Object chatComponentObject) {
|
||||
return (ChatComponentText) chatComponentObject;
|
||||
}
|
||||
|
|
|
@ -6,8 +6,9 @@
|
|||
package me.filoghost.holographicdisplays.nms.v1_16_R1;
|
||||
|
||||
import me.filoghost.holographicdisplays.api.line.HologramLine;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.PacketController;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import net.minecraft.server.v1_16_R1.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_16_R1.DamageSource;
|
||||
import net.minecraft.server.v1_16_R1.EntityArmorStand;
|
||||
|
@ -29,11 +30,12 @@ import org.bukkit.craftbukkit.v1_16_R1.util.CraftChatMessage;
|
|||
|
||||
public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand {
|
||||
|
||||
private HologramLine parentPiece;
|
||||
private final HologramLine parentPiece;
|
||||
private final PacketController packetController;
|
||||
private CraftEntity customBukkitEntity;
|
||||
private String customName;
|
||||
|
||||
public EntityNMSArmorStand(World world, HologramLine parentPiece) {
|
||||
public EntityNMSArmorStand(World world, HologramLine parentPiece, PacketController packetController) {
|
||||
super(EntityTypes.ARMOR_STAND, world);
|
||||
super.setInvisible(true);
|
||||
super.setSmall(true);
|
||||
|
@ -42,9 +44,10 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||
super.setBasePlate(true);
|
||||
super.setMarker(true);
|
||||
super.collides = false;
|
||||
this.parentPiece = parentPiece;
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
|
||||
this.parentPiece = parentPiece;
|
||||
this.packetController = packetController;
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
}
|
||||
|
||||
|
@ -193,9 +196,9 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setLocationNMS(double x, double y, double z, boolean broadcastLocationPacket) {
|
||||
public void setLocationNMS(double x, double y, double z) {
|
||||
super.setPosition(x, y, z);
|
||||
if (broadcastLocationPacket) {
|
||||
if (packetController.shouldBroadcastLocationPacket()) {
|
||||
broadcastLocationPacketNMS();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,8 +32,8 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle");
|
||||
|
||||
private ItemLine parentPiece;
|
||||
private ItemPickupManager itemPickupManager;
|
||||
private final ItemLine parentPiece;
|
||||
private final ItemPickupManager itemPickupManager;
|
||||
private CraftEntity customBukkitEntity;
|
||||
|
||||
public EntityNMSItem(World world, ItemLine piece, ItemPickupManager itemPickupManager) {
|
||||
|
@ -62,14 +62,13 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||
// Method called when a player is near.
|
||||
@Override
|
||||
public void pickup(EntityHuman human) {
|
||||
|
||||
if (human.locY() < super.locY() - 1.5 || human.locY() > super.locY() + 1.0) {
|
||||
// Too low or too high, it's a bit weird./
|
||||
return;
|
||||
}
|
||||
|
||||
if (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) {
|
||||
itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent());
|
||||
itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece);
|
||||
// It is never added to the inventory.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
|||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle");
|
||||
|
||||
private HologramLine parentPiece;
|
||||
private final HologramLine parentPiece;
|
||||
private CraftEntity customBukkitEntity;
|
||||
|
||||
public EntityNMSSlime(World world, HologramLine parentPiece) {
|
||||
|
|
|
@ -16,6 +16,7 @@ import me.filoghost.holographicdisplays.nms.interfaces.ChatComponentAdapter;
|
|||
import me.filoghost.holographicdisplays.nms.interfaces.CustomNameHelper;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.ItemPickupManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.PacketController;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSItem;
|
||||
|
@ -30,6 +31,7 @@ import net.minecraft.server.v1_16_R1.RegistryID;
|
|||
import net.minecraft.server.v1_16_R1.RegistryMaterials;
|
||||
import net.minecraft.server.v1_16_R1.WorldServer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.entity.CraftEntity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
@ -41,6 +43,14 @@ public class NmsManagerImpl implements NMSManager {
|
|||
private static final ReflectField<RegistryID<EntityTypes<?>>> REGISTRY_ID_FIELD = ReflectField.lookup(new ClassToken<RegistryID<EntityTypes<?>>>(){}, RegistryMaterials.class, "b");
|
||||
private static final ReflectField<Object[]> ID_TO_CLASS_MAP_FIELD = ReflectField.lookup(Object[].class, RegistryID.class, "d");
|
||||
private static final ReflectMethod<Void> REGISTER_ENTITY_METHOD = ReflectMethod.lookup(void.class, WorldServer.class, "registerEntity", Entity.class);
|
||||
|
||||
private final ItemPickupManager itemPickupManager;
|
||||
private final PacketController packetController;
|
||||
|
||||
public NmsManagerImpl(ItemPickupManager itemPickupManager, PacketController packetController) {
|
||||
this.itemPickupManager = itemPickupManager;
|
||||
this.packetController = packetController;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() throws Exception {
|
||||
|
@ -63,7 +73,7 @@ public class NmsManagerImpl implements NMSManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) {
|
||||
public NMSItem spawnNMSItem(World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack) {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager);
|
||||
customItem.setLocationNMS(x, y, z);
|
||||
|
@ -86,10 +96,10 @@ public class NmsManagerImpl implements NMSManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) {
|
||||
public NMSArmorStand spawnNMSArmorStand(World world, double x, double y, double z, HologramLine parentPiece) {
|
||||
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket);
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
|
@ -155,6 +165,7 @@ public class NmsManagerImpl implements NMSManager {
|
|||
|
||||
INSTANCE {
|
||||
|
||||
@Override
|
||||
public ChatComponentText cast(Object chatComponentObject) {
|
||||
return (ChatComponentText) chatComponentObject;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
package me.filoghost.holographicdisplays.nms.v1_16_R2;
|
||||
|
||||
import me.filoghost.holographicdisplays.api.line.HologramLine;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.PacketController;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import net.minecraft.server.v1_16_R2.AxisAlignedBB;
|
||||
|
@ -29,11 +30,12 @@ import org.bukkit.craftbukkit.v1_16_R2.util.CraftChatMessage;
|
|||
|
||||
public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand {
|
||||
|
||||
private HologramLine parentPiece;
|
||||
private final HologramLine parentPiece;
|
||||
private final PacketController packetController;
|
||||
private CraftEntity customBukkitEntity;
|
||||
private String customName;
|
||||
|
||||
public EntityNMSArmorStand(World world, HologramLine parentPiece) {
|
||||
public EntityNMSArmorStand(World world, HologramLine parentPiece, PacketController packetController) {
|
||||
super(EntityTypes.ARMOR_STAND, world);
|
||||
super.setInvisible(true);
|
||||
super.setSmall(true);
|
||||
|
@ -42,9 +44,10 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||
super.setBasePlate(true);
|
||||
super.setMarker(true);
|
||||
super.collides = false;
|
||||
this.parentPiece = parentPiece;
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
|
||||
this.parentPiece = parentPiece;
|
||||
this.packetController = packetController;
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
}
|
||||
|
||||
|
@ -193,9 +196,9 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setLocationNMS(double x, double y, double z, boolean broadcastLocationPacket) {
|
||||
public void setLocationNMS(double x, double y, double z) {
|
||||
super.setPosition(x, y, z);
|
||||
if (broadcastLocationPacket) {
|
||||
if (packetController.shouldBroadcastLocationPacket()) {
|
||||
broadcastLocationPacketNMS();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,8 +32,8 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle");
|
||||
|
||||
private ItemLine parentPiece;
|
||||
private ItemPickupManager itemPickupManager;
|
||||
private final ItemLine parentPiece;
|
||||
private final ItemPickupManager itemPickupManager;
|
||||
private CraftEntity customBukkitEntity;
|
||||
|
||||
public EntityNMSItem(World world, ItemLine piece, ItemPickupManager itemPickupManager) {
|
||||
|
@ -62,14 +62,13 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||
// Method called when a player is near.
|
||||
@Override
|
||||
public void pickup(EntityHuman human) {
|
||||
|
||||
if (human.locY() < super.locY() - 1.5 || human.locY() > super.locY() + 1.0) {
|
||||
// Too low or too high, it's a bit weird./
|
||||
return;
|
||||
}
|
||||
|
||||
if (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) {
|
||||
itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent());
|
||||
itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece);
|
||||
// It is never added to the inventory.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
|||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle");
|
||||
|
||||
private HologramLine parentPiece;
|
||||
private final HologramLine parentPiece;
|
||||
private CraftEntity customBukkitEntity;
|
||||
|
||||
public EntityNMSSlime(World world, HologramLine parentPiece) {
|
||||
|
|
|
@ -16,6 +16,7 @@ import me.filoghost.holographicdisplays.nms.interfaces.ChatComponentAdapter;
|
|||
import me.filoghost.holographicdisplays.nms.interfaces.CustomNameHelper;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.ItemPickupManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.PacketController;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSItem;
|
||||
|
@ -29,6 +30,7 @@ import net.minecraft.server.v1_16_R2.MathHelper;
|
|||
import net.minecraft.server.v1_16_R2.RegistryMaterials;
|
||||
import net.minecraft.server.v1_16_R2.WorldServer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.entity.CraftEntity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
@ -40,6 +42,14 @@ public class NmsManagerImpl implements NMSManager {
|
|||
|
||||
private static final ReflectField<Map<EntityTypes<?>, Integer>> REGISTRY_TO_ID_FIELD = ReflectField.lookup(new ClassToken<Map<EntityTypes<?>, Integer>>(){}, RegistryMaterials.class, "bg");
|
||||
private static final ReflectMethod<Void> REGISTER_ENTITY_METHOD = ReflectMethod.lookup(void.class, WorldServer.class, "registerEntity", Entity.class);
|
||||
|
||||
private final ItemPickupManager itemPickupManager;
|
||||
private final PacketController packetController;
|
||||
|
||||
public NmsManagerImpl(ItemPickupManager itemPickupManager, PacketController packetController) {
|
||||
this.itemPickupManager = itemPickupManager;
|
||||
this.packetController = packetController;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() throws Exception {
|
||||
|
@ -54,7 +64,7 @@ public class NmsManagerImpl implements NMSManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) {
|
||||
public NMSItem spawnNMSItem(World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack) {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager);
|
||||
customItem.setLocationNMS(x, y, z);
|
||||
|
@ -77,10 +87,10 @@ public class NmsManagerImpl implements NMSManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) {
|
||||
public NMSArmorStand spawnNMSArmorStand(World world, double x, double y, double z, HologramLine parentPiece) {
|
||||
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket);
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
|
@ -146,6 +156,7 @@ public class NmsManagerImpl implements NMSManager {
|
|||
|
||||
INSTANCE {
|
||||
|
||||
@Override
|
||||
public ChatComponentText cast(Object chatComponentObject) {
|
||||
return (ChatComponentText) chatComponentObject;
|
||||
}
|
||||
|
|
|
@ -6,8 +6,9 @@
|
|||
package me.filoghost.holographicdisplays.nms.v1_16_R3;
|
||||
|
||||
import me.filoghost.holographicdisplays.api.line.HologramLine;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.PacketController;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import net.minecraft.server.v1_16_R3.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_16_R3.DamageSource;
|
||||
import net.minecraft.server.v1_16_R3.EntityArmorStand;
|
||||
|
@ -29,11 +30,12 @@ import org.bukkit.craftbukkit.v1_16_R3.util.CraftChatMessage;
|
|||
|
||||
public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand {
|
||||
|
||||
private HologramLine parentPiece;
|
||||
private final HologramLine parentPiece;
|
||||
private final PacketController packetController;
|
||||
private CraftEntity customBukkitEntity;
|
||||
private String customName;
|
||||
|
||||
public EntityNMSArmorStand(World world, HologramLine parentPiece) {
|
||||
public EntityNMSArmorStand(World world, HologramLine parentPiece, PacketController packetController) {
|
||||
super(EntityTypes.ARMOR_STAND, world);
|
||||
super.setInvisible(true);
|
||||
super.setSmall(true);
|
||||
|
@ -42,9 +44,10 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||
super.setBasePlate(true);
|
||||
super.setMarker(true);
|
||||
super.collides = false;
|
||||
this.parentPiece = parentPiece;
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
|
||||
this.parentPiece = parentPiece;
|
||||
this.packetController = packetController;
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
}
|
||||
|
||||
|
@ -193,9 +196,9 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setLocationNMS(double x, double y, double z, boolean broadcastLocationPacket) {
|
||||
public void setLocationNMS(double x, double y, double z) {
|
||||
super.setPosition(x, y, z);
|
||||
if (broadcastLocationPacket) {
|
||||
if (packetController.shouldBroadcastLocationPacket()) {
|
||||
broadcastLocationPacketNMS();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,8 +32,8 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle");
|
||||
|
||||
private ItemLine parentPiece;
|
||||
private ItemPickupManager itemPickupManager;
|
||||
private final ItemLine parentPiece;
|
||||
private final ItemPickupManager itemPickupManager;
|
||||
private CraftEntity customBukkitEntity;
|
||||
|
||||
public EntityNMSItem(World world, ItemLine piece, ItemPickupManager itemPickupManager) {
|
||||
|
@ -62,14 +62,13 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||
// Method called when a player is near.
|
||||
@Override
|
||||
public void pickup(EntityHuman human) {
|
||||
|
||||
if (human.locY() < super.locY() - 1.5 || human.locY() > super.locY() + 1.0) {
|
||||
// Too low or too high, it's a bit weird./
|
||||
return;
|
||||
}
|
||||
|
||||
if (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) {
|
||||
itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent());
|
||||
itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece);
|
||||
// It is never added to the inventory.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
|||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle");
|
||||
|
||||
private HologramLine parentPiece;
|
||||
private final HologramLine parentPiece;
|
||||
private CraftEntity customBukkitEntity;
|
||||
|
||||
public EntityNMSSlime(World world, HologramLine parentPiece) {
|
||||
|
|
|
@ -16,6 +16,7 @@ import me.filoghost.holographicdisplays.nms.interfaces.ChatComponentAdapter;
|
|||
import me.filoghost.holographicdisplays.nms.interfaces.CustomNameHelper;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.ItemPickupManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.PacketController;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSItem;
|
||||
|
@ -29,6 +30,7 @@ import net.minecraft.server.v1_16_R3.MathHelper;
|
|||
import net.minecraft.server.v1_16_R3.RegistryMaterials;
|
||||
import net.minecraft.server.v1_16_R3.WorldServer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
@ -40,6 +42,14 @@ public class NmsManagerImpl implements NMSManager {
|
|||
|
||||
private static final ReflectField<Map<EntityTypes<?>, Integer>> REGISTRY_TO_ID_FIELD = ReflectField.lookup(new ClassToken<Map<EntityTypes<?>, Integer>>(){}, RegistryMaterials.class, "bg");
|
||||
private static final ReflectMethod<Void> REGISTER_ENTITY_METHOD = ReflectMethod.lookup(void.class, WorldServer.class, "registerEntity", Entity.class);
|
||||
|
||||
private final ItemPickupManager itemPickupManager;
|
||||
private final PacketController packetController;
|
||||
|
||||
public NmsManagerImpl(ItemPickupManager itemPickupManager, PacketController packetController) {
|
||||
this.itemPickupManager = itemPickupManager;
|
||||
this.packetController = packetController;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() throws Exception {
|
||||
|
@ -54,7 +64,7 @@ public class NmsManagerImpl implements NMSManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) {
|
||||
public NMSItem spawnNMSItem(World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack) {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager);
|
||||
customItem.setLocationNMS(x, y, z);
|
||||
|
@ -77,10 +87,10 @@ public class NmsManagerImpl implements NMSManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) {
|
||||
public NMSArmorStand spawnNMSArmorStand(World world, double x, double y, double z, HologramLine parentPiece) {
|
||||
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket);
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
|
@ -146,6 +156,7 @@ public class NmsManagerImpl implements NMSManager {
|
|||
|
||||
INSTANCE {
|
||||
|
||||
@Override
|
||||
public ChatComponentText cast(Object chatComponentObject) {
|
||||
return (ChatComponentText) chatComponentObject;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import me.filoghost.fcommons.reflection.ReflectMethod;
|
|||
import me.filoghost.holographicdisplays.api.line.HologramLine;
|
||||
import me.filoghost.holographicdisplays.common.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.PacketController;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import net.minecraft.server.v1_8_R2.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_8_R2.DamageSource;
|
||||
|
@ -28,30 +29,32 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||
private static final ReflectField<Integer> DISABLED_SLOTS_FIELD = ReflectField.lookup(int.class, EntityArmorStand.class, "bi");
|
||||
private static final ReflectMethod<Void> SET_MARKER_METHOD = ReflectMethod.lookup(void.class, EntityArmorStand.class, "n", boolean.class);
|
||||
|
||||
private HologramLine parentPiece;
|
||||
private final HologramLine parentPiece;
|
||||
private final PacketController packetController;
|
||||
private String customName;
|
||||
|
||||
public EntityNMSArmorStand(World world, HologramLine parentPiece) {
|
||||
public EntityNMSArmorStand(World world, HologramLine parentPiece, PacketController packetController) {
|
||||
super(world);
|
||||
setInvisible(true);
|
||||
setSmall(true);
|
||||
setArms(false);
|
||||
setGravity(true);
|
||||
setBasePlate(true);
|
||||
super.setInvisible(true);
|
||||
super.setSmall(true);
|
||||
super.setArms(false);
|
||||
super.setGravity(true);
|
||||
super.setBasePlate(true);
|
||||
try {
|
||||
SET_MARKER_METHOD.invoke(this, true);
|
||||
} catch (Throwable t) {
|
||||
DebugLogger.cannotSetArmorStandAsMarker(t);
|
||||
// It will still work, but the offset will be wrong.
|
||||
}
|
||||
this.parentPiece = parentPiece;
|
||||
try {
|
||||
DISABLED_SLOTS_FIELD.set(this, Integer.MAX_VALUE);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
// There's still the overridden method.
|
||||
}
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
|
||||
this.parentPiece = parentPiece;
|
||||
this.packetController = packetController;
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
}
|
||||
|
||||
|
@ -185,9 +188,9 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setLocationNMS(double x, double y, double z, boolean broadcastLocationPacket) {
|
||||
public void setLocationNMS(double x, double y, double z) {
|
||||
super.setPosition(x, y, z);
|
||||
if (broadcastLocationPacket) {
|
||||
if (packetController.shouldBroadcastLocationPacket()) {
|
||||
broadcastLocationPacketNMS();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,8 +32,8 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||
private static final ReflectField<Double> RIDER_PITCH_DELTA = ReflectField.lookup(double.class, Entity.class, "ar");
|
||||
private static final ReflectField<Double> RIDER_YAW_DELTA = ReflectField.lookup(double.class, Entity.class, "as");
|
||||
|
||||
private ItemLine parentPiece;
|
||||
private ItemPickupManager itemPickupManager;
|
||||
private final ItemLine parentPiece;
|
||||
private final ItemPickupManager itemPickupManager;
|
||||
|
||||
public EntityNMSItem(World world, ItemLine piece, ItemPickupManager itemPickupManager) {
|
||||
super(world);
|
||||
|
@ -61,14 +61,13 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||
// Method called when a player is near.
|
||||
@Override
|
||||
public void d(EntityHuman human) {
|
||||
|
||||
if (human.locY < this.locY - 1.5 || human.locY > this.locY + 1.0) {
|
||||
// Too low or too high, it's a bit weird.
|
||||
return;
|
||||
}
|
||||
|
||||
if (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) {
|
||||
itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent());
|
||||
itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece);
|
||||
// It is never added to the inventory.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
|||
private static final ReflectField<Double> RIDER_PITCH_DELTA = ReflectField.lookup(double.class, Entity.class, "ar");
|
||||
private static final ReflectField<Double> RIDER_YAW_DELTA = ReflectField.lookup(double.class, Entity.class, "as");
|
||||
|
||||
private HologramLine parentPiece;
|
||||
private final HologramLine parentPiece;
|
||||
|
||||
public EntityNMSSlime(World world, HologramLine parentPiece) {
|
||||
super(world);
|
||||
|
|
|
@ -15,6 +15,7 @@ import me.filoghost.holographicdisplays.common.DebugLogger;
|
|||
import me.filoghost.holographicdisplays.nms.interfaces.CustomNameHelper;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.ItemPickupManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.PacketController;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSItem;
|
||||
|
@ -37,6 +38,14 @@ public class NmsManagerImpl implements NMSManager {
|
|||
private static final ReflectField<Map<Class<?>, Integer>> ENTITY_IDS_BY_CLASS_FIELD = ReflectField.lookup(new ClassToken<Map<Class<?>, Integer>>(){}, EntityTypes.class, "f");
|
||||
|
||||
private static final ReflectMethod<?> VALIDATE_ENTITY_METHOD = ReflectMethod.lookup(Object.class, World.class, "a", Entity.class);
|
||||
|
||||
private final ItemPickupManager itemPickupManager;
|
||||
private final PacketController packetController;
|
||||
|
||||
public NmsManagerImpl(ItemPickupManager itemPickupManager, PacketController packetController) {
|
||||
this.itemPickupManager = itemPickupManager;
|
||||
this.packetController = packetController;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() throws Exception {
|
||||
|
@ -51,7 +60,7 @@ public class NmsManagerImpl implements NMSManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) {
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack) {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager);
|
||||
customItem.setLocationNMS(x, y, z);
|
||||
|
@ -74,10 +83,10 @@ public class NmsManagerImpl implements NMSManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) {
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece) {
|
||||
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket);
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import me.filoghost.fcommons.reflection.ReflectMethod;
|
|||
import me.filoghost.holographicdisplays.api.line.HologramLine;
|
||||
import me.filoghost.holographicdisplays.common.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.PacketController;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import net.minecraft.server.v1_8_R3.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_8_R3.DamageSource;
|
||||
|
@ -28,30 +29,32 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||
private static final ReflectField<Integer> DISABLED_SLOTS_FIELD = ReflectField.lookup(int.class, EntityArmorStand.class, "bi");
|
||||
private static final ReflectMethod<Void> SET_MARKER_METHOD = ReflectMethod.lookup(void.class, EntityArmorStand.class, "n", boolean.class);
|
||||
|
||||
private HologramLine parentPiece;
|
||||
private final HologramLine parentPiece;
|
||||
private final PacketController packetController;
|
||||
private String customName;
|
||||
|
||||
public EntityNMSArmorStand(World world, HologramLine parentPiece) {
|
||||
public EntityNMSArmorStand(World world, HologramLine parentPiece, PacketController packetController) {
|
||||
super(world);
|
||||
setInvisible(true);
|
||||
setSmall(true);
|
||||
setArms(false);
|
||||
setGravity(true);
|
||||
setBasePlate(true);
|
||||
super.setInvisible(true);
|
||||
super.setSmall(true);
|
||||
super.setArms(false);
|
||||
super.setGravity(true);
|
||||
super.setBasePlate(true);
|
||||
try {
|
||||
SET_MARKER_METHOD.invoke(this, true);
|
||||
} catch (Throwable t) {
|
||||
DebugLogger.cannotSetArmorStandAsMarker(t);
|
||||
// It will still work, but the offset will be wrong.
|
||||
}
|
||||
this.parentPiece = parentPiece;
|
||||
try {
|
||||
DISABLED_SLOTS_FIELD.set(this, Integer.MAX_VALUE);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
// There's still the overridden method.
|
||||
}
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
|
||||
this.parentPiece = parentPiece;
|
||||
this.packetController = packetController;
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
}
|
||||
|
||||
|
@ -185,9 +188,9 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setLocationNMS(double x, double y, double z, boolean broadcastLocationPacket) {
|
||||
public void setLocationNMS(double x, double y, double z) {
|
||||
super.setPosition(x, y, z);
|
||||
if (broadcastLocationPacket) {
|
||||
if (packetController.shouldBroadcastLocationPacket()) {
|
||||
broadcastLocationPacketNMS();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,8 +32,8 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||
private static final ReflectField<Double> RIDER_PITCH_DELTA = ReflectField.lookup(double.class, Entity.class, "ar");
|
||||
private static final ReflectField<Double> RIDER_YAW_DELTA = ReflectField.lookup(double.class, Entity.class, "as");
|
||||
|
||||
private ItemLine parentPiece;
|
||||
private ItemPickupManager itemPickupManager;
|
||||
private final ItemLine parentPiece;
|
||||
private final ItemPickupManager itemPickupManager;
|
||||
|
||||
public EntityNMSItem(World world, ItemLine piece, ItemPickupManager itemPickupManager) {
|
||||
super(world);
|
||||
|
@ -61,14 +61,13 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||
// Method called when a player is near.
|
||||
@Override
|
||||
public void d(EntityHuman human) {
|
||||
|
||||
if (human.locY < this.locY - 1.5 || human.locY > this.locY + 1.0) {
|
||||
// Too low or too high, it's a bit weird.
|
||||
return;
|
||||
}
|
||||
|
||||
if (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) {
|
||||
itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent());
|
||||
itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece);
|
||||
// It is never added to the inventory.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
|||
private static final ReflectField<Double> RIDER_PITCH_DELTA = ReflectField.lookup(double.class, Entity.class, "ar");
|
||||
private static final ReflectField<Double> RIDER_YAW_DELTA = ReflectField.lookup(double.class, Entity.class, "as");
|
||||
|
||||
private HologramLine parentPiece;
|
||||
private final HologramLine parentPiece;
|
||||
|
||||
public EntityNMSSlime(World world, HologramLine parentPiece) {
|
||||
super(world);
|
||||
|
|
|
@ -15,6 +15,7 @@ import me.filoghost.holographicdisplays.common.DebugLogger;
|
|||
import me.filoghost.holographicdisplays.nms.interfaces.CustomNameHelper;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.ItemPickupManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.PacketController;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSItem;
|
||||
|
@ -37,6 +38,14 @@ public class NmsManagerImpl implements NMSManager {
|
|||
private static final ReflectField<Map<Class<?>, Integer>> ENTITY_IDS_BY_CLASS_FIELD = ReflectField.lookup(new ClassToken<Map<Class<?>, Integer>>(){}, EntityTypes.class, "f");
|
||||
|
||||
private static final ReflectMethod<?> VALIDATE_ENTITY_METHOD = ReflectMethod.lookup(Object.class, World.class, "a", Entity.class);
|
||||
|
||||
private final ItemPickupManager itemPickupManager;
|
||||
private final PacketController packetController;
|
||||
|
||||
public NmsManagerImpl(ItemPickupManager itemPickupManager, PacketController packetController) {
|
||||
this.itemPickupManager = itemPickupManager;
|
||||
this.packetController = packetController;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() throws Exception {
|
||||
|
@ -51,7 +60,7 @@ public class NmsManagerImpl implements NMSManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) {
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack) {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager);
|
||||
customItem.setLocationNMS(x, y, z);
|
||||
|
@ -74,10 +83,10 @@ public class NmsManagerImpl implements NMSManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) {
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece) {
|
||||
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket);
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
|
|
|
@ -5,10 +5,11 @@
|
|||
*/
|
||||
package me.filoghost.holographicdisplays.nms.v1_9_R1;
|
||||
|
||||
import me.filoghost.holographicdisplays.api.line.HologramLine;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.holographicdisplays.api.line.HologramLine;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.PacketController;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import net.minecraft.server.v1_9_R1.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_9_R1.DamageSource;
|
||||
import net.minecraft.server.v1_9_R1.EntityArmorStand;
|
||||
|
@ -29,11 +30,12 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||
|
||||
private static final ReflectField<Integer> DISABLED_SLOTS_FIELD = ReflectField.lookup(int.class, EntityArmorStand.class, "bz");
|
||||
|
||||
private HologramLine parentPiece;
|
||||
private final HologramLine parentPiece;
|
||||
private final PacketController packetController;
|
||||
|
||||
private String customName;
|
||||
|
||||
public EntityNMSArmorStand(World world, HologramLine parentPiece) {
|
||||
public EntityNMSArmorStand(World world, HologramLine parentPiece, PacketController packetController) {
|
||||
super(world);
|
||||
super.setInvisible(true);
|
||||
super.setSmall(true);
|
||||
|
@ -41,14 +43,15 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||
super.setGravity(true);
|
||||
super.setBasePlate(true);
|
||||
super.setMarker(true);
|
||||
this.parentPiece = parentPiece;
|
||||
try {
|
||||
DISABLED_SLOTS_FIELD.set(this, Integer.MAX_VALUE);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
// There's still the overridden method.
|
||||
}
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
|
||||
this.parentPiece = parentPiece;
|
||||
this.packetController = packetController;
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
}
|
||||
|
||||
|
@ -197,9 +200,9 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setLocationNMS(double x, double y, double z, boolean broadcastLocationPacket) {
|
||||
public void setLocationNMS(double x, double y, double z) {
|
||||
super.setPosition(x, y, z);
|
||||
if (broadcastLocationPacket) {
|
||||
if (packetController.shouldBroadcastLocationPacket()) {
|
||||
broadcastLocationPacketNMS();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,8 +33,8 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "as");
|
||||
|
||||
private ItemLine parentPiece;
|
||||
private ItemPickupManager itemPickupManager;
|
||||
private final ItemLine parentPiece;
|
||||
private final ItemPickupManager itemPickupManager;
|
||||
|
||||
private int resendMountPacketTicks;
|
||||
|
||||
|
@ -84,14 +84,13 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||
// Method called when a player is near.
|
||||
@Override
|
||||
public void d(EntityHuman human) {
|
||||
|
||||
if (human.locY < super.locY - 1.5 || human.locY > super.locY + 1.0) {
|
||||
// Too low or too high, it's a bit weird.
|
||||
return;
|
||||
}
|
||||
|
||||
if (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) {
|
||||
itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent());
|
||||
itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece);
|
||||
// It is never added to the inventory.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
|||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "as");
|
||||
|
||||
private HologramLine parentPiece;
|
||||
private final HologramLine parentPiece;
|
||||
|
||||
private int resendMountPacketTicks;
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ import me.filoghost.holographicdisplays.common.DebugLogger;
|
|||
import me.filoghost.holographicdisplays.nms.interfaces.CustomNameHelper;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.ItemPickupManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.PacketController;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSItem;
|
||||
|
@ -36,6 +37,14 @@ public class NmsManagerImpl implements NMSManager {
|
|||
private static final ReflectField<Map<Class<?>, Integer>> ENTITY_IDS_BY_CLASS_FIELD = ReflectField.lookup(new ClassToken<Map<Class<?>, Integer>>(){}, EntityTypes.class, "f");
|
||||
|
||||
private static final ReflectMethod<?> VALIDATE_ENTITY_METHOD = ReflectMethod.lookup(Object.class, World.class, "b", Entity.class);
|
||||
|
||||
private final ItemPickupManager itemPickupManager;
|
||||
private final PacketController packetController;
|
||||
|
||||
public NmsManagerImpl(ItemPickupManager itemPickupManager, PacketController packetController) {
|
||||
this.itemPickupManager = itemPickupManager;
|
||||
this.packetController = packetController;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() throws Exception {
|
||||
|
@ -50,7 +59,7 @@ public class NmsManagerImpl implements NMSManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) {
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack) {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager);
|
||||
customItem.setLocationNMS(x, y, z);
|
||||
|
@ -73,10 +82,10 @@ public class NmsManagerImpl implements NMSManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) {
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece) {
|
||||
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket);
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
|
|
|
@ -6,8 +6,9 @@
|
|||
package me.filoghost.holographicdisplays.nms.v1_9_R2;
|
||||
|
||||
import me.filoghost.holographicdisplays.api.line.HologramLine;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.PacketController;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import net.minecraft.server.v1_9_R2.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_9_R2.DamageSource;
|
||||
import net.minecraft.server.v1_9_R2.EntityArmorStand;
|
||||
|
@ -26,10 +27,11 @@ import org.bukkit.craftbukkit.v1_9_R2.entity.CraftEntity;
|
|||
|
||||
public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand {
|
||||
|
||||
private HologramLine parentPiece;
|
||||
private final HologramLine parentPiece;
|
||||
private final PacketController packetController;
|
||||
private String customName;
|
||||
|
||||
public EntityNMSArmorStand(World world, HologramLine parentPiece) {
|
||||
public EntityNMSArmorStand(World world, HologramLine parentPiece, PacketController packetController) {
|
||||
super(world);
|
||||
super.setInvisible(true);
|
||||
super.setSmall(true);
|
||||
|
@ -37,9 +39,10 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||
super.setGravity(true);
|
||||
super.setBasePlate(true);
|
||||
super.setMarker(true);
|
||||
this.parentPiece = parentPiece;
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
|
||||
this.parentPiece = parentPiece;
|
||||
this.packetController = packetController;
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
}
|
||||
|
||||
|
@ -189,9 +192,9 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setLocationNMS(double x, double y, double z, boolean broadcastLocationPacket) {
|
||||
public void setLocationNMS(double x, double y, double z) {
|
||||
super.setPosition(x, y, z);
|
||||
if (broadcastLocationPacket) {
|
||||
if (packetController.shouldBroadcastLocationPacket()) {
|
||||
broadcastLocationPacketNMS();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,8 +33,8 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "at");
|
||||
|
||||
private ItemLine parentPiece;
|
||||
private ItemPickupManager itemPickupManager;
|
||||
private final ItemLine parentPiece;
|
||||
private final ItemPickupManager itemPickupManager;
|
||||
|
||||
private int resendMountPacketTicks;
|
||||
|
||||
|
@ -85,14 +85,13 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||
// Method called when a player is near.
|
||||
@Override
|
||||
public void d(EntityHuman human) {
|
||||
|
||||
if (human.locY < super.locY - 1.5 || human.locY > super.locY + 1.0) {
|
||||
// Too low or too high, it's a bit weird.
|
||||
return;
|
||||
}
|
||||
|
||||
if (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) {
|
||||
itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent());
|
||||
itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece);
|
||||
// It is never added to the inventory.
|
||||
}
|
||||
}
|
||||
|
@ -229,8 +228,8 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||
Entity entity = (Entity) vehicleBase;
|
||||
|
||||
try {
|
||||
if (super.bz() != null) {
|
||||
Entity oldVehicle = super.bz();
|
||||
Entity oldVehicle = super.bz();
|
||||
if (oldVehicle != null) {
|
||||
VEHICLE_FIELD.set(this, null);
|
||||
oldVehicle.passengers.remove(this);
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
|||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "at");
|
||||
|
||||
private HologramLine parentPiece;
|
||||
private final HologramLine parentPiece;
|
||||
|
||||
private int resendMountPacketTicks;
|
||||
|
||||
|
@ -216,8 +216,8 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
|||
Entity entity = (Entity) vehicleBase;
|
||||
|
||||
try {
|
||||
if (super.bz() != null) {
|
||||
Entity oldVehicle = super.bz();
|
||||
Entity oldVehicle = super.bz();
|
||||
if (oldVehicle != null) {
|
||||
VEHICLE_FIELD.set(this, null);
|
||||
oldVehicle.passengers.remove(this);
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import me.filoghost.holographicdisplays.common.DebugLogger;
|
|||
import me.filoghost.holographicdisplays.nms.interfaces.CustomNameHelper;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.ItemPickupManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.PacketController;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSItem;
|
||||
|
@ -36,6 +37,14 @@ public class NmsManagerImpl implements NMSManager {
|
|||
private static final ReflectField<Map<Class<?>, Integer>> ENTITY_IDS_BY_CLASS_FIELD = ReflectField.lookup(new ClassToken<Map<Class<?>, Integer>>(){}, EntityTypes.class, "f");
|
||||
|
||||
private static final ReflectMethod<?> VALIDATE_ENTITY_METHOD = ReflectMethod.lookup(Object.class, World.class, "b", Entity.class);
|
||||
|
||||
private final ItemPickupManager itemPickupManager;
|
||||
private final PacketController packetController;
|
||||
|
||||
public NmsManagerImpl(ItemPickupManager itemPickupManager, PacketController packetController) {
|
||||
this.itemPickupManager = itemPickupManager;
|
||||
this.packetController = packetController;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() throws Exception {
|
||||
|
@ -50,7 +59,7 @@ public class NmsManagerImpl implements NMSManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) {
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack) {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager);
|
||||
customItem.setLocationNMS(x, y, z);
|
||||
|
@ -73,10 +82,10 @@ public class NmsManagerImpl implements NMSManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) {
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece) {
|
||||
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket);
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
|
|
|
@ -8,17 +8,15 @@ package me.filoghost.holographicdisplays;
|
|||
import org.bukkit.ChatColor;
|
||||
|
||||
public class Colors {
|
||||
|
||||
public static final String
|
||||
|
||||
PRIMARY = "" + ChatColor.AQUA,
|
||||
PRIMARY_SHADOW = "" + ChatColor.DARK_AQUA,
|
||||
|
||||
SECONDARY = "" + ChatColor.WHITE,
|
||||
SECONDARY_SHADOW = "" + ChatColor.GRAY,
|
||||
|
||||
BOLD = "" + ChatColor.BOLD,
|
||||
|
||||
ERROR = "" + ChatColor.RED;
|
||||
public static final String PRIMARY = "" + ChatColor.AQUA;
|
||||
public static final String PRIMARY_SHADOW = "" + ChatColor.DARK_AQUA;
|
||||
|
||||
public static final String SECONDARY = "" + ChatColor.WHITE;
|
||||
public static final String SECONDARY_SHADOW = "" + ChatColor.GRAY;
|
||||
|
||||
public static final String BOLD = "" + ChatColor.BOLD;
|
||||
|
||||
public static final String ERROR = "" + ChatColor.RED;
|
||||
|
||||
}
|
||||
|
|
|
@ -3,13 +3,14 @@
|
|||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.object;
|
||||
package me.filoghost.holographicdisplays;
|
||||
|
||||
import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.holographicdisplays.HolographicDisplays;
|
||||
import me.filoghost.holographicdisplays.api.Hologram;
|
||||
import me.filoghost.holographicdisplays.api.internal.BackendAPI;
|
||||
import me.filoghost.holographicdisplays.api.placeholder.PlaceholderReplacer;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.object.APIHologramManager;
|
||||
import me.filoghost.holographicdisplays.placeholder.Placeholder;
|
||||
import me.filoghost.holographicdisplays.placeholder.PlaceholdersRegister;
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -20,19 +21,26 @@ import org.bukkit.plugin.Plugin;
|
|||
import java.util.Collection;
|
||||
|
||||
public class DefaultBackendAPI extends BackendAPI {
|
||||
|
||||
|
||||
private final APIHologramManager apiHologramManager;
|
||||
private final NMSManager nmsManager;
|
||||
|
||||
public DefaultBackendAPI(APIHologramManager apiHologramManager, NMSManager nmsManager) {
|
||||
this.apiHologramManager = apiHologramManager;
|
||||
this.nmsManager = nmsManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hologram createHologram(Plugin plugin, Location source) {
|
||||
Preconditions.notNull(plugin, "plugin");
|
||||
Preconditions.notNull(source, "source");
|
||||
Preconditions.notNull(source.getWorld(), "source's world");
|
||||
Preconditions.checkState(Bukkit.isPrimaryThread(), "Async hologram creation");
|
||||
|
||||
PluginHologram hologram = new PluginHologram(source, plugin);
|
||||
PluginHologramManager.addHologram(hologram);
|
||||
|
||||
return hologram;
|
||||
return apiHologramManager.createHologram(source, plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean registerPlaceholder(Plugin plugin, String textPlaceholder, double refreshRate, PlaceholderReplacer replacer) {
|
||||
Preconditions.notNull(textPlaceholder, "textPlaceholder");
|
||||
Preconditions.checkArgument(refreshRate >= 0, "refreshRate should be positive");
|
||||
|
@ -41,27 +49,32 @@ public class DefaultBackendAPI extends BackendAPI {
|
|||
return PlaceholdersRegister.register(new Placeholder(plugin, textPlaceholder, refreshRate, replacer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHologramEntity(Entity bukkitEntity) {
|
||||
Preconditions.notNull(bukkitEntity, "bukkitEntity");
|
||||
return HolographicDisplays.getNMSManager().isNMSEntityBase(bukkitEntity);
|
||||
return nmsManager.isNMSEntityBase(bukkitEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Hologram> getHolograms(Plugin plugin) {
|
||||
Preconditions.notNull(plugin, "plugin");
|
||||
return PluginHologramManager.getHolograms(plugin);
|
||||
return apiHologramManager.getHologramsByPlugin(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getRegisteredPlaceholders(Plugin plugin) {
|
||||
Preconditions.notNull(plugin, "plugin");
|
||||
return PlaceholdersRegister.getTextPlaceholdersByPlugin(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean unregisterPlaceholder(Plugin plugin, String textPlaceholder) {
|
||||
Preconditions.notNull(plugin, "plugin");
|
||||
Preconditions.notNull(textPlaceholder, "textPlaceholder");
|
||||
return PlaceholdersRegister.unregister(plugin, textPlaceholder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterPlaceholders(Plugin plugin) {
|
||||
Preconditions.notNull(plugin, "plugin");
|
||||
for (String placeholder : getRegisteredPlaceholders(plugin)) {
|
|
@ -5,74 +5,92 @@
|
|||
*/
|
||||
package me.filoghost.holographicdisplays;
|
||||
|
||||
import me.filoghost.fcommons.BaseJavaPlugin;
|
||||
import me.filoghost.fcommons.FCommonsPlugin;
|
||||
import me.filoghost.fcommons.FeatureSupport;
|
||||
import me.filoghost.fcommons.config.exception.ConfigException;
|
||||
import me.filoghost.fcommons.logging.Log;
|
||||
import me.filoghost.fcommons.reflection.ReflectUtils;
|
||||
import me.filoghost.holographicdisplays.api.Hologram;
|
||||
import me.filoghost.holographicdisplays.api.internal.BackendAPI;
|
||||
import me.filoghost.holographicdisplays.api.line.ItemLine;
|
||||
import me.filoghost.holographicdisplays.bridge.bungeecord.BungeeServerTracker;
|
||||
import me.filoghost.holographicdisplays.bridge.protocollib.ProtocolLibHook;
|
||||
import me.filoghost.holographicdisplays.bridge.protocollib.current.ProtocolLibHookImpl;
|
||||
import me.filoghost.holographicdisplays.commands.HologramCommandManager;
|
||||
import me.filoghost.holographicdisplays.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.disk.Configuration;
|
||||
import me.filoghost.holographicdisplays.disk.upgrade.LegacySymbolsUpgrader;
|
||||
import me.filoghost.holographicdisplays.listener.ChunkListener;
|
||||
import me.filoghost.holographicdisplays.listener.MainListener;
|
||||
import me.filoghost.holographicdisplays.listener.SpawnListener;
|
||||
import me.filoghost.holographicdisplays.listener.UpdateNotificationListener;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.ItemPickupManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.object.DefaultBackendAPI;
|
||||
import me.filoghost.holographicdisplays.object.NamedHologram;
|
||||
import me.filoghost.holographicdisplays.object.NamedHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.PluginHologram;
|
||||
import me.filoghost.holographicdisplays.object.PluginHologramManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.PacketController;
|
||||
import me.filoghost.holographicdisplays.object.APIHologram;
|
||||
import me.filoghost.holographicdisplays.object.APIHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.placeholder.AnimationsRegister;
|
||||
import me.filoghost.holographicdisplays.placeholder.PlaceholdersManager;
|
||||
import me.filoghost.holographicdisplays.task.BungeeCleanupTask;
|
||||
import me.filoghost.holographicdisplays.task.StartupLoadHologramsTask;
|
||||
import me.filoghost.holographicdisplays.task.WorldPlayerCounterTask;
|
||||
import me.filoghost.holographicdisplays.util.NMSVersion;
|
||||
import me.filoghost.holographicdisplays.util.VersionUtils;
|
||||
import me.filoghost.updatechecker.UpdateChecker;
|
||||
import org.bstats.bukkit.MetricsLite;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class HolographicDisplays extends BaseJavaPlugin {
|
||||
public class HolographicDisplays extends FCommonsPlugin implements PacketController, ItemPickupManager {
|
||||
|
||||
// The main instance of the plugin.
|
||||
private static HolographicDisplays instance;
|
||||
|
||||
// The manager for net.minecraft.server access.
|
||||
private static NMSManager nmsManager;
|
||||
|
||||
// The listener for all the Bukkit and NMS events.
|
||||
private static MainListener mainListener;
|
||||
|
||||
// The command handler, just in case a plugin wants to register more commands.
|
||||
private static HologramCommandManager commandManager;
|
||||
|
||||
// The new version found by the updater, null if there is no new version.
|
||||
private static String newVersion;
|
||||
|
||||
// Not null if ProtocolLib is installed and successfully loaded.
|
||||
private static ProtocolLibHook protocolLibHook;
|
||||
|
||||
private static Path dataFolderPath;
|
||||
private InternalHologramManager internalHologramManager;
|
||||
private APIHologramManager apiHologramManager;
|
||||
|
||||
@Override
|
||||
public void onCheckedEnable() throws PluginEnableException {
|
||||
// Warn about plugin reloaders and the /reload command.
|
||||
if (instance != null || System.getProperty("HolographicDisplaysLoaded") != null) {
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[HolographicDisplays] Please do not use /reload or plugin reloaders. Use the command \"/holograms reload\" instead. You will receive no support for doing this operation.");
|
||||
Bukkit.getConsoleSender().sendMessage(
|
||||
ChatColor.RED + "[HolographicDisplays] Please do not use /reload or plugin reloaders."
|
||||
+ " Use the command \"/holograms reload\" instead."
|
||||
+ " You will receive no support for doing this operation.");
|
||||
}
|
||||
|
||||
System.setProperty("HolographicDisplaysLoaded", "true");
|
||||
instance = this;
|
||||
dataFolderPath = getDataFolder().toPath();
|
||||
ConfigManager configManager = new ConfigManager(dataFolderPath);
|
||||
|
||||
// The bungee chat API is required.
|
||||
if (!FeatureSupport.CHAT_COMPONENTS) {
|
||||
throw new PluginEnableException(
|
||||
"Holographic Displays requires the new chat API.",
|
||||
"You are probably running CraftBukkit instead of Spigot.");
|
||||
}
|
||||
|
||||
if (!NMSVersion.isValid()) {
|
||||
throw new PluginEnableException(
|
||||
"Holographic Displays does not support this server version.",
|
||||
"Supported Spigot versions: from 1.8.3 to 1.16.4.");
|
||||
}
|
||||
|
||||
if (getCommand("holograms") == null) {
|
||||
throw new PluginEnableException(
|
||||
"Holographic Displays was unable to register the command \"holograms\".",
|
||||
"This can be caused by edits to plugin.yml or other plugins.");
|
||||
}
|
||||
|
||||
NMSManager nmsManager;
|
||||
try {
|
||||
nmsManager = NMSVersion.get().createNMSManager(this, this);
|
||||
nmsManager.setup();
|
||||
} catch (Exception e) {
|
||||
throw new PluginEnableException(e, "Couldn't initialize the NMS manager.");
|
||||
}
|
||||
|
||||
internalHologramManager = new InternalHologramManager(nmsManager);
|
||||
apiHologramManager = new APIHologramManager(nmsManager);
|
||||
ConfigManager configManager = new ConfigManager(getDataFolder().toPath());
|
||||
|
||||
// Run only once at startup, before anything else.
|
||||
try {
|
||||
|
@ -87,42 +105,13 @@ public class HolographicDisplays extends BaseJavaPlugin {
|
|||
// Load the configuration.
|
||||
configManager.reloadMainConfig();
|
||||
|
||||
if (Configuration.updateNotification) {
|
||||
UpdateChecker.run(this, 75097, (String newVersion) -> {
|
||||
HolographicDisplays.newVersion = newVersion;
|
||||
Log.info("Found a new version available: " + newVersion);
|
||||
Log.info("Download it on Bukkit Dev:");
|
||||
Log.info("dev.bukkit.org/projects/holographic-displays");
|
||||
});
|
||||
}
|
||||
|
||||
// The bungee chat API is required.
|
||||
if (!ReflectUtils.isClassLoaded("net.md_5.bungee.api.chat.ComponentBuilder")) {
|
||||
throw new PluginEnableException(
|
||||
"Holographic Displays requires the new chat API.",
|
||||
"You are probably running CraftBukkit instead of Spigot.");
|
||||
}
|
||||
|
||||
if (!NMSVersion.isValid()) {
|
||||
throw new PluginEnableException(
|
||||
"Holographic Displays does not support this server version.",
|
||||
"Supported Spigot versions: from 1.8.3 to 1.16.4.");
|
||||
}
|
||||
|
||||
try {
|
||||
nmsManager = NMSVersion.createNMSManager();
|
||||
nmsManager.setup();
|
||||
} catch (Exception e) {
|
||||
throw new PluginEnableException(e, "Couldn't initialize the NMS manager.");
|
||||
}
|
||||
|
||||
// ProtocolLib check.
|
||||
hookProtocolLib();
|
||||
ProtocolLibHook.setup(this, nmsManager);
|
||||
|
||||
// Load animation files and the placeholder manager.
|
||||
PlaceholdersManager.load(this);
|
||||
try {
|
||||
AnimationsRegister.loadAnimations(this);
|
||||
AnimationsRegister.loadAnimations(configManager);
|
||||
} catch (Exception e) {
|
||||
Log.warning("Failed to load animation files!", e);
|
||||
}
|
||||
|
@ -134,112 +123,66 @@ public class HolographicDisplays extends BaseJavaPlugin {
|
|||
// Start repeating tasks.
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new BungeeCleanupTask(), 5 * 60 * 20, 5 * 60 * 20);
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new WorldPlayerCounterTask(), 0L, 3 * 20);
|
||||
|
||||
if (getCommand("holograms") == null) {
|
||||
throw new PluginEnableException(
|
||||
"Holographic Displays was unable to register the command \"holograms\".",
|
||||
"This can be caused by edits to plugin.yml or other plugins.");
|
||||
}
|
||||
|
||||
commandManager = new HologramCommandManager(configManager);
|
||||
commandManager.register(this);
|
||||
|
||||
mainListener = new MainListener(nmsManager);
|
||||
Bukkit.getPluginManager().registerEvents(mainListener, this);
|
||||
HologramCommandManager commandManager = new HologramCommandManager(configManager, internalHologramManager, nmsManager);
|
||||
commandManager.register(this);
|
||||
|
||||
registerListener(new MainListener(nmsManager));
|
||||
registerListener(new SpawnListener(nmsManager));
|
||||
registerListener(new ChunkListener(nmsManager, internalHologramManager, apiHologramManager));
|
||||
UpdateNotificationListener updateNotificationListener = new UpdateNotificationListener();
|
||||
registerListener(updateNotificationListener);
|
||||
|
||||
// Enable the API.
|
||||
BackendAPI.setImplementation(new DefaultBackendAPI(apiHologramManager, nmsManager));
|
||||
|
||||
// Register bStats metrics
|
||||
int pluginID = 3123;
|
||||
new MetricsLite(this, pluginID);
|
||||
|
||||
updateNotificationListener.runAsyncUpdateCheck();
|
||||
|
||||
// Holograms are loaded later, when the worlds are ready.
|
||||
Bukkit.getScheduler().runTask(this,
|
||||
new StartupLoadHologramsTask(configManager.getHologramDatabase().getHolograms()));
|
||||
|
||||
// Enable the API.
|
||||
BackendAPI.setImplementation(new DefaultBackendAPI());
|
||||
Bukkit.getScheduler().runTask(this, new StartupLoadHologramsTask(
|
||||
internalHologramManager,
|
||||
configManager.getHologramDatabase().getHolograms()));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
for (NamedHologram hologram : NamedHologramManager.getHolograms()) {
|
||||
hologram.despawnEntities();
|
||||
if (internalHologramManager != null) {
|
||||
for (InternalHologram hologram : internalHologramManager.getHolograms()) {
|
||||
hologram.despawnEntities();
|
||||
}
|
||||
}
|
||||
for (PluginHologram hologram : PluginHologramManager.getHolograms()) {
|
||||
hologram.despawnEntities();
|
||||
if (apiHologramManager != null) {
|
||||
for (APIHologram hologram : apiHologramManager.getHolograms()) {
|
||||
hologram.despawnEntities();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static NMSManager getNMSManager() {
|
||||
return nmsManager;
|
||||
}
|
||||
|
||||
public static MainListener getMainListener() {
|
||||
return mainListener;
|
||||
}
|
||||
|
||||
public static HologramCommandManager getCommandManager() {
|
||||
return commandManager;
|
||||
}
|
||||
|
||||
public static HolographicDisplays getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
public static String getNewVersion() {
|
||||
return newVersion;
|
||||
}
|
||||
|
||||
|
||||
public void hookProtocolLib() {
|
||||
if (!Bukkit.getPluginManager().isPluginEnabled("ProtocolLib")) {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleItemLinePickup(Player player, ItemLine itemLine) {
|
||||
Hologram hologram = itemLine.getParent();
|
||||
try {
|
||||
String protocolVersion = Bukkit.getPluginManager().getPlugin("ProtocolLib").getDescription().getVersion();
|
||||
Matcher versionNumbersMatcher = Pattern.compile("([0-9\\.])+").matcher(protocolVersion);
|
||||
|
||||
if (!versionNumbersMatcher.find()) {
|
||||
throw new IllegalArgumentException("could not find version numbers pattern");
|
||||
if (hologram.getVisibilityManager().isVisibleTo(player)) {
|
||||
itemLine.getPickupHandler().onPickup(player);
|
||||
}
|
||||
|
||||
String versionNumbers = versionNumbersMatcher.group();
|
||||
|
||||
if (!VersionUtils.isVersionGreaterEqual(versionNumbers, "4.1")) {
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[Holographic Displays] Detected old version of ProtocolLib, support disabled. You must use ProtocolLib 4.1 or higher.");
|
||||
return;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.warning("Could not detect ProtocolLib version (" + e.getClass().getName() + ": " + e.getMessage() + "), enabling support anyway and hoping for the best. If you get errors, please contact the author.");
|
||||
} catch (Throwable t) {
|
||||
Plugin plugin = hologram instanceof APIHologram ? ((APIHologram) hologram).getOwner() : HolographicDisplays.getInstance();
|
||||
Log.warning("The plugin " + plugin.getName() + " generated an exception when the player " + player.getName() + " picked up an item from a hologram.", t);
|
||||
}
|
||||
|
||||
try {
|
||||
ProtocolLibHook protocolLibHook = new ProtocolLibHookImpl();
|
||||
|
||||
if (protocolLibHook.hook(this, nmsManager)) {
|
||||
HolographicDisplays.protocolLibHook = protocolLibHook;
|
||||
Log.info("Enabled player relative placeholders with ProtocolLib.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.warning("Failed to load ProtocolLib support. Is it updated?", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static boolean hasProtocolLibHook() {
|
||||
return protocolLibHook != null;
|
||||
}
|
||||
|
||||
|
||||
public static ProtocolLibHook getProtocolLibHook() {
|
||||
return protocolLibHook;
|
||||
}
|
||||
|
||||
public static Path getDataFolderPath() {
|
||||
return dataFolderPath;
|
||||
@Override
|
||||
public boolean shouldBroadcastLocationPacket() {
|
||||
return ProtocolLibHook.isEnabled();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -59,7 +59,6 @@ public class BungeeServerInfo {
|
|||
}
|
||||
|
||||
public void setMotd(String motd) {
|
||||
|
||||
if (motd == null) {
|
||||
this.motd1 = "";
|
||||
this.motd2 = "";
|
||||
|
|
|
@ -13,15 +13,16 @@ import me.filoghost.holographicdisplays.disk.Configuration;
|
|||
import me.filoghost.holographicdisplays.disk.ServerAddress;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class BungeeServerTracker {
|
||||
|
||||
private static final String PINGER_NOT_ENABLED_ERROR = "[Please enable pinger]";
|
||||
|
||||
private static Map<String, BungeeServerInfo> trackedServers = new ConcurrentHashMap<>();
|
||||
private static final Map<String, BungeeServerInfo> trackedServers = new ConcurrentHashMap<>();
|
||||
private static int taskID = -1;
|
||||
|
||||
public static void resetTrackedServers() {
|
||||
|
@ -34,7 +35,7 @@ public class BungeeServerTracker {
|
|||
info.setMotd(Configuration.pingerOfflineMotd);
|
||||
trackedServers.put(server, info);
|
||||
|
||||
if (!Configuration.pingerEnable) {
|
||||
if (!Configuration.pingerEnabled) {
|
||||
BungeeChannel.getInstance().askPlayerCount(server);
|
||||
}
|
||||
}
|
||||
|
@ -64,9 +65,8 @@ public class BungeeServerTracker {
|
|||
}
|
||||
|
||||
public static String getMaxPlayers(String server) {
|
||||
|
||||
if (!Configuration.pingerEnable) {
|
||||
return "[Please enable pinger]";
|
||||
if (!Configuration.pingerEnabled) {
|
||||
return PINGER_NOT_ENABLED_ERROR;
|
||||
}
|
||||
|
||||
BungeeServerInfo info = trackedServers.get(server);
|
||||
|
@ -81,9 +81,8 @@ public class BungeeServerTracker {
|
|||
}
|
||||
|
||||
public static String getMotd1(String server) {
|
||||
|
||||
if (!Configuration.pingerEnable) {
|
||||
return "[Please enable pinger]";
|
||||
if (!Configuration.pingerEnabled) {
|
||||
return PINGER_NOT_ENABLED_ERROR;
|
||||
}
|
||||
|
||||
BungeeServerInfo info = trackedServers.get(server);
|
||||
|
@ -98,9 +97,8 @@ public class BungeeServerTracker {
|
|||
}
|
||||
|
||||
public static String getMotd2(String server) {
|
||||
|
||||
if (!Configuration.pingerEnable) {
|
||||
return "[Please enable pinger]";
|
||||
if (!Configuration.pingerEnabled) {
|
||||
return PINGER_NOT_ENABLED_ERROR;
|
||||
}
|
||||
|
||||
BungeeServerInfo info = trackedServers.get(server);
|
||||
|
@ -115,9 +113,8 @@ public class BungeeServerTracker {
|
|||
}
|
||||
|
||||
public static String getOnlineStatus(String server) {
|
||||
|
||||
if (!Configuration.pingerEnable) {
|
||||
return "[Please enable pinger]";
|
||||
if (!Configuration.pingerEnabled) {
|
||||
return PINGER_NOT_ENABLED_ERROR;
|
||||
}
|
||||
|
||||
BungeeServerInfo info = trackedServers.get(server);
|
||||
|
@ -127,7 +124,7 @@ public class BungeeServerTracker {
|
|||
} else {
|
||||
// It was not tracked, add it.
|
||||
track(server);
|
||||
return "0";
|
||||
return Configuration.pingerStatusOffline;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,52 +138,53 @@ public class BungeeServerTracker {
|
|||
}
|
||||
|
||||
taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(HolographicDisplays.getInstance(), () -> {
|
||||
|
||||
if (Configuration.pingerEnable) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(HolographicDisplays.getInstance(), () -> {
|
||||
|
||||
for (ServerAddress serverAddress : Configuration.pingerServers) {
|
||||
BungeeServerInfo serverInfo = getOrCreateServerInfo(serverAddress.getName());
|
||||
boolean displayOffline = false;
|
||||
|
||||
try {
|
||||
PingResponse data = ServerPinger.fetchData(serverAddress, Configuration.pingerTimeout);
|
||||
|
||||
if (data.isOnline()) {
|
||||
serverInfo.setOnline(true);
|
||||
serverInfo.setOnlinePlayers(data.getOnlinePlayers());
|
||||
serverInfo.setMaxPlayers(data.getMaxPlayers());
|
||||
serverInfo.setMotd(data.getMotd());
|
||||
} else {
|
||||
displayOffline = true;
|
||||
}
|
||||
} catch (SocketTimeoutException e) {
|
||||
displayOffline = true;
|
||||
} catch (UnknownHostException e) {
|
||||
Log.warning("Couldn't fetch data from " + serverAddress + ": unknown host address.");
|
||||
displayOffline = true;
|
||||
} catch (IOException e) {
|
||||
displayOffline = true;
|
||||
} catch (Throwable t) {
|
||||
displayOffline = true;
|
||||
Log.warning("Couldn't fetch data from " + serverAddress, t);
|
||||
}
|
||||
|
||||
if (displayOffline) {
|
||||
serverInfo.setOnline(false);
|
||||
serverInfo.setOnlinePlayers(0);
|
||||
serverInfo.setMaxPlayers(0);
|
||||
serverInfo.setMotd(Configuration.pingerOfflineMotd);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (Configuration.pingerEnabled) {
|
||||
runAsyncPinger();
|
||||
} else {
|
||||
for (String server : trackedServers.keySet()) {
|
||||
BungeeChannel.getInstance().askPlayerCount(server);
|
||||
}
|
||||
}
|
||||
|
||||
}, 1, refreshSeconds * 20);
|
||||
}, 1, refreshSeconds * 20L);
|
||||
}
|
||||
|
||||
private static void runAsyncPinger() {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(HolographicDisplays.getInstance(), () -> {
|
||||
for (ServerAddress serverAddress : Configuration.pingerServers) {
|
||||
BungeeServerInfo serverInfo = getOrCreateServerInfo(serverAddress.getName());
|
||||
boolean displayOffline = false;
|
||||
|
||||
try {
|
||||
PingResponse data = ServerPinger.fetchData(serverAddress, Configuration.pingerTimeout);
|
||||
|
||||
if (data.isOnline()) {
|
||||
serverInfo.setOnline(true);
|
||||
serverInfo.setOnlinePlayers(data.getOnlinePlayers());
|
||||
serverInfo.setMaxPlayers(data.getMaxPlayers());
|
||||
serverInfo.setMotd(data.getMotd());
|
||||
} else {
|
||||
displayOffline = true;
|
||||
}
|
||||
} catch (SocketTimeoutException e) {
|
||||
// Common error, avoid logging
|
||||
displayOffline = true;
|
||||
} catch (UnknownHostException e) {
|
||||
Log.warning("Couldn't fetch data from " + serverAddress + ": unknown host address.");
|
||||
displayOffline = true;
|
||||
} catch (Throwable t) {
|
||||
Log.warning("Couldn't fetch data from " + serverAddress + ".", t);
|
||||
displayOffline = true;
|
||||
}
|
||||
|
||||
if (displayOffline) {
|
||||
serverInfo.setOnline(false);
|
||||
serverInfo.setOnlinePlayers(0);
|
||||
serverInfo.setMaxPlayers(0);
|
||||
serverInfo.setMotd(Configuration.pingerOfflineMotd);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,10 +18,9 @@ public class PingResponse
|
|||
private int maxPlayers;
|
||||
|
||||
public PingResponse(String jsonString, ServerAddress address) {
|
||||
|
||||
if (jsonString == null || jsonString.isEmpty()) {
|
||||
motd = "Invalid ping response";
|
||||
DebugLogger.warning("Received empty Json response from IP \"" + address.toString() + "\"!");
|
||||
DebugLogger.warning("Received empty Json response from IP \"" + address.toString() + "\".");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,13 +12,11 @@ import java.io.DataInputStream;
|
|||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class ServerPinger {
|
||||
|
||||
public static PingResponse fetchData(final ServerAddress serverAddress, int timeout) throws SocketTimeoutException, UnknownHostException, IOException {
|
||||
public static PingResponse fetchData(final ServerAddress serverAddress, int timeout) throws IOException {
|
||||
Socket socket = null;
|
||||
DataOutputStream dataOut = null;
|
||||
DataInputStream dataIn = null;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.bridge.protocollib.current;
|
||||
package me.filoghost.holographicdisplays.bridge.protocollib;
|
||||
|
||||
import com.comphenix.net.sf.cglib.proxy.Factory;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
|
@ -16,7 +16,7 @@ import com.comphenix.protocol.wrappers.BukkitConverters;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
public class DebugHelper {
|
||||
class DebugHelper {
|
||||
|
||||
private static final int HEX_DUMP_THRESHOLD = 256;
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.bridge.protocollib.current;
|
||||
package me.filoghost.holographicdisplays.bridge.protocollib;
|
||||
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
|
@ -16,7 +16,7 @@ import me.filoghost.holographicdisplays.util.NMSVersion;
|
|||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class MetadataHelper {
|
||||
class MetadataHelper {
|
||||
|
||||
private final int itemSlotIndex;
|
||||
private final int entityStatusIndex;
|
|
@ -0,0 +1,203 @@
|
|||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.bridge.protocollib;
|
||||
|
||||
import com.comphenix.net.sf.cglib.proxy.Factory;
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
||||
import me.filoghost.holographicdisplays.bridge.protocollib.packet.EntityRelatedPacketWrapper;
|
||||
import me.filoghost.holographicdisplays.bridge.protocollib.packet.WrapperPlayServerEntityMetadata;
|
||||
import me.filoghost.holographicdisplays.bridge.protocollib.packet.WrapperPlayServerSpawnEntity;
|
||||
import me.filoghost.holographicdisplays.bridge.protocollib.packet.WrapperPlayServerSpawnEntityLiving;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.object.line.HologramLineImpl;
|
||||
import me.filoghost.holographicdisplays.object.line.TextLineImpl;
|
||||
import me.filoghost.holographicdisplays.placeholder.RelativePlaceholder;
|
||||
import me.filoghost.holographicdisplays.util.NMSVersion;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
class PacketListener extends PacketAdapter {
|
||||
|
||||
private final NMSManager nmsManager;
|
||||
private final MetadataHelper metadataHelper;
|
||||
|
||||
public PacketListener(Plugin plugin, NMSManager nmsManager, MetadataHelper metadataHelper) {
|
||||
super(PacketAdapter.params()
|
||||
.plugin(plugin)
|
||||
.types(
|
||||
PacketType.Play.Server.SPAWN_ENTITY_LIVING,
|
||||
PacketType.Play.Server.SPAWN_ENTITY,
|
||||
PacketType.Play.Server.ENTITY_METADATA,
|
||||
PacketType.Play.Server.REL_ENTITY_MOVE,
|
||||
PacketType.Play.Server.REL_ENTITY_MOVE_LOOK)
|
||||
.serverSide()
|
||||
.listenerPriority(ListenerPriority.NORMAL));
|
||||
|
||||
this.nmsManager = nmsManager;
|
||||
this.metadataHelper = metadataHelper;
|
||||
}
|
||||
|
||||
public void registerListener() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
PacketContainer packet = event.getPacket();
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (player instanceof Factory) {
|
||||
return; // Ignore temporary players (reference: https://github.com/dmulloy2/ProtocolLib/issues/349)
|
||||
}
|
||||
|
||||
// Spawn entity packet
|
||||
if (packet.getType() == PacketType.Play.Server.SPAWN_ENTITY_LIVING) {
|
||||
WrapperPlayServerSpawnEntityLiving spawnEntityPacket = new WrapperPlayServerSpawnEntityLiving(packet);
|
||||
HologramLineImpl hologramLine = getHologramLine(event, spawnEntityPacket);
|
||||
|
||||
if (hologramLine == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!hologramLine.getParent().getVisibilityManager().isVisibleTo(player)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_15_R1)) {
|
||||
// There's no metadata field in 1.15+ on the spawn entity packet
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(hologramLine instanceof TextLineImpl)) {
|
||||
return;
|
||||
}
|
||||
TextLineImpl textLine = (TextLineImpl) hologramLine;
|
||||
|
||||
if (!hologramLine.getParent().isAllowPlaceholders() || !textLine.hasRelativePlaceholders()) {
|
||||
return;
|
||||
}
|
||||
|
||||
spawnEntityPacket = new WrapperPlayServerSpawnEntityLiving(packet.deepClone());
|
||||
WrappedWatchableObject customNameWatchableObject = metadataHelper.getCustomNameWacthableObject(spawnEntityPacket.getMetadata());
|
||||
|
||||
if (customNameWatchableObject == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
replaceRelativePlaceholders(customNameWatchableObject, player, textLine.getRelativePlaceholders());
|
||||
event.setPacket(spawnEntityPacket.getHandle());
|
||||
|
||||
} else if (packet.getType() == PacketType.Play.Server.SPAWN_ENTITY) {
|
||||
WrapperPlayServerSpawnEntity spawnEntityPacket = new WrapperPlayServerSpawnEntity(packet);
|
||||
HologramLineImpl hologramLine = getHologramLine(event, spawnEntityPacket);
|
||||
|
||||
if (hologramLine == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!hologramLine.getParent().getVisibilityManager().isVisibleTo(player)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
} else if (packet.getType() == PacketType.Play.Server.ENTITY_METADATA) {
|
||||
WrapperPlayServerEntityMetadata entityMetadataPacket = new WrapperPlayServerEntityMetadata(packet);
|
||||
HologramLineImpl hologramLine = getHologramLine(event, entityMetadataPacket);
|
||||
|
||||
if (hologramLine == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!hologramLine.getParent().getVisibilityManager().isVisibleTo(player)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(hologramLine instanceof TextLineImpl)) {
|
||||
return;
|
||||
}
|
||||
TextLineImpl textLine = (TextLineImpl) hologramLine;
|
||||
|
||||
if (!hologramLine.getParent().isAllowPlaceholders() || !textLine.hasRelativePlaceholders()) {
|
||||
return;
|
||||
}
|
||||
|
||||
entityMetadataPacket = new WrapperPlayServerEntityMetadata(packet.deepClone());
|
||||
WrappedWatchableObject customNameWatchableObject = metadataHelper.getCustomNameWatchableObject(entityMetadataPacket.getEntityMetadata());
|
||||
|
||||
if (customNameWatchableObject == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean modified = replaceRelativePlaceholders(customNameWatchableObject, player, textLine.getRelativePlaceholders());
|
||||
if (modified) {
|
||||
event.setPacket(entityMetadataPacket.getHandle());
|
||||
}
|
||||
|
||||
} else if (packet.getType() == PacketType.Play.Server.REL_ENTITY_MOVE || packet.getType() == PacketType.Play.Server.REL_ENTITY_MOVE_LOOK) {
|
||||
int entityID = packet.getIntegers().read(0);
|
||||
NMSEntityBase nmsEntityBase = nmsManager.getNMSEntityBaseFromID(event.getPlayer().getWorld(), entityID);
|
||||
|
||||
if (nmsEntityBase instanceof NMSArmorStand) {
|
||||
event.setCancelled(true); // Don't send relative movement packets for armor stands, only keep precise teleport packets.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean replaceRelativePlaceholders(WrappedWatchableObject customNameWatchableObject, Player player, Collection<RelativePlaceholder> relativePlaceholders) {
|
||||
if (customNameWatchableObject == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final Object originalCustomNameNMSObject = metadataHelper.getCustomNameNMSObject(customNameWatchableObject);
|
||||
if (originalCustomNameNMSObject == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Object replacedCustomNameNMSObject = originalCustomNameNMSObject;
|
||||
for (RelativePlaceholder relativePlaceholder : relativePlaceholders) {
|
||||
replacedCustomNameNMSObject = nmsManager.replaceCustomNameText(replacedCustomNameNMSObject, relativePlaceholder.getTextPlaceholder(), relativePlaceholder.getReplacement(player));
|
||||
}
|
||||
|
||||
if (replacedCustomNameNMSObject == originalCustomNameNMSObject) {
|
||||
// It means nothing has been replaced, since original custom name has been returned.
|
||||
return false;
|
||||
}
|
||||
|
||||
metadataHelper.setCustomNameNMSObject(customNameWatchableObject, replacedCustomNameNMSObject);
|
||||
return true;
|
||||
}
|
||||
|
||||
private HologramLineImpl getHologramLine(PacketEvent packetEvent, EntityRelatedPacketWrapper packetWrapper) {
|
||||
return getHologramLine(packetEvent.getPlayer().getWorld(), packetWrapper.getEntityID());
|
||||
}
|
||||
|
||||
private HologramLineImpl getHologramLine(World world, int entityID) {
|
||||
if (entityID < 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
NMSEntityBase nmsEntity = nmsManager.getNMSEntityBaseFromID(world, entityID);
|
||||
if (nmsEntity == null) {
|
||||
return null; // Entity not existing or not related to holograms.
|
||||
}
|
||||
|
||||
return (HologramLineImpl) nmsEntity.getHologramLine();
|
||||
}
|
||||
|
||||
}
|
|
@ -3,35 +3,100 @@
|
|||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.bridge.protocollib.current;
|
||||
package me.filoghost.holographicdisplays.bridge.protocollib;
|
||||
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
import me.filoghost.holographicdisplays.bridge.protocollib.current.packet.AbstractPacket;
|
||||
import me.filoghost.holographicdisplays.bridge.protocollib.current.packet.WrapperPlayServerAttachEntity;
|
||||
import me.filoghost.holographicdisplays.bridge.protocollib.current.packet.WrapperPlayServerEntityDestroy;
|
||||
import me.filoghost.holographicdisplays.bridge.protocollib.current.packet.WrapperPlayServerEntityMetadata;
|
||||
import me.filoghost.holographicdisplays.bridge.protocollib.current.packet.WrapperPlayServerMount;
|
||||
import me.filoghost.holographicdisplays.bridge.protocollib.current.packet.WrapperPlayServerSpawnEntity;
|
||||
import me.filoghost.holographicdisplays.bridge.protocollib.current.packet.WrapperPlayServerSpawnEntity.ObjectTypes;
|
||||
import me.filoghost.holographicdisplays.bridge.protocollib.current.packet.WrapperPlayServerSpawnEntityLiving;
|
||||
import me.filoghost.holographicdisplays.bridge.protocollib.packet.AbstractPacket;
|
||||
import me.filoghost.holographicdisplays.bridge.protocollib.packet.WrapperPlayServerAttachEntity;
|
||||
import me.filoghost.holographicdisplays.bridge.protocollib.packet.WrapperPlayServerEntityDestroy;
|
||||
import me.filoghost.holographicdisplays.bridge.protocollib.packet.WrapperPlayServerEntityMetadata;
|
||||
import me.filoghost.holographicdisplays.bridge.protocollib.packet.WrapperPlayServerMount;
|
||||
import me.filoghost.holographicdisplays.bridge.protocollib.packet.WrapperPlayServerSpawnEntity;
|
||||
import me.filoghost.holographicdisplays.bridge.protocollib.packet.WrapperPlayServerSpawnEntity.ObjectTypes;
|
||||
import me.filoghost.holographicdisplays.bridge.protocollib.packet.WrapperPlayServerSpawnEntityLiving;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSItem;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSSlime;
|
||||
import me.filoghost.holographicdisplays.object.BaseHologram;
|
||||
import me.filoghost.holographicdisplays.object.line.HologramLineImpl;
|
||||
import me.filoghost.holographicdisplays.object.line.ItemLineImpl;
|
||||
import me.filoghost.holographicdisplays.object.line.TextLineImpl;
|
||||
import me.filoghost.holographicdisplays.object.line.TouchSlimeLineImpl;
|
||||
import me.filoghost.holographicdisplays.object.line.TouchableLineImpl;
|
||||
import me.filoghost.holographicdisplays.util.NMSVersion;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PacketHelper {
|
||||
class PacketSender {
|
||||
|
||||
private MetadataHelper metadataHelper;
|
||||
private final MetadataHelper metadataHelper;
|
||||
|
||||
public PacketHelper(MetadataHelper metadataHelper) {
|
||||
public PacketSender(MetadataHelper metadataHelper) {
|
||||
this.metadataHelper = metadataHelper;
|
||||
}
|
||||
|
||||
public void sendDestroyEntitiesPacket(Player player, BaseHologram hologram) {
|
||||
List<Integer> ids = new ArrayList<>();
|
||||
for (HologramLineImpl line : hologram.getLinesUnsafe()) {
|
||||
if (line.isSpawned()) {
|
||||
for (int id : line.getEntitiesIDs()) {
|
||||
ids.add(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!ids.isEmpty()) {
|
||||
sendDestroyEntitiesPacket(player, ids);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendCreateEntitiesPacket(Player player, BaseHologram hologram) {
|
||||
for (HologramLineImpl line : hologram.getLinesUnsafe()) {
|
||||
sendCreateEntitiesPacket(player, line);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendCreateEntitiesPacket(Player player, HologramLineImpl line) {
|
||||
if (!line.isSpawned()) {
|
||||
return;
|
||||
}
|
||||
|
||||
TouchableLineImpl touchableLine;
|
||||
|
||||
if (line instanceof TextLineImpl) {
|
||||
TextLineImpl textLine = (TextLineImpl) line;
|
||||
touchableLine = textLine;
|
||||
|
||||
sendSpawnArmorStandPacket(player, (NMSArmorStand) textLine.getNmsNameable());
|
||||
|
||||
} else if (line instanceof ItemLineImpl) {
|
||||
ItemLineImpl itemLine = (ItemLineImpl) line;
|
||||
touchableLine = itemLine;
|
||||
|
||||
sendSpawnArmorStandPacket(player, (NMSArmorStand) itemLine.getNmsVehicle());
|
||||
sendSpawnItemPacket(player, itemLine.getNmsItem());
|
||||
sendVehicleAttachPacket(player, itemLine.getNmsVehicle(), itemLine.getNmsItem());
|
||||
sendItemMetadataPacket(player, itemLine.getNmsItem());
|
||||
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unexpected hologram line type: " + line.getClass().getName());
|
||||
}
|
||||
|
||||
if (touchableLine.getTouchSlime() != null) {
|
||||
TouchSlimeLineImpl touchSlime = touchableLine.getTouchSlime();
|
||||
|
||||
if (touchSlime.isSpawned()) {
|
||||
sendSpawnArmorStandPacket(player, (NMSArmorStand) touchSlime.getNmsVehicle());
|
||||
sendSpawnSlimePacket(player, touchSlime.getNmsSlime());
|
||||
sendVehicleAttachPacket(player, touchSlime.getNmsVehicle(), touchSlime.getNmsSlime());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void sendSpawnArmorStandPacket(Player receiver, NMSArmorStand armorStand) {
|
||||
private void sendSpawnArmorStandPacket(Player receiver, NMSArmorStand armorStand) {
|
||||
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_11_R1)) {
|
||||
AbstractPacket spawnPacket;
|
||||
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_14_R1)) {
|
||||
|
@ -66,13 +131,13 @@ public class PacketHelper {
|
|||
}
|
||||
|
||||
|
||||
public void sendSpawnItemPacket(Player receiver, NMSItem item) {
|
||||
private void sendSpawnItemPacket(Player receiver, NMSItem item) {
|
||||
AbstractPacket packet = new WrapperPlayServerSpawnEntity(item.getBukkitEntityNMS(), ObjectTypes.ITEM_STACK, 1);
|
||||
packet.sendPacket(receiver);
|
||||
}
|
||||
|
||||
|
||||
public void sendSpawnSlimePacket(Player receiver, NMSSlime slime) {
|
||||
private void sendSpawnSlimePacket(Player receiver, NMSSlime slime) {
|
||||
AbstractPacket spawnPacket = new WrapperPlayServerSpawnEntityLiving(slime.getBukkitEntityNMS());
|
||||
spawnPacket.sendPacket(receiver);
|
||||
|
||||
|
@ -90,7 +155,7 @@ public class PacketHelper {
|
|||
}
|
||||
|
||||
|
||||
public void sendItemMetadataPacket(Player receiver, NMSItem item) {
|
||||
private void sendItemMetadataPacket(Player receiver, NMSItem item) {
|
||||
WrapperPlayServerEntityMetadata packet = new WrapperPlayServerEntityMetadata();
|
||||
|
||||
WrappedDataWatcher dataWatcher = new WrappedDataWatcher();
|
||||
|
@ -102,7 +167,7 @@ public class PacketHelper {
|
|||
}
|
||||
|
||||
|
||||
public void sendVehicleAttachPacket(Player receiver, NMSEntityBase vehicle, NMSEntityBase passenger) {
|
||||
private void sendVehicleAttachPacket(Player receiver, NMSEntityBase vehicle, NMSEntityBase passenger) {
|
||||
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_9_R1)) {
|
||||
WrapperPlayServerMount packet = new WrapperPlayServerMount();
|
||||
packet.setVehicleId(vehicle.getIdNMS());
|
||||
|
@ -117,7 +182,7 @@ public class PacketHelper {
|
|||
}
|
||||
|
||||
|
||||
public void sendDestroyEntitiesPacket(Player player, List<Integer> ids) {
|
||||
private void sendDestroyEntitiesPacket(Player player, List<Integer> ids) {
|
||||
WrapperPlayServerEntityDestroy packet = new WrapperPlayServerEntityDestroy();
|
||||
packet.setEntities(ids);
|
||||
packet.sendPacket(player);
|
|
@ -5,17 +5,77 @@
|
|||
*/
|
||||
package me.filoghost.holographicdisplays.bridge.protocollib;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import me.filoghost.fcommons.logging.Log;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.object.CraftHologram;
|
||||
import me.filoghost.holographicdisplays.object.BaseHologram;
|
||||
import me.filoghost.holographicdisplays.util.VersionUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public interface ProtocolLibHook {
|
||||
|
||||
boolean hook(Plugin plugin, NMSManager nmsManager);
|
||||
|
||||
void sendDestroyEntitiesPacket(Player player, CraftHologram hologram);
|
||||
|
||||
void sendCreateEntitiesPacket(Player player, CraftHologram hologram);
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ProtocolLibHook {
|
||||
|
||||
private static boolean enabled;
|
||||
private static PacketSender packetSender;
|
||||
|
||||
public static void setup(Plugin plugin, NMSManager nmsManager) {
|
||||
if (!Bukkit.getPluginManager().isPluginEnabled("ProtocolLib")) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
String protocolVersion = Bukkit.getPluginManager().getPlugin("ProtocolLib").getDescription().getVersion();
|
||||
Matcher versionNumbersMatcher = Pattern.compile("([0-9.])+").matcher(protocolVersion);
|
||||
|
||||
if (!versionNumbersMatcher.find()) {
|
||||
throw new IllegalArgumentException("unable to find pattern match");
|
||||
}
|
||||
|
||||
String versionNumbers = versionNumbersMatcher.group();
|
||||
|
||||
if (!VersionUtils.isVersionGreaterEqual(versionNumbers, "4.1")) {
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[Holographic Displays] Detected old version of ProtocolLib, support disabled. You must use ProtocolLib 4.1 or higher.");
|
||||
return;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.warning("Could not detect ProtocolLib version (" + e.getMessage() + "), enabling support anyway and hoping for the best.", e);
|
||||
}
|
||||
|
||||
try {
|
||||
MetadataHelper metadataHelper = new MetadataHelper();
|
||||
new PacketListener(plugin, nmsManager, metadataHelper).registerListener();
|
||||
packetSender = new PacketSender(metadataHelper);
|
||||
Log.info("Enabled player relative placeholders with ProtocolLib.");
|
||||
} catch (Exception e) {
|
||||
Log.warning("Failed to load ProtocolLib support. Is it updated?", e);
|
||||
return;
|
||||
}
|
||||
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
public static void sendDestroyEntitiesPacket(Player player, BaseHologram hologram) {
|
||||
checkState();
|
||||
packetSender.sendDestroyEntitiesPacket(player, hologram);
|
||||
}
|
||||
|
||||
public static void sendCreateEntitiesPacket(Player player, BaseHologram hologram) {
|
||||
checkState();
|
||||
packetSender.sendCreateEntitiesPacket(player, hologram);
|
||||
}
|
||||
|
||||
public static boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
private static void checkState() {
|
||||
Preconditions.checkState(isEnabled(), "hook not enabled");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,280 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.bridge.protocollib.current;
|
||||
|
||||
import com.comphenix.net.sf.cglib.proxy.Factory;
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketAdapter.AdapterParameteters;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
||||
import me.filoghost.holographicdisplays.HolographicDisplays;
|
||||
import me.filoghost.holographicdisplays.bridge.protocollib.ProtocolLibHook;
|
||||
import me.filoghost.holographicdisplays.bridge.protocollib.current.packet.EntityRelatedPacketWrapper;
|
||||
import me.filoghost.holographicdisplays.bridge.protocollib.current.packet.WrapperPlayServerEntityMetadata;
|
||||
import me.filoghost.holographicdisplays.bridge.protocollib.current.packet.WrapperPlayServerSpawnEntity;
|
||||
import me.filoghost.holographicdisplays.bridge.protocollib.current.packet.WrapperPlayServerSpawnEntityLiving;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.object.CraftHologram;
|
||||
import me.filoghost.holographicdisplays.object.line.CraftHologramLine;
|
||||
import me.filoghost.holographicdisplays.object.line.CraftItemLine;
|
||||
import me.filoghost.holographicdisplays.object.line.CraftTextLine;
|
||||
import me.filoghost.holographicdisplays.object.line.CraftTouchSlimeLine;
|
||||
import me.filoghost.holographicdisplays.object.line.CraftTouchableLine;
|
||||
import me.filoghost.holographicdisplays.placeholder.RelativePlaceholder;
|
||||
import me.filoghost.holographicdisplays.util.NMSVersion;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This is for the ProtocolLib versions containing the WrappedDataWatcher.WrappedDataWatcherObject class.
|
||||
*/
|
||||
public class ProtocolLibHookImpl implements ProtocolLibHook {
|
||||
|
||||
private NMSManager nmsManager;
|
||||
private PacketHelper packetHelper;
|
||||
private MetadataHelper metadataHelper;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hook(Plugin plugin, NMSManager nmsManager) {
|
||||
this.nmsManager = nmsManager;
|
||||
this.metadataHelper = new MetadataHelper();
|
||||
this.packetHelper = new PacketHelper(metadataHelper);
|
||||
|
||||
AdapterParameteters params = PacketAdapter
|
||||
.params()
|
||||
.plugin(plugin)
|
||||
.types(
|
||||
PacketType.Play.Server.SPAWN_ENTITY_LIVING,
|
||||
PacketType.Play.Server.SPAWN_ENTITY,
|
||||
PacketType.Play.Server.ENTITY_METADATA,
|
||||
PacketType.Play.Server.REL_ENTITY_MOVE,
|
||||
PacketType.Play.Server.REL_ENTITY_MOVE_LOOK)
|
||||
.serverSide()
|
||||
.listenerPriority(ListenerPriority.NORMAL);
|
||||
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(params) {
|
||||
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
PacketContainer packet = event.getPacket();
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (player instanceof Factory) {
|
||||
return; // Ignore temporary players (reference: https://github.com/dmulloy2/ProtocolLib/issues/349)
|
||||
}
|
||||
|
||||
// Spawn entity packet
|
||||
if (packet.getType() == PacketType.Play.Server.SPAWN_ENTITY_LIVING) {
|
||||
WrapperPlayServerSpawnEntityLiving spawnEntityPacket = new WrapperPlayServerSpawnEntityLiving(packet);
|
||||
CraftHologramLine hologramLine = getHologramLine(event, spawnEntityPacket);
|
||||
|
||||
if (hologramLine == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!hologramLine.getParent().getVisibilityManager().isVisibleTo(player)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_15_R1)) {
|
||||
// There's no metadata field in 1.15+ on the spawn entity packet
|
||||
return;
|
||||
}
|
||||
|
||||
if (!hologramLine.getParent().isAllowPlaceholders() || !hologramLine.hasRelativePlaceholders()) {
|
||||
return;
|
||||
}
|
||||
|
||||
spawnEntityPacket = new WrapperPlayServerSpawnEntityLiving(packet.deepClone());
|
||||
WrappedWatchableObject customNameWatchableObject = metadataHelper.getCustomNameWacthableObject(spawnEntityPacket.getMetadata());
|
||||
|
||||
if (customNameWatchableObject == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
replaceRelativePlaceholders(customNameWatchableObject, player, hologramLine.getRelativePlaceholders());
|
||||
event.setPacket(spawnEntityPacket.getHandle());
|
||||
|
||||
} else if (packet.getType() == PacketType.Play.Server.SPAWN_ENTITY) {
|
||||
WrapperPlayServerSpawnEntity spawnEntityPacket = new WrapperPlayServerSpawnEntity(packet);
|
||||
CraftHologramLine hologramLine = getHologramLine(event, spawnEntityPacket);
|
||||
|
||||
if (hologramLine == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!hologramLine.getParent().getVisibilityManager().isVisibleTo(player)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
} else if (packet.getType() == PacketType.Play.Server.ENTITY_METADATA) {
|
||||
WrapperPlayServerEntityMetadata entityMetadataPacket = new WrapperPlayServerEntityMetadata(packet);
|
||||
CraftHologramLine hologramLine = getHologramLine(event, entityMetadataPacket);
|
||||
|
||||
if (hologramLine == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!hologramLine.getParent().getVisibilityManager().isVisibleTo(player)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!hologramLine.getParent().isAllowPlaceholders() || !hologramLine.hasRelativePlaceholders()) {
|
||||
return;
|
||||
}
|
||||
|
||||
entityMetadataPacket = new WrapperPlayServerEntityMetadata(packet.deepClone());
|
||||
WrappedWatchableObject customNameWatchableObject = metadataHelper.getCustomNameWatchableObject(entityMetadataPacket.getEntityMetadata());
|
||||
|
||||
if (customNameWatchableObject == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean modified = replaceRelativePlaceholders(customNameWatchableObject, player, hologramLine.getRelativePlaceholders());
|
||||
if (modified) {
|
||||
event.setPacket(entityMetadataPacket.getHandle());
|
||||
}
|
||||
|
||||
} else if (packet.getType() == PacketType.Play.Server.REL_ENTITY_MOVE || packet.getType() == PacketType.Play.Server.REL_ENTITY_MOVE_LOOK) {
|
||||
int entityID = packet.getIntegers().read(0);
|
||||
NMSEntityBase nmsEntityBase = getNMSEntityBase(event.getPlayer().getWorld(), entityID);
|
||||
|
||||
if (nmsEntityBase instanceof NMSArmorStand) {
|
||||
event.setCancelled(true); // Don't send relative movement packets for armor stands, only keep precise teleport packets.
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private boolean replaceRelativePlaceholders(WrappedWatchableObject customNameWatchableObject, Player player, Collection<RelativePlaceholder> relativePlaceholders) {
|
||||
if (customNameWatchableObject == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final Object originalCustomNameNMSObject = metadataHelper.getCustomNameNMSObject(customNameWatchableObject);
|
||||
if (originalCustomNameNMSObject == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Object replacedCustomNameNMSObject = originalCustomNameNMSObject;
|
||||
for (RelativePlaceholder relativePlaceholder : relativePlaceholders) {
|
||||
replacedCustomNameNMSObject = nmsManager.replaceCustomNameText(replacedCustomNameNMSObject, relativePlaceholder.getTextPlaceholder(), relativePlaceholder.getReplacement(player));
|
||||
}
|
||||
|
||||
if (replacedCustomNameNMSObject == originalCustomNameNMSObject) {
|
||||
// It means nothing has been replaced, since original custom name has been returned.
|
||||
return false;
|
||||
}
|
||||
|
||||
metadataHelper.setCustomNameNMSObject(customNameWatchableObject, replacedCustomNameNMSObject);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void sendDestroyEntitiesPacket(Player player, CraftHologram hologram) {
|
||||
List<Integer> ids = new ArrayList<>();
|
||||
for (CraftHologramLine line : hologram.getLinesUnsafe()) {
|
||||
if (line.isSpawned()) {
|
||||
for (int id : line.getEntitiesIDs()) {
|
||||
ids.add(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!ids.isEmpty()) {
|
||||
packetHelper.sendDestroyEntitiesPacket(player, ids);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void sendCreateEntitiesPacket(Player player, CraftHologram hologram) {
|
||||
for (CraftHologramLine line : hologram.getLinesUnsafe()) {
|
||||
sendCreateEntitiesPacket(player, line);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void sendCreateEntitiesPacket(Player player, CraftHologramLine line) {
|
||||
if (!line.isSpawned()) {
|
||||
return;
|
||||
}
|
||||
|
||||
CraftTouchableLine touchableLine;
|
||||
|
||||
if (line instanceof CraftTextLine) {
|
||||
CraftTextLine textLine = (CraftTextLine) line;
|
||||
touchableLine = textLine;
|
||||
|
||||
packetHelper.sendSpawnArmorStandPacket(player, (NMSArmorStand) textLine.getNmsNameable());
|
||||
|
||||
} else if (line instanceof CraftItemLine) {
|
||||
CraftItemLine itemLine = (CraftItemLine) line;
|
||||
touchableLine = itemLine;
|
||||
|
||||
packetHelper.sendSpawnArmorStandPacket(player, (NMSArmorStand) itemLine.getNmsVehicle());
|
||||
packetHelper.sendSpawnItemPacket(player, itemLine.getNmsItem());
|
||||
packetHelper.sendVehicleAttachPacket(player, itemLine.getNmsVehicle(), itemLine.getNmsItem());
|
||||
packetHelper.sendItemMetadataPacket(player, itemLine.getNmsItem());
|
||||
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unexpected hologram line type: " + line.getClass().getName());
|
||||
}
|
||||
|
||||
if (touchableLine.getTouchSlime() != null) {
|
||||
CraftTouchSlimeLine touchSlime = touchableLine.getTouchSlime();
|
||||
|
||||
if (touchSlime.isSpawned()) {
|
||||
packetHelper.sendSpawnArmorStandPacket(player, (NMSArmorStand) touchSlime.getNmsVehicle());
|
||||
packetHelper.sendSpawnSlimePacket(player, touchSlime.getNmsSlime());
|
||||
packetHelper.sendVehicleAttachPacket(player, touchSlime.getNmsVehicle(), touchSlime.getNmsSlime());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private CraftHologramLine getHologramLine(PacketEvent packetEvent, EntityRelatedPacketWrapper packetWrapper) {
|
||||
return getHologramLine(packetEvent.getPlayer().getWorld(), packetWrapper.getEntityID());
|
||||
}
|
||||
|
||||
private CraftHologramLine getHologramLine(World world, int entityID) {
|
||||
if (entityID < 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
NMSEntityBase nmsEntity = getNMSEntityBase(world, entityID);
|
||||
if (nmsEntity == null) {
|
||||
return null; // Entity not existing or not related to holograms.
|
||||
}
|
||||
|
||||
return (CraftHologramLine) nmsEntity.getHologramLine();
|
||||
}
|
||||
|
||||
private NMSEntityBase getNMSEntityBase(World world, int entityID) {
|
||||
return HolographicDisplays.getNMSManager().getNMSEntityBaseFromID(world, entityID);
|
||||
}
|
||||
|
||||
}
|
|
@ -14,8 +14,7 @@
|
|||
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
* 02111-1307 USA
|
||||
*/
|
||||
|
||||
package me.filoghost.holographicdisplays.bridge.protocollib.current.packet;
|
||||
package me.filoghost.holographicdisplays.bridge.protocollib.packet;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.bridge.protocollib.current.packet;
|
||||
package me.filoghost.holographicdisplays.bridge.protocollib.packet;
|
||||
|
||||
public interface EntityRelatedPacketWrapper {
|
||||
|
|
@ -14,8 +14,7 @@
|
|||
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
* 02111-1307 USA
|
||||
*/
|
||||
|
||||
package me.filoghost.holographicdisplays.bridge.protocollib.current.packet;
|
||||
package me.filoghost.holographicdisplays.bridge.protocollib.packet;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
|
@ -14,8 +14,7 @@
|
|||
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
* 02111-1307 USA
|
||||
*/
|
||||
|
||||
package me.filoghost.holographicdisplays.bridge.protocollib.current.packet;
|
||||
package me.filoghost.holographicdisplays.bridge.protocollib.packet;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
|
@ -58,4 +57,4 @@ public class WrapperPlayServerEntityDestroy extends AbstractPacket {
|
|||
public void setEntities(List<Integer> entities) {
|
||||
setEntities(Ints.toArray(entities));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,8 +14,7 @@
|
|||
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
* 02111-1307 USA
|
||||
*/
|
||||
|
||||
package me.filoghost.holographicdisplays.bridge.protocollib.current.packet;
|
||||
package me.filoghost.holographicdisplays.bridge.protocollib.packet;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
|
@ -43,6 +42,7 @@ public class WrapperPlayServerEntityMetadata extends AbstractPacket implements E
|
|||
* Retrieve unique entity ID to update.
|
||||
* @return The current Entity ID
|
||||
*/
|
||||
@Override
|
||||
public int getEntityID() {
|
||||
return handle.getIntegers().read(0);
|
||||
}
|
|
@ -14,8 +14,7 @@
|
|||
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
* 02111-1307 USA
|
||||
*/
|
||||
|
||||
package me.filoghost.holographicdisplays.bridge.protocollib.current.packet;
|
||||
package me.filoghost.holographicdisplays.bridge.protocollib.packet;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
|
@ -14,8 +14,7 @@
|
|||
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
* 02111-1307 USA
|
||||
*/
|
||||
|
||||
package me.filoghost.holographicdisplays.bridge.protocollib.current.packet;
|
||||
package me.filoghost.holographicdisplays.bridge.protocollib.packet;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
|
@ -65,7 +64,7 @@ public class WrapperPlayServerSpawnEntity extends AbstractPacket implements Enti
|
|||
/**
|
||||
* The singleton instance. Can also be retrieved from the parent class.
|
||||
*/
|
||||
private static ObjectTypes INSTANCE = new ObjectTypes();
|
||||
private static final ObjectTypes INSTANCE = new ObjectTypes();
|
||||
|
||||
/**
|
||||
* Retrieve an instance of the object types enum.
|
||||
|
@ -110,6 +109,7 @@ public class WrapperPlayServerSpawnEntity extends AbstractPacket implements Enti
|
|||
* Retrieve entity ID of the Object.
|
||||
* @return The current EID
|
||||
*/
|
||||
@Override
|
||||
public int getEntityID() {
|
||||
return handle.getIntegers().read(0);
|
||||
}
|
|
@ -14,8 +14,7 @@
|
|||
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
* 02111-1307 USA
|
||||
*/
|
||||
|
||||
package me.filoghost.holographicdisplays.bridge.protocollib.current.packet;
|
||||
package me.filoghost.holographicdisplays.bridge.protocollib.packet;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
|
@ -56,6 +55,7 @@ public class WrapperPlayServerSpawnEntityLiving extends AbstractPacket implement
|
|||
* Retrieve entity ID.
|
||||
* @return The current EID
|
||||
*/
|
||||
@Override
|
||||
public int getEntityID() {
|
||||
return handle.getIntegers().read(0);
|
||||
}
|
|
@ -24,6 +24,7 @@ import me.filoghost.holographicdisplays.commands.subs.InsertlineCommand;
|
|||
import me.filoghost.holographicdisplays.commands.subs.ListCommand;
|
||||
import me.filoghost.holographicdisplays.commands.subs.MovehereCommand;
|
||||
import me.filoghost.holographicdisplays.commands.subs.NearCommand;
|
||||
import me.filoghost.holographicdisplays.commands.subs.QuickEditCommand;
|
||||
import me.filoghost.holographicdisplays.commands.subs.ReadimageCommand;
|
||||
import me.filoghost.holographicdisplays.commands.subs.ReadtextCommand;
|
||||
import me.filoghost.holographicdisplays.commands.subs.ReloadCommand;
|
||||
|
@ -32,48 +33,55 @@ import me.filoghost.holographicdisplays.commands.subs.SetlineCommand;
|
|||
import me.filoghost.holographicdisplays.commands.subs.TeleportCommand;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import me.filoghost.holographicdisplays.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.disk.Configuration;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologramManager;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder.FormatRetention;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class HologramCommandManager extends SubCommandManager {
|
||||
|
||||
private final List<HologramSubCommand> subCommands;
|
||||
private final Map<Class<? extends HologramSubCommand>, HologramSubCommand> subCommandsByClass;
|
||||
|
||||
private final HelpCommand helpCommand;
|
||||
|
||||
public HologramCommandManager(ConfigManager configManager) {
|
||||
public HologramCommandManager(ConfigManager configManager, InternalHologramManager internalHologramManager, NMSManager nmsManager) {
|
||||
setName("holograms");
|
||||
subCommands = new ArrayList<>();
|
||||
subCommandsByClass = new HashMap<>();
|
||||
|
||||
registerSubCommand(new AddlineCommand(configManager));
|
||||
registerSubCommand(new CreateCommand(configManager));
|
||||
registerSubCommand(new DeleteCommand(configManager));
|
||||
registerSubCommand(new EditCommand());
|
||||
registerSubCommand(new ListCommand());
|
||||
registerSubCommand(new NearCommand());
|
||||
registerSubCommand(new TeleportCommand());
|
||||
registerSubCommand(new MovehereCommand(configManager));
|
||||
registerSubCommand(new AlignCommand(configManager));
|
||||
registerSubCommand(new CopyCommand(configManager));
|
||||
registerSubCommand(new ReloadCommand(configManager));
|
||||
|
||||
registerSubCommand(new RemovelineCommand(configManager));
|
||||
registerSubCommand(new SetlineCommand(configManager));
|
||||
registerSubCommand(new InsertlineCommand(configManager));
|
||||
registerSubCommand(new ReadtextCommand(configManager));
|
||||
registerSubCommand(new ReadimageCommand(configManager));
|
||||
registerSubCommand(new InfoCommand());
|
||||
|
||||
registerSubCommand(new DebugCommand());
|
||||
registerSubCommand(helpCommand = new HelpCommand());
|
||||
|
||||
subCommands.add(new AddlineCommand(this, internalHologramManager, configManager));
|
||||
subCommands.add(new CreateCommand(internalHologramManager, configManager));
|
||||
subCommands.add(new DeleteCommand(internalHologramManager, configManager));
|
||||
subCommands.add(new EditCommand(this, internalHologramManager));
|
||||
subCommands.add(new ListCommand(internalHologramManager));
|
||||
subCommands.add(new NearCommand(internalHologramManager));
|
||||
subCommands.add(new TeleportCommand(internalHologramManager));
|
||||
subCommands.add(new MovehereCommand(internalHologramManager, configManager));
|
||||
subCommands.add(new AlignCommand(internalHologramManager, configManager));
|
||||
subCommands.add(new CopyCommand(internalHologramManager, configManager));
|
||||
subCommands.add(new ReloadCommand(configManager, internalHologramManager));
|
||||
|
||||
subCommands.add(new RemovelineCommand(this, internalHologramManager, configManager));
|
||||
subCommands.add(new SetlineCommand(this, internalHologramManager, configManager));
|
||||
subCommands.add(new InsertlineCommand(this, internalHologramManager, configManager));
|
||||
subCommands.add(new ReadtextCommand(internalHologramManager, configManager));
|
||||
subCommands.add(new ReadimageCommand(internalHologramManager, configManager));
|
||||
subCommands.add(new InfoCommand(this, internalHologramManager));
|
||||
|
||||
subCommands.add(new DebugCommand(nmsManager));
|
||||
subCommands.add(helpCommand = new HelpCommand(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -95,20 +103,48 @@ public class HologramCommandManager extends SubCommandManager {
|
|||
return null;
|
||||
}
|
||||
|
||||
public void sendQuickEditCommands(SubCommandContext commandContext, InternalHologram hologram) {
|
||||
if (!Configuration.quickEditCommands) {
|
||||
return;
|
||||
}
|
||||
if (!(commandContext.getSender() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ComponentBuilder message = new ComponentBuilder("EDIT LINES:").color(ChatColor.GRAY).bold(true).append(" ", FormatRetention.NONE);
|
||||
|
||||
for (HologramSubCommand subCommand : subCommands) {
|
||||
if (!(subCommand instanceof QuickEditCommand)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QuickEditCommand quickEditCommand = (QuickEditCommand) subCommand;
|
||||
|
||||
// Assume first argument is always "<hologram>" and remove it
|
||||
String usageArgs = subCommand.getUsageArgs();
|
||||
if (usageArgs != null && usageArgs.contains(" ")) {
|
||||
usageArgs = usageArgs.substring(usageArgs.indexOf(" ") + 1);
|
||||
} else {
|
||||
usageArgs = "";
|
||||
}
|
||||
|
||||
String usage = "/" + commandContext.getRootLabel() + " " + subCommand.getName() + " " + hologram + " ";
|
||||
message.append("[" + quickEditCommand.getActionName() + "]").color(ChatColor.DARK_AQUA)
|
||||
.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, usage))
|
||||
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(
|
||||
ChatColor.GRAY + "Click to insert in chat the highlighted part of the command:\n" +
|
||||
ChatColor.YELLOW + usage + ChatColor.DARK_GRAY + usageArgs)));
|
||||
message.append(" ", FormatRetention.NONE);
|
||||
}
|
||||
|
||||
((Player) commandContext.getSender()).spigot().sendMessage(message.create());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<HologramSubCommand> getSubCommands() {
|
||||
return subCommands;
|
||||
}
|
||||
|
||||
public void registerSubCommand(HologramSubCommand subCommand) {
|
||||
subCommands.add(subCommand);
|
||||
subCommandsByClass.put(subCommand.getClass(), subCommand);
|
||||
}
|
||||
|
||||
public HologramSubCommand getSubCommand(Class<? extends HologramSubCommand> subCommandClass) {
|
||||
return subCommandsByClass.get(subCommandClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void sendNoArgsMessage(CommandContext context) {
|
||||
CommandSender sender = context.getSender();
|
||||
|
@ -145,6 +181,6 @@ public class HologramCommandManager extends SubCommandManager {
|
|||
Bukkit.getLogger().log(Level.SEVERE, "Unhandled exception while executing /" + context.getRootLabel(), t);
|
||||
context.getSender().sendMessage(Colors.ERROR + "Internal error while executing command."
|
||||
+ " Please look on the console for more details.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,13 +7,12 @@ package me.filoghost.holographicdisplays.commands;
|
|||
|
||||
import me.filoghost.fcommons.command.validation.CommandException;
|
||||
import me.filoghost.fcommons.command.validation.CommandValidate;
|
||||
import me.filoghost.holographicdisplays.HolographicDisplays;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import me.filoghost.holographicdisplays.disk.HologramLineParser;
|
||||
import me.filoghost.holographicdisplays.disk.HologramLoadException;
|
||||
import me.filoghost.holographicdisplays.object.NamedHologram;
|
||||
import me.filoghost.holographicdisplays.object.NamedHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.line.CraftHologramLine;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.line.HologramLineImpl;
|
||||
import me.filoghost.holographicdisplays.util.FileUtils;
|
||||
|
||||
import java.nio.file.Files;
|
||||
|
@ -21,7 +20,7 @@ import java.nio.file.Path;
|
|||
|
||||
public class HologramCommandValidate {
|
||||
|
||||
public static CraftHologramLine parseHologramLine(NamedHologram hologram, String serializedLine, boolean validateMaterial) throws CommandException {
|
||||
public static HologramLineImpl parseHologramLine(InternalHologram hologram, String serializedLine, boolean validateMaterial) throws CommandException {
|
||||
try {
|
||||
return HologramLineParser.parseLine(hologram, serializedLine, validateMaterial);
|
||||
} catch (HologramLoadException e) {
|
||||
|
@ -29,14 +28,13 @@ public class HologramCommandValidate {
|
|||
}
|
||||
}
|
||||
|
||||
public static NamedHologram getNamedHologram(String hologramName) throws CommandException {
|
||||
NamedHologram hologram = NamedHologramManager.getHologram(hologramName);
|
||||
public static InternalHologram getNamedHologram(InternalHologramManager internalHologramManager, String hologramName) throws CommandException {
|
||||
InternalHologram hologram = internalHologramManager.getHologramByName(hologramName);
|
||||
CommandValidate.notNull(hologram, "Cannot find a hologram named \"" + hologramName + "\".");
|
||||
return hologram;
|
||||
}
|
||||
|
||||
public static Path getUserReadableFile(String fileName) throws CommandException {
|
||||
Path dataFolder = HolographicDisplays.getDataFolderPath();
|
||||
public static Path getUserReadableFile(Path dataFolder, String fileName) throws CommandException {
|
||||
Path targetFile = dataFolder.resolve(fileName);
|
||||
CommandValidate.check(FileUtils.isInsideDirectory(targetFile, dataFolder), "The specified file must be inside HolographicDisplays' folder.");
|
||||
CommandValidate.check(Files.exists(targetFile), "The specified file \"" + fileName + "\" does not exist inside HolographicDisplays' folder.");
|
||||
|
|
|
@ -8,43 +8,54 @@ package me.filoghost.holographicdisplays.commands.subs;
|
|||
import me.filoghost.fcommons.command.sub.SubCommandContext;
|
||||
import me.filoghost.fcommons.command.validation.CommandException;
|
||||
import me.filoghost.holographicdisplays.Colors;
|
||||
import me.filoghost.holographicdisplays.commands.HologramCommandManager;
|
||||
import me.filoghost.holographicdisplays.commands.HologramCommandValidate;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import me.filoghost.holographicdisplays.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.event.NamedHologramEditedEvent;
|
||||
import me.filoghost.holographicdisplays.object.NamedHologram;
|
||||
import me.filoghost.holographicdisplays.object.line.CraftHologramLine;
|
||||
import me.filoghost.holographicdisplays.event.InternalHologramEditEvent;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.line.HologramLineImpl;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class AddlineCommand extends LineEditingCommand {
|
||||
public class AddlineCommand extends LineEditingCommand implements QuickEditCommand {
|
||||
|
||||
private final HologramCommandManager commandManager;
|
||||
private final InternalHologramManager internalHologramManager;
|
||||
private final ConfigManager configManager;
|
||||
|
||||
public AddlineCommand(ConfigManager configManager) {
|
||||
public AddlineCommand(HologramCommandManager commandManager, InternalHologramManager internalHologramManager, ConfigManager configManager) {
|
||||
super("addline");
|
||||
setMinArgs(2);
|
||||
setUsageArgs("<hologram> <text>");
|
||||
setDescription("Adds a line to an existing hologram.");
|
||||
|
||||
|
||||
this.commandManager = commandManager;
|
||||
this.internalHologramManager = internalHologramManager;
|
||||
this.configManager = configManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||
NamedHologram hologram = HologramCommandValidate.getNamedHologram(args[0]);
|
||||
InternalHologram hologram = HologramCommandValidate.getNamedHologram(internalHologramManager, args[0]);
|
||||
String serializedLine = Utils.join(args, " ", 1, args.length);
|
||||
|
||||
CraftHologramLine line = HologramCommandValidate.parseHologramLine(hologram, serializedLine, true);
|
||||
HologramLineImpl line = HologramCommandValidate.parseHologramLine(hologram, serializedLine, true);
|
||||
hologram.getLinesUnsafe().add(line);
|
||||
hologram.refreshAll();
|
||||
|
||||
configManager.getHologramDatabase().addOrUpdate(hologram);
|
||||
configManager.saveHologramDatabase();
|
||||
Bukkit.getPluginManager().callEvent(new NamedHologramEditedEvent(hologram));
|
||||
Bukkit.getPluginManager().callEvent(new InternalHologramEditEvent(hologram));
|
||||
|
||||
sender.sendMessage(Colors.PRIMARY + "Line added!");
|
||||
EditCommand.sendQuickEditCommands(context, hologram);
|
||||
sender.sendMessage(Colors.PRIMARY + "Line added.");
|
||||
commandManager.sendQuickEditCommands(context, hologram);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getActionName() {
|
||||
return "Add";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,29 +12,32 @@ import me.filoghost.holographicdisplays.Colors;
|
|||
import me.filoghost.holographicdisplays.commands.HologramCommandValidate;
|
||||
import me.filoghost.holographicdisplays.commands.HologramSubCommand;
|
||||
import me.filoghost.holographicdisplays.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.object.NamedHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologramManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class AlignCommand extends HologramSubCommand {
|
||||
|
||||
private final InternalHologramManager internalHologramManager;
|
||||
private final ConfigManager configManager;
|
||||
|
||||
public AlignCommand(ConfigManager configManager) {
|
||||
public AlignCommand(InternalHologramManager internalHologramManager, ConfigManager configManager) {
|
||||
super("align");
|
||||
setMinArgs(3);
|
||||
setUsageArgs("<X | Y | Z | XZ> <hologram> <referenceHologram>");
|
||||
setDescription("Aligns the first hologram to the second, in the specified axis.");
|
||||
|
||||
|
||||
this.internalHologramManager = internalHologramManager;
|
||||
this.configManager = configManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||
NamedHologram hologram = HologramCommandValidate.getNamedHologram(args[1]);
|
||||
NamedHologram referenceHologram = HologramCommandValidate.getNamedHologram(args[2]);
|
||||
InternalHologram hologram = HologramCommandValidate.getNamedHologram(internalHologramManager, args[1]);
|
||||
InternalHologram referenceHologram = HologramCommandValidate.getNamedHologram(internalHologramManager, args[2]);
|
||||
|
||||
CommandValidate.check(hologram != referenceHologram, "The hologram must not be the same!");
|
||||
CommandValidate.check(hologram != referenceHologram, "The holograms must not be the same.");
|
||||
|
||||
Location loc = hologram.getLocation();
|
||||
|
||||
|
|
|
@ -11,31 +11,34 @@ import me.filoghost.holographicdisplays.Colors;
|
|||
import me.filoghost.holographicdisplays.commands.HologramCommandValidate;
|
||||
import me.filoghost.holographicdisplays.commands.HologramSubCommand;
|
||||
import me.filoghost.holographicdisplays.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.object.NamedHologram;
|
||||
import me.filoghost.holographicdisplays.object.line.CraftHologramLine;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.line.HologramLineImpl;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class CopyCommand extends HologramSubCommand {
|
||||
|
||||
private final InternalHologramManager internalHologramManager;
|
||||
private final ConfigManager configManager;
|
||||
|
||||
public CopyCommand(ConfigManager configManager) {
|
||||
public CopyCommand(InternalHologramManager internalHologramManager, ConfigManager configManager) {
|
||||
super("copy");
|
||||
setMinArgs(2);
|
||||
setUsageArgs("<fromHologram> <toHologram>");
|
||||
setDescription("Copies the contents of a hologram into another one.");
|
||||
|
||||
|
||||
this.internalHologramManager = internalHologramManager;
|
||||
this.configManager = configManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||
NamedHologram fromHologram = HologramCommandValidate.getNamedHologram(args[0]);
|
||||
NamedHologram toHologram = HologramCommandValidate.getNamedHologram(args[1]);
|
||||
InternalHologram fromHologram = HologramCommandValidate.getNamedHologram(internalHologramManager, args[0]);
|
||||
InternalHologram toHologram = HologramCommandValidate.getNamedHologram(internalHologramManager, args[1]);
|
||||
|
||||
toHologram.clearLines();
|
||||
for (CraftHologramLine line : fromHologram.getLinesUnsafe()) {
|
||||
CraftHologramLine clonedLine = HologramCommandValidate.parseHologramLine(toHologram, line.getSerializedConfigValue(), false);
|
||||
for (HologramLineImpl line : fromHologram.getLinesUnsafe()) {
|
||||
HologramLineImpl clonedLine = HologramCommandValidate.parseHologramLine(toHologram, line.getSerializedConfigValue(), false);
|
||||
toHologram.getLinesUnsafe().add(clonedLine);
|
||||
}
|
||||
|
||||
|
@ -44,7 +47,7 @@ public class CopyCommand extends HologramSubCommand {
|
|||
configManager.getHologramDatabase().addOrUpdate(toHologram);
|
||||
configManager.saveHologramDatabase();
|
||||
|
||||
sender.sendMessage(Colors.PRIMARY + "Hologram \"" + fromHologram.getName() + "\" copied into hologram \"" + toHologram.getName() + "\"!");
|
||||
sender.sendMessage(Colors.PRIMARY + "Hologram \"" + fromHologram.getName() + "\" copied into hologram \"" + toHologram.getName() + "\".");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,9 +13,9 @@ import me.filoghost.holographicdisplays.commands.HologramCommandValidate;
|
|||
import me.filoghost.holographicdisplays.commands.HologramSubCommand;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import me.filoghost.holographicdisplays.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.object.NamedHologram;
|
||||
import me.filoghost.holographicdisplays.object.NamedHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.line.CraftHologramLine;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.line.HologramLineImpl;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -23,9 +23,10 @@ import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
|||
|
||||
public class CreateCommand extends HologramSubCommand {
|
||||
|
||||
private final InternalHologramManager internalHologramManager;
|
||||
private final ConfigManager configManager;
|
||||
|
||||
public CreateCommand(ConfigManager configManager) {
|
||||
|
||||
public CreateCommand(InternalHologramManager internalHologramManager, ConfigManager configManager) {
|
||||
super("create");
|
||||
setMinArgs(1);
|
||||
setUsageArgs("<hologramName> [text]");
|
||||
|
@ -33,7 +34,8 @@ public class CreateCommand extends HologramSubCommand {
|
|||
"Creates a new hologram with the given name, that must",
|
||||
"be alphanumeric. The name will be used as reference to",
|
||||
"that hologram for editing commands.");
|
||||
|
||||
|
||||
this.internalHologramManager = internalHologramManager;
|
||||
this.configManager = configManager;
|
||||
}
|
||||
|
||||
|
@ -43,11 +45,10 @@ public class CreateCommand extends HologramSubCommand {
|
|||
Player player = CommandValidate.getPlayerSender(sender);
|
||||
String hologramName = args[0];
|
||||
|
||||
if (!hologramName.matches("[a-zA-Z0-9_\\-]+")) {
|
||||
throw new CommandException("The name must contain only alphanumeric chars, underscores and hyphens.");
|
||||
}
|
||||
|
||||
CommandValidate.check(!NamedHologramManager.isExistingHologram(hologramName), "A hologram with that name already exists.");
|
||||
CommandValidate.check(hologramName.matches("[a-zA-Z0-9_\\-]+"),
|
||||
"The name must contain only alphanumeric chars, underscores and hyphens.");
|
||||
CommandValidate.check(!internalHologramManager.isExistingHologram(hologramName),
|
||||
"A hologram with that name already exists.");
|
||||
|
||||
Location spawnLoc = player.getLocation();
|
||||
boolean moveUp = player.isOnGround();
|
||||
|
@ -55,21 +56,20 @@ public class CreateCommand extends HologramSubCommand {
|
|||
if (moveUp) {
|
||||
spawnLoc.add(0.0, 1.2, 0.0);
|
||||
}
|
||||
|
||||
NamedHologram hologram = new NamedHologram(spawnLoc, hologramName);
|
||||
|
||||
InternalHologram hologram = internalHologramManager.createHologram(spawnLoc, hologramName);
|
||||
|
||||
if (args.length > 1) {
|
||||
String text = Utils.join(args, " ", 1, args.length);
|
||||
CommandValidate.check(!text.equalsIgnoreCase("{empty}"), "The first line should not be empty.");
|
||||
|
||||
CraftHologramLine line = HologramCommandValidate.parseHologramLine(hologram, text, true);
|
||||
HologramLineImpl line = HologramCommandValidate.parseHologramLine(hologram, text, true);
|
||||
hologram.getLinesUnsafe().add(line);
|
||||
player.sendMessage(Colors.SECONDARY_SHADOW + "(Change the lines with /" + context.getRootLabel() + " edit " + hologram.getName() + ")");
|
||||
} else {
|
||||
hologram.appendTextLine("Default hologram. Change it with " + Colors.PRIMARY + "/" + context.getRootLabel() + " edit " + hologram.getName());
|
||||
}
|
||||
|
||||
NamedHologramManager.addHologram(hologram);
|
||||
|
||||
hologram.refreshAll();
|
||||
|
||||
configManager.getHologramDatabase().addOrUpdate(hologram);
|
||||
|
|
|
@ -7,12 +7,12 @@ package me.filoghost.holographicdisplays.commands.subs;
|
|||
|
||||
import me.filoghost.fcommons.command.sub.SubCommandContext;
|
||||
import me.filoghost.holographicdisplays.Colors;
|
||||
import me.filoghost.holographicdisplays.HolographicDisplays;
|
||||
import me.filoghost.holographicdisplays.api.Hologram;
|
||||
import me.filoghost.holographicdisplays.commands.HologramSubCommand;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.object.NamedHologram;
|
||||
import me.filoghost.holographicdisplays.object.PluginHologram;
|
||||
import me.filoghost.holographicdisplays.object.APIHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
|
@ -25,10 +25,14 @@ import java.util.Map.Entry;
|
|||
|
||||
public class DebugCommand extends HologramSubCommand {
|
||||
|
||||
public DebugCommand() {
|
||||
private final NMSManager nmsManager;
|
||||
|
||||
public DebugCommand(NMSManager nmsManager) {
|
||||
super("debug");
|
||||
setShowInHelpCommand(false);
|
||||
setDescription("Displays information useful for debugging.");
|
||||
|
||||
this.nmsManager = nmsManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -40,7 +44,7 @@ public class DebugCommand extends HologramSubCommand {
|
|||
|
||||
for (Chunk chunk : world.getLoadedChunks()) {
|
||||
for (Entity entity : chunk.getEntities()) {
|
||||
NMSEntityBase nmsEntity = HolographicDisplays.getNMSManager().getNMSEntityBase(entity);
|
||||
NMSEntityBase nmsEntity = nmsManager.getNMSEntityBase(entity);
|
||||
|
||||
if (nmsEntity == null) {
|
||||
continue;
|
||||
|
@ -78,10 +82,10 @@ public class DebugCommand extends HologramSubCommand {
|
|||
}
|
||||
|
||||
private String getHologramDisplayName(Hologram hologram) {
|
||||
if (hologram instanceof NamedHologram) {
|
||||
return ((NamedHologram) hologram).getName();
|
||||
} else if (hologram instanceof PluginHologram) {
|
||||
return ((PluginHologram) hologram).getOwner().getName() + "@" + Integer.toHexString(hologram.hashCode());
|
||||
if (hologram instanceof InternalHologram) {
|
||||
return ((InternalHologram) hologram).getName();
|
||||
} else if (hologram instanceof APIHologram) {
|
||||
return ((APIHologram) hologram).getOwner().getName() + "@" + Integer.toHexString(hologram.hashCode());
|
||||
} else {
|
||||
return hologram.toString();
|
||||
}
|
||||
|
|
|
@ -11,29 +11,30 @@ import me.filoghost.holographicdisplays.Colors;
|
|||
import me.filoghost.holographicdisplays.commands.HologramCommandValidate;
|
||||
import me.filoghost.holographicdisplays.commands.HologramSubCommand;
|
||||
import me.filoghost.holographicdisplays.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.object.NamedHologram;
|
||||
import me.filoghost.holographicdisplays.object.NamedHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologramManager;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class DeleteCommand extends HologramSubCommand {
|
||||
|
||||
private final InternalHologramManager internalHologramManager;
|
||||
private final ConfigManager configManager;
|
||||
|
||||
public DeleteCommand(ConfigManager configManager) {
|
||||
public DeleteCommand(InternalHologramManager internalHologramManager, ConfigManager configManager) {
|
||||
super("delete", "remove");
|
||||
setMinArgs(1);
|
||||
setUsageArgs("<hologram>");
|
||||
setDescription("Deletes a hologram. Cannot be undone.");
|
||||
|
||||
|
||||
this.internalHologramManager = internalHologramManager;
|
||||
this.configManager = configManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||
NamedHologram hologram = HologramCommandValidate.getNamedHologram(args[0]);
|
||||
InternalHologram hologram = HologramCommandValidate.getNamedHologram(internalHologramManager, args[0]);
|
||||
|
||||
hologram.delete();
|
||||
NamedHologramManager.removeHologram(hologram);
|
||||
|
||||
configManager.getHologramDatabase().removeHologram(hologram);
|
||||
configManager.saveHologramDatabase();
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue