mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2025-02-23 07:21:20 +01:00
Refactor and cleanup NMS-related classes
This commit is contained in:
parent
f7bc9b950f
commit
470b8bfcbd
@ -7,6 +7,7 @@ package me.filoghost.holographicdisplays.core;
|
||||
|
||||
import me.filoghost.fcommons.logging.Log;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.SpawnFailedException;
|
||||
|
||||
public class DebugLogger {
|
||||
|
||||
@ -47,8 +48,8 @@ public class DebugLogger {
|
||||
}
|
||||
}
|
||||
|
||||
public static void handleSpawnFail(StandardHologramLine parentPiece) {
|
||||
warning("Couldn't spawn entity for this hologram: " + parentPiece.getHologram());
|
||||
public static void handleSpawnFail(SpawnFailedException exception, StandardHologramLine parentPiece) {
|
||||
severe("Couldn't spawn entity for this hologram: " + parentPiece.getHologram(), exception);
|
||||
}
|
||||
|
||||
public static void cannotSetPassenger(Throwable t) {
|
||||
@ -59,8 +60,8 @@ public class DebugLogger {
|
||||
severe("Couldn't set armor stand as marker", t);
|
||||
}
|
||||
|
||||
public static void cannotSetRiderPitchYaw(Throwable t) {
|
||||
severe("Couldn't set rider pitch and yaw", t);
|
||||
public static void cannotSetPassengerPitchYawDelta(Throwable t) {
|
||||
severe("Couldn't set passenger pitch/yaw delta", t);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,16 +10,14 @@ import org.bukkit.ChatColor;
|
||||
|
||||
public class NMSCommons {
|
||||
|
||||
// This is used on hologram icons, to prevent vanilla items from merging with them.
|
||||
/**
|
||||
* Lore is used on hologram icons, to prevent vanilla items from merging with them.
|
||||
*/
|
||||
public static final String ANTI_STACK_LORE = ChatColor.BLACK.toString() + Math.random();
|
||||
|
||||
private static final boolean IS_PAPER_SERVER = Bukkit.getName().equals("Paper");
|
||||
|
||||
/**
|
||||
* Paper contains some code changes compared to Spigot.
|
||||
*/
|
||||
public static boolean isPaperServer() {
|
||||
return IS_PAPER_SERVER;
|
||||
}
|
||||
public static final boolean IS_PAPER_SERVER = Bukkit.getName().equals("Paper");
|
||||
|
||||
}
|
||||
|
@ -5,12 +5,12 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.core.nms;
|
||||
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardItemLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntity;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSSlime;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardItemLine;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public interface NMSManager {
|
||||
@ -18,18 +18,18 @@ 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, StandardHologramLine parentPiece);
|
||||
NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, StandardHologramLine parentPiece) throws SpawnFailedException;
|
||||
|
||||
NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, StandardItemLine parentPiece, ItemStack stack);
|
||||
NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, StandardItemLine parentPiece, ItemStack stack) throws SpawnFailedException;
|
||||
|
||||
NMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, StandardHologramLine parentPiece);
|
||||
NMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, StandardHologramLine parentPiece) throws SpawnFailedException;
|
||||
|
||||
boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity);
|
||||
|
||||
NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity);
|
||||
NMSEntity getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity);
|
||||
|
||||
NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID);
|
||||
NMSEntity getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID);
|
||||
|
||||
CustomNameEditor getCustomNameChatComponentEditor();
|
||||
CustomNameEditor getCustomNameEditor();
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.core.nms;
|
||||
|
||||
public class SpawnFailedException extends Exception {
|
||||
|
||||
public static final String REGISTER_ENTITY_FAIL = "failed to register entity";
|
||||
public static final String CHUNK_NOT_LOADED = "chunk was not loaded";
|
||||
public static final String ADD_ENTITY_FAILED = "failed to add entity with workaround";
|
||||
|
||||
public SpawnFailedException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public SpawnFailedException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
@ -5,6 +5,15 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.core.nms.entity;
|
||||
|
||||
public interface NMSArmorStand extends NMSNameable {
|
||||
public interface NMSArmorStand extends NMSVehicle {
|
||||
|
||||
// Sets a custom name as a String.
|
||||
void setCustomNameNMS(String name);
|
||||
|
||||
// Returns the custom name as a String.
|
||||
String getCustomNameStringNMS();
|
||||
|
||||
// Returns the custom name as version-dependent NMS object (String for MC 1.12 and below, ChatComponent for MC 1.13+ a ChatComponent).
|
||||
Object getCustomNameObjectNMS();
|
||||
|
||||
}
|
||||
|
@ -1,13 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.core.nms.entity;
|
||||
|
||||
public interface NMSCanMount extends NMSEntityBase {
|
||||
|
||||
// Sets the passenger of this entity through NMS.
|
||||
void setPassengerOfNMS(NMSEntityBase vehicleBase);
|
||||
|
||||
}
|
@ -10,7 +10,7 @@ import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
/**
|
||||
* An interface to represent a custom NMS entity being part of a hologram.
|
||||
*/
|
||||
public interface NMSEntityBase {
|
||||
public interface NMSEntity {
|
||||
|
||||
// Returns the linked line, all the entities are part of a piece. Should never be null.
|
||||
StandardHologramLine getHologramLine();
|
@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.core.nms.entity;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public interface NMSItem extends NMSEntityBase, NMSCanMount {
|
||||
public interface NMSItem extends NMSEntity {
|
||||
|
||||
// Sets the bukkit ItemStack for this item.
|
||||
void setItemStackNMS(ItemStack stack);
|
||||
|
@ -1,19 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.core.nms.entity;
|
||||
|
||||
public interface NMSNameable extends NMSEntityBase {
|
||||
|
||||
// Sets a custom name as a String.
|
||||
void setCustomNameNMS(String name);
|
||||
|
||||
// Returns the custom name as a String.
|
||||
String getCustomNameStringNMS();
|
||||
|
||||
// Returns the custom name as version-dependent NMS object (String for MC 1.12 and below, ChatComponent for MC 1.13+ a ChatComponent).
|
||||
Object getCustomNameObjectNMS();
|
||||
|
||||
}
|
@ -5,6 +5,6 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.core.nms.entity;
|
||||
|
||||
public interface NMSSlime extends NMSEntityBase, NMSCanMount {
|
||||
public interface NMSSlime extends NMSEntity {
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.core.nms.entity;
|
||||
|
||||
public interface NMSVehicle extends NMSEntity {
|
||||
|
||||
void setPassengerNMS(NMSEntity passenger);
|
||||
|
||||
}
|
@ -32,52 +32,52 @@ public class CraftNMSArmorStand extends CraftArmorStand {
|
||||
}
|
||||
|
||||
// Methods from Armor stand class
|
||||
@Override public void setArms(boolean arms) { }
|
||||
@Override public void setBasePlate(boolean basePlate) { }
|
||||
@Override public void setBodyPose(EulerAngle pose) { }
|
||||
@Override public void setBoots(ItemStack item) { }
|
||||
@Override public void setChestplate(ItemStack item) { }
|
||||
@Override public void setHeadPose(EulerAngle pose) { }
|
||||
@Override public void setHelmet(ItemStack item) { }
|
||||
@Override public void setItemInHand(ItemStack item) { }
|
||||
@Override public void setLeftArmPose(EulerAngle pose) { }
|
||||
@Override public void setLeftLegPose(EulerAngle pose) { }
|
||||
@Override public void setLeggings(ItemStack item) { }
|
||||
@Override public void setRightArmPose(EulerAngle pose) { }
|
||||
@Override public void setRightLegPose(EulerAngle pose) { }
|
||||
@Override public void setSmall(boolean small) { }
|
||||
@Override public void setVisible(boolean visible) { }
|
||||
@Override public void setMarker(boolean marker) { }
|
||||
@Override public void setArms(boolean arms) {}
|
||||
@Override public void setBasePlate(boolean basePlate) {}
|
||||
@Override public void setBodyPose(EulerAngle pose) {}
|
||||
@Override public void setBoots(ItemStack item) {}
|
||||
@Override public void setChestplate(ItemStack item) {}
|
||||
@Override public void setHeadPose(EulerAngle pose) {}
|
||||
@Override public void setHelmet(ItemStack item) {}
|
||||
@Override public void setItemInHand(ItemStack item) {}
|
||||
@Override public void setLeftArmPose(EulerAngle pose) {}
|
||||
@Override public void setLeftLegPose(EulerAngle pose) {}
|
||||
@Override public void setLeggings(ItemStack item) {}
|
||||
@Override public void setRightArmPose(EulerAngle pose) {}
|
||||
@Override public void setRightLegPose(EulerAngle pose) {}
|
||||
@Override public void setSmall(boolean small) {}
|
||||
@Override public void setVisible(boolean visible) {}
|
||||
@Override public void setMarker(boolean marker) {}
|
||||
|
||||
// Methods from LivingEntity class
|
||||
@Override public boolean addPotionEffect(PotionEffect effect) { return false; }
|
||||
@Override public boolean addPotionEffect(PotionEffect effect, boolean param) { return false; }
|
||||
@Override public boolean addPotionEffects(Collection<PotionEffect> effects) { return false; }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) { }
|
||||
@Override public void setAI(boolean ai) { }
|
||||
@Override public void setCanPickupItems(boolean pickup) { }
|
||||
@Override public void setCollidable(boolean collidable) { }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) {}
|
||||
@Override public void setAI(boolean ai) {}
|
||||
@Override public void setCanPickupItems(boolean pickup) {}
|
||||
@Override public void setCollidable(boolean collidable) {}
|
||||
@Override public void setGliding(boolean gliding) { }
|
||||
@Override public boolean setLeashHolder(Entity holder) { return false; }
|
||||
|
||||
// Methods from Entity
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void setGlowing(boolean flag) { }
|
||||
@Override public void setGravity(boolean gravity) { }
|
||||
@Override public void setInvulnerable(boolean flag) { }
|
||||
@Override public void setMomentum(Vector value) { }
|
||||
@Override public void setSilent(boolean flag) { }
|
||||
@Override public void setTicksLived(int value) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
@Override public void setGlowing(boolean flag) {}
|
||||
@Override public void setGravity(boolean gravity) {}
|
||||
@Override public void setInvulnerable(boolean flag) {}
|
||||
@Override public void setMomentum(Vector value) {}
|
||||
@Override public void setSilent(boolean flag) {}
|
||||
@Override public void setTicksLived(int value) {}
|
||||
|
||||
}
|
||||
|
@ -28,27 +28,27 @@ public class CraftNMSItem extends CraftItem {
|
||||
}
|
||||
|
||||
// Methods from Entity
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void setGlowing(boolean flag) { }
|
||||
@Override public void setGravity(boolean gravity) { }
|
||||
@Override public void setInvulnerable(boolean flag) { }
|
||||
@Override public void setMomentum(Vector value) { }
|
||||
@Override public void setSilent(boolean flag) { }
|
||||
@Override public void setTicksLived(int value) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
@Override public void setGlowing(boolean flag) {}
|
||||
@Override public void setGravity(boolean gravity) {}
|
||||
@Override public void setInvulnerable(boolean flag) {}
|
||||
@Override public void setMomentum(Vector value) {}
|
||||
@Override public void setSilent(boolean flag) {}
|
||||
@Override public void setTicksLived(int value) {}
|
||||
|
||||
// Methods from Item
|
||||
@Override public void setItemStack(ItemStack stack) { }
|
||||
@Override public void setPickupDelay(int delay) { }
|
||||
@Override public void setItemStack(ItemStack stack) {}
|
||||
@Override public void setPickupDelay(int delay) {}
|
||||
|
||||
}
|
||||
|
@ -33,34 +33,34 @@ public class CraftNMSSlime extends CraftSlime {
|
||||
@Override public boolean addPotionEffect(PotionEffect effect) { return false; }
|
||||
@Override public boolean addPotionEffect(PotionEffect effect, boolean param) { return false; }
|
||||
@Override public boolean addPotionEffects(Collection<PotionEffect> effects) { return false; }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) { }
|
||||
@Override public void setAI(boolean ai) { }
|
||||
@Override public void setCanPickupItems(boolean pickup) { }
|
||||
@Override public void setCollidable(boolean collidable) { }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) {}
|
||||
@Override public void setAI(boolean ai) {}
|
||||
@Override public void setCanPickupItems(boolean pickup) {}
|
||||
@Override public void setCollidable(boolean collidable) {}
|
||||
@Override public void setGliding(boolean gliding) { }
|
||||
@Override public boolean setLeashHolder(Entity holder) { return false; }
|
||||
|
||||
// Methods from Entity
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void setGlowing(boolean flag) { }
|
||||
@Override public void setGravity(boolean gravity) { }
|
||||
@Override public void setInvulnerable(boolean flag) { }
|
||||
@Override public void setMomentum(Vector value) { }
|
||||
@Override public void setSilent(boolean flag) { }
|
||||
@Override public void setTicksLived(int value) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
@Override public void setGlowing(boolean flag) {}
|
||||
@Override public void setGravity(boolean gravity) {}
|
||||
@Override public void setInvulnerable(boolean flag) {}
|
||||
@Override public void setMomentum(Vector value) {}
|
||||
@Override public void setSilent(boolean flag) {}
|
||||
@Override public void setTicksLived(int value) {}
|
||||
|
||||
// Methods from Slime
|
||||
@Override public void setSize(int size) { }
|
||||
@Override public void setSize(int size) {}
|
||||
|
||||
}
|
||||
|
@ -5,12 +5,17 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.nms.v1_10_R1;
|
||||
|
||||
import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.Utils;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.PacketController;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntity;
|
||||
import net.minecraft.server.v1_10_R1.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_10_R1.DamageSource;
|
||||
import net.minecraft.server.v1_10_R1.Entity;
|
||||
import net.minecraft.server.v1_10_R1.EntityArmorStand;
|
||||
import net.minecraft.server.v1_10_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_10_R1.EntityPlayer;
|
||||
@ -27,12 +32,17 @@ import org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity;
|
||||
|
||||
public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand {
|
||||
|
||||
private final StandardHologramLine parentPiece;
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "au");
|
||||
|
||||
private final StandardHologramLine parentHologramLine;
|
||||
private final PacketController packetController;
|
||||
private String customName;
|
||||
|
||||
public EntityNMSArmorStand(World world, StandardHologramLine parentPiece, PacketController packetController) {
|
||||
public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, PacketController packetController) {
|
||||
super(world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
this.packetController = packetController;
|
||||
|
||||
super.setInvisible(true);
|
||||
super.setSmall(true);
|
||||
super.setArms(false);
|
||||
@ -40,11 +50,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
super.setBasePlate(true);
|
||||
super.setMarker(true);
|
||||
super.collides = false;
|
||||
|
||||
this.parentPiece = parentPiece;
|
||||
this.packetController = packetController;
|
||||
super.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -52,8 +59,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
// Disable normal ticking for this entity.
|
||||
|
||||
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
|
||||
if (this.onGround) {
|
||||
this.onGround = false;
|
||||
if (super.onGround) {
|
||||
super.onGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,8 +69,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
// Disable normal ticking for this entity.
|
||||
|
||||
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
|
||||
if (this.onGround) {
|
||||
this.onGround = false;
|
||||
if (super.onGround) {
|
||||
super.onGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,7 +151,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
|
||||
@Override
|
||||
public void a(AxisAlignedBB boundingBox) {
|
||||
// Do not change it!
|
||||
// Prevent bounding box from being changed
|
||||
}
|
||||
|
||||
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
|
||||
@ -202,9 +209,9 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
private void broadcastLocationPacketNMS() {
|
||||
PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this);
|
||||
|
||||
for (Object obj : super.world.players) {
|
||||
if (obj instanceof EntityPlayer) {
|
||||
EntityPlayer nmsPlayer = (EntityPlayer) obj;
|
||||
for (Object humanEntity : super.world.players) {
|
||||
if (humanEntity instanceof EntityPlayer) {
|
||||
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
|
||||
|
||||
double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ);
|
||||
if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) {
|
||||
@ -214,6 +221,21 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerNMS(NMSEntity passenger) {
|
||||
Preconditions.checkArgument(passenger instanceof Entity);
|
||||
Entity passengerEntity = (Entity) passenger;
|
||||
Preconditions.checkArgument(passengerEntity.bB() == null);
|
||||
Preconditions.checkState(super.passengers.isEmpty());
|
||||
|
||||
try {
|
||||
VEHICLE_FIELD.set(passenger, this);
|
||||
this.passengers.add(this);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
DebugLogger.cannotSetPassenger(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDeadNMS() {
|
||||
return super.dead;
|
||||
@ -226,11 +248,12 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getBukkitEntityNMS() {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,14 +5,11 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.nms.v1_10_R1;
|
||||
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.Utils;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSCommons;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardItemLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSCommons;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import net.minecraft.server.v1_10_R1.Blocks;
|
||||
import net.minecraft.server.v1_10_R1.DamageSource;
|
||||
import net.minecraft.server.v1_10_R1.Entity;
|
||||
@ -30,16 +27,15 @@ import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack;
|
||||
|
||||
public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "au");
|
||||
|
||||
private final StandardItemLine parentPiece;
|
||||
private final StandardItemLine parentHologramLine;
|
||||
|
||||
private int resendMountPacketTicks;
|
||||
|
||||
public EntityNMSItem(World world, StandardItemLine piece) {
|
||||
public EntityNMSItem(World world, StandardItemLine parentHologramLine) {
|
||||
super(world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
|
||||
super.pickupDelay = Integer.MAX_VALUE;
|
||||
this.parentPiece = piece;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -57,9 +53,9 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
// Send a packet near to "remind" players that the item is riding the armor stand (Spigot bug or client bug)
|
||||
PacketPlayOutMount mountPacket = new PacketPlayOutMount(vehicle);
|
||||
|
||||
for (Object obj : super.world.players) {
|
||||
if (obj instanceof EntityPlayer) {
|
||||
EntityPlayer nmsPlayer = (EntityPlayer) obj;
|
||||
for (Object humanEntity : super.world.players) {
|
||||
if (humanEntity instanceof EntityPlayer) {
|
||||
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
|
||||
|
||||
double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ);
|
||||
if (distanceSquared < 1024 && nmsPlayer.playerConnection != null) {
|
||||
@ -88,7 +84,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
}
|
||||
|
||||
if (human instanceof EntityPlayer) {
|
||||
parentPiece.onPickup(((EntityPlayer) human).getBukkitEntity());
|
||||
parentHologramLine.onPickup(((EntityPlayer) human).getBukkitEntity());
|
||||
// It is never added to the inventory.
|
||||
}
|
||||
}
|
||||
@ -194,10 +190,10 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
}
|
||||
|
||||
NBTTagList tagList = new NBTTagList();
|
||||
tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE)); // Antistack lore
|
||||
tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE));
|
||||
display.set("Lore", tagList);
|
||||
|
||||
setItemStack(newItem);
|
||||
super.setItemStack(newItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -207,41 +203,17 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getBukkitEntityNMS() {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerOfNMS(NMSEntityBase vehicleBase) {
|
||||
if (!(vehicleBase instanceof Entity)) {
|
||||
// It should never dismount
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = (Entity) vehicleBase;
|
||||
|
||||
try {
|
||||
Entity oldVehicle = super.bB();
|
||||
if (oldVehicle != null) {
|
||||
VEHICLE_FIELD.set(this, null);
|
||||
oldVehicle.passengers.remove(this);
|
||||
}
|
||||
|
||||
VEHICLE_FIELD.set(this, entity);
|
||||
entity.passengers.clear();
|
||||
entity.passengers.add(this);
|
||||
|
||||
} catch (Throwable t) {
|
||||
DebugLogger.cannotSetPassenger(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getRawItemStack() {
|
||||
return super.getItemStack();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,12 +5,9 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.nms.v1_10_R1;
|
||||
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.Utils;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSSlime;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSSlime;
|
||||
import net.minecraft.server.v1_10_R1.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_10_R1.DamageSource;
|
||||
import net.minecraft.server.v1_10_R1.Entity;
|
||||
@ -27,20 +24,19 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
|
||||
public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "au");
|
||||
|
||||
private final StandardHologramLine parentPiece;
|
||||
private final StandardHologramLine parentHologramLine;
|
||||
|
||||
private int resendMountPacketTicks;
|
||||
|
||||
public EntityNMSSlime(World world, StandardHologramLine parentPiece) {
|
||||
public EntityNMSSlime(World world, StandardHologramLine parentHologramLine) {
|
||||
super(world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
|
||||
super.persistent = true;
|
||||
super.collides = false;
|
||||
a(0.0F, 0.0F);
|
||||
setSize(1);
|
||||
setInvisible(true);
|
||||
this.parentPiece = parentPiece;
|
||||
super.a(0.0F, 0.0F);
|
||||
super.setSize(1);
|
||||
super.setInvisible(true);
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
}
|
||||
|
||||
@ -59,9 +55,9 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
// Send a packet near to "remind" players that the slime is riding the armor stand (Spigot bug or client bug)
|
||||
PacketPlayOutMount mountPacket = new PacketPlayOutMount(vehicle);
|
||||
|
||||
for (Object obj : super.world.players) {
|
||||
if (obj instanceof EntityPlayer) {
|
||||
EntityPlayer nmsPlayer = (EntityPlayer) obj;
|
||||
for (Object humanEntity : super.world.players) {
|
||||
if (humanEntity instanceof EntityPlayer) {
|
||||
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
|
||||
|
||||
double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ);
|
||||
if (distanceSquared < 1024 && nmsPlayer.playerConnection != null) {
|
||||
@ -83,7 +79,7 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
|
||||
@Override
|
||||
public void a(AxisAlignedBB boundingBox) {
|
||||
// Do not change it!
|
||||
// Prevent bounding box from being changed
|
||||
}
|
||||
|
||||
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
|
||||
@ -199,36 +195,12 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getBukkitEntityNMS() {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerOfNMS(NMSEntityBase vehicleBase) {
|
||||
if (!(vehicleBase instanceof Entity)) {
|
||||
// It should never dismount
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = (Entity) vehicleBase;
|
||||
|
||||
try {
|
||||
Entity oldVehicle = super.bB();
|
||||
if (oldVehicle != null) {
|
||||
VEHICLE_FIELD.set(this, null);
|
||||
oldVehicle.passengers.remove(this);
|
||||
}
|
||||
|
||||
VEHICLE_FIELD.set(this, entity);
|
||||
entity.passengers.clear();
|
||||
entity.passengers.add(this);
|
||||
|
||||
} catch (Throwable t) {
|
||||
DebugLogger.cannotSetPassenger(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,15 +9,15 @@ import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.fcommons.reflection.ClassToken;
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.fcommons.reflection.ReflectMethod;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardItemLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.CustomNameEditor;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSManager;
|
||||
import me.filoghost.holographicdisplays.core.nms.PacketController;
|
||||
import me.filoghost.holographicdisplays.core.nms.SpawnFailedException;
|
||||
import me.filoghost.holographicdisplays.core.nms.StringCustomNameEditor;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntity;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import net.minecraft.server.v1_10_R1.Entity;
|
||||
import net.minecraft.server.v1_10_R1.EntityTypes;
|
||||
@ -36,7 +36,7 @@ public class VersionNMSManager implements NMSManager {
|
||||
private static final ReflectField<Map<Class<?>, String>> ENTITY_NAMES_BY_CLASS_FIELD = ReflectField.lookup(new ClassToken<Map<Class<?>, String>>(){}, EntityTypes.class, "d");
|
||||
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 static final ReflectMethod<?> REGISTER_ENTITY_METHOD = ReflectMethod.lookup(Object.class, World.class, "b", Entity.class);
|
||||
|
||||
private final PacketController packetController;
|
||||
|
||||
@ -57,40 +57,34 @@ public class VersionNMSManager implements NMSManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, StandardItemLine parentPiece, ItemStack stack) {
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, StandardItemLine parentPiece, ItemStack stack) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece);
|
||||
customItem.setLocationNMS(x, y, z);
|
||||
customItem.setItemStackNMS(stack);
|
||||
if (!addEntityToWorld(nmsWorld, customItem)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return customItem;
|
||||
EntityNMSItem item = new EntityNMSItem(nmsWorld, parentPiece);
|
||||
item.setLocationNMS(x, y, z);
|
||||
item.setItemStackNMS(stack);
|
||||
addEntityToWorld(nmsWorld, item);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, StandardHologramLine parentPiece) {
|
||||
public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, StandardHologramLine parentPiece) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece);
|
||||
touchSlime.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, touchSlime)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return touchSlime;
|
||||
EntityNMSSlime slime = new EntityNMSSlime(nmsWorld, parentPiece);
|
||||
slime.setLocationNMS(x, y, z);
|
||||
addEntityToWorld(nmsWorld, slime);
|
||||
return slime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, StandardHologramLine parentPiece) {
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, StandardHologramLine parentPiece) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return invisibleArmorStand;
|
||||
EntityNMSArmorStand armorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
armorStand.setLocationNMS(x, y, z);
|
||||
addEntityToWorld(nmsWorld, armorStand);
|
||||
return armorStand;
|
||||
}
|
||||
|
||||
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) {
|
||||
private void addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) throws SpawnFailedException {
|
||||
Preconditions.checkState(Bukkit.isPrimaryThread(), "Async entity add");
|
||||
|
||||
final int chunkX = MathHelper.floor(nmsEntity.locX / 16.0);
|
||||
@ -99,51 +93,50 @@ public class VersionNMSManager implements NMSManager {
|
||||
if (!nmsWorld.getChunkProviderServer().isLoaded(chunkX, chunkZ)) {
|
||||
// This should never happen
|
||||
nmsEntity.dead = true;
|
||||
return false;
|
||||
throw new SpawnFailedException(SpawnFailedException.CHUNK_NOT_LOADED);
|
||||
}
|
||||
|
||||
nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity);
|
||||
nmsWorld.entityList.add(nmsEntity);
|
||||
|
||||
try {
|
||||
VALIDATE_ENTITY_METHOD.invoke(nmsWorld, nmsEntity);
|
||||
REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
nmsEntity.dead = true;
|
||||
throw new SpawnFailedException(SpawnFailedException.REGISTER_ENTITY_FAIL, e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase;
|
||||
return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
public NMSEntity getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle();
|
||||
|
||||
if (nmsEntity instanceof NMSEntityBase) {
|
||||
return ((NMSEntityBase) nmsEntity);
|
||||
if (nmsEntity instanceof NMSEntity) {
|
||||
return ((NMSEntity) nmsEntity);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) {
|
||||
public NMSEntity getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
Entity nmsEntity = nmsWorld.getEntity(entityID);
|
||||
|
||||
if (nmsEntity instanceof NMSEntityBase) {
|
||||
return ((NMSEntityBase) nmsEntity);
|
||||
if (nmsEntity instanceof NMSEntity) {
|
||||
return ((NMSEntity) nmsEntity);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomNameEditor getCustomNameChatComponentEditor() {
|
||||
public CustomNameEditor getCustomNameEditor() {
|
||||
return StringCustomNameEditor.INSTANCE;
|
||||
}
|
||||
|
||||
|
@ -32,52 +32,52 @@ public class CraftNMSArmorStand extends CraftArmorStand {
|
||||
}
|
||||
|
||||
// Methods from Armor stand class
|
||||
@Override public void setArms(boolean arms) { }
|
||||
@Override public void setBasePlate(boolean basePlate) { }
|
||||
@Override public void setBodyPose(EulerAngle pose) { }
|
||||
@Override public void setBoots(ItemStack item) { }
|
||||
@Override public void setChestplate(ItemStack item) { }
|
||||
@Override public void setHeadPose(EulerAngle pose) { }
|
||||
@Override public void setHelmet(ItemStack item) { }
|
||||
@Override public void setItemInHand(ItemStack item) { }
|
||||
@Override public void setLeftArmPose(EulerAngle pose) { }
|
||||
@Override public void setLeftLegPose(EulerAngle pose) { }
|
||||
@Override public void setLeggings(ItemStack item) { }
|
||||
@Override public void setRightArmPose(EulerAngle pose) { }
|
||||
@Override public void setRightLegPose(EulerAngle pose) { }
|
||||
@Override public void setSmall(boolean small) { }
|
||||
@Override public void setVisible(boolean visible) { }
|
||||
@Override public void setMarker(boolean marker) { }
|
||||
@Override public void setArms(boolean arms) {}
|
||||
@Override public void setBasePlate(boolean basePlate) {}
|
||||
@Override public void setBodyPose(EulerAngle pose) {}
|
||||
@Override public void setBoots(ItemStack item) {}
|
||||
@Override public void setChestplate(ItemStack item) {}
|
||||
@Override public void setHeadPose(EulerAngle pose) {}
|
||||
@Override public void setHelmet(ItemStack item) {}
|
||||
@Override public void setItemInHand(ItemStack item) {}
|
||||
@Override public void setLeftArmPose(EulerAngle pose) {}
|
||||
@Override public void setLeftLegPose(EulerAngle pose) {}
|
||||
@Override public void setLeggings(ItemStack item) {}
|
||||
@Override public void setRightArmPose(EulerAngle pose) {}
|
||||
@Override public void setRightLegPose(EulerAngle pose) {}
|
||||
@Override public void setSmall(boolean small) {}
|
||||
@Override public void setVisible(boolean visible) {}
|
||||
@Override public void setMarker(boolean marker) {}
|
||||
|
||||
// Methods from LivingEntity class
|
||||
@Override public boolean addPotionEffect(PotionEffect effect) { return false; }
|
||||
@Override public boolean addPotionEffect(PotionEffect effect, boolean param) { return false; }
|
||||
@Override public boolean addPotionEffects(Collection<PotionEffect> effects) { return false; }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) { }
|
||||
@Override public void setAI(boolean ai) { }
|
||||
@Override public void setCanPickupItems(boolean pickup) { }
|
||||
@Override public void setCollidable(boolean collidable) { }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) {}
|
||||
@Override public void setAI(boolean ai) {}
|
||||
@Override public void setCanPickupItems(boolean pickup) {}
|
||||
@Override public void setCollidable(boolean collidable) {}
|
||||
@Override public void setGliding(boolean gliding) { }
|
||||
@Override public boolean setLeashHolder(Entity holder) { return false; }
|
||||
|
||||
// Methods from Entity
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void setGlowing(boolean flag) { }
|
||||
@Override public void setGravity(boolean gravity) { }
|
||||
@Override public void setInvulnerable(boolean flag) { }
|
||||
@Override public void setMomentum(Vector value) { }
|
||||
@Override public void setSilent(boolean flag) { }
|
||||
@Override public void setTicksLived(int value) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
@Override public void setGlowing(boolean flag) {}
|
||||
@Override public void setGravity(boolean gravity) {}
|
||||
@Override public void setInvulnerable(boolean flag) {}
|
||||
@Override public void setMomentum(Vector value) {}
|
||||
@Override public void setSilent(boolean flag) {}
|
||||
@Override public void setTicksLived(int value) {}
|
||||
|
||||
}
|
||||
|
@ -28,27 +28,27 @@ public class CraftNMSItem extends CraftItem {
|
||||
}
|
||||
|
||||
// Methods from Entity
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void setGlowing(boolean flag) { }
|
||||
@Override public void setGravity(boolean gravity) { }
|
||||
@Override public void setInvulnerable(boolean flag) { }
|
||||
@Override public void setMomentum(Vector value) { }
|
||||
@Override public void setSilent(boolean flag) { }
|
||||
@Override public void setTicksLived(int value) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
@Override public void setGlowing(boolean flag) {}
|
||||
@Override public void setGravity(boolean gravity) {}
|
||||
@Override public void setInvulnerable(boolean flag) {}
|
||||
@Override public void setMomentum(Vector value) {}
|
||||
@Override public void setSilent(boolean flag) {}
|
||||
@Override public void setTicksLived(int value) {}
|
||||
|
||||
// Methods from Item
|
||||
@Override public void setItemStack(ItemStack stack) { }
|
||||
@Override public void setPickupDelay(int delay) { }
|
||||
@Override public void setItemStack(ItemStack stack) {}
|
||||
@Override public void setPickupDelay(int delay) {}
|
||||
|
||||
}
|
||||
|
@ -33,34 +33,34 @@ public class CraftNMSSlime extends CraftSlime {
|
||||
@Override public boolean addPotionEffect(PotionEffect effect) { return false; }
|
||||
@Override public boolean addPotionEffect(PotionEffect effect, boolean param) { return false; }
|
||||
@Override public boolean addPotionEffects(Collection<PotionEffect> effects) { return false; }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) { }
|
||||
@Override public void setAI(boolean ai) { }
|
||||
@Override public void setCanPickupItems(boolean pickup) { }
|
||||
@Override public void setCollidable(boolean collidable) { }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) {}
|
||||
@Override public void setAI(boolean ai) {}
|
||||
@Override public void setCanPickupItems(boolean pickup) {}
|
||||
@Override public void setCollidable(boolean collidable) {}
|
||||
@Override public void setGliding(boolean gliding) { }
|
||||
@Override public boolean setLeashHolder(Entity holder) { return false; }
|
||||
|
||||
// Methods from Entity
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void setGlowing(boolean flag) { }
|
||||
@Override public void setGravity(boolean gravity) { }
|
||||
@Override public void setInvulnerable(boolean flag) { }
|
||||
@Override public void setMomentum(Vector value) { }
|
||||
@Override public void setSilent(boolean flag) { }
|
||||
@Override public void setTicksLived(int value) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
@Override public void setGlowing(boolean flag) {}
|
||||
@Override public void setGravity(boolean gravity) {}
|
||||
@Override public void setInvulnerable(boolean flag) {}
|
||||
@Override public void setMomentum(Vector value) {}
|
||||
@Override public void setSilent(boolean flag) {}
|
||||
@Override public void setTicksLived(int value) {}
|
||||
|
||||
// Methods from Slime
|
||||
@Override public void setSize(int size) { }
|
||||
@Override public void setSize(int size) {}
|
||||
|
||||
}
|
||||
|
@ -5,12 +5,17 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.nms.v1_11_R1;
|
||||
|
||||
import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.Utils;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.PacketController;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntity;
|
||||
import net.minecraft.server.v1_11_R1.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_11_R1.DamageSource;
|
||||
import net.minecraft.server.v1_11_R1.Entity;
|
||||
import net.minecraft.server.v1_11_R1.EntityArmorStand;
|
||||
import net.minecraft.server.v1_11_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_11_R1.EntityPlayer;
|
||||
@ -27,12 +32,17 @@ import org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity;
|
||||
|
||||
public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand {
|
||||
|
||||
private final StandardHologramLine parentPiece;
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "au");
|
||||
|
||||
private final StandardHologramLine parentHologramLine;
|
||||
private final PacketController packetController;
|
||||
private String customName;
|
||||
|
||||
public EntityNMSArmorStand(World world, StandardHologramLine parentPiece, PacketController packetController) {
|
||||
public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, PacketController packetController) {
|
||||
super(world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
this.packetController = packetController;
|
||||
|
||||
super.setInvisible(true);
|
||||
super.setSmall(true);
|
||||
super.setArms(false);
|
||||
@ -40,11 +50,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
super.setBasePlate(true);
|
||||
super.setMarker(true);
|
||||
super.collides = false;
|
||||
|
||||
this.parentPiece = parentPiece;
|
||||
this.packetController = packetController;
|
||||
super.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -52,8 +59,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
// Disable normal ticking for this entity.
|
||||
|
||||
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
|
||||
if (this.onGround) {
|
||||
this.onGround = false;
|
||||
if (super.onGround) {
|
||||
super.onGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,8 +69,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
// Disable normal ticking for this entity.
|
||||
|
||||
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
|
||||
if (this.onGround) {
|
||||
this.onGround = false;
|
||||
if (super.onGround) {
|
||||
super.onGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,7 +151,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
|
||||
@Override
|
||||
public void a(AxisAlignedBB boundingBox) {
|
||||
// Do not change it!
|
||||
// Prevent bounding box from being changed
|
||||
}
|
||||
|
||||
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
|
||||
@ -202,9 +209,9 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
private void broadcastLocationPacketNMS() {
|
||||
PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this);
|
||||
|
||||
for (Object obj : super.world.players) {
|
||||
if (obj instanceof EntityPlayer) {
|
||||
EntityPlayer nmsPlayer = (EntityPlayer) obj;
|
||||
for (Object humanEntity : super.world.players) {
|
||||
if (humanEntity instanceof EntityPlayer) {
|
||||
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
|
||||
|
||||
double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ);
|
||||
if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) {
|
||||
@ -214,6 +221,21 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerNMS(NMSEntity passenger) {
|
||||
Preconditions.checkArgument(passenger instanceof Entity);
|
||||
Entity passengerEntity = (Entity) passenger;
|
||||
Preconditions.checkArgument(passengerEntity.bB() == null);
|
||||
Preconditions.checkState(super.passengers.isEmpty());
|
||||
|
||||
try {
|
||||
VEHICLE_FIELD.set(passenger, this);
|
||||
this.passengers.add(this);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
DebugLogger.cannotSetPassenger(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDeadNMS() {
|
||||
return super.dead;
|
||||
@ -226,11 +248,12 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getBukkitEntityNMS() {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,16 +5,12 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.nms.v1_11_R1;
|
||||
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSCommons;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardItemLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSCommons;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import net.minecraft.server.v1_11_R1.Blocks;
|
||||
import net.minecraft.server.v1_11_R1.DamageSource;
|
||||
import net.minecraft.server.v1_11_R1.Entity;
|
||||
import net.minecraft.server.v1_11_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_11_R1.EntityItem;
|
||||
import net.minecraft.server.v1_11_R1.EntityPlayer;
|
||||
@ -28,14 +24,13 @@ import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack;
|
||||
|
||||
public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "au");
|
||||
private final StandardItemLine parentHologramLine;
|
||||
|
||||
private final StandardItemLine parentPiece;
|
||||
|
||||
public EntityNMSItem(World world, StandardItemLine piece) {
|
||||
public EntityNMSItem(World world, StandardItemLine parentHologramLine) {
|
||||
super(world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
|
||||
super.pickupDelay = 32767; // Lock the item pickup delay, also prevents entities from picking up the item
|
||||
this.parentPiece = piece;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -63,7 +58,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
}
|
||||
|
||||
if (human instanceof EntityPlayer) {
|
||||
parentPiece.onPickup(((EntityPlayer) human).getBukkitEntity());
|
||||
parentHologramLine.onPickup(((EntityPlayer) human).getBukkitEntity());
|
||||
// It is never added to the inventory.
|
||||
}
|
||||
}
|
||||
@ -153,7 +148,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
|
||||
@Override
|
||||
public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) {
|
||||
ItemStack newItem = CraftItemStack.asNMSCopy(stack); // ItemStack.a is returned if the stack is null, invalid or the material is not an Item
|
||||
ItemStack newItem = CraftItemStack.asNMSCopy(stack); // ItemStack.a is returned if the stack is not valid
|
||||
|
||||
if (newItem == null || newItem == ItemStack.a) {
|
||||
newItem = new ItemStack(Blocks.BEDROCK);
|
||||
@ -168,10 +163,10 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
}
|
||||
|
||||
NBTTagList tagList = new NBTTagList();
|
||||
tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE)); // Antistack lore
|
||||
tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE));
|
||||
display.set("Lore", tagList);
|
||||
|
||||
setItemStack(newItem);
|
||||
super.setItemStack(newItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -181,7 +176,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -189,33 +184,9 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerOfNMS(NMSEntityBase vehicleBase) {
|
||||
if (!(vehicleBase instanceof Entity)) {
|
||||
// It should never dismount
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = (Entity) vehicleBase;
|
||||
|
||||
try {
|
||||
Entity oldVehicle = super.bB();
|
||||
if (oldVehicle != null) {
|
||||
VEHICLE_FIELD.set(this, null);
|
||||
oldVehicle.passengers.remove(this);
|
||||
}
|
||||
|
||||
VEHICLE_FIELD.set(this, entity);
|
||||
entity.passengers.clear();
|
||||
entity.passengers.add(this);
|
||||
|
||||
} catch (Throwable t) {
|
||||
DebugLogger.cannotSetPassenger(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getRawItemStack() {
|
||||
return super.getItemStack();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,13 +6,9 @@
|
||||
package me.filoghost.holographicdisplays.nms.v1_11_R1;
|
||||
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSSlime;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import net.minecraft.server.v1_11_R1.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_11_R1.DamageSource;
|
||||
import net.minecraft.server.v1_11_R1.Entity;
|
||||
import net.minecraft.server.v1_11_R1.EntityDamageSource;
|
||||
import net.minecraft.server.v1_11_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_11_R1.EntitySlime;
|
||||
@ -25,18 +21,17 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
|
||||
public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "au");
|
||||
|
||||
private final StandardHologramLine parentPiece;
|
||||
private final StandardHologramLine parentHologramLine;
|
||||
|
||||
public EntityNMSSlime(World world, StandardHologramLine parentPiece) {
|
||||
public EntityNMSSlime(World world, StandardHologramLine parentHologramLine) {
|
||||
super(world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
|
||||
super.persistent = true;
|
||||
super.collides = false;
|
||||
a(0.0F, 0.0F);
|
||||
setSize(1, false);
|
||||
setInvisible(true);
|
||||
this.parentPiece = parentPiece;
|
||||
super.a(0.0F, 0.0F);
|
||||
super.setSize(1, false);
|
||||
super.setInvisible(true);
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
}
|
||||
|
||||
@ -58,7 +53,7 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
|
||||
@Override
|
||||
public void a(AxisAlignedBB boundingBox) {
|
||||
// Do not change it!
|
||||
// Prevent bounding box from being changed
|
||||
}
|
||||
|
||||
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
|
||||
@ -174,7 +169,7 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -182,28 +177,4 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerOfNMS(NMSEntityBase vehicleBase) {
|
||||
if (!(vehicleBase instanceof Entity)) {
|
||||
// It should never dismount
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = (Entity) vehicleBase;
|
||||
|
||||
try {
|
||||
Entity oldVehicle = super.bB();
|
||||
if (oldVehicle != null) {
|
||||
VEHICLE_FIELD.set(this, null);
|
||||
oldVehicle.passengers.remove(this);
|
||||
}
|
||||
|
||||
VEHICLE_FIELD.set(this, entity);
|
||||
entity.passengers.clear();
|
||||
entity.passengers.add(this);
|
||||
|
||||
} catch (Throwable t) {
|
||||
DebugLogger.cannotSetPassenger(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -125,8 +125,5 @@ public class NullBoundingBox extends AxisAlignedBB {
|
||||
public boolean e(Vec3D arg0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -9,15 +9,15 @@ import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.fcommons.reflection.ClassToken;
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.fcommons.reflection.ReflectMethod;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardItemLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.CustomNameEditor;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSManager;
|
||||
import me.filoghost.holographicdisplays.core.nms.PacketController;
|
||||
import me.filoghost.holographicdisplays.core.nms.SpawnFailedException;
|
||||
import me.filoghost.holographicdisplays.core.nms.StringCustomNameEditor;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntity;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import net.minecraft.server.v1_11_R1.Entity;
|
||||
import net.minecraft.server.v1_11_R1.EntityTypes;
|
||||
@ -36,7 +36,7 @@ public class VersionNMSManager implements NMSManager {
|
||||
private static final ReflectField<RegistryID<Class<? extends Entity>>> REGISTRY_ID_FIELD = ReflectField.lookup(new ClassToken<RegistryID<Class<? extends Entity>>>(){}, RegistryMaterials.class, "a");
|
||||
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 static final ReflectMethod<?> REGISTER_ENTITY_METHOD = ReflectMethod.lookup(Object.class, World.class, "b", Entity.class);
|
||||
|
||||
private final PacketController packetController;
|
||||
|
||||
@ -65,40 +65,34 @@ public class VersionNMSManager implements NMSManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, StandardItemLine parentPiece, ItemStack stack) {
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, StandardItemLine parentPiece, ItemStack stack) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece);
|
||||
customItem.setLocationNMS(x, y, z);
|
||||
customItem.setItemStackNMS(stack);
|
||||
if (!addEntityToWorld(nmsWorld, customItem)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return customItem;
|
||||
EntityNMSItem item = new EntityNMSItem(nmsWorld, parentPiece);
|
||||
item.setLocationNMS(x, y, z);
|
||||
item.setItemStackNMS(stack);
|
||||
addEntityToWorld(nmsWorld, item);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, StandardHologramLine parentPiece) {
|
||||
public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, StandardHologramLine parentPiece) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece);
|
||||
touchSlime.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, touchSlime)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return touchSlime;
|
||||
EntityNMSSlime slime = new EntityNMSSlime(nmsWorld, parentPiece);
|
||||
slime.setLocationNMS(x, y, z);
|
||||
addEntityToWorld(nmsWorld, slime);
|
||||
return slime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, StandardHologramLine parentPiece) {
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, StandardHologramLine parentPiece) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return invisibleArmorStand;
|
||||
EntityNMSArmorStand armorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
armorStand.setLocationNMS(x, y, z);
|
||||
addEntityToWorld(nmsWorld, armorStand);
|
||||
return armorStand;
|
||||
}
|
||||
|
||||
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) {
|
||||
private void addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) throws SpawnFailedException {
|
||||
Preconditions.checkState(Bukkit.isPrimaryThread(), "Async entity add");
|
||||
|
||||
final int chunkX = MathHelper.floor(nmsEntity.locX / 16.0);
|
||||
@ -107,51 +101,50 @@ public class VersionNMSManager implements NMSManager {
|
||||
if (!nmsWorld.getChunkProviderServer().isLoaded(chunkX, chunkZ)) {
|
||||
// This should never happen
|
||||
nmsEntity.dead = true;
|
||||
return false;
|
||||
throw new SpawnFailedException(SpawnFailedException.CHUNK_NOT_LOADED);
|
||||
}
|
||||
|
||||
nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity);
|
||||
nmsWorld.entityList.add(nmsEntity);
|
||||
|
||||
try {
|
||||
VALIDATE_ENTITY_METHOD.invoke(nmsWorld, nmsEntity);
|
||||
REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
nmsEntity.dead = true;
|
||||
throw new SpawnFailedException(SpawnFailedException.REGISTER_ENTITY_FAIL, e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase;
|
||||
return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
public NMSEntity getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle();
|
||||
|
||||
if (nmsEntity instanceof NMSEntityBase) {
|
||||
return ((NMSEntityBase) nmsEntity);
|
||||
if (nmsEntity instanceof NMSEntity) {
|
||||
return ((NMSEntity) nmsEntity);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) {
|
||||
public NMSEntity getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
Entity nmsEntity = nmsWorld.getEntity(entityID);
|
||||
|
||||
if (nmsEntity instanceof NMSEntityBase) {
|
||||
return ((NMSEntityBase) nmsEntity);
|
||||
if (nmsEntity instanceof NMSEntity) {
|
||||
return ((NMSEntity) nmsEntity);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomNameEditor getCustomNameChatComponentEditor() {
|
||||
public CustomNameEditor getCustomNameEditor() {
|
||||
return StringCustomNameEditor.INSTANCE;
|
||||
}
|
||||
|
||||
|
@ -33,52 +33,52 @@ public class CraftNMSArmorStand extends CraftArmorStand {
|
||||
|
||||
// Methods from Armor stand class
|
||||
|
||||
@Override public void setArms(boolean arms) { }
|
||||
@Override public void setBasePlate(boolean basePlate) { }
|
||||
@Override public void setBodyPose(EulerAngle pose) { }
|
||||
@Override public void setBoots(ItemStack item) { }
|
||||
@Override public void setChestplate(ItemStack item) { }
|
||||
@Override public void setHeadPose(EulerAngle pose) { }
|
||||
@Override public void setHelmet(ItemStack item) { }
|
||||
@Override public void setItemInHand(ItemStack item) { }
|
||||
@Override public void setLeftArmPose(EulerAngle pose) { }
|
||||
@Override public void setLeftLegPose(EulerAngle pose) { }
|
||||
@Override public void setLeggings(ItemStack item) { }
|
||||
@Override public void setRightArmPose(EulerAngle pose) { }
|
||||
@Override public void setRightLegPose(EulerAngle pose) { }
|
||||
@Override public void setSmall(boolean small) { }
|
||||
@Override public void setVisible(boolean visible) { }
|
||||
@Override public void setMarker(boolean marker) { }
|
||||
@Override public void setArms(boolean arms) {}
|
||||
@Override public void setBasePlate(boolean basePlate) {}
|
||||
@Override public void setBodyPose(EulerAngle pose) {}
|
||||
@Override public void setBoots(ItemStack item) {}
|
||||
@Override public void setChestplate(ItemStack item) {}
|
||||
@Override public void setHeadPose(EulerAngle pose) {}
|
||||
@Override public void setHelmet(ItemStack item) {}
|
||||
@Override public void setItemInHand(ItemStack item) {}
|
||||
@Override public void setLeftArmPose(EulerAngle pose) {}
|
||||
@Override public void setLeftLegPose(EulerAngle pose) {}
|
||||
@Override public void setLeggings(ItemStack item) {}
|
||||
@Override public void setRightArmPose(EulerAngle pose) {}
|
||||
@Override public void setRightLegPose(EulerAngle pose) {}
|
||||
@Override public void setSmall(boolean small) {}
|
||||
@Override public void setVisible(boolean visible) {}
|
||||
@Override public void setMarker(boolean marker) {}
|
||||
|
||||
// Methods from LivingEntity class
|
||||
@Override public boolean addPotionEffect(PotionEffect effect) { return false; }
|
||||
@Override public boolean addPotionEffect(PotionEffect effect, boolean param) { return false; }
|
||||
@Override public boolean addPotionEffects(Collection<PotionEffect> effects) { return false; }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) { }
|
||||
@Override public void setAI(boolean ai) { }
|
||||
@Override public void setCanPickupItems(boolean pickup) { }
|
||||
@Override public void setCollidable(boolean collidable) { }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) {}
|
||||
@Override public void setAI(boolean ai) {}
|
||||
@Override public void setCanPickupItems(boolean pickup) {}
|
||||
@Override public void setCollidable(boolean collidable) {}
|
||||
@Override public void setGliding(boolean gliding) { }
|
||||
@Override public boolean setLeashHolder(Entity holder) { return false; }
|
||||
|
||||
// Methods from Entity
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void setGlowing(boolean flag) { }
|
||||
@Override public void setGravity(boolean gravity) { }
|
||||
@Override public void setInvulnerable(boolean flag) { }
|
||||
@Override public void setMomentum(Vector value) { }
|
||||
@Override public void setSilent(boolean flag) { }
|
||||
@Override public void setTicksLived(int value) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
@Override public void setGlowing(boolean flag) {}
|
||||
@Override public void setGravity(boolean gravity) {}
|
||||
@Override public void setInvulnerable(boolean flag) {}
|
||||
@Override public void setMomentum(Vector value) {}
|
||||
@Override public void setSilent(boolean flag) {}
|
||||
@Override public void setTicksLived(int value) {}
|
||||
|
||||
}
|
||||
|
@ -28,27 +28,27 @@ public class CraftNMSItem extends CraftItem {
|
||||
}
|
||||
|
||||
// Methods from Entity
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void setGlowing(boolean flag) { }
|
||||
@Override public void setGravity(boolean gravity) { }
|
||||
@Override public void setInvulnerable(boolean flag) { }
|
||||
@Override public void setMomentum(Vector value) { }
|
||||
@Override public void setSilent(boolean flag) { }
|
||||
@Override public void setTicksLived(int value) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
@Override public void setGlowing(boolean flag) {}
|
||||
@Override public void setGravity(boolean gravity) {}
|
||||
@Override public void setInvulnerable(boolean flag) {}
|
||||
@Override public void setMomentum(Vector value) {}
|
||||
@Override public void setSilent(boolean flag) {}
|
||||
@Override public void setTicksLived(int value) {}
|
||||
|
||||
// Methods from Item
|
||||
@Override public void setItemStack(ItemStack stack) { }
|
||||
@Override public void setPickupDelay(int delay) { }
|
||||
@Override public void setItemStack(ItemStack stack) {}
|
||||
@Override public void setPickupDelay(int delay) {}
|
||||
|
||||
}
|
||||
|
@ -33,34 +33,34 @@ public class CraftNMSSlime extends CraftSlime {
|
||||
@Override public boolean addPotionEffect(PotionEffect effect) { return false; }
|
||||
@Override public boolean addPotionEffect(PotionEffect effect, boolean param) { return false; }
|
||||
@Override public boolean addPotionEffects(Collection<PotionEffect> effects) { return false; }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) { }
|
||||
@Override public void setAI(boolean ai) { }
|
||||
@Override public void setCanPickupItems(boolean pickup) { }
|
||||
@Override public void setCollidable(boolean collidable) { }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) {}
|
||||
@Override public void setAI(boolean ai) {}
|
||||
@Override public void setCanPickupItems(boolean pickup) {}
|
||||
@Override public void setCollidable(boolean collidable) {}
|
||||
@Override public void setGliding(boolean gliding) { }
|
||||
@Override public boolean setLeashHolder(Entity holder) { return false; }
|
||||
|
||||
// Methods from Entity
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void setGlowing(boolean flag) { }
|
||||
@Override public void setGravity(boolean gravity) { }
|
||||
@Override public void setInvulnerable(boolean flag) { }
|
||||
@Override public void setMomentum(Vector value) { }
|
||||
@Override public void setSilent(boolean flag) { }
|
||||
@Override public void setTicksLived(int value) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
@Override public void setGlowing(boolean flag) {}
|
||||
@Override public void setGravity(boolean gravity) {}
|
||||
@Override public void setInvulnerable(boolean flag) {}
|
||||
@Override public void setMomentum(Vector value) {}
|
||||
@Override public void setSilent(boolean flag) {}
|
||||
@Override public void setTicksLived(int value) {}
|
||||
|
||||
// Methods from Slime
|
||||
@Override public void setSize(int size) { }
|
||||
@Override public void setSize(int size) {}
|
||||
|
||||
}
|
||||
|
@ -5,12 +5,17 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.nms.v1_12_R1;
|
||||
|
||||
import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.Utils;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.PacketController;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntity;
|
||||
import net.minecraft.server.v1_12_R1.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_12_R1.DamageSource;
|
||||
import net.minecraft.server.v1_12_R1.Entity;
|
||||
import net.minecraft.server.v1_12_R1.EntityArmorStand;
|
||||
import net.minecraft.server.v1_12_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_12_R1.EntityPlayer;
|
||||
@ -27,12 +32,17 @@ import org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity;
|
||||
|
||||
public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand {
|
||||
|
||||
private final StandardHologramLine parentPiece;
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "au");
|
||||
|
||||
private final StandardHologramLine parentHologramLine;
|
||||
private final PacketController packetController;
|
||||
private String customName;
|
||||
|
||||
public EntityNMSArmorStand(World world, StandardHologramLine parentPiece, PacketController packetController) {
|
||||
public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, PacketController packetController) {
|
||||
super(world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
this.packetController = packetController;
|
||||
|
||||
super.setInvisible(true);
|
||||
super.setSmall(true);
|
||||
super.setArms(false);
|
||||
@ -40,11 +50,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
super.setBasePlate(true);
|
||||
super.setMarker(true);
|
||||
super.collides = false;
|
||||
|
||||
this.parentPiece = parentPiece;
|
||||
this.packetController = packetController;
|
||||
super.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -52,8 +59,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
// Disable normal ticking for this entity.
|
||||
|
||||
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
|
||||
if (this.onGround) {
|
||||
this.onGround = false;
|
||||
if (super.onGround) {
|
||||
super.onGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,8 +69,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
// Disable normal ticking for this entity.
|
||||
|
||||
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
|
||||
if (this.onGround) {
|
||||
this.onGround = false;
|
||||
if (super.onGround) {
|
||||
super.onGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,7 +151,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
|
||||
@Override
|
||||
public void a(AxisAlignedBB boundingBox) {
|
||||
// Do not change it!
|
||||
// Prevent bounding box from being changed
|
||||
}
|
||||
|
||||
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
|
||||
@ -202,9 +209,9 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
private void broadcastLocationPacketNMS() {
|
||||
PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this);
|
||||
|
||||
for (Object obj : super.world.players) {
|
||||
if (obj instanceof EntityPlayer) {
|
||||
EntityPlayer nmsPlayer = (EntityPlayer) obj;
|
||||
for (Object humanEntity : super.world.players) {
|
||||
if (humanEntity instanceof EntityPlayer) {
|
||||
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
|
||||
|
||||
double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ);
|
||||
if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) {
|
||||
@ -214,6 +221,21 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerNMS(NMSEntity passenger) {
|
||||
Preconditions.checkArgument(passenger instanceof Entity);
|
||||
Entity passengerEntity = (Entity) passenger;
|
||||
Preconditions.checkArgument(passengerEntity.bJ() == null);
|
||||
Preconditions.checkState(super.passengers.isEmpty());
|
||||
|
||||
try {
|
||||
VEHICLE_FIELD.set(passenger, this);
|
||||
this.passengers.add(this);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
DebugLogger.cannotSetPassenger(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDeadNMS() {
|
||||
return super.dead;
|
||||
@ -226,11 +248,12 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getBukkitEntityNMS() {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,16 +5,12 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.nms.v1_12_R1;
|
||||
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSCommons;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardItemLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSCommons;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import net.minecraft.server.v1_12_R1.Blocks;
|
||||
import net.minecraft.server.v1_12_R1.DamageSource;
|
||||
import net.minecraft.server.v1_12_R1.Entity;
|
||||
import net.minecraft.server.v1_12_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_12_R1.EntityItem;
|
||||
import net.minecraft.server.v1_12_R1.EntityPlayer;
|
||||
@ -28,14 +24,13 @@ import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack;
|
||||
|
||||
public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "au");
|
||||
private final StandardItemLine parentHologramLine;
|
||||
|
||||
private final StandardItemLine parentPiece;
|
||||
|
||||
public EntityNMSItem(World world, StandardItemLine piece) {
|
||||
public EntityNMSItem(World world, StandardItemLine parentHologramLine) {
|
||||
super(world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
|
||||
super.pickupDelay = 32767; // Lock the item pickup delay, also prevents entities from picking up the item
|
||||
this.parentPiece = piece;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -63,7 +58,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
}
|
||||
|
||||
if (human instanceof EntityPlayer) {
|
||||
parentPiece.onPickup(((EntityPlayer) human).getBukkitEntity());
|
||||
parentHologramLine.onPickup(((EntityPlayer) human).getBukkitEntity());
|
||||
// It is never added to the inventory.
|
||||
}
|
||||
}
|
||||
@ -153,7 +148,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
|
||||
@Override
|
||||
public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) {
|
||||
ItemStack newItem = CraftItemStack.asNMSCopy(stack); // ItemStack.a is returned if the stack is null, invalid or the material is not an Item
|
||||
ItemStack newItem = CraftItemStack.asNMSCopy(stack); // ItemStack.a is returned if the stack is not valid
|
||||
|
||||
if (newItem == null || newItem == ItemStack.a) {
|
||||
newItem = new ItemStack(Blocks.BEDROCK);
|
||||
@ -168,10 +163,10 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
}
|
||||
|
||||
NBTTagList tagList = new NBTTagList();
|
||||
tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE)); // Antistack lore
|
||||
tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE));
|
||||
display.set("Lore", tagList);
|
||||
|
||||
setItemStack(newItem);
|
||||
super.setItemStack(newItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -181,41 +176,17 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getBukkitEntityNMS() {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerOfNMS(NMSEntityBase vehicleBase) {
|
||||
if (!(vehicleBase instanceof Entity)) {
|
||||
// It should never dismount
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = (Entity) vehicleBase;
|
||||
|
||||
try {
|
||||
Entity oldVehicle = super.bJ();
|
||||
if (oldVehicle != null) {
|
||||
VEHICLE_FIELD.set(this, null);
|
||||
oldVehicle.passengers.remove(this);
|
||||
}
|
||||
|
||||
VEHICLE_FIELD.set(this, entity);
|
||||
entity.passengers.clear();
|
||||
entity.passengers.add(this);
|
||||
|
||||
} catch (Throwable t) {
|
||||
DebugLogger.cannotSetPassenger(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getRawItemStack() {
|
||||
return super.getItemStack();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,13 +6,9 @@
|
||||
package me.filoghost.holographicdisplays.nms.v1_12_R1;
|
||||
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSSlime;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import net.minecraft.server.v1_12_R1.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_12_R1.DamageSource;
|
||||
import net.minecraft.server.v1_12_R1.Entity;
|
||||
import net.minecraft.server.v1_12_R1.EntityDamageSource;
|
||||
import net.minecraft.server.v1_12_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_12_R1.EntitySlime;
|
||||
@ -25,18 +21,17 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
|
||||
public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "au");
|
||||
|
||||
private final StandardHologramLine parentPiece;
|
||||
private final StandardHologramLine parentHologramLine;
|
||||
|
||||
public EntityNMSSlime(World world, StandardHologramLine parentPiece) {
|
||||
public EntityNMSSlime(World world, StandardHologramLine parentHologramLine) {
|
||||
super(world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
|
||||
super.persistent = true;
|
||||
super.collides = false;
|
||||
a(0.0F, 0.0F);
|
||||
setSize(1, false);
|
||||
setInvisible(true);
|
||||
this.parentPiece = parentPiece;
|
||||
super.a(0.0F, 0.0F);
|
||||
super.setSize(1, false);
|
||||
super.setInvisible(true);
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
}
|
||||
|
||||
@ -58,7 +53,7 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
|
||||
@Override
|
||||
public void a(AxisAlignedBB boundingBox) {
|
||||
// Do not change it!
|
||||
// Prevent bounding box from being changed
|
||||
}
|
||||
|
||||
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
|
||||
@ -174,36 +169,12 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getBukkitEntityNMS() {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerOfNMS(NMSEntityBase vehicleBase) {
|
||||
if (!(vehicleBase instanceof Entity)) {
|
||||
// It should never dismount
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = (Entity) vehicleBase;
|
||||
|
||||
try {
|
||||
Entity oldVehicle = super.bJ();
|
||||
if (oldVehicle != null) {
|
||||
VEHICLE_FIELD.set(this, null);
|
||||
oldVehicle.passengers.remove(this);
|
||||
}
|
||||
|
||||
VEHICLE_FIELD.set(this, entity);
|
||||
entity.passengers.clear();
|
||||
entity.passengers.add(this);
|
||||
|
||||
} catch (Throwable t) {
|
||||
DebugLogger.cannotSetPassenger(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -125,8 +125,5 @@ public class NullBoundingBox extends AxisAlignedBB {
|
||||
public boolean e(Vec3D arg0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -9,15 +9,15 @@ import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.fcommons.reflection.ClassToken;
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.fcommons.reflection.ReflectMethod;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardItemLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.CustomNameEditor;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSManager;
|
||||
import me.filoghost.holographicdisplays.core.nms.PacketController;
|
||||
import me.filoghost.holographicdisplays.core.nms.SpawnFailedException;
|
||||
import me.filoghost.holographicdisplays.core.nms.StringCustomNameEditor;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntity;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import net.minecraft.server.v1_12_R1.Entity;
|
||||
import net.minecraft.server.v1_12_R1.EntityTypes;
|
||||
@ -36,7 +36,7 @@ public class VersionNMSManager implements NMSManager {
|
||||
private static final ReflectField<RegistryID<Class<? extends Entity>>> REGISTRY_ID_FIELD = ReflectField.lookup(new ClassToken<RegistryID<Class<? extends Entity>>>(){}, RegistryMaterials.class, "a");
|
||||
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 static final ReflectMethod<?> REGISTER_ENTITY_METHOD = ReflectMethod.lookup(Object.class, World.class, "b", Entity.class);
|
||||
|
||||
private final PacketController packetController;
|
||||
|
||||
@ -65,40 +65,34 @@ public class VersionNMSManager implements NMSManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, StandardItemLine parentPiece, ItemStack stack) {
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, StandardItemLine parentPiece, ItemStack stack) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece);
|
||||
customItem.setLocationNMS(x, y, z);
|
||||
customItem.setItemStackNMS(stack);
|
||||
if (!addEntityToWorld(nmsWorld, customItem)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return customItem;
|
||||
EntityNMSItem item = new EntityNMSItem(nmsWorld, parentPiece);
|
||||
item.setLocationNMS(x, y, z);
|
||||
item.setItemStackNMS(stack);
|
||||
addEntityToWorld(nmsWorld, item);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, StandardHologramLine parentPiece) {
|
||||
public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, StandardHologramLine parentPiece) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece);
|
||||
touchSlime.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, touchSlime)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return touchSlime;
|
||||
EntityNMSSlime slime = new EntityNMSSlime(nmsWorld, parentPiece);
|
||||
slime.setLocationNMS(x, y, z);
|
||||
addEntityToWorld(nmsWorld, slime);
|
||||
return slime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, StandardHologramLine parentPiece) {
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, StandardHologramLine parentPiece) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return invisibleArmorStand;
|
||||
EntityNMSArmorStand armorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
armorStand.setLocationNMS(x, y, z);
|
||||
addEntityToWorld(nmsWorld, armorStand);
|
||||
return armorStand;
|
||||
}
|
||||
|
||||
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) {
|
||||
private void addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) throws SpawnFailedException {
|
||||
Preconditions.checkState(Bukkit.isPrimaryThread(), "Async entity add");
|
||||
|
||||
final int chunkX = MathHelper.floor(nmsEntity.locX / 16.0);
|
||||
@ -107,51 +101,50 @@ public class VersionNMSManager implements NMSManager {
|
||||
if (!nmsWorld.getChunkProviderServer().isLoaded(chunkX, chunkZ)) {
|
||||
// This should never happen
|
||||
nmsEntity.dead = true;
|
||||
return false;
|
||||
throw new SpawnFailedException(SpawnFailedException.CHUNK_NOT_LOADED);
|
||||
}
|
||||
|
||||
nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity);
|
||||
nmsWorld.entityList.add(nmsEntity);
|
||||
|
||||
try {
|
||||
VALIDATE_ENTITY_METHOD.invoke(nmsWorld, nmsEntity);
|
||||
REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
nmsEntity.dead = true;
|
||||
throw new SpawnFailedException(SpawnFailedException.REGISTER_ENTITY_FAIL, e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase;
|
||||
return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
public NMSEntity getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle();
|
||||
|
||||
if (nmsEntity instanceof NMSEntityBase) {
|
||||
return ((NMSEntityBase) nmsEntity);
|
||||
if (nmsEntity instanceof NMSEntity) {
|
||||
return ((NMSEntity) nmsEntity);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) {
|
||||
public NMSEntity getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
Entity nmsEntity = nmsWorld.getEntity(entityID);
|
||||
|
||||
if (nmsEntity instanceof NMSEntityBase) {
|
||||
return ((NMSEntityBase) nmsEntity);
|
||||
if (nmsEntity instanceof NMSEntity) {
|
||||
return ((NMSEntity) nmsEntity);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomNameEditor getCustomNameChatComponentEditor() {
|
||||
public CustomNameEditor getCustomNameEditor() {
|
||||
return StringCustomNameEditor.INSTANCE;
|
||||
}
|
||||
|
||||
|
@ -33,54 +33,54 @@ public class CraftNMSArmorStand extends CraftArmorStand {
|
||||
|
||||
// Methods from Armor stand class
|
||||
|
||||
@Override public void setArms(boolean arms) { }
|
||||
@Override public void setBasePlate(boolean basePlate) { }
|
||||
@Override public void setBodyPose(EulerAngle pose) { }
|
||||
@Override public void setBoots(ItemStack item) { }
|
||||
@Override public void setChestplate(ItemStack item) { }
|
||||
@Override public void setHeadPose(EulerAngle pose) { }
|
||||
@Override public void setHelmet(ItemStack item) { }
|
||||
@Override public void setItemInHand(ItemStack item) { }
|
||||
@Override public void setLeftArmPose(EulerAngle pose) { }
|
||||
@Override public void setLeftLegPose(EulerAngle pose) { }
|
||||
@Override public void setLeggings(ItemStack item) { }
|
||||
@Override public void setRightArmPose(EulerAngle pose) { }
|
||||
@Override public void setRightLegPose(EulerAngle pose) { }
|
||||
@Override public void setSmall(boolean small) { }
|
||||
@Override public void setVisible(boolean visible) { }
|
||||
@Override public void setMarker(boolean marker) { }
|
||||
@Override public void setArms(boolean arms) {}
|
||||
@Override public void setBasePlate(boolean basePlate) {}
|
||||
@Override public void setBodyPose(EulerAngle pose) {}
|
||||
@Override public void setBoots(ItemStack item) {}
|
||||
@Override public void setChestplate(ItemStack item) {}
|
||||
@Override public void setHeadPose(EulerAngle pose) {}
|
||||
@Override public void setHelmet(ItemStack item) {}
|
||||
@Override public void setItemInHand(ItemStack item) {}
|
||||
@Override public void setLeftArmPose(EulerAngle pose) {}
|
||||
@Override public void setLeftLegPose(EulerAngle pose) {}
|
||||
@Override public void setLeggings(ItemStack item) {}
|
||||
@Override public void setRightArmPose(EulerAngle pose) {}
|
||||
@Override public void setRightLegPose(EulerAngle pose) {}
|
||||
@Override public void setSmall(boolean small) {}
|
||||
@Override public void setVisible(boolean visible) {}
|
||||
@Override public void setMarker(boolean marker) {}
|
||||
|
||||
// Methods from LivingEntity class
|
||||
@Override public boolean addPotionEffect(PotionEffect effect) { return false; }
|
||||
@Override public boolean addPotionEffect(PotionEffect effect, boolean param) { return false; }
|
||||
@Override public boolean addPotionEffects(Collection<PotionEffect> effects) { return false; }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) { }
|
||||
@Override public void setAI(boolean ai) { }
|
||||
@Override public void setCanPickupItems(boolean pickup) { }
|
||||
@Override public void setCollidable(boolean collidable) { }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) {}
|
||||
@Override public void setAI(boolean ai) {}
|
||||
@Override public void setCanPickupItems(boolean pickup) {}
|
||||
@Override public void setCollidable(boolean collidable) {}
|
||||
@Override public void setGliding(boolean gliding) { }
|
||||
@Override public boolean setLeashHolder(Entity holder) { return false; }
|
||||
@Override public void setSwimming(boolean swimming) { }
|
||||
@Override public void setSwimming(boolean swimming) {}
|
||||
|
||||
// Methods from Entity
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void setGlowing(boolean flag) { }
|
||||
@Override public void setGravity(boolean gravity) { }
|
||||
@Override public void setInvulnerable(boolean flag) { }
|
||||
@Override public void setMomentum(Vector value) { }
|
||||
@Override public void setSilent(boolean flag) { }
|
||||
@Override public void setTicksLived(int value) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
@Override public void setGlowing(boolean flag) {}
|
||||
@Override public void setGravity(boolean gravity) {}
|
||||
@Override public void setInvulnerable(boolean flag) {}
|
||||
@Override public void setMomentum(Vector value) {}
|
||||
@Override public void setSilent(boolean flag) {}
|
||||
@Override public void setTicksLived(int value) {}
|
||||
|
||||
|
||||
}
|
||||
|
@ -28,27 +28,27 @@ public class CraftNMSItem extends CraftItem {
|
||||
}
|
||||
|
||||
// Methods from Entity
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void setGlowing(boolean flag) { }
|
||||
@Override public void setGravity(boolean gravity) { }
|
||||
@Override public void setInvulnerable(boolean flag) { }
|
||||
@Override public void setMomentum(Vector value) { }
|
||||
@Override public void setSilent(boolean flag) { }
|
||||
@Override public void setTicksLived(int value) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
@Override public void setGlowing(boolean flag) {}
|
||||
@Override public void setGravity(boolean gravity) {}
|
||||
@Override public void setInvulnerable(boolean flag) {}
|
||||
@Override public void setMomentum(Vector value) {}
|
||||
@Override public void setSilent(boolean flag) {}
|
||||
@Override public void setTicksLived(int value) {}
|
||||
|
||||
// Methods from Item
|
||||
@Override public void setItemStack(ItemStack stack) { }
|
||||
@Override public void setPickupDelay(int delay) { }
|
||||
@Override public void setItemStack(ItemStack stack) {}
|
||||
@Override public void setPickupDelay(int delay) {}
|
||||
|
||||
}
|
||||
|
@ -34,37 +34,37 @@ public class CraftNMSSlime extends CraftSlime {
|
||||
@Override public boolean addPotionEffect(PotionEffect effect) { return false; }
|
||||
@Override public boolean addPotionEffect(PotionEffect effect, boolean param) { return false; }
|
||||
@Override public boolean addPotionEffects(Collection<PotionEffect> effects) { return false; }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) { }
|
||||
@Override public void setAI(boolean ai) { }
|
||||
@Override public void setCanPickupItems(boolean pickup) { }
|
||||
@Override public void setCollidable(boolean collidable) { }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) {}
|
||||
@Override public void setAI(boolean ai) {}
|
||||
@Override public void setCanPickupItems(boolean pickup) {}
|
||||
@Override public void setCollidable(boolean collidable) {}
|
||||
@Override public void setGliding(boolean gliding) { }
|
||||
@Override public boolean setLeashHolder(Entity holder) { return false; }
|
||||
@Override public void setSwimming(boolean swimming) { }
|
||||
@Override public void setSwimming(boolean swimming) {}
|
||||
|
||||
// Methods from Entity
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void setGlowing(boolean flag) { }
|
||||
@Override public void setGravity(boolean gravity) { }
|
||||
@Override public void setInvulnerable(boolean flag) { }
|
||||
@Override public void setMomentum(Vector value) { }
|
||||
@Override public void setSilent(boolean flag) { }
|
||||
@Override public void setTicksLived(int value) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
@Override public void setGlowing(boolean flag) {}
|
||||
@Override public void setGravity(boolean gravity) {}
|
||||
@Override public void setInvulnerable(boolean flag) {}
|
||||
@Override public void setMomentum(Vector value) {}
|
||||
@Override public void setSilent(boolean flag) {}
|
||||
@Override public void setTicksLived(int value) {}
|
||||
|
||||
|
||||
// Methods from Slime
|
||||
@Override public void setSize(int size) { }
|
||||
@Override public void setTarget(LivingEntity target) { }
|
||||
@Override public void setSize(int size) {}
|
||||
@Override public void setTarget(LivingEntity target) {}
|
||||
|
||||
}
|
||||
|
@ -5,12 +5,17 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.nms.v1_13_R1;
|
||||
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.Utils;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.PacketController;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntity;
|
||||
import net.minecraft.server.v1_13_R1.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_13_R1.DamageSource;
|
||||
import net.minecraft.server.v1_13_R1.Entity;
|
||||
import net.minecraft.server.v1_13_R1.EntityArmorStand;
|
||||
import net.minecraft.server.v1_13_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_13_R1.EntityPlayer;
|
||||
@ -29,12 +34,17 @@ import org.bukkit.craftbukkit.v1_13_R1.util.CraftChatMessage;
|
||||
|
||||
public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand {
|
||||
|
||||
private final StandardHologramLine parentPiece;
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "ax");
|
||||
|
||||
private final StandardHologramLine parentHologramLine;
|
||||
private final PacketController packetController;
|
||||
private String customName;
|
||||
|
||||
public EntityNMSArmorStand(World world, StandardHologramLine parentPiece, PacketController packetController) {
|
||||
public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, PacketController packetController) {
|
||||
super(world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
this.packetController = packetController;
|
||||
|
||||
super.setInvisible(true);
|
||||
super.setSmall(true);
|
||||
super.setArms(false);
|
||||
@ -42,11 +52,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
super.setBasePlate(true);
|
||||
super.setMarker(true);
|
||||
super.collides = false;
|
||||
|
||||
this.parentPiece = parentPiece;
|
||||
this.packetController = packetController;
|
||||
super.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -54,8 +61,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
// Disable normal ticking for this entity.
|
||||
|
||||
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
|
||||
if (this.onGround) {
|
||||
this.onGround = false;
|
||||
if (super.onGround) {
|
||||
super.onGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,8 +71,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
// Disable normal ticking for this entity.
|
||||
|
||||
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
|
||||
if (this.onGround) {
|
||||
this.onGround = false;
|
||||
if (super.onGround) {
|
||||
super.onGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,7 +153,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
|
||||
@Override
|
||||
public void a(AxisAlignedBB boundingBox) {
|
||||
// Do not change it!
|
||||
// Prevent bounding box from being changed
|
||||
}
|
||||
|
||||
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
|
||||
@ -204,9 +211,9 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
private void broadcastLocationPacketNMS() {
|
||||
PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this);
|
||||
|
||||
for (Object obj : super.world.players) {
|
||||
if (obj instanceof EntityPlayer) {
|
||||
EntityPlayer nmsPlayer = (EntityPlayer) obj;
|
||||
for (Object humanEntity : super.world.players) {
|
||||
if (humanEntity instanceof EntityPlayer) {
|
||||
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
|
||||
|
||||
double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ);
|
||||
if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) {
|
||||
@ -216,6 +223,21 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerNMS(NMSEntity passenger) {
|
||||
Preconditions.checkArgument(passenger instanceof Entity);
|
||||
Entity passengerEntity = (Entity) passenger;
|
||||
Preconditions.checkArgument(passengerEntity.getVehicle() == null);
|
||||
Preconditions.checkState(super.passengers.isEmpty());
|
||||
|
||||
try {
|
||||
VEHICLE_FIELD.set(passenger, this);
|
||||
this.passengers.add(this);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
DebugLogger.cannotSetPassenger(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDeadNMS() {
|
||||
return super.dead;
|
||||
@ -228,11 +250,12 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getBukkitEntityNMS() {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,16 +5,12 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.nms.v1_13_R1;
|
||||
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSCommons;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardItemLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSCommons;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import net.minecraft.server.v1_13_R1.Blocks;
|
||||
import net.minecraft.server.v1_13_R1.DamageSource;
|
||||
import net.minecraft.server.v1_13_R1.Entity;
|
||||
import net.minecraft.server.v1_13_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_13_R1.EntityItem;
|
||||
import net.minecraft.server.v1_13_R1.EntityPlayer;
|
||||
@ -28,14 +24,13 @@ import org.bukkit.craftbukkit.v1_13_R1.inventory.CraftItemStack;
|
||||
|
||||
public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "ax");
|
||||
private final StandardItemLine parentHologramLine;
|
||||
|
||||
private final StandardItemLine parentPiece;
|
||||
|
||||
public EntityNMSItem(World world, StandardItemLine piece) {
|
||||
public EntityNMSItem(World world, StandardItemLine parentHologramLine) {
|
||||
super(world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
|
||||
super.pickupDelay = 32767; // Lock the item pickup delay, also prevents entities from picking up the item
|
||||
this.parentPiece = piece;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -63,7 +58,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
}
|
||||
|
||||
if (human instanceof EntityPlayer) {
|
||||
parentPiece.onPickup(((EntityPlayer) human).getBukkitEntity());
|
||||
parentHologramLine.onPickup(((EntityPlayer) human).getBukkitEntity());
|
||||
// It is never added to the inventory.
|
||||
}
|
||||
}
|
||||
@ -153,7 +148,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
|
||||
@Override
|
||||
public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) {
|
||||
ItemStack newItem = CraftItemStack.asNMSCopy(stack); // ItemStack.a is returned if the stack is null, invalid or the material is not an Item
|
||||
ItemStack newItem = CraftItemStack.asNMSCopy(stack); // ItemStack.a is returned if the stack is not valid
|
||||
|
||||
if (newItem == null || newItem == ItemStack.a) {
|
||||
newItem = new ItemStack(Blocks.BEDROCK);
|
||||
@ -168,10 +163,10 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
}
|
||||
|
||||
NBTTagList tagList = new NBTTagList();
|
||||
tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE)); // Antistack lore
|
||||
tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE));
|
||||
display.set("Lore", tagList);
|
||||
|
||||
setItemStack(newItem);
|
||||
super.setItemStack(newItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -181,41 +176,17 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getBukkitEntityNMS() {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerOfNMS(NMSEntityBase vehicleBase) {
|
||||
if (!(vehicleBase instanceof Entity)) {
|
||||
// It should never dismount
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = (Entity) vehicleBase;
|
||||
|
||||
try {
|
||||
if (super.getVehicle() != null) {
|
||||
Entity oldVehicle = super.getVehicle();
|
||||
VEHICLE_FIELD.set(this, null);
|
||||
oldVehicle.passengers.remove(this);
|
||||
}
|
||||
|
||||
VEHICLE_FIELD.set(this, entity);
|
||||
entity.passengers.clear();
|
||||
entity.passengers.add(this);
|
||||
|
||||
} catch (Throwable t) {
|
||||
DebugLogger.cannotSetPassenger(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getRawItemStack() {
|
||||
return super.getItemStack();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,13 +6,9 @@
|
||||
package me.filoghost.holographicdisplays.nms.v1_13_R1;
|
||||
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSSlime;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import net.minecraft.server.v1_13_R1.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_13_R1.DamageSource;
|
||||
import net.minecraft.server.v1_13_R1.Entity;
|
||||
import net.minecraft.server.v1_13_R1.EntityDamageSource;
|
||||
import net.minecraft.server.v1_13_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_13_R1.EntitySlime;
|
||||
@ -26,18 +22,17 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
|
||||
public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "ax");
|
||||
private final StandardHologramLine parentHologramLine;
|
||||
|
||||
private final StandardHologramLine parentPiece;
|
||||
|
||||
public EntityNMSSlime(World world, StandardHologramLine parentPiece) {
|
||||
public EntityNMSSlime(World world, StandardHologramLine parentHologramLine) {
|
||||
super(world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
|
||||
super.persistent = true;
|
||||
super.collides = false;
|
||||
a(0.0F, 0.0F);
|
||||
setSize(1, false);
|
||||
setInvisible(true);
|
||||
this.parentPiece = parentPiece;
|
||||
super.a(0.0F, 0.0F);
|
||||
super.setSize(1, false);
|
||||
super.setInvisible(true);
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
}
|
||||
|
||||
@ -59,7 +54,7 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
|
||||
@Override
|
||||
public void a(AxisAlignedBB boundingBox) {
|
||||
// Do not change it!
|
||||
// Prevent bounding box from being changed
|
||||
}
|
||||
|
||||
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
|
||||
@ -175,36 +170,12 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getBukkitEntityNMS() {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerOfNMS(NMSEntityBase vehicleBase) {
|
||||
if (!(vehicleBase instanceof Entity)) {
|
||||
// It should never dismount
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = (Entity) vehicleBase;
|
||||
|
||||
try {
|
||||
if (super.getVehicle() != null) {
|
||||
Entity oldVehicle = super.getVehicle();
|
||||
VEHICLE_FIELD.set(this, null);
|
||||
oldVehicle.passengers.remove(this);
|
||||
}
|
||||
|
||||
VEHICLE_FIELD.set(this, entity);
|
||||
entity.passengers.clear();
|
||||
entity.passengers.add(this);
|
||||
|
||||
} catch (Throwable t) {
|
||||
DebugLogger.cannotSetPassenger(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -116,8 +116,5 @@ public class NullBoundingBox extends AxisAlignedBB {
|
||||
public AxisAlignedBB f(double arg0, double arg1, double arg2) {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -9,17 +9,17 @@ import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.fcommons.reflection.ClassToken;
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.fcommons.reflection.ReflectMethod;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.nms.CustomNameEditor;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardItemLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.ChatComponentCustomNameEditor;
|
||||
import me.filoghost.holographicdisplays.core.nms.CustomNameEditor;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSCommons;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSManager;
|
||||
import me.filoghost.holographicdisplays.core.nms.PacketController;
|
||||
import me.filoghost.holographicdisplays.core.nms.SpawnFailedException;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntity;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardItemLine;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import net.minecraft.server.v1_13_R1.ChatComponentText;
|
||||
import net.minecraft.server.v1_13_R1.Entity;
|
||||
import net.minecraft.server.v1_13_R1.EntityTypes;
|
||||
@ -42,7 +42,7 @@ public class VersionNMSManager implements NMSManager {
|
||||
private static final ReflectField<Object[]> ID_TO_CLASS_MAP_FIELD = ReflectField.lookup(Object[].class, RegistryID.class, "d");
|
||||
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 static final ReflectMethod<?> REGISTER_ENTITY_METHOD = ReflectMethod.lookup(Object.class, World.class, "b", Entity.class);
|
||||
|
||||
private final PacketController packetController;
|
||||
|
||||
@ -71,40 +71,34 @@ public class VersionNMSManager implements NMSManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, StandardItemLine parentPiece, ItemStack stack) {
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, StandardItemLine parentPiece, ItemStack stack) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece);
|
||||
customItem.setLocationNMS(x, y, z);
|
||||
customItem.setItemStackNMS(stack);
|
||||
if (!addEntityToWorld(nmsWorld, customItem)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return customItem;
|
||||
EntityNMSItem item = new EntityNMSItem(nmsWorld, parentPiece);
|
||||
item.setLocationNMS(x, y, z);
|
||||
item.setItemStackNMS(stack);
|
||||
addEntityToWorld(nmsWorld, item);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, StandardHologramLine parentPiece) {
|
||||
public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, StandardHologramLine parentPiece) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece);
|
||||
touchSlime.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, touchSlime)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return touchSlime;
|
||||
EntityNMSSlime slime = new EntityNMSSlime(nmsWorld, parentPiece);
|
||||
slime.setLocationNMS(x, y, z);
|
||||
addEntityToWorld(nmsWorld, slime);
|
||||
return slime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, StandardHologramLine parentPiece) {
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, StandardHologramLine parentPiece) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return invisibleArmorStand;
|
||||
EntityNMSArmorStand armorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
armorStand.setLocationNMS(x, y, z);
|
||||
addEntityToWorld(nmsWorld, armorStand);
|
||||
return armorStand;
|
||||
}
|
||||
|
||||
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) {
|
||||
private void addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) throws SpawnFailedException {
|
||||
Preconditions.checkState(Bukkit.isPrimaryThread(), "Async entity add");
|
||||
|
||||
final int chunkX = MathHelper.floor(nmsEntity.locX / 16.0);
|
||||
@ -113,61 +107,60 @@ public class VersionNMSManager implements NMSManager {
|
||||
if (!nmsWorld.getChunkProviderServer().isLoaded(chunkX, chunkZ)) {
|
||||
// This should never happen
|
||||
nmsEntity.dead = true;
|
||||
return false;
|
||||
throw new SpawnFailedException(SpawnFailedException.CHUNK_NOT_LOADED);
|
||||
}
|
||||
|
||||
nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity);
|
||||
if (NMSCommons.isPaperServer()) {
|
||||
if (NMSCommons.IS_PAPER_SERVER) {
|
||||
try {
|
||||
// Workaround because nmsWorld.entityList is a different class in Paper, if used without reflection it throws NoSuchFieldError.
|
||||
ENTITY_LIST_FIELD.get(nmsWorld).add(nmsEntity);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
throw new SpawnFailedException(SpawnFailedException.CHUNK_NOT_LOADED);
|
||||
}
|
||||
} else {
|
||||
nmsWorld.entityList.add(nmsEntity);
|
||||
}
|
||||
|
||||
try {
|
||||
VALIDATE_ENTITY_METHOD.invoke(nmsWorld, nmsEntity);
|
||||
REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
nmsEntity.dead = true;
|
||||
throw new SpawnFailedException(SpawnFailedException.REGISTER_ENTITY_FAIL, e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase;
|
||||
return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
public NMSEntity getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle();
|
||||
|
||||
if (nmsEntity instanceof NMSEntityBase) {
|
||||
return ((NMSEntityBase) nmsEntity);
|
||||
if (nmsEntity instanceof NMSEntity) {
|
||||
return ((NMSEntity) nmsEntity);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) {
|
||||
public NMSEntity getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
Entity nmsEntity = nmsWorld.getEntity(entityID);
|
||||
|
||||
if (nmsEntity instanceof NMSEntityBase) {
|
||||
return ((NMSEntityBase) nmsEntity);
|
||||
if (nmsEntity instanceof NMSEntity) {
|
||||
return ((NMSEntity) nmsEntity);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomNameEditor getCustomNameChatComponentEditor() {
|
||||
public CustomNameEditor getCustomNameEditor() {
|
||||
return VersionChatComponentCustomNameEditor.INSTANCE;
|
||||
}
|
||||
|
||||
|
@ -33,55 +33,55 @@ public class CraftNMSArmorStand extends CraftArmorStand {
|
||||
|
||||
// Methods from Armor stand class
|
||||
|
||||
@Override public void setArms(boolean arms) { }
|
||||
@Override public void setBasePlate(boolean basePlate) { }
|
||||
@Override public void setBodyPose(EulerAngle pose) { }
|
||||
@Override public void setBoots(ItemStack item) { }
|
||||
@Override public void setChestplate(ItemStack item) { }
|
||||
@Override public void setHeadPose(EulerAngle pose) { }
|
||||
@Override public void setHelmet(ItemStack item) { }
|
||||
@Override public void setItemInHand(ItemStack item) { }
|
||||
@Override public void setLeftArmPose(EulerAngle pose) { }
|
||||
@Override public void setLeftLegPose(EulerAngle pose) { }
|
||||
@Override public void setLeggings(ItemStack item) { }
|
||||
@Override public void setRightArmPose(EulerAngle pose) { }
|
||||
@Override public void setRightLegPose(EulerAngle pose) { }
|
||||
@Override public void setSmall(boolean small) { }
|
||||
@Override public void setVisible(boolean visible) { }
|
||||
@Override public void setMarker(boolean marker) { }
|
||||
@Override public void setArms(boolean arms) {}
|
||||
@Override public void setBasePlate(boolean basePlate) {}
|
||||
@Override public void setBodyPose(EulerAngle pose) {}
|
||||
@Override public void setBoots(ItemStack item) {}
|
||||
@Override public void setChestplate(ItemStack item) {}
|
||||
@Override public void setHeadPose(EulerAngle pose) {}
|
||||
@Override public void setHelmet(ItemStack item) {}
|
||||
@Override public void setItemInHand(ItemStack item) {}
|
||||
@Override public void setLeftArmPose(EulerAngle pose) {}
|
||||
@Override public void setLeftLegPose(EulerAngle pose) {}
|
||||
@Override public void setLeggings(ItemStack item) {}
|
||||
@Override public void setRightArmPose(EulerAngle pose) {}
|
||||
@Override public void setRightLegPose(EulerAngle pose) {}
|
||||
@Override public void setSmall(boolean small) {}
|
||||
@Override public void setVisible(boolean visible) {}
|
||||
@Override public void setMarker(boolean marker) {}
|
||||
|
||||
// Methods from LivingEntity class
|
||||
@Override public boolean addPotionEffect(PotionEffect effect) { return false; }
|
||||
@Override public boolean addPotionEffect(PotionEffect effect, boolean param) { return false; }
|
||||
@Override public boolean addPotionEffects(Collection<PotionEffect> effects) { return false; }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) { }
|
||||
@Override public void setAI(boolean ai) { }
|
||||
@Override public void setCanPickupItems(boolean pickup) { }
|
||||
@Override public void setCollidable(boolean collidable) { }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) {}
|
||||
@Override public void setAI(boolean ai) {}
|
||||
@Override public void setCanPickupItems(boolean pickup) {}
|
||||
@Override public void setCollidable(boolean collidable) {}
|
||||
@Override public void setGliding(boolean gliding) { }
|
||||
@Override public boolean setLeashHolder(Entity holder) { return false; }
|
||||
@Override public void setSwimming(boolean swimming) { }
|
||||
@Override public void setSwimming(boolean swimming) {}
|
||||
|
||||
// Methods from Entity
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void setGlowing(boolean flag) { }
|
||||
@Override public void setGravity(boolean gravity) { }
|
||||
@Override public void setInvulnerable(boolean flag) { }
|
||||
@Override public void setMomentum(Vector value) { }
|
||||
@Override public void setSilent(boolean flag) { }
|
||||
@Override public void setTicksLived(int value) { }
|
||||
@Override public void setPersistent(boolean flag) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
@Override public void setGlowing(boolean flag) {}
|
||||
@Override public void setGravity(boolean gravity) {}
|
||||
@Override public void setInvulnerable(boolean flag) {}
|
||||
@Override public void setMomentum(Vector value) {}
|
||||
@Override public void setSilent(boolean flag) {}
|
||||
@Override public void setTicksLived(int value) {}
|
||||
@Override public void setPersistent(boolean flag) {}
|
||||
|
||||
|
||||
}
|
||||
|
@ -28,28 +28,28 @@ public class CraftNMSItem extends CraftItem {
|
||||
}
|
||||
|
||||
// Methods from Entity
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void setGlowing(boolean flag) { }
|
||||
@Override public void setGravity(boolean gravity) { }
|
||||
@Override public void setInvulnerable(boolean flag) { }
|
||||
@Override public void setMomentum(Vector value) { }
|
||||
@Override public void setSilent(boolean flag) { }
|
||||
@Override public void setTicksLived(int value) { }
|
||||
@Override public void setPersistent(boolean flag) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
@Override public void setGlowing(boolean flag) {}
|
||||
@Override public void setGravity(boolean gravity) {}
|
||||
@Override public void setInvulnerable(boolean flag) {}
|
||||
@Override public void setMomentum(Vector value) {}
|
||||
@Override public void setSilent(boolean flag) {}
|
||||
@Override public void setTicksLived(int value) {}
|
||||
@Override public void setPersistent(boolean flag) {}
|
||||
|
||||
// Methods from Item
|
||||
@Override public void setItemStack(ItemStack stack) { }
|
||||
@Override public void setPickupDelay(int delay) { }
|
||||
@Override public void setItemStack(ItemStack stack) {}
|
||||
@Override public void setPickupDelay(int delay) {}
|
||||
|
||||
}
|
||||
|
@ -35,41 +35,41 @@ public class CraftNMSSlime extends CraftSlime {
|
||||
@Override public boolean addPotionEffect(PotionEffect effect) { return false; }
|
||||
@Override public boolean addPotionEffect(PotionEffect effect, boolean param) { return false; }
|
||||
@Override public boolean addPotionEffects(Collection<PotionEffect> effects) { return false; }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) { }
|
||||
@Override public void setAI(boolean ai) { }
|
||||
@Override public void setCanPickupItems(boolean pickup) { }
|
||||
@Override public void setCollidable(boolean collidable) { }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) {}
|
||||
@Override public void setAI(boolean ai) {}
|
||||
@Override public void setCanPickupItems(boolean pickup) {}
|
||||
@Override public void setCollidable(boolean collidable) {}
|
||||
@Override public void setGliding(boolean gliding) { }
|
||||
@Override public boolean setLeashHolder(Entity holder) { return false; }
|
||||
@Override public void setSwimming(boolean swimming) { }
|
||||
@Override public void setSwimming(boolean swimming) {}
|
||||
|
||||
// Methods from Entity
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void setGlowing(boolean flag) { }
|
||||
@Override public void setGravity(boolean gravity) { }
|
||||
@Override public void setInvulnerable(boolean flag) { }
|
||||
@Override public void setMomentum(Vector value) { }
|
||||
@Override public void setSilent(boolean flag) { }
|
||||
@Override public void setTicksLived(int value) { }
|
||||
@Override public void setPersistent(boolean flag) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
@Override public void setGlowing(boolean flag) {}
|
||||
@Override public void setGravity(boolean gravity) {}
|
||||
@Override public void setInvulnerable(boolean flag) {}
|
||||
@Override public void setMomentum(Vector value) {}
|
||||
@Override public void setSilent(boolean flag) {}
|
||||
@Override public void setTicksLived(int value) {}
|
||||
@Override public void setPersistent(boolean flag) {}
|
||||
|
||||
// Methods from Mob
|
||||
@Override public void setLootTable(LootTable table) { }
|
||||
@Override public void setSeed(long seed) { }
|
||||
@Override public void setLootTable(LootTable table) {}
|
||||
@Override public void setSeed(long seed) {}
|
||||
|
||||
// Methods from Slime
|
||||
@Override public void setSize(int size) { }
|
||||
@Override public void setTarget(LivingEntity target) { }
|
||||
@Override public void setSize(int size) {}
|
||||
@Override public void setTarget(LivingEntity target) {}
|
||||
|
||||
}
|
||||
|
@ -5,12 +5,17 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.nms.v1_13_R2;
|
||||
|
||||
import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.Utils;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.PacketController;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntity;
|
||||
import net.minecraft.server.v1_13_R2.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_13_R2.DamageSource;
|
||||
import net.minecraft.server.v1_13_R2.Entity;
|
||||
import net.minecraft.server.v1_13_R2.EntityArmorStand;
|
||||
import net.minecraft.server.v1_13_R2.EntityHuman;
|
||||
import net.minecraft.server.v1_13_R2.EntityPlayer;
|
||||
@ -29,12 +34,17 @@ import org.bukkit.craftbukkit.v1_13_R2.util.CraftChatMessage;
|
||||
|
||||
public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand {
|
||||
|
||||
private final StandardHologramLine parentPiece;
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle");
|
||||
|
||||
private final StandardHologramLine parentHologramLine;
|
||||
private final PacketController packetController;
|
||||
private String customName;
|
||||
|
||||
public EntityNMSArmorStand(World world, StandardHologramLine parentPiece, PacketController packetController) {
|
||||
public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, PacketController packetController) {
|
||||
super(world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
this.packetController = packetController;
|
||||
|
||||
super.setInvisible(true);
|
||||
super.setSmall(true);
|
||||
super.setArms(false);
|
||||
@ -42,11 +52,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
super.setBasePlate(true);
|
||||
super.setMarker(true);
|
||||
super.collides = false;
|
||||
|
||||
this.parentPiece = parentPiece;
|
||||
this.packetController = packetController;
|
||||
super.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -54,8 +61,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
// Disable normal ticking for this entity.
|
||||
|
||||
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
|
||||
if (this.onGround) {
|
||||
this.onGround = false;
|
||||
if (super.onGround) {
|
||||
super.onGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,8 +71,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
// Disable normal ticking for this entity.
|
||||
|
||||
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
|
||||
if (this.onGround) {
|
||||
this.onGround = false;
|
||||
if (super.onGround) {
|
||||
super.onGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,7 +153,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
|
||||
@Override
|
||||
public void a(AxisAlignedBB boundingBox) {
|
||||
// Do not change it!
|
||||
// Prevent bounding box from being changed
|
||||
}
|
||||
|
||||
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
|
||||
@ -204,9 +211,9 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
private void broadcastLocationPacketNMS() {
|
||||
PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this);
|
||||
|
||||
for (Object obj : super.world.players) {
|
||||
if (obj instanceof EntityPlayer) {
|
||||
EntityPlayer nmsPlayer = (EntityPlayer) obj;
|
||||
for (Object humanEntity : super.world.players) {
|
||||
if (humanEntity instanceof EntityPlayer) {
|
||||
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
|
||||
|
||||
double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ);
|
||||
if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) {
|
||||
@ -216,6 +223,21 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerNMS(NMSEntity passenger) {
|
||||
Preconditions.checkArgument(passenger instanceof Entity);
|
||||
Entity passengerEntity = (Entity) passenger;
|
||||
Preconditions.checkArgument(passengerEntity.getVehicle() == null);
|
||||
Preconditions.checkState(super.passengers.isEmpty());
|
||||
|
||||
try {
|
||||
VEHICLE_FIELD.set(passenger, this);
|
||||
this.passengers.add(this);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
DebugLogger.cannotSetPassenger(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDeadNMS() {
|
||||
return super.dead;
|
||||
@ -228,11 +250,12 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getBukkitEntityNMS() {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,16 +5,12 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.nms.v1_13_R2;
|
||||
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSCommons;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardItemLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSCommons;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import net.minecraft.server.v1_13_R2.Blocks;
|
||||
import net.minecraft.server.v1_13_R2.DamageSource;
|
||||
import net.minecraft.server.v1_13_R2.Entity;
|
||||
import net.minecraft.server.v1_13_R2.EntityHuman;
|
||||
import net.minecraft.server.v1_13_R2.EntityItem;
|
||||
import net.minecraft.server.v1_13_R2.EntityPlayer;
|
||||
@ -28,14 +24,13 @@ import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack;
|
||||
|
||||
public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle");
|
||||
private final StandardItemLine parentHologramLine;
|
||||
|
||||
private final StandardItemLine parentPiece;
|
||||
|
||||
public EntityNMSItem(World world, StandardItemLine piece) {
|
||||
public EntityNMSItem(World world, StandardItemLine parentHologramLine) {
|
||||
super(world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
|
||||
super.pickupDelay = 32767; // Lock the item pickup delay, also prevents entities from picking up the item
|
||||
this.parentPiece = piece;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -63,7 +58,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
}
|
||||
|
||||
if (human instanceof EntityPlayer) {
|
||||
parentPiece.onPickup(((EntityPlayer) human).getBukkitEntity());
|
||||
parentHologramLine.onPickup(((EntityPlayer) human).getBukkitEntity());
|
||||
// It is never added to the inventory.
|
||||
}
|
||||
}
|
||||
@ -153,7 +148,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
|
||||
@Override
|
||||
public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) {
|
||||
ItemStack newItem = CraftItemStack.asNMSCopy(stack); // ItemStack.a is returned if the stack is null, invalid or the material is not an Item
|
||||
ItemStack newItem = CraftItemStack.asNMSCopy(stack); // ItemStack.a is returned if the stack is not valid
|
||||
|
||||
if (newItem == null || newItem == ItemStack.a) {
|
||||
newItem = new ItemStack(Blocks.BEDROCK);
|
||||
@ -168,10 +163,10 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
}
|
||||
|
||||
NBTTagList tagList = new NBTTagList();
|
||||
tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE)); // Antistack lore
|
||||
tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE));
|
||||
display.set("Lore", tagList);
|
||||
|
||||
setItemStack(newItem);
|
||||
super.setItemStack(newItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -181,41 +176,17 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getBukkitEntityNMS() {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerOfNMS(NMSEntityBase vehicleBase) {
|
||||
if (!(vehicleBase instanceof Entity)) {
|
||||
// It should never dismount
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = (Entity) vehicleBase;
|
||||
|
||||
try {
|
||||
if (super.getVehicle() != null) {
|
||||
Entity oldVehicle = super.getVehicle();
|
||||
VEHICLE_FIELD.set(this, null);
|
||||
oldVehicle.passengers.remove(this);
|
||||
}
|
||||
|
||||
VEHICLE_FIELD.set(this, entity);
|
||||
entity.passengers.clear();
|
||||
entity.passengers.add(this);
|
||||
|
||||
} catch (Throwable t) {
|
||||
DebugLogger.cannotSetPassenger(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getRawItemStack() {
|
||||
return super.getItemStack();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,13 +6,9 @@
|
||||
package me.filoghost.holographicdisplays.nms.v1_13_R2;
|
||||
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSSlime;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import net.minecraft.server.v1_13_R2.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_13_R2.DamageSource;
|
||||
import net.minecraft.server.v1_13_R2.Entity;
|
||||
import net.minecraft.server.v1_13_R2.EntityDamageSource;
|
||||
import net.minecraft.server.v1_13_R2.EntityPlayer;
|
||||
import net.minecraft.server.v1_13_R2.EntitySlime;
|
||||
@ -26,18 +22,17 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
|
||||
public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle");
|
||||
|
||||
private final StandardHologramLine parentPiece;
|
||||
private final StandardHologramLine parentHologramLine;
|
||||
|
||||
public EntityNMSSlime(World world, StandardHologramLine parentPiece) {
|
||||
public EntityNMSSlime(World world, StandardHologramLine parentHologramLine) {
|
||||
super(world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
|
||||
super.persistent = true;
|
||||
super.collides = false;
|
||||
a(0.0F, 0.0F);
|
||||
setSize(1, false);
|
||||
setInvisible(true);
|
||||
this.parentPiece = parentPiece;
|
||||
super.a(0.0F, 0.0F);
|
||||
super.setSize(1, false);
|
||||
super.setInvisible(true);
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
}
|
||||
|
||||
@ -59,7 +54,7 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
|
||||
@Override
|
||||
public void a(AxisAlignedBB boundingBox) {
|
||||
// Do not change it!
|
||||
// Prevent bounding box from being changed
|
||||
}
|
||||
|
||||
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
|
||||
@ -175,36 +170,12 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getBukkitEntityNMS() {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerOfNMS(NMSEntityBase vehicleBase) {
|
||||
if (!(vehicleBase instanceof Entity)) {
|
||||
// It should never dismount
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = (Entity) vehicleBase;
|
||||
|
||||
try {
|
||||
if (super.getVehicle() != null) {
|
||||
Entity oldVehicle = super.getVehicle();
|
||||
VEHICLE_FIELD.set(this, null);
|
||||
oldVehicle.passengers.remove(this);
|
||||
}
|
||||
|
||||
VEHICLE_FIELD.set(this, entity);
|
||||
entity.passengers.clear();
|
||||
entity.passengers.add(this);
|
||||
|
||||
} catch (Throwable t) {
|
||||
DebugLogger.cannotSetPassenger(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -116,8 +116,5 @@ public class NullBoundingBox extends AxisAlignedBB {
|
||||
public AxisAlignedBB f(double arg0, double arg1, double arg2) {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -9,14 +9,14 @@ import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.fcommons.reflection.ClassToken;
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.fcommons.reflection.ReflectMethod;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.nms.CustomNameEditor;
|
||||
import me.filoghost.holographicdisplays.core.nms.ChatComponentCustomNameEditor;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSCommons;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSManager;
|
||||
import me.filoghost.holographicdisplays.core.nms.PacketController;
|
||||
import me.filoghost.holographicdisplays.core.nms.SpawnFailedException;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntity;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardItemLine;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
@ -43,7 +43,7 @@ public class VersionNMSManager implements NMSManager {
|
||||
private static final ReflectField<Object[]> ID_TO_CLASS_MAP_FIELD = ReflectField.lookup(Object[].class, RegistryID.class, "d");
|
||||
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 static final ReflectMethod<?> REGISTER_ENTITY_METHOD = ReflectMethod.lookup(Object.class, World.class, "b", Entity.class);
|
||||
|
||||
private final PacketController packetController;
|
||||
|
||||
@ -72,40 +72,34 @@ public class VersionNMSManager implements NMSManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, StandardItemLine parentPiece, ItemStack stack) {
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, StandardItemLine parentPiece, ItemStack stack) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece);
|
||||
customItem.setLocationNMS(x, y, z);
|
||||
customItem.setItemStackNMS(stack);
|
||||
if (!addEntityToWorld(nmsWorld, customItem)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return customItem;
|
||||
EntityNMSItem item = new EntityNMSItem(nmsWorld, parentPiece);
|
||||
item.setLocationNMS(x, y, z);
|
||||
item.setItemStackNMS(stack);
|
||||
addEntityToWorld(nmsWorld, item);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, StandardHologramLine parentPiece) {
|
||||
public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, StandardHologramLine parentPiece) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece);
|
||||
touchSlime.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, touchSlime)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return touchSlime;
|
||||
EntityNMSSlime slime = new EntityNMSSlime(nmsWorld, parentPiece);
|
||||
slime.setLocationNMS(x, y, z);
|
||||
addEntityToWorld(nmsWorld, slime);
|
||||
return slime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, StandardHologramLine parentPiece) {
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, StandardHologramLine parentPiece) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return invisibleArmorStand;
|
||||
EntityNMSArmorStand armorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
armorStand.setLocationNMS(x, y, z);
|
||||
addEntityToWorld(nmsWorld, armorStand);
|
||||
return armorStand;
|
||||
}
|
||||
|
||||
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) {
|
||||
private void addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) throws SpawnFailedException {
|
||||
Preconditions.checkState(Bukkit.isPrimaryThread(), "Async entity add");
|
||||
|
||||
final int chunkX = MathHelper.floor(nmsEntity.locX / 16.0);
|
||||
@ -114,61 +108,60 @@ public class VersionNMSManager implements NMSManager {
|
||||
if (!nmsWorld.isChunkLoaded(chunkX, chunkZ, true)) { // The boolean "true" is currently unused
|
||||
// This should never happen
|
||||
nmsEntity.dead = true;
|
||||
return false;
|
||||
throw new SpawnFailedException(SpawnFailedException.CHUNK_NOT_LOADED);
|
||||
}
|
||||
|
||||
nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity);
|
||||
if (NMSCommons.isPaperServer()) {
|
||||
if (NMSCommons.IS_PAPER_SERVER) {
|
||||
try {
|
||||
// Workaround because nmsWorld.entityList is a different class in Paper, if used without reflection it throws NoSuchFieldError.
|
||||
ENTITY_LIST_FIELD.get(nmsWorld).add(nmsEntity);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
throw new SpawnFailedException(SpawnFailedException.CHUNK_NOT_LOADED);
|
||||
}
|
||||
} else {
|
||||
nmsWorld.entityList.add(nmsEntity);
|
||||
}
|
||||
|
||||
try {
|
||||
VALIDATE_ENTITY_METHOD.invoke(nmsWorld, nmsEntity);
|
||||
REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
nmsEntity.dead = true;
|
||||
throw new SpawnFailedException(SpawnFailedException.REGISTER_ENTITY_FAIL, e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase;
|
||||
return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
public NMSEntity getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle();
|
||||
|
||||
if (nmsEntity instanceof NMSEntityBase) {
|
||||
return ((NMSEntityBase) nmsEntity);
|
||||
if (nmsEntity instanceof NMSEntity) {
|
||||
return ((NMSEntity) nmsEntity);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) {
|
||||
public NMSEntity getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
Entity nmsEntity = nmsWorld.getEntity(entityID);
|
||||
|
||||
if (nmsEntity instanceof NMSEntityBase) {
|
||||
return ((NMSEntityBase) nmsEntity);
|
||||
if (nmsEntity instanceof NMSEntity) {
|
||||
return ((NMSEntity) nmsEntity);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomNameEditor getCustomNameChatComponentEditor() {
|
||||
public CustomNameEditor getCustomNameEditor() {
|
||||
return VersionChatComponentCustomNameEditor.INSTANCE;
|
||||
}
|
||||
|
||||
|
@ -32,56 +32,56 @@ public class CraftNMSArmorStand extends CraftArmorStand {
|
||||
}
|
||||
|
||||
// Methods from ArmorStand class
|
||||
@Override public void setArms(boolean arms) { }
|
||||
@Override public void setBasePlate(boolean basePlate) { }
|
||||
@Override public void setBodyPose(EulerAngle pose) { }
|
||||
@Override public void setBoots(ItemStack item) { }
|
||||
@Override public void setChestplate(ItemStack item) { }
|
||||
@Override public void setHeadPose(EulerAngle pose) { }
|
||||
@Override public void setHelmet(ItemStack item) { }
|
||||
@Override public void setItemInHand(ItemStack item) { }
|
||||
@Override public void setLeftArmPose(EulerAngle pose) { }
|
||||
@Override public void setLeftLegPose(EulerAngle pose) { }
|
||||
@Override public void setLeggings(ItemStack item) { }
|
||||
@Override public void setRightArmPose(EulerAngle pose) { }
|
||||
@Override public void setRightLegPose(EulerAngle pose) { }
|
||||
@Override public void setSmall(boolean small) { }
|
||||
@Override public void setVisible(boolean visible) { }
|
||||
@Override public void setMarker(boolean marker) { }
|
||||
@Override public void setArms(boolean arms) {}
|
||||
@Override public void setBasePlate(boolean basePlate) {}
|
||||
@Override public void setBodyPose(EulerAngle pose) {}
|
||||
@Override public void setBoots(ItemStack item) {}
|
||||
@Override public void setChestplate(ItemStack item) {}
|
||||
@Override public void setHeadPose(EulerAngle pose) {}
|
||||
@Override public void setHelmet(ItemStack item) {}
|
||||
@Override public void setItemInHand(ItemStack item) {}
|
||||
@Override public void setLeftArmPose(EulerAngle pose) {}
|
||||
@Override public void setLeftLegPose(EulerAngle pose) {}
|
||||
@Override public void setLeggings(ItemStack item) {}
|
||||
@Override public void setRightArmPose(EulerAngle pose) {}
|
||||
@Override public void setRightLegPose(EulerAngle pose) {}
|
||||
@Override public void setSmall(boolean small) {}
|
||||
@Override public void setVisible(boolean visible) {}
|
||||
@Override public void setMarker(boolean marker) {}
|
||||
|
||||
// Methods from LivingEntity class
|
||||
@Override public boolean addPotionEffect(PotionEffect effect) { return false; }
|
||||
@Override public boolean addPotionEffect(PotionEffect effect, boolean param) { return false; }
|
||||
@Override public boolean addPotionEffects(Collection<PotionEffect> effects) { return false; }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) { }
|
||||
@Override public void setAI(boolean ai) { }
|
||||
@Override public void setCanPickupItems(boolean pickup) { }
|
||||
@Override public void setCollidable(boolean collidable) { }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) {}
|
||||
@Override public void setAI(boolean ai) {}
|
||||
@Override public void setCanPickupItems(boolean pickup) {}
|
||||
@Override public void setCollidable(boolean collidable) {}
|
||||
@Override public void setGliding(boolean gliding) { }
|
||||
@Override public boolean setLeashHolder(Entity holder) { return false; }
|
||||
@Override public void setSwimming(boolean swimming) { }
|
||||
@Override public void setSwimming(boolean swimming) {}
|
||||
|
||||
// Methods from Entity class
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void setGlowing(boolean flag) { }
|
||||
@Override public void setGravity(boolean gravity) { }
|
||||
@Override public void setInvulnerable(boolean flag) { }
|
||||
@Override public void setMomentum(Vector value) { }
|
||||
@Override public void setSilent(boolean flag) { }
|
||||
@Override public void setTicksLived(int value) { }
|
||||
@Override public void setPersistent(boolean flag) { }
|
||||
@Override public void setRotation(float yaw, float pitch) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
@Override public void setGlowing(boolean flag) {}
|
||||
@Override public void setGravity(boolean gravity) {}
|
||||
@Override public void setInvulnerable(boolean flag) {}
|
||||
@Override public void setMomentum(Vector value) {}
|
||||
@Override public void setSilent(boolean flag) {}
|
||||
@Override public void setTicksLived(int value) {}
|
||||
@Override public void setPersistent(boolean flag) {}
|
||||
@Override public void setRotation(float yaw, float pitch) {}
|
||||
|
||||
|
||||
}
|
||||
|
@ -28,29 +28,29 @@ public class CraftNMSItem extends CraftItem {
|
||||
}
|
||||
|
||||
// Methods from Item class
|
||||
@Override public void setItemStack(ItemStack stack) { }
|
||||
@Override public void setPickupDelay(int delay) { }
|
||||
@Override public void setItemStack(ItemStack stack) {}
|
||||
@Override public void setPickupDelay(int delay) {}
|
||||
|
||||
// Methods from Entity class
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void setGlowing(boolean flag) { }
|
||||
@Override public void setGravity(boolean gravity) { }
|
||||
@Override public void setInvulnerable(boolean flag) { }
|
||||
@Override public void setMomentum(Vector value) { }
|
||||
@Override public void setSilent(boolean flag) { }
|
||||
@Override public void setTicksLived(int value) { }
|
||||
@Override public void setPersistent(boolean flag) { }
|
||||
@Override public void setRotation(float yaw, float pitch) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
@Override public void setGlowing(boolean flag) {}
|
||||
@Override public void setGravity(boolean gravity) {}
|
||||
@Override public void setInvulnerable(boolean flag) {}
|
||||
@Override public void setMomentum(Vector value) {}
|
||||
@Override public void setSilent(boolean flag) {}
|
||||
@Override public void setTicksLived(int value) {}
|
||||
@Override public void setPersistent(boolean flag) {}
|
||||
@Override public void setRotation(float yaw, float pitch) {}
|
||||
|
||||
}
|
||||
|
@ -32,45 +32,45 @@ public class CraftNMSSlime extends CraftSlime {
|
||||
}
|
||||
|
||||
// Methods from Slime class
|
||||
@Override public void setSize(int size) { }
|
||||
@Override public void setTarget(LivingEntity target) { }
|
||||
@Override public void setSize(int size) {}
|
||||
@Override public void setTarget(LivingEntity target) {}
|
||||
|
||||
// Methods from Mob class
|
||||
@Override public void setLootTable(LootTable table) { }
|
||||
@Override public void setSeed(long seed) { }
|
||||
@Override public void setLootTable(LootTable table) {}
|
||||
@Override public void setSeed(long seed) {}
|
||||
|
||||
// Methods from LivingEntity class
|
||||
@Override public boolean addPotionEffect(PotionEffect effect) { return false; }
|
||||
@Override public boolean addPotionEffect(PotionEffect effect, boolean param) { return false; }
|
||||
@Override public boolean addPotionEffects(Collection<PotionEffect> effects) { return false; }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) { }
|
||||
@Override public void setAI(boolean ai) { }
|
||||
@Override public void setCanPickupItems(boolean pickup) { }
|
||||
@Override public void setCollidable(boolean collidable) { }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) {}
|
||||
@Override public void setAI(boolean ai) {}
|
||||
@Override public void setCanPickupItems(boolean pickup) {}
|
||||
@Override public void setCollidable(boolean collidable) {}
|
||||
@Override public void setGliding(boolean gliding) { }
|
||||
@Override public boolean setLeashHolder(Entity holder) { return false; }
|
||||
@Override public void setSwimming(boolean swimming) { }
|
||||
@Override public void setSwimming(boolean swimming) {}
|
||||
|
||||
// Methods from Entity class
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void setGlowing(boolean flag) { }
|
||||
@Override public void setGravity(boolean gravity) { }
|
||||
@Override public void setInvulnerable(boolean flag) { }
|
||||
@Override public void setMomentum(Vector value) { }
|
||||
@Override public void setSilent(boolean flag) { }
|
||||
@Override public void setTicksLived(int value) { }
|
||||
@Override public void setPersistent(boolean flag) { }
|
||||
@Override public void setRotation(float yaw, float pitch) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
@Override public void setGlowing(boolean flag) {}
|
||||
@Override public void setGravity(boolean gravity) {}
|
||||
@Override public void setInvulnerable(boolean flag) {}
|
||||
@Override public void setMomentum(Vector value) {}
|
||||
@Override public void setSilent(boolean flag) {}
|
||||
@Override public void setTicksLived(int value) {}
|
||||
@Override public void setPersistent(boolean flag) {}
|
||||
@Override public void setRotation(float yaw, float pitch) {}
|
||||
|
||||
}
|
||||
|
@ -5,12 +5,17 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.nms.v1_14_R1;
|
||||
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.Utils;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.PacketController;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntity;
|
||||
import net.minecraft.server.v1_14_R1.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||
import net.minecraft.server.v1_14_R1.Entity;
|
||||
import net.minecraft.server.v1_14_R1.EntityArmorStand;
|
||||
import net.minecraft.server.v1_14_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_14_R1.EntityPlayer;
|
||||
@ -29,14 +34,19 @@ import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.util.CraftChatMessage;
|
||||
|
||||
public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand {
|
||||
|
||||
private final StandardHologramLine parentPiece;
|
||||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle");
|
||||
|
||||
private final StandardHologramLine parentHologramLine;
|
||||
private final PacketController packetController;
|
||||
private CraftEntity customBukkitEntity;
|
||||
private String customName;
|
||||
|
||||
public EntityNMSArmorStand(World world, StandardHologramLine parentPiece, PacketController packetController) {
|
||||
public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, PacketController packetController) {
|
||||
super(EntityTypes.ARMOR_STAND, world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
this.packetController = packetController;
|
||||
|
||||
super.setInvisible(true);
|
||||
super.setSmall(true);
|
||||
super.setArms(false);
|
||||
@ -44,11 +54,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
super.setBasePlate(true);
|
||||
super.setMarker(true);
|
||||
super.collides = false;
|
||||
|
||||
this.parentPiece = parentPiece;
|
||||
this.packetController = packetController;
|
||||
super.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -56,8 +63,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
// Disable normal ticking for this entity.
|
||||
|
||||
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
|
||||
if (this.onGround) {
|
||||
this.onGround = false;
|
||||
if (super.onGround) {
|
||||
super.onGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,8 +73,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
// Disable normal ticking for this entity.
|
||||
|
||||
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
|
||||
if (this.onGround) {
|
||||
this.onGround = false;
|
||||
if (super.onGround) {
|
||||
super.onGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,7 +155,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
|
||||
@Override
|
||||
public void a(AxisAlignedBB boundingBox) {
|
||||
// Do not change it!
|
||||
// Prevent bounding box from being changed
|
||||
}
|
||||
|
||||
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
|
||||
@ -206,9 +213,9 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
private void broadcastLocationPacketNMS() {
|
||||
PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this);
|
||||
|
||||
for (Object obj : super.world.getPlayers()) {
|
||||
if (obj instanceof EntityPlayer) {
|
||||
EntityPlayer nmsPlayer = (EntityPlayer) obj;
|
||||
for (Object humanEntity : super.world.getPlayers()) {
|
||||
if (humanEntity instanceof EntityPlayer) {
|
||||
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
|
||||
|
||||
double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ);
|
||||
if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) {
|
||||
@ -218,6 +225,21 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerNMS(NMSEntity passenger) {
|
||||
Preconditions.checkArgument(passenger instanceof Entity);
|
||||
Entity passengerEntity = (Entity) passenger;
|
||||
Preconditions.checkArgument(passengerEntity.getVehicle() == null);
|
||||
Preconditions.checkState(super.passengers.isEmpty());
|
||||
|
||||
try {
|
||||
VEHICLE_FIELD.set(passenger, this);
|
||||
this.passengers.add(this);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
DebugLogger.cannotSetPassenger(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDeadNMS() {
|
||||
return super.dead;
|
||||
@ -230,11 +252,12 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getBukkitEntityNMS() {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,16 +5,12 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.nms.v1_14_R1;
|
||||
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSCommons;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardItemLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSCommons;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import net.minecraft.server.v1_14_R1.Blocks;
|
||||
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||
import net.minecraft.server.v1_14_R1.Entity;
|
||||
import net.minecraft.server.v1_14_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_14_R1.EntityItem;
|
||||
import net.minecraft.server.v1_14_R1.EntityPlayer;
|
||||
@ -29,15 +25,14 @@ import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack;
|
||||
|
||||
public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle");
|
||||
|
||||
private final StandardItemLine parentPiece;
|
||||
private final StandardItemLine parentHologramLine;
|
||||
private CraftEntity customBukkitEntity;
|
||||
|
||||
public EntityNMSItem(World world, StandardItemLine piece) {
|
||||
public EntityNMSItem(World world, StandardItemLine parentHologramLine) {
|
||||
super(EntityTypes.ITEM, world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
|
||||
super.pickupDelay = 32767; // Lock the item pickup delay, also prevents entities from picking up the item
|
||||
this.parentPiece = piece;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -65,7 +60,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
}
|
||||
|
||||
if (human instanceof EntityPlayer) {
|
||||
parentPiece.onPickup(((EntityPlayer) human).getBukkitEntity());
|
||||
parentHologramLine.onPickup(((EntityPlayer) human).getBukkitEntity());
|
||||
// It is never added to the inventory.
|
||||
}
|
||||
}
|
||||
@ -155,7 +150,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
|
||||
@Override
|
||||
public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) {
|
||||
ItemStack newItem = CraftItemStack.asNMSCopy(stack); // ItemStack.a is returned if the stack is null, invalid or the material is not an Item
|
||||
ItemStack newItem = CraftItemStack.asNMSCopy(stack); // ItemStack.a is returned if the stack is not valid
|
||||
|
||||
if (newItem == null || newItem == ItemStack.a) {
|
||||
newItem = new ItemStack(Blocks.BEDROCK);
|
||||
@ -170,10 +165,10 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
}
|
||||
|
||||
NBTTagList tagList = new NBTTagList();
|
||||
tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE)); // Antistack lore
|
||||
tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE));
|
||||
display.set("Lore", tagList);
|
||||
|
||||
setItemStack(newItem);
|
||||
super.setItemStack(newItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -183,41 +178,17 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getBukkitEntityNMS() {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerOfNMS(NMSEntityBase vehicleBase) {
|
||||
if (!(vehicleBase instanceof Entity)) {
|
||||
// It should never dismount
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = (Entity) vehicleBase;
|
||||
|
||||
try {
|
||||
if (super.getVehicle() != null) {
|
||||
Entity oldVehicle = super.getVehicle();
|
||||
VEHICLE_FIELD.set(this, null);
|
||||
oldVehicle.passengers.remove(this);
|
||||
}
|
||||
|
||||
VEHICLE_FIELD.set(this, entity);
|
||||
entity.passengers.clear();
|
||||
entity.passengers.add(this);
|
||||
|
||||
} catch (Throwable t) {
|
||||
DebugLogger.cannotSetPassenger(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getRawItemStack() {
|
||||
return super.getItemStack();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,13 +6,9 @@
|
||||
package me.filoghost.holographicdisplays.nms.v1_14_R1;
|
||||
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSSlime;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import net.minecraft.server.v1_14_R1.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||
import net.minecraft.server.v1_14_R1.Entity;
|
||||
import net.minecraft.server.v1_14_R1.EntityDamageSource;
|
||||
import net.minecraft.server.v1_14_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_14_R1.EntitySlime;
|
||||
@ -27,19 +23,18 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
|
||||
public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle");
|
||||
|
||||
private final StandardHologramLine parentPiece;
|
||||
private final StandardHologramLine parentHologramLine;
|
||||
private CraftEntity customBukkitEntity;
|
||||
|
||||
public EntityNMSSlime(World world, StandardHologramLine parentPiece) {
|
||||
public EntityNMSSlime(World world, StandardHologramLine parentHologramLine) {
|
||||
super(EntityTypes.SLIME, world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
|
||||
super.persistent = true;
|
||||
super.collides = false;
|
||||
a(0.0F, 0.0F);
|
||||
setSize(1, false);
|
||||
setInvisible(true);
|
||||
this.parentPiece = parentPiece;
|
||||
super.a(0.0F, 0.0F);
|
||||
super.setSize(1, false);
|
||||
super.setInvisible(true);
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
}
|
||||
|
||||
@ -61,7 +56,7 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
|
||||
@Override
|
||||
public void a(AxisAlignedBB boundingBox) {
|
||||
// Do not change it!
|
||||
// Prevent bounding box from being changed
|
||||
}
|
||||
|
||||
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
|
||||
@ -177,36 +172,12 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getBukkitEntityNMS() {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerOfNMS(NMSEntityBase vehicleBase) {
|
||||
if (!(vehicleBase instanceof Entity)) {
|
||||
// It should never dismount
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = (Entity) vehicleBase;
|
||||
|
||||
try {
|
||||
if (super.getVehicle() != null) {
|
||||
Entity oldVehicle = super.getVehicle();
|
||||
VEHICLE_FIELD.set(this, null);
|
||||
oldVehicle.passengers.remove(this);
|
||||
}
|
||||
|
||||
VEHICLE_FIELD.set(this, entity);
|
||||
entity.passengers.clear();
|
||||
entity.passengers.add(this);
|
||||
|
||||
} catch (Throwable t) {
|
||||
DebugLogger.cannotSetPassenger(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -120,8 +120,5 @@ public class NullBoundingBox extends AxisAlignedBB {
|
||||
public Vec3D f() {
|
||||
return Vec3D.a;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -9,13 +9,13 @@ import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.fcommons.reflection.ClassToken;
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.fcommons.reflection.ReflectMethod;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.nms.CustomNameEditor;
|
||||
import me.filoghost.holographicdisplays.core.nms.ChatComponentCustomNameEditor;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSManager;
|
||||
import me.filoghost.holographicdisplays.core.nms.PacketController;
|
||||
import me.filoghost.holographicdisplays.core.nms.SpawnFailedException;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntity;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardItemLine;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
@ -71,40 +71,34 @@ public class VersionNMSManager implements NMSManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSItem spawnNMSItem(World bukkitWorld, double x, double y, double z, StandardItemLine parentPiece, ItemStack stack) {
|
||||
public NMSItem spawnNMSItem(World bukkitWorld, double x, double y, double z, StandardItemLine parentPiece, ItemStack stack) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece);
|
||||
customItem.setLocationNMS(x, y, z);
|
||||
customItem.setItemStackNMS(stack);
|
||||
if (!addEntityToWorld(nmsWorld, customItem)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return customItem;
|
||||
EntityNMSItem item = new EntityNMSItem(nmsWorld, parentPiece);
|
||||
item.setLocationNMS(x, y, z);
|
||||
item.setItemStackNMS(stack);
|
||||
addEntityToWorld(nmsWorld, item);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityNMSSlime spawnNMSSlime(World bukkitWorld, double x, double y, double z, StandardHologramLine parentPiece) {
|
||||
public EntityNMSSlime spawnNMSSlime(World bukkitWorld, double x, double y, double z, StandardHologramLine parentPiece) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece);
|
||||
touchSlime.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, touchSlime)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return touchSlime;
|
||||
EntityNMSSlime slime = new EntityNMSSlime(nmsWorld, parentPiece);
|
||||
slime.setLocationNMS(x, y, z);
|
||||
addEntityToWorld(nmsWorld, slime);
|
||||
return slime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSArmorStand spawnNMSArmorStand(World world, double x, double y, double z, StandardHologramLine parentPiece) {
|
||||
public NMSArmorStand spawnNMSArmorStand(World world, double x, double y, double z, StandardHologramLine parentPiece) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return invisibleArmorStand;
|
||||
EntityNMSArmorStand armorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
armorStand.setLocationNMS(x, y, z);
|
||||
addEntityToWorld(nmsWorld, armorStand);
|
||||
return armorStand;
|
||||
}
|
||||
|
||||
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) {
|
||||
private void addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) throws SpawnFailedException {
|
||||
Preconditions.checkState(Bukkit.isPrimaryThread(), "Async entity add");
|
||||
|
||||
final int chunkX = MathHelper.floor(nmsEntity.locX / 16.0);
|
||||
@ -113,49 +107,48 @@ public class VersionNMSManager implements NMSManager {
|
||||
if (!nmsWorld.isChunkLoaded(chunkX, chunkZ)) {
|
||||
// This should never happen
|
||||
nmsEntity.dead = true;
|
||||
return false;
|
||||
throw new SpawnFailedException(SpawnFailedException.CHUNK_NOT_LOADED);
|
||||
}
|
||||
|
||||
nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity);
|
||||
try {
|
||||
REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity);
|
||||
return true;
|
||||
} catch (ReflectiveOperationException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
nmsEntity.dead = true;
|
||||
throw new SpawnFailedException(SpawnFailedException.REGISTER_ENTITY_FAIL, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase;
|
||||
return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
public NMSEntity getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle();
|
||||
|
||||
if (nmsEntity instanceof NMSEntityBase) {
|
||||
return ((NMSEntityBase) nmsEntity);
|
||||
if (nmsEntity instanceof NMSEntity) {
|
||||
return ((NMSEntity) nmsEntity);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) {
|
||||
public NMSEntity getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
Entity nmsEntity = nmsWorld.getEntity(entityID);
|
||||
|
||||
if (nmsEntity instanceof NMSEntityBase) {
|
||||
return ((NMSEntityBase) nmsEntity);
|
||||
if (nmsEntity instanceof NMSEntity) {
|
||||
return ((NMSEntity) nmsEntity);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomNameEditor getCustomNameChatComponentEditor() {
|
||||
public CustomNameEditor getCustomNameEditor() {
|
||||
return VersionChatComponentCustomNameEditor.INSTANCE;
|
||||
}
|
||||
|
||||
|
@ -32,56 +32,56 @@ public class CraftNMSArmorStand extends CraftArmorStand {
|
||||
}
|
||||
|
||||
// Methods from ArmorStand class
|
||||
@Override public void setArms(boolean arms) { }
|
||||
@Override public void setBasePlate(boolean basePlate) { }
|
||||
@Override public void setBodyPose(EulerAngle pose) { }
|
||||
@Override public void setBoots(ItemStack item) { }
|
||||
@Override public void setChestplate(ItemStack item) { }
|
||||
@Override public void setHeadPose(EulerAngle pose) { }
|
||||
@Override public void setHelmet(ItemStack item) { }
|
||||
@Override public void setItemInHand(ItemStack item) { }
|
||||
@Override public void setLeftArmPose(EulerAngle pose) { }
|
||||
@Override public void setLeftLegPose(EulerAngle pose) { }
|
||||
@Override public void setLeggings(ItemStack item) { }
|
||||
@Override public void setRightArmPose(EulerAngle pose) { }
|
||||
@Override public void setRightLegPose(EulerAngle pose) { }
|
||||
@Override public void setSmall(boolean small) { }
|
||||
@Override public void setVisible(boolean visible) { }
|
||||
@Override public void setMarker(boolean marker) { }
|
||||
@Override public void setArms(boolean arms) {}
|
||||
@Override public void setBasePlate(boolean basePlate) {}
|
||||
@Override public void setBodyPose(EulerAngle pose) {}
|
||||
@Override public void setBoots(ItemStack item) {}
|
||||
@Override public void setChestplate(ItemStack item) {}
|
||||
@Override public void setHeadPose(EulerAngle pose) {}
|
||||
@Override public void setHelmet(ItemStack item) {}
|
||||
@Override public void setItemInHand(ItemStack item) {}
|
||||
@Override public void setLeftArmPose(EulerAngle pose) {}
|
||||
@Override public void setLeftLegPose(EulerAngle pose) {}
|
||||
@Override public void setLeggings(ItemStack item) {}
|
||||
@Override public void setRightArmPose(EulerAngle pose) {}
|
||||
@Override public void setRightLegPose(EulerAngle pose) {}
|
||||
@Override public void setSmall(boolean small) {}
|
||||
@Override public void setVisible(boolean visible) {}
|
||||
@Override public void setMarker(boolean marker) {}
|
||||
|
||||
// Methods from LivingEntity class
|
||||
@Override public boolean addPotionEffect(PotionEffect effect) { return false; }
|
||||
@Override public boolean addPotionEffect(PotionEffect effect, boolean param) { return false; }
|
||||
@Override public boolean addPotionEffects(Collection<PotionEffect> effects) { return false; }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) { }
|
||||
@Override public void setAI(boolean ai) { }
|
||||
@Override public void setCanPickupItems(boolean pickup) { }
|
||||
@Override public void setCollidable(boolean collidable) { }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) {}
|
||||
@Override public void setAI(boolean ai) {}
|
||||
@Override public void setCanPickupItems(boolean pickup) {}
|
||||
@Override public void setCollidable(boolean collidable) {}
|
||||
@Override public void setGliding(boolean gliding) { }
|
||||
@Override public boolean setLeashHolder(Entity holder) { return false; }
|
||||
@Override public void setSwimming(boolean swimming) { }
|
||||
@Override public void setSwimming(boolean swimming) {}
|
||||
|
||||
// Methods from Entity class
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void setGlowing(boolean flag) { }
|
||||
@Override public void setGravity(boolean gravity) { }
|
||||
@Override public void setInvulnerable(boolean flag) { }
|
||||
@Override public void setMomentum(Vector value) { }
|
||||
@Override public void setSilent(boolean flag) { }
|
||||
@Override public void setTicksLived(int value) { }
|
||||
@Override public void setPersistent(boolean flag) { }
|
||||
@Override public void setRotation(float yaw, float pitch) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
@Override public void setGlowing(boolean flag) {}
|
||||
@Override public void setGravity(boolean gravity) {}
|
||||
@Override public void setInvulnerable(boolean flag) {}
|
||||
@Override public void setMomentum(Vector value) {}
|
||||
@Override public void setSilent(boolean flag) {}
|
||||
@Override public void setTicksLived(int value) {}
|
||||
@Override public void setPersistent(boolean flag) {}
|
||||
@Override public void setRotation(float yaw, float pitch) {}
|
||||
|
||||
|
||||
}
|
||||
|
@ -28,29 +28,29 @@ public class CraftNMSItem extends CraftItem {
|
||||
}
|
||||
|
||||
// Methods from Item class
|
||||
@Override public void setItemStack(ItemStack stack) { }
|
||||
@Override public void setPickupDelay(int delay) { }
|
||||
@Override public void setItemStack(ItemStack stack) {}
|
||||
@Override public void setPickupDelay(int delay) {}
|
||||
|
||||
// Methods from Entity class
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void setGlowing(boolean flag) { }
|
||||
@Override public void setGravity(boolean gravity) { }
|
||||
@Override public void setInvulnerable(boolean flag) { }
|
||||
@Override public void setMomentum(Vector value) { }
|
||||
@Override public void setSilent(boolean flag) { }
|
||||
@Override public void setTicksLived(int value) { }
|
||||
@Override public void setPersistent(boolean flag) { }
|
||||
@Override public void setRotation(float yaw, float pitch) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
@Override public void setGlowing(boolean flag) {}
|
||||
@Override public void setGravity(boolean gravity) {}
|
||||
@Override public void setInvulnerable(boolean flag) {}
|
||||
@Override public void setMomentum(Vector value) {}
|
||||
@Override public void setSilent(boolean flag) {}
|
||||
@Override public void setTicksLived(int value) {}
|
||||
@Override public void setPersistent(boolean flag) {}
|
||||
@Override public void setRotation(float yaw, float pitch) {}
|
||||
|
||||
}
|
||||
|
@ -32,45 +32,45 @@ public class CraftNMSSlime extends CraftSlime {
|
||||
}
|
||||
|
||||
// Methods from Slime class
|
||||
@Override public void setSize(int size) { }
|
||||
@Override public void setTarget(LivingEntity target) { }
|
||||
@Override public void setSize(int size) {}
|
||||
@Override public void setTarget(LivingEntity target) {}
|
||||
|
||||
// Methods from Mob class
|
||||
@Override public void setLootTable(LootTable table) { }
|
||||
@Override public void setSeed(long seed) { }
|
||||
@Override public void setLootTable(LootTable table) {}
|
||||
@Override public void setSeed(long seed) {}
|
||||
|
||||
// Methods from LivingEntity class
|
||||
@Override public boolean addPotionEffect(PotionEffect effect) { return false; }
|
||||
@Override public boolean addPotionEffect(PotionEffect effect, boolean param) { return false; }
|
||||
@Override public boolean addPotionEffects(Collection<PotionEffect> effects) { return false; }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) { }
|
||||
@Override public void setAI(boolean ai) { }
|
||||
@Override public void setCanPickupItems(boolean pickup) { }
|
||||
@Override public void setCollidable(boolean collidable) { }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) {}
|
||||
@Override public void setAI(boolean ai) {}
|
||||
@Override public void setCanPickupItems(boolean pickup) {}
|
||||
@Override public void setCollidable(boolean collidable) {}
|
||||
@Override public void setGliding(boolean gliding) { }
|
||||
@Override public boolean setLeashHolder(Entity holder) { return false; }
|
||||
@Override public void setSwimming(boolean swimming) { }
|
||||
@Override public void setSwimming(boolean swimming) {}
|
||||
|
||||
// Methods from Entity class
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void setGlowing(boolean flag) { }
|
||||
@Override public void setGravity(boolean gravity) { }
|
||||
@Override public void setInvulnerable(boolean flag) { }
|
||||
@Override public void setMomentum(Vector value) { }
|
||||
@Override public void setSilent(boolean flag) { }
|
||||
@Override public void setTicksLived(int value) { }
|
||||
@Override public void setPersistent(boolean flag) { }
|
||||
@Override public void setRotation(float yaw, float pitch) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
@Override public void setGlowing(boolean flag) {}
|
||||
@Override public void setGravity(boolean gravity) {}
|
||||
@Override public void setInvulnerable(boolean flag) {}
|
||||
@Override public void setMomentum(Vector value) {}
|
||||
@Override public void setSilent(boolean flag) {}
|
||||
@Override public void setTicksLived(int value) {}
|
||||
@Override public void setPersistent(boolean flag) {}
|
||||
@Override public void setRotation(float yaw, float pitch) {}
|
||||
|
||||
}
|
||||
|
@ -5,12 +5,17 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.nms.v1_15_R1;
|
||||
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.Utils;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.PacketController;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntity;
|
||||
import net.minecraft.server.v1_15_R1.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_15_R1.DamageSource;
|
||||
import net.minecraft.server.v1_15_R1.Entity;
|
||||
import net.minecraft.server.v1_15_R1.EntityArmorStand;
|
||||
import net.minecraft.server.v1_15_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_15_R1.EntityPlayer;
|
||||
@ -30,13 +35,18 @@ import org.bukkit.craftbukkit.v1_15_R1.util.CraftChatMessage;
|
||||
|
||||
public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand {
|
||||
|
||||
private final StandardHologramLine parentPiece;
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle");
|
||||
|
||||
private final StandardHologramLine parentHologramLine;
|
||||
private final PacketController packetController;
|
||||
private CraftEntity customBukkitEntity;
|
||||
private String customName;
|
||||
|
||||
public EntityNMSArmorStand(World world, StandardHologramLine parentPiece, PacketController packetController) {
|
||||
public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, PacketController packetController) {
|
||||
super(EntityTypes.ARMOR_STAND, world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
this.packetController = packetController;
|
||||
|
||||
super.setInvisible(true);
|
||||
super.setSmall(true);
|
||||
super.setArms(false);
|
||||
@ -44,11 +54,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
super.setBasePlate(true);
|
||||
super.setMarker(true);
|
||||
super.collides = false;
|
||||
|
||||
this.parentPiece = parentPiece;
|
||||
this.packetController = packetController;
|
||||
super.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -56,8 +63,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
// Disable normal ticking for this entity.
|
||||
|
||||
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
|
||||
if (this.onGround) {
|
||||
this.onGround = false;
|
||||
if (super.onGround) {
|
||||
super.onGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,8 +73,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
// Disable normal ticking for this entity.
|
||||
|
||||
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
|
||||
if (this.onGround) {
|
||||
this.onGround = false;
|
||||
if (super.onGround) {
|
||||
super.onGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,7 +155,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
|
||||
@Override
|
||||
public void a(AxisAlignedBB boundingBox) {
|
||||
// Do not change it!
|
||||
// Prevent bounding box from being changed
|
||||
}
|
||||
|
||||
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
|
||||
@ -206,9 +213,9 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
private void broadcastLocationPacketNMS() {
|
||||
PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this);
|
||||
|
||||
for (Object obj : super.world.getPlayers()) {
|
||||
if (obj instanceof EntityPlayer) {
|
||||
EntityPlayer nmsPlayer = (EntityPlayer) obj;
|
||||
for (Object humanEntity : super.world.getPlayers()) {
|
||||
if (humanEntity instanceof EntityPlayer) {
|
||||
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
|
||||
|
||||
double distanceSquared = Utils.square(nmsPlayer.locX() - super.locX()) + Utils.square(nmsPlayer.locZ() - super.locZ());
|
||||
if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) {
|
||||
@ -218,6 +225,21 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerNMS(NMSEntity passenger) {
|
||||
Preconditions.checkArgument(passenger instanceof Entity);
|
||||
Entity passengerEntity = (Entity) passenger;
|
||||
Preconditions.checkArgument(passengerEntity.getVehicle() == null);
|
||||
Preconditions.checkState(super.passengers.isEmpty());
|
||||
|
||||
try {
|
||||
VEHICLE_FIELD.set(passenger, this);
|
||||
this.passengers.add(this);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
DebugLogger.cannotSetPassenger(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDeadNMS() {
|
||||
return super.dead;
|
||||
@ -230,11 +252,12 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getBukkitEntityNMS() {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,16 +5,12 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.nms.v1_15_R1;
|
||||
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSCommons;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardItemLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSCommons;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import net.minecraft.server.v1_15_R1.Blocks;
|
||||
import net.minecraft.server.v1_15_R1.DamageSource;
|
||||
import net.minecraft.server.v1_15_R1.Entity;
|
||||
import net.minecraft.server.v1_15_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_15_R1.EntityItem;
|
||||
import net.minecraft.server.v1_15_R1.EntityPlayer;
|
||||
@ -29,15 +25,14 @@ import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack;
|
||||
|
||||
public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle");
|
||||
|
||||
private final StandardItemLine parentPiece;
|
||||
private final StandardItemLine parentHologramLine;
|
||||
private CraftEntity customBukkitEntity;
|
||||
|
||||
public EntityNMSItem(World world, StandardItemLine piece) {
|
||||
public EntityNMSItem(World world, StandardItemLine parentHologramLine) {
|
||||
super(EntityTypes.ITEM, world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
|
||||
super.pickupDelay = 32767; // Lock the item pickup delay, also prevents entities from picking up the item
|
||||
this.parentPiece = piece;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -65,7 +60,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
}
|
||||
|
||||
if (human instanceof EntityPlayer) {
|
||||
parentPiece.onPickup(((EntityPlayer) human).getBukkitEntity());
|
||||
parentHologramLine.onPickup(((EntityPlayer) human).getBukkitEntity());
|
||||
// It is never added to the inventory.
|
||||
}
|
||||
}
|
||||
@ -155,7 +150,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
|
||||
@Override
|
||||
public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) {
|
||||
ItemStack newItem = CraftItemStack.asNMSCopy(stack); // ItemStack.a is returned if the stack is null, invalid or the material is not an Item
|
||||
ItemStack newItem = CraftItemStack.asNMSCopy(stack); // ItemStack.a is returned if the stack is not valid
|
||||
|
||||
if (newItem == null || newItem == ItemStack.a) {
|
||||
newItem = new ItemStack(Blocks.BEDROCK);
|
||||
@ -170,10 +165,10 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
}
|
||||
|
||||
NBTTagList tagList = new NBTTagList();
|
||||
tagList.add(NBTTagString.a(NMSCommons.ANTI_STACK_LORE)); // Antistack lore
|
||||
tagList.add(NBTTagString.a(NMSCommons.ANTI_STACK_LORE));
|
||||
display.set("Lore", tagList);
|
||||
|
||||
setItemStack(newItem);
|
||||
super.setItemStack(newItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -183,7 +178,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -191,33 +186,9 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerOfNMS(NMSEntityBase vehicleBase) {
|
||||
if (!(vehicleBase instanceof Entity)) {
|
||||
// It should never dismount
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = (Entity) vehicleBase;
|
||||
|
||||
try {
|
||||
if (super.getVehicle() != null) {
|
||||
Entity oldVehicle = super.getVehicle();
|
||||
VEHICLE_FIELD.set(this, null);
|
||||
oldVehicle.passengers.remove(this);
|
||||
}
|
||||
|
||||
VEHICLE_FIELD.set(this, entity);
|
||||
entity.passengers.clear();
|
||||
entity.passengers.add(this);
|
||||
|
||||
} catch (Throwable t) {
|
||||
DebugLogger.cannotSetPassenger(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getRawItemStack() {
|
||||
return super.getItemStack();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,13 +6,9 @@
|
||||
package me.filoghost.holographicdisplays.nms.v1_15_R1;
|
||||
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSSlime;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import net.minecraft.server.v1_15_R1.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_15_R1.DamageSource;
|
||||
import net.minecraft.server.v1_15_R1.Entity;
|
||||
import net.minecraft.server.v1_15_R1.EntityDamageSource;
|
||||
import net.minecraft.server.v1_15_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_15_R1.EntitySlime;
|
||||
@ -27,19 +23,18 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
|
||||
public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle");
|
||||
|
||||
private final StandardHologramLine parentPiece;
|
||||
private final StandardHologramLine parentHologramLine;
|
||||
private CraftEntity customBukkitEntity;
|
||||
|
||||
public EntityNMSSlime(World world, StandardHologramLine parentPiece) {
|
||||
public EntityNMSSlime(World world, StandardHologramLine parentHologramLine) {
|
||||
super(EntityTypes.SLIME, world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
|
||||
super.persistent = true;
|
||||
super.collides = false;
|
||||
a(0.0F, 0.0F);
|
||||
setSize(1, false);
|
||||
setInvisible(true);
|
||||
this.parentPiece = parentPiece;
|
||||
super.a(0.0F, 0.0F);
|
||||
super.setSize(1, false);
|
||||
super.setInvisible(true);
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
}
|
||||
|
||||
@ -61,7 +56,7 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
|
||||
@Override
|
||||
public void a(AxisAlignedBB boundingBox) {
|
||||
// Do not change it!
|
||||
// Prevent bounding box from being changed
|
||||
}
|
||||
|
||||
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
|
||||
@ -177,36 +172,12 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getBukkitEntityNMS() {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerOfNMS(NMSEntityBase vehicleBase) {
|
||||
if (!(vehicleBase instanceof Entity)) {
|
||||
// It should never dismount
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = (Entity) vehicleBase;
|
||||
|
||||
try {
|
||||
if (super.getVehicle() != null) {
|
||||
Entity oldVehicle = super.getVehicle();
|
||||
VEHICLE_FIELD.set(this, null);
|
||||
oldVehicle.passengers.remove(this);
|
||||
}
|
||||
|
||||
VEHICLE_FIELD.set(this, entity);
|
||||
entity.passengers.clear();
|
||||
entity.passengers.add(this);
|
||||
|
||||
} catch (Throwable t) {
|
||||
DebugLogger.cannotSetPassenger(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -120,6 +120,5 @@ public class NullBoundingBox extends AxisAlignedBB {
|
||||
public Vec3D f() {
|
||||
return Vec3D.a;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -9,16 +9,16 @@ import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.fcommons.reflection.ClassToken;
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.fcommons.reflection.ReflectMethod;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.nms.CustomNameEditor;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardItemLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.ChatComponentCustomNameEditor;
|
||||
import me.filoghost.holographicdisplays.core.nms.CustomNameEditor;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSManager;
|
||||
import me.filoghost.holographicdisplays.core.nms.PacketController;
|
||||
import me.filoghost.holographicdisplays.core.nms.SpawnFailedException;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntity;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardItemLine;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import net.minecraft.server.v1_15_R1.ChatComponentText;
|
||||
import net.minecraft.server.v1_15_R1.Entity;
|
||||
import net.minecraft.server.v1_15_R1.EntityTypes;
|
||||
@ -70,40 +70,34 @@ public class VersionNMSManager implements NMSManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSItem spawnNMSItem(World bukkitWorld, double x, double y, double z, StandardItemLine parentPiece, ItemStack stack) {
|
||||
public NMSItem spawnNMSItem(World bukkitWorld, double x, double y, double z, StandardItemLine parentPiece, ItemStack stack) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece);
|
||||
customItem.setLocationNMS(x, y, z);
|
||||
customItem.setItemStackNMS(stack);
|
||||
if (!addEntityToWorld(nmsWorld, customItem)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return customItem;
|
||||
EntityNMSItem item = new EntityNMSItem(nmsWorld, parentPiece);
|
||||
item.setLocationNMS(x, y, z);
|
||||
item.setItemStackNMS(stack);
|
||||
addEntityToWorld(nmsWorld, item);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityNMSSlime spawnNMSSlime(World bukkitWorld, double x, double y, double z, StandardHologramLine parentPiece) {
|
||||
public EntityNMSSlime spawnNMSSlime(World bukkitWorld, double x, double y, double z, StandardHologramLine parentPiece) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece);
|
||||
touchSlime.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, touchSlime)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return touchSlime;
|
||||
EntityNMSSlime slime = new EntityNMSSlime(nmsWorld, parentPiece);
|
||||
slime.setLocationNMS(x, y, z);
|
||||
addEntityToWorld(nmsWorld, slime);
|
||||
return slime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSArmorStand spawnNMSArmorStand(World world, double x, double y, double z, StandardHologramLine parentPiece) {
|
||||
public NMSArmorStand spawnNMSArmorStand(World world, double x, double y, double z, StandardHologramLine parentPiece) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return invisibleArmorStand;
|
||||
EntityNMSArmorStand armorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
armorStand.setLocationNMS(x, y, z);
|
||||
addEntityToWorld(nmsWorld, armorStand);
|
||||
return armorStand;
|
||||
}
|
||||
|
||||
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) {
|
||||
private void addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) throws SpawnFailedException {
|
||||
Preconditions.checkState(Bukkit.isPrimaryThread(), "Async entity add");
|
||||
|
||||
final int chunkX = MathHelper.floor(nmsEntity.locX() / 16.0);
|
||||
@ -112,49 +106,48 @@ public class VersionNMSManager implements NMSManager {
|
||||
if (!nmsWorld.isChunkLoaded(chunkX, chunkZ)) {
|
||||
// This should never happen
|
||||
nmsEntity.dead = true;
|
||||
return false;
|
||||
throw new SpawnFailedException(SpawnFailedException.CHUNK_NOT_LOADED);
|
||||
}
|
||||
|
||||
nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity);
|
||||
try {
|
||||
REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity);
|
||||
return true;
|
||||
} catch (ReflectiveOperationException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
nmsEntity.dead = true;
|
||||
throw new SpawnFailedException(SpawnFailedException.REGISTER_ENTITY_FAIL, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase;
|
||||
return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
public NMSEntity getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle();
|
||||
|
||||
if (nmsEntity instanceof NMSEntityBase) {
|
||||
return ((NMSEntityBase) nmsEntity);
|
||||
if (nmsEntity instanceof NMSEntity) {
|
||||
return ((NMSEntity) nmsEntity);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) {
|
||||
public NMSEntity getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
Entity nmsEntity = nmsWorld.getEntity(entityID);
|
||||
|
||||
if (nmsEntity instanceof NMSEntityBase) {
|
||||
return ((NMSEntityBase) nmsEntity);
|
||||
if (nmsEntity instanceof NMSEntity) {
|
||||
return ((NMSEntity) nmsEntity);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomNameEditor getCustomNameChatComponentEditor() {
|
||||
public CustomNameEditor getCustomNameEditor() {
|
||||
return VersionChatComponentCustomNameEditor.INSTANCE;
|
||||
}
|
||||
|
||||
|
@ -32,56 +32,56 @@ public class CraftNMSArmorStand extends CraftArmorStand {
|
||||
}
|
||||
|
||||
// Methods from ArmorStand class
|
||||
@Override public void setArms(boolean arms) { }
|
||||
@Override public void setBasePlate(boolean basePlate) { }
|
||||
@Override public void setBodyPose(EulerAngle pose) { }
|
||||
@Override public void setBoots(ItemStack item) { }
|
||||
@Override public void setChestplate(ItemStack item) { }
|
||||
@Override public void setHeadPose(EulerAngle pose) { }
|
||||
@Override public void setHelmet(ItemStack item) { }
|
||||
@Override public void setItemInHand(ItemStack item) { }
|
||||
@Override public void setLeftArmPose(EulerAngle pose) { }
|
||||
@Override public void setLeftLegPose(EulerAngle pose) { }
|
||||
@Override public void setLeggings(ItemStack item) { }
|
||||
@Override public void setRightArmPose(EulerAngle pose) { }
|
||||
@Override public void setRightLegPose(EulerAngle pose) { }
|
||||
@Override public void setSmall(boolean small) { }
|
||||
@Override public void setVisible(boolean visible) { }
|
||||
@Override public void setMarker(boolean marker) { }
|
||||
@Override public void setArms(boolean arms) {}
|
||||
@Override public void setBasePlate(boolean basePlate) {}
|
||||
@Override public void setBodyPose(EulerAngle pose) {}
|
||||
@Override public void setBoots(ItemStack item) {}
|
||||
@Override public void setChestplate(ItemStack item) {}
|
||||
@Override public void setHeadPose(EulerAngle pose) {}
|
||||
@Override public void setHelmet(ItemStack item) {}
|
||||
@Override public void setItemInHand(ItemStack item) {}
|
||||
@Override public void setLeftArmPose(EulerAngle pose) {}
|
||||
@Override public void setLeftLegPose(EulerAngle pose) {}
|
||||
@Override public void setLeggings(ItemStack item) {}
|
||||
@Override public void setRightArmPose(EulerAngle pose) {}
|
||||
@Override public void setRightLegPose(EulerAngle pose) {}
|
||||
@Override public void setSmall(boolean small) {}
|
||||
@Override public void setVisible(boolean visible) {}
|
||||
@Override public void setMarker(boolean marker) {}
|
||||
|
||||
// Methods from LivingEntity class
|
||||
@Override public boolean addPotionEffect(PotionEffect effect) { return false; }
|
||||
@Override public boolean addPotionEffect(PotionEffect effect, boolean param) { return false; }
|
||||
@Override public boolean addPotionEffects(Collection<PotionEffect> effects) { return false; }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) { }
|
||||
@Override public void setAI(boolean ai) { }
|
||||
@Override public void setCanPickupItems(boolean pickup) { }
|
||||
@Override public void setCollidable(boolean collidable) { }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) {}
|
||||
@Override public void setAI(boolean ai) {}
|
||||
@Override public void setCanPickupItems(boolean pickup) {}
|
||||
@Override public void setCollidable(boolean collidable) {}
|
||||
@Override public void setGliding(boolean gliding) { }
|
||||
@Override public boolean setLeashHolder(Entity holder) { return false; }
|
||||
@Override public void setSwimming(boolean swimming) { }
|
||||
@Override public void setSwimming(boolean swimming) {}
|
||||
|
||||
// Methods from Entity class
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void setGlowing(boolean flag) { }
|
||||
@Override public void setGravity(boolean gravity) { }
|
||||
@Override public void setInvulnerable(boolean flag) { }
|
||||
@Override public void setMomentum(Vector value) { }
|
||||
@Override public void setSilent(boolean flag) { }
|
||||
@Override public void setTicksLived(int value) { }
|
||||
@Override public void setPersistent(boolean flag) { }
|
||||
@Override public void setRotation(float yaw, float pitch) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
@Override public void setGlowing(boolean flag) {}
|
||||
@Override public void setGravity(boolean gravity) {}
|
||||
@Override public void setInvulnerable(boolean flag) {}
|
||||
@Override public void setMomentum(Vector value) {}
|
||||
@Override public void setSilent(boolean flag) {}
|
||||
@Override public void setTicksLived(int value) {}
|
||||
@Override public void setPersistent(boolean flag) {}
|
||||
@Override public void setRotation(float yaw, float pitch) {}
|
||||
|
||||
|
||||
}
|
||||
|
@ -28,29 +28,29 @@ public class CraftNMSItem extends CraftItem {
|
||||
}
|
||||
|
||||
// Methods from Item class
|
||||
@Override public void setItemStack(ItemStack stack) { }
|
||||
@Override public void setPickupDelay(int delay) { }
|
||||
@Override public void setItemStack(ItemStack stack) {}
|
||||
@Override public void setPickupDelay(int delay) {}
|
||||
|
||||
// Methods from Entity class
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void setGlowing(boolean flag) { }
|
||||
@Override public void setGravity(boolean gravity) { }
|
||||
@Override public void setInvulnerable(boolean flag) { }
|
||||
@Override public void setMomentum(Vector value) { }
|
||||
@Override public void setSilent(boolean flag) { }
|
||||
@Override public void setTicksLived(int value) { }
|
||||
@Override public void setPersistent(boolean flag) { }
|
||||
@Override public void setRotation(float yaw, float pitch) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
@Override public void setGlowing(boolean flag) {}
|
||||
@Override public void setGravity(boolean gravity) {}
|
||||
@Override public void setInvulnerable(boolean flag) {}
|
||||
@Override public void setMomentum(Vector value) {}
|
||||
@Override public void setSilent(boolean flag) {}
|
||||
@Override public void setTicksLived(int value) {}
|
||||
@Override public void setPersistent(boolean flag) {}
|
||||
@Override public void setRotation(float yaw, float pitch) {}
|
||||
|
||||
}
|
||||
|
@ -32,45 +32,45 @@ public class CraftNMSSlime extends CraftSlime {
|
||||
}
|
||||
|
||||
// Methods from Slime class
|
||||
@Override public void setSize(int size) { }
|
||||
@Override public void setTarget(LivingEntity target) { }
|
||||
@Override public void setSize(int size) {}
|
||||
@Override public void setTarget(LivingEntity target) {}
|
||||
|
||||
// Methods from Mob class
|
||||
@Override public void setLootTable(LootTable table) { }
|
||||
@Override public void setSeed(long seed) { }
|
||||
@Override public void setLootTable(LootTable table) {}
|
||||
@Override public void setSeed(long seed) {}
|
||||
|
||||
// Methods from LivingEntity class
|
||||
@Override public boolean addPotionEffect(PotionEffect effect) { return false; }
|
||||
@Override public boolean addPotionEffect(PotionEffect effect, boolean param) { return false; }
|
||||
@Override public boolean addPotionEffects(Collection<PotionEffect> effects) { return false; }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) { }
|
||||
@Override public void setAI(boolean ai) { }
|
||||
@Override public void setCanPickupItems(boolean pickup) { }
|
||||
@Override public void setCollidable(boolean collidable) { }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) {}
|
||||
@Override public void setAI(boolean ai) {}
|
||||
@Override public void setCanPickupItems(boolean pickup) {}
|
||||
@Override public void setCollidable(boolean collidable) {}
|
||||
@Override public void setGliding(boolean gliding) { }
|
||||
@Override public boolean setLeashHolder(Entity holder) { return false; }
|
||||
@Override public void setSwimming(boolean swimming) { }
|
||||
@Override public void setSwimming(boolean swimming) {}
|
||||
|
||||
// Methods from Entity class
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void setGlowing(boolean flag) { }
|
||||
@Override public void setGravity(boolean gravity) { }
|
||||
@Override public void setInvulnerable(boolean flag) { }
|
||||
@Override public void setMomentum(Vector value) { }
|
||||
@Override public void setSilent(boolean flag) { }
|
||||
@Override public void setTicksLived(int value) { }
|
||||
@Override public void setPersistent(boolean flag) { }
|
||||
@Override public void setRotation(float yaw, float pitch) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
@Override public void setGlowing(boolean flag) {}
|
||||
@Override public void setGravity(boolean gravity) {}
|
||||
@Override public void setInvulnerable(boolean flag) {}
|
||||
@Override public void setMomentum(Vector value) {}
|
||||
@Override public void setSilent(boolean flag) {}
|
||||
@Override public void setTicksLived(int value) {}
|
||||
@Override public void setPersistent(boolean flag) {}
|
||||
@Override public void setRotation(float yaw, float pitch) {}
|
||||
|
||||
}
|
||||
|
@ -5,12 +5,17 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.nms.v1_16_R1;
|
||||
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.Utils;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.PacketController;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntity;
|
||||
import net.minecraft.server.v1_16_R1.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_16_R1.DamageSource;
|
||||
import net.minecraft.server.v1_16_R1.Entity;
|
||||
import net.minecraft.server.v1_16_R1.EntityArmorStand;
|
||||
import net.minecraft.server.v1_16_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_16_R1.EntityPlayer;
|
||||
@ -30,13 +35,18 @@ import org.bukkit.craftbukkit.v1_16_R1.util.CraftChatMessage;
|
||||
|
||||
public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand {
|
||||
|
||||
private final StandardHologramLine parentPiece;
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle");
|
||||
|
||||
private final StandardHologramLine parentHologramLine;
|
||||
private final PacketController packetController;
|
||||
private CraftEntity customBukkitEntity;
|
||||
private String customName;
|
||||
|
||||
public EntityNMSArmorStand(World world, StandardHologramLine parentPiece, PacketController packetController) {
|
||||
public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, PacketController packetController) {
|
||||
super(EntityTypes.ARMOR_STAND, world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
this.packetController = packetController;
|
||||
|
||||
super.setInvisible(true);
|
||||
super.setSmall(true);
|
||||
super.setArms(false);
|
||||
@ -44,11 +54,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
super.setBasePlate(true);
|
||||
super.setMarker(true);
|
||||
super.collides = false;
|
||||
|
||||
this.parentPiece = parentPiece;
|
||||
this.packetController = packetController;
|
||||
super.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -56,8 +63,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
// Disable normal ticking for this entity.
|
||||
|
||||
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
|
||||
if (this.onGround) {
|
||||
this.onGround = false;
|
||||
if (super.onGround) {
|
||||
super.onGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,8 +73,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
// Disable normal ticking for this entity.
|
||||
|
||||
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
|
||||
if (this.onGround) {
|
||||
this.onGround = false;
|
||||
if (super.onGround) {
|
||||
super.onGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,7 +155,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
|
||||
@Override
|
||||
public void a(AxisAlignedBB boundingBox) {
|
||||
// Do not change it!
|
||||
// Prevent bounding box from being changed
|
||||
}
|
||||
|
||||
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
|
||||
@ -206,9 +213,9 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
private void broadcastLocationPacketNMS() {
|
||||
PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this);
|
||||
|
||||
for (Object obj : super.world.getPlayers()) {
|
||||
if (obj instanceof EntityPlayer) {
|
||||
EntityPlayer nmsPlayer = (EntityPlayer) obj;
|
||||
for (Object humanEntity : super.world.getPlayers()) {
|
||||
if (humanEntity instanceof EntityPlayer) {
|
||||
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
|
||||
|
||||
double distanceSquared = Utils.square(nmsPlayer.locX() - super.locX()) + Utils.square(nmsPlayer.locZ() - super.locZ());
|
||||
if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) {
|
||||
@ -218,6 +225,21 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerNMS(NMSEntity passenger) {
|
||||
Preconditions.checkArgument(passenger instanceof Entity);
|
||||
Entity passengerEntity = (Entity) passenger;
|
||||
Preconditions.checkArgument(passengerEntity.getVehicle() == null);
|
||||
Preconditions.checkState(super.passengers.isEmpty());
|
||||
|
||||
try {
|
||||
VEHICLE_FIELD.set(passenger, this);
|
||||
this.passengers.add(this);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
DebugLogger.cannotSetPassenger(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDeadNMS() {
|
||||
return super.dead;
|
||||
@ -230,11 +252,12 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getBukkitEntityNMS() {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,16 +5,12 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.nms.v1_16_R1;
|
||||
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSCommons;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardItemLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSCommons;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import net.minecraft.server.v1_16_R1.Blocks;
|
||||
import net.minecraft.server.v1_16_R1.DamageSource;
|
||||
import net.minecraft.server.v1_16_R1.Entity;
|
||||
import net.minecraft.server.v1_16_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_16_R1.EntityItem;
|
||||
import net.minecraft.server.v1_16_R1.EntityPlayer;
|
||||
@ -29,15 +25,14 @@ import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack;
|
||||
|
||||
public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle");
|
||||
|
||||
private final StandardItemLine parentPiece;
|
||||
private final StandardItemLine parentHologramLine;
|
||||
private CraftEntity customBukkitEntity;
|
||||
|
||||
public EntityNMSItem(World world, StandardItemLine piece) {
|
||||
public EntityNMSItem(World world, StandardItemLine parentHologramLine) {
|
||||
super(EntityTypes.ITEM, world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
|
||||
super.pickupDelay = 32767; // Lock the item pickup delay, also prevents entities from picking up the item
|
||||
this.parentPiece = piece;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -65,7 +60,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
}
|
||||
|
||||
if (human instanceof EntityPlayer) {
|
||||
parentPiece.onPickup(((EntityPlayer) human).getBukkitEntity());
|
||||
parentHologramLine.onPickup(((EntityPlayer) human).getBukkitEntity());
|
||||
// It is never added to the inventory.
|
||||
}
|
||||
}
|
||||
@ -155,7 +150,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
|
||||
@Override
|
||||
public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) {
|
||||
ItemStack newItem = CraftItemStack.asNMSCopy(stack); // ItemStack.a is returned if the stack is null, invalid or the material is not an Item
|
||||
ItemStack newItem = CraftItemStack.asNMSCopy(stack); // ItemStack.b is returned if the stack is not valid
|
||||
|
||||
if (newItem == null || newItem == ItemStack.b) {
|
||||
newItem = new ItemStack(Blocks.BEDROCK);
|
||||
@ -170,10 +165,10 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
}
|
||||
|
||||
NBTTagList tagList = new NBTTagList();
|
||||
tagList.add(NBTTagString.a(NMSCommons.ANTI_STACK_LORE)); // Antistack lore
|
||||
tagList.add(NBTTagString.a(NMSCommons.ANTI_STACK_LORE));
|
||||
display.set("Lore", tagList);
|
||||
|
||||
setItemStack(newItem);
|
||||
super.setItemStack(newItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -183,7 +178,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -191,33 +186,9 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerOfNMS(NMSEntityBase vehicleBase) {
|
||||
if (!(vehicleBase instanceof Entity)) {
|
||||
// It should never dismount
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = (Entity) vehicleBase;
|
||||
|
||||
try {
|
||||
if (super.getVehicle() != null) {
|
||||
Entity oldVehicle = super.getVehicle();
|
||||
VEHICLE_FIELD.set(this, null);
|
||||
oldVehicle.passengers.remove(this);
|
||||
}
|
||||
|
||||
VEHICLE_FIELD.set(this, entity);
|
||||
entity.passengers.clear();
|
||||
entity.passengers.add(this);
|
||||
|
||||
} catch (Throwable t) {
|
||||
DebugLogger.cannotSetPassenger(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getRawItemStack() {
|
||||
return super.getItemStack();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,13 +6,9 @@
|
||||
package me.filoghost.holographicdisplays.nms.v1_16_R1;
|
||||
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSSlime;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import net.minecraft.server.v1_16_R1.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_16_R1.DamageSource;
|
||||
import net.minecraft.server.v1_16_R1.Entity;
|
||||
import net.minecraft.server.v1_16_R1.EntityDamageSource;
|
||||
import net.minecraft.server.v1_16_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_16_R1.EntitySlime;
|
||||
@ -27,19 +23,18 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
|
||||
public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle");
|
||||
|
||||
private final StandardHologramLine parentPiece;
|
||||
private final StandardHologramLine parentHologramLine;
|
||||
private CraftEntity customBukkitEntity;
|
||||
|
||||
public EntityNMSSlime(World world, StandardHologramLine parentPiece) {
|
||||
public EntityNMSSlime(World world, StandardHologramLine parentHologramLine) {
|
||||
super(EntityTypes.SLIME, world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
|
||||
super.persistent = true;
|
||||
super.collides = false;
|
||||
a(0.0F, 0.0F);
|
||||
setSize(1, false);
|
||||
setInvisible(true);
|
||||
this.parentPiece = parentPiece;
|
||||
super.a(0.0F, 0.0F);
|
||||
super.setSize(1, false);
|
||||
super.setInvisible(true);
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
}
|
||||
|
||||
@ -61,7 +56,7 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
|
||||
@Override
|
||||
public void a(AxisAlignedBB boundingBox) {
|
||||
// Do not change it!
|
||||
// Prevent bounding box from being changed
|
||||
}
|
||||
|
||||
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
|
||||
@ -177,36 +172,12 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getBukkitEntityNMS() {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerOfNMS(NMSEntityBase vehicleBase) {
|
||||
if (!(vehicleBase instanceof Entity)) {
|
||||
// It should never dismount
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = (Entity) vehicleBase;
|
||||
|
||||
try {
|
||||
if (super.getVehicle() != null) {
|
||||
Entity oldVehicle = super.getVehicle();
|
||||
VEHICLE_FIELD.set(this, null);
|
||||
oldVehicle.passengers.remove(this);
|
||||
}
|
||||
|
||||
VEHICLE_FIELD.set(this, entity);
|
||||
entity.passengers.clear();
|
||||
entity.passengers.add(this);
|
||||
|
||||
} catch (Throwable t) {
|
||||
DebugLogger.cannotSetPassenger(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -120,6 +120,5 @@ public class NullBoundingBox extends AxisAlignedBB {
|
||||
public Vec3D f() {
|
||||
return Vec3D.a;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -9,16 +9,16 @@ import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.fcommons.reflection.ClassToken;
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.fcommons.reflection.ReflectMethod;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.nms.CustomNameEditor;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardItemLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.ChatComponentCustomNameEditor;
|
||||
import me.filoghost.holographicdisplays.core.nms.CustomNameEditor;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSManager;
|
||||
import me.filoghost.holographicdisplays.core.nms.PacketController;
|
||||
import me.filoghost.holographicdisplays.core.nms.SpawnFailedException;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntity;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardItemLine;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import net.minecraft.server.v1_16_R1.ChatComponentText;
|
||||
import net.minecraft.server.v1_16_R1.Entity;
|
||||
import net.minecraft.server.v1_16_R1.EntityTypes;
|
||||
@ -70,40 +70,34 @@ public class VersionNMSManager implements NMSManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSItem spawnNMSItem(World bukkitWorld, double x, double y, double z, StandardItemLine parentPiece, ItemStack stack) {
|
||||
public NMSItem spawnNMSItem(World bukkitWorld, double x, double y, double z, StandardItemLine parentPiece, ItemStack stack) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece);
|
||||
customItem.setLocationNMS(x, y, z);
|
||||
customItem.setItemStackNMS(stack);
|
||||
if (!addEntityToWorld(nmsWorld, customItem)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return customItem;
|
||||
EntityNMSItem item = new EntityNMSItem(nmsWorld, parentPiece);
|
||||
item.setLocationNMS(x, y, z);
|
||||
item.setItemStackNMS(stack);
|
||||
addEntityToWorld(nmsWorld, item);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityNMSSlime spawnNMSSlime(World bukkitWorld, double x, double y, double z, StandardHologramLine parentPiece) {
|
||||
public EntityNMSSlime spawnNMSSlime(World bukkitWorld, double x, double y, double z, StandardHologramLine parentPiece) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece);
|
||||
touchSlime.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, touchSlime)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return touchSlime;
|
||||
EntityNMSSlime slime = new EntityNMSSlime(nmsWorld, parentPiece);
|
||||
slime.setLocationNMS(x, y, z);
|
||||
addEntityToWorld(nmsWorld, slime);
|
||||
return slime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSArmorStand spawnNMSArmorStand(World world, double x, double y, double z, StandardHologramLine parentPiece) {
|
||||
public NMSArmorStand spawnNMSArmorStand(World world, double x, double y, double z, StandardHologramLine parentPiece) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return invisibleArmorStand;
|
||||
EntityNMSArmorStand armorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
armorStand.setLocationNMS(x, y, z);
|
||||
addEntityToWorld(nmsWorld, armorStand);
|
||||
return armorStand;
|
||||
}
|
||||
|
||||
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) {
|
||||
private void addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) throws SpawnFailedException {
|
||||
Preconditions.checkState(Bukkit.isPrimaryThread(), "Async entity add");
|
||||
|
||||
final int chunkX = MathHelper.floor(nmsEntity.locX() / 16.0);
|
||||
@ -112,49 +106,48 @@ public class VersionNMSManager implements NMSManager {
|
||||
if (!nmsWorld.isChunkLoaded(chunkX, chunkZ)) {
|
||||
// This should never happen
|
||||
nmsEntity.dead = true;
|
||||
return false;
|
||||
throw new SpawnFailedException(SpawnFailedException.CHUNK_NOT_LOADED);
|
||||
}
|
||||
|
||||
nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity);
|
||||
try {
|
||||
REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity);
|
||||
return true;
|
||||
} catch (ReflectiveOperationException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
nmsEntity.dead = true;
|
||||
throw new SpawnFailedException(SpawnFailedException.REGISTER_ENTITY_FAIL, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase;
|
||||
return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
public NMSEntity getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle();
|
||||
|
||||
if (nmsEntity instanceof NMSEntityBase) {
|
||||
return ((NMSEntityBase) nmsEntity);
|
||||
if (nmsEntity instanceof NMSEntity) {
|
||||
return ((NMSEntity) nmsEntity);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) {
|
||||
public NMSEntity getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
Entity nmsEntity = nmsWorld.getEntity(entityID);
|
||||
|
||||
if (nmsEntity instanceof NMSEntityBase) {
|
||||
return ((NMSEntityBase) nmsEntity);
|
||||
if (nmsEntity instanceof NMSEntity) {
|
||||
return ((NMSEntity) nmsEntity);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomNameEditor getCustomNameChatComponentEditor() {
|
||||
public CustomNameEditor getCustomNameEditor() {
|
||||
return VersionChatComponentCustomNameEditor.INSTANCE;
|
||||
}
|
||||
|
||||
|
@ -32,56 +32,56 @@ public class CraftNMSArmorStand extends CraftArmorStand {
|
||||
}
|
||||
|
||||
// Methods from ArmorStand class
|
||||
@Override public void setArms(boolean arms) { }
|
||||
@Override public void setBasePlate(boolean basePlate) { }
|
||||
@Override public void setBodyPose(EulerAngle pose) { }
|
||||
@Override public void setBoots(ItemStack item) { }
|
||||
@Override public void setChestplate(ItemStack item) { }
|
||||
@Override public void setHeadPose(EulerAngle pose) { }
|
||||
@Override public void setHelmet(ItemStack item) { }
|
||||
@Override public void setItemInHand(ItemStack item) { }
|
||||
@Override public void setLeftArmPose(EulerAngle pose) { }
|
||||
@Override public void setLeftLegPose(EulerAngle pose) { }
|
||||
@Override public void setLeggings(ItemStack item) { }
|
||||
@Override public void setRightArmPose(EulerAngle pose) { }
|
||||
@Override public void setRightLegPose(EulerAngle pose) { }
|
||||
@Override public void setSmall(boolean small) { }
|
||||
@Override public void setVisible(boolean visible) { }
|
||||
@Override public void setMarker(boolean marker) { }
|
||||
@Override public void setArms(boolean arms) {}
|
||||
@Override public void setBasePlate(boolean basePlate) {}
|
||||
@Override public void setBodyPose(EulerAngle pose) {}
|
||||
@Override public void setBoots(ItemStack item) {}
|
||||
@Override public void setChestplate(ItemStack item) {}
|
||||
@Override public void setHeadPose(EulerAngle pose) {}
|
||||
@Override public void setHelmet(ItemStack item) {}
|
||||
@Override public void setItemInHand(ItemStack item) {}
|
||||
@Override public void setLeftArmPose(EulerAngle pose) {}
|
||||
@Override public void setLeftLegPose(EulerAngle pose) {}
|
||||
@Override public void setLeggings(ItemStack item) {}
|
||||
@Override public void setRightArmPose(EulerAngle pose) {}
|
||||
@Override public void setRightLegPose(EulerAngle pose) {}
|
||||
@Override public void setSmall(boolean small) {}
|
||||
@Override public void setVisible(boolean visible) {}
|
||||
@Override public void setMarker(boolean marker) {}
|
||||
|
||||
// Methods from LivingEntity class
|
||||
@Override public boolean addPotionEffect(PotionEffect effect) { return false; }
|
||||
@Override public boolean addPotionEffect(PotionEffect effect, boolean param) { return false; }
|
||||
@Override public boolean addPotionEffects(Collection<PotionEffect> effects) { return false; }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) { }
|
||||
@Override public void setAI(boolean ai) { }
|
||||
@Override public void setCanPickupItems(boolean pickup) { }
|
||||
@Override public void setCollidable(boolean collidable) { }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) {}
|
||||
@Override public void setAI(boolean ai) {}
|
||||
@Override public void setCanPickupItems(boolean pickup) {}
|
||||
@Override public void setCollidable(boolean collidable) {}
|
||||
@Override public void setGliding(boolean gliding) { }
|
||||
@Override public boolean setLeashHolder(Entity holder) { return false; }
|
||||
@Override public void setSwimming(boolean swimming) { }
|
||||
@Override public void setSwimming(boolean swimming) {}
|
||||
|
||||
// Methods from Entity class
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void setGlowing(boolean flag) { }
|
||||
@Override public void setGravity(boolean gravity) { }
|
||||
@Override public void setInvulnerable(boolean flag) { }
|
||||
@Override public void setMomentum(Vector value) { }
|
||||
@Override public void setSilent(boolean flag) { }
|
||||
@Override public void setTicksLived(int value) { }
|
||||
@Override public void setPersistent(boolean flag) { }
|
||||
@Override public void setRotation(float yaw, float pitch) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
@Override public void setGlowing(boolean flag) {}
|
||||
@Override public void setGravity(boolean gravity) {}
|
||||
@Override public void setInvulnerable(boolean flag) {}
|
||||
@Override public void setMomentum(Vector value) {}
|
||||
@Override public void setSilent(boolean flag) {}
|
||||
@Override public void setTicksLived(int value) {}
|
||||
@Override public void setPersistent(boolean flag) {}
|
||||
@Override public void setRotation(float yaw, float pitch) {}
|
||||
|
||||
|
||||
}
|
||||
|
@ -28,29 +28,29 @@ public class CraftNMSItem extends CraftItem {
|
||||
}
|
||||
|
||||
// Methods from Item class
|
||||
@Override public void setItemStack(ItemStack stack) { }
|
||||
@Override public void setPickupDelay(int delay) { }
|
||||
@Override public void setItemStack(ItemStack stack) {}
|
||||
@Override public void setPickupDelay(int delay) {}
|
||||
|
||||
// Methods from Entity class
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void setGlowing(boolean flag) { }
|
||||
@Override public void setGravity(boolean gravity) { }
|
||||
@Override public void setInvulnerable(boolean flag) { }
|
||||
@Override public void setMomentum(Vector value) { }
|
||||
@Override public void setSilent(boolean flag) { }
|
||||
@Override public void setTicksLived(int value) { }
|
||||
@Override public void setPersistent(boolean flag) { }
|
||||
@Override public void setRotation(float yaw, float pitch) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
@Override public void setGlowing(boolean flag) {}
|
||||
@Override public void setGravity(boolean gravity) {}
|
||||
@Override public void setInvulnerable(boolean flag) {}
|
||||
@Override public void setMomentum(Vector value) {}
|
||||
@Override public void setSilent(boolean flag) {}
|
||||
@Override public void setTicksLived(int value) {}
|
||||
@Override public void setPersistent(boolean flag) {}
|
||||
@Override public void setRotation(float yaw, float pitch) {}
|
||||
|
||||
}
|
||||
|
@ -32,45 +32,45 @@ public class CraftNMSSlime extends CraftSlime {
|
||||
}
|
||||
|
||||
// Methods from Slime class
|
||||
@Override public void setSize(int size) { }
|
||||
@Override public void setTarget(LivingEntity target) { }
|
||||
@Override public void setSize(int size) {}
|
||||
@Override public void setTarget(LivingEntity target) {}
|
||||
|
||||
// Methods from Mob class
|
||||
@Override public void setLootTable(LootTable table) { }
|
||||
@Override public void setSeed(long seed) { }
|
||||
@Override public void setLootTable(LootTable table) {}
|
||||
@Override public void setSeed(long seed) {}
|
||||
|
||||
// Methods from LivingEntity class
|
||||
@Override public boolean addPotionEffect(PotionEffect effect) { return false; }
|
||||
@Override public boolean addPotionEffect(PotionEffect effect, boolean param) { return false; }
|
||||
@Override public boolean addPotionEffects(Collection<PotionEffect> effects) { return false; }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) { }
|
||||
@Override public void setAI(boolean ai) { }
|
||||
@Override public void setCanPickupItems(boolean pickup) { }
|
||||
@Override public void setCollidable(boolean collidable) { }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) {}
|
||||
@Override public void setAI(boolean ai) {}
|
||||
@Override public void setCanPickupItems(boolean pickup) {}
|
||||
@Override public void setCollidable(boolean collidable) {}
|
||||
@Override public void setGliding(boolean gliding) { }
|
||||
@Override public boolean setLeashHolder(Entity holder) { return false; }
|
||||
@Override public void setSwimming(boolean swimming) { }
|
||||
@Override public void setSwimming(boolean swimming) {}
|
||||
|
||||
// Methods from Entity class
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void setGlowing(boolean flag) { }
|
||||
@Override public void setGravity(boolean gravity) { }
|
||||
@Override public void setInvulnerable(boolean flag) { }
|
||||
@Override public void setMomentum(Vector value) { }
|
||||
@Override public void setSilent(boolean flag) { }
|
||||
@Override public void setTicksLived(int value) { }
|
||||
@Override public void setPersistent(boolean flag) { }
|
||||
@Override public void setRotation(float yaw, float pitch) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
@Override public void setGlowing(boolean flag) {}
|
||||
@Override public void setGravity(boolean gravity) {}
|
||||
@Override public void setInvulnerable(boolean flag) {}
|
||||
@Override public void setMomentum(Vector value) {}
|
||||
@Override public void setSilent(boolean flag) {}
|
||||
@Override public void setTicksLived(int value) {}
|
||||
@Override public void setPersistent(boolean flag) {}
|
||||
@Override public void setRotation(float yaw, float pitch) {}
|
||||
|
||||
}
|
||||
|
@ -5,12 +5,17 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.nms.v1_16_R2;
|
||||
|
||||
import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.Utils;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.PacketController;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.core.Utils;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntity;
|
||||
import net.minecraft.server.v1_16_R2.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_16_R2.DamageSource;
|
||||
import net.minecraft.server.v1_16_R2.Entity;
|
||||
import net.minecraft.server.v1_16_R2.EntityArmorStand;
|
||||
import net.minecraft.server.v1_16_R2.EntityHuman;
|
||||
import net.minecraft.server.v1_16_R2.EntityPlayer;
|
||||
@ -30,13 +35,18 @@ import org.bukkit.craftbukkit.v1_16_R2.util.CraftChatMessage;
|
||||
|
||||
public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand {
|
||||
|
||||
private final StandardHologramLine parentPiece;
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle");
|
||||
|
||||
private final StandardHologramLine parentHologramLine;
|
||||
private final PacketController packetController;
|
||||
private CraftEntity customBukkitEntity;
|
||||
private String customName;
|
||||
|
||||
public EntityNMSArmorStand(World world, StandardHologramLine parentPiece, PacketController packetController) {
|
||||
public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, PacketController packetController) {
|
||||
super(EntityTypes.ARMOR_STAND, world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
this.packetController = packetController;
|
||||
|
||||
super.setInvisible(true);
|
||||
super.setSmall(true);
|
||||
super.setArms(false);
|
||||
@ -44,11 +54,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
super.setBasePlate(true);
|
||||
super.setMarker(true);
|
||||
super.collides = false;
|
||||
|
||||
this.parentPiece = parentPiece;
|
||||
this.packetController = packetController;
|
||||
super.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -56,8 +63,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
// Disable normal ticking for this entity.
|
||||
|
||||
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
|
||||
if (this.onGround) {
|
||||
this.onGround = false;
|
||||
if (super.onGround) {
|
||||
super.onGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,8 +73,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
// Disable normal ticking for this entity.
|
||||
|
||||
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
|
||||
if (this.onGround) {
|
||||
this.onGround = false;
|
||||
if (super.onGround) {
|
||||
super.onGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,7 +155,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
|
||||
@Override
|
||||
public void a(AxisAlignedBB boundingBox) {
|
||||
// Do not change it!
|
||||
// Prevent bounding box from being changed
|
||||
}
|
||||
|
||||
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
|
||||
@ -206,9 +213,9 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
private void broadcastLocationPacketNMS() {
|
||||
PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this);
|
||||
|
||||
for (Object obj : super.world.getPlayers()) {
|
||||
if (obj instanceof EntityPlayer) {
|
||||
EntityPlayer nmsPlayer = (EntityPlayer) obj;
|
||||
for (Object humanEntity : super.world.getPlayers()) {
|
||||
if (humanEntity instanceof EntityPlayer) {
|
||||
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
|
||||
|
||||
double distanceSquared = Utils.square(nmsPlayer.locX() - super.locX()) + Utils.square(nmsPlayer.locZ() - super.locZ());
|
||||
if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) {
|
||||
@ -218,6 +225,21 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerNMS(NMSEntity passenger) {
|
||||
Preconditions.checkArgument(passenger instanceof Entity);
|
||||
Entity passengerEntity = (Entity) passenger;
|
||||
Preconditions.checkArgument(passengerEntity.getVehicle() == null);
|
||||
Preconditions.checkState(super.passengers.isEmpty());
|
||||
|
||||
try {
|
||||
VEHICLE_FIELD.set(passenger, this);
|
||||
this.passengers.add(this);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
DebugLogger.cannotSetPassenger(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDeadNMS() {
|
||||
return super.dead;
|
||||
@ -230,11 +252,12 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getBukkitEntityNMS() {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,16 +5,12 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.nms.v1_16_R2;
|
||||
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSCommons;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardItemLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSCommons;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import net.minecraft.server.v1_16_R2.Blocks;
|
||||
import net.minecraft.server.v1_16_R2.DamageSource;
|
||||
import net.minecraft.server.v1_16_R2.Entity;
|
||||
import net.minecraft.server.v1_16_R2.EntityHuman;
|
||||
import net.minecraft.server.v1_16_R2.EntityItem;
|
||||
import net.minecraft.server.v1_16_R2.EntityPlayer;
|
||||
@ -29,15 +25,14 @@ import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack;
|
||||
|
||||
public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle");
|
||||
|
||||
private final StandardItemLine parentPiece;
|
||||
private final StandardItemLine parentHologramLine;
|
||||
private CraftEntity customBukkitEntity;
|
||||
|
||||
public EntityNMSItem(World world, StandardItemLine piece) {
|
||||
public EntityNMSItem(World world, StandardItemLine parentHologramLine) {
|
||||
super(EntityTypes.ITEM, world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
|
||||
super.pickupDelay = 32767; // Lock the item pickup delay, also prevents entities from picking up the item
|
||||
this.parentPiece = piece;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -65,7 +60,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
}
|
||||
|
||||
if (human instanceof EntityPlayer) {
|
||||
parentPiece.onPickup(((EntityPlayer) human).getBukkitEntity());
|
||||
parentHologramLine.onPickup(((EntityPlayer) human).getBukkitEntity());
|
||||
// It is never added to the inventory.
|
||||
}
|
||||
}
|
||||
@ -155,7 +150,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
|
||||
@Override
|
||||
public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) {
|
||||
ItemStack newItem = CraftItemStack.asNMSCopy(stack); // ItemStack.a is returned if the stack is null, invalid or the material is not an Item
|
||||
ItemStack newItem = CraftItemStack.asNMSCopy(stack); // ItemStack.b is returned if the stack is not valid
|
||||
|
||||
if (newItem == null || newItem == ItemStack.b) {
|
||||
newItem = new ItemStack(Blocks.BEDROCK);
|
||||
@ -170,10 +165,10 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
}
|
||||
|
||||
NBTTagList tagList = new NBTTagList();
|
||||
tagList.add(NBTTagString.a(NMSCommons.ANTI_STACK_LORE)); // Antistack lore
|
||||
tagList.add(NBTTagString.a(NMSCommons.ANTI_STACK_LORE));
|
||||
display.set("Lore", tagList);
|
||||
|
||||
setItemStack(newItem);
|
||||
super.setItemStack(newItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -183,7 +178,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -191,33 +186,9 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerOfNMS(NMSEntityBase vehicleBase) {
|
||||
if (!(vehicleBase instanceof Entity)) {
|
||||
// It should never dismount
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = (Entity) vehicleBase;
|
||||
|
||||
try {
|
||||
if (super.getVehicle() != null) {
|
||||
Entity oldVehicle = super.getVehicle();
|
||||
VEHICLE_FIELD.set(this, null);
|
||||
oldVehicle.passengers.remove(this);
|
||||
}
|
||||
|
||||
VEHICLE_FIELD.set(this, entity);
|
||||
entity.passengers.clear();
|
||||
entity.passengers.add(this);
|
||||
|
||||
} catch (Throwable t) {
|
||||
DebugLogger.cannotSetPassenger(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getRawItemStack() {
|
||||
return super.getItemStack();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,13 +6,9 @@
|
||||
package me.filoghost.holographicdisplays.nms.v1_16_R2;
|
||||
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSSlime;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import net.minecraft.server.v1_16_R2.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_16_R2.DamageSource;
|
||||
import net.minecraft.server.v1_16_R2.Entity;
|
||||
import net.minecraft.server.v1_16_R2.EntityDamageSource;
|
||||
import net.minecraft.server.v1_16_R2.EntityPlayer;
|
||||
import net.minecraft.server.v1_16_R2.EntitySlime;
|
||||
@ -27,19 +23,18 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
|
||||
public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle");
|
||||
|
||||
private final StandardHologramLine parentPiece;
|
||||
private final StandardHologramLine parentHologramLine;
|
||||
private CraftEntity customBukkitEntity;
|
||||
|
||||
public EntityNMSSlime(World world, StandardHologramLine parentPiece) {
|
||||
public EntityNMSSlime(World world, StandardHologramLine parentHologramLine) {
|
||||
super(EntityTypes.SLIME, world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
|
||||
super.persistent = true;
|
||||
super.collides = false;
|
||||
a(0.0F, 0.0F);
|
||||
setSize(1, false);
|
||||
setInvisible(true);
|
||||
this.parentPiece = parentPiece;
|
||||
super.a(0.0F, 0.0F);
|
||||
super.setSize(1, false);
|
||||
super.setInvisible(true);
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
}
|
||||
|
||||
@ -61,7 +56,7 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
|
||||
@Override
|
||||
public void a(AxisAlignedBB boundingBox) {
|
||||
// Do not change it!
|
||||
// Prevent bounding box from being changed
|
||||
}
|
||||
|
||||
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
|
||||
@ -177,36 +172,12 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getBukkitEntityNMS() {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerOfNMS(NMSEntityBase vehicleBase) {
|
||||
if (!(vehicleBase instanceof Entity)) {
|
||||
// It should never dismount
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = (Entity) vehicleBase;
|
||||
|
||||
try {
|
||||
if (super.getVehicle() != null) {
|
||||
Entity oldVehicle = super.getVehicle();
|
||||
VEHICLE_FIELD.set(this, null);
|
||||
oldVehicle.passengers.remove(this);
|
||||
}
|
||||
|
||||
VEHICLE_FIELD.set(this, entity);
|
||||
entity.passengers.clear();
|
||||
entity.passengers.add(this);
|
||||
|
||||
} catch (Throwable t) {
|
||||
DebugLogger.cannotSetPassenger(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -120,6 +120,5 @@ public class NullBoundingBox extends AxisAlignedBB {
|
||||
public Vec3D f() {
|
||||
return Vec3D.a;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -9,16 +9,16 @@ import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.fcommons.reflection.ClassToken;
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.fcommons.reflection.ReflectMethod;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.nms.CustomNameEditor;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardItemLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.ChatComponentCustomNameEditor;
|
||||
import me.filoghost.holographicdisplays.core.nms.CustomNameEditor;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSManager;
|
||||
import me.filoghost.holographicdisplays.core.nms.PacketController;
|
||||
import me.filoghost.holographicdisplays.core.nms.SpawnFailedException;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntity;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardItemLine;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import net.minecraft.server.v1_16_R2.ChatComponentText;
|
||||
import net.minecraft.server.v1_16_R2.Entity;
|
||||
import net.minecraft.server.v1_16_R2.EntityTypes;
|
||||
@ -61,40 +61,34 @@ public class VersionNMSManager implements NMSManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSItem spawnNMSItem(World bukkitWorld, double x, double y, double z, StandardItemLine parentPiece, ItemStack stack) {
|
||||
public NMSItem spawnNMSItem(World bukkitWorld, double x, double y, double z, StandardItemLine parentPiece, ItemStack stack) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece);
|
||||
customItem.setLocationNMS(x, y, z);
|
||||
customItem.setItemStackNMS(stack);
|
||||
if (!addEntityToWorld(nmsWorld, customItem)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return customItem;
|
||||
EntityNMSItem item = new EntityNMSItem(nmsWorld, parentPiece);
|
||||
item.setLocationNMS(x, y, z);
|
||||
item.setItemStackNMS(stack);
|
||||
addEntityToWorld(nmsWorld, item);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityNMSSlime spawnNMSSlime(World bukkitWorld, double x, double y, double z, StandardHologramLine parentPiece) {
|
||||
public EntityNMSSlime spawnNMSSlime(World bukkitWorld, double x, double y, double z, StandardHologramLine parentPiece) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece);
|
||||
touchSlime.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, touchSlime)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return touchSlime;
|
||||
EntityNMSSlime slime = new EntityNMSSlime(nmsWorld, parentPiece);
|
||||
slime.setLocationNMS(x, y, z);
|
||||
addEntityToWorld(nmsWorld, slime);
|
||||
return slime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSArmorStand spawnNMSArmorStand(World world, double x, double y, double z, StandardHologramLine parentPiece) {
|
||||
public NMSArmorStand spawnNMSArmorStand(World world, double x, double y, double z, StandardHologramLine parentPiece) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return invisibleArmorStand;
|
||||
EntityNMSArmorStand armorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
armorStand.setLocationNMS(x, y, z);
|
||||
addEntityToWorld(nmsWorld, armorStand);
|
||||
return armorStand;
|
||||
}
|
||||
|
||||
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) {
|
||||
private void addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) throws SpawnFailedException {
|
||||
Preconditions.checkState(Bukkit.isPrimaryThread(), "Async entity add");
|
||||
|
||||
final int chunkX = MathHelper.floor(nmsEntity.locX() / 16.0);
|
||||
@ -103,49 +97,48 @@ public class VersionNMSManager implements NMSManager {
|
||||
if (!nmsWorld.isChunkLoaded(chunkX, chunkZ)) {
|
||||
// This should never happen
|
||||
nmsEntity.dead = true;
|
||||
return false;
|
||||
throw new SpawnFailedException(SpawnFailedException.CHUNK_NOT_LOADED);
|
||||
}
|
||||
|
||||
nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity);
|
||||
try {
|
||||
REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity);
|
||||
return true;
|
||||
} catch (ReflectiveOperationException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
nmsEntity.dead = true;
|
||||
throw new SpawnFailedException(SpawnFailedException.REGISTER_ENTITY_FAIL, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase;
|
||||
return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
public NMSEntity getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle();
|
||||
|
||||
if (nmsEntity instanceof NMSEntityBase) {
|
||||
return ((NMSEntityBase) nmsEntity);
|
||||
if (nmsEntity instanceof NMSEntity) {
|
||||
return ((NMSEntity) nmsEntity);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) {
|
||||
public NMSEntity getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
Entity nmsEntity = nmsWorld.getEntity(entityID);
|
||||
|
||||
if (nmsEntity instanceof NMSEntityBase) {
|
||||
return ((NMSEntityBase) nmsEntity);
|
||||
if (nmsEntity instanceof NMSEntity) {
|
||||
return ((NMSEntity) nmsEntity);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomNameEditor getCustomNameChatComponentEditor() {
|
||||
public CustomNameEditor getCustomNameEditor() {
|
||||
return VersionChatComponentCustomNameEditor.INSTANCE;
|
||||
}
|
||||
|
||||
|
@ -32,56 +32,56 @@ public class CraftNMSArmorStand extends CraftArmorStand {
|
||||
}
|
||||
|
||||
// Methods from ArmorStand class
|
||||
@Override public void setArms(boolean arms) { }
|
||||
@Override public void setBasePlate(boolean basePlate) { }
|
||||
@Override public void setBodyPose(EulerAngle pose) { }
|
||||
@Override public void setBoots(ItemStack item) { }
|
||||
@Override public void setChestplate(ItemStack item) { }
|
||||
@Override public void setHeadPose(EulerAngle pose) { }
|
||||
@Override public void setHelmet(ItemStack item) { }
|
||||
@Override public void setItemInHand(ItemStack item) { }
|
||||
@Override public void setLeftArmPose(EulerAngle pose) { }
|
||||
@Override public void setLeftLegPose(EulerAngle pose) { }
|
||||
@Override public void setLeggings(ItemStack item) { }
|
||||
@Override public void setRightArmPose(EulerAngle pose) { }
|
||||
@Override public void setRightLegPose(EulerAngle pose) { }
|
||||
@Override public void setSmall(boolean small) { }
|
||||
@Override public void setVisible(boolean visible) { }
|
||||
@Override public void setMarker(boolean marker) { }
|
||||
@Override public void setArms(boolean arms) {}
|
||||
@Override public void setBasePlate(boolean basePlate) {}
|
||||
@Override public void setBodyPose(EulerAngle pose) {}
|
||||
@Override public void setBoots(ItemStack item) {}
|
||||
@Override public void setChestplate(ItemStack item) {}
|
||||
@Override public void setHeadPose(EulerAngle pose) {}
|
||||
@Override public void setHelmet(ItemStack item) {}
|
||||
@Override public void setItemInHand(ItemStack item) {}
|
||||
@Override public void setLeftArmPose(EulerAngle pose) {}
|
||||
@Override public void setLeftLegPose(EulerAngle pose) {}
|
||||
@Override public void setLeggings(ItemStack item) {}
|
||||
@Override public void setRightArmPose(EulerAngle pose) {}
|
||||
@Override public void setRightLegPose(EulerAngle pose) {}
|
||||
@Override public void setSmall(boolean small) {}
|
||||
@Override public void setVisible(boolean visible) {}
|
||||
@Override public void setMarker(boolean marker) {}
|
||||
|
||||
// Methods from LivingEntity class
|
||||
@Override public boolean addPotionEffect(PotionEffect effect) { return false; }
|
||||
@Override public boolean addPotionEffect(PotionEffect effect, boolean param) { return false; }
|
||||
@Override public boolean addPotionEffects(Collection<PotionEffect> effects) { return false; }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) { }
|
||||
@Override public void setAI(boolean ai) { }
|
||||
@Override public void setCanPickupItems(boolean pickup) { }
|
||||
@Override public void setCollidable(boolean collidable) { }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) {}
|
||||
@Override public void setAI(boolean ai) {}
|
||||
@Override public void setCanPickupItems(boolean pickup) {}
|
||||
@Override public void setCollidable(boolean collidable) {}
|
||||
@Override public void setGliding(boolean gliding) { }
|
||||
@Override public boolean setLeashHolder(Entity holder) { return false; }
|
||||
@Override public void setSwimming(boolean swimming) { }
|
||||
@Override public void setSwimming(boolean swimming) {}
|
||||
|
||||
// Methods from Entity class
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void setGlowing(boolean flag) { }
|
||||
@Override public void setGravity(boolean gravity) { }
|
||||
@Override public void setInvulnerable(boolean flag) { }
|
||||
@Override public void setMomentum(Vector value) { }
|
||||
@Override public void setSilent(boolean flag) { }
|
||||
@Override public void setTicksLived(int value) { }
|
||||
@Override public void setPersistent(boolean flag) { }
|
||||
@Override public void setRotation(float yaw, float pitch) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
@Override public void setGlowing(boolean flag) {}
|
||||
@Override public void setGravity(boolean gravity) {}
|
||||
@Override public void setInvulnerable(boolean flag) {}
|
||||
@Override public void setMomentum(Vector value) {}
|
||||
@Override public void setSilent(boolean flag) {}
|
||||
@Override public void setTicksLived(int value) {}
|
||||
@Override public void setPersistent(boolean flag) {}
|
||||
@Override public void setRotation(float yaw, float pitch) {}
|
||||
|
||||
|
||||
}
|
||||
|
@ -28,29 +28,29 @@ public class CraftNMSItem extends CraftItem {
|
||||
}
|
||||
|
||||
// Methods from Item class
|
||||
@Override public void setItemStack(ItemStack stack) { }
|
||||
@Override public void setPickupDelay(int delay) { }
|
||||
@Override public void setItemStack(ItemStack stack) {}
|
||||
@Override public void setPickupDelay(int delay) {}
|
||||
|
||||
// Methods from Entity class
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void setGlowing(boolean flag) { }
|
||||
@Override public void setGravity(boolean gravity) { }
|
||||
@Override public void setInvulnerable(boolean flag) { }
|
||||
@Override public void setMomentum(Vector value) { }
|
||||
@Override public void setSilent(boolean flag) { }
|
||||
@Override public void setTicksLived(int value) { }
|
||||
@Override public void setPersistent(boolean flag) { }
|
||||
@Override public void setRotation(float yaw, float pitch) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
@Override public void setGlowing(boolean flag) {}
|
||||
@Override public void setGravity(boolean gravity) {}
|
||||
@Override public void setInvulnerable(boolean flag) {}
|
||||
@Override public void setMomentum(Vector value) {}
|
||||
@Override public void setSilent(boolean flag) {}
|
||||
@Override public void setTicksLived(int value) {}
|
||||
@Override public void setPersistent(boolean flag) {}
|
||||
@Override public void setRotation(float yaw, float pitch) {}
|
||||
|
||||
}
|
||||
|
@ -32,45 +32,45 @@ public class CraftNMSSlime extends CraftSlime {
|
||||
}
|
||||
|
||||
// Methods from Slime class
|
||||
@Override public void setSize(int size) { }
|
||||
@Override public void setTarget(LivingEntity target) { }
|
||||
@Override public void setSize(int size) {}
|
||||
@Override public void setTarget(LivingEntity target) {}
|
||||
|
||||
// Methods from Mob class
|
||||
@Override public void setLootTable(LootTable table) { }
|
||||
@Override public void setSeed(long seed) { }
|
||||
@Override public void setLootTable(LootTable table) {}
|
||||
@Override public void setSeed(long seed) {}
|
||||
|
||||
// Methods from LivingEntity class
|
||||
@Override public boolean addPotionEffect(PotionEffect effect) { return false; }
|
||||
@Override public boolean addPotionEffect(PotionEffect effect, boolean param) { return false; }
|
||||
@Override public boolean addPotionEffects(Collection<PotionEffect> effects) { return false; }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) { }
|
||||
@Override public void setAI(boolean ai) { }
|
||||
@Override public void setCanPickupItems(boolean pickup) { }
|
||||
@Override public void setCollidable(boolean collidable) { }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) {}
|
||||
@Override public void setAI(boolean ai) {}
|
||||
@Override public void setCanPickupItems(boolean pickup) {}
|
||||
@Override public void setCollidable(boolean collidable) {}
|
||||
@Override public void setGliding(boolean gliding) { }
|
||||
@Override public boolean setLeashHolder(Entity holder) { return false; }
|
||||
@Override public void setSwimming(boolean swimming) { }
|
||||
@Override public void setSwimming(boolean swimming) {}
|
||||
|
||||
// Methods from Entity class
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void setGlowing(boolean flag) { }
|
||||
@Override public void setGravity(boolean gravity) { }
|
||||
@Override public void setInvulnerable(boolean flag) { }
|
||||
@Override public void setMomentum(Vector value) { }
|
||||
@Override public void setSilent(boolean flag) { }
|
||||
@Override public void setTicksLived(int value) { }
|
||||
@Override public void setPersistent(boolean flag) { }
|
||||
@Override public void setRotation(float yaw, float pitch) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
@Override public void setGlowing(boolean flag) {}
|
||||
@Override public void setGravity(boolean gravity) {}
|
||||
@Override public void setInvulnerable(boolean flag) {}
|
||||
@Override public void setMomentum(Vector value) {}
|
||||
@Override public void setSilent(boolean flag) {}
|
||||
@Override public void setTicksLived(int value) {}
|
||||
@Override public void setPersistent(boolean flag) {}
|
||||
@Override public void setRotation(float yaw, float pitch) {}
|
||||
|
||||
}
|
||||
|
@ -5,12 +5,17 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.nms.v1_16_R3;
|
||||
|
||||
import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.Utils;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.PacketController;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntity;
|
||||
import net.minecraft.server.v1_16_R3.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_16_R3.DamageSource;
|
||||
import net.minecraft.server.v1_16_R3.Entity;
|
||||
import net.minecraft.server.v1_16_R3.EntityArmorStand;
|
||||
import net.minecraft.server.v1_16_R3.EntityHuman;
|
||||
import net.minecraft.server.v1_16_R3.EntityPlayer;
|
||||
@ -30,13 +35,18 @@ import org.bukkit.craftbukkit.v1_16_R3.util.CraftChatMessage;
|
||||
|
||||
public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand {
|
||||
|
||||
private final StandardHologramLine parentPiece;
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle");
|
||||
|
||||
private final StandardHologramLine parentHologramLine;
|
||||
private final PacketController packetController;
|
||||
private CraftEntity customBukkitEntity;
|
||||
private String customName;
|
||||
|
||||
public EntityNMSArmorStand(World world, StandardHologramLine parentPiece, PacketController packetController) {
|
||||
public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, PacketController packetController) {
|
||||
super(EntityTypes.ARMOR_STAND, world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
this.packetController = packetController;
|
||||
|
||||
super.setInvisible(true);
|
||||
super.setSmall(true);
|
||||
super.setArms(false);
|
||||
@ -44,11 +54,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
super.setBasePlate(true);
|
||||
super.setMarker(true);
|
||||
super.collides = false;
|
||||
|
||||
this.parentPiece = parentPiece;
|
||||
this.packetController = packetController;
|
||||
super.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -56,8 +63,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
// Disable normal ticking for this entity.
|
||||
|
||||
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
|
||||
if (this.onGround) {
|
||||
this.onGround = false;
|
||||
if (super.onGround) {
|
||||
super.onGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,8 +73,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
// Disable normal ticking for this entity.
|
||||
|
||||
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
|
||||
if (this.onGround) {
|
||||
this.onGround = false;
|
||||
if (super.onGround) {
|
||||
super.onGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,7 +155,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
|
||||
@Override
|
||||
public void a(AxisAlignedBB boundingBox) {
|
||||
// Do not change it!
|
||||
// Prevent bounding box from being changed
|
||||
}
|
||||
|
||||
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
|
||||
@ -206,9 +213,9 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
private void broadcastLocationPacketNMS() {
|
||||
PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this);
|
||||
|
||||
for (Object obj : super.world.getPlayers()) {
|
||||
if (obj instanceof EntityPlayer) {
|
||||
EntityPlayer nmsPlayer = (EntityPlayer) obj;
|
||||
for (Object humanEntity : super.world.getPlayers()) {
|
||||
if (humanEntity instanceof EntityPlayer) {
|
||||
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
|
||||
|
||||
double distanceSquared = Utils.square(nmsPlayer.locX() - super.locX()) + Utils.square(nmsPlayer.locZ() - super.locZ());
|
||||
if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) {
|
||||
@ -218,6 +225,21 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerNMS(NMSEntity passenger) {
|
||||
Preconditions.checkArgument(passenger instanceof Entity);
|
||||
Entity passengerEntity = (Entity) passenger;
|
||||
Preconditions.checkArgument(passengerEntity.getVehicle() == null);
|
||||
Preconditions.checkState(super.passengers.isEmpty());
|
||||
|
||||
try {
|
||||
VEHICLE_FIELD.set(passenger, this);
|
||||
this.passengers.add(this);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
DebugLogger.cannotSetPassenger(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDeadNMS() {
|
||||
return super.dead;
|
||||
@ -230,11 +252,12 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getBukkitEntityNMS() {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,16 +5,12 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.nms.v1_16_R3;
|
||||
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSCommons;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardItemLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSCommons;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import net.minecraft.server.v1_16_R3.Blocks;
|
||||
import net.minecraft.server.v1_16_R3.DamageSource;
|
||||
import net.minecraft.server.v1_16_R3.Entity;
|
||||
import net.minecraft.server.v1_16_R3.EntityHuman;
|
||||
import net.minecraft.server.v1_16_R3.EntityItem;
|
||||
import net.minecraft.server.v1_16_R3.EntityPlayer;
|
||||
@ -29,15 +25,14 @@ import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack;
|
||||
|
||||
public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle");
|
||||
|
||||
private final StandardItemLine parentPiece;
|
||||
private final StandardItemLine parentHologramLine;
|
||||
private CraftEntity customBukkitEntity;
|
||||
|
||||
public EntityNMSItem(World world, StandardItemLine piece) {
|
||||
public EntityNMSItem(World world, StandardItemLine parentHologramLine) {
|
||||
super(EntityTypes.ITEM, world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
|
||||
super.pickupDelay = 32767; // Lock the item pickup delay, also prevents entities from picking up the item
|
||||
this.parentPiece = piece;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -65,7 +60,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
}
|
||||
|
||||
if (human instanceof EntityPlayer) {
|
||||
parentPiece.onPickup(((EntityPlayer) human).getBukkitEntity());
|
||||
parentHologramLine.onPickup(((EntityPlayer) human).getBukkitEntity());
|
||||
// It is never added to the inventory.
|
||||
}
|
||||
}
|
||||
@ -155,7 +150,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
|
||||
@Override
|
||||
public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) {
|
||||
ItemStack newItem = CraftItemStack.asNMSCopy(stack); // ItemStack.a is returned if the stack is null, invalid or the material is not an Item
|
||||
ItemStack newItem = CraftItemStack.asNMSCopy(stack); // ItemStack.b is returned if the stack is not valid
|
||||
|
||||
if (newItem == null || newItem == ItemStack.b) {
|
||||
newItem = new ItemStack(Blocks.BEDROCK);
|
||||
@ -170,10 +165,10 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
}
|
||||
|
||||
NBTTagList tagList = new NBTTagList();
|
||||
tagList.add(NBTTagString.a(NMSCommons.ANTI_STACK_LORE)); // Antistack lore
|
||||
tagList.add(NBTTagString.a(NMSCommons.ANTI_STACK_LORE));
|
||||
display.set("Lore", tagList);
|
||||
|
||||
setItemStack(newItem);
|
||||
super.setItemStack(newItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -183,7 +178,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -191,33 +186,9 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerOfNMS(NMSEntityBase vehicleBase) {
|
||||
if (!(vehicleBase instanceof Entity)) {
|
||||
// It should never dismount
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = (Entity) vehicleBase;
|
||||
|
||||
try {
|
||||
if (super.getVehicle() != null) {
|
||||
Entity oldVehicle = super.getVehicle();
|
||||
VEHICLE_FIELD.set(this, null);
|
||||
oldVehicle.passengers.remove(this);
|
||||
}
|
||||
|
||||
VEHICLE_FIELD.set(this, entity);
|
||||
entity.passengers.clear();
|
||||
entity.passengers.add(this);
|
||||
|
||||
} catch (Throwable t) {
|
||||
DebugLogger.cannotSetPassenger(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getRawItemStack() {
|
||||
return super.getItemStack();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,14 +5,10 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.nms.v1_16_R3;
|
||||
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSSlime;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSSlime;
|
||||
import net.minecraft.server.v1_16_R3.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_16_R3.DamageSource;
|
||||
import net.minecraft.server.v1_16_R3.Entity;
|
||||
import net.minecraft.server.v1_16_R3.EntityDamageSource;
|
||||
import net.minecraft.server.v1_16_R3.EntityPlayer;
|
||||
import net.minecraft.server.v1_16_R3.EntitySlime;
|
||||
@ -27,19 +23,18 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
|
||||
public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
|
||||
private static final ReflectField<Entity> VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle");
|
||||
|
||||
private final StandardHologramLine parentPiece;
|
||||
private final StandardHologramLine parentHologramLine;
|
||||
private CraftEntity customBukkitEntity;
|
||||
|
||||
public EntityNMSSlime(World world, StandardHologramLine parentPiece) {
|
||||
public EntityNMSSlime(World world, StandardHologramLine parentHologramLine) {
|
||||
super(EntityTypes.SLIME, world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
|
||||
super.persistent = true;
|
||||
super.collides = false;
|
||||
a(0.0F, 0.0F);
|
||||
setSize(1, false);
|
||||
setInvisible(true);
|
||||
this.parentPiece = parentPiece;
|
||||
super.a(0.0F, 0.0F);
|
||||
super.setSize(1, false);
|
||||
super.setInvisible(true);
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
}
|
||||
|
||||
@ -61,7 +56,7 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
|
||||
@Override
|
||||
public void a(AxisAlignedBB boundingBox) {
|
||||
// Do not change it!
|
||||
// Prevent bounding box from being changed
|
||||
}
|
||||
|
||||
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
|
||||
@ -177,36 +172,12 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getBukkitEntityNMS() {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerOfNMS(NMSEntityBase vehicleBase) {
|
||||
if (!(vehicleBase instanceof Entity)) {
|
||||
// It should never dismount
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = (Entity) vehicleBase;
|
||||
|
||||
try {
|
||||
if (super.getVehicle() != null) {
|
||||
Entity oldVehicle = super.getVehicle();
|
||||
VEHICLE_FIELD.set(this, null);
|
||||
oldVehicle.passengers.remove(this);
|
||||
}
|
||||
|
||||
VEHICLE_FIELD.set(this, entity);
|
||||
entity.passengers.clear();
|
||||
entity.passengers.add(this);
|
||||
|
||||
} catch (Throwable t) {
|
||||
DebugLogger.cannotSetPassenger(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -120,6 +120,5 @@ public class NullBoundingBox extends AxisAlignedBB {
|
||||
public Vec3D f() {
|
||||
return Vec3D.ORIGIN;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -9,16 +9,16 @@ import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.fcommons.reflection.ClassToken;
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.fcommons.reflection.ReflectMethod;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.nms.CustomNameEditor;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardItemLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.ChatComponentCustomNameEditor;
|
||||
import me.filoghost.holographicdisplays.core.nms.CustomNameEditor;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSManager;
|
||||
import me.filoghost.holographicdisplays.core.nms.PacketController;
|
||||
import me.filoghost.holographicdisplays.core.nms.SpawnFailedException;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntity;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardItemLine;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import net.minecraft.server.v1_16_R3.ChatComponentText;
|
||||
import net.minecraft.server.v1_16_R3.Entity;
|
||||
import net.minecraft.server.v1_16_R3.EntityTypes;
|
||||
@ -61,40 +61,34 @@ public class VersionNMSManager implements NMSManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSItem spawnNMSItem(World bukkitWorld, double x, double y, double z, StandardItemLine parentPiece, ItemStack stack) {
|
||||
public NMSItem spawnNMSItem(World bukkitWorld, double x, double y, double z, StandardItemLine parentPiece, ItemStack stack) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece);
|
||||
customItem.setLocationNMS(x, y, z);
|
||||
customItem.setItemStackNMS(stack);
|
||||
if (!addEntityToWorld(nmsWorld, customItem)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return customItem;
|
||||
EntityNMSItem item = new EntityNMSItem(nmsWorld, parentPiece);
|
||||
item.setLocationNMS(x, y, z);
|
||||
item.setItemStackNMS(stack);
|
||||
addEntityToWorld(nmsWorld, item);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityNMSSlime spawnNMSSlime(World bukkitWorld, double x, double y, double z, StandardHologramLine parentPiece) {
|
||||
public EntityNMSSlime spawnNMSSlime(World bukkitWorld, double x, double y, double z, StandardHologramLine parentPiece) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece);
|
||||
touchSlime.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, touchSlime)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return touchSlime;
|
||||
EntityNMSSlime slime = new EntityNMSSlime(nmsWorld, parentPiece);
|
||||
slime.setLocationNMS(x, y, z);
|
||||
addEntityToWorld(nmsWorld, slime);
|
||||
return slime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSArmorStand spawnNMSArmorStand(World world, double x, double y, double z, StandardHologramLine parentPiece) {
|
||||
public NMSArmorStand spawnNMSArmorStand(World world, double x, double y, double z, StandardHologramLine parentPiece) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return invisibleArmorStand;
|
||||
EntityNMSArmorStand armorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
armorStand.setLocationNMS(x, y, z);
|
||||
addEntityToWorld(nmsWorld, armorStand);
|
||||
return armorStand;
|
||||
}
|
||||
|
||||
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) {
|
||||
private void addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) throws SpawnFailedException {
|
||||
Preconditions.checkState(Bukkit.isPrimaryThread(), "Async entity add");
|
||||
|
||||
final int chunkX = MathHelper.floor(nmsEntity.locX() / 16.0);
|
||||
@ -103,49 +97,48 @@ public class VersionNMSManager implements NMSManager {
|
||||
if (!nmsWorld.isChunkLoaded(chunkX, chunkZ)) {
|
||||
// This should never happen
|
||||
nmsEntity.dead = true;
|
||||
return false;
|
||||
throw new SpawnFailedException(SpawnFailedException.CHUNK_NOT_LOADED);
|
||||
}
|
||||
|
||||
nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity);
|
||||
try {
|
||||
REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity);
|
||||
return true;
|
||||
} catch (ReflectiveOperationException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
nmsEntity.dead = true;
|
||||
throw new SpawnFailedException(SpawnFailedException.REGISTER_ENTITY_FAIL, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase;
|
||||
return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
public NMSEntity getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle();
|
||||
|
||||
if (nmsEntity instanceof NMSEntityBase) {
|
||||
return ((NMSEntityBase) nmsEntity);
|
||||
if (nmsEntity instanceof NMSEntity) {
|
||||
return ((NMSEntity) nmsEntity);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) {
|
||||
public NMSEntity getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
Entity nmsEntity = nmsWorld.getEntity(entityID);
|
||||
|
||||
if (nmsEntity instanceof NMSEntityBase) {
|
||||
return ((NMSEntityBase) nmsEntity);
|
||||
if (nmsEntity instanceof NMSEntity) {
|
||||
return ((NMSEntity) nmsEntity);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomNameEditor getCustomNameChatComponentEditor() {
|
||||
public CustomNameEditor getCustomNameEditor() {
|
||||
return VersionChatComponentCustomNameEditor.INSTANCE;
|
||||
}
|
||||
|
||||
|
@ -32,41 +32,41 @@ public class CraftNMSArmorStand extends CraftArmorStand {
|
||||
}
|
||||
|
||||
// Methods from Armor stand class
|
||||
@Override public void setArms(boolean arms) { }
|
||||
@Override public void setBasePlate(boolean basePlate) { }
|
||||
@Override public void setBodyPose(EulerAngle pose) { }
|
||||
@Override public void setBoots(ItemStack item) { }
|
||||
@Override public void setChestplate(ItemStack item) { }
|
||||
@Override public void setGravity(boolean gravity) { }
|
||||
@Override public void setHeadPose(EulerAngle pose) { }
|
||||
@Override public void setHelmet(ItemStack item) { }
|
||||
@Override public void setItemInHand(ItemStack item) { }
|
||||
@Override public void setLeftArmPose(EulerAngle pose) { }
|
||||
@Override public void setLeftLegPose(EulerAngle pose) { }
|
||||
@Override public void setLeggings(ItemStack item) { }
|
||||
@Override public void setRightArmPose(EulerAngle pose) { }
|
||||
@Override public void setRightLegPose(EulerAngle pose) { }
|
||||
@Override public void setSmall(boolean small) { }
|
||||
@Override public void setVisible(boolean visible) { }
|
||||
@Override public void setArms(boolean arms) {}
|
||||
@Override public void setBasePlate(boolean basePlate) {}
|
||||
@Override public void setBodyPose(EulerAngle pose) {}
|
||||
@Override public void setBoots(ItemStack item) {}
|
||||
@Override public void setChestplate(ItemStack item) {}
|
||||
@Override public void setGravity(boolean gravity) {}
|
||||
@Override public void setHeadPose(EulerAngle pose) {}
|
||||
@Override public void setHelmet(ItemStack item) {}
|
||||
@Override public void setItemInHand(ItemStack item) {}
|
||||
@Override public void setLeftArmPose(EulerAngle pose) {}
|
||||
@Override public void setLeftLegPose(EulerAngle pose) {}
|
||||
@Override public void setLeggings(ItemStack item) {}
|
||||
@Override public void setRightArmPose(EulerAngle pose) {}
|
||||
@Override public void setRightLegPose(EulerAngle pose) {}
|
||||
@Override public void setSmall(boolean small) {}
|
||||
@Override public void setVisible(boolean visible) {}
|
||||
|
||||
// Methods from LivingEntity class
|
||||
@Override public boolean addPotionEffect(PotionEffect effect) { return false; }
|
||||
@Override public boolean addPotionEffect(PotionEffect effect, boolean param) { return false; }
|
||||
@Override public boolean addPotionEffects(Collection<PotionEffect> effects) { return false; }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) { }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) {}
|
||||
|
||||
// Methods from Entity
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
|
||||
}
|
||||
|
@ -28,20 +28,20 @@ public class CraftNMSItem extends CraftItem {
|
||||
}
|
||||
|
||||
// Methods from Entity
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
|
||||
// Methods from Item
|
||||
@Override public void setItemStack(ItemStack stack) { }
|
||||
@Override public void setPickupDelay(int delay) { }
|
||||
@Override public void setItemStack(ItemStack stack) {}
|
||||
@Override public void setPickupDelay(int delay) {}
|
||||
}
|
||||
|
@ -33,22 +33,22 @@ public class CraftNMSSlime extends CraftSlime {
|
||||
@Override public boolean addPotionEffect(PotionEffect effect) { return false; }
|
||||
@Override public boolean addPotionEffect(PotionEffect effect, boolean param) { return false; }
|
||||
@Override public boolean addPotionEffects(Collection<PotionEffect> effects) { return false; }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) { }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) {}
|
||||
|
||||
// Methods from Entity
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
|
||||
// Methods from Slime
|
||||
@Override public void setSize(int size) { }
|
||||
@Override public void setSize(int size) {}
|
||||
}
|
||||
|
@ -5,15 +5,18 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.nms.v1_8_R2;
|
||||
|
||||
import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.fcommons.reflection.ReflectMethod;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.Utils;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.PacketController;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntity;
|
||||
import net.minecraft.server.v1_8_R2.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_8_R2.DamageSource;
|
||||
import net.minecraft.server.v1_8_R2.Entity;
|
||||
import net.minecraft.server.v1_8_R2.EntityArmorStand;
|
||||
import net.minecraft.server.v1_8_R2.EntityHuman;
|
||||
import net.minecraft.server.v1_8_R2.EntityPlayer;
|
||||
@ -26,15 +29,19 @@ import org.bukkit.craftbukkit.v1_8_R2.entity.CraftEntity;
|
||||
|
||||
public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand {
|
||||
|
||||
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 static final ReflectField<Double> PASSENGER_PITCH_DELTA = ReflectField.lookup(double.class, Entity.class, "ar");
|
||||
private static final ReflectField<Double> PASSENGER_YAW_DELTA = ReflectField.lookup(double.class, Entity.class, "as");
|
||||
|
||||
private final StandardHologramLine parentPiece;
|
||||
private final StandardHologramLine parentHologramLine;
|
||||
private final PacketController packetController;
|
||||
private String customName;
|
||||
|
||||
public EntityNMSArmorStand(World world, StandardHologramLine parentPiece, PacketController packetController) {
|
||||
public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, PacketController packetController) {
|
||||
super(world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
this.packetController = packetController;
|
||||
|
||||
super.setInvisible(true);
|
||||
super.setSmall(true);
|
||||
super.setArms(false);
|
||||
@ -42,20 +49,13 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
super.setBasePlate(true);
|
||||
try {
|
||||
SET_MARKER_METHOD.invoke(this, true);
|
||||
} catch (Throwable t) {
|
||||
DebugLogger.cannotSetArmorStandAsMarker(t);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
DebugLogger.cannotSetArmorStandAsMarker(e);
|
||||
// It will still work, but the offset will be wrong.
|
||||
}
|
||||
try {
|
||||
DISABLED_SLOTS_FIELD.set(this, Integer.MAX_VALUE);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
// There's still the overridden method.
|
||||
}
|
||||
|
||||
this.parentPiece = parentPiece;
|
||||
this.packetController = packetController;
|
||||
super.noclip = true;
|
||||
super.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet.
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -63,8 +63,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
// Disable normal ticking for this entity.
|
||||
|
||||
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
|
||||
if (this.onGround) {
|
||||
this.onGround = false;
|
||||
if (super.onGround) {
|
||||
super.onGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,8 +73,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
// Disable normal ticking for this entity.
|
||||
|
||||
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
|
||||
if (this.onGround) {
|
||||
this.onGround = false;
|
||||
if (super.onGround) {
|
||||
super.onGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -140,7 +140,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
|
||||
@Override
|
||||
public void a(AxisAlignedBB boundingBox) {
|
||||
// Do not change it!
|
||||
// Prevent bounding box from being changed
|
||||
}
|
||||
|
||||
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
|
||||
@ -177,9 +177,9 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
@Override
|
||||
public CraftEntity getBukkitEntity() {
|
||||
if (super.bukkitEntity == null) {
|
||||
this.bukkitEntity = new CraftNMSArmorStand(this.world.getServer(), this);
|
||||
super.bukkitEntity = new CraftNMSArmorStand(super.world.getServer(), this);
|
||||
}
|
||||
return this.bukkitEntity;
|
||||
return super.bukkitEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -198,11 +198,11 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
private void broadcastLocationPacketNMS() {
|
||||
PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this);
|
||||
|
||||
for (Object obj : this.world.players) {
|
||||
if (obj instanceof EntityPlayer) {
|
||||
EntityPlayer nmsPlayer = (EntityPlayer) obj;
|
||||
for (Object humanEntity : super.world.players) {
|
||||
if (humanEntity instanceof EntityPlayer) {
|
||||
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
|
||||
|
||||
double distanceSquared = Utils.square(nmsPlayer.locX - this.locX) + Utils.square(nmsPlayer.locZ - this.locZ);
|
||||
double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ);
|
||||
if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) {
|
||||
nmsPlayer.playerConnection.sendPacket(teleportPacket);
|
||||
}
|
||||
@ -210,6 +210,24 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerNMS(NMSEntity passenger) {
|
||||
Preconditions.checkArgument(passenger instanceof Entity);
|
||||
Entity passengerEntity = (Entity) passenger;
|
||||
Preconditions.checkArgument(passengerEntity.vehicle == null);
|
||||
Preconditions.checkState(super.passenger == null);
|
||||
|
||||
try {
|
||||
PASSENGER_PITCH_DELTA.set(passengerEntity, 0.0);
|
||||
PASSENGER_YAW_DELTA.set(passengerEntity, 0.0);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
DebugLogger.cannotSetPassengerPitchYawDelta(e);
|
||||
}
|
||||
|
||||
passengerEntity.vehicle = this;
|
||||
super.passenger = passengerEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDeadNMS() {
|
||||
return this.dead;
|
||||
@ -222,11 +240,12 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getBukkitEntityNMS() {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,16 +5,12 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.nms.v1_8_R2;
|
||||
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSCommons;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardItemLine;
|
||||
import net.minecraft.server.v1_8_R2.Blocks;
|
||||
import net.minecraft.server.v1_8_R2.DamageSource;
|
||||
import net.minecraft.server.v1_8_R2.Entity;
|
||||
import net.minecraft.server.v1_8_R2.EntityHuman;
|
||||
import net.minecraft.server.v1_8_R2.EntityItem;
|
||||
import net.minecraft.server.v1_8_R2.EntityPlayer;
|
||||
@ -28,15 +24,13 @@ import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack;
|
||||
|
||||
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 final StandardItemLine parentHologramLine;
|
||||
|
||||
private final StandardItemLine parentPiece;
|
||||
|
||||
public EntityNMSItem(World world, StandardItemLine piece) {
|
||||
public EntityNMSItem(World world, StandardItemLine parentHologramLine) {
|
||||
super(world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
|
||||
super.pickupDelay = Integer.MAX_VALUE;
|
||||
this.parentPiece = piece;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -64,7 +58,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
}
|
||||
|
||||
if (human instanceof EntityPlayer) {
|
||||
parentPiece.onPickup(((EntityPlayer) human).getBukkitEntity());
|
||||
parentHologramLine.onPickup(((EntityPlayer) human).getBukkitEntity());
|
||||
// It is never added to the inventory.
|
||||
}
|
||||
}
|
||||
@ -116,9 +110,9 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
@Override
|
||||
public CraftEntity getBukkitEntity() {
|
||||
if (super.bukkitEntity == null) {
|
||||
this.bukkitEntity = new CraftNMSItem(this.world.getServer(), this);
|
||||
super.bukkitEntity = new CraftNMSItem(super.world.getServer(), this);
|
||||
}
|
||||
return this.bukkitEntity;
|
||||
return super.bukkitEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -154,20 +148,20 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
}
|
||||
|
||||
NBTTagList tagList = new NBTTagList();
|
||||
tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE)); // Antistack lore
|
||||
tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE));
|
||||
display.set("Lore", tagList);
|
||||
|
||||
setItemStack(newItem);
|
||||
super.setItemStack(newItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIdNMS() {
|
||||
return this.getId();
|
||||
return super.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -175,32 +169,9 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerOfNMS(NMSEntityBase vehicleBase) {
|
||||
if (!(vehicleBase instanceof Entity)) {
|
||||
// It should never dismount
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = (Entity) vehicleBase;
|
||||
|
||||
try {
|
||||
RIDER_PITCH_DELTA.set(this, 0.0);
|
||||
RIDER_YAW_DELTA.set(this, 0.0);
|
||||
} catch (Throwable t) {
|
||||
DebugLogger.cannotSetRiderPitchYaw(t);
|
||||
}
|
||||
|
||||
if (this.vehicle != null) {
|
||||
this.vehicle.passenger = null;
|
||||
}
|
||||
|
||||
this.vehicle = entity;
|
||||
entity.passenger = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getRawItemStack() {
|
||||
return super.getItemStack();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,14 +5,10 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.nms.v1_8_R2;
|
||||
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSSlime;
|
||||
import net.minecraft.server.v1_8_R2.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_8_R2.DamageSource;
|
||||
import net.minecraft.server.v1_8_R2.Entity;
|
||||
import net.minecraft.server.v1_8_R2.EntityDamageSource;
|
||||
import net.minecraft.server.v1_8_R2.EntityPlayer;
|
||||
import net.minecraft.server.v1_8_R2.EntitySlime;
|
||||
@ -24,18 +20,17 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
|
||||
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 final StandardHologramLine parentPiece;
|
||||
private final StandardHologramLine parentHologramLine;
|
||||
|
||||
public EntityNMSSlime(World world, StandardHologramLine parentPiece) {
|
||||
public EntityNMSSlime(World world, StandardHologramLine parentHologramLine) {
|
||||
super(world);
|
||||
this.parentHologramLine = parentHologramLine;
|
||||
|
||||
super.persistent = true;
|
||||
a(0.0F, 0.0F);
|
||||
setSize(1);
|
||||
setInvisible(true);
|
||||
this.parentPiece = parentPiece;
|
||||
super.noclip = true;
|
||||
super.a(0.0F, 0.0F);
|
||||
super.setSize(1);
|
||||
super.setInvisible(true);
|
||||
forceSetBoundingBox(new NullBoundingBox());
|
||||
}
|
||||
|
||||
@ -47,7 +42,7 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
ticksLived = 0;
|
||||
|
||||
// The slime dies without a vehicle.
|
||||
if (this.vehicle == null) {
|
||||
if (super.vehicle == null) {
|
||||
killEntityNMS();
|
||||
}
|
||||
}
|
||||
@ -62,7 +57,7 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
|
||||
@Override
|
||||
public void a(AxisAlignedBB boundingBox) {
|
||||
// Do not change it!
|
||||
// Prevent bounding box from being changed
|
||||
}
|
||||
|
||||
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
|
||||
@ -135,9 +130,9 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
@Override
|
||||
public CraftEntity getBukkitEntity() {
|
||||
if (super.bukkitEntity == null) {
|
||||
this.bukkitEntity = new CraftNMSSlime(this.world.getServer(), this);
|
||||
super.bukkitEntity = new CraftNMSSlime(super.world.getServer(), this);
|
||||
}
|
||||
return this.bukkitEntity;
|
||||
return super.bukkitEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -157,12 +152,12 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
|
||||
@Override
|
||||
public int getIdNMS() {
|
||||
return this.getId();
|
||||
return super.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public StandardHologramLine getHologramLine() {
|
||||
return parentPiece;
|
||||
return parentHologramLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -170,27 +165,4 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassengerOfNMS(NMSEntityBase vehicleBase) {
|
||||
if (!(vehicleBase instanceof Entity)) {
|
||||
// It should never dismount
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = (Entity) vehicleBase;
|
||||
|
||||
try {
|
||||
RIDER_PITCH_DELTA.set(this, 0.0);
|
||||
RIDER_YAW_DELTA.set(this, 0.0);
|
||||
} catch (Throwable t) {
|
||||
DebugLogger.cannotSetRiderPitchYaw(t);
|
||||
}
|
||||
|
||||
if (this.vehicle != null) {
|
||||
this.vehicle.passenger = null;
|
||||
}
|
||||
|
||||
this.vehicle = entity;
|
||||
entity.passenger = this;
|
||||
}
|
||||
}
|
||||
|
@ -74,7 +74,5 @@ public class NullBoundingBox extends AxisAlignedBB {
|
||||
public AxisAlignedBB shrink(double arg0, double arg1, double arg2) {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -9,15 +9,15 @@ import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.fcommons.reflection.ClassToken;
|
||||
import me.filoghost.fcommons.reflection.ReflectField;
|
||||
import me.filoghost.fcommons.reflection.ReflectMethod;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.hologram.StandardItemLine;
|
||||
import me.filoghost.holographicdisplays.core.nms.CustomNameEditor;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSManager;
|
||||
import me.filoghost.holographicdisplays.core.nms.PacketController;
|
||||
import me.filoghost.holographicdisplays.core.nms.SpawnFailedException;
|
||||
import me.filoghost.holographicdisplays.core.nms.StringCustomNameEditor;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntity;
|
||||
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
|
||||
import net.minecraft.server.v1_8_R2.Entity;
|
||||
import net.minecraft.server.v1_8_R2.EntityTypes;
|
||||
@ -37,7 +37,7 @@ public class VersionNMSManager implements NMSManager {
|
||||
private static final ReflectField<Map<Class<?>, String>> ENTITY_NAMES_BY_CLASS_FIELD = ReflectField.lookup(new ClassToken<Map<Class<?>, String>>(){}, EntityTypes.class, "d");
|
||||
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 static final ReflectMethod<?> REGISTER_ENTITY_METHOD = ReflectMethod.lookup(Object.class, World.class, "a", Entity.class);
|
||||
|
||||
private final PacketController packetController;
|
||||
|
||||
@ -58,44 +58,42 @@ public class VersionNMSManager implements NMSManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, StandardItemLine parentPiece, ItemStack stack) {
|
||||
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, StandardItemLine parentPiece, ItemStack stack) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece);
|
||||
customItem.setLocationNMS(x, y, z);
|
||||
customItem.setItemStackNMS(stack);
|
||||
if (!addEntityToWorld(nmsWorld, customItem)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return customItem;
|
||||
EntityNMSItem item = new EntityNMSItem(nmsWorld, parentPiece);
|
||||
item.setLocationNMS(x, y, z);
|
||||
item.setItemStackNMS(stack);
|
||||
addEntityToWorld(nmsWorld, item);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, StandardHologramLine parentPiece) {
|
||||
public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, StandardHologramLine parentPiece) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece);
|
||||
touchSlime.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, touchSlime)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return touchSlime;
|
||||
EntityNMSSlime slime = new EntityNMSSlime(nmsWorld, parentPiece);
|
||||
slime.setLocationNMS(x, y, z);
|
||||
addEntityToWorld(nmsWorld, slime);
|
||||
return slime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, StandardHologramLine parentPiece) {
|
||||
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, StandardHologramLine parentPiece) throws SpawnFailedException {
|
||||
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
|
||||
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
invisibleArmorStand.setLocationNMS(x, y, z);
|
||||
if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) {
|
||||
DebugLogger.handleSpawnFail(parentPiece);
|
||||
}
|
||||
return invisibleArmorStand;
|
||||
EntityNMSArmorStand armorStand = new EntityNMSArmorStand(nmsWorld, parentPiece, packetController);
|
||||
armorStand.setLocationNMS(x, y, z);
|
||||
addEntityToWorld(nmsWorld, armorStand);
|
||||
return armorStand;
|
||||
}
|
||||
|
||||
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) {
|
||||
private void addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) throws SpawnFailedException {
|
||||
Preconditions.checkState(Bukkit.isPrimaryThread(), "Async entity add");
|
||||
|
||||
if (!VALIDATE_ENTITY_METHOD.isValid()) {
|
||||
return nmsWorld.addEntity(nmsEntity, SpawnReason.CUSTOM);
|
||||
if (!REGISTER_ENTITY_METHOD.isValid()) {
|
||||
boolean added = nmsWorld.addEntity(nmsEntity, SpawnReason.CUSTOM);
|
||||
if (!added) {
|
||||
nmsEntity.dead = true;
|
||||
throw new SpawnFailedException(SpawnFailedException.ADD_ENTITY_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
final int chunkX = MathHelper.floor(nmsEntity.locX / 16.0);
|
||||
@ -104,51 +102,50 @@ public class VersionNMSManager implements NMSManager {
|
||||
if (!nmsWorld.chunkProviderServer.isChunkLoaded(chunkX, chunkZ)) {
|
||||
// This should never happen
|
||||
nmsEntity.dead = true;
|
||||
return false;
|
||||
throw new SpawnFailedException(SpawnFailedException.CHUNK_NOT_LOADED);
|
||||
}
|
||||
|
||||
nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity);
|
||||
nmsWorld.entityList.add(nmsEntity);
|
||||
|
||||
try {
|
||||
VALIDATE_ENTITY_METHOD.invoke(nmsWorld, nmsEntity);
|
||||
REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
nmsEntity.dead = true;
|
||||
throw new SpawnFailedException(SpawnFailedException.REGISTER_ENTITY_FAIL, e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase;
|
||||
return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
public NMSEntity getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
|
||||
Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle();
|
||||
|
||||
if (nmsEntity instanceof NMSEntityBase) {
|
||||
return ((NMSEntityBase) nmsEntity);
|
||||
if (nmsEntity instanceof NMSEntity) {
|
||||
return ((NMSEntity) nmsEntity);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) {
|
||||
public NMSEntity getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) {
|
||||
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
|
||||
Entity nmsEntity = nmsWorld.a(entityID);
|
||||
|
||||
if (nmsEntity instanceof NMSEntityBase) {
|
||||
return ((NMSEntityBase) nmsEntity);
|
||||
if (nmsEntity instanceof NMSEntity) {
|
||||
return ((NMSEntity) nmsEntity);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomNameEditor getCustomNameChatComponentEditor() {
|
||||
public CustomNameEditor getCustomNameEditor() {
|
||||
return StringCustomNameEditor.INSTANCE;
|
||||
}
|
||||
|
||||
|
@ -32,41 +32,41 @@ public class CraftNMSArmorStand extends CraftArmorStand {
|
||||
}
|
||||
|
||||
// Methods from Armor stand class
|
||||
@Override public void setArms(boolean arms) { }
|
||||
@Override public void setBasePlate(boolean basePlate) { }
|
||||
@Override public void setBodyPose(EulerAngle pose) { }
|
||||
@Override public void setBoots(ItemStack item) { }
|
||||
@Override public void setChestplate(ItemStack item) { }
|
||||
@Override public void setGravity(boolean gravity) { }
|
||||
@Override public void setHeadPose(EulerAngle pose) { }
|
||||
@Override public void setHelmet(ItemStack item) { }
|
||||
@Override public void setItemInHand(ItemStack item) { }
|
||||
@Override public void setLeftArmPose(EulerAngle pose) { }
|
||||
@Override public void setLeftLegPose(EulerAngle pose) { }
|
||||
@Override public void setLeggings(ItemStack item) { }
|
||||
@Override public void setRightArmPose(EulerAngle pose) { }
|
||||
@Override public void setRightLegPose(EulerAngle pose) { }
|
||||
@Override public void setSmall(boolean small) { }
|
||||
@Override public void setVisible(boolean visible) { }
|
||||
@Override public void setArms(boolean arms) {}
|
||||
@Override public void setBasePlate(boolean basePlate) {}
|
||||
@Override public void setBodyPose(EulerAngle pose) {}
|
||||
@Override public void setBoots(ItemStack item) {}
|
||||
@Override public void setChestplate(ItemStack item) {}
|
||||
@Override public void setGravity(boolean gravity) {}
|
||||
@Override public void setHeadPose(EulerAngle pose) {}
|
||||
@Override public void setHelmet(ItemStack item) {}
|
||||
@Override public void setItemInHand(ItemStack item) {}
|
||||
@Override public void setLeftArmPose(EulerAngle pose) {}
|
||||
@Override public void setLeftLegPose(EulerAngle pose) {}
|
||||
@Override public void setLeggings(ItemStack item) {}
|
||||
@Override public void setRightArmPose(EulerAngle pose) {}
|
||||
@Override public void setRightLegPose(EulerAngle pose) {}
|
||||
@Override public void setSmall(boolean small) {}
|
||||
@Override public void setVisible(boolean visible) {}
|
||||
|
||||
// Methods from LivingEntity class
|
||||
@Override public boolean addPotionEffect(PotionEffect effect) { return false; }
|
||||
@Override public boolean addPotionEffect(PotionEffect effect, boolean param) { return false; }
|
||||
@Override public boolean addPotionEffects(Collection<PotionEffect> effects) { return false; }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) { }
|
||||
@Override public void setRemoveWhenFarAway(boolean remove) {}
|
||||
|
||||
// Methods from Entity
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
|
||||
}
|
||||
|
@ -28,20 +28,20 @@ public class CraftNMSItem extends CraftItem {
|
||||
}
|
||||
|
||||
// Methods from Entity
|
||||
@Override public void setVelocity(Vector vel) { }
|
||||
@Override public void setVelocity(Vector vel) {}
|
||||
@Override public boolean teleport(Location loc) { return false; }
|
||||
@Override public boolean teleport(Entity entity) { return false; }
|
||||
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
|
||||
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
|
||||
@Override public void setFireTicks(int ticks) { }
|
||||
@Override public void setFireTicks(int ticks) {}
|
||||
@Override public boolean setPassenger(Entity entity) { return false; }
|
||||
@Override public boolean eject() { return false; }
|
||||
@Override public boolean leaveVehicle() { return false; }
|
||||
@Override public void playEffect(EntityEffect effect) { }
|
||||
@Override public void setCustomName(String name) { }
|
||||
@Override public void setCustomNameVisible(boolean flag) { }
|
||||
@Override public void playEffect(EntityEffect effect) {}
|
||||
@Override public void setCustomName(String name) {}
|
||||
@Override public void setCustomNameVisible(boolean flag) {}
|
||||
|
||||
// Methods from Item
|
||||
@Override public void setItemStack(ItemStack stack) { }
|
||||
@Override public void setPickupDelay(int delay) { }
|
||||
@Override public void setItemStack(ItemStack stack) {}
|
||||
@Override public void setPickupDelay(int delay) {}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user