From 7d865386212727ee8cdcb1955023f8c94dbf1d6a Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 24 Jul 2021 12:51:14 +0200 Subject: [PATCH] Use packets instead of entities Missing: * All implementations before 1.17 * Placeholder toggle * Visibility settings * Line touch handling * Item pickup handling --- .github/ISSUE_TEMPLATE/1-bug.yml | 8 +- .../api/HolographicDisplaysAPI.java | 12 - .../api/hologram/Hologram.java | 2 - .../api/hologram/VisibilitySettings.java | 2 - .../HolographicDisplaysAPIProvider.java | 3 - .../common/DebugLogger.java | 18 -- .../common/hologram/StandardHologram.java | 28 +- .../hologram/StandardHologramComponent.java | 28 ++ .../common/hologram/StandardHologramLine.java | 11 +- .../common/hologram/StandardItemLine.java | 9 +- .../common/hologram/StandardTextLine.java | 4 - .../hologram/StandardTouchableLine.java | 6 +- .../common/nms/AbstractNMSPacketList.java | 44 +++ .../common/nms/EntityID.java | 39 +++ .../common/nms/FallbackEntityIDGenerator.java | 37 +++ .../common/nms/IndividualCustomName.java | 15 + .../common/nms/IndividualNMSPacket.java | 25 ++ .../common/nms/NMSCommons.java | 23 -- .../common/nms/NMSErrors.java | 14 + .../common/nms/NMSManager.java | 34 +-- ...ocolPacketSettings.java => NMSPacket.java} | 6 +- .../common/nms/NMSPacketList.java | 37 +++ .../common/nms/SpawnFailedException.java | 22 -- .../common/nms/entity/NMSArmorStand.java | 24 -- .../common/nms/entity/NMSEntity.java | 30 -- .../common/nms/entity/NMSEntityHelper.java | 27 -- .../common/nms/entity/NMSItem.java | 19 -- .../common/nms/entity/NMSSlime.java | 10 - .../common/nms/entity/NMSVehicle.java | 12 - .../holograms/api/HolographicDisplaysAPI.java | 2 +- .../nms/v1_10_R1/CraftNMSArmorStand.java | 85 ------ .../nms/v1_10_R1/CraftNMSItem.java | 56 ---- .../nms/v1_10_R1/CraftNMSSlime.java | 68 ----- .../nms/v1_10_R1/EntityNMSArmorStand.java | 260 ----------------- .../nms/v1_10_R1/EntityNMSItem.java | 214 -------------- .../nms/v1_10_R1/EntityNMSSlime.java | 204 ------------- .../nms/v1_10_R1/NullBoundingBox.java | 114 -------- .../nms/v1_10_R1/VersionNMSEntityHelper.java | 46 --- .../nms/v1_10_R1/VersionNMSManager.java | 140 +-------- .../nms/v1_11_R1/CraftNMSArmorStand.java | 85 ------ .../nms/v1_11_R1/CraftNMSItem.java | 56 ---- .../nms/v1_11_R1/CraftNMSSlime.java | 68 ----- .../nms/v1_11_R1/EntityNMSArmorStand.java | 260 ----------------- .../nms/v1_11_R1/EntityNMSItem.java | 199 ------------- .../nms/v1_11_R1/EntityNMSSlime.java | 190 ------------- .../nms/v1_11_R1/NullBoundingBox.java | 129 --------- .../nms/v1_11_R1/VersionNMSEntityHelper.java | 46 --- .../nms/v1_11_R1/VersionNMSManager.java | 148 +--------- .../nms/v1_12_R1/CraftNMSArmorStand.java | 86 ------ .../nms/v1_12_R1/CraftNMSItem.java | 56 ---- .../nms/v1_12_R1/CraftNMSSlime.java | 68 ----- .../nms/v1_12_R1/EntityNMSArmorStand.java | 260 ----------------- .../nms/v1_12_R1/EntityNMSItem.java | 199 ------------- .../nms/v1_12_R1/EntityNMSSlime.java | 190 ------------- .../nms/v1_12_R1/NullBoundingBox.java | 129 --------- .../nms/v1_12_R1/VersionNMSEntityHelper.java | 46 --- .../nms/v1_12_R1/VersionNMSManager.java | 148 +--------- .../nms/v1_13_R1/CraftNMSArmorStand.java | 88 ------ .../nms/v1_13_R1/CraftNMSItem.java | 56 ---- .../nms/v1_13_R1/CraftNMSSlime.java | 72 ----- .../nms/v1_13_R1/EntityNMSArmorStand.java | 262 ----------------- .../nms/v1_13_R1/EntityNMSItem.java | 199 ------------- .../nms/v1_13_R1/EntityNMSSlime.java | 191 ------------- .../nms/v1_13_R1/NullBoundingBox.java | 120 -------- .../nms/v1_13_R1/VersionNMSEntityHelper.java | 46 --- .../nms/v1_13_R1/VersionNMSManager.java | 164 +---------- .../nms/v1_13_R2/CraftNMSArmorStand.java | 89 ------ .../nms/v1_13_R2/CraftNMSItem.java | 57 ---- .../nms/v1_13_R2/CraftNMSSlime.java | 77 ----- .../nms/v1_13_R2/EntityNMSArmorStand.java | 262 ----------------- .../nms/v1_13_R2/EntityNMSItem.java | 199 ------------- .../nms/v1_13_R2/EntityNMSSlime.java | 191 ------------- .../nms/v1_13_R2/NullBoundingBox.java | 120 -------- .../nms/v1_13_R2/VersionNMSEntityHelper.java | 46 --- .../nms/v1_13_R2/VersionNMSManager.java | 165 +---------- .../nms/v1_14_R1/CraftNMSArmorStand.java | 89 ------ .../nms/v1_14_R1/CraftNMSItem.java | 58 ---- .../nms/v1_14_R1/CraftNMSSlime.java | 78 ----- .../nms/v1_14_R1/EntityNMSArmorStand.java | 264 ----------------- .../nms/v1_14_R1/EntityNMSItem.java | 201 ------------- .../nms/v1_14_R1/EntityNMSSlime.java | 193 ------------- .../nms/v1_14_R1/NullBoundingBox.java | 124 -------- .../nms/v1_14_R1/VersionNMSEntityHelper.java | 46 --- .../nms/v1_14_R1/VersionNMSManager.java | 148 +--------- .../nms/v1_15_R1/CraftNMSArmorStand.java | 89 ------ .../nms/v1_15_R1/CraftNMSItem.java | 58 ---- .../nms/v1_15_R1/CraftNMSSlime.java | 78 ----- .../nms/v1_15_R1/EntityNMSArmorStand.java | 264 ----------------- .../nms/v1_15_R1/EntityNMSItem.java | 201 ------------- .../nms/v1_15_R1/EntityNMSSlime.java | 193 ------------- .../nms/v1_15_R1/NullBoundingBox.java | 124 -------- .../nms/v1_15_R1/VersionNMSEntityHelper.java | 46 --- .../nms/v1_15_R1/VersionNMSManager.java | 148 +--------- .../nms/v1_16_R1/CraftNMSArmorStand.java | 89 ------ .../nms/v1_16_R1/CraftNMSItem.java | 58 ---- .../nms/v1_16_R1/CraftNMSSlime.java | 78 ----- .../nms/v1_16_R1/EntityNMSArmorStand.java | 264 ----------------- .../nms/v1_16_R1/EntityNMSItem.java | 201 ------------- .../nms/v1_16_R1/EntityNMSSlime.java | 193 ------------- .../nms/v1_16_R1/NullBoundingBox.java | 124 -------- .../nms/v1_16_R1/VersionNMSEntityHelper.java | 46 --- .../nms/v1_16_R1/VersionNMSManager.java | 148 +--------- .../nms/v1_16_R2/CraftNMSArmorStand.java | 89 ------ .../nms/v1_16_R2/CraftNMSItem.java | 58 ---- .../nms/v1_16_R2/CraftNMSSlime.java | 78 ----- .../nms/v1_16_R2/EntityNMSArmorStand.java | 264 ----------------- .../nms/v1_16_R2/EntityNMSItem.java | 201 ------------- .../nms/v1_16_R2/EntityNMSSlime.java | 193 ------------- .../nms/v1_16_R2/NullBoundingBox.java | 124 -------- .../nms/v1_16_R2/VersionNMSEntityHelper.java | 46 --- .../nms/v1_16_R2/VersionNMSManager.java | 139 +-------- .../nms/v1_16_R3/CraftNMSArmorStand.java | 89 ------ .../nms/v1_16_R3/CraftNMSItem.java | 58 ---- .../nms/v1_16_R3/CraftNMSSlime.java | 78 ----- .../nms/v1_16_R3/EntityNMSArmorStand.java | 269 ------------------ .../nms/v1_16_R3/EntityNMSItem.java | 201 ------------- .../nms/v1_16_R3/EntityNMSSlime.java | 193 ------------- .../nms/v1_16_R3/NullBoundingBox.java | 124 -------- .../nms/v1_16_R3/VersionNMSEntityHelper.java | 46 --- .../nms/v1_16_R3/VersionNMSManager.java | 139 +-------- .../nms/v1_17_R1/CraftNMSArmorStand.java | 94 ------ .../nms/v1_17_R1/CraftNMSItem.java | 60 ---- .../nms/v1_17_R1/CraftNMSSlime.java | 81 ------ .../nms/v1_17_R1/DataWatcherEntry.java | 26 ++ .../nms/v1_17_R1/DataWatcherKey.java | 54 ++++ .../nms/v1_17_R1/EntityDestroyNMSPacket.java | 29 ++ .../v1_17_R1/EntityListDestroyNMSPacket.java | 34 +++ .../v1_17_R1/EntityLivingSpawnNMSPacket.java | 48 ++++ .../nms/v1_17_R1/EntityMetadataNMSPacket.java | 30 ++ .../nms/v1_17_R1/EntityMountNMSPacket.java | 30 ++ .../nms/v1_17_R1/EntityNMSArmorStand.java | 264 ----------------- .../nms/v1_17_R1/EntityNMSItem.java | 206 -------------- .../nms/v1_17_R1/EntityNMSSlime.java | 193 ------------- .../nms/v1_17_R1/EntitySpawnNMSPacket.java | 48 ++++ .../nms/v1_17_R1/EntityTeleportNMSPacket.java | 41 +++ .../nms/v1_17_R1/EntityTypeID.java | 14 + .../nms/v1_17_R1/NullBoundingBox.java | 124 -------- .../nms/v1_17_R1/PacketByteBuffer.java | 53 ++++ .../nms/v1_17_R1/VersionNMSEntityHelper.java | 48 ---- .../nms/v1_17_R1/VersionNMSManager.java | 128 ++------- .../nms/v1_17_R1/VersionNMSPacket.java | 22 ++ .../nms/v1_17_R1/VersionNMSPacketList.java | 145 ++++++++++ .../nms/v1_8_R2/CraftNMSArmorStand.java | 74 ----- .../nms/v1_8_R2/CraftNMSItem.java | 49 ---- .../nms/v1_8_R2/CraftNMSSlime.java | 56 ---- .../nms/v1_8_R2/EntityNMSArmorStand.java | 253 ---------------- .../nms/v1_8_R2/EntityNMSItem.java | 184 ------------ .../nms/v1_8_R2/EntityNMSSlime.java | 178 ------------ .../nms/v1_8_R2/NullBoundingBox.java | 78 ----- .../nms/v1_8_R2/VersionNMSEntityHelper.java | 46 --- .../nms/v1_8_R2/VersionNMSManager.java | 149 +--------- .../nms/v1_8_R3/CraftNMSArmorStand.java | 74 ----- .../nms/v1_8_R3/CraftNMSItem.java | 49 ---- .../nms/v1_8_R3/CraftNMSSlime.java | 56 ---- .../nms/v1_8_R3/EntityNMSArmorStand.java | 253 ---------------- .../nms/v1_8_R3/EntityNMSItem.java | 184 ------------ .../nms/v1_8_R3/EntityNMSSlime.java | 178 ------------ .../nms/v1_8_R3/NullBoundingBox.java | 78 ----- .../nms/v1_8_R3/VersionNMSEntityHelper.java | 46 --- .../nms/v1_8_R3/VersionNMSManager.java | 149 +--------- .../nms/v1_9_R1/CraftNMSArmorStand.java | 75 ----- .../nms/v1_9_R1/CraftNMSItem.java | 50 ---- .../nms/v1_9_R1/CraftNMSSlime.java | 57 ---- .../nms/v1_9_R1/EntityNMSArmorStand.java | 261 ----------------- .../nms/v1_9_R1/EntityNMSItem.java | 213 -------------- .../nms/v1_9_R1/EntityNMSSlime.java | 203 ------------- .../nms/v1_9_R1/NullBoundingBox.java | 114 -------- .../nms/v1_9_R1/VersionNMSEntityHelper.java | 46 --- .../nms/v1_9_R1/VersionNMSManager.java | 140 +-------- .../nms/v1_9_R2/CraftNMSArmorStand.java | 75 ----- .../nms/v1_9_R2/CraftNMSItem.java | 50 ---- .../nms/v1_9_R2/CraftNMSSlime.java | 57 ---- .../nms/v1_9_R2/EntityNMSArmorStand.java | 261 ----------------- .../nms/v1_9_R2/EntityNMSItem.java | 214 -------------- .../nms/v1_9_R2/EntityNMSSlime.java | 204 ------------- .../nms/v1_9_R2/NullBoundingBox.java | 114 -------- .../nms/v1_9_R2/VersionNMSEntityHelper.java | 46 --- .../nms/v1_9_R2/VersionNMSManager.java | 140 +-------- plugin/pom.xml | 5 - .../plugin/HolographicDisplays.java | 60 ++-- ...DefaultHolographicDisplaysAPIProvider.java | 8 - .../plugin/api/v2/V2HologramsAPIProvider.java | 2 +- .../bridge/protocollib/DebugHelper.java | 100 ------- .../bridge/protocollib/MetadataHelper.java | 204 ------------- .../bridge/protocollib/PacketListener.java | 167 ----------- .../bridge/protocollib/PacketSender.java | 203 ------------- .../bridge/protocollib/ProtocolLibHook.java | 119 -------- .../commands/HologramCommandManager.java | 11 +- .../plugin/commands/subs/DebugCommand.java | 72 +---- .../plugin/hologram/api/APIHologram.java | 16 +- .../hologram/api/APIHologramManager.java | 13 +- .../api/DefaultVisibilitySettings.java | 47 +-- .../plugin/hologram/base/BaseHologram.java | 106 ++----- .../hologram/base/BaseHologramComponent.java | 79 +++-- .../hologram/base/BaseHologramLine.java | 64 +---- .../hologram/base/BaseHologramManager.java | 11 - .../plugin/hologram/base/BaseItemLine.java | 115 +------- .../plugin/hologram/base/BaseTextLine.java | 70 +---- .../hologram/base/BaseTouchableLine.java | 112 +------- .../hologram/internal/InternalHologram.java | 12 +- .../internal/InternalHologramManager.java | 17 +- .../plugin/hologram/tracking/DisplayText.java | 92 ++++++ .../hologram/tracking/ItemLineTracker.java | 126 ++++++++ .../plugin/hologram/tracking/LineTracker.java | 147 ++++++++++ .../hologram/tracking/LineTrackerManager.java | 86 ++++++ .../tracking/LocationBasedLineTracker.java | 103 +++++++ .../hologram/tracking/TextLineTracker.java | 101 +++++++ .../tracking/TouchableLineTracker.java | 101 +++++++ .../lib/packetwrapper/AbstractPacket.java | 80 ------ .../WrapperPlayServerAttachEntity.java | 132 --------- .../WrapperPlayServerEntityDestroy.java | 66 ----- .../WrapperPlayServerEntityMetadata.java | 87 ------ .../packetwrapper/WrapperPlayServerMount.java | 73 ----- .../WrapperPlayServerSpawnEntity.java | 152 ---------- .../WrapperPlayServerSpawnEntityLiving.java | 116 -------- .../plugin/listener/ChunkListener.java | 33 +-- .../plugin/listener/InteractListener.java | 52 ---- .../plugin/listener/PlayerQuitListener.java | 26 ++ .../plugin/listener/SpawnListener.java | 45 --- .../plugin/placeholder/TickingTask.java | 22 +- .../parsing/StringWithPlaceholders.java | 36 ++- .../tracking/PlaceholderLineTracker.java | 82 ------ .../placeholder/tracking/TrackedLine.java | 62 ---- .../plugin/util/NMSVersion.java | 68 +++-- plugin/src/main/resources/plugin.yml | 2 +- .../api/v2/V2TouchableLineAdapterTest.java | 12 +- .../parsing/StringWithPlaceholdersTest.java | 10 +- .../plugin/test/TestAPIHologramsManager.java | 20 ++ .../plugin/test/TestNMSManager.java | 36 +++ pom.xml | 12 - 230 files changed, 2063 insertions(+), 20253 deletions(-) create mode 100644 common/src/main/java/me/filoghost/holographicdisplays/common/hologram/StandardHologramComponent.java create mode 100644 common/src/main/java/me/filoghost/holographicdisplays/common/nms/AbstractNMSPacketList.java create mode 100644 common/src/main/java/me/filoghost/holographicdisplays/common/nms/EntityID.java create mode 100644 common/src/main/java/me/filoghost/holographicdisplays/common/nms/FallbackEntityIDGenerator.java create mode 100644 common/src/main/java/me/filoghost/holographicdisplays/common/nms/IndividualCustomName.java create mode 100644 common/src/main/java/me/filoghost/holographicdisplays/common/nms/IndividualNMSPacket.java delete mode 100644 common/src/main/java/me/filoghost/holographicdisplays/common/nms/NMSCommons.java create mode 100644 common/src/main/java/me/filoghost/holographicdisplays/common/nms/NMSErrors.java rename common/src/main/java/me/filoghost/holographicdisplays/common/nms/{ProtocolPacketSettings.java => NMSPacket.java} (62%) create mode 100644 common/src/main/java/me/filoghost/holographicdisplays/common/nms/NMSPacketList.java delete mode 100644 common/src/main/java/me/filoghost/holographicdisplays/common/nms/SpawnFailedException.java delete mode 100644 common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/NMSArmorStand.java delete mode 100644 common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/NMSEntity.java delete mode 100644 common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/NMSEntityHelper.java delete mode 100644 common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/NMSItem.java delete mode 100644 common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/NMSSlime.java delete mode 100644 common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/NMSVehicle.java delete mode 100644 nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/CraftNMSArmorStand.java delete mode 100644 nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/CraftNMSItem.java delete mode 100644 nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/CraftNMSSlime.java delete mode 100644 nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityNMSArmorStand.java delete mode 100644 nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityNMSItem.java delete mode 100644 nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityNMSSlime.java delete mode 100644 nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/NullBoundingBox.java delete mode 100644 nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionNMSEntityHelper.java delete mode 100644 nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/CraftNMSArmorStand.java delete mode 100644 nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/CraftNMSItem.java delete mode 100644 nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/CraftNMSSlime.java delete mode 100644 nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityNMSArmorStand.java delete mode 100644 nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityNMSItem.java delete mode 100644 nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityNMSSlime.java delete mode 100644 nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/NullBoundingBox.java delete mode 100644 nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionNMSEntityHelper.java delete mode 100644 nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/CraftNMSArmorStand.java delete mode 100644 nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/CraftNMSItem.java delete mode 100644 nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/CraftNMSSlime.java delete mode 100644 nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityNMSArmorStand.java delete mode 100644 nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityNMSItem.java delete mode 100644 nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityNMSSlime.java delete mode 100644 nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/NullBoundingBox.java delete mode 100644 nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionNMSEntityHelper.java delete mode 100644 nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/CraftNMSArmorStand.java delete mode 100644 nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/CraftNMSItem.java delete mode 100644 nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/CraftNMSSlime.java delete mode 100644 nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/EntityNMSArmorStand.java delete mode 100644 nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/EntityNMSItem.java delete mode 100644 nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/EntityNMSSlime.java delete mode 100644 nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/NullBoundingBox.java delete mode 100644 nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/VersionNMSEntityHelper.java delete mode 100644 nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/CraftNMSArmorStand.java delete mode 100644 nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/CraftNMSItem.java delete mode 100644 nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/CraftNMSSlime.java delete mode 100644 nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityNMSArmorStand.java delete mode 100644 nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityNMSItem.java delete mode 100644 nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityNMSSlime.java delete mode 100644 nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/NullBoundingBox.java delete mode 100644 nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionNMSEntityHelper.java delete mode 100644 nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/CraftNMSArmorStand.java delete mode 100644 nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/CraftNMSItem.java delete mode 100644 nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/CraftNMSSlime.java delete mode 100644 nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityNMSArmorStand.java delete mode 100644 nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityNMSItem.java delete mode 100644 nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityNMSSlime.java delete mode 100644 nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/NullBoundingBox.java delete mode 100644 nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionNMSEntityHelper.java delete mode 100644 nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/CraftNMSArmorStand.java delete mode 100644 nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/CraftNMSItem.java delete mode 100644 nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/CraftNMSSlime.java delete mode 100644 nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityNMSArmorStand.java delete mode 100644 nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityNMSItem.java delete mode 100644 nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityNMSSlime.java delete mode 100644 nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/NullBoundingBox.java delete mode 100644 nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionNMSEntityHelper.java delete mode 100644 nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/CraftNMSArmorStand.java delete mode 100644 nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/CraftNMSItem.java delete mode 100644 nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/CraftNMSSlime.java delete mode 100644 nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityNMSArmorStand.java delete mode 100644 nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityNMSItem.java delete mode 100644 nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityNMSSlime.java delete mode 100644 nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/NullBoundingBox.java delete mode 100644 nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionNMSEntityHelper.java delete mode 100644 nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/CraftNMSArmorStand.java delete mode 100644 nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/CraftNMSItem.java delete mode 100644 nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/CraftNMSSlime.java delete mode 100644 nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityNMSArmorStand.java delete mode 100644 nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityNMSItem.java delete mode 100644 nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityNMSSlime.java delete mode 100644 nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/NullBoundingBox.java delete mode 100644 nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionNMSEntityHelper.java delete mode 100644 nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/CraftNMSArmorStand.java delete mode 100644 nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/CraftNMSItem.java delete mode 100644 nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/CraftNMSSlime.java delete mode 100644 nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityNMSArmorStand.java delete mode 100644 nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityNMSItem.java delete mode 100644 nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityNMSSlime.java delete mode 100644 nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/NullBoundingBox.java delete mode 100644 nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionNMSEntityHelper.java delete mode 100644 nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/CraftNMSArmorStand.java delete mode 100644 nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/CraftNMSItem.java delete mode 100644 nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/CraftNMSSlime.java create mode 100644 nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/DataWatcherEntry.java create mode 100644 nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/DataWatcherKey.java create mode 100644 nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityDestroyNMSPacket.java create mode 100644 nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityListDestroyNMSPacket.java create mode 100644 nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityLivingSpawnNMSPacket.java create mode 100644 nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityMetadataNMSPacket.java create mode 100644 nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityMountNMSPacket.java delete mode 100644 nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityNMSArmorStand.java delete mode 100644 nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityNMSItem.java delete mode 100644 nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityNMSSlime.java create mode 100644 nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntitySpawnNMSPacket.java create mode 100644 nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityTeleportNMSPacket.java create mode 100644 nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityTypeID.java delete mode 100644 nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/NullBoundingBox.java create mode 100644 nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/PacketByteBuffer.java delete mode 100644 nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionNMSEntityHelper.java create mode 100644 nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionNMSPacket.java create mode 100644 nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionNMSPacketList.java delete mode 100644 nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/CraftNMSArmorStand.java delete mode 100644 nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/CraftNMSItem.java delete mode 100644 nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/CraftNMSSlime.java delete mode 100644 nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/EntityNMSArmorStand.java delete mode 100644 nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/EntityNMSItem.java delete mode 100644 nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/EntityNMSSlime.java delete mode 100644 nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/NullBoundingBox.java delete mode 100644 nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/VersionNMSEntityHelper.java delete mode 100644 nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/CraftNMSArmorStand.java delete mode 100644 nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/CraftNMSItem.java delete mode 100644 nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/CraftNMSSlime.java delete mode 100644 nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityNMSArmorStand.java delete mode 100644 nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityNMSItem.java delete mode 100644 nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityNMSSlime.java delete mode 100644 nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/NullBoundingBox.java delete mode 100644 nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionNMSEntityHelper.java delete mode 100644 nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/CraftNMSArmorStand.java delete mode 100644 nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/CraftNMSItem.java delete mode 100644 nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/CraftNMSSlime.java delete mode 100644 nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/EntityNMSArmorStand.java delete mode 100644 nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/EntityNMSItem.java delete mode 100644 nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/EntityNMSSlime.java delete mode 100644 nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/NullBoundingBox.java delete mode 100644 nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/VersionNMSEntityHelper.java delete mode 100644 nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/CraftNMSArmorStand.java delete mode 100644 nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/CraftNMSItem.java delete mode 100644 nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/CraftNMSSlime.java delete mode 100644 nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityNMSArmorStand.java delete mode 100644 nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityNMSItem.java delete mode 100644 nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityNMSSlime.java delete mode 100644 nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/NullBoundingBox.java delete mode 100644 nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionNMSEntityHelper.java delete mode 100644 plugin/src/main/java/me/filoghost/holographicdisplays/plugin/bridge/protocollib/DebugHelper.java delete mode 100644 plugin/src/main/java/me/filoghost/holographicdisplays/plugin/bridge/protocollib/MetadataHelper.java delete mode 100644 plugin/src/main/java/me/filoghost/holographicdisplays/plugin/bridge/protocollib/PacketListener.java delete mode 100644 plugin/src/main/java/me/filoghost/holographicdisplays/plugin/bridge/protocollib/PacketSender.java delete mode 100644 plugin/src/main/java/me/filoghost/holographicdisplays/plugin/bridge/protocollib/ProtocolLibHook.java create mode 100644 plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/DisplayText.java create mode 100644 plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/ItemLineTracker.java create mode 100644 plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/LineTracker.java create mode 100644 plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/LineTrackerManager.java create mode 100644 plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/LocationBasedLineTracker.java create mode 100644 plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/TextLineTracker.java create mode 100644 plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/TouchableLineTracker.java delete mode 100644 plugin/src/main/java/me/filoghost/holographicdisplays/plugin/lib/packetwrapper/AbstractPacket.java delete mode 100644 plugin/src/main/java/me/filoghost/holographicdisplays/plugin/lib/packetwrapper/WrapperPlayServerAttachEntity.java delete mode 100644 plugin/src/main/java/me/filoghost/holographicdisplays/plugin/lib/packetwrapper/WrapperPlayServerEntityDestroy.java delete mode 100644 plugin/src/main/java/me/filoghost/holographicdisplays/plugin/lib/packetwrapper/WrapperPlayServerEntityMetadata.java delete mode 100644 plugin/src/main/java/me/filoghost/holographicdisplays/plugin/lib/packetwrapper/WrapperPlayServerMount.java delete mode 100644 plugin/src/main/java/me/filoghost/holographicdisplays/plugin/lib/packetwrapper/WrapperPlayServerSpawnEntity.java delete mode 100644 plugin/src/main/java/me/filoghost/holographicdisplays/plugin/lib/packetwrapper/WrapperPlayServerSpawnEntityLiving.java delete mode 100644 plugin/src/main/java/me/filoghost/holographicdisplays/plugin/listener/InteractListener.java create mode 100644 plugin/src/main/java/me/filoghost/holographicdisplays/plugin/listener/PlayerQuitListener.java delete mode 100644 plugin/src/main/java/me/filoghost/holographicdisplays/plugin/listener/SpawnListener.java delete mode 100644 plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/tracking/PlaceholderLineTracker.java delete mode 100644 plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/tracking/TrackedLine.java create mode 100644 plugin/src/test/java/me/filoghost/holographicdisplays/plugin/test/TestAPIHologramsManager.java create mode 100644 plugin/src/test/java/me/filoghost/holographicdisplays/plugin/test/TestNMSManager.java diff --git a/.github/ISSUE_TEMPLATE/1-bug.yml b/.github/ISSUE_TEMPLATE/1-bug.yml index 0bd9a5eb..11f999e1 100644 --- a/.github/ISSUE_TEMPLATE/1-bug.yml +++ b/.github/ISSUE_TEMPLATE/1-bug.yml @@ -17,7 +17,7 @@ body: required: true - label: "I have tested the [latest development build](https://ci.codemc.io/job/filoghost/job/HolographicDisplays) of Holographic Displays and the bug is still present." required: true - - label: "I have updated **Spigot** (and **ProtocolLib** if installed) to the latest release for my particular Minecraft version." + - label: "I have updated **Spigot** to the latest release for my particular Minecraft version." required: true - label: "I made sure the bug hasn't already been reported on the [issue tracker](https://github.com/filoghost/HolographicDisplays/issues?q=is%3Aissue)." required: true @@ -59,12 +59,6 @@ body: validations: required: true - - type: input - attributes: - label: "ProtocolLib version (if installed)" - description: "Output of the command `/version ProtocolLib`." - placeholder: "ProtocolLib version 4.6.0-SNAPSHOT-b476" - - type: input attributes: label: "Installed plugins that allow players to join with multiple Minecraft versions" diff --git a/api/src/main/java/me/filoghost/holographicdisplays/api/HolographicDisplaysAPI.java b/api/src/main/java/me/filoghost/holographicdisplays/api/HolographicDisplaysAPI.java index fced716f..e6a6469b 100644 --- a/api/src/main/java/me/filoghost/holographicdisplays/api/HolographicDisplaysAPI.java +++ b/api/src/main/java/me/filoghost/holographicdisplays/api/HolographicDisplaysAPI.java @@ -9,7 +9,6 @@ import me.filoghost.holographicdisplays.api.hologram.Hologram; import me.filoghost.holographicdisplays.api.internal.HolographicDisplaysAPIProvider; import me.filoghost.holographicdisplays.api.placeholder.PlaceholderReplacer; import org.bukkit.Location; -import org.bukkit.entity.Entity; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; @@ -97,15 +96,4 @@ public interface HolographicDisplaysAPI { */ void unregisterPlaceholders(); - /** - * Checks if an entity is part of a hologram. - * - * @param entity the entity to check - * @return if the entity is part of a hologram - * @since 1 - */ - static boolean isHologramEntity(@NotNull Entity entity) { - return HolographicDisplaysAPIProvider.getImplementation().isHologramEntity(entity); - } - } diff --git a/api/src/main/java/me/filoghost/holographicdisplays/api/hologram/Hologram.java b/api/src/main/java/me/filoghost/holographicdisplays/api/hologram/Hologram.java index ed7d557e..686e4012 100644 --- a/api/src/main/java/me/filoghost/holographicdisplays/api/hologram/Hologram.java +++ b/api/src/main/java/me/filoghost/holographicdisplays/api/hologram/Hologram.java @@ -177,8 +177,6 @@ public interface Hologram { /** * Returns the {@link VisibilitySettings} of this hologram. - *
Note: the usage of the VisibilitySettings requires ProtocolLib. - * Without the plugin, holograms will be always visible. * * @return the VisibilitySettings of this hologram * @since 1 diff --git a/api/src/main/java/me/filoghost/holographicdisplays/api/hologram/VisibilitySettings.java b/api/src/main/java/me/filoghost/holographicdisplays/api/hologram/VisibilitySettings.java index ec9b7a7e..aac4f27e 100644 --- a/api/src/main/java/me/filoghost/holographicdisplays/api/hologram/VisibilitySettings.java +++ b/api/src/main/java/me/filoghost/holographicdisplays/api/hologram/VisibilitySettings.java @@ -11,8 +11,6 @@ import org.jetbrains.annotations.NotNull; /** * Settings to manage the visibility of a hologram to players. Allows to set both the default visibility and the * visibility to a specific player. - *

- * Warning: changing the visibility requires ProtocolLib, otherwise methods of this class have no effect. * * @since 1 */ diff --git a/api/src/main/java/me/filoghost/holographicdisplays/api/internal/HolographicDisplaysAPIProvider.java b/api/src/main/java/me/filoghost/holographicdisplays/api/internal/HolographicDisplaysAPIProvider.java index c9ee3c29..71a05199 100644 --- a/api/src/main/java/me/filoghost/holographicdisplays/api/internal/HolographicDisplaysAPIProvider.java +++ b/api/src/main/java/me/filoghost/holographicdisplays/api/internal/HolographicDisplaysAPIProvider.java @@ -6,7 +6,6 @@ package me.filoghost.holographicdisplays.api.internal; import me.filoghost.holographicdisplays.api.HolographicDisplaysAPI; -import org.bukkit.entity.Entity; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.ApiStatus.Internal; @@ -31,6 +30,4 @@ public abstract class HolographicDisplaysAPIProvider { public abstract HolographicDisplaysAPI getHolographicDisplaysAPI(Plugin plugin); - public abstract boolean isHologramEntity(Entity entity); - } diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/DebugLogger.java b/common/src/main/java/me/filoghost/holographicdisplays/common/DebugLogger.java index 5de63160..46b5ce7d 100644 --- a/common/src/main/java/me/filoghost/holographicdisplays/common/DebugLogger.java +++ b/common/src/main/java/me/filoghost/holographicdisplays/common/DebugLogger.java @@ -6,8 +6,6 @@ package me.filoghost.holographicdisplays.common; import me.filoghost.fcommons.logging.Log; -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.nms.SpawnFailedException; public class DebugLogger { @@ -48,20 +46,4 @@ public class DebugLogger { } } - public static void handleSpawnFail(SpawnFailedException exception, StandardHologramLine parentHologramLine) { - severe("Couldn't spawn entity for this hologram: " + parentHologramLine.getHologram(), exception); - } - - public static void cannotSetPassenger(Throwable t) { - severe("Couldn't set passenger", t); - } - - public static void cannotSetArmorStandAsMarker(Throwable t) { - severe("Couldn't set armor stand as marker", t); - } - - public static void cannotSetPassengerPitchYawDelta(Throwable t) { - severe("Couldn't set passenger pitch/yaw delta", t); - } - } diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/hologram/StandardHologram.java b/common/src/main/java/me/filoghost/holographicdisplays/common/hologram/StandardHologram.java index f84fb99c..09132888 100644 --- a/common/src/main/java/me/filoghost/holographicdisplays/common/hologram/StandardHologram.java +++ b/common/src/main/java/me/filoghost/holographicdisplays/common/hologram/StandardHologram.java @@ -5,24 +5,12 @@ */ package me.filoghost.holographicdisplays.common.hologram; -import org.bukkit.Chunk; -import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; import java.util.List; -public interface StandardHologram { - - World getWorld(); - - double getX(); - - double getY(); - - double getZ(); - - boolean isInChunk(Chunk chunk); +public interface StandardHologram extends StandardHologramComponent { List getLines(); @@ -32,18 +20,4 @@ public interface StandardHologram { boolean isVisibleTo(Player player); - void refresh(); - - void refresh(boolean forceRespawn); - - void refresh(boolean forceRespawn, boolean isChunkLoaded); - - void despawnEntities(); - - boolean isDeleted(); - - void setDeleted(); - - String toFormattedString(); - } diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/hologram/StandardHologramComponent.java b/common/src/main/java/me/filoghost/holographicdisplays/common/hologram/StandardHologramComponent.java new file mode 100644 index 00000000..e3b4cd8b --- /dev/null +++ b/common/src/main/java/me/filoghost/holographicdisplays/common/hologram/StandardHologramComponent.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.common.hologram; + +import org.bukkit.World; + +public interface StandardHologramComponent { + + World getWorld(); + + double getX(); + + double getY(); + + double getZ(); + + int getChunkX(); + + int getChunkZ(); + + boolean isDeleted(); + + void setDeleted(); + +} diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/hologram/StandardHologramLine.java b/common/src/main/java/me/filoghost/holographicdisplays/common/hologram/StandardHologramLine.java index 410ef0b3..0fbc4183 100644 --- a/common/src/main/java/me/filoghost/holographicdisplays/common/hologram/StandardHologramLine.java +++ b/common/src/main/java/me/filoghost/holographicdisplays/common/hologram/StandardHologramLine.java @@ -6,20 +6,13 @@ package me.filoghost.holographicdisplays.common.hologram; import org.bukkit.World; -import org.bukkit.entity.Player; -import java.util.Collection; - -public interface StandardHologramLine { +public interface StandardHologramLine extends StandardHologramComponent { StandardHologram getHologram(); - void respawn(World world, double x, double y, double z); - - void despawn(); + void setLocation(World world, double x, double y, double z); double getHeight(); - void collectTrackedEntityIDs(Player player, Collection collector); - } diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/hologram/StandardItemLine.java b/common/src/main/java/me/filoghost/holographicdisplays/common/hologram/StandardItemLine.java index 2da9a41d..27eaaddd 100644 --- a/common/src/main/java/me/filoghost/holographicdisplays/common/hologram/StandardItemLine.java +++ b/common/src/main/java/me/filoghost/holographicdisplays/common/hologram/StandardItemLine.java @@ -5,16 +5,13 @@ */ package me.filoghost.holographicdisplays.common.hologram; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.nms.entity.NMSItem; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; public interface StandardItemLine extends StandardTouchableLine { + ItemStack getItemStack(); + void onPickup(Player player); - NMSItem getNMSItem(); - - NMSArmorStand getNMSItemVehicle(); - } diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/hologram/StandardTextLine.java b/common/src/main/java/me/filoghost/holographicdisplays/common/hologram/StandardTextLine.java index a7914d72..a0614032 100644 --- a/common/src/main/java/me/filoghost/holographicdisplays/common/hologram/StandardTextLine.java +++ b/common/src/main/java/me/filoghost/holographicdisplays/common/hologram/StandardTextLine.java @@ -5,14 +5,10 @@ */ package me.filoghost.holographicdisplays.common.hologram; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; - public interface StandardTextLine extends StandardTouchableLine { String getText(); boolean isAllowPlaceholders(); - NMSArmorStand getNMSArmorStand(); - } diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/hologram/StandardTouchableLine.java b/common/src/main/java/me/filoghost/holographicdisplays/common/hologram/StandardTouchableLine.java index 69de4a09..281e611f 100644 --- a/common/src/main/java/me/filoghost/holographicdisplays/common/hologram/StandardTouchableLine.java +++ b/common/src/main/java/me/filoghost/holographicdisplays/common/hologram/StandardTouchableLine.java @@ -5,16 +5,12 @@ */ package me.filoghost.holographicdisplays.common.hologram; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.nms.entity.NMSSlime; import org.bukkit.entity.Player; public interface StandardTouchableLine extends StandardHologramLine { void onTouch(Player player); - NMSSlime getNMSSlime(); - - NMSArmorStand getNMSSlimeVehicle(); + boolean hasTouchHandler(); } diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/AbstractNMSPacketList.java b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/AbstractNMSPacketList.java new file mode 100644 index 00000000..23579701 --- /dev/null +++ b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/AbstractNMSPacketList.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.common.nms; + +import org.bukkit.entity.Player; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; + +public abstract class AbstractNMSPacketList implements NMSPacketList { + + // Lazily instantiate a list only when adding more than one element + private @Nullable NMSPacket singlePacket; + private @Nullable List multiplePackets; + + protected void add(NMSPacket packet) { + if (multiplePackets != null) { + multiplePackets.add(packet); + } else if (singlePacket != null) { + multiplePackets = new ArrayList<>(); + multiplePackets.add(singlePacket); + multiplePackets.add(packet); + singlePacket = null; + } else { + singlePacket = packet; + } + } + + @Override + public void sendTo(Player player) { + if (multiplePackets != null) { + for (NMSPacket packet : multiplePackets) { + packet.sendTo(player); + } + } else if (singlePacket != null) { + singlePacket.sendTo(player); + } + } + +} diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/EntityID.java b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/EntityID.java new file mode 100644 index 00000000..34be40aa --- /dev/null +++ b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/EntityID.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.common.nms; + +import org.jetbrains.annotations.Nullable; + +import java.util.UUID; +import java.util.function.Supplier; + +public class EntityID { + + private final Supplier numericIDGenerator; + + // Lazy initialization + private @Nullable Integer numericID; + private @Nullable UUID uuid; + + public EntityID(Supplier numericIDGenerator) { + this.numericIDGenerator = numericIDGenerator; + } + + public int getNumericID() { + if (numericID == null) { + numericID = numericIDGenerator.get(); + } + return numericID; + } + + public UUID getUUID() { + if (uuid == null) { + uuid = UUID.randomUUID(); + } + return uuid; + } + +} diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/FallbackEntityIDGenerator.java b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/FallbackEntityIDGenerator.java new file mode 100644 index 00000000..db59749e --- /dev/null +++ b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/FallbackEntityIDGenerator.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.common.nms; + +import java.util.function.Supplier; + +/** + * Fallback entity ID generator that counts down from Integer.MIN_VALUE / 2 to Integer.MIN_VALUE, looping over + * when reaching the end. + *

+ * It does not start from zero to avoid conflicts with fake entities created by other plugins, and it counts down to minimize the time + * window where the real NMS counter and this one may return the same numbers. + *

+ * The Minecraft client can disconnect if the server sends bad packets for two entities with the same ID, which may have different types. + */ +public class FallbackEntityIDGenerator implements Supplier { + + private static final int COUNTER_START_VALUE = Integer.MIN_VALUE / 2; + private static final int COUNTER_END_VALUE = Integer.MIN_VALUE; + + private int counter = COUNTER_START_VALUE; + + @Override + public Integer get() { + // Loop over on allowed range values + if (counter == COUNTER_END_VALUE) { + counter = COUNTER_START_VALUE; + } + + counter--; + return counter; + } + +} diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/IndividualCustomName.java b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/IndividualCustomName.java new file mode 100644 index 00000000..c868ea01 --- /dev/null +++ b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/IndividualCustomName.java @@ -0,0 +1,15 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.common.nms; + +import org.bukkit.entity.Player; + +@FunctionalInterface +public interface IndividualCustomName { + + String get(Player player); + +} diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/IndividualNMSPacket.java b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/IndividualNMSPacket.java new file mode 100644 index 00000000..d0310155 --- /dev/null +++ b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/IndividualNMSPacket.java @@ -0,0 +1,25 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.common.nms; + +import org.bukkit.entity.Player; + +import java.util.function.Function; + +public class IndividualNMSPacket implements NMSPacket { + + private final Function individualPacketFactory; + + public IndividualNMSPacket(Function individualPacketFactory) { + this.individualPacketFactory = individualPacketFactory; + } + + @Override + public void sendTo(Player player) { + individualPacketFactory.apply(player).sendTo(player); + } + +} diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/NMSCommons.java b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/NMSCommons.java deleted file mode 100644 index dc80c56e..00000000 --- a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/NMSCommons.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.common.nms; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; - -public class NMSCommons { - - /** - * 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(); - - /** - * Paper contains some code changes compared to Spigot. - */ - public static final boolean IS_PAPER_SERVER = Bukkit.getName().equals("Paper"); - -} diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/NMSErrors.java b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/NMSErrors.java new file mode 100644 index 00000000..449dbaff --- /dev/null +++ b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/NMSErrors.java @@ -0,0 +1,14 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.common.nms; + +public class NMSErrors { + + public static final String GETTING_ENTITY_ID_GENERATOR_SHORT = "Could not get the NMS entity ID generator."; + public static final String GETTING_ENTITY_ID_GENERATOR_LONG = GETTING_ENTITY_ID_GENERATOR_SHORT + + " There is a small chance of entity ID conflicts, causing client-side issues on single entities."; + +} diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/NMSManager.java b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/NMSManager.java index 7cc39b9a..93b3f039 100644 --- a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/NMSManager.java +++ b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/NMSManager.java @@ -5,40 +5,10 @@ */ package me.filoghost.holographicdisplays.common.nms; -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntity; -import me.filoghost.holographicdisplays.common.nms.entity.NMSItem; -import me.filoghost.holographicdisplays.common.nms.entity.NMSSlime; -import org.bukkit.World; -import org.bukkit.entity.Entity; -import org.bukkit.inventory.ItemStack; - public interface NMSManager { - /** - * Register all the custom entities of the plugin. - * - * @throws Exception if anything during the process fails - */ - void setup() throws Exception; + EntityID newEntityID(); - NMSArmorStand spawnNMSArmorStand(World bukkitWorld, double x, double y, double z, StandardHologramLine parentHologramLine) - throws SpawnFailedException; - - NMSItem spawnNMSItem(World bukkitWorld, double x, double y, double z, StandardItemLine parentHologramLine, ItemStack stack) - throws SpawnFailedException; - - NMSSlime spawnNMSSlime(World bukkitWorld, double x, double y, double z, StandardHologramLine parentHologramLine) - throws SpawnFailedException; - - boolean isNMSEntityBase(Entity bukkitEntity); - - NMSEntity getNMSEntityBase(Entity bukkitEntity); - - NMSEntity getNMSEntityBaseFromID(World bukkitWorld, int entityID); - - Object createCustomNameNMSObject(String customName); + NMSPacketList createPacketList(); } diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/ProtocolPacketSettings.java b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/NMSPacket.java similarity index 62% rename from common/src/main/java/me/filoghost/holographicdisplays/common/nms/ProtocolPacketSettings.java rename to common/src/main/java/me/filoghost/holographicdisplays/common/nms/NMSPacket.java index bef9886d..66916233 100644 --- a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/ProtocolPacketSettings.java +++ b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/NMSPacket.java @@ -5,8 +5,10 @@ */ package me.filoghost.holographicdisplays.common.nms; -public interface ProtocolPacketSettings { +import org.bukkit.entity.Player; - boolean sendAccurateLocationPackets(); +public interface NMSPacket { + + void sendTo(Player player); } diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/NMSPacketList.java b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/NMSPacketList.java new file mode 100644 index 00000000..293a5c2d --- /dev/null +++ b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/NMSPacketList.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.common.nms; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public interface NMSPacketList { + + void addArmorStandSpawnPackets(EntityID entityID, double locationX, double locationY, double locationZ); + + void addArmorStandSpawnPackets(EntityID entityID, double locationX, double locationY, double locationZ, String customName); + + void addArmorStandSpawnPackets(EntityID entityID, double locationX, double locationY, double locationZ, IndividualCustomName individualCustomName); + + void addArmorStandNameChangePackets(EntityID entityID, String customName); + + void addArmorStandNameChangePackets(EntityID entityID, IndividualCustomName individualCustomName); + + void addItemSpawnPackets(EntityID entityID, double locationX, double locationY, double locationZ, ItemStack itemStack); + + void addItemStackChangePackets(EntityID entityID, ItemStack itemStack); + + void addSlimeSpawnPackets(EntityID entityID, double locationX, double locationY, double locationZ); + + void addEntityDestroyPackets(EntityID... entityIDs); + + void addTeleportPackets(EntityID entityID, double locationX, double locationY, double locationZ); + + void addMountPackets(EntityID vehicleEntityID, EntityID passengerEntityID); + + void sendTo(Player player); + +} diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/SpawnFailedException.java b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/SpawnFailedException.java deleted file mode 100644 index fc649359..00000000 --- a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/SpawnFailedException.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.common.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); - } - -} diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/NMSArmorStand.java b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/NMSArmorStand.java deleted file mode 100644 index 6f82357d..00000000 --- a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/NMSArmorStand.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.common.nms.entity; - -public interface NMSArmorStand extends NMSVehicle { - - void setCustomNameNMS(String customName); - - /** - * Returns the last custom name set. - */ - String getCustomNameStringNMS(); - - /** - * Returns the custom name NMS object, whose type is version-dependent (String for MC 1.12 and below, ChatComponent - * for MC 1.13+). The returned value may differ from {@link #getCustomNameStringNMS()} even if it's a string, for - * example if the custom name has been truncated before being applied. - */ - Object getCustomNameObjectNMS(); - -} diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/NMSEntity.java b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/NMSEntity.java deleted file mode 100644 index 64f5e897..00000000 --- a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/NMSEntity.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.common.nms.entity; - -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import org.bukkit.entity.Player; - -/** - * A custom entity that is part of a hologram. - */ -public interface NMSEntity { - - StandardHologramLine getHologramLine(); - - void setLocationNMS(double x, double y, double z); - - boolean isDeadNMS(); - - void killEntityNMS(); - - int getIdNMS(); - - org.bukkit.entity.Entity getBukkitEntityNMS(); - - boolean isTrackedBy(Player bukkitPlayer); - -} diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/NMSEntityHelper.java b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/NMSEntityHelper.java deleted file mode 100644 index 23611a9e..00000000 --- a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/NMSEntityHelper.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.common.nms.entity; - -import org.bukkit.entity.Player; - -public abstract class NMSEntityHelper { - - private T tracker; - - protected final T getTracker() { - if (tracker == null) { - // Cache it the first time it's available - tracker = getTracker0(); - } - - return tracker; - } - - protected abstract T getTracker0(); - - public abstract boolean isTrackedBy(Player bukkitPlayer); - -} diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/NMSItem.java b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/NMSItem.java deleted file mode 100644 index 0f656dd7..00000000 --- a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/NMSItem.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.common.nms.entity; - -import org.bukkit.inventory.ItemStack; - -public interface NMSItem extends NMSEntity { - - void setItemStackNMS(ItemStack stack); - - /** - * Returns the item stack NMS object. - */ - Object getRawItemStack(); - -} diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/NMSSlime.java b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/NMSSlime.java deleted file mode 100644 index 7eaff379..00000000 --- a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/NMSSlime.java +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.common.nms.entity; - -public interface NMSSlime extends NMSEntity { - -} diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/NMSVehicle.java b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/NMSVehicle.java deleted file mode 100644 index a02a69a0..00000000 --- a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/NMSVehicle.java +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.common.nms.entity; - -public interface NMSVehicle extends NMSEntity { - - void setPassengerNMS(NMSEntity passenger); - -} diff --git a/legacy-api/v1/src/main/java/com/gmail/filoghost/holograms/api/HolographicDisplaysAPI.java b/legacy-api/v1/src/main/java/com/gmail/filoghost/holograms/api/HolographicDisplaysAPI.java index 7b2d5cef..e03da755 100644 --- a/legacy-api/v1/src/main/java/com/gmail/filoghost/holograms/api/HolographicDisplaysAPI.java +++ b/legacy-api/v1/src/main/java/com/gmail/filoghost/holograms/api/HolographicDisplaysAPI.java @@ -77,7 +77,7 @@ public class HolographicDisplaysAPI { @Deprecated public static boolean isHologramEntity(Entity bukkitEntity) { - return me.filoghost.holographicdisplays.api.HolographicDisplaysAPI.isHologramEntity(bukkitEntity); + return false; } } diff --git a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/CraftNMSArmorStand.java b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/CraftNMSArmorStand.java deleted file mode 100644 index 949fc9c5..00000000 --- a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/CraftNMSArmorStand.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_10_R1; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_10_R1.CraftServer; -import org.bukkit.craftbukkit.v1_10_R1.entity.CraftArmorStand; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.ItemStack; -import org.bukkit.potion.PotionEffect; -import org.bukkit.util.EulerAngle; -import org.bukkit.util.Vector; - -import java.util.Collection; - -public class CraftNMSArmorStand extends CraftArmorStand { - - public CraftNMSArmorStand(CraftServer server, EntityNMSArmorStand entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // 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) {} - - // 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 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 setGliding(boolean gliding) {} - @Override public boolean setLeashHolder(Entity holder) { return false; } - - // Methods from Entity - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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) {} - -} diff --git a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/CraftNMSItem.java b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/CraftNMSItem.java deleted file mode 100644 index d6eeda5d..00000000 --- a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/CraftNMSItem.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_10_R1; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_10_R1.CraftServer; -import org.bukkit.craftbukkit.v1_10_R1.entity.CraftItem; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; - -public class CraftNMSItem extends CraftItem { - - public CraftNMSItem(CraftServer server, EntityNMSItem entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // Methods from Entity - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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) {} - -} diff --git a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/CraftNMSSlime.java b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/CraftNMSSlime.java deleted file mode 100644 index 5c1e3d68..00000000 --- a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/CraftNMSSlime.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_10_R1; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_10_R1.CraftServer; -import org.bukkit.craftbukkit.v1_10_R1.entity.CraftSlime; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.potion.PotionEffect; -import org.bukkit.util.Vector; - -import java.util.Collection; - -public class CraftNMSSlime extends CraftSlime { - - public CraftNMSSlime(CraftServer server, EntityNMSSlime entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // 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 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 setGliding(boolean gliding) {} - @Override public boolean setLeashHolder(Entity holder) { return false; } - - // Methods from Entity - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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) {} - -} diff --git a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityNMSArmorStand.java b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityNMSArmorStand.java deleted file mode 100644 index da4a9494..00000000 --- a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityNMSArmorStand.java +++ /dev/null @@ -1,260 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_10_R1; - -import me.filoghost.fcommons.Preconditions; -import me.filoghost.fcommons.Strings; -import me.filoghost.fcommons.reflection.ReflectField; -import me.filoghost.holographicdisplays.common.DebugLogger; -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.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.EnumHand; -import net.minecraft.server.v1_10_R1.EnumInteractionResult; -import net.minecraft.server.v1_10_R1.EnumItemSlot; -import net.minecraft.server.v1_10_R1.ItemStack; -import net.minecraft.server.v1_10_R1.NBTTagCompound; -import net.minecraft.server.v1_10_R1.PacketPlayOutEntityTeleport; -import net.minecraft.server.v1_10_R1.SoundEffect; -import net.minecraft.server.v1_10_R1.Vec3D; -import net.minecraft.server.v1_10_R1.World; -import org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity; -import org.bukkit.entity.Player; - -import java.util.Objects; - -public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand { - - private static final ReflectField VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "au"); - - private final StandardHologramLine parentHologramLine; - private final ProtocolPacketSettings protocolPacketSettings; - private final VersionNMSEntityHelper helper; - private String customName; - - public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, ProtocolPacketSettings protocolPacketSettings) { - super(world); - this.parentHologramLine = parentHologramLine; - this.protocolPacketSettings = protocolPacketSettings; - this.helper = new VersionNMSEntityHelper(this); - - super.setInvisible(true); - super.setSmall(true); - super.setArms(false); - super.setNoGravity(true); - super.setBasePlate(true); - super.setMarker(true); - super.collides = false; - super.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet - forceSetBoundingBox(new NullBoundingBox()); - } - - @Override - public void m() { - // Disable normal ticking for this entity - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity - if (super.onGround) { - super.onGround = false; - } - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity - if (super.onGround) { - super.onGround = false; - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound e(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void f(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void a(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void setCustomName(String customName) { - // Prevents changes to custom name - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Prevents changes to custom name visibility - } - - @Override - public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, ItemStack itemstack, EnumHand enumhand) { - // Prevent armor stand from being equipped - return EnumInteractionResult.PASS; - } - - @Override - public boolean c(int i, ItemStack item) { - // Prevent armor stand from being equipped - return false; - } - - @Override - public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { - // Prevent armor stand from being equipped - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Prevent changes to bounding box - } - - public void forceSetBoundingBox(AxisAlignedBB boundingBox) { - super.a(boundingBox); - } - - @Override - public void a(SoundEffect soundeffect, float f, float f1) { - // Remove sounds - } - - @Override - public void setCustomNameNMS(String customName) { - if (Objects.equals(this.customName, customName)) { - return; - } - this.customName = customName; - super.setCustomName(createCustomNameNMSObject(customName)); - super.setCustomNameVisible(customName != null && !customName.isEmpty()); - } - - protected static String createCustomNameNMSObject(String customName) { - return customName != null ? Strings.truncate(customName, 256) : ""; - } - - @Override - public String getCustomNameStringNMS() { - return this.customName; - } - - @Override - public String getCustomNameObjectNMS() { - return super.getCustomName(); - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSArmorStand(super.world.getServer(), this); - } - return super.bukkitEntity; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - if (protocolPacketSettings.sendAccurateLocationPackets()) { - helper.broadcastPacket(new PacketPlayOutEntityTeleport(this)); - } - } - - @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(passengerEntity); - } catch (ReflectiveOperationException e) { - DebugLogger.cannotSetPassenger(e); - } - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - -} diff --git a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityNMSItem.java b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityNMSItem.java deleted file mode 100644 index 8c01c05a..00000000 --- a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityNMSItem.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_10_R1; - -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; -import me.filoghost.holographicdisplays.common.nms.NMSCommons; -import me.filoghost.holographicdisplays.common.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; -import net.minecraft.server.v1_10_R1.EntityHuman; -import net.minecraft.server.v1_10_R1.EntityItem; -import net.minecraft.server.v1_10_R1.EntityPlayer; -import net.minecraft.server.v1_10_R1.ItemStack; -import net.minecraft.server.v1_10_R1.NBTTagCompound; -import net.minecraft.server.v1_10_R1.NBTTagList; -import net.minecraft.server.v1_10_R1.NBTTagString; -import net.minecraft.server.v1_10_R1.PacketPlayOutMount; -import net.minecraft.server.v1_10_R1.World; -import org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack; -import org.bukkit.entity.Player; - -public class EntityNMSItem extends EntityItem implements NMSItem { - - private final StandardItemLine parentHologramLine; - private final VersionNMSEntityHelper helper; - - private int resendMountPacketTicks; - - public EntityNMSItem(World world, StandardItemLine parentHologramLine) { - super(world); - this.parentHologramLine = parentHologramLine; - this.helper = new VersionNMSEntityHelper(this); - - super.pickupDelay = Integer.MAX_VALUE; - } - - @Override - public void m() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - - if (resendMountPacketTicks++ > 20) { - resendMountPacketTicks = 0; - - Entity vehicle = bB(); - if (vehicle != null) { - // Send a packet near to "remind" players that the item is riding the armor stand (Spigot bug or client bug) - helper.broadcastPacket(new PacketPlayOutMount(vehicle)); - } - } - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - // Method called when a player is near - @Override - public void d(EntityHuman human) { - if (human.locY < super.locY - 1.5 || human.locY > super.locY + 1.0) { - // Too low or too high, it's a bit weird - return; - } - - if (human instanceof EntityPlayer) { - parentHologramLine.onPickup(((EntityPlayer) human).getBukkitEntity()); - // It is never added to the inventory - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound e(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void f(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void a(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public boolean isAlive() { - // This override prevents items from being picked up by hoppers (should have no side effects) - return false; - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSItem(super.world.getServer(), this); - } - return super.bukkitEntity; - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - } - - @Override - public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) { - ItemStack newItem = CraftItemStack.asNMSCopy(stack); - - if (newItem == null) { - newItem = new ItemStack(Blocks.BEDROCK); - } - - if (newItem.getTag() == null) { - newItem.setTag(new NBTTagCompound()); - } - NBTTagCompound display = newItem.getTag().getCompound("display"); - - if (!newItem.getTag().hasKey("display")) { - newItem.getTag().set("display", display); - } - - NBTTagList tagList = new NBTTagList(); - tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE)); - display.set("Lore", tagList); - - super.setItemStack(newItem); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - - @Override - public Object getRawItemStack() { - return super.getItemStack(); - } - -} diff --git a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityNMSSlime.java b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityNMSSlime.java deleted file mode 100644 index f85c7b02..00000000 --- a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityNMSSlime.java +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_10_R1; - -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.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; -import net.minecraft.server.v1_10_R1.EntityDamageSource; -import net.minecraft.server.v1_10_R1.EntityPlayer; -import net.minecraft.server.v1_10_R1.EntitySlime; -import net.minecraft.server.v1_10_R1.NBTTagCompound; -import net.minecraft.server.v1_10_R1.PacketPlayOutMount; -import net.minecraft.server.v1_10_R1.SoundEffect; -import net.minecraft.server.v1_10_R1.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.player.PlayerInteractEntityEvent; - -public class EntityNMSSlime extends EntitySlime implements NMSSlime { - - private final StandardHologramLine parentHologramLine; - private final VersionNMSEntityHelper helper; - - private int resendMountPacketTicks; - - public EntityNMSSlime(World world, StandardHologramLine parentHologramLine) { - super(world); - this.parentHologramLine = parentHologramLine; - this.helper = new VersionNMSEntityHelper(this); - - super.persistent = true; - super.collides = false; - super.a(0.0F, 0.0F); - super.setSize(1); - super.setInvisible(true); - forceSetBoundingBox(new NullBoundingBox()); - } - - @Override - public void m() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - - if (resendMountPacketTicks++ > 20) { - resendMountPacketTicks = 0; - - Entity vehicle = bB(); - if (vehicle != null) { - // Send a packet near to "remind" players that the slime is riding the armor stand (Spigot bug or client bug) - helper.broadcastPacket(new PacketPlayOutMount(vehicle)); - } - } - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Prevent changes to bounding box - } - - public void forceSetBoundingBox(AxisAlignedBB boundingBox) { - super.a(boundingBox); - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound e(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void f(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void a(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean damageEntity(DamageSource damageSource, float amount) { - if (damageSource instanceof EntityDamageSource) { - EntityDamageSource entityDamageSource = (EntityDamageSource) damageSource; - if (entityDamageSource.getEntity() instanceof EntityPlayer) { - Player player = ((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(); - PlayerInteractEntityEvent event = new PlayerInteractEntityEvent(player, getBukkitEntity()); - Bukkit.getPluginManager().callEvent(event); // Bukkit takes care of the exceptions - } - } - return false; - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void setCustomName(String customName) { - // Prevents changes to custom name - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Prevents changes to custom name visibility - } - - @Override - public void a(SoundEffect soundeffect, float f, float f1) { - // Remove sounds - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSSlime(super.world.getServer(), this); - } - return super.bukkitEntity; - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - -} diff --git a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/NullBoundingBox.java b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/NullBoundingBox.java deleted file mode 100644 index b9d9505a..00000000 --- a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/NullBoundingBox.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_10_R1; - -import net.minecraft.server.v1_10_R1.AxisAlignedBB; -import net.minecraft.server.v1_10_R1.BlockPosition; -import net.minecraft.server.v1_10_R1.MovingObjectPosition; -import net.minecraft.server.v1_10_R1.Vec3D; - -public class NullBoundingBox extends AxisAlignedBB { - - public NullBoundingBox() { - super(0, 0, 0, 0, 0, 0); - } - - @Override - public double a() { - return 0.0; - } - - @Override - public double a(AxisAlignedBB arg0, double arg1) { - return 0.0; - } - - @Override - public AxisAlignedBB a(AxisAlignedBB arg0) { - return this; - } - - @Override - public AxisAlignedBB a(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public MovingObjectPosition b(Vec3D arg0, Vec3D arg1) { - return null; - } - - @Override - public boolean a(Vec3D arg0) { - return false; - } - - @Override - public double b(AxisAlignedBB arg0, double arg1) { - return 0.0; - } - - @Override - public boolean b(AxisAlignedBB arg0) { - return false; - } - - @Override - public double c(AxisAlignedBB arg0, double arg1) { - return 0.0; - } - - @Override - public AxisAlignedBB c(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public AxisAlignedBB grow(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public AxisAlignedBB shrink(double arg0) { - return this; - } - - @Override - public AxisAlignedBB a(BlockPosition arg0) { - return this; - } - - @Override - public boolean a(double arg0, double arg1, double arg2, double arg3, double arg4, double arg5) { - return false; - } - - @Override - public boolean b(Vec3D arg0) { - return false; - } - - @Override - public boolean c(Vec3D arg0) { - return false; - } - - @Override - public boolean d(Vec3D arg0) { - return false; - } - - @Override - public AxisAlignedBB e(double arg0) { - return this; - } - - @Override - public AxisAlignedBB g(double arg0) { - return this; - } - -} diff --git a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionNMSEntityHelper.java b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionNMSEntityHelper.java deleted file mode 100644 index a31ac257..00000000 --- a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionNMSEntityHelper.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_10_R1; - -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntityHelper; -import net.minecraft.server.v1_10_R1.Entity; -import net.minecraft.server.v1_10_R1.EntityTrackerEntry; -import net.minecraft.server.v1_10_R1.Packet; -import net.minecraft.server.v1_10_R1.WorldServer; -import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; - -public class VersionNMSEntityHelper extends NMSEntityHelper { - - private final Entity entity; - - public VersionNMSEntityHelper(Entity entity) { - this.entity = entity; - } - - @Override - protected EntityTrackerEntry getTracker0() { - return ((WorldServer) entity.world).tracker.trackedEntities.get(entity.getId()); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - EntityTrackerEntry tracker = getTracker(); - if (tracker != null) { - return tracker.trackedPlayers.contains(((CraftPlayer) bukkitPlayer).getHandle()); - } else { - return false; - } - } - - public void broadcastPacket(Packet packet) { - EntityTrackerEntry tracker = getTracker(); - if (tracker != null) { - tracker.broadcast(packet); - } - } - -} diff --git a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionNMSManager.java b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionNMSManager.java index 63ddbced..b18b37b3 100644 --- a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionNMSManager.java +++ b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionNMSManager.java @@ -5,146 +5,20 @@ */ package me.filoghost.holographicdisplays.nms.v1_10_R1; -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.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; +import me.filoghost.holographicdisplays.common.nms.EntityID; import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; -import me.filoghost.holographicdisplays.common.nms.SpawnFailedException; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntity; -import me.filoghost.holographicdisplays.common.nms.entity.NMSItem; -import net.minecraft.server.v1_10_R1.Entity; -import net.minecraft.server.v1_10_R1.EntityTypes; -import net.minecraft.server.v1_10_R1.MathHelper; -import net.minecraft.server.v1_10_R1.World; -import net.minecraft.server.v1_10_R1.WorldServer; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_10_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity; -import org.bukkit.inventory.ItemStack; - -import java.util.Map; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; public class VersionNMSManager implements NMSManager { - private static final ReflectField, String>> ENTITY_NAMES_BY_CLASS_FIELD - = ReflectField.lookup(new ClassToken, String>>() {}, EntityTypes.class, "d"); - private static final ReflectField, Integer>> ENTITY_IDS_BY_CLASS_FIELD - = ReflectField.lookup(new ClassToken, Integer>>() {}, EntityTypes.class, "f"); - - private static final ReflectMethod REGISTER_ENTITY_METHOD = ReflectMethod.lookup(Object.class, World.class, "b", Entity.class); - - private final ProtocolPacketSettings protocolPacketSettings; - - public VersionNMSManager(ProtocolPacketSettings protocolPacketSettings) { - this.protocolPacketSettings = protocolPacketSettings; + @Override + public EntityID newEntityID() { + return null; } @Override - public void setup() throws Exception { - registerCustomEntity(EntityNMSArmorStand.class, "ArmorStand", 30); - registerCustomEntity(EntityNMSItem.class, "Item", 1); - registerCustomEntity(EntityNMSSlime.class, "Slime", 55); - } - - public void registerCustomEntity(Class entityClass, String name, int id) throws Exception { - ENTITY_NAMES_BY_CLASS_FIELD.getStatic().put(entityClass, name); - ENTITY_IDS_BY_CLASS_FIELD.getStatic().put(entityClass, id); - } - - @Override - public NMSItem spawnNMSItem( - org.bukkit.World bukkitWorld, double x, double y, double z, - StandardItemLine parentHologramLine, - ItemStack stack) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSItem item = new EntityNMSItem(nmsWorld, parentHologramLine); - 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 parentHologramLine) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSSlime slime = new EntityNMSSlime(nmsWorld, parentHologramLine); - 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 parentHologramLine) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) world).getHandle(); - EntityNMSArmorStand armorStand = new EntityNMSArmorStand(nmsWorld, parentHologramLine, protocolPacketSettings); - armorStand.setLocationNMS(x, y, z); - addEntityToWorld(nmsWorld, armorStand); - return armorStand; - } - - 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); - final int chunkZ = MathHelper.floor(nmsEntity.locZ / 16.0); - - if (!nmsWorld.getChunkProviderServer().isLoaded(chunkX, chunkZ)) { - // This should never happen - nmsEntity.dead = true; - throw new SpawnFailedException(SpawnFailedException.CHUNK_NOT_LOADED); - } - - nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity); - nmsWorld.entityList.add(nmsEntity); - - try { - REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity); - } catch (ReflectiveOperationException e) { - 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 NMSEntity; - } - - @Override - public NMSEntity getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - - if (nmsEntity instanceof NMSEntity) { - return (NMSEntity) nmsEntity; - } else { - return null; - } - } - - @Override - public NMSEntity getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - Entity nmsEntity = nmsWorld.getEntity(entityID); - - if (nmsEntity instanceof NMSEntity) { - return (NMSEntity) nmsEntity; - } else { - return null; - } - } - - @Override - public Object createCustomNameNMSObject(String customName) { - return EntityNMSArmorStand.createCustomNameNMSObject(customName); + public NMSPacketList createPacketList() { + return null; } } diff --git a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/CraftNMSArmorStand.java b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/CraftNMSArmorStand.java deleted file mode 100644 index 3434f5e3..00000000 --- a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/CraftNMSArmorStand.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_11_R1; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_11_R1.CraftServer; -import org.bukkit.craftbukkit.v1_11_R1.entity.CraftArmorStand; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.ItemStack; -import org.bukkit.potion.PotionEffect; -import org.bukkit.util.EulerAngle; -import org.bukkit.util.Vector; - -import java.util.Collection; - -public class CraftNMSArmorStand extends CraftArmorStand { - - public CraftNMSArmorStand(CraftServer server, EntityNMSArmorStand entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // 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) {} - - // 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 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 setGliding(boolean gliding) {} - @Override public boolean setLeashHolder(Entity holder) { return false; } - - // Methods from Entity - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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) {} - -} diff --git a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/CraftNMSItem.java b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/CraftNMSItem.java deleted file mode 100644 index 373a49e1..00000000 --- a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/CraftNMSItem.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_11_R1; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_11_R1.CraftServer; -import org.bukkit.craftbukkit.v1_11_R1.entity.CraftItem; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; - -public class CraftNMSItem extends CraftItem { - - public CraftNMSItem(CraftServer server, EntityNMSItem entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // Methods from Entity - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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) {} - -} diff --git a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/CraftNMSSlime.java b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/CraftNMSSlime.java deleted file mode 100644 index 901be493..00000000 --- a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/CraftNMSSlime.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_11_R1; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_11_R1.CraftServer; -import org.bukkit.craftbukkit.v1_11_R1.entity.CraftSlime; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.potion.PotionEffect; -import org.bukkit.util.Vector; - -import java.util.Collection; - -public class CraftNMSSlime extends CraftSlime { - - public CraftNMSSlime(CraftServer server, EntityNMSSlime entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // 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 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 setGliding(boolean gliding) {} - @Override public boolean setLeashHolder(Entity holder) { return false; } - - // Methods from Entity - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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) {} - -} diff --git a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityNMSArmorStand.java b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityNMSArmorStand.java deleted file mode 100644 index 49ef2ac5..00000000 --- a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityNMSArmorStand.java +++ /dev/null @@ -1,260 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_11_R1; - -import me.filoghost.fcommons.Preconditions; -import me.filoghost.fcommons.Strings; -import me.filoghost.fcommons.reflection.ReflectField; -import me.filoghost.holographicdisplays.common.DebugLogger; -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.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.EnumHand; -import net.minecraft.server.v1_11_R1.EnumInteractionResult; -import net.minecraft.server.v1_11_R1.EnumItemSlot; -import net.minecraft.server.v1_11_R1.ItemStack; -import net.minecraft.server.v1_11_R1.NBTTagCompound; -import net.minecraft.server.v1_11_R1.PacketPlayOutEntityTeleport; -import net.minecraft.server.v1_11_R1.SoundEffect; -import net.minecraft.server.v1_11_R1.Vec3D; -import net.minecraft.server.v1_11_R1.World; -import org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity; -import org.bukkit.entity.Player; - -import java.util.Objects; - -public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand { - - private static final ReflectField VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "au"); - - private final StandardHologramLine parentHologramLine; - private final ProtocolPacketSettings protocolPacketSettings; - private final VersionNMSEntityHelper helper; - private String customName; - - public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, ProtocolPacketSettings protocolPacketSettings) { - super(world); - this.parentHologramLine = parentHologramLine; - this.protocolPacketSettings = protocolPacketSettings; - this.helper = new VersionNMSEntityHelper(this); - - super.setInvisible(true); - super.setSmall(true); - super.setArms(false); - super.setNoGravity(true); - super.setBasePlate(true); - super.setMarker(true); - super.collides = false; - super.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet - forceSetBoundingBox(new NullBoundingBox()); - } - - @Override - public void A_() { - // Disable normal ticking for this entity - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity - if (super.onGround) { - super.onGround = false; - } - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity - if (super.onGround) { - super.onGround = false; - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound e(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void f(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void a(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void setCustomName(String customName) { - // Prevents changes to custom name - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Prevents changes to custom name visibility - } - - @Override - public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) { - // Prevent armor stand from being equipped - return EnumInteractionResult.PASS; - } - - @Override - public boolean c(int i, ItemStack item) { - // Prevent armor stand from being equipped - return false; - } - - @Override - public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { - // Prevent armor stand from being equipped - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Prevent changes to bounding box - } - - public void forceSetBoundingBox(AxisAlignedBB boundingBox) { - super.a(boundingBox); - } - - @Override - public void a(SoundEffect soundeffect, float f, float f1) { - // Remove sounds - } - - @Override - public void setCustomNameNMS(String customName) { - if (Objects.equals(this.customName, customName)) { - return; - } - this.customName = customName; - super.setCustomName(createCustomNameNMSObject(customName)); - super.setCustomNameVisible(customName != null && !customName.isEmpty()); - } - - protected static String createCustomNameNMSObject(String customName) { - return customName != null ? Strings.truncate(customName, 256) : ""; - } - - @Override - public String getCustomNameStringNMS() { - return this.customName; - } - - @Override - public String getCustomNameObjectNMS() { - return super.getCustomName(); - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSArmorStand(super.world.getServer(), this); - } - return super.bukkitEntity; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - if (protocolPacketSettings.sendAccurateLocationPackets()) { - helper.broadcastPacket(new PacketPlayOutEntityTeleport(this)); - } - } - - @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(passengerEntity); - } catch (ReflectiveOperationException e) { - DebugLogger.cannotSetPassenger(e); - } - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - -} diff --git a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityNMSItem.java b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityNMSItem.java deleted file mode 100644 index eec7fc05..00000000 --- a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityNMSItem.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_11_R1; - -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; -import me.filoghost.holographicdisplays.common.nms.NMSCommons; -import me.filoghost.holographicdisplays.common.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.EntityHuman; -import net.minecraft.server.v1_11_R1.EntityItem; -import net.minecraft.server.v1_11_R1.EntityPlayer; -import net.minecraft.server.v1_11_R1.ItemStack; -import net.minecraft.server.v1_11_R1.NBTTagCompound; -import net.minecraft.server.v1_11_R1.NBTTagList; -import net.minecraft.server.v1_11_R1.NBTTagString; -import net.minecraft.server.v1_11_R1.World; -import org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack; -import org.bukkit.entity.Player; - -public class EntityNMSItem extends EntityItem implements NMSItem { - - private final StandardItemLine parentHologramLine; - private final VersionNMSEntityHelper helper; - - public EntityNMSItem(World world, StandardItemLine parentHologramLine) { - super(world); - this.parentHologramLine = parentHologramLine; - this.helper = new VersionNMSEntityHelper(this); - - super.pickupDelay = 32767; // Lock the item pickup delay, also prevents entities from picking up the item - } - - @Override - public void A_() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - // Method called when a player is near - @Override - public void d(EntityHuman human) { - if (human.locY < super.locY - 1.5 || human.locY > super.locY + 1.0) { - // Too low or too high, it's a bit weird - return; - } - - if (human instanceof EntityPlayer) { - parentHologramLine.onPickup(((EntityPlayer) human).getBukkitEntity()); - // It is never added to the inventory - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound e(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void f(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void a(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public boolean isAlive() { - // This override prevents items from being picked up by hoppers (should have no side effects) - return false; - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSItem(super.world.getServer(), this); - } - return super.bukkitEntity; - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - } - - @Override - public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) { - ItemStack newItem = CraftItemStack.asNMSCopy(stack); - - if (newItem == null || newItem == ItemStack.a) { // ItemStack.a is returned if the stack is not valid - newItem = new ItemStack(Blocks.BEDROCK); - } - - if (newItem.getTag() == null) { - newItem.setTag(new NBTTagCompound()); - } - NBTTagCompound display = newItem.getTag().getCompound("display"); // Returns a new NBTTagCompound if not existing - if (!newItem.getTag().hasKey("display")) { - newItem.getTag().set("display", display); - } - - NBTTagList tagList = new NBTTagList(); - tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE)); - display.set("Lore", tagList); - - super.setItemStack(newItem); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - - @Override - public Object getRawItemStack() { - return super.getItemStack(); - } - -} diff --git a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityNMSSlime.java b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityNMSSlime.java deleted file mode 100644 index d3a6a7f9..00000000 --- a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityNMSSlime.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_11_R1; - -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.nms.entity.NMSSlime; -import net.minecraft.server.v1_11_R1.AxisAlignedBB; -import net.minecraft.server.v1_11_R1.DamageSource; -import net.minecraft.server.v1_11_R1.EntityDamageSource; -import net.minecraft.server.v1_11_R1.EntityPlayer; -import net.minecraft.server.v1_11_R1.EntitySlime; -import net.minecraft.server.v1_11_R1.NBTTagCompound; -import net.minecraft.server.v1_11_R1.SoundEffect; -import net.minecraft.server.v1_11_R1.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.player.PlayerInteractEntityEvent; - -public class EntityNMSSlime extends EntitySlime implements NMSSlime { - - private final StandardHologramLine parentHologramLine; - private final VersionNMSEntityHelper helper; - - public EntityNMSSlime(World world, StandardHologramLine parentHologramLine) { - super(world); - this.parentHologramLine = parentHologramLine; - this.helper = new VersionNMSEntityHelper(this); - - super.persistent = true; - super.collides = false; - super.a(0.0F, 0.0F); - super.setSize(1, false); - super.setInvisible(true); - forceSetBoundingBox(new NullBoundingBox()); - } - - @Override - public void A_() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Prevent changes to bounding box - } - - public void forceSetBoundingBox(AxisAlignedBB boundingBox) { - super.a(boundingBox); - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound e(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void f(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void a(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean damageEntity(DamageSource damageSource, float amount) { - if (damageSource instanceof EntityDamageSource) { - EntityDamageSource entityDamageSource = (EntityDamageSource) damageSource; - if (entityDamageSource.getEntity() instanceof EntityPlayer) { - Player player = ((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(); - PlayerInteractEntityEvent event = new PlayerInteractEntityEvent(player, getBukkitEntity()); - Bukkit.getPluginManager().callEvent(event); // Bukkit takes care of the exceptions - } - } - return false; - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void setCustomName(String customName) { - // Prevents changes to custom name - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Prevents changes to custom name visibility - } - - @Override - public void a(SoundEffect soundeffect, float f, float f1) { - // Remove sounds - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSSlime(super.world.getServer(), this); - } - return super.bukkitEntity; - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - -} diff --git a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/NullBoundingBox.java b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/NullBoundingBox.java deleted file mode 100644 index 68cbfafb..00000000 --- a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/NullBoundingBox.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_11_R1; - -import net.minecraft.server.v1_11_R1.AxisAlignedBB; -import net.minecraft.server.v1_11_R1.BlockPosition; -import net.minecraft.server.v1_11_R1.MovingObjectPosition; -import net.minecraft.server.v1_11_R1.Vec3D; - -public class NullBoundingBox extends AxisAlignedBB { - - public NullBoundingBox() { - super(0, 0, 0, 0, 0, 0); - } - - @Override - public double a() { - return 0.0; - } - - @Override - public double a(AxisAlignedBB arg0, double arg1) { - return 0.0; - } - - @Override - public AxisAlignedBB a(AxisAlignedBB arg0) { - return this; - } - - @Override - public AxisAlignedBB a(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public MovingObjectPosition b(Vec3D arg0, Vec3D arg1) { - return null; - } - - @Override - public double b(AxisAlignedBB arg0, double arg1) { - return 0.0; - } - - @Override - public double c(AxisAlignedBB arg0, double arg1) { - return 0.0; - } - - @Override - public AxisAlignedBB grow(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public AxisAlignedBB shrink(double arg0) { - return this; - } - - @Override - public AxisAlignedBB a(BlockPosition arg0) { - return this; - } - - @Override - public boolean a(double arg0, double arg1, double arg2, double arg3, double arg4, double arg5) { - return false; - } - - @Override - public boolean b(Vec3D arg0) { - return false; - } - - @Override - public boolean c(Vec3D arg0) { - return false; - } - - @Override - public boolean d(Vec3D arg0) { - return false; - } - - @Override - public AxisAlignedBB e(double arg0) { - return this; - } - - @Override - public AxisAlignedBB g(double arg0) { - return this; - } - - @Override - public AxisAlignedBB a(Vec3D arg0) { - return this; - } - - @Override - public AxisAlignedBB b(AxisAlignedBB arg0) { - return this; - } - - @Override - public AxisAlignedBB b(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public boolean c(AxisAlignedBB arg0) { - return false; - } - - @Override - public AxisAlignedBB d(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public boolean e(Vec3D arg0) { - return false; - } - -} diff --git a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionNMSEntityHelper.java b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionNMSEntityHelper.java deleted file mode 100644 index 0bd3636d..00000000 --- a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionNMSEntityHelper.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_11_R1; - -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntityHelper; -import net.minecraft.server.v1_11_R1.Entity; -import net.minecraft.server.v1_11_R1.EntityTrackerEntry; -import net.minecraft.server.v1_11_R1.Packet; -import net.minecraft.server.v1_11_R1.WorldServer; -import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; - -public class VersionNMSEntityHelper extends NMSEntityHelper { - - private final Entity entity; - - public VersionNMSEntityHelper(Entity entity) { - this.entity = entity; - } - - @Override - protected EntityTrackerEntry getTracker0() { - return ((WorldServer) entity.world).tracker.trackedEntities.get(entity.getId()); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - EntityTrackerEntry tracker = getTracker(); - if (tracker != null) { - return tracker.trackedPlayers.contains(((CraftPlayer) bukkitPlayer).getHandle()); - } else { - return false; - } - } - - public void broadcastPacket(Packet packet) { - EntityTrackerEntry tracker = getTracker(); - if (tracker != null) { - tracker.broadcast(packet); - } - } - -} diff --git a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionNMSManager.java b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionNMSManager.java index 65a797c9..e7454fac 100644 --- a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionNMSManager.java +++ b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionNMSManager.java @@ -5,154 +5,20 @@ */ package me.filoghost.holographicdisplays.nms.v1_11_R1; -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.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; +import me.filoghost.holographicdisplays.common.nms.EntityID; import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; -import me.filoghost.holographicdisplays.common.nms.SpawnFailedException; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntity; -import me.filoghost.holographicdisplays.common.nms.entity.NMSItem; -import net.minecraft.server.v1_11_R1.Entity; -import net.minecraft.server.v1_11_R1.EntityTypes; -import net.minecraft.server.v1_11_R1.MathHelper; -import net.minecraft.server.v1_11_R1.RegistryID; -import net.minecraft.server.v1_11_R1.RegistryMaterials; -import net.minecraft.server.v1_11_R1.World; -import net.minecraft.server.v1_11_R1.WorldServer; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_11_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity; -import org.bukkit.inventory.ItemStack; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; public class VersionNMSManager implements NMSManager { - private static final ReflectField>> REGISTRY_ID_FIELD - = ReflectField.lookup(new ClassToken>>() {}, RegistryMaterials.class, "a"); - private static final ReflectField ID_TO_CLASS_MAP_FIELD - = ReflectField.lookup(Object[].class, RegistryID.class, "d"); - - private static final ReflectMethod REGISTER_ENTITY_METHOD = ReflectMethod.lookup(Object.class, World.class, "b", Entity.class); - - private final ProtocolPacketSettings protocolPacketSettings; - - public VersionNMSManager(ProtocolPacketSettings protocolPacketSettings) { - this.protocolPacketSettings = protocolPacketSettings; + @Override + public EntityID newEntityID() { + return null; } @Override - public void setup() throws Exception { - registerCustomEntity(EntityNMSSlime.class, 55); - } - - public void registerCustomEntity(Class entityClass, int id) throws Exception { - // Use reflection to get the RegistryID of entities - RegistryID> registryID = REGISTRY_ID_FIELD.get(EntityTypes.b); - Object[] idToClassMap = ID_TO_CLASS_MAP_FIELD.get(registryID); - - // Save the the ID -> entity class mapping before the registration - Object oldValue = idToClassMap[id]; - - // Register the entity class - registryID.a(entityClass, id); - - // Restore the ID -> entity class mapping - idToClassMap[id] = oldValue; - } - - @Override - public NMSItem spawnNMSItem( - org.bukkit.World bukkitWorld, double x, double y, double z, - StandardItemLine parentHologramLine, - ItemStack stack) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSItem item = new EntityNMSItem(nmsWorld, parentHologramLine); - 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 parentHologramLine) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSSlime slime = new EntityNMSSlime(nmsWorld, parentHologramLine); - 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 parentHologramLine) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) world).getHandle(); - EntityNMSArmorStand armorStand = new EntityNMSArmorStand(nmsWorld, parentHologramLine, protocolPacketSettings); - armorStand.setLocationNMS(x, y, z); - addEntityToWorld(nmsWorld, armorStand); - return armorStand; - } - - 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); - final int chunkZ = MathHelper.floor(nmsEntity.locZ / 16.0); - - if (!nmsWorld.getChunkProviderServer().isLoaded(chunkX, chunkZ)) { - // This should never happen - nmsEntity.dead = true; - throw new SpawnFailedException(SpawnFailedException.CHUNK_NOT_LOADED); - } - - nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity); - nmsWorld.entityList.add(nmsEntity); - - try { - REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity); - } catch (ReflectiveOperationException e) { - 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 NMSEntity; - } - - @Override - public NMSEntity getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - - if (nmsEntity instanceof NMSEntity) { - return (NMSEntity) nmsEntity; - } else { - return null; - } - } - - @Override - public NMSEntity getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - Entity nmsEntity = nmsWorld.getEntity(entityID); - - if (nmsEntity instanceof NMSEntity) { - return (NMSEntity) nmsEntity; - } else { - return null; - } - } - - @Override - public Object createCustomNameNMSObject(String customName) { - return EntityNMSArmorStand.createCustomNameNMSObject(customName); + public NMSPacketList createPacketList() { + return null; } } diff --git a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/CraftNMSArmorStand.java b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/CraftNMSArmorStand.java deleted file mode 100644 index 23ae80e5..00000000 --- a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/CraftNMSArmorStand.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_12_R1; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_12_R1.CraftServer; -import org.bukkit.craftbukkit.v1_12_R1.entity.CraftArmorStand; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.ItemStack; -import org.bukkit.potion.PotionEffect; -import org.bukkit.util.EulerAngle; -import org.bukkit.util.Vector; - -import java.util.Collection; - -public class CraftNMSArmorStand extends CraftArmorStand { - - public CraftNMSArmorStand(CraftServer server, EntityNMSArmorStand entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // 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) {} - - // 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 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 setGliding(boolean gliding) {} - @Override public boolean setLeashHolder(Entity holder) { return false; } - - // Methods from Entity - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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) {} - -} diff --git a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/CraftNMSItem.java b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/CraftNMSItem.java deleted file mode 100644 index b58aba5e..00000000 --- a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/CraftNMSItem.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_12_R1; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_12_R1.CraftServer; -import org.bukkit.craftbukkit.v1_12_R1.entity.CraftItem; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; - -public class CraftNMSItem extends CraftItem { - - public CraftNMSItem(CraftServer server, EntityNMSItem entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // Methods from Entity - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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) {} - -} diff --git a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/CraftNMSSlime.java b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/CraftNMSSlime.java deleted file mode 100644 index f83dc414..00000000 --- a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/CraftNMSSlime.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_12_R1; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_12_R1.CraftServer; -import org.bukkit.craftbukkit.v1_12_R1.entity.CraftSlime; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.potion.PotionEffect; -import org.bukkit.util.Vector; - -import java.util.Collection; - -public class CraftNMSSlime extends CraftSlime { - - public CraftNMSSlime(CraftServer server, EntityNMSSlime entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // 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 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 setGliding(boolean gliding) {} - @Override public boolean setLeashHolder(Entity holder) { return false; } - - // Methods from Entity - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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) {} - -} diff --git a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityNMSArmorStand.java b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityNMSArmorStand.java deleted file mode 100644 index 46975f35..00000000 --- a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityNMSArmorStand.java +++ /dev/null @@ -1,260 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_12_R1; - -import me.filoghost.fcommons.Preconditions; -import me.filoghost.fcommons.Strings; -import me.filoghost.fcommons.reflection.ReflectField; -import me.filoghost.holographicdisplays.common.DebugLogger; -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.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.EnumHand; -import net.minecraft.server.v1_12_R1.EnumInteractionResult; -import net.minecraft.server.v1_12_R1.EnumItemSlot; -import net.minecraft.server.v1_12_R1.ItemStack; -import net.minecraft.server.v1_12_R1.NBTTagCompound; -import net.minecraft.server.v1_12_R1.PacketPlayOutEntityTeleport; -import net.minecraft.server.v1_12_R1.SoundEffect; -import net.minecraft.server.v1_12_R1.Vec3D; -import net.minecraft.server.v1_12_R1.World; -import org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity; -import org.bukkit.entity.Player; - -import java.util.Objects; - -public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand { - - private static final ReflectField VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "au"); - - private final StandardHologramLine parentHologramLine; - private final ProtocolPacketSettings protocolPacketSettings; - private final VersionNMSEntityHelper helper; - private String customName; - - public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, ProtocolPacketSettings protocolPacketSettings) { - super(world); - this.parentHologramLine = parentHologramLine; - this.protocolPacketSettings = protocolPacketSettings; - this.helper = new VersionNMSEntityHelper(this); - - super.setInvisible(true); - super.setSmall(true); - super.setArms(false); - super.setNoGravity(true); - super.setBasePlate(true); - super.setMarker(true); - super.collides = false; - super.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet - forceSetBoundingBox(new NullBoundingBox()); - } - - @Override - public void B_() { - // Disable normal ticking for this entity - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity - if (super.onGround) { - super.onGround = false; - } - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity - if (super.onGround) { - super.onGround = false; - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound save(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void f(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void a(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void setCustomName(String customName) { - // Prevents changes to custom name - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Prevents changes to custom name visibility - } - - @Override - public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) { - // Prevent armor stand from being equipped - return EnumInteractionResult.PASS; - } - - @Override - public boolean c(int i, ItemStack item) { - // Prevent armor stand from being equipped - return false; - } - - @Override - public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { - // Prevent armor stand from being equipped - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Prevent changes to bounding box - } - - public void forceSetBoundingBox(AxisAlignedBB boundingBox) { - super.a(boundingBox); - } - - @Override - public void a(SoundEffect soundeffect, float f, float f1) { - // Remove sounds - } - - @Override - public void setCustomNameNMS(String customName) { - if (Objects.equals(this.customName, customName)) { - return; - } - this.customName = customName; - super.setCustomName(createCustomNameNMSObject(customName)); - super.setCustomNameVisible(customName != null && !customName.isEmpty()); - } - - protected static String createCustomNameNMSObject(String customName) { - return customName != null ? Strings.truncate(customName, 256) : ""; - } - - @Override - public String getCustomNameStringNMS() { - return this.customName; - } - - @Override - public String getCustomNameObjectNMS() { - return super.getCustomName(); - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSArmorStand(super.world.getServer(), this); - } - return super.bukkitEntity; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - if (protocolPacketSettings.sendAccurateLocationPackets()) { - helper.broadcastPacket(new PacketPlayOutEntityTeleport(this)); - } - } - - @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(passengerEntity); - } catch (ReflectiveOperationException e) { - DebugLogger.cannotSetPassenger(e); - } - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - -} diff --git a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityNMSItem.java b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityNMSItem.java deleted file mode 100644 index bff2348a..00000000 --- a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityNMSItem.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_12_R1; - -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; -import me.filoghost.holographicdisplays.common.nms.NMSCommons; -import me.filoghost.holographicdisplays.common.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.EntityHuman; -import net.minecraft.server.v1_12_R1.EntityItem; -import net.minecraft.server.v1_12_R1.EntityPlayer; -import net.minecraft.server.v1_12_R1.ItemStack; -import net.minecraft.server.v1_12_R1.NBTTagCompound; -import net.minecraft.server.v1_12_R1.NBTTagList; -import net.minecraft.server.v1_12_R1.NBTTagString; -import net.minecraft.server.v1_12_R1.World; -import org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack; -import org.bukkit.entity.Player; - -public class EntityNMSItem extends EntityItem implements NMSItem { - - private final StandardItemLine parentHologramLine; - private final VersionNMSEntityHelper helper; - - public EntityNMSItem(World world, StandardItemLine parentHologramLine) { - super(world); - this.parentHologramLine = parentHologramLine; - this.helper = new VersionNMSEntityHelper(this); - - super.pickupDelay = 32767; // Lock the item pickup delay, also prevents entities from picking up the item - } - - @Override - public void B_() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - // Method called when a player is near - @Override - public void d(EntityHuman human) { - if (human.locY < super.locY - 1.5 || human.locY > super.locY + 1.0) { - // Too low or too high, it's a bit weird - return; - } - - if (human instanceof EntityPlayer) { - parentHologramLine.onPickup(((EntityPlayer) human).getBukkitEntity()); - // It is never added to the inventory - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound save(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void f(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void a(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public boolean isAlive() { - // This override prevents items from being picked up by hoppers (should have no side effects) - return false; - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSItem(super.world.getServer(), this); - } - return super.bukkitEntity; - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - } - - @Override - public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) { - ItemStack newItem = CraftItemStack.asNMSCopy(stack); - - if (newItem == null || newItem == ItemStack.a) { // ItemStack.a is returned if the stack is not valid - newItem = new ItemStack(Blocks.BEDROCK); - } - - if (newItem.getTag() == null) { - newItem.setTag(new NBTTagCompound()); - } - NBTTagCompound display = newItem.getTag().getCompound("display"); // Returns a new NBTTagCompound if not existing - if (!newItem.getTag().hasKey("display")) { - newItem.getTag().set("display", display); - } - - NBTTagList tagList = new NBTTagList(); - tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE)); - display.set("Lore", tagList); - - super.setItemStack(newItem); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - - @Override - public Object getRawItemStack() { - return super.getItemStack(); - } - -} diff --git a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityNMSSlime.java b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityNMSSlime.java deleted file mode 100644 index f3ded9f4..00000000 --- a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityNMSSlime.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_12_R1; - -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.nms.entity.NMSSlime; -import net.minecraft.server.v1_12_R1.AxisAlignedBB; -import net.minecraft.server.v1_12_R1.DamageSource; -import net.minecraft.server.v1_12_R1.EntityDamageSource; -import net.minecraft.server.v1_12_R1.EntityPlayer; -import net.minecraft.server.v1_12_R1.EntitySlime; -import net.minecraft.server.v1_12_R1.NBTTagCompound; -import net.minecraft.server.v1_12_R1.SoundEffect; -import net.minecraft.server.v1_12_R1.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.player.PlayerInteractEntityEvent; - -public class EntityNMSSlime extends EntitySlime implements NMSSlime { - - private final StandardHologramLine parentHologramLine; - private final VersionNMSEntityHelper helper; - - public EntityNMSSlime(World world, StandardHologramLine parentHologramLine) { - super(world); - this.parentHologramLine = parentHologramLine; - this.helper = new VersionNMSEntityHelper(this); - - super.persistent = true; - super.collides = false; - super.a(0.0F, 0.0F); - super.setSize(1, false); - super.setInvisible(true); - forceSetBoundingBox(new NullBoundingBox()); - } - - @Override - public void B_() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Prevent changes to bounding box - } - - public void forceSetBoundingBox(AxisAlignedBB boundingBox) { - super.a(boundingBox); - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound save(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void f(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void a(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean damageEntity(DamageSource damageSource, float amount) { - if (damageSource instanceof EntityDamageSource) { - EntityDamageSource entityDamageSource = (EntityDamageSource) damageSource; - if (entityDamageSource.getEntity() instanceof EntityPlayer) { - Player player = ((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(); - PlayerInteractEntityEvent event = new PlayerInteractEntityEvent(player, getBukkitEntity()); - Bukkit.getPluginManager().callEvent(event); // Bukkit takes care of the exceptions - } - } - return false; - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void setCustomName(String customName) { - // Prevents changes to custom name - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Prevents changes to custom name visibility - } - - @Override - public void a(SoundEffect soundeffect, float f, float f1) { - // Remove sounds - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSSlime(super.world.getServer(), this); - } - return super.bukkitEntity; - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - -} diff --git a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/NullBoundingBox.java b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/NullBoundingBox.java deleted file mode 100644 index 832c0788..00000000 --- a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/NullBoundingBox.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_12_R1; - -import net.minecraft.server.v1_12_R1.AxisAlignedBB; -import net.minecraft.server.v1_12_R1.BlockPosition; -import net.minecraft.server.v1_12_R1.MovingObjectPosition; -import net.minecraft.server.v1_12_R1.Vec3D; - -public class NullBoundingBox extends AxisAlignedBB { - - public NullBoundingBox() { - super(0, 0, 0, 0, 0, 0); - } - - @Override - public double a() { - return 0.0; - } - - @Override - public double a(AxisAlignedBB arg0, double arg1) { - return 0.0; - } - - @Override - public AxisAlignedBB a(AxisAlignedBB arg0) { - return this; - } - - @Override - public AxisAlignedBB a(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public MovingObjectPosition b(Vec3D arg0, Vec3D arg1) { - return null; - } - - @Override - public double b(AxisAlignedBB arg0, double arg1) { - return 0.0; - } - - @Override - public double c(AxisAlignedBB arg0, double arg1) { - return 0.0; - } - - @Override - public AxisAlignedBB grow(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public AxisAlignedBB shrink(double arg0) { - return this; - } - - @Override - public AxisAlignedBB a(BlockPosition arg0) { - return this; - } - - @Override - public boolean a(double arg0, double arg1, double arg2, double arg3, double arg4, double arg5) { - return false; - } - - @Override - public boolean b(Vec3D arg0) { - return false; - } - - @Override - public boolean c(Vec3D arg0) { - return false; - } - - @Override - public boolean d(Vec3D arg0) { - return false; - } - - @Override - public AxisAlignedBB e(double arg0) { - return this; - } - - @Override - public AxisAlignedBB g(double arg0) { - return this; - } - - @Override - public AxisAlignedBB a(Vec3D arg0) { - return this; - } - - @Override - public AxisAlignedBB b(AxisAlignedBB arg0) { - return this; - } - - @Override - public AxisAlignedBB b(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public boolean c(AxisAlignedBB arg0) { - return false; - } - - @Override - public AxisAlignedBB d(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public boolean e(Vec3D arg0) { - return false; - } - -} diff --git a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionNMSEntityHelper.java b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionNMSEntityHelper.java deleted file mode 100644 index ca8a19b3..00000000 --- a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionNMSEntityHelper.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_12_R1; - -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntityHelper; -import net.minecraft.server.v1_12_R1.Entity; -import net.minecraft.server.v1_12_R1.EntityTrackerEntry; -import net.minecraft.server.v1_12_R1.Packet; -import net.minecraft.server.v1_12_R1.WorldServer; -import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; - -public class VersionNMSEntityHelper extends NMSEntityHelper { - - private final Entity entity; - - public VersionNMSEntityHelper(Entity entity) { - this.entity = entity; - } - - @Override - protected EntityTrackerEntry getTracker0() { - return ((WorldServer) entity.world).tracker.trackedEntities.get(entity.getId()); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - EntityTrackerEntry tracker = getTracker(); - if (tracker != null) { - return tracker.trackedPlayers.contains(((CraftPlayer) bukkitPlayer).getHandle()); - } else { - return false; - } - } - - public void broadcastPacket(Packet packet) { - EntityTrackerEntry tracker = getTracker(); - if (tracker != null) { - tracker.broadcast(packet); - } - } - -} diff --git a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionNMSManager.java b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionNMSManager.java index 91e93864..2f0a5fdd 100644 --- a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionNMSManager.java +++ b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionNMSManager.java @@ -5,154 +5,20 @@ */ package me.filoghost.holographicdisplays.nms.v1_12_R1; -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.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; +import me.filoghost.holographicdisplays.common.nms.EntityID; import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; -import me.filoghost.holographicdisplays.common.nms.SpawnFailedException; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntity; -import me.filoghost.holographicdisplays.common.nms.entity.NMSItem; -import net.minecraft.server.v1_12_R1.Entity; -import net.minecraft.server.v1_12_R1.EntityTypes; -import net.minecraft.server.v1_12_R1.MathHelper; -import net.minecraft.server.v1_12_R1.RegistryID; -import net.minecraft.server.v1_12_R1.RegistryMaterials; -import net.minecraft.server.v1_12_R1.World; -import net.minecraft.server.v1_12_R1.WorldServer; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity; -import org.bukkit.inventory.ItemStack; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; public class VersionNMSManager implements NMSManager { - private static final ReflectField>> REGISTRY_ID_FIELD - = ReflectField.lookup(new ClassToken>>() {}, RegistryMaterials.class, "a"); - private static final ReflectField ID_TO_CLASS_MAP_FIELD - = ReflectField.lookup(Object[].class, RegistryID.class, "d"); - - private static final ReflectMethod REGISTER_ENTITY_METHOD = ReflectMethod.lookup(Object.class, World.class, "b", Entity.class); - - private final ProtocolPacketSettings protocolPacketSettings; - - public VersionNMSManager(ProtocolPacketSettings protocolPacketSettings) { - this.protocolPacketSettings = protocolPacketSettings; + @Override + public EntityID newEntityID() { + return null; } @Override - public void setup() throws Exception { - registerCustomEntity(EntityNMSSlime.class, 55); - } - - public void registerCustomEntity(Class entityClass, int id) throws Exception { - // Use reflection to get the RegistryID of entities - RegistryID> registryID = REGISTRY_ID_FIELD.get(EntityTypes.b); - Object[] idToClassMap = ID_TO_CLASS_MAP_FIELD.get(registryID); - - // Save the the ID -> entity class mapping before the registration - Object oldValue = idToClassMap[id]; - - // Register the entity class - registryID.a(entityClass, id); - - // Restore the ID -> entity class mapping - idToClassMap[id] = oldValue; - } - - @Override - public NMSItem spawnNMSItem( - org.bukkit.World bukkitWorld, double x, double y, double z, - StandardItemLine parentHologramLine, - ItemStack stack) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSItem item = new EntityNMSItem(nmsWorld, parentHologramLine); - 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 parentHologramLine) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSSlime slime = new EntityNMSSlime(nmsWorld, parentHologramLine); - 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 parentHologramLine) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) world).getHandle(); - EntityNMSArmorStand armorStand = new EntityNMSArmorStand(nmsWorld, parentHologramLine, protocolPacketSettings); - armorStand.setLocationNMS(x, y, z); - addEntityToWorld(nmsWorld, armorStand); - return armorStand; - } - - 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); - final int chunkZ = MathHelper.floor(nmsEntity.locZ / 16.0); - - if (!nmsWorld.getChunkProviderServer().isLoaded(chunkX, chunkZ)) { - // This should never happen - nmsEntity.dead = true; - throw new SpawnFailedException(SpawnFailedException.CHUNK_NOT_LOADED); - } - - nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity); - nmsWorld.entityList.add(nmsEntity); - - try { - REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity); - } catch (ReflectiveOperationException e) { - 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 NMSEntity; - } - - @Override - public NMSEntity getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - - if (nmsEntity instanceof NMSEntity) { - return (NMSEntity) nmsEntity; - } else { - return null; - } - } - - @Override - public NMSEntity getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - Entity nmsEntity = nmsWorld.getEntity(entityID); - - if (nmsEntity instanceof NMSEntity) { - return (NMSEntity) nmsEntity; - } else { - return null; - } - } - - @Override - public Object createCustomNameNMSObject(String customName) { - return EntityNMSArmorStand.createCustomNameNMSObject(customName); + public NMSPacketList createPacketList() { + return null; } } diff --git a/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/CraftNMSArmorStand.java b/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/CraftNMSArmorStand.java deleted file mode 100644 index 04f863f0..00000000 --- a/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/CraftNMSArmorStand.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_13_R1; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_13_R1.CraftServer; -import org.bukkit.craftbukkit.v1_13_R1.entity.CraftArmorStand; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.ItemStack; -import org.bukkit.potion.PotionEffect; -import org.bukkit.util.EulerAngle; -import org.bukkit.util.Vector; - -import java.util.Collection; - -public class CraftNMSArmorStand extends CraftArmorStand { - - public CraftNMSArmorStand(CraftServer server, EntityNMSArmorStand entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // 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) {} - - // 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 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 setGliding(boolean gliding) {} - @Override public boolean setLeashHolder(Entity holder) { return false; } - @Override public void setSwimming(boolean swimming) {} - - // Methods from Entity - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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) {} - - -} diff --git a/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/CraftNMSItem.java b/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/CraftNMSItem.java deleted file mode 100644 index 7c33e811..00000000 --- a/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/CraftNMSItem.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_13_R1; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_13_R1.CraftServer; -import org.bukkit.craftbukkit.v1_13_R1.entity.CraftItem; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; - -public class CraftNMSItem extends CraftItem { - - public CraftNMSItem(CraftServer server, EntityNMSItem entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // Methods from Entity - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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) {} - -} diff --git a/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/CraftNMSSlime.java b/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/CraftNMSSlime.java deleted file mode 100644 index 74ed2663..00000000 --- a/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/CraftNMSSlime.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_13_R1; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_13_R1.CraftServer; -import org.bukkit.craftbukkit.v1_13_R1.entity.CraftSlime; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.potion.PotionEffect; -import org.bukkit.util.Vector; - -import java.util.Collection; - -public class CraftNMSSlime extends CraftSlime { - - public CraftNMSSlime(CraftServer server, EntityNMSSlime entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // 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 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 setGliding(boolean gliding) {} - @Override public boolean setLeashHolder(Entity holder) { return false; } - @Override public void setSwimming(boolean swimming) {} - - // Methods from Entity - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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) {} - -} diff --git a/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/EntityNMSArmorStand.java b/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/EntityNMSArmorStand.java deleted file mode 100644 index b367218b..00000000 --- a/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/EntityNMSArmorStand.java +++ /dev/null @@ -1,262 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_13_R1; - -import me.filoghost.fcommons.Preconditions; -import me.filoghost.fcommons.Strings; -import me.filoghost.fcommons.reflection.ReflectField; -import me.filoghost.holographicdisplays.common.DebugLogger; -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.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.EnumHand; -import net.minecraft.server.v1_13_R1.EnumInteractionResult; -import net.minecraft.server.v1_13_R1.EnumItemSlot; -import net.minecraft.server.v1_13_R1.IChatBaseComponent; -import net.minecraft.server.v1_13_R1.ItemStack; -import net.minecraft.server.v1_13_R1.NBTTagCompound; -import net.minecraft.server.v1_13_R1.PacketPlayOutEntityTeleport; -import net.minecraft.server.v1_13_R1.SoundEffect; -import net.minecraft.server.v1_13_R1.Vec3D; -import net.minecraft.server.v1_13_R1.World; -import org.bukkit.craftbukkit.v1_13_R1.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_13_R1.util.CraftChatMessage; -import org.bukkit.entity.Player; - -import java.util.Objects; - -public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand { - - private static final ReflectField VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "ax"); - - private final StandardHologramLine parentHologramLine; - private final ProtocolPacketSettings protocolPacketSettings; - private final VersionNMSEntityHelper helper; - private String customName; - - public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, ProtocolPacketSettings protocolPacketSettings) { - super(world); - this.parentHologramLine = parentHologramLine; - this.protocolPacketSettings = protocolPacketSettings; - this.helper = new VersionNMSEntityHelper(this); - - super.setInvisible(true); - super.setSmall(true); - super.setArms(false); - super.setNoGravity(true); - super.setBasePlate(true); - super.setMarker(true); - super.collides = false; - super.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet - forceSetBoundingBox(new NullBoundingBox()); - } - - @Override - public void tick() { - // Disable normal ticking for this entity - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity - if (super.onGround) { - super.onGround = false; - } - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity - if (super.onGround) { - super.onGround = false; - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound save(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void f(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void a(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void setCustomName(IChatBaseComponent ichatbasecomponent) { - // Prevents changes to custom name - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Prevents changes to custom name visibility - } - - @Override - public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) { - // Prevent armor stand from being equipped - return EnumInteractionResult.PASS; - } - - @Override - public boolean c(int i, ItemStack item) { - // Prevent armor stand from being equipped - return false; - } - - @Override - public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { - // Prevent armor stand from being equipped - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Prevent changes to bounding box - } - - public void forceSetBoundingBox(AxisAlignedBB boundingBox) { - super.a(boundingBox); - } - - @Override - public void a(SoundEffect soundeffect, float f, float f1) { - // Remove sounds - } - - @Override - public void setCustomNameNMS(String customName) { - if (Objects.equals(this.customName, customName)) { - return; - } - this.customName = customName; - super.setCustomName(createCustomNameNMSObject(customName)); - super.setCustomNameVisible(customName != null && !customName.isEmpty()); - } - - protected static IChatBaseComponent createCustomNameNMSObject(String customName) { - return CraftChatMessage.fromStringOrNull(Strings.truncate(customName, 300)); - } - - @Override - public String getCustomNameStringNMS() { - return this.customName; - } - - @Override - public IChatBaseComponent getCustomNameObjectNMS() { - return super.getCustomName(); - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSArmorStand(super.world.getServer(), this); - } - return super.bukkitEntity; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - if (protocolPacketSettings.sendAccurateLocationPackets()) { - helper.broadcastPacket(new PacketPlayOutEntityTeleport(this)); - } - } - - @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(passengerEntity); - } catch (ReflectiveOperationException e) { - DebugLogger.cannotSetPassenger(e); - } - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - -} diff --git a/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/EntityNMSItem.java b/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/EntityNMSItem.java deleted file mode 100644 index 8c0b149c..00000000 --- a/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/EntityNMSItem.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_13_R1; - -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; -import me.filoghost.holographicdisplays.common.nms.NMSCommons; -import me.filoghost.holographicdisplays.common.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.EntityHuman; -import net.minecraft.server.v1_13_R1.EntityItem; -import net.minecraft.server.v1_13_R1.EntityPlayer; -import net.minecraft.server.v1_13_R1.ItemStack; -import net.minecraft.server.v1_13_R1.NBTTagCompound; -import net.minecraft.server.v1_13_R1.NBTTagList; -import net.minecraft.server.v1_13_R1.NBTTagString; -import net.minecraft.server.v1_13_R1.World; -import org.bukkit.craftbukkit.v1_13_R1.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_13_R1.inventory.CraftItemStack; -import org.bukkit.entity.Player; - -public class EntityNMSItem extends EntityItem implements NMSItem { - - private final StandardItemLine parentHologramLine; - private final VersionNMSEntityHelper helper; - - public EntityNMSItem(World world, StandardItemLine parentHologramLine) { - super(world); - this.parentHologramLine = parentHologramLine; - this.helper = new VersionNMSEntityHelper(this); - - super.pickupDelay = 32767; // Lock the item pickup delay, also prevents entities from picking up the item - } - - @Override - public void tick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - // Method called when a player is near - @Override - public void d(EntityHuman human) { - if (human.locY < super.locY - 1.5 || human.locY > super.locY + 1.0) { - // Too low or too high, it's a bit weird - return; - } - - if (human instanceof EntityPlayer) { - parentHologramLine.onPickup(((EntityPlayer) human).getBukkitEntity()); - // It is never added to the inventory - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound save(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void f(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void a(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public boolean isAlive() { - // This override prevents items from being picked up by hoppers (should have no side effects) - return false; - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSItem(super.world.getServer(), this); - } - return super.bukkitEntity; - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - } - - @Override - public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) { - ItemStack newItem = CraftItemStack.asNMSCopy(stack); - - if (newItem == null || newItem == ItemStack.a) { // ItemStack.a is returned if the stack is not valid - newItem = new ItemStack(Blocks.BEDROCK); - } - - if (newItem.getTag() == null) { - newItem.setTag(new NBTTagCompound()); - } - NBTTagCompound display = newItem.getTag().getCompound("display"); // Returns a new NBTTagCompound if not existing - if (!newItem.getTag().hasKey("display")) { - newItem.getTag().set("display", display); - } - - NBTTagList tagList = new NBTTagList(); - tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE)); - display.set("Lore", tagList); - - super.setItemStack(newItem); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - - @Override - public Object getRawItemStack() { - return super.getItemStack(); - } - -} diff --git a/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/EntityNMSSlime.java b/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/EntityNMSSlime.java deleted file mode 100644 index d4fe6670..00000000 --- a/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/EntityNMSSlime.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_13_R1; - -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.nms.entity.NMSSlime; -import net.minecraft.server.v1_13_R1.AxisAlignedBB; -import net.minecraft.server.v1_13_R1.DamageSource; -import net.minecraft.server.v1_13_R1.EntityDamageSource; -import net.minecraft.server.v1_13_R1.EntityPlayer; -import net.minecraft.server.v1_13_R1.EntitySlime; -import net.minecraft.server.v1_13_R1.IChatBaseComponent; -import net.minecraft.server.v1_13_R1.NBTTagCompound; -import net.minecraft.server.v1_13_R1.SoundEffect; -import net.minecraft.server.v1_13_R1.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_13_R1.entity.CraftEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.player.PlayerInteractEntityEvent; - -public class EntityNMSSlime extends EntitySlime implements NMSSlime { - - private final StandardHologramLine parentHologramLine; - private final VersionNMSEntityHelper helper; - - public EntityNMSSlime(World world, StandardHologramLine parentHologramLine) { - super(world); - this.parentHologramLine = parentHologramLine; - this.helper = new VersionNMSEntityHelper(this); - - super.persistent = true; - super.collides = false; - super.a(0.0F, 0.0F); - super.setSize(1, false); - super.setInvisible(true); - forceSetBoundingBox(new NullBoundingBox()); - } - - @Override - public void tick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Prevent changes to bounding box - } - - public void forceSetBoundingBox(AxisAlignedBB boundingBox) { - super.a(boundingBox); - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound save(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void f(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void a(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean damageEntity(DamageSource damageSource, float amount) { - if (damageSource instanceof EntityDamageSource) { - EntityDamageSource entityDamageSource = (EntityDamageSource) damageSource; - if (entityDamageSource.getEntity() instanceof EntityPlayer) { - Player player = ((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(); - PlayerInteractEntityEvent event = new PlayerInteractEntityEvent(player, getBukkitEntity()); - Bukkit.getPluginManager().callEvent(event); // Bukkit takes care of the exceptions - } - } - return false; - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void setCustomName(IChatBaseComponent ichatbasecomponent) { - // Prevents changes to custom name - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Prevents changes to custom name visibility - } - - @Override - public void a(SoundEffect soundeffect, float f, float f1) { - // Remove sounds - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSSlime(super.world.getServer(), this); - } - return super.bukkitEntity; - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - -} diff --git a/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/NullBoundingBox.java b/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/NullBoundingBox.java deleted file mode 100644 index 8e14df58..00000000 --- a/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/NullBoundingBox.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_13_R1; - -import net.minecraft.server.v1_13_R1.AxisAlignedBB; -import net.minecraft.server.v1_13_R1.BlockPosition; -import net.minecraft.server.v1_13_R1.EnumDirection.EnumAxis; -import net.minecraft.server.v1_13_R1.MovingObjectPosition; -import net.minecraft.server.v1_13_R1.Vec3D; - -public class NullBoundingBox extends AxisAlignedBB { - - public NullBoundingBox() { - super(0, 0, 0, 0, 0, 0); - } - - @Override - public double a() { - return 0.0; - } - - @Override - public AxisAlignedBB a(AxisAlignedBB arg0) { - return this; - } - - @Override - public AxisAlignedBB a(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public MovingObjectPosition b(Vec3D arg0, Vec3D arg1) { - return null; - } - - @Override - public AxisAlignedBB grow(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public AxisAlignedBB shrink(double arg0) { - return this; - } - - @Override - public AxisAlignedBB a(BlockPosition arg0) { - return this; - } - - @Override - public boolean a(double arg0, double arg1, double arg2, double arg3, double arg4, double arg5) { - return false; - } - - @Override - public boolean b(Vec3D arg0) { - return false; - } - - @Override - public AxisAlignedBB g(double arg0) { - return this; - } - - @Override - public AxisAlignedBB a(Vec3D arg0) { - return this; - } - - @Override - public AxisAlignedBB b(AxisAlignedBB arg0) { - return this; - } - - @Override - public AxisAlignedBB b(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public boolean c(AxisAlignedBB arg0) { - return false; - } - - @Override - public AxisAlignedBB d(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public double a(EnumAxis arg0) { - return 0.0; - } - - @Override - public MovingObjectPosition a(Vec3D arg0, Vec3D arg1, BlockPosition arg2) { - return null; - } - - @Override - public double b(EnumAxis arg0) { - return 0.0; - } - - @Override - public boolean e(double arg0, double arg1, double arg2) { - return false; - } - - @Override - public AxisAlignedBB f(double arg0, double arg1, double arg2) { - return this; - } - -} diff --git a/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/VersionNMSEntityHelper.java b/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/VersionNMSEntityHelper.java deleted file mode 100644 index 5b8ba570..00000000 --- a/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/VersionNMSEntityHelper.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_13_R1; - -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntityHelper; -import net.minecraft.server.v1_13_R1.Entity; -import net.minecraft.server.v1_13_R1.EntityTrackerEntry; -import net.minecraft.server.v1_13_R1.Packet; -import net.minecraft.server.v1_13_R1.WorldServer; -import org.bukkit.craftbukkit.v1_13_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; - -public class VersionNMSEntityHelper extends NMSEntityHelper { - - private final Entity entity; - - public VersionNMSEntityHelper(Entity entity) { - this.entity = entity; - } - - @Override - protected EntityTrackerEntry getTracker0() { - return ((WorldServer) entity.world).tracker.trackedEntities.get(entity.getId()); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - EntityTrackerEntry tracker = getTracker(); - if (tracker != null) { - return tracker.trackedPlayers.contains(((CraftPlayer) bukkitPlayer).getHandle()); - } else { - return false; - } - } - - public void broadcastPacket(Packet packet) { - EntityTrackerEntry tracker = getTracker(); - if (tracker != null) { - tracker.broadcast(packet); - } - } - -} diff --git a/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/VersionNMSManager.java b/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/VersionNMSManager.java index 36875af2..e60bd4c9 100644 --- a/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/VersionNMSManager.java +++ b/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/VersionNMSManager.java @@ -5,170 +5,20 @@ */ package me.filoghost.holographicdisplays.nms.v1_13_R1; -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.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; -import me.filoghost.holographicdisplays.common.nms.NMSCommons; +import me.filoghost.holographicdisplays.common.nms.EntityID; import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; -import me.filoghost.holographicdisplays.common.nms.SpawnFailedException; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntity; -import me.filoghost.holographicdisplays.common.nms.entity.NMSItem; -import net.minecraft.server.v1_13_R1.Entity; -import net.minecraft.server.v1_13_R1.EntityTypes; -import net.minecraft.server.v1_13_R1.MathHelper; -import net.minecraft.server.v1_13_R1.RegistryID; -import net.minecraft.server.v1_13_R1.RegistryMaterials; -import net.minecraft.server.v1_13_R1.World; -import net.minecraft.server.v1_13_R1.WorldServer; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_13_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_13_R1.entity.CraftEntity; -import org.bukkit.inventory.ItemStack; - -import java.util.List; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; public class VersionNMSManager implements NMSManager { - private static final ReflectField>> REGISTRY_ID_FIELD - = ReflectField.lookup(new ClassToken>>() {}, RegistryMaterials.class, "a"); - private static final ReflectField ID_TO_CLASS_MAP_FIELD - = ReflectField.lookup(Object[].class, RegistryID.class, "d"); - private static final ReflectField> ENTITY_LIST_FIELD - = ReflectField.lookup(new ClassToken>() {}, World.class, "entityList"); - - private static final ReflectMethod REGISTER_ENTITY_METHOD = ReflectMethod.lookup(Object.class, World.class, "b", Entity.class); - - private final ProtocolPacketSettings protocolPacketSettings; - - public VersionNMSManager(ProtocolPacketSettings protocolPacketSettings) { - this.protocolPacketSettings = protocolPacketSettings; + @Override + public EntityID newEntityID() { + return null; } @Override - public void setup() throws Exception { - registerCustomEntity(EntityNMSSlime.class, 55); - } - - public void registerCustomEntity(Class entityClass, int id) throws Exception { - // Use reflection to get the RegistryID of entities - RegistryID> registryID = REGISTRY_ID_FIELD.get(EntityTypes.REGISTRY); - Object[] idToClassMap = ID_TO_CLASS_MAP_FIELD.get(registryID); - - // Save the the ID -> EntityTypes mapping before the registration - Object oldValue = idToClassMap[id]; - - // Register the EntityTypes object - registryID.a(new EntityTypes<>(entityClass, world -> null, true, true, null), id); - - // Restore the ID -> EntityTypes mapping - idToClassMap[id] = oldValue; - } - - @Override - public NMSItem spawnNMSItem( - org.bukkit.World bukkitWorld, double x, double y, double z, - StandardItemLine parentHologramLine, - ItemStack stack) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSItem item = new EntityNMSItem(nmsWorld, parentHologramLine); - 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 parentHologramLine) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSSlime slime = new EntityNMSSlime(nmsWorld, parentHologramLine); - 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 parentHologramLine) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) world).getHandle(); - EntityNMSArmorStand armorStand = new EntityNMSArmorStand(nmsWorld, parentHologramLine, protocolPacketSettings); - armorStand.setLocationNMS(x, y, z); - addEntityToWorld(nmsWorld, armorStand); - return armorStand; - } - - 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); - final int chunkZ = MathHelper.floor(nmsEntity.locZ / 16.0); - - if (!nmsWorld.getChunkProviderServer().isLoaded(chunkX, chunkZ)) { - // This should never happen - nmsEntity.dead = true; - throw new SpawnFailedException(SpawnFailedException.CHUNK_NOT_LOADED); - } - - nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity); - 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(); - throw new SpawnFailedException(SpawnFailedException.CHUNK_NOT_LOADED); - } - } else { - nmsWorld.entityList.add(nmsEntity); - } - - try { - REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity); - } catch (ReflectiveOperationException e) { - 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 NMSEntity; - } - - @Override - public NMSEntity getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - - if (nmsEntity instanceof NMSEntity) { - return (NMSEntity) nmsEntity; - } else { - return null; - } - } - - @Override - public NMSEntity getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - Entity nmsEntity = nmsWorld.getEntity(entityID); - - if (nmsEntity instanceof NMSEntity) { - return (NMSEntity) nmsEntity; - } else { - return null; - } - } - - @Override - public Object createCustomNameNMSObject(String customName) { - return EntityNMSArmorStand.createCustomNameNMSObject(customName); + public NMSPacketList createPacketList() { + return null; } } diff --git a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/CraftNMSArmorStand.java b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/CraftNMSArmorStand.java deleted file mode 100644 index 5ff093b7..00000000 --- a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/CraftNMSArmorStand.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_13_R2; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_13_R2.CraftServer; -import org.bukkit.craftbukkit.v1_13_R2.entity.CraftArmorStand; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.ItemStack; -import org.bukkit.potion.PotionEffect; -import org.bukkit.util.EulerAngle; -import org.bukkit.util.Vector; - -import java.util.Collection; - -public class CraftNMSArmorStand extends CraftArmorStand { - - public CraftNMSArmorStand(CraftServer server, EntityNMSArmorStand entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // 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) {} - - // 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 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 setGliding(boolean gliding) {} - @Override public boolean setLeashHolder(Entity holder) { return false; } - @Override public void setSwimming(boolean swimming) {} - - // Methods from Entity - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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) {} - - -} diff --git a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/CraftNMSItem.java b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/CraftNMSItem.java deleted file mode 100644 index adebba15..00000000 --- a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/CraftNMSItem.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_13_R2; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_13_R2.CraftServer; -import org.bukkit.craftbukkit.v1_13_R2.entity.CraftItem; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; - -public class CraftNMSItem extends CraftItem { - - public CraftNMSItem(CraftServer server, EntityNMSItem entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // Methods from Entity - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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) {} - -} diff --git a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/CraftNMSSlime.java b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/CraftNMSSlime.java deleted file mode 100644 index 34b7ff49..00000000 --- a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/CraftNMSSlime.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_13_R2; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_13_R2.CraftServer; -import org.bukkit.craftbukkit.v1_13_R2.entity.CraftSlime; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.loot.LootTable; -import org.bukkit.potion.PotionEffect; -import org.bukkit.util.Vector; - -import java.util.Collection; - -public class CraftNMSSlime extends CraftSlime { - - public CraftNMSSlime(CraftServer server, EntityNMSSlime entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // 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 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 setGliding(boolean gliding) {} - @Override public boolean setLeashHolder(Entity holder) { return false; } - @Override public void setSwimming(boolean swimming) {} - - // Methods from Entity - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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) {} - - // Methods from Slime - @Override public void setSize(int size) {} - @Override public void setTarget(LivingEntity target) {} - -} diff --git a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityNMSArmorStand.java b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityNMSArmorStand.java deleted file mode 100644 index 64d0cc72..00000000 --- a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityNMSArmorStand.java +++ /dev/null @@ -1,262 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_13_R2; - -import me.filoghost.fcommons.Preconditions; -import me.filoghost.fcommons.Strings; -import me.filoghost.fcommons.reflection.ReflectField; -import me.filoghost.holographicdisplays.common.DebugLogger; -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.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.EnumHand; -import net.minecraft.server.v1_13_R2.EnumInteractionResult; -import net.minecraft.server.v1_13_R2.EnumItemSlot; -import net.minecraft.server.v1_13_R2.IChatBaseComponent; -import net.minecraft.server.v1_13_R2.ItemStack; -import net.minecraft.server.v1_13_R2.NBTTagCompound; -import net.minecraft.server.v1_13_R2.PacketPlayOutEntityTeleport; -import net.minecraft.server.v1_13_R2.SoundEffect; -import net.minecraft.server.v1_13_R2.Vec3D; -import net.minecraft.server.v1_13_R2.World; -import org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_13_R2.util.CraftChatMessage; -import org.bukkit.entity.Player; - -import java.util.Objects; - -public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand { - - private static final ReflectField VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle"); - - private final StandardHologramLine parentHologramLine; - private final ProtocolPacketSettings protocolPacketSettings; - private final VersionNMSEntityHelper helper; - private String customName; - - public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, ProtocolPacketSettings protocolPacketSettings) { - super(world); - this.parentHologramLine = parentHologramLine; - this.protocolPacketSettings = protocolPacketSettings; - this.helper = new VersionNMSEntityHelper(this); - - super.setInvisible(true); - super.setSmall(true); - super.setArms(false); - super.setNoGravity(true); - super.setBasePlate(true); - super.setMarker(true); - super.collides = false; - super.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet - forceSetBoundingBox(new NullBoundingBox()); - } - - @Override - public void tick() { - // Disable normal ticking for this entity - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity - if (super.onGround) { - super.onGround = false; - } - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity - if (super.onGround) { - super.onGround = false; - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound save(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void f(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void a(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void setCustomName(IChatBaseComponent ichatbasecomponent) { - // Prevents changes to custom name - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Prevents changes to custom name visibility - } - - @Override - public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) { - // Prevent armor stand from being equipped - return EnumInteractionResult.PASS; - } - - @Override - public boolean c(int i, ItemStack item) { - // Prevent armor stand from being equipped - return false; - } - - @Override - public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { - // Prevent armor stand from being equipped - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Prevent changes to bounding box - } - - public void forceSetBoundingBox(AxisAlignedBB boundingBox) { - super.a(boundingBox); - } - - @Override - public void a(SoundEffect soundeffect, float f, float f1) { - // Remove sounds - } - - @Override - public void setCustomNameNMS(String customName) { - if (Objects.equals(this.customName, customName)) { - return; - } - this.customName = customName; - super.setCustomName(createCustomNameNMSObject(customName)); - super.setCustomNameVisible(customName != null && !customName.isEmpty()); - } - - protected static IChatBaseComponent createCustomNameNMSObject(String customName) { - return CraftChatMessage.fromStringOrNull(Strings.truncate(customName, 300)); - } - - @Override - public String getCustomNameStringNMS() { - return this.customName; - } - - @Override - public IChatBaseComponent getCustomNameObjectNMS() { - return super.getCustomName(); - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSArmorStand(super.world.getServer(), this); - } - return super.bukkitEntity; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - if (protocolPacketSettings.sendAccurateLocationPackets()) { - helper.broadcastPacket(new PacketPlayOutEntityTeleport(this)); - } - } - - @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(passengerEntity); - } catch (ReflectiveOperationException e) { - DebugLogger.cannotSetPassenger(e); - } - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - -} diff --git a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityNMSItem.java b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityNMSItem.java deleted file mode 100644 index 7d930c97..00000000 --- a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityNMSItem.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_13_R2; - -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; -import me.filoghost.holographicdisplays.common.nms.NMSCommons; -import me.filoghost.holographicdisplays.common.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.EntityHuman; -import net.minecraft.server.v1_13_R2.EntityItem; -import net.minecraft.server.v1_13_R2.EntityPlayer; -import net.minecraft.server.v1_13_R2.ItemStack; -import net.minecraft.server.v1_13_R2.NBTTagCompound; -import net.minecraft.server.v1_13_R2.NBTTagList; -import net.minecraft.server.v1_13_R2.NBTTagString; -import net.minecraft.server.v1_13_R2.World; -import org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack; -import org.bukkit.entity.Player; - -public class EntityNMSItem extends EntityItem implements NMSItem { - - private final StandardItemLine parentHologramLine; - private final VersionNMSEntityHelper helper; - - public EntityNMSItem(World world, StandardItemLine parentHologramLine) { - super(world); - this.parentHologramLine = parentHologramLine; - this.helper = new VersionNMSEntityHelper(this); - - super.pickupDelay = 32767; // Lock the item pickup delay, also prevents entities from picking up the item - } - - @Override - public void tick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - // Method called when a player is near - @Override - public void d(EntityHuman human) { - if (human.locY < super.locY - 1.5 || human.locY > super.locY + 1.0) { - // Too low or too high, it's a bit weird - return; - } - - if (human instanceof EntityPlayer) { - parentHologramLine.onPickup(((EntityPlayer) human).getBukkitEntity()); - // It is never added to the inventory - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound save(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void f(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void a(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public boolean isAlive() { - // This override prevents items from being picked up by hoppers (should have no side effects) - return false; - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSItem(super.world.getServer(), this); - } - return super.bukkitEntity; - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - } - - @Override - public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) { - ItemStack newItem = CraftItemStack.asNMSCopy(stack); - - if (newItem == null || newItem == ItemStack.a) { // ItemStack.a is returned if the stack is not valid - newItem = new ItemStack(Blocks.BEDROCK); - } - - if (newItem.getTag() == null) { - newItem.setTag(new NBTTagCompound()); - } - NBTTagCompound display = newItem.getTag().getCompound("display"); // Returns a new NBTTagCompound if not existing - if (!newItem.getTag().hasKey("display")) { - newItem.getTag().set("display", display); - } - - NBTTagList tagList = new NBTTagList(); - tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE)); - display.set("Lore", tagList); - - super.setItemStack(newItem); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - - @Override - public Object getRawItemStack() { - return super.getItemStack(); - } - -} diff --git a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityNMSSlime.java b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityNMSSlime.java deleted file mode 100644 index e14006a7..00000000 --- a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityNMSSlime.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_13_R2; - -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.nms.entity.NMSSlime; -import net.minecraft.server.v1_13_R2.AxisAlignedBB; -import net.minecraft.server.v1_13_R2.DamageSource; -import net.minecraft.server.v1_13_R2.EntityDamageSource; -import net.minecraft.server.v1_13_R2.EntityPlayer; -import net.minecraft.server.v1_13_R2.EntitySlime; -import net.minecraft.server.v1_13_R2.IChatBaseComponent; -import net.minecraft.server.v1_13_R2.NBTTagCompound; -import net.minecraft.server.v1_13_R2.SoundEffect; -import net.minecraft.server.v1_13_R2.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.player.PlayerInteractEntityEvent; - -public class EntityNMSSlime extends EntitySlime implements NMSSlime { - - private final StandardHologramLine parentHologramLine; - private final VersionNMSEntityHelper helper; - - public EntityNMSSlime(World world, StandardHologramLine parentHologramLine) { - super(world); - this.parentHologramLine = parentHologramLine; - this.helper = new VersionNMSEntityHelper(this); - - super.persistent = true; - super.collides = false; - super.a(0.0F, 0.0F); - super.setSize(1, false); - super.setInvisible(true); - forceSetBoundingBox(new NullBoundingBox()); - } - - @Override - public void tick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Prevent changes to bounding box - } - - public void forceSetBoundingBox(AxisAlignedBB boundingBox) { - super.a(boundingBox); - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound save(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void f(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void a(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean damageEntity(DamageSource damageSource, float amount) { - if (damageSource instanceof EntityDamageSource) { - EntityDamageSource entityDamageSource = (EntityDamageSource) damageSource; - if (entityDamageSource.getEntity() instanceof EntityPlayer) { - Player player = ((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(); - PlayerInteractEntityEvent event = new PlayerInteractEntityEvent(player, getBukkitEntity()); - Bukkit.getPluginManager().callEvent(event); // Bukkit takes care of the exceptions - } - } - return false; - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void setCustomName(IChatBaseComponent ichatbasecomponent) { - // Prevents changes to custom name - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Prevents changes to custom name visibility - } - - @Override - public void a(SoundEffect soundeffect, float f, float f1) { - // Remove sounds - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSSlime(super.world.getServer(), this); - } - return super.bukkitEntity; - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - -} diff --git a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/NullBoundingBox.java b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/NullBoundingBox.java deleted file mode 100644 index d22b36dc..00000000 --- a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/NullBoundingBox.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_13_R2; - -import net.minecraft.server.v1_13_R2.AxisAlignedBB; -import net.minecraft.server.v1_13_R2.BlockPosition; -import net.minecraft.server.v1_13_R2.EnumDirection.EnumAxis; -import net.minecraft.server.v1_13_R2.MovingObjectPosition; -import net.minecraft.server.v1_13_R2.Vec3D; - -public class NullBoundingBox extends AxisAlignedBB { - - public NullBoundingBox() { - super(0, 0, 0, 0, 0, 0); - } - - @Override - public double a() { - return 0.0; - } - - @Override - public AxisAlignedBB a(AxisAlignedBB arg0) { - return this; - } - - @Override - public AxisAlignedBB a(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public MovingObjectPosition b(Vec3D arg0, Vec3D arg1) { - return null; - } - - @Override - public AxisAlignedBB grow(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public AxisAlignedBB shrink(double arg0) { - return this; - } - - @Override - public AxisAlignedBB a(BlockPosition arg0) { - return this; - } - - @Override - public boolean a(double arg0, double arg1, double arg2, double arg3, double arg4, double arg5) { - return false; - } - - @Override - public boolean b(Vec3D arg0) { - return false; - } - - @Override - public AxisAlignedBB g(double arg0) { - return this; - } - - @Override - public AxisAlignedBB a(Vec3D arg0) { - return this; - } - - @Override - public AxisAlignedBB b(AxisAlignedBB arg0) { - return this; - } - - @Override - public AxisAlignedBB b(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public boolean c(AxisAlignedBB arg0) { - return false; - } - - @Override - public AxisAlignedBB d(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public double a(EnumAxis arg0) { - return 0.0; - } - - @Override - public MovingObjectPosition a(Vec3D arg0, Vec3D arg1, BlockPosition arg2) { - return null; - } - - @Override - public double b(EnumAxis arg0) { - return 0.0; - } - - @Override - public boolean e(double arg0, double arg1, double arg2) { - return false; - } - - @Override - public AxisAlignedBB f(double arg0, double arg1, double arg2) { - return this; - } - -} diff --git a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionNMSEntityHelper.java b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionNMSEntityHelper.java deleted file mode 100644 index 532dfad2..00000000 --- a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionNMSEntityHelper.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_13_R2; - -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntityHelper; -import net.minecraft.server.v1_13_R2.Entity; -import net.minecraft.server.v1_13_R2.EntityTrackerEntry; -import net.minecraft.server.v1_13_R2.Packet; -import net.minecraft.server.v1_13_R2.WorldServer; -import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer; -import org.bukkit.entity.Player; - -public class VersionNMSEntityHelper extends NMSEntityHelper { - - private final Entity entity; - - public VersionNMSEntityHelper(Entity entity) { - this.entity = entity; - } - - @Override - protected EntityTrackerEntry getTracker0() { - return ((WorldServer) entity.world).tracker.trackedEntities.get(entity.getId()); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - EntityTrackerEntry tracker = getTracker(); - if (tracker != null) { - return tracker.trackedPlayers.contains(((CraftPlayer) bukkitPlayer).getHandle()); - } else { - return false; - } - } - - public void broadcastPacket(Packet packet) { - EntityTrackerEntry tracker = getTracker(); - if (tracker != null) { - tracker.broadcast(packet); - } - } - -} diff --git a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionNMSManager.java b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionNMSManager.java index 71b2a9a3..aeea5a12 100644 --- a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionNMSManager.java +++ b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionNMSManager.java @@ -5,171 +5,20 @@ */ package me.filoghost.holographicdisplays.nms.v1_13_R2; -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.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; -import me.filoghost.holographicdisplays.common.nms.NMSCommons; +import me.filoghost.holographicdisplays.common.nms.EntityID; import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; -import me.filoghost.holographicdisplays.common.nms.SpawnFailedException; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntity; -import me.filoghost.holographicdisplays.common.nms.entity.NMSItem; -import net.minecraft.server.v1_13_R2.Entity; -import net.minecraft.server.v1_13_R2.EntityTypes; -import net.minecraft.server.v1_13_R2.IRegistry; -import net.minecraft.server.v1_13_R2.MathHelper; -import net.minecraft.server.v1_13_R2.RegistryID; -import net.minecraft.server.v1_13_R2.RegistryMaterials; -import net.minecraft.server.v1_13_R2.World; -import net.minecraft.server.v1_13_R2.WorldServer; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_13_R2.CraftWorld; -import org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity; -import org.bukkit.inventory.ItemStack; - -import java.util.List; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; public class VersionNMSManager implements NMSManager { - private static final ReflectField>> REGISTRY_ID_FIELD - = ReflectField.lookup(new ClassToken>>() {}, RegistryMaterials.class, "b"); - private static final ReflectField ID_TO_CLASS_MAP_FIELD - = ReflectField.lookup(Object[].class, RegistryID.class, "d"); - private static final ReflectField> ENTITY_LIST_FIELD - = ReflectField.lookup(new ClassToken>() {}, World.class, "entityList"); - - private static final ReflectMethod REGISTER_ENTITY_METHOD = ReflectMethod.lookup(Object.class, World.class, "b", Entity.class); - - private final ProtocolPacketSettings protocolPacketSettings; - - public VersionNMSManager(ProtocolPacketSettings protocolPacketSettings) { - this.protocolPacketSettings = protocolPacketSettings; + @Override + public EntityID newEntityID() { + return null; } @Override - public void setup() throws Exception { - registerCustomEntity(EntityNMSSlime.class, 55); - } - - public void registerCustomEntity(Class entityClass, int id) throws Exception { - // Use reflection to get the RegistryID of entities - RegistryID> registryID = REGISTRY_ID_FIELD.get(IRegistry.ENTITY_TYPE); - Object[] idToClassMap = ID_TO_CLASS_MAP_FIELD.get(registryID); - - // Save the the ID -> EntityTypes mapping before the registration - Object oldValue = idToClassMap[id]; - - // Register the EntityTypes object - registryID.a(new EntityTypes<>(entityClass, world -> null, true, true, null), id); - - // Restore the ID -> EntityTypes mapping - idToClassMap[id] = oldValue; - } - - @Override - public NMSItem spawnNMSItem( - org.bukkit.World bukkitWorld, double x, double y, double z, - StandardItemLine parentHologramLine, - ItemStack stack) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSItem item = new EntityNMSItem(nmsWorld, parentHologramLine); - 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 parentHologramLine) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSSlime slime = new EntityNMSSlime(nmsWorld, parentHologramLine); - 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 parentHologramLine) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) world).getHandle(); - EntityNMSArmorStand armorStand = new EntityNMSArmorStand(nmsWorld, parentHologramLine, protocolPacketSettings); - armorStand.setLocationNMS(x, y, z); - addEntityToWorld(nmsWorld, armorStand); - return armorStand; - } - - 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); - final int chunkZ = MathHelper.floor(nmsEntity.locZ / 16.0); - - if (!nmsWorld.isChunkLoaded(chunkX, chunkZ, true)) { // The boolean "true" is currently unused - // This should never happen - nmsEntity.dead = true; - throw new SpawnFailedException(SpawnFailedException.CHUNK_NOT_LOADED); - } - - nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity); - 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(); - throw new SpawnFailedException(SpawnFailedException.CHUNK_NOT_LOADED); - } - } else { - nmsWorld.entityList.add(nmsEntity); - } - - try { - REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity); - } catch (ReflectiveOperationException e) { - 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 NMSEntity; - } - - @Override - public NMSEntity getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - - if (nmsEntity instanceof NMSEntity) { - return (NMSEntity) nmsEntity; - } else { - return null; - } - } - - @Override - public NMSEntity getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - Entity nmsEntity = nmsWorld.getEntity(entityID); - - if (nmsEntity instanceof NMSEntity) { - return (NMSEntity) nmsEntity; - } else { - return null; - } - } - - @Override - public Object createCustomNameNMSObject(String customName) { - return EntityNMSArmorStand.createCustomNameNMSObject(customName); + public NMSPacketList createPacketList() { + return null; } } diff --git a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/CraftNMSArmorStand.java b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/CraftNMSArmorStand.java deleted file mode 100644 index 940ab13d..00000000 --- a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/CraftNMSArmorStand.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_14_R1; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_14_R1.CraftServer; -import org.bukkit.craftbukkit.v1_14_R1.entity.CraftArmorStand; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.ItemStack; -import org.bukkit.potion.PotionEffect; -import org.bukkit.util.EulerAngle; -import org.bukkit.util.Vector; - -import java.util.Collection; - -public class CraftNMSArmorStand extends CraftArmorStand { - - public CraftNMSArmorStand(CraftServer server, EntityNMSArmorStand entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // 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) {} - - // 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 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 setGliding(boolean gliding) {} - @Override public boolean setLeashHolder(Entity holder) { return false; } - @Override public void setSwimming(boolean swimming) {} - - // Methods from Entity class - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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) {} - - -} diff --git a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/CraftNMSItem.java b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/CraftNMSItem.java deleted file mode 100644 index 765b26b4..00000000 --- a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/CraftNMSItem.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_14_R1; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_14_R1.CraftServer; -import org.bukkit.craftbukkit.v1_14_R1.entity.CraftItem; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; - -public class CraftNMSItem extends CraftItem { - - public CraftNMSItem(CraftServer server, EntityNMSItem entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // Methods from Item class - @Override public void setItemStack(ItemStack stack) {} - @Override public void setPickupDelay(int delay) {} - - // Methods from Entity class - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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) {} - -} diff --git a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/CraftNMSSlime.java b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/CraftNMSSlime.java deleted file mode 100644 index d7a02406..00000000 --- a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/CraftNMSSlime.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_14_R1; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_14_R1.CraftServer; -import org.bukkit.craftbukkit.v1_14_R1.entity.CraftSlime; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.loot.LootTable; -import org.bukkit.potion.PotionEffect; -import org.bukkit.util.Vector; - -import java.util.Collection; - -public class CraftNMSSlime extends CraftSlime { - - public CraftNMSSlime(CraftServer server, EntityNMSSlime entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // Methods from Slime class - @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) {} - - // 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 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 setGliding(boolean gliding) {} - @Override public boolean setLeashHolder(Entity holder) { return false; } - @Override public void setSwimming(boolean swimming) {} - - // Methods from Entity class - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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) {} - -} diff --git a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityNMSArmorStand.java b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityNMSArmorStand.java deleted file mode 100644 index f2ebfae8..00000000 --- a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityNMSArmorStand.java +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_14_R1; - -import me.filoghost.fcommons.Preconditions; -import me.filoghost.fcommons.Strings; -import me.filoghost.fcommons.reflection.ReflectField; -import me.filoghost.holographicdisplays.common.DebugLogger; -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.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.EntityTypes; -import net.minecraft.server.v1_14_R1.EnumHand; -import net.minecraft.server.v1_14_R1.EnumInteractionResult; -import net.minecraft.server.v1_14_R1.EnumItemSlot; -import net.minecraft.server.v1_14_R1.IChatBaseComponent; -import net.minecraft.server.v1_14_R1.ItemStack; -import net.minecraft.server.v1_14_R1.NBTTagCompound; -import net.minecraft.server.v1_14_R1.PacketPlayOutEntityTeleport; -import net.minecraft.server.v1_14_R1.SoundEffect; -import net.minecraft.server.v1_14_R1.Vec3D; -import net.minecraft.server.v1_14_R1.World; -import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_14_R1.util.CraftChatMessage; -import org.bukkit.entity.Player; - -import java.util.Objects; - -public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand { - - private static final ReflectField VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle"); - - private final StandardHologramLine parentHologramLine; - private final ProtocolPacketSettings protocolPacketSettings; - private final VersionNMSEntityHelper helper; - private CraftEntity customBukkitEntity; - private String customName; - - public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, ProtocolPacketSettings protocolPacketSettings) { - super(EntityTypes.ARMOR_STAND, world); - this.parentHologramLine = parentHologramLine; - this.protocolPacketSettings = protocolPacketSettings; - this.helper = new VersionNMSEntityHelper(this); - - super.setInvisible(true); - super.setSmall(true); - super.setArms(false); - super.setNoGravity(true); - super.setBasePlate(true); - super.setMarker(true); - super.collides = false; - super.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet - forceSetBoundingBox(new NullBoundingBox()); - } - - @Override - public void tick() { - // Disable normal ticking for this entity - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity - if (super.onGround) { - super.onGround = false; - } - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity - if (super.onGround) { - super.onGround = false; - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound save(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void f(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void a(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void setCustomName(IChatBaseComponent ichatbasecomponent) { - // Prevents changes to custom name - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Prevents changes to custom name visibility - } - - @Override - public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) { - // Prevent armor stand from being equipped - return EnumInteractionResult.PASS; - } - - @Override - public boolean a_(int i, ItemStack item) { - // Prevent armor stand from being equipped - return false; - } - - @Override - public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { - // Prevent armor stand from being equipped - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Prevent changes to bounding box - } - - public void forceSetBoundingBox(AxisAlignedBB boundingBox) { - super.a(boundingBox); - } - - @Override - public void a(SoundEffect soundeffect, float f, float f1) { - // Remove sounds - } - - @Override - public void setCustomNameNMS(String customName) { - if (Objects.equals(this.customName, customName)) { - return; - } - this.customName = customName; - super.setCustomName(createCustomNameNMSObject(customName)); - super.setCustomNameVisible(customName != null && !customName.isEmpty()); - } - - protected static IChatBaseComponent createCustomNameNMSObject(String customName) { - return CraftChatMessage.fromStringOrNull(Strings.truncate(customName, 300)); - } - - @Override - public String getCustomNameStringNMS() { - return this.customName; - } - - @Override - public IChatBaseComponent getCustomNameObjectNMS() { - return super.getCustomName(); - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public CraftEntity getBukkitEntity() { - if (customBukkitEntity == null) { - customBukkitEntity = new CraftNMSArmorStand(super.world.getServer(), this); - } - return customBukkitEntity; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - if (protocolPacketSettings.sendAccurateLocationPackets()) { - helper.broadcastPacket(new PacketPlayOutEntityTeleport(this)); - } - } - - @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(passengerEntity); - } catch (ReflectiveOperationException e) { - DebugLogger.cannotSetPassenger(e); - } - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - -} diff --git a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityNMSItem.java b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityNMSItem.java deleted file mode 100644 index 30f164f5..00000000 --- a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityNMSItem.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_14_R1; - -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; -import me.filoghost.holographicdisplays.common.nms.NMSCommons; -import me.filoghost.holographicdisplays.common.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.EntityHuman; -import net.minecraft.server.v1_14_R1.EntityItem; -import net.minecraft.server.v1_14_R1.EntityPlayer; -import net.minecraft.server.v1_14_R1.EntityTypes; -import net.minecraft.server.v1_14_R1.ItemStack; -import net.minecraft.server.v1_14_R1.NBTTagCompound; -import net.minecraft.server.v1_14_R1.NBTTagList; -import net.minecraft.server.v1_14_R1.NBTTagString; -import net.minecraft.server.v1_14_R1.World; -import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack; -import org.bukkit.entity.Player; - -public class EntityNMSItem extends EntityItem implements NMSItem { - - private final StandardItemLine parentHologramLine; - private final VersionNMSEntityHelper helper; - private CraftEntity customBukkitEntity; - - public EntityNMSItem(World world, StandardItemLine parentHologramLine) { - super(EntityTypes.ITEM, world); - this.parentHologramLine = parentHologramLine; - this.helper = new VersionNMSEntityHelper(this); - - super.pickupDelay = 32767; // Lock the item pickup delay, also prevents entities from picking up the item - } - - @Override - public void tick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - // Method called when a player is near - @Override - public void pickup(EntityHuman human) { - if (human.locY < super.locY - 1.5 || human.locY > super.locY + 1.0) { - // Too low or too high, it's a bit weird - return; - } - - if (human instanceof EntityPlayer) { - parentHologramLine.onPickup(((EntityPlayer) human).getBukkitEntity()); - // It is never added to the inventory - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound save(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void f(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void a(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public boolean isAlive() { - // This override prevents items from being picked up by hoppers (should have no side effects) - return false; - } - - @Override - public CraftEntity getBukkitEntity() { - if (customBukkitEntity == null) { - customBukkitEntity = new CraftNMSItem(super.world.getServer(), this); - } - return customBukkitEntity; - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - } - - @Override - public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) { - ItemStack newItem = CraftItemStack.asNMSCopy(stack); - - if (newItem == null || newItem == ItemStack.a) { // ItemStack.a is returned if the stack is not valid - newItem = new ItemStack(Blocks.BEDROCK); - } - - if (newItem.getTag() == null) { - newItem.setTag(new NBTTagCompound()); - } - NBTTagCompound display = newItem.getTag().getCompound("display"); // Returns a new NBTTagCompound if not existing - if (!newItem.getTag().hasKey("display")) { - newItem.getTag().set("display", display); - } - - NBTTagList tagList = new NBTTagList(); - tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE)); - display.set("Lore", tagList); - - super.setItemStack(newItem); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - - @Override - public Object getRawItemStack() { - return super.getItemStack(); - } - -} diff --git a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityNMSSlime.java b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityNMSSlime.java deleted file mode 100644 index c8cdb923..00000000 --- a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityNMSSlime.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_14_R1; - -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.nms.entity.NMSSlime; -import net.minecraft.server.v1_14_R1.AxisAlignedBB; -import net.minecraft.server.v1_14_R1.DamageSource; -import net.minecraft.server.v1_14_R1.EntityDamageSource; -import net.minecraft.server.v1_14_R1.EntityPlayer; -import net.minecraft.server.v1_14_R1.EntitySlime; -import net.minecraft.server.v1_14_R1.EntityTypes; -import net.minecraft.server.v1_14_R1.IChatBaseComponent; -import net.minecraft.server.v1_14_R1.NBTTagCompound; -import net.minecraft.server.v1_14_R1.SoundEffect; -import net.minecraft.server.v1_14_R1.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.player.PlayerInteractEntityEvent; - -public class EntityNMSSlime extends EntitySlime implements NMSSlime { - - private final StandardHologramLine parentHologramLine; - private final VersionNMSEntityHelper helper; - private CraftEntity customBukkitEntity; - - public EntityNMSSlime(World world, StandardHologramLine parentHologramLine) { - super(EntityTypes.SLIME, world); - this.parentHologramLine = parentHologramLine; - this.helper = new VersionNMSEntityHelper(this); - - super.persistent = true; - super.collides = false; - super.a(0.0F, 0.0F); - super.setSize(1, false); - super.setInvisible(true); - forceSetBoundingBox(new NullBoundingBox()); - } - - @Override - public void tick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Prevent changes to bounding box - } - - public void forceSetBoundingBox(AxisAlignedBB boundingBox) { - super.a(boundingBox); - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound save(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void f(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void a(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean damageEntity(DamageSource damageSource, float amount) { - if (damageSource instanceof EntityDamageSource) { - EntityDamageSource entityDamageSource = (EntityDamageSource) damageSource; - if (entityDamageSource.getEntity() instanceof EntityPlayer) { - Player player = ((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(); - PlayerInteractEntityEvent event = new PlayerInteractEntityEvent(player, getBukkitEntity()); - Bukkit.getPluginManager().callEvent(event); // Bukkit takes care of the exceptions - } - } - return false; - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void setCustomName(IChatBaseComponent ichatbasecomponent) { - // Prevents changes to custom name - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Prevents changes to custom name visibility - } - - @Override - public void a(SoundEffect soundeffect, float f, float f1) { - // Remove sounds - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public CraftEntity getBukkitEntity() { - if (customBukkitEntity == null) { - customBukkitEntity = new CraftNMSSlime(super.world.getServer(), this); - } - return customBukkitEntity; - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - -} diff --git a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/NullBoundingBox.java b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/NullBoundingBox.java deleted file mode 100644 index 72175746..00000000 --- a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/NullBoundingBox.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_14_R1; - -import net.minecraft.server.v1_14_R1.AxisAlignedBB; -import net.minecraft.server.v1_14_R1.BlockPosition; -import net.minecraft.server.v1_14_R1.EnumDirection.EnumAxis; -import net.minecraft.server.v1_14_R1.Vec3D; - -public class NullBoundingBox extends AxisAlignedBB { - - public NullBoundingBox() { - super(0, 0, 0, 0, 0, 0); - } - - @Override - public double a() { - return 0.0; - } - - @Override - public AxisAlignedBB a(AxisAlignedBB arg0) { - return this; - } - - @Override - public AxisAlignedBB a(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public AxisAlignedBB grow(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public AxisAlignedBB shrink(double arg0) { - return this; - } - - @Override - public AxisAlignedBB a(BlockPosition arg0) { - return this; - } - - @Override - public boolean a(double arg0, double arg1, double arg2, double arg3, double arg4, double arg5) { - return false; - } - - @Override - public AxisAlignedBB g(double arg0) { - return this; - } - - @Override - public AxisAlignedBB a(Vec3D arg0) { - return this; - } - - @Override - public AxisAlignedBB b(AxisAlignedBB arg0) { - return this; - } - - @Override - public AxisAlignedBB b(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public boolean c(AxisAlignedBB arg0) { - return false; - } - - @Override - public AxisAlignedBB d(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public double a(EnumAxis arg0) { - return 0.0; - } - - @Override - public double b(EnumAxis arg0) { - return 0.0; - } - - @Override - public boolean e(double arg0, double arg1, double arg2) { - return false; - } - - @Override - public double b() { - return 0.0; - } - - @Override - public double c() { - return 0.0; - } - - @Override - public double d() { - return 0.0; - } - - @Override - public boolean c(Vec3D var0) { - return false; - } - - @Override - public Vec3D f() { - return Vec3D.a; - } - -} diff --git a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionNMSEntityHelper.java b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionNMSEntityHelper.java deleted file mode 100644 index 683fe54c..00000000 --- a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionNMSEntityHelper.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_14_R1; - -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntityHelper; -import net.minecraft.server.v1_14_R1.Entity; -import net.minecraft.server.v1_14_R1.Packet; -import net.minecraft.server.v1_14_R1.PlayerChunkMap.EntityTracker; -import net.minecraft.server.v1_14_R1.WorldServer; -import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; - -public class VersionNMSEntityHelper extends NMSEntityHelper { - - private final Entity entity; - - public VersionNMSEntityHelper(Entity entity) { - this.entity = entity; - } - - @Override - protected EntityTracker getTracker0() { - return ((WorldServer) entity.world).getChunkProvider().playerChunkMap.trackedEntities.get(entity.getId()); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - EntityTracker tracker = getTracker(); - if (tracker != null) { - return tracker.trackedPlayers.contains(((CraftPlayer) bukkitPlayer).getHandle()); - } else { - return false; - } - } - - public void broadcastPacket(Packet packet) { - EntityTracker tracker = getTracker(); - if (tracker != null) { - tracker.broadcast(packet); - } - } - -} diff --git a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionNMSManager.java b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionNMSManager.java index ef3d9737..235b99d9 100644 --- a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionNMSManager.java +++ b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionNMSManager.java @@ -5,154 +5,20 @@ */ package me.filoghost.holographicdisplays.nms.v1_14_R1; -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.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; +import me.filoghost.holographicdisplays.common.nms.EntityID; import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; -import me.filoghost.holographicdisplays.common.nms.SpawnFailedException; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntity; -import me.filoghost.holographicdisplays.common.nms.entity.NMSItem; -import net.minecraft.server.v1_14_R1.Entity; -import net.minecraft.server.v1_14_R1.EntityTypes; -import net.minecraft.server.v1_14_R1.EnumCreatureType; -import net.minecraft.server.v1_14_R1.IRegistry; -import net.minecraft.server.v1_14_R1.MathHelper; -import net.minecraft.server.v1_14_R1.RegistryID; -import net.minecraft.server.v1_14_R1.RegistryMaterials; -import net.minecraft.server.v1_14_R1.WorldServer; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_14_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity; -import org.bukkit.inventory.ItemStack; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; public class VersionNMSManager implements NMSManager { - private static final ReflectField>> REGISTRY_ID_FIELD - = ReflectField.lookup(new ClassToken>>() {}, RegistryMaterials.class, "b"); - private static final ReflectField ID_TO_CLASS_MAP_FIELD - = ReflectField.lookup(Object[].class, RegistryID.class, "d"); - private static final ReflectMethod REGISTER_ENTITY_METHOD - = ReflectMethod.lookup(void.class, WorldServer.class, "registerEntity", Entity.class); - - private final ProtocolPacketSettings protocolPacketSettings; - - public VersionNMSManager(ProtocolPacketSettings protocolPacketSettings) { - this.protocolPacketSettings = protocolPacketSettings; + @Override + public EntityID newEntityID() { + return null; } @Override - public void setup() throws Exception { - registerCustomEntity(EntityNMSSlime.class, 55, 2.04f, 2.04f); - } - - public void registerCustomEntity(Class entityClass, int id, float sizeWidth, float sizeHeight) throws Exception { - // Use reflection to get the RegistryID of entities - RegistryID> registryID = REGISTRY_ID_FIELD.get(IRegistry.ENTITY_TYPE); - Object[] idToClassMap = ID_TO_CLASS_MAP_FIELD.get(registryID); - - // Save the the ID -> EntityTypes mapping before the registration - Object oldValue = idToClassMap[id]; - - // Register the EntityTypes object - registryID.a(EntityTypes.a.a(EnumCreatureType.MONSTER).a(sizeWidth, sizeHeight).b().a((String) null), id); - - // Restore the ID -> EntityTypes mapping - idToClassMap[id] = oldValue; - } - - @Override - public NMSItem spawnNMSItem( - World bukkitWorld, double x, double y, double z, - StandardItemLine parentHologramLine, - ItemStack stack) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSItem item = new EntityNMSItem(nmsWorld, parentHologramLine); - 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 parentHologramLine) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSSlime slime = new EntityNMSSlime(nmsWorld, parentHologramLine); - slime.setLocationNMS(x, y, z); - addEntityToWorld(nmsWorld, slime); - return slime; - } - - @Override - public NMSArmorStand spawnNMSArmorStand( - World world, double x, double y, double z, - StandardHologramLine parentHologramLine) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) world).getHandle(); - EntityNMSArmorStand armorStand = new EntityNMSArmorStand(nmsWorld, parentHologramLine, protocolPacketSettings); - armorStand.setLocationNMS(x, y, z); - addEntityToWorld(nmsWorld, armorStand); - return armorStand; - } - - 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); - final int chunkZ = MathHelper.floor(nmsEntity.locZ / 16.0); - - if (!nmsWorld.isChunkLoaded(chunkX, chunkZ)) { - // This should never happen - nmsEntity.dead = true; - throw new SpawnFailedException(SpawnFailedException.CHUNK_NOT_LOADED); - } - - nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity); - try { - REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity); - } catch (ReflectiveOperationException e) { - 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 NMSEntity; - } - - @Override - public NMSEntity getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - - if (nmsEntity instanceof NMSEntity) { - return (NMSEntity) nmsEntity; - } else { - return null; - } - } - - @Override - public NMSEntity getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - Entity nmsEntity = nmsWorld.getEntity(entityID); - - if (nmsEntity instanceof NMSEntity) { - return (NMSEntity) nmsEntity; - } else { - return null; - } - } - - @Override - public Object createCustomNameNMSObject(String customName) { - return EntityNMSArmorStand.createCustomNameNMSObject(customName); + public NMSPacketList createPacketList() { + return null; } } diff --git a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/CraftNMSArmorStand.java b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/CraftNMSArmorStand.java deleted file mode 100644 index 8cfd8b08..00000000 --- a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/CraftNMSArmorStand.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_15_R1; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_15_R1.CraftServer; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftArmorStand; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.ItemStack; -import org.bukkit.potion.PotionEffect; -import org.bukkit.util.EulerAngle; -import org.bukkit.util.Vector; - -import java.util.Collection; - -public class CraftNMSArmorStand extends CraftArmorStand { - - public CraftNMSArmorStand(CraftServer server, EntityNMSArmorStand entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // 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) {} - - // 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 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 setGliding(boolean gliding) {} - @Override public boolean setLeashHolder(Entity holder) { return false; } - @Override public void setSwimming(boolean swimming) {} - - // Methods from Entity class - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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) {} - - -} diff --git a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/CraftNMSItem.java b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/CraftNMSItem.java deleted file mode 100644 index b2b696c1..00000000 --- a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/CraftNMSItem.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_15_R1; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_15_R1.CraftServer; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftItem; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; - -public class CraftNMSItem extends CraftItem { - - public CraftNMSItem(CraftServer server, EntityNMSItem entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // Methods from Item class - @Override public void setItemStack(ItemStack stack) {} - @Override public void setPickupDelay(int delay) {} - - // Methods from Entity class - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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) {} - -} diff --git a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/CraftNMSSlime.java b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/CraftNMSSlime.java deleted file mode 100644 index e1b3676c..00000000 --- a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/CraftNMSSlime.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_15_R1; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_15_R1.CraftServer; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftSlime; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.loot.LootTable; -import org.bukkit.potion.PotionEffect; -import org.bukkit.util.Vector; - -import java.util.Collection; - -public class CraftNMSSlime extends CraftSlime { - - public CraftNMSSlime(CraftServer server, EntityNMSSlime entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // Methods from Slime class - @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) {} - - // 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 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 setGliding(boolean gliding) {} - @Override public boolean setLeashHolder(Entity holder) { return false; } - @Override public void setSwimming(boolean swimming) {} - - // Methods from Entity class - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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) {} - -} diff --git a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityNMSArmorStand.java b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityNMSArmorStand.java deleted file mode 100644 index b04a3105..00000000 --- a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityNMSArmorStand.java +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_15_R1; - -import me.filoghost.fcommons.Preconditions; -import me.filoghost.fcommons.Strings; -import me.filoghost.fcommons.reflection.ReflectField; -import me.filoghost.holographicdisplays.common.DebugLogger; -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.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.EntityTypes; -import net.minecraft.server.v1_15_R1.EnumHand; -import net.minecraft.server.v1_15_R1.EnumInteractionResult; -import net.minecraft.server.v1_15_R1.EnumItemSlot; -import net.minecraft.server.v1_15_R1.IChatBaseComponent; -import net.minecraft.server.v1_15_R1.ItemStack; -import net.minecraft.server.v1_15_R1.NBTTagCompound; -import net.minecraft.server.v1_15_R1.PacketPlayOutEntityTeleport; -import net.minecraft.server.v1_15_R1.SoundEffect; -import net.minecraft.server.v1_15_R1.Vec3D; -import net.minecraft.server.v1_15_R1.World; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_15_R1.util.CraftChatMessage; -import org.bukkit.entity.Player; - -import java.util.Objects; - -public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand { - - private static final ReflectField VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle"); - - private final StandardHologramLine parentHologramLine; - private final ProtocolPacketSettings protocolPacketSettings; - private final VersionNMSEntityHelper helper; - private CraftEntity customBukkitEntity; - private String customName; - - public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, ProtocolPacketSettings protocolPacketSettings) { - super(EntityTypes.ARMOR_STAND, world); - this.parentHologramLine = parentHologramLine; - this.protocolPacketSettings = protocolPacketSettings; - this.helper = new VersionNMSEntityHelper(this); - - super.setInvisible(true); - super.setSmall(true); - super.setArms(false); - super.setNoGravity(true); - super.setBasePlate(true); - super.setMarker(true); - super.collides = false; - super.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet - forceSetBoundingBox(new NullBoundingBox()); - } - - @Override - public void tick() { - // Disable normal ticking for this entity - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity - if (super.onGround) { - super.onGround = false; - } - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity - if (super.onGround) { - super.onGround = false; - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound save(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void f(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void a(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void setCustomName(IChatBaseComponent ichatbasecomponent) { - // Prevents changes to custom name - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Prevents changes to custom name visibility - } - - @Override - public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) { - // Prevent armor stand from being equipped - return EnumInteractionResult.PASS; - } - - @Override - public boolean a_(int i, ItemStack item) { - // Prevent armor stand from being equipped - return false; - } - - @Override - public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { - // Prevent armor stand from being equipped - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Prevent changes to bounding box - } - - public void forceSetBoundingBox(AxisAlignedBB boundingBox) { - super.a(boundingBox); - } - - @Override - public void a(SoundEffect soundeffect, float f, float f1) { - // Remove sounds - } - - @Override - public void setCustomNameNMS(String customName) { - if (Objects.equals(this.customName, customName)) { - return; - } - this.customName = customName; - super.setCustomName(createCustomNameNMSObject(customName)); - super.setCustomNameVisible(customName != null && !customName.isEmpty()); - } - - protected static IChatBaseComponent createCustomNameNMSObject(String customName) { - return CraftChatMessage.fromStringOrNull(Strings.truncate(customName, 300)); - } - - @Override - public String getCustomNameStringNMS() { - return this.customName; - } - - @Override - public IChatBaseComponent getCustomNameObjectNMS() { - return super.getCustomName(); - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public CraftEntity getBukkitEntity() { - if (customBukkitEntity == null) { - customBukkitEntity = new CraftNMSArmorStand(super.world.getServer(), this); - } - return customBukkitEntity; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - if (protocolPacketSettings.sendAccurateLocationPackets()) { - helper.broadcastPacket(new PacketPlayOutEntityTeleport(this)); - } - } - - @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(passengerEntity); - } catch (ReflectiveOperationException e) { - DebugLogger.cannotSetPassenger(e); - } - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - -} diff --git a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityNMSItem.java b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityNMSItem.java deleted file mode 100644 index 787e39c2..00000000 --- a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityNMSItem.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_15_R1; - -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; -import me.filoghost.holographicdisplays.common.nms.NMSCommons; -import me.filoghost.holographicdisplays.common.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.EntityHuman; -import net.minecraft.server.v1_15_R1.EntityItem; -import net.minecraft.server.v1_15_R1.EntityPlayer; -import net.minecraft.server.v1_15_R1.EntityTypes; -import net.minecraft.server.v1_15_R1.ItemStack; -import net.minecraft.server.v1_15_R1.NBTTagCompound; -import net.minecraft.server.v1_15_R1.NBTTagList; -import net.minecraft.server.v1_15_R1.NBTTagString; -import net.minecraft.server.v1_15_R1.World; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack; -import org.bukkit.entity.Player; - -public class EntityNMSItem extends EntityItem implements NMSItem { - - private final StandardItemLine parentHologramLine; - private final VersionNMSEntityHelper helper; - private CraftEntity customBukkitEntity; - - public EntityNMSItem(World world, StandardItemLine parentHologramLine) { - super(EntityTypes.ITEM, world); - this.parentHologramLine = parentHologramLine; - this.helper = new VersionNMSEntityHelper(this); - - super.pickupDelay = 32767; // Lock the item pickup delay, also prevents entities from picking up the item - } - - @Override - public void tick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - // Method called when a player is near - @Override - public void pickup(EntityHuman human) { - if (human.locY() < super.locY() - 1.5 || human.locY() > super.locY() + 1.0) { - // Too low or too high, it's a bit weird - return; - } - - if (human instanceof EntityPlayer) { - parentHologramLine.onPickup(((EntityPlayer) human).getBukkitEntity()); - // It is never added to the inventory - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound save(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void f(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void a(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public boolean isAlive() { - // This override prevents items from being picked up by hoppers (should have no side effects) - return false; - } - - @Override - public CraftEntity getBukkitEntity() { - if (customBukkitEntity == null) { - customBukkitEntity = new CraftNMSItem(super.world.getServer(), this); - } - return customBukkitEntity; - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - } - - @Override - public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) { - ItemStack newItem = CraftItemStack.asNMSCopy(stack); - - if (newItem == null || newItem == ItemStack.a) { // ItemStack.a is returned if the stack is not valid - newItem = new ItemStack(Blocks.BEDROCK); - } - - if (newItem.getTag() == null) { - newItem.setTag(new NBTTagCompound()); - } - NBTTagCompound display = newItem.getTag().getCompound("display"); // Returns a new NBTTagCompound if not existing - if (!newItem.getTag().hasKey("display")) { - newItem.getTag().set("display", display); - } - - NBTTagList tagList = new NBTTagList(); - tagList.add(NBTTagString.a(NMSCommons.ANTI_STACK_LORE)); - display.set("Lore", tagList); - - super.setItemStack(newItem); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - - @Override - public Object getRawItemStack() { - return super.getItemStack(); - } - -} diff --git a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityNMSSlime.java b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityNMSSlime.java deleted file mode 100644 index 0f4958da..00000000 --- a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityNMSSlime.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_15_R1; - -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.nms.entity.NMSSlime; -import net.minecraft.server.v1_15_R1.AxisAlignedBB; -import net.minecraft.server.v1_15_R1.DamageSource; -import net.minecraft.server.v1_15_R1.EntityDamageSource; -import net.minecraft.server.v1_15_R1.EntityPlayer; -import net.minecraft.server.v1_15_R1.EntitySlime; -import net.minecraft.server.v1_15_R1.EntityTypes; -import net.minecraft.server.v1_15_R1.IChatBaseComponent; -import net.minecraft.server.v1_15_R1.NBTTagCompound; -import net.minecraft.server.v1_15_R1.SoundEffect; -import net.minecraft.server.v1_15_R1.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.player.PlayerInteractEntityEvent; - -public class EntityNMSSlime extends EntitySlime implements NMSSlime { - - private final StandardHologramLine parentHologramLine; - private final VersionNMSEntityHelper helper; - private CraftEntity customBukkitEntity; - - public EntityNMSSlime(World world, StandardHologramLine parentHologramLine) { - super(EntityTypes.SLIME, world); - this.parentHologramLine = parentHologramLine; - this.helper = new VersionNMSEntityHelper(this); - - super.persistent = true; - super.collides = false; - super.a(0.0F, 0.0F); - super.setSize(1, false); - super.setInvisible(true); - forceSetBoundingBox(new NullBoundingBox()); - } - - @Override - public void tick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Prevent changes to bounding box - } - - public void forceSetBoundingBox(AxisAlignedBB boundingBox) { - super.a(boundingBox); - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound save(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void f(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void a(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean damageEntity(DamageSource damageSource, float amount) { - if (damageSource instanceof EntityDamageSource) { - EntityDamageSource entityDamageSource = (EntityDamageSource) damageSource; - if (entityDamageSource.getEntity() instanceof EntityPlayer) { - Player player = ((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(); - PlayerInteractEntityEvent event = new PlayerInteractEntityEvent(player, getBukkitEntity()); - Bukkit.getPluginManager().callEvent(event); // Bukkit takes care of the exceptions - } - } - return false; - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void setCustomName(IChatBaseComponent ichatbasecomponent) { - // Prevents changes to custom name - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Prevents changes to custom name visibility - } - - @Override - public void a(SoundEffect soundeffect, float f, float f1) { - // Remove sounds - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public CraftEntity getBukkitEntity() { - if (customBukkitEntity == null) { - customBukkitEntity = new CraftNMSSlime(super.world.getServer(), this); - } - return customBukkitEntity; - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - -} diff --git a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/NullBoundingBox.java b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/NullBoundingBox.java deleted file mode 100644 index c8856439..00000000 --- a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/NullBoundingBox.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_15_R1; - -import net.minecraft.server.v1_15_R1.AxisAlignedBB; -import net.minecraft.server.v1_15_R1.BlockPosition; -import net.minecraft.server.v1_15_R1.EnumDirection.EnumAxis; -import net.minecraft.server.v1_15_R1.Vec3D; - -public class NullBoundingBox extends AxisAlignedBB { - - public NullBoundingBox() { - super(0, 0, 0, 0, 0, 0); - } - - @Override - public double a() { - return 0.0; - } - - @Override - public AxisAlignedBB a(AxisAlignedBB arg0) { - return this; - } - - @Override - public AxisAlignedBB a(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public AxisAlignedBB grow(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public AxisAlignedBB shrink(double arg0) { - return this; - } - - @Override - public AxisAlignedBB a(BlockPosition arg0) { - return this; - } - - @Override - public boolean a(double arg0, double arg1, double arg2, double arg3, double arg4, double arg5) { - return false; - } - - @Override - public AxisAlignedBB g(double arg0) { - return this; - } - - @Override - public AxisAlignedBB a(Vec3D arg0) { - return this; - } - - @Override - public AxisAlignedBB b(AxisAlignedBB arg0) { - return this; - } - - @Override - public AxisAlignedBB b(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public boolean c(AxisAlignedBB arg0) { - return false; - } - - @Override - public AxisAlignedBB d(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public double a(EnumAxis arg0) { - return 0.0; - } - - @Override - public double b(EnumAxis arg0) { - return 0.0; - } - - @Override - public boolean e(double arg0, double arg1, double arg2) { - return false; - } - - @Override - public double b() { - return 0.0; - } - - @Override - public double c() { - return 0.0; - } - - @Override - public double d() { - return 0.0; - } - - @Override - public boolean c(Vec3D var0) { - return false; - } - - @Override - public Vec3D f() { - return Vec3D.a; - } - -} diff --git a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionNMSEntityHelper.java b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionNMSEntityHelper.java deleted file mode 100644 index 7df5782d..00000000 --- a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionNMSEntityHelper.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_15_R1; - -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntityHelper; -import net.minecraft.server.v1_15_R1.Entity; -import net.minecraft.server.v1_15_R1.Packet; -import net.minecraft.server.v1_15_R1.PlayerChunkMap.EntityTracker; -import net.minecraft.server.v1_15_R1.WorldServer; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; - -public class VersionNMSEntityHelper extends NMSEntityHelper { - - private final Entity entity; - - public VersionNMSEntityHelper(Entity entity) { - this.entity = entity; - } - - @Override - protected EntityTracker getTracker0() { - return ((WorldServer) entity.world).getChunkProvider().playerChunkMap.trackedEntities.get(entity.getId()); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - EntityTracker tracker = getTracker(); - if (tracker != null) { - return tracker.trackedPlayers.contains(((CraftPlayer) bukkitPlayer).getHandle()); - } else { - return false; - } - } - - public void broadcastPacket(Packet packet) { - EntityTracker tracker = getTracker(); - if (tracker != null) { - tracker.broadcast(packet); - } - } - -} diff --git a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionNMSManager.java b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionNMSManager.java index 706192db..334f592b 100644 --- a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionNMSManager.java +++ b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionNMSManager.java @@ -5,154 +5,20 @@ */ package me.filoghost.holographicdisplays.nms.v1_15_R1; -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.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; +import me.filoghost.holographicdisplays.common.nms.EntityID; import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; -import me.filoghost.holographicdisplays.common.nms.SpawnFailedException; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntity; -import me.filoghost.holographicdisplays.common.nms.entity.NMSItem; -import net.minecraft.server.v1_15_R1.Entity; -import net.minecraft.server.v1_15_R1.EntityTypes; -import net.minecraft.server.v1_15_R1.EnumCreatureType; -import net.minecraft.server.v1_15_R1.IRegistry; -import net.minecraft.server.v1_15_R1.MathHelper; -import net.minecraft.server.v1_15_R1.RegistryID; -import net.minecraft.server.v1_15_R1.RegistryMaterials; -import net.minecraft.server.v1_15_R1.WorldServer; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity; -import org.bukkit.inventory.ItemStack; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; public class VersionNMSManager implements NMSManager { - private static final ReflectField>> REGISTRY_ID_FIELD - = ReflectField.lookup(new ClassToken>>() {}, RegistryMaterials.class, "b"); - private static final ReflectField ID_TO_CLASS_MAP_FIELD - = ReflectField.lookup(Object[].class, RegistryID.class, "d"); - private static final ReflectMethod REGISTER_ENTITY_METHOD - = ReflectMethod.lookup(void.class, WorldServer.class, "registerEntity", Entity.class); - - private final ProtocolPacketSettings protocolPacketSettings; - - public VersionNMSManager(ProtocolPacketSettings protocolPacketSettings) { - this.protocolPacketSettings = protocolPacketSettings; + @Override + public EntityID newEntityID() { + return null; } @Override - public void setup() throws Exception { - registerCustomEntity(EntityNMSSlime.class, 55, 2.04f, 2.04f); - } - - public void registerCustomEntity(Class entityClass, int id, float sizeWidth, float sizeHeight) throws Exception { - // Use reflection to get the RegistryID of entities - RegistryID> registryID = REGISTRY_ID_FIELD.get(IRegistry.ENTITY_TYPE); - Object[] idToClassMap = ID_TO_CLASS_MAP_FIELD.get(registryID); - - // Save the the ID -> EntityTypes mapping before the registration - Object oldValue = idToClassMap[id]; - - // Register the EntityTypes object - registryID.a(EntityTypes.a.a(EnumCreatureType.MONSTER).a(sizeWidth, sizeHeight).b().a((String) null), id); - - // Restore the ID -> EntityTypes mapping - idToClassMap[id] = oldValue; - } - - @Override - public NMSItem spawnNMSItem( - World bukkitWorld, double x, double y, double z, - StandardItemLine parentHologramLine, - ItemStack stack) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSItem item = new EntityNMSItem(nmsWorld, parentHologramLine); - 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 parentHologramLine) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSSlime slime = new EntityNMSSlime(nmsWorld, parentHologramLine); - slime.setLocationNMS(x, y, z); - addEntityToWorld(nmsWorld, slime); - return slime; - } - - @Override - public NMSArmorStand spawnNMSArmorStand( - World world, double x, double y, double z, - StandardHologramLine parentHologramLine) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) world).getHandle(); - EntityNMSArmorStand armorStand = new EntityNMSArmorStand(nmsWorld, parentHologramLine, protocolPacketSettings); - armorStand.setLocationNMS(x, y, z); - addEntityToWorld(nmsWorld, armorStand); - return armorStand; - } - - 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); - final int chunkZ = MathHelper.floor(nmsEntity.locZ() / 16.0); - - if (!nmsWorld.isChunkLoaded(chunkX, chunkZ)) { - // This should never happen - nmsEntity.dead = true; - throw new SpawnFailedException(SpawnFailedException.CHUNK_NOT_LOADED); - } - - nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity); - try { - REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity); - } catch (ReflectiveOperationException e) { - 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 NMSEntity; - } - - @Override - public NMSEntity getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - - if (nmsEntity instanceof NMSEntity) { - return (NMSEntity) nmsEntity; - } else { - return null; - } - } - - @Override - public NMSEntity getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - Entity nmsEntity = nmsWorld.getEntity(entityID); - - if (nmsEntity instanceof NMSEntity) { - return (NMSEntity) nmsEntity; - } else { - return null; - } - } - - @Override - public Object createCustomNameNMSObject(String customName) { - return EntityNMSArmorStand.createCustomNameNMSObject(customName); + public NMSPacketList createPacketList() { + return null; } } diff --git a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/CraftNMSArmorStand.java b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/CraftNMSArmorStand.java deleted file mode 100644 index 4b2b8eb3..00000000 --- a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/CraftNMSArmorStand.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_16_R1; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_16_R1.CraftServer; -import org.bukkit.craftbukkit.v1_16_R1.entity.CraftArmorStand; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.ItemStack; -import org.bukkit.potion.PotionEffect; -import org.bukkit.util.EulerAngle; -import org.bukkit.util.Vector; - -import java.util.Collection; - -public class CraftNMSArmorStand extends CraftArmorStand { - - public CraftNMSArmorStand(CraftServer server, EntityNMSArmorStand entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // 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) {} - - // 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 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 setGliding(boolean gliding) {} - @Override public boolean setLeashHolder(Entity holder) { return false; } - @Override public void setSwimming(boolean swimming) {} - - // Methods from Entity class - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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) {} - - -} diff --git a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/CraftNMSItem.java b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/CraftNMSItem.java deleted file mode 100644 index 7d20041d..00000000 --- a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/CraftNMSItem.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_16_R1; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_16_R1.CraftServer; -import org.bukkit.craftbukkit.v1_16_R1.entity.CraftItem; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; - -public class CraftNMSItem extends CraftItem { - - public CraftNMSItem(CraftServer server, EntityNMSItem entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // Methods from Item class - @Override public void setItemStack(ItemStack stack) {} - @Override public void setPickupDelay(int delay) {} - - // Methods from Entity class - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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) {} - -} diff --git a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/CraftNMSSlime.java b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/CraftNMSSlime.java deleted file mode 100644 index 7f48e772..00000000 --- a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/CraftNMSSlime.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_16_R1; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_16_R1.CraftServer; -import org.bukkit.craftbukkit.v1_16_R1.entity.CraftSlime; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.loot.LootTable; -import org.bukkit.potion.PotionEffect; -import org.bukkit.util.Vector; - -import java.util.Collection; - -public class CraftNMSSlime extends CraftSlime { - - public CraftNMSSlime(CraftServer server, EntityNMSSlime entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // Methods from Slime class - @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) {} - - // 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 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 setGliding(boolean gliding) {} - @Override public boolean setLeashHolder(Entity holder) { return false; } - @Override public void setSwimming(boolean swimming) {} - - // Methods from Entity class - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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) {} - -} diff --git a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityNMSArmorStand.java b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityNMSArmorStand.java deleted file mode 100644 index 56945590..00000000 --- a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityNMSArmorStand.java +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_16_R1; - -import me.filoghost.fcommons.Preconditions; -import me.filoghost.fcommons.Strings; -import me.filoghost.fcommons.reflection.ReflectField; -import me.filoghost.holographicdisplays.common.DebugLogger; -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.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.EntityTypes; -import net.minecraft.server.v1_16_R1.EnumHand; -import net.minecraft.server.v1_16_R1.EnumInteractionResult; -import net.minecraft.server.v1_16_R1.EnumItemSlot; -import net.minecraft.server.v1_16_R1.IChatBaseComponent; -import net.minecraft.server.v1_16_R1.ItemStack; -import net.minecraft.server.v1_16_R1.NBTTagCompound; -import net.minecraft.server.v1_16_R1.PacketPlayOutEntityTeleport; -import net.minecraft.server.v1_16_R1.SoundEffect; -import net.minecraft.server.v1_16_R1.Vec3D; -import net.minecraft.server.v1_16_R1.World; -import org.bukkit.craftbukkit.v1_16_R1.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_16_R1.util.CraftChatMessage; -import org.bukkit.entity.Player; - -import java.util.Objects; - -public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand { - - private static final ReflectField VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle"); - - private final StandardHologramLine parentHologramLine; - private final ProtocolPacketSettings protocolPacketSettings; - private final VersionNMSEntityHelper helper; - private CraftEntity customBukkitEntity; - private String customName; - - public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, ProtocolPacketSettings protocolPacketSettings) { - super(EntityTypes.ARMOR_STAND, world); - this.parentHologramLine = parentHologramLine; - this.protocolPacketSettings = protocolPacketSettings; - this.helper = new VersionNMSEntityHelper(this); - - super.setInvisible(true); - super.setSmall(true); - super.setArms(false); - super.setNoGravity(true); - super.setBasePlate(true); - super.setMarker(true); - super.collides = false; - super.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet - forceSetBoundingBox(new NullBoundingBox()); - } - - @Override - public void tick() { - // Disable normal ticking for this entity - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity - if (super.onGround) { - super.onGround = false; - } - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity - if (super.onGround) { - super.onGround = false; - } - } - - @Override - public void saveData(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean a_(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound save(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void load(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void loadData(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void setCustomName(IChatBaseComponent ichatbasecomponent) { - // Prevents changes to custom name - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Prevents changes to custom name visibility - } - - @Override - public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) { - // Prevent armor stand from being equipped - return EnumInteractionResult.PASS; - } - - @Override - public boolean a_(int i, ItemStack item) { - // Prevent armor stand from being equipped - return false; - } - - @Override - public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { - // Prevent armor stand from being equipped - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Prevent changes to bounding box - } - - public void forceSetBoundingBox(AxisAlignedBB boundingBox) { - super.a(boundingBox); - } - - @Override - public void playSound(SoundEffect soundeffect, float f, float f1) { - // Remove sounds - } - - @Override - public void setCustomNameNMS(String customName) { - if (Objects.equals(this.customName, customName)) { - return; - } - this.customName = customName; - super.setCustomName(createCustomNameNMSObject(customName)); - super.setCustomNameVisible(customName != null && !customName.isEmpty()); - } - - protected static IChatBaseComponent createCustomNameNMSObject(String customName) { - return CraftChatMessage.fromStringOrNull(Strings.truncate(customName, 300)); - } - - @Override - public String getCustomNameStringNMS() { - return this.customName; - } - - @Override - public IChatBaseComponent getCustomNameObjectNMS() { - return super.getCustomName(); - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public CraftEntity getBukkitEntity() { - if (customBukkitEntity == null) { - customBukkitEntity = new CraftNMSArmorStand(super.world.getServer(), this); - } - return customBukkitEntity; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - if (protocolPacketSettings.sendAccurateLocationPackets()) { - helper.broadcastPacket(new PacketPlayOutEntityTeleport(this)); - } - } - - @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(passengerEntity); - } catch (ReflectiveOperationException e) { - DebugLogger.cannotSetPassenger(e); - } - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - -} diff --git a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityNMSItem.java b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityNMSItem.java deleted file mode 100644 index 23b3e3b8..00000000 --- a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityNMSItem.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_16_R1; - -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; -import me.filoghost.holographicdisplays.common.nms.NMSCommons; -import me.filoghost.holographicdisplays.common.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.EntityHuman; -import net.minecraft.server.v1_16_R1.EntityItem; -import net.minecraft.server.v1_16_R1.EntityPlayer; -import net.minecraft.server.v1_16_R1.EntityTypes; -import net.minecraft.server.v1_16_R1.ItemStack; -import net.minecraft.server.v1_16_R1.NBTTagCompound; -import net.minecraft.server.v1_16_R1.NBTTagList; -import net.minecraft.server.v1_16_R1.NBTTagString; -import net.minecraft.server.v1_16_R1.World; -import org.bukkit.craftbukkit.v1_16_R1.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack; -import org.bukkit.entity.Player; - -public class EntityNMSItem extends EntityItem implements NMSItem { - - private final StandardItemLine parentHologramLine; - private final VersionNMSEntityHelper helper; - private CraftEntity customBukkitEntity; - - public EntityNMSItem(World world, StandardItemLine parentHologramLine) { - super(EntityTypes.ITEM, world); - this.parentHologramLine = parentHologramLine; - this.helper = new VersionNMSEntityHelper(this); - - super.pickupDelay = 32767; // Lock the item pickup delay, also prevents entities from picking up the item - } - - @Override - public void tick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - // Method called when a player is near - @Override - public void pickup(EntityHuman human) { - if (human.locY() < super.locY() - 1.5 || human.locY() > super.locY() + 1.0) { - // Too low or too high, it's a bit weird - return; - } - - if (human instanceof EntityPlayer) { - parentHologramLine.onPickup(((EntityPlayer) human).getBukkitEntity()); - // It is never added to the inventory - } - } - - @Override - public void saveData(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean a_(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound save(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void load(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void loadData(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public boolean isAlive() { - // This override prevents items from being picked up by hoppers (should have no side effects) - return false; - } - - @Override - public CraftEntity getBukkitEntity() { - if (customBukkitEntity == null) { - customBukkitEntity = new CraftNMSItem(super.world.getServer(), this); - } - return customBukkitEntity; - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - } - - @Override - public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) { - ItemStack newItem = CraftItemStack.asNMSCopy(stack); - - if (newItem == null || newItem == ItemStack.b) { // ItemStack.b is returned if the stack is not valid - newItem = new ItemStack(Blocks.BEDROCK); - } - - if (newItem.getTag() == null) { - newItem.setTag(new NBTTagCompound()); - } - NBTTagCompound display = newItem.getTag().getCompound("display"); // Returns a new NBTTagCompound if not existing - if (!newItem.getTag().hasKey("display")) { - newItem.getTag().set("display", display); - } - - NBTTagList tagList = new NBTTagList(); - tagList.add(NBTTagString.a(NMSCommons.ANTI_STACK_LORE)); - display.set("Lore", tagList); - - super.setItemStack(newItem); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - - @Override - public Object getRawItemStack() { - return super.getItemStack(); - } - -} diff --git a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityNMSSlime.java b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityNMSSlime.java deleted file mode 100644 index db7dbf16..00000000 --- a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityNMSSlime.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_16_R1; - -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.nms.entity.NMSSlime; -import net.minecraft.server.v1_16_R1.AxisAlignedBB; -import net.minecraft.server.v1_16_R1.DamageSource; -import net.minecraft.server.v1_16_R1.EntityDamageSource; -import net.minecraft.server.v1_16_R1.EntityPlayer; -import net.minecraft.server.v1_16_R1.EntitySlime; -import net.minecraft.server.v1_16_R1.EntityTypes; -import net.minecraft.server.v1_16_R1.IChatBaseComponent; -import net.minecraft.server.v1_16_R1.NBTTagCompound; -import net.minecraft.server.v1_16_R1.SoundEffect; -import net.minecraft.server.v1_16_R1.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_16_R1.entity.CraftEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.player.PlayerInteractEntityEvent; - -public class EntityNMSSlime extends EntitySlime implements NMSSlime { - - private final StandardHologramLine parentHologramLine; - private final VersionNMSEntityHelper helper; - private CraftEntity customBukkitEntity; - - public EntityNMSSlime(World world, StandardHologramLine parentHologramLine) { - super(EntityTypes.SLIME, world); - this.parentHologramLine = parentHologramLine; - this.helper = new VersionNMSEntityHelper(this); - - super.persistent = true; - super.collides = false; - super.a(0.0F, 0.0F); - super.setSize(1, false); - super.setInvisible(true); - forceSetBoundingBox(new NullBoundingBox()); - } - - @Override - public void tick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Prevent changes to bounding box - } - - public void forceSetBoundingBox(AxisAlignedBB boundingBox) { - super.a(boundingBox); - } - - @Override - public void saveData(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean a_(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound save(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void load(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void loadData(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean damageEntity(DamageSource damageSource, float amount) { - if (damageSource instanceof EntityDamageSource) { - EntityDamageSource entityDamageSource = (EntityDamageSource) damageSource; - if (entityDamageSource.getEntity() instanceof EntityPlayer) { - Player player = ((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(); - PlayerInteractEntityEvent event = new PlayerInteractEntityEvent(player, getBukkitEntity()); - Bukkit.getPluginManager().callEvent(event); // Bukkit takes care of the exceptions - } - } - return false; - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void setCustomName(IChatBaseComponent ichatbasecomponent) { - // Prevents changes to custom name - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Prevents changes to custom name visibility - } - - @Override - public void playSound(SoundEffect soundeffect, float f, float f1) { - // Remove sounds - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public CraftEntity getBukkitEntity() { - if (customBukkitEntity == null) { - customBukkitEntity = new CraftNMSSlime(super.world.getServer(), this); - } - return customBukkitEntity; - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - -} diff --git a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/NullBoundingBox.java b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/NullBoundingBox.java deleted file mode 100644 index 0761918b..00000000 --- a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/NullBoundingBox.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_16_R1; - -import net.minecraft.server.v1_16_R1.AxisAlignedBB; -import net.minecraft.server.v1_16_R1.BlockPosition; -import net.minecraft.server.v1_16_R1.EnumDirection.EnumAxis; -import net.minecraft.server.v1_16_R1.Vec3D; - -public class NullBoundingBox extends AxisAlignedBB { - - public NullBoundingBox() { - super(0, 0, 0, 0, 0, 0); - } - - @Override - public double a() { - return 0.0; - } - - @Override - public AxisAlignedBB a(AxisAlignedBB arg0) { - return this; - } - - @Override - public AxisAlignedBB a(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public AxisAlignedBB grow(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public AxisAlignedBB shrink(double arg0) { - return this; - } - - @Override - public AxisAlignedBB a(BlockPosition arg0) { - return this; - } - - @Override - public boolean a(double arg0, double arg1, double arg2, double arg3, double arg4, double arg5) { - return false; - } - - @Override - public AxisAlignedBB g(double arg0) { - return this; - } - - @Override - public AxisAlignedBB b(Vec3D arg0) { - return this; - } - - @Override - public AxisAlignedBB b(AxisAlignedBB arg0) { - return this; - } - - @Override - public AxisAlignedBB b(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public boolean c(AxisAlignedBB arg0) { - return false; - } - - @Override - public AxisAlignedBB d(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public double a(EnumAxis arg0) { - return 0.0; - } - - @Override - public double b(EnumAxis arg0) { - return 0.0; - } - - @Override - public boolean e(double arg0, double arg1, double arg2) { - return false; - } - - @Override - public double b() { - return 0.0; - } - - @Override - public double c() { - return 0.0; - } - - @Override - public double d() { - return 0.0; - } - - @Override - public boolean d(Vec3D var0) { - return false; - } - - @Override - public Vec3D f() { - return Vec3D.a; - } - -} diff --git a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionNMSEntityHelper.java b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionNMSEntityHelper.java deleted file mode 100644 index a9a808e0..00000000 --- a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionNMSEntityHelper.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_16_R1; - -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntityHelper; -import net.minecraft.server.v1_16_R1.Entity; -import net.minecraft.server.v1_16_R1.Packet; -import net.minecraft.server.v1_16_R1.PlayerChunkMap.EntityTracker; -import net.minecraft.server.v1_16_R1.WorldServer; -import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; - -public class VersionNMSEntityHelper extends NMSEntityHelper { - - private final Entity entity; - - public VersionNMSEntityHelper(Entity entity) { - this.entity = entity; - } - - @Override - protected EntityTracker getTracker0() { - return ((WorldServer) entity.world).getChunkProvider().playerChunkMap.trackedEntities.get(entity.getId()); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - EntityTracker tracker = getTracker(); - if (tracker != null) { - return tracker.trackedPlayers.contains(((CraftPlayer) bukkitPlayer).getHandle()); - } else { - return false; - } - } - - public void broadcastPacket(Packet packet) { - EntityTracker tracker = getTracker(); - if (tracker != null) { - tracker.broadcast(packet); - } - } - -} diff --git a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionNMSManager.java b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionNMSManager.java index a149ed6b..d3608cc0 100644 --- a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionNMSManager.java +++ b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionNMSManager.java @@ -5,154 +5,20 @@ */ package me.filoghost.holographicdisplays.nms.v1_16_R1; -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.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; +import me.filoghost.holographicdisplays.common.nms.EntityID; import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; -import me.filoghost.holographicdisplays.common.nms.SpawnFailedException; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntity; -import me.filoghost.holographicdisplays.common.nms.entity.NMSItem; -import net.minecraft.server.v1_16_R1.Entity; -import net.minecraft.server.v1_16_R1.EntityTypes; -import net.minecraft.server.v1_16_R1.EnumCreatureType; -import net.minecraft.server.v1_16_R1.IRegistry; -import net.minecraft.server.v1_16_R1.MathHelper; -import net.minecraft.server.v1_16_R1.RegistryID; -import net.minecraft.server.v1_16_R1.RegistryMaterials; -import net.minecraft.server.v1_16_R1.WorldServer; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_16_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_16_R1.entity.CraftEntity; -import org.bukkit.inventory.ItemStack; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; public class VersionNMSManager implements NMSManager { - private static final ReflectField>> REGISTRY_ID_FIELD - = ReflectField.lookup(new ClassToken>>() {}, RegistryMaterials.class, "b"); - private static final ReflectField ID_TO_CLASS_MAP_FIELD - = ReflectField.lookup(Object[].class, RegistryID.class, "d"); - private static final ReflectMethod REGISTER_ENTITY_METHOD - = ReflectMethod.lookup(void.class, WorldServer.class, "registerEntity", Entity.class); - - private final ProtocolPacketSettings protocolPacketSettings; - - public VersionNMSManager(ProtocolPacketSettings protocolPacketSettings) { - this.protocolPacketSettings = protocolPacketSettings; + @Override + public EntityID newEntityID() { + return null; } @Override - public void setup() throws Exception { - registerCustomEntity(EntityNMSSlime.class, 55, 2.04f, 2.04f); - } - - public void registerCustomEntity(Class entityClass, int id, float sizeWidth, float sizeHeight) throws Exception { - // Use reflection to get the RegistryID of entities - RegistryID> registryID = REGISTRY_ID_FIELD.get(IRegistry.ENTITY_TYPE); - Object[] idToClassMap = ID_TO_CLASS_MAP_FIELD.get(registryID); - - // Save the the ID -> EntityTypes mapping before the registration - Object oldValue = idToClassMap[id]; - - // Register the EntityTypes object - registryID.a(EntityTypes.Builder.a(EnumCreatureType.MONSTER).a(sizeWidth, sizeHeight).b().a((String) null), id); - - // Restore the ID -> EntityTypes mapping - idToClassMap[id] = oldValue; - } - - @Override - public NMSItem spawnNMSItem( - World bukkitWorld, double x, double y, double z, - StandardItemLine parentHologramLine, - ItemStack stack) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSItem item = new EntityNMSItem(nmsWorld, parentHologramLine); - 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 parentHologramLine) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSSlime slime = new EntityNMSSlime(nmsWorld, parentHologramLine); - slime.setLocationNMS(x, y, z); - addEntityToWorld(nmsWorld, slime); - return slime; - } - - @Override - public NMSArmorStand spawnNMSArmorStand( - World world, double x, double y, double z, - StandardHologramLine parentHologramLine) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) world).getHandle(); - EntityNMSArmorStand armorStand = new EntityNMSArmorStand(nmsWorld, parentHologramLine, protocolPacketSettings); - armorStand.setLocationNMS(x, y, z); - addEntityToWorld(nmsWorld, armorStand); - return armorStand; - } - - 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); - final int chunkZ = MathHelper.floor(nmsEntity.locZ() / 16.0); - - if (!nmsWorld.isChunkLoaded(chunkX, chunkZ)) { - // This should never happen - nmsEntity.dead = true; - throw new SpawnFailedException(SpawnFailedException.CHUNK_NOT_LOADED); - } - - nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity); - try { - REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity); - } catch (ReflectiveOperationException e) { - 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 NMSEntity; - } - - @Override - public NMSEntity getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - - if (nmsEntity instanceof NMSEntity) { - return (NMSEntity) nmsEntity; - } else { - return null; - } - } - - @Override - public NMSEntity getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - Entity nmsEntity = nmsWorld.getEntity(entityID); - - if (nmsEntity instanceof NMSEntity) { - return (NMSEntity) nmsEntity; - } else { - return null; - } - } - - @Override - public Object createCustomNameNMSObject(String customName) { - return EntityNMSArmorStand.createCustomNameNMSObject(customName); + public NMSPacketList createPacketList() { + return null; } } diff --git a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/CraftNMSArmorStand.java b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/CraftNMSArmorStand.java deleted file mode 100644 index 9aaa37b6..00000000 --- a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/CraftNMSArmorStand.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_16_R2; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_16_R2.CraftServer; -import org.bukkit.craftbukkit.v1_16_R2.entity.CraftArmorStand; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.ItemStack; -import org.bukkit.potion.PotionEffect; -import org.bukkit.util.EulerAngle; -import org.bukkit.util.Vector; - -import java.util.Collection; - -public class CraftNMSArmorStand extends CraftArmorStand { - - public CraftNMSArmorStand(CraftServer server, EntityNMSArmorStand entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // 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) {} - - // 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 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 setGliding(boolean gliding) {} - @Override public boolean setLeashHolder(Entity holder) { return false; } - @Override public void setSwimming(boolean swimming) {} - - // Methods from Entity class - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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) {} - - -} diff --git a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/CraftNMSItem.java b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/CraftNMSItem.java deleted file mode 100644 index 67eab596..00000000 --- a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/CraftNMSItem.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_16_R2; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_16_R2.CraftServer; -import org.bukkit.craftbukkit.v1_16_R2.entity.CraftItem; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; - -public class CraftNMSItem extends CraftItem { - - public CraftNMSItem(CraftServer server, EntityNMSItem entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // Methods from Item class - @Override public void setItemStack(ItemStack stack) {} - @Override public void setPickupDelay(int delay) {} - - // Methods from Entity class - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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) {} - -} diff --git a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/CraftNMSSlime.java b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/CraftNMSSlime.java deleted file mode 100644 index 9e47b5cc..00000000 --- a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/CraftNMSSlime.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_16_R2; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_16_R2.CraftServer; -import org.bukkit.craftbukkit.v1_16_R2.entity.CraftSlime; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.loot.LootTable; -import org.bukkit.potion.PotionEffect; -import org.bukkit.util.Vector; - -import java.util.Collection; - -public class CraftNMSSlime extends CraftSlime { - - public CraftNMSSlime(CraftServer server, EntityNMSSlime entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // Methods from Slime class - @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) {} - - // 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 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 setGliding(boolean gliding) {} - @Override public boolean setLeashHolder(Entity holder) { return false; } - @Override public void setSwimming(boolean swimming) {} - - // Methods from Entity class - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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) {} - -} diff --git a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityNMSArmorStand.java b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityNMSArmorStand.java deleted file mode 100644 index a0175f56..00000000 --- a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityNMSArmorStand.java +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_16_R2; - -import me.filoghost.fcommons.Preconditions; -import me.filoghost.fcommons.Strings; -import me.filoghost.fcommons.reflection.ReflectField; -import me.filoghost.holographicdisplays.common.DebugLogger; -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.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.EntityTypes; -import net.minecraft.server.v1_16_R2.EnumHand; -import net.minecraft.server.v1_16_R2.EnumInteractionResult; -import net.minecraft.server.v1_16_R2.EnumItemSlot; -import net.minecraft.server.v1_16_R2.IChatBaseComponent; -import net.minecraft.server.v1_16_R2.ItemStack; -import net.minecraft.server.v1_16_R2.NBTTagCompound; -import net.minecraft.server.v1_16_R2.PacketPlayOutEntityTeleport; -import net.minecraft.server.v1_16_R2.SoundEffect; -import net.minecraft.server.v1_16_R2.Vec3D; -import net.minecraft.server.v1_16_R2.World; -import org.bukkit.craftbukkit.v1_16_R2.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_16_R2.util.CraftChatMessage; -import org.bukkit.entity.Player; - -import java.util.Objects; - -public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand { - - private static final ReflectField VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle"); - - private final StandardHologramLine parentHologramLine; - private final ProtocolPacketSettings protocolPacketSettings; - private final VersionNMSEntityHelper helper; - private CraftEntity customBukkitEntity; - private String customName; - - public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, ProtocolPacketSettings protocolPacketSettings) { - super(EntityTypes.ARMOR_STAND, world); - this.parentHologramLine = parentHologramLine; - this.protocolPacketSettings = protocolPacketSettings; - this.helper = new VersionNMSEntityHelper(this); - - super.setInvisible(true); - super.setSmall(true); - super.setArms(false); - super.setNoGravity(true); - super.setBasePlate(true); - super.setMarker(true); - super.collides = false; - super.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet - forceSetBoundingBox(new NullBoundingBox()); - } - - @Override - public void tick() { - // Disable normal ticking for this entity - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity - if (super.onGround) { - super.onGround = false; - } - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity - if (super.onGround) { - super.onGround = false; - } - } - - @Override - public void saveData(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean a_(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound save(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void load(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void loadData(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void setCustomName(IChatBaseComponent ichatbasecomponent) { - // Prevents changes to custom name - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Prevents changes to custom name visibility - } - - @Override - public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) { - // Prevent armor stand from being equipped - return EnumInteractionResult.PASS; - } - - @Override - public boolean a_(int i, ItemStack item) { - // Prevent armor stand from being equipped - return false; - } - - @Override - public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { - // Prevent armor stand from being equipped - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Prevent changes to bounding box - } - - public void forceSetBoundingBox(AxisAlignedBB boundingBox) { - super.a(boundingBox); - } - - @Override - public void playSound(SoundEffect soundeffect, float f, float f1) { - // Remove sounds - } - - @Override - public void setCustomNameNMS(String customName) { - if (Objects.equals(this.customName, customName)) { - return; - } - this.customName = customName; - super.setCustomName(createCustomNameNMSObject(customName)); - super.setCustomNameVisible(customName != null && !customName.isEmpty()); - } - - protected static IChatBaseComponent createCustomNameNMSObject(String customName) { - return CraftChatMessage.fromStringOrNull(Strings.truncate(customName, 300)); - } - - @Override - public String getCustomNameStringNMS() { - return this.customName; - } - - @Override - public IChatBaseComponent getCustomNameObjectNMS() { - return super.getCustomName(); - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public CraftEntity getBukkitEntity() { - if (customBukkitEntity == null) { - customBukkitEntity = new CraftNMSArmorStand(super.world.getServer(), this); - } - return customBukkitEntity; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - if (protocolPacketSettings.sendAccurateLocationPackets()) { - helper.broadcastPacket(new PacketPlayOutEntityTeleport(this)); - } - } - - @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(passengerEntity); - } catch (ReflectiveOperationException e) { - DebugLogger.cannotSetPassenger(e); - } - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - -} diff --git a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityNMSItem.java b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityNMSItem.java deleted file mode 100644 index 99681cec..00000000 --- a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityNMSItem.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_16_R2; - -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; -import me.filoghost.holographicdisplays.common.nms.NMSCommons; -import me.filoghost.holographicdisplays.common.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.EntityHuman; -import net.minecraft.server.v1_16_R2.EntityItem; -import net.minecraft.server.v1_16_R2.EntityPlayer; -import net.minecraft.server.v1_16_R2.EntityTypes; -import net.minecraft.server.v1_16_R2.ItemStack; -import net.minecraft.server.v1_16_R2.NBTTagCompound; -import net.minecraft.server.v1_16_R2.NBTTagList; -import net.minecraft.server.v1_16_R2.NBTTagString; -import net.minecraft.server.v1_16_R2.World; -import org.bukkit.craftbukkit.v1_16_R2.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack; -import org.bukkit.entity.Player; - -public class EntityNMSItem extends EntityItem implements NMSItem { - - private final StandardItemLine parentHologramLine; - private final VersionNMSEntityHelper helper; - private CraftEntity customBukkitEntity; - - public EntityNMSItem(World world, StandardItemLine parentHologramLine) { - super(EntityTypes.ITEM, world); - this.parentHologramLine = parentHologramLine; - this.helper = new VersionNMSEntityHelper(this); - - super.pickupDelay = 32767; // Lock the item pickup delay, also prevents entities from picking up the item - } - - @Override - public void tick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - // Method called when a player is near - @Override - public void pickup(EntityHuman human) { - if (human.locY() < super.locY() - 1.5 || human.locY() > super.locY() + 1.0) { - // Too low or too high, it's a bit weird - return; - } - - if (human instanceof EntityPlayer) { - parentHologramLine.onPickup(((EntityPlayer) human).getBukkitEntity()); - // It is never added to the inventory - } - } - - @Override - public void saveData(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean a_(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound save(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void load(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void loadData(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public boolean isAlive() { - // This override prevents items from being picked up by hoppers (should have no side effects) - return false; - } - - @Override - public CraftEntity getBukkitEntity() { - if (customBukkitEntity == null) { - customBukkitEntity = new CraftNMSItem(super.world.getServer(), this); - } - return customBukkitEntity; - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - } - - @Override - public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) { - ItemStack newItem = CraftItemStack.asNMSCopy(stack); - - if (newItem == null || newItem == ItemStack.b) { // ItemStack.b is returned if the stack is not valid - newItem = new ItemStack(Blocks.BEDROCK); - } - - if (newItem.getTag() == null) { - newItem.setTag(new NBTTagCompound()); - } - NBTTagCompound display = newItem.getTag().getCompound("display"); // Returns a new NBTTagCompound if not existing - if (!newItem.getTag().hasKey("display")) { - newItem.getTag().set("display", display); - } - - NBTTagList tagList = new NBTTagList(); - tagList.add(NBTTagString.a(NMSCommons.ANTI_STACK_LORE)); - display.set("Lore", tagList); - - super.setItemStack(newItem); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - - @Override - public Object getRawItemStack() { - return super.getItemStack(); - } - -} diff --git a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityNMSSlime.java b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityNMSSlime.java deleted file mode 100644 index 1952e4ec..00000000 --- a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityNMSSlime.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_16_R2; - -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.nms.entity.NMSSlime; -import net.minecraft.server.v1_16_R2.AxisAlignedBB; -import net.minecraft.server.v1_16_R2.DamageSource; -import net.minecraft.server.v1_16_R2.EntityDamageSource; -import net.minecraft.server.v1_16_R2.EntityPlayer; -import net.minecraft.server.v1_16_R2.EntitySlime; -import net.minecraft.server.v1_16_R2.EntityTypes; -import net.minecraft.server.v1_16_R2.IChatBaseComponent; -import net.minecraft.server.v1_16_R2.NBTTagCompound; -import net.minecraft.server.v1_16_R2.SoundEffect; -import net.minecraft.server.v1_16_R2.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_16_R2.entity.CraftEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.player.PlayerInteractEntityEvent; - -public class EntityNMSSlime extends EntitySlime implements NMSSlime { - - private final StandardHologramLine parentHologramLine; - private final VersionNMSEntityHelper helper; - private CraftEntity customBukkitEntity; - - public EntityNMSSlime(World world, StandardHologramLine parentHologramLine) { - super(EntityTypes.SLIME, world); - this.parentHologramLine = parentHologramLine; - this.helper = new VersionNMSEntityHelper(this); - - super.persistent = true; - super.collides = false; - super.a(0.0F, 0.0F); - super.setSize(1, false); - super.setInvisible(true); - forceSetBoundingBox(new NullBoundingBox()); - } - - @Override - public void tick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Prevent changes to bounding box - } - - public void forceSetBoundingBox(AxisAlignedBB boundingBox) { - super.a(boundingBox); - } - - @Override - public void saveData(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean a_(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound save(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void load(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void loadData(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean damageEntity(DamageSource damageSource, float amount) { - if (damageSource instanceof EntityDamageSource) { - EntityDamageSource entityDamageSource = (EntityDamageSource) damageSource; - if (entityDamageSource.getEntity() instanceof EntityPlayer) { - Player player = ((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(); - PlayerInteractEntityEvent event = new PlayerInteractEntityEvent(player, getBukkitEntity()); - Bukkit.getPluginManager().callEvent(event); // Bukkit takes care of the exceptions - } - } - return false; - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void setCustomName(IChatBaseComponent ichatbasecomponent) { - // Prevents changes to custom name - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Prevents changes to custom name visibility - } - - @Override - public void playSound(SoundEffect soundeffect, float f, float f1) { - // Remove sounds - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public CraftEntity getBukkitEntity() { - if (customBukkitEntity == null) { - customBukkitEntity = new CraftNMSSlime(super.world.getServer(), this); - } - return customBukkitEntity; - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - -} diff --git a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/NullBoundingBox.java b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/NullBoundingBox.java deleted file mode 100644 index 64b72cfe..00000000 --- a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/NullBoundingBox.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_16_R2; - -import net.minecraft.server.v1_16_R2.AxisAlignedBB; -import net.minecraft.server.v1_16_R2.BlockPosition; -import net.minecraft.server.v1_16_R2.EnumDirection.EnumAxis; -import net.minecraft.server.v1_16_R2.Vec3D; - -public class NullBoundingBox extends AxisAlignedBB { - - public NullBoundingBox() { - super(0, 0, 0, 0, 0, 0); - } - - @Override - public double a() { - return 0.0; - } - - @Override - public AxisAlignedBB a(AxisAlignedBB arg0) { - return this; - } - - @Override - public AxisAlignedBB a(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public AxisAlignedBB grow(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public AxisAlignedBB shrink(double arg0) { - return this; - } - - @Override - public AxisAlignedBB a(BlockPosition arg0) { - return this; - } - - @Override - public boolean a(double arg0, double arg1, double arg2, double arg3, double arg4, double arg5) { - return false; - } - - @Override - public AxisAlignedBB g(double arg0) { - return this; - } - - @Override - public AxisAlignedBB b(Vec3D arg0) { - return this; - } - - @Override - public AxisAlignedBB b(AxisAlignedBB arg0) { - return this; - } - - @Override - public AxisAlignedBB b(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public boolean c(AxisAlignedBB arg0) { - return false; - } - - @Override - public AxisAlignedBB d(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public double a(EnumAxis arg0) { - return 0.0; - } - - @Override - public double b(EnumAxis arg0) { - return 0.0; - } - - @Override - public boolean e(double arg0, double arg1, double arg2) { - return false; - } - - @Override - public double b() { - return 0.0; - } - - @Override - public double c() { - return 0.0; - } - - @Override - public double d() { - return 0.0; - } - - @Override - public boolean d(Vec3D var0) { - return false; - } - - @Override - public Vec3D f() { - return Vec3D.a; - } - -} diff --git a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionNMSEntityHelper.java b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionNMSEntityHelper.java deleted file mode 100644 index de26754d..00000000 --- a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionNMSEntityHelper.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_16_R2; - -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntityHelper; -import net.minecraft.server.v1_16_R2.Entity; -import net.minecraft.server.v1_16_R2.Packet; -import net.minecraft.server.v1_16_R2.PlayerChunkMap.EntityTracker; -import net.minecraft.server.v1_16_R2.WorldServer; -import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer; -import org.bukkit.entity.Player; - -public class VersionNMSEntityHelper extends NMSEntityHelper { - - private final Entity entity; - - public VersionNMSEntityHelper(Entity entity) { - this.entity = entity; - } - - @Override - protected EntityTracker getTracker0() { - return ((WorldServer) entity.world).getChunkProvider().playerChunkMap.trackedEntities.get(entity.getId()); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - EntityTracker tracker = getTracker(); - if (tracker != null) { - return tracker.trackedPlayers.contains(((CraftPlayer) bukkitPlayer).getHandle()); - } else { - return false; - } - } - - public void broadcastPacket(Packet packet) { - EntityTracker tracker = getTracker(); - if (tracker != null) { - tracker.broadcast(packet); - } - } - -} diff --git a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionNMSManager.java b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionNMSManager.java index 719da9da..6deb1812 100644 --- a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionNMSManager.java +++ b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionNMSManager.java @@ -5,145 +5,20 @@ */ package me.filoghost.holographicdisplays.nms.v1_16_R2; -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.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; +import me.filoghost.holographicdisplays.common.nms.EntityID; import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; -import me.filoghost.holographicdisplays.common.nms.SpawnFailedException; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntity; -import me.filoghost.holographicdisplays.common.nms.entity.NMSItem; -import net.minecraft.server.v1_16_R2.Entity; -import net.minecraft.server.v1_16_R2.EntityTypes; -import net.minecraft.server.v1_16_R2.EnumCreatureType; -import net.minecraft.server.v1_16_R2.IRegistry; -import net.minecraft.server.v1_16_R2.MathHelper; -import net.minecraft.server.v1_16_R2.RegistryMaterials; -import net.minecraft.server.v1_16_R2.WorldServer; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_16_R2.CraftWorld; -import org.bukkit.craftbukkit.v1_16_R2.entity.CraftEntity; -import org.bukkit.inventory.ItemStack; - -import java.util.Map; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; public class VersionNMSManager implements NMSManager { - private static final ReflectField, Integer>> REGISTRY_TO_ID_FIELD - = ReflectField.lookup(new ClassToken, Integer>>() {}, RegistryMaterials.class, "bg"); - private static final ReflectMethod REGISTER_ENTITY_METHOD - = ReflectMethod.lookup(void.class, WorldServer.class, "registerEntity", Entity.class); - - private final ProtocolPacketSettings protocolPacketSettings; - - public VersionNMSManager(ProtocolPacketSettings protocolPacketSettings) { - this.protocolPacketSettings = protocolPacketSettings; + @Override + public EntityID newEntityID() { + return null; } @Override - public void setup() throws Exception { - registerCustomEntity(EntityNMSSlime.class, 55, 2.04f, 2.04f); - } - - public void registerCustomEntity(Class entityClass, int id, float sizeWidth, float sizeHeight) throws Exception { - // Use reflection to map the custom entity to the correct ID - Map, Integer> entityTypesToId = REGISTRY_TO_ID_FIELD.get(IRegistry.ENTITY_TYPE); - EntityTypes customEntityTypes = EntityTypes.Builder.a(EnumCreatureType.MONSTER).a(sizeWidth, sizeHeight).b().a((String) null); - entityTypesToId.put(customEntityTypes, id); - } - - @Override - public NMSItem spawnNMSItem( - World bukkitWorld, double x, double y, double z, - StandardItemLine parentHologramLine, - ItemStack stack) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSItem item = new EntityNMSItem(nmsWorld, parentHologramLine); - 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 parentHologramLine) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSSlime slime = new EntityNMSSlime(nmsWorld, parentHologramLine); - slime.setLocationNMS(x, y, z); - addEntityToWorld(nmsWorld, slime); - return slime; - } - - @Override - public NMSArmorStand spawnNMSArmorStand( - World world, double x, double y, double z, - StandardHologramLine parentHologramLine) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) world).getHandle(); - EntityNMSArmorStand armorStand = new EntityNMSArmorStand(nmsWorld, parentHologramLine, protocolPacketSettings); - armorStand.setLocationNMS(x, y, z); - addEntityToWorld(nmsWorld, armorStand); - return armorStand; - } - - 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); - final int chunkZ = MathHelper.floor(nmsEntity.locZ() / 16.0); - - if (!nmsWorld.isChunkLoaded(chunkX, chunkZ)) { - // This should never happen - nmsEntity.dead = true; - throw new SpawnFailedException(SpawnFailedException.CHUNK_NOT_LOADED); - } - - nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity); - try { - REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity); - } catch (ReflectiveOperationException e) { - 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 NMSEntity; - } - - @Override - public NMSEntity getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - - if (nmsEntity instanceof NMSEntity) { - return (NMSEntity) nmsEntity; - } else { - return null; - } - } - - @Override - public NMSEntity getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - Entity nmsEntity = nmsWorld.getEntity(entityID); - - if (nmsEntity instanceof NMSEntity) { - return (NMSEntity) nmsEntity; - } else { - return null; - } - } - - @Override - public Object createCustomNameNMSObject(String customName) { - return EntityNMSArmorStand.createCustomNameNMSObject(customName); + public NMSPacketList createPacketList() { + return null; } } diff --git a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/CraftNMSArmorStand.java b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/CraftNMSArmorStand.java deleted file mode 100644 index e79a066d..00000000 --- a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/CraftNMSArmorStand.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_16_R3; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_16_R3.CraftServer; -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftArmorStand; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.ItemStack; -import org.bukkit.potion.PotionEffect; -import org.bukkit.util.EulerAngle; -import org.bukkit.util.Vector; - -import java.util.Collection; - -public class CraftNMSArmorStand extends CraftArmorStand { - - public CraftNMSArmorStand(CraftServer server, EntityNMSArmorStand entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // 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) {} - - // 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 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 setGliding(boolean gliding) {} - @Override public boolean setLeashHolder(Entity holder) { return false; } - @Override public void setSwimming(boolean swimming) {} - - // Methods from Entity class - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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) {} - - -} diff --git a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/CraftNMSItem.java b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/CraftNMSItem.java deleted file mode 100644 index bd849c52..00000000 --- a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/CraftNMSItem.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_16_R3; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_16_R3.CraftServer; -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftItem; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; - -public class CraftNMSItem extends CraftItem { - - public CraftNMSItem(CraftServer server, EntityNMSItem entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // Methods from Item class - @Override public void setItemStack(ItemStack stack) {} - @Override public void setPickupDelay(int delay) {} - - // Methods from Entity class - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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) {} - -} diff --git a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/CraftNMSSlime.java b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/CraftNMSSlime.java deleted file mode 100644 index 302f1410..00000000 --- a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/CraftNMSSlime.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_16_R3; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_16_R3.CraftServer; -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftSlime; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.loot.LootTable; -import org.bukkit.potion.PotionEffect; -import org.bukkit.util.Vector; - -import java.util.Collection; - -public class CraftNMSSlime extends CraftSlime { - - public CraftNMSSlime(CraftServer server, EntityNMSSlime entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // Methods from Slime class - @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) {} - - // 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 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 setGliding(boolean gliding) {} - @Override public boolean setLeashHolder(Entity holder) { return false; } - @Override public void setSwimming(boolean swimming) {} - - // Methods from Entity class - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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) {} - -} diff --git a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityNMSArmorStand.java b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityNMSArmorStand.java deleted file mode 100644 index 59b939f6..00000000 --- a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityNMSArmorStand.java +++ /dev/null @@ -1,269 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_16_R3; - -import me.filoghost.fcommons.Preconditions; -import me.filoghost.fcommons.Strings; -import me.filoghost.fcommons.reflection.ReflectField; -import me.filoghost.holographicdisplays.common.DebugLogger; -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.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.EntityTypes; -import net.minecraft.server.v1_16_R3.EnumHand; -import net.minecraft.server.v1_16_R3.EnumInteractionResult; -import net.minecraft.server.v1_16_R3.EnumItemSlot; -import net.minecraft.server.v1_16_R3.IChatBaseComponent; -import net.minecraft.server.v1_16_R3.ItemStack; -import net.minecraft.server.v1_16_R3.NBTTagCompound; -import net.minecraft.server.v1_16_R3.PacketPlayOutEntityTeleport; -import net.minecraft.server.v1_16_R3.SoundEffect; -import net.minecraft.server.v1_16_R3.Vec3D; -import net.minecraft.server.v1_16_R3.World; -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_16_R3.util.CraftChatMessage; -import org.bukkit.entity.Player; - -import java.util.Objects; - -public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand { - - private static final ReflectField VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "vehicle"); - - private final StandardHologramLine parentHologramLine; - private final ProtocolPacketSettings protocolPacketSettings; - private final VersionNMSEntityHelper helper; - private CraftEntity customBukkitEntity; - private String customName; - - public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, ProtocolPacketSettings protocolPacketSettings) { - super(EntityTypes.ARMOR_STAND, world); - this.parentHologramLine = parentHologramLine; - this.protocolPacketSettings = protocolPacketSettings; - this.helper = new VersionNMSEntityHelper(this); - - super.setInvisible(true); - super.setSmall(true); - super.setArms(false); - super.setNoGravity(true); - super.setBasePlate(true); - super.setMarker(true); - super.collides = false; - super.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet - forceSetBoundingBox(new NullBoundingBox()); - } - - @Override - public void tick() { - // Disable normal ticking for this entity - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity - if (super.onGround) { - super.onGround = false; - } - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity - if (super.onGround) { - super.onGround = false; - } - } - - @Override - public void saveData(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean a_(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound save(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void load(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void loadData(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void setCustomName(IChatBaseComponent ichatbasecomponent) { - // Prevents changes to custom name - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Prevents changes to custom name visibility - } - - @Override - public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) { - // Prevent armor stand from being equipped - return EnumInteractionResult.PASS; - } - - @Override - public boolean a_(int i, ItemStack item) { - // Prevent armor stand from being equipped - return false; - } - - @Override - public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { - // Prevent armor stand from being equipped - } - - @Override - public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack, boolean silent) { - // Prevent armor stand from being equipped - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Prevent changes to bounding box - } - - public void forceSetBoundingBox(AxisAlignedBB boundingBox) { - super.a(boundingBox); - } - - @Override - public void playSound(SoundEffect soundeffect, float f, float f1) { - // Remove sounds - } - - @Override - public void setCustomNameNMS(String customName) { - if (Objects.equals(this.customName, customName)) { - return; - } - this.customName = customName; - super.setCustomName(createCustomNameNMSObject(customName)); - super.setCustomNameVisible(customName != null && !customName.isEmpty()); - } - - protected static IChatBaseComponent createCustomNameNMSObject(String customName) { - return CraftChatMessage.fromStringOrNull(Strings.truncate(customName, 300)); - } - - @Override - public String getCustomNameStringNMS() { - return this.customName; - } - - @Override - public IChatBaseComponent getCustomNameObjectNMS() { - return super.getCustomName(); - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public CraftEntity getBukkitEntity() { - if (customBukkitEntity == null) { - customBukkitEntity = new CraftNMSArmorStand(super.world.getServer(), this); - } - return customBukkitEntity; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - if (protocolPacketSettings.sendAccurateLocationPackets()) { - helper.broadcastPacket(new PacketPlayOutEntityTeleport(this)); - } - } - - @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(passengerEntity); - } catch (ReflectiveOperationException e) { - DebugLogger.cannotSetPassenger(e); - } - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - -} diff --git a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityNMSItem.java b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityNMSItem.java deleted file mode 100644 index 9af0803e..00000000 --- a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityNMSItem.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_16_R3; - -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; -import me.filoghost.holographicdisplays.common.nms.NMSCommons; -import me.filoghost.holographicdisplays.common.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.EntityHuman; -import net.minecraft.server.v1_16_R3.EntityItem; -import net.minecraft.server.v1_16_R3.EntityPlayer; -import net.minecraft.server.v1_16_R3.EntityTypes; -import net.minecraft.server.v1_16_R3.ItemStack; -import net.minecraft.server.v1_16_R3.NBTTagCompound; -import net.minecraft.server.v1_16_R3.NBTTagList; -import net.minecraft.server.v1_16_R3.NBTTagString; -import net.minecraft.server.v1_16_R3.World; -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack; -import org.bukkit.entity.Player; - -public class EntityNMSItem extends EntityItem implements NMSItem { - - private final StandardItemLine parentHologramLine; - private final VersionNMSEntityHelper helper; - private CraftEntity customBukkitEntity; - - public EntityNMSItem(World world, StandardItemLine parentHologramLine) { - super(EntityTypes.ITEM, world); - this.parentHologramLine = parentHologramLine; - this.helper = new VersionNMSEntityHelper(this); - - super.pickupDelay = 32767; // Lock the item pickup delay, also prevents entities from picking up the item - } - - @Override - public void tick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - // Method called when a player is near - @Override - public void pickup(EntityHuman human) { - if (human.locY() < super.locY() - 1.5 || human.locY() > super.locY() + 1.0) { - // Too low or too high, it's a bit weird - return; - } - - if (human instanceof EntityPlayer) { - parentHologramLine.onPickup(((EntityPlayer) human).getBukkitEntity()); - // It is never added to the inventory - } - } - - @Override - public void saveData(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean a_(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound save(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void load(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void loadData(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public boolean isAlive() { - // This override prevents items from being picked up by hoppers (should have no side effects) - return false; - } - - @Override - public CraftEntity getBukkitEntity() { - if (customBukkitEntity == null) { - customBukkitEntity = new CraftNMSItem(super.world.getServer(), this); - } - return customBukkitEntity; - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - } - - @Override - public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) { - ItemStack newItem = CraftItemStack.asNMSCopy(stack); - - if (newItem == null || newItem == ItemStack.b) { // ItemStack.b is returned if the stack is not valid - newItem = new ItemStack(Blocks.BEDROCK); - } - - if (newItem.getTag() == null) { - newItem.setTag(new NBTTagCompound()); - } - NBTTagCompound display = newItem.getTag().getCompound("display"); // Returns a new NBTTagCompound if not existing - if (!newItem.getTag().hasKey("display")) { - newItem.getTag().set("display", display); - } - - NBTTagList tagList = new NBTTagList(); - tagList.add(NBTTagString.a(NMSCommons.ANTI_STACK_LORE)); - display.set("Lore", tagList); - - super.setItemStack(newItem); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - - @Override - public Object getRawItemStack() { - return super.getItemStack(); - } - -} diff --git a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityNMSSlime.java b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityNMSSlime.java deleted file mode 100644 index 7d8ec1f5..00000000 --- a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityNMSSlime.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_16_R3; - -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.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.EntityDamageSource; -import net.minecraft.server.v1_16_R3.EntityPlayer; -import net.minecraft.server.v1_16_R3.EntitySlime; -import net.minecraft.server.v1_16_R3.EntityTypes; -import net.minecraft.server.v1_16_R3.IChatBaseComponent; -import net.minecraft.server.v1_16_R3.NBTTagCompound; -import net.minecraft.server.v1_16_R3.SoundEffect; -import net.minecraft.server.v1_16_R3.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.player.PlayerInteractEntityEvent; - -public class EntityNMSSlime extends EntitySlime implements NMSSlime { - - private final StandardHologramLine parentHologramLine; - private final VersionNMSEntityHelper helper; - private CraftEntity customBukkitEntity; - - public EntityNMSSlime(World world, StandardHologramLine parentHologramLine) { - super(EntityTypes.SLIME, world); - this.parentHologramLine = parentHologramLine; - this.helper = new VersionNMSEntityHelper(this); - - super.persistent = true; - super.collides = false; - super.a(0.0F, 0.0F); - super.setSize(1, false); - super.setInvisible(true); - forceSetBoundingBox(new NullBoundingBox()); - } - - @Override - public void tick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Prevent changes to bounding box - } - - public void forceSetBoundingBox(AxisAlignedBB boundingBox) { - super.a(boundingBox); - } - - @Override - public void saveData(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean a_(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound save(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void load(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void loadData(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean damageEntity(DamageSource damageSource, float amount) { - if (damageSource instanceof EntityDamageSource) { - EntityDamageSource entityDamageSource = (EntityDamageSource) damageSource; - if (entityDamageSource.getEntity() instanceof EntityPlayer) { - Player player = ((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(); - PlayerInteractEntityEvent event = new PlayerInteractEntityEvent(player, getBukkitEntity()); - Bukkit.getPluginManager().callEvent(event); // Bukkit takes care of the exceptions - } - } - return false; - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void setCustomName(IChatBaseComponent ichatbasecomponent) { - // Prevents changes to custom name - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Prevents changes to custom name visibility - } - - @Override - public void playSound(SoundEffect soundeffect, float f, float f1) { - // Remove sounds - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public CraftEntity getBukkitEntity() { - if (customBukkitEntity == null) { - customBukkitEntity = new CraftNMSSlime(super.world.getServer(), this); - } - return customBukkitEntity; - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - -} diff --git a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/NullBoundingBox.java b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/NullBoundingBox.java deleted file mode 100644 index ac2763b6..00000000 --- a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/NullBoundingBox.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_16_R3; - -import net.minecraft.server.v1_16_R3.AxisAlignedBB; -import net.minecraft.server.v1_16_R3.BlockPosition; -import net.minecraft.server.v1_16_R3.EnumDirection.EnumAxis; -import net.minecraft.server.v1_16_R3.Vec3D; - -public class NullBoundingBox extends AxisAlignedBB { - - public NullBoundingBox() { - super(0, 0, 0, 0, 0, 0); - } - - @Override - public double a() { - return 0.0; - } - - @Override - public AxisAlignedBB a(AxisAlignedBB arg0) { - return this; - } - - @Override - public AxisAlignedBB a(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public AxisAlignedBB grow(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public AxisAlignedBB shrink(double arg0) { - return this; - } - - @Override - public AxisAlignedBB a(BlockPosition arg0) { - return this; - } - - @Override - public boolean a(double arg0, double arg1, double arg2, double arg3, double arg4, double arg5) { - return false; - } - - @Override - public AxisAlignedBB g(double arg0) { - return this; - } - - @Override - public AxisAlignedBB b(Vec3D arg0) { - return this; - } - - @Override - public AxisAlignedBB b(AxisAlignedBB arg0) { - return this; - } - - @Override - public AxisAlignedBB b(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public boolean c(AxisAlignedBB arg0) { - return false; - } - - @Override - public AxisAlignedBB d(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public double a(EnumAxis arg0) { - return 0.0; - } - - @Override - public double b(EnumAxis arg0) { - return 0.0; - } - - @Override - public boolean e(double arg0, double arg1, double arg2) { - return false; - } - - @Override - public double b() { - return 0.0; - } - - @Override - public double c() { - return 0.0; - } - - @Override - public double d() { - return 0.0; - } - - @Override - public boolean d(Vec3D var0) { - return false; - } - - @Override - public Vec3D f() { - return Vec3D.ORIGIN; - } - -} diff --git a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionNMSEntityHelper.java b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionNMSEntityHelper.java deleted file mode 100644 index 965d208f..00000000 --- a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionNMSEntityHelper.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_16_R3; - -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntityHelper; -import net.minecraft.server.v1_16_R3.Entity; -import net.minecraft.server.v1_16_R3.Packet; -import net.minecraft.server.v1_16_R3.PlayerChunkMap.EntityTracker; -import net.minecraft.server.v1_16_R3.WorldServer; -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer; -import org.bukkit.entity.Player; - -public class VersionNMSEntityHelper extends NMSEntityHelper { - - private final Entity entity; - - public VersionNMSEntityHelper(Entity entity) { - this.entity = entity; - } - - @Override - protected EntityTracker getTracker0() { - return ((WorldServer) entity.world).getChunkProvider().playerChunkMap.trackedEntities.get(entity.getId()); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - EntityTracker tracker = getTracker(); - if (tracker != null) { - return tracker.trackedPlayers.contains(((CraftPlayer) bukkitPlayer).getHandle()); - } else { - return false; - } - } - - public void broadcastPacket(Packet packet) { - EntityTracker tracker = getTracker(); - if (tracker != null) { - tracker.broadcast(packet); - } - } - -} diff --git a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionNMSManager.java b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionNMSManager.java index 72e5d541..658fd1f8 100644 --- a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionNMSManager.java +++ b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionNMSManager.java @@ -5,145 +5,20 @@ */ package me.filoghost.holographicdisplays.nms.v1_16_R3; -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.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; +import me.filoghost.holographicdisplays.common.nms.EntityID; import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; -import me.filoghost.holographicdisplays.common.nms.SpawnFailedException; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntity; -import me.filoghost.holographicdisplays.common.nms.entity.NMSItem; -import net.minecraft.server.v1_16_R3.Entity; -import net.minecraft.server.v1_16_R3.EntityTypes; -import net.minecraft.server.v1_16_R3.EnumCreatureType; -import net.minecraft.server.v1_16_R3.IRegistry; -import net.minecraft.server.v1_16_R3.MathHelper; -import net.minecraft.server.v1_16_R3.RegistryMaterials; -import net.minecraft.server.v1_16_R3.WorldServer; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_16_R3.CraftWorld; -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity; -import org.bukkit.inventory.ItemStack; - -import java.util.Map; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; public class VersionNMSManager implements NMSManager { - private static final ReflectField, Integer>> REGISTRY_TO_ID_FIELD - = ReflectField.lookup(new ClassToken, Integer>>() {}, RegistryMaterials.class, "bg"); - private static final ReflectMethod REGISTER_ENTITY_METHOD - = ReflectMethod.lookup(void.class, WorldServer.class, "registerEntity", Entity.class); - - private final ProtocolPacketSettings protocolPacketSettings; - - public VersionNMSManager(ProtocolPacketSettings protocolPacketSettings) { - this.protocolPacketSettings = protocolPacketSettings; + @Override + public EntityID newEntityID() { + return null; } @Override - public void setup() throws Exception { - registerCustomEntity(EntityNMSSlime.class, 55, 2.04f, 2.04f); - } - - public void registerCustomEntity(Class entityClass, int id, float sizeWidth, float sizeHeight) throws Exception { - // Use reflection to map the custom entity to the correct ID - Map, Integer> entityTypesToId = REGISTRY_TO_ID_FIELD.get(IRegistry.ENTITY_TYPE); - EntityTypes customEntityTypes = EntityTypes.Builder.a(EnumCreatureType.MONSTER).a(sizeWidth, sizeHeight).b().a((String) null); - entityTypesToId.put(customEntityTypes, id); - } - - @Override - public NMSItem spawnNMSItem( - World bukkitWorld, double x, double y, double z, - StandardItemLine parentHologramLine, - ItemStack stack) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSItem item = new EntityNMSItem(nmsWorld, parentHologramLine); - 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 parentHologramLine) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSSlime slime = new EntityNMSSlime(nmsWorld, parentHologramLine); - slime.setLocationNMS(x, y, z); - addEntityToWorld(nmsWorld, slime); - return slime; - } - - @Override - public NMSArmorStand spawnNMSArmorStand( - World world, double x, double y, double z, - StandardHologramLine parentHologramLine) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) world).getHandle(); - EntityNMSArmorStand armorStand = new EntityNMSArmorStand(nmsWorld, parentHologramLine, protocolPacketSettings); - armorStand.setLocationNMS(x, y, z); - addEntityToWorld(nmsWorld, armorStand); - return armorStand; - } - - 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); - final int chunkZ = MathHelper.floor(nmsEntity.locZ() / 16.0); - - if (!nmsWorld.isChunkLoaded(chunkX, chunkZ)) { - // This should never happen - nmsEntity.dead = true; - throw new SpawnFailedException(SpawnFailedException.CHUNK_NOT_LOADED); - } - - nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity); - try { - REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity); - } catch (ReflectiveOperationException e) { - 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 NMSEntity; - } - - @Override - public NMSEntity getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - - if (nmsEntity instanceof NMSEntity) { - return (NMSEntity) nmsEntity; - } else { - return null; - } - } - - @Override - public NMSEntity getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - Entity nmsEntity = nmsWorld.getEntity(entityID); - - if (nmsEntity instanceof NMSEntity) { - return (NMSEntity) nmsEntity; - } else { - return null; - } - } - - @Override - public Object createCustomNameNMSObject(String customName) { - return EntityNMSArmorStand.createCustomNameNMSObject(customName); + public NMSPacketList createPacketList() { + return null; } } diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/CraftNMSArmorStand.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/CraftNMSArmorStand.java deleted file mode 100644 index f66b0897..00000000 --- a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/CraftNMSArmorStand.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_17_R1; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_17_R1.CraftServer; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftArmorStand; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.ItemStack; -import org.bukkit.potion.PotionEffect; -import org.bukkit.util.EulerAngle; -import org.bukkit.util.Vector; - -import java.util.Collection; - -public class CraftNMSArmorStand extends CraftArmorStand { - - public CraftNMSArmorStand(CraftServer server, EntityNMSArmorStand entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // 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 addEquipmentLock(EquipmentSlot equipmentSlot, LockType lockType) {} - @Override public void removeEquipmentLock(EquipmentSlot equipmentSlot, LockType lockType) {} - - // 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 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 setGliding(boolean gliding) {} - @Override public boolean setLeashHolder(Entity holder) { return false; } - @Override public void setSwimming(boolean swimming) {} - @Override public void setInvisible(boolean invisible) {} - - // Methods from Entity class - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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 boolean addPassenger(Entity passenger) { return false; } - @Override public boolean removePassenger(Entity passenger) { return false; } - -} diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/CraftNMSItem.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/CraftNMSItem.java deleted file mode 100644 index 7c87c3e7..00000000 --- a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/CraftNMSItem.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_17_R1; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_17_R1.CraftServer; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftItem; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; - -public class CraftNMSItem extends CraftItem { - - public CraftNMSItem(CraftServer server, EntityNMSItem entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // Methods from Item class - @Override public void setItemStack(ItemStack stack) {} - @Override public void setPickupDelay(int delay) {} - - // Methods from Entity class - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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 boolean addPassenger(Entity passenger) { return false; } - @Override public boolean removePassenger(Entity passenger) { return false; } - -} diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/CraftNMSSlime.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/CraftNMSSlime.java deleted file mode 100644 index 124cb22d..00000000 --- a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/CraftNMSSlime.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_17_R1; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_17_R1.CraftServer; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftSlime; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.loot.LootTable; -import org.bukkit.potion.PotionEffect; -import org.bukkit.util.Vector; - -import java.util.Collection; - -public class CraftNMSSlime extends CraftSlime { - - public CraftNMSSlime(CraftServer server, EntityNMSSlime entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // Methods from Slime class - @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) {} - - // 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 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 setGliding(boolean gliding) {} - @Override public boolean setLeashHolder(Entity holder) { return false; } - @Override public void setSwimming(boolean swimming) {} - @Override public void setInvisible(boolean invisible) {} - - // Methods from Entity class - @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 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 setLastDamageCause(EntityDamageEvent event) {} - @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 boolean addPassenger(Entity passenger) { return false; } - @Override public boolean removePassenger(Entity passenger) { return false; } - -} diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/DataWatcherEntry.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/DataWatcherEntry.java new file mode 100644 index 00000000..f023848c --- /dev/null +++ b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/DataWatcherEntry.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_17_R1; + +class DataWatcherEntry { + + private final DataWatcherKey key; + private final T value; + + DataWatcherEntry(DataWatcherKey key, T value) { + this.key = key; + this.value = value; + } + + DataWatcherKey getKey() { + return key; + } + + T getValue() { + return value; + } + +} diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/DataWatcherKey.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/DataWatcherKey.java new file mode 100644 index 00000000..be0f809a --- /dev/null +++ b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/DataWatcherKey.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_17_R1; + +import io.netty.handler.codec.EncoderException; +import net.minecraft.network.chat.IChatBaseComponent; +import net.minecraft.network.syncher.DataWatcherRegistry; +import net.minecraft.network.syncher.DataWatcherSerializer; +import net.minecraft.world.item.ItemStack; + +import java.util.Optional; + +class DataWatcherKey { + + private static final DataWatcherSerializer BYTE_SERIALIZER = DataWatcherRegistry.a; + private static final DataWatcherSerializer BOOLEAN_SERIALIZER = DataWatcherRegistry.i; + private static final DataWatcherSerializer ITEM_STACK_SERIALIZER = DataWatcherRegistry.g; + private static final DataWatcherSerializer> OPTIONAL_CHAT_COMPONENT_SERIALIZER = DataWatcherRegistry.f; + + static DataWatcherKey ENTITY_STATUS = new DataWatcherKey<>(0, BYTE_SERIALIZER); + static DataWatcherKey> CUSTOM_NAME = new DataWatcherKey<>(2, OPTIONAL_CHAT_COMPONENT_SERIALIZER); + static DataWatcherKey CUSTOM_NAME_VISIBILITY = new DataWatcherKey<>(3, BOOLEAN_SERIALIZER); + static DataWatcherKey ITEM_STACK = new DataWatcherKey<>(8, ITEM_STACK_SERIALIZER); + static DataWatcherKey ARMOR_STAND_STATUS = new DataWatcherKey<>(15, BYTE_SERIALIZER); + + private final int keyIndex; + private final DataWatcherSerializer serializer; + private final int serializerTypeID; + + private DataWatcherKey(int keyIndex, DataWatcherSerializer serializer) { + this.keyIndex = keyIndex; + this.serializer = serializer; + this.serializerTypeID = DataWatcherRegistry.b(serializer); + if (serializerTypeID < 0) { + throw new EncoderException("Could not find serializer ID of " + serializer); + } + } + + int getKeyIndex() { + return keyIndex; + } + + DataWatcherSerializer getSerializer() { + return serializer; + } + + int getSerializerTypeID() { + return serializerTypeID; + } + +} diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityDestroyNMSPacket.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityDestroyNMSPacket.java new file mode 100644 index 00000000..5fee2e8c --- /dev/null +++ b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityDestroyNMSPacket.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_17_R1; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy; + +class EntityDestroyNMSPacket extends VersionNMSPacket { + + private final Packet rawPacket; + + EntityDestroyNMSPacket(EntityID entityID) { + PacketByteBuffer packetByteBuffer = PacketByteBuffer.get(); + + packetByteBuffer.writeVarInt(entityID.getNumericID()); + + this.rawPacket = new PacketPlayOutEntityDestroy(packetByteBuffer); + } + + @Override + Packet getRawPacket() { + return rawPacket; + } + +} diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityListDestroyNMSPacket.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityListDestroyNMSPacket.java new file mode 100644 index 00000000..dc59f7f4 --- /dev/null +++ b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityListDestroyNMSPacket.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_17_R1; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy; +import org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.IntArrayList; + +class EntityListDestroyNMSPacket extends VersionNMSPacket { + + private final Packet rawPacket; + + EntityListDestroyNMSPacket(EntityID... entityIDs) { + PacketByteBuffer packetByteBuffer = PacketByteBuffer.get(); + + IntArrayList entityIDsList = new IntArrayList(entityIDs.length); + for (EntityID entityID : entityIDs) { + entityIDsList.add(entityID.getNumericID()); + } + packetByteBuffer.writeIntList(entityIDsList); + + this.rawPacket = new PacketPlayOutEntityDestroy(packetByteBuffer); + } + + @Override + Packet getRawPacket() { + return rawPacket; + } + +} diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityLivingSpawnNMSPacket.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityLivingSpawnNMSPacket.java new file mode 100644 index 00000000..daf4dfdb --- /dev/null +++ b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityLivingSpawnNMSPacket.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_17_R1; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.game.PacketPlayOutSpawnEntityLiving; + +class EntityLivingSpawnNMSPacket extends VersionNMSPacket { + + private final Packet rawPacket; + + EntityLivingSpawnNMSPacket(EntityID entityID, int entityTypeID, double locationX, double locationY, double locationZ) { + PacketByteBuffer packetByteBuffer = PacketByteBuffer.get(); + + packetByteBuffer.writeVarInt(entityID.getNumericID()); + packetByteBuffer.writeUUID(entityID.getUUID()); + packetByteBuffer.writeVarInt(entityTypeID); + + // Position + packetByteBuffer.writeDouble(locationX); + packetByteBuffer.writeDouble(locationY); + packetByteBuffer.writeDouble(locationZ); + + // Rotation + packetByteBuffer.writeByte(0); + packetByteBuffer.writeByte(0); + + // Head rotation + packetByteBuffer.writeByte(0); + + // Velocity + packetByteBuffer.writeShort(0); + packetByteBuffer.writeShort(0); + packetByteBuffer.writeShort(0); + + this.rawPacket = new PacketPlayOutSpawnEntityLiving(packetByteBuffer); + } + + @Override + Packet getRawPacket() { + return rawPacket; + } + +} diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityMetadataNMSPacket.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityMetadataNMSPacket.java new file mode 100644 index 00000000..2d882984 --- /dev/null +++ b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityMetadataNMSPacket.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_17_R1; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata; + +class EntityMetadataNMSPacket extends VersionNMSPacket { + + private final Packet rawPacket; + + EntityMetadataNMSPacket(EntityID entityID, DataWatcherEntry... dataWatcherEntries) { + PacketByteBuffer packetByteBuffer = PacketByteBuffer.get(); + + packetByteBuffer.writeVarInt(entityID.getNumericID()); + packetByteBuffer.writeDataWatcherEntries(dataWatcherEntries); + + this.rawPacket = new PacketPlayOutEntityMetadata(packetByteBuffer); + } + + @Override + Packet getRawPacket() { + return rawPacket; + } + +} diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityMountNMSPacket.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityMountNMSPacket.java new file mode 100644 index 00000000..3ab915e0 --- /dev/null +++ b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityMountNMSPacket.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_17_R1; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.game.PacketPlayOutMount; + +class EntityMountNMSPacket extends VersionNMSPacket { + + private final Packet rawPacket; + + EntityMountNMSPacket(EntityID vehicleEntityID, EntityID passengerEntityID) { + PacketByteBuffer packetByteBuffer = PacketByteBuffer.get(); + + packetByteBuffer.writeVarInt(vehicleEntityID.getNumericID()); + packetByteBuffer.writeIntArray(passengerEntityID.getNumericID()); + + this.rawPacket = new PacketPlayOutMount(packetByteBuffer); + } + + @Override + Packet getRawPacket() { + return rawPacket; + } + +} diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityNMSArmorStand.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityNMSArmorStand.java deleted file mode 100644 index f6cebeee..00000000 --- a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityNMSArmorStand.java +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_17_R1; - -import com.google.common.collect.ImmutableList; -import me.filoghost.fcommons.Preconditions; -import me.filoghost.fcommons.Strings; -import me.filoghost.fcommons.reflection.ReflectField; -import me.filoghost.holographicdisplays.common.DebugLogger; -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntity; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.chat.IChatBaseComponent; -import net.minecraft.network.protocol.game.PacketPlayOutEntityTeleport; -import net.minecraft.sounds.SoundEffect; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.damagesource.DamageSource; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityTypes; -import net.minecraft.world.entity.EnumItemSlot; -import net.minecraft.world.entity.decoration.EntityArmorStand; -import net.minecraft.world.entity.player.EntityHuman; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.World; -import net.minecraft.world.phys.AxisAlignedBB; -import net.minecraft.world.phys.Vec3D; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_17_R1.util.CraftChatMessage; -import org.bukkit.entity.Player; - -import java.util.Objects; - -public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand { - - private static final ReflectField VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "au"); - - private final StandardHologramLine parentHologramLine; - private final ProtocolPacketSettings protocolPacketSettings; - private final VersionNMSEntityHelper helper; - private CraftEntity customBukkitEntity; - private String customName; - - public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, ProtocolPacketSettings protocolPacketSettings) { - super(EntityTypes.c /* ARMOR_STAND */, world); - this.parentHologramLine = parentHologramLine; - this.protocolPacketSettings = protocolPacketSettings; - this.helper = new VersionNMSEntityHelper(this); - - super.setInvisible(true); - super.setSmall(true); - super.setArms(false); - super.setNoGravity(true); - super.setBasePlate(true); - super.setMarker(true); - super.collides = false; - super.z /* onGround */ = true; // Workaround to force EntityTrackerEntry to send a teleport packet - forceSetBoundingBox(new NullBoundingBox()); - } - - @Override - public void tick() { - // Disable normal ticking for this entity - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity - if (super.z /* onGround */) { - super.z = false; - } - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity - if (super.z /* onGround */) { - super.z = false; - } - } - - @Override - public void setPosition(double d0, double d1, double d2) { - // Do not change it! - } - - @Override - public void saveData(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean e(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound save(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void load(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void loadData(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void setCustomName(IChatBaseComponent ichatbasecomponent) { - // Prevents changes to custom name - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Prevents changes to custom name visibility - } - - @Override - public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) { - // Prevent armor stand from being equipped - return EnumInteractionResult.d /* PASS */; - } - - @Override - public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { - // Prevent armor stand from being equipped - } - - @Override - public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack, boolean silent) { - // Prevent armor stand from being equipped - } - - public void forceSetBoundingBox(AxisAlignedBB boundingBox) { - super.a(boundingBox); - } - - @Override - public void playSound(SoundEffect soundeffect, float f, float f1) { - // Remove sounds - } - - @Override - public void setCustomNameNMS(String customName) { - if (Objects.equals(this.customName, customName)) { - return; - } - this.customName = customName; - super.setCustomName(createCustomNameNMSObject(customName)); - super.setCustomNameVisible(customName != null && !customName.isEmpty()); - } - - protected static IChatBaseComponent createCustomNameNMSObject(String customName) { - return CraftChatMessage.fromStringOrNull(Strings.truncate(customName, 300)); - } - - @Override - public String getCustomNameStringNMS() { - return this.customName; - } - - @Override - public IChatBaseComponent getCustomNameObjectNMS() { - return super.getCustomName(); - } - - @Override - public void killEntity() { - // Prevent entity from dying - } - - @Override - public CraftEntity getBukkitEntity() { - if (customBukkitEntity == null) { - customBukkitEntity = new CraftNMSArmorStand(super.getWorld().getCraftServer(), this); - } - return customBukkitEntity; - } - - @Override - public void killEntityNMS() { - super.setRemoved(RemovalReason.b /* DISCARDED */); - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - if (protocolPacketSettings.sendAccurateLocationPackets()) { - helper.broadcastPacket(new PacketPlayOutEntityTeleport(this)); - } - } - - @Override - public void setPassengerNMS(NMSEntity passenger) { - Preconditions.checkArgument(passenger instanceof Entity); - Entity passengerEntity = (Entity) passenger; - Preconditions.checkArgument(passengerEntity.getVehicle() == null); - Preconditions.checkState(super.getPassengers().isEmpty()); - - try { - VEHICLE_FIELD.set(passenger, this); - ((Entity) this).at /* passengers */ = ImmutableList.of(passengerEntity); - } catch (ReflectiveOperationException e) { - DebugLogger.cannotSetPassenger(e); - } - } - - @Override - public boolean isDeadNMS() { - return super.isRemoved(); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - -} diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityNMSItem.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityNMSItem.java deleted file mode 100644 index 9d54594f..00000000 --- a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityNMSItem.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_17_R1; - -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; -import me.filoghost.holographicdisplays.common.nms.NMSCommons; -import me.filoghost.holographicdisplays.common.nms.entity.NMSItem; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.nbt.NBTTagString; -import net.minecraft.server.level.EntityPlayer; -import net.minecraft.world.damagesource.DamageSource; -import net.minecraft.world.entity.EntityTypes; -import net.minecraft.world.entity.item.EntityItem; -import net.minecraft.world.entity.player.EntityHuman; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.World; -import net.minecraft.world.level.block.Blocks; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; -import org.bukkit.entity.Player; - -public class EntityNMSItem extends EntityItem implements NMSItem { - - private final StandardItemLine parentHologramLine; - private final VersionNMSEntityHelper helper; - private CraftEntity customBukkitEntity; - - public EntityNMSItem(World world, StandardItemLine parentHologramLine) { - super(EntityTypes.Q, world); - this.parentHologramLine = parentHologramLine; - this.helper = new VersionNMSEntityHelper(this); - - super.ap /* pickupDelay */ = 32767; // Lock the item pickup delay, also prevents entities from picking up the item - } - - @Override - public void tick() { - // Disable normal ticking for this entity - - // So it won't get removed - super.R /* tickCount */ = 0; - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // So it won't get removed - super.R /* tickCount */ = 0; - } - - @Override - public void setPosition(double d0, double d1, double d2) { - // Do not change it! - } - - // Method called when a player is near - @Override - public void pickup(EntityHuman human) { - if (human.locY() < super.locY() - 1.5 || human.locY() > super.locY() + 1.0) { - // Too low or too high, it's a bit weird - return; - } - - if (human instanceof EntityPlayer) { - parentHologramLine.onPickup(((EntityPlayer) human).getBukkitEntity()); - // It is never added to the inventory - } - } - - @Override - public void saveData(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean e(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound save(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void load(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void loadData(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void killEntity() { - // Prevent entity from dying - } - - @Override - public boolean isAlive() { - // This override prevents items from being picked up by hoppers (should have no side effects) - return false; - } - - @Override - public CraftEntity getBukkitEntity() { - if (customBukkitEntity == null) { - customBukkitEntity = new CraftNMSItem(super.getWorld().getCraftServer(), this); - } - return customBukkitEntity; - } - - @Override - public boolean isDeadNMS() { - return super.isRemoved(); - } - - @Override - public void killEntityNMS() { - super.setRemoved(RemovalReason.b /* DISCARDED */); - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - } - - @Override - public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) { - ItemStack newItem = CraftItemStack.asNMSCopy(stack); - - if (newItem == null || newItem == ItemStack.b /* EMPTY */) { - newItem = new ItemStack(Blocks.z /* BEDROCK */); - } - - if (newItem.getTag() == null) { - newItem.setTag(new NBTTagCompound()); - } - NBTTagCompound display = newItem.getTag().getCompound("display"); // Returns a new NBTTagCompound if not existing - if (!newItem.getTag().hasKey("display")) { - newItem.getTag().set("display", display); - } - - NBTTagList tagList = new NBTTagList(); - tagList.add(NBTTagString.a(NMSCommons.ANTI_STACK_LORE)); - display.set("Lore", tagList); - - super.setItemStack(newItem); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - - @Override - public Object getRawItemStack() { - return super.getItemStack(); - } - -} diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityNMSSlime.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityNMSSlime.java deleted file mode 100644 index 9701fb60..00000000 --- a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityNMSSlime.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_17_R1; - -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.nms.entity.NMSSlime; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.chat.IChatBaseComponent; -import net.minecraft.server.level.EntityPlayer; -import net.minecraft.sounds.SoundEffect; -import net.minecraft.world.damagesource.DamageSource; -import net.minecraft.world.damagesource.EntityDamageSource; -import net.minecraft.world.entity.EntityTypes; -import net.minecraft.world.entity.monster.EntitySlime; -import net.minecraft.world.level.World; -import net.minecraft.world.phys.AxisAlignedBB; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.player.PlayerInteractEntityEvent; - -public class EntityNMSSlime extends EntitySlime implements NMSSlime { - - private final StandardHologramLine parentHologramLine; - private final VersionNMSEntityHelper helper; - private CraftEntity customBukkitEntity; - - public EntityNMSSlime(World world, StandardHologramLine parentHologramLine) { - super(EntityTypes.aD /* SLIME */, world); - this.parentHologramLine = parentHologramLine; - this.helper = new VersionNMSEntityHelper(this); - - super.collides = false; - super.setPersistent(); - super.a(0.0F, 0.0F); - super.setSize(1, false); - super.setInvisible(true); - forceSetBoundingBox(new NullBoundingBox()); - } - - @Override - public void tick() { - // Disable normal ticking for this entity - - // So it won't get removed - super.R /* tickCount */ = 0; - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // So it won't get removed - super.R /* tickCount */ = 0; - } - - @Override - public void setPosition(double d0, double d1, double d2) { - // Do not change it! - } - - public void forceSetBoundingBox(AxisAlignedBB boundingBox) { - super.a(boundingBox); - } - - @Override - public void saveData(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean e(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound save(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void load(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void loadData(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean damageEntity(DamageSource damageSource, float amount) { - if (damageSource instanceof EntityDamageSource) { - EntityDamageSource entityDamageSource = (EntityDamageSource) damageSource; - if (entityDamageSource.getEntity() instanceof EntityPlayer) { - Player player = ((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(); - PlayerInteractEntityEvent event = new PlayerInteractEntityEvent(player, getBukkitEntity()); - Bukkit.getPluginManager().callEvent(event); // Bukkit takes care of the exceptions - } - } - return false; - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void setCustomName(IChatBaseComponent ichatbasecomponent) { - // Prevents changes to custom name - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Prevents changes to custom name visibility - } - - @Override - public void playSound(SoundEffect soundeffect, float f, float f1) { - // Remove sounds - } - - @Override - public void killEntity() { - // Prevent entity from dying - } - - @Override - public CraftEntity getBukkitEntity() { - if (customBukkitEntity == null) { - customBukkitEntity = new CraftNMSSlime(super.getWorld().getCraftServer(), this); - } - return customBukkitEntity; - } - - @Override - public boolean isDeadNMS() { - return super.isRemoved(); - } - - @Override - public void killEntityNMS() { - super.setRemoved(RemovalReason.b /* DISCARDED */); - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - -} diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntitySpawnNMSPacket.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntitySpawnNMSPacket.java new file mode 100644 index 00000000..49d2d706 --- /dev/null +++ b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntitySpawnNMSPacket.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_17_R1; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity; + +class EntitySpawnNMSPacket extends VersionNMSPacket { + + private final Packet rawPacket; + + EntitySpawnNMSPacket(EntityID entityID, int entityTypeID, double locationX, double locationY, double locationZ) { + PacketByteBuffer packetByteBuffer = PacketByteBuffer.get(); + + packetByteBuffer.writeVarInt(entityID.getNumericID()); + packetByteBuffer.writeUUID(entityID.getUUID()); + packetByteBuffer.writeVarInt(entityTypeID); + + // Position + packetByteBuffer.writeDouble(locationX); + packetByteBuffer.writeDouble(locationY); + packetByteBuffer.writeDouble(locationZ); + + // Rotation + packetByteBuffer.writeByte(0); + packetByteBuffer.writeByte(0); + + // Object data + packetByteBuffer.writeInt(0); + + // Velocity + packetByteBuffer.writeShort(0); + packetByteBuffer.writeShort(0); + packetByteBuffer.writeShort(0); + + this.rawPacket = new PacketPlayOutSpawnEntity(packetByteBuffer); + } + + @Override + Packet getRawPacket() { + return rawPacket; + } + +} diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityTeleportNMSPacket.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityTeleportNMSPacket.java new file mode 100644 index 00000000..ecf84a1f --- /dev/null +++ b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityTeleportNMSPacket.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_17_R1; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.game.PacketPlayOutEntityTeleport; + +class EntityTeleportNMSPacket extends VersionNMSPacket { + + private final Packet rawPacket; + + EntityTeleportNMSPacket(EntityID entityID, double locationX, double locationY, double locationZ) { + PacketByteBuffer packetByteBuffer = PacketByteBuffer.get(); + + packetByteBuffer.writeVarInt(entityID.getNumericID()); + + // Location + packetByteBuffer.writeDouble(locationX); + packetByteBuffer.writeDouble(locationY); + packetByteBuffer.writeDouble(locationZ); + + // Rotation + packetByteBuffer.writeByte(0); + packetByteBuffer.writeByte(0); + + // On ground + packetByteBuffer.writeBoolean(false); + + this.rawPacket = new PacketPlayOutEntityTeleport(packetByteBuffer); + } + + @Override + Packet getRawPacket() { + return rawPacket; + } + +} diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityTypeID.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityTypeID.java new file mode 100644 index 00000000..5fe2185e --- /dev/null +++ b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityTypeID.java @@ -0,0 +1,14 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_17_R1; + +class EntityTypeID { + + static final int ARMOR_STAND = 1; + static final int ITEM = 41; + static final int SLIME = 80; + +} diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/NullBoundingBox.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/NullBoundingBox.java deleted file mode 100644 index 54df1b9e..00000000 --- a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/NullBoundingBox.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_17_R1; - -import net.minecraft.core.BlockPosition; -import net.minecraft.core.EnumDirection.EnumAxis; -import net.minecraft.world.phys.AxisAlignedBB; -import net.minecraft.world.phys.Vec3D; - -public class NullBoundingBox extends AxisAlignedBB { - - public NullBoundingBox() { - super(0, 0, 0, 0, 0, 0); - } - - @Override - public double a() { - return 0.0; - } - - @Override - public AxisAlignedBB a(AxisAlignedBB arg0) { - return this; - } - - @Override - public AxisAlignedBB a(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public AxisAlignedBB grow(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public AxisAlignedBB shrink(double arg0) { - return this; - } - - @Override - public AxisAlignedBB a(BlockPosition arg0) { - return this; - } - - @Override - public boolean a(double arg0, double arg1, double arg2, double arg3, double arg4, double arg5) { - return false; - } - - @Override - public AxisAlignedBB g(double arg0) { - return this; - } - - @Override - public AxisAlignedBB b(Vec3D arg0) { - return this; - } - - @Override - public AxisAlignedBB b(AxisAlignedBB arg0) { - return this; - } - - @Override - public AxisAlignedBB b(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public boolean c(AxisAlignedBB arg0) { - return false; - } - - @Override - public AxisAlignedBB d(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public double a(EnumAxis arg0) { - return 0.0; - } - - @Override - public double b(EnumAxis arg0) { - return 0.0; - } - - @Override - public boolean e(double arg0, double arg1, double arg2) { - return false; - } - - @Override - public double b() { - return 0.0; - } - - @Override - public double c() { - return 0.0; - } - - @Override - public double d() { - return 0.0; - } - - @Override - public boolean d(Vec3D var0) { - return false; - } - - @Override - public Vec3D f() { - return Vec3D.a /* ZERO */; - } - -} diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/PacketByteBuffer.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/PacketByteBuffer.java new file mode 100644 index 00000000..ff15aad4 --- /dev/null +++ b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/PacketByteBuffer.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_17_R1; + +import io.netty.buffer.Unpooled; +import net.minecraft.network.PacketDataSerializer; +import org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.IntList; + +import java.util.UUID; + +class PacketByteBuffer extends PacketDataSerializer { + + static PacketByteBuffer get() { + return new PacketByteBuffer(); // TODO try to clear and re-use a single instance + } + + private PacketByteBuffer() { + super(Unpooled.buffer()); + } + + void writeVarInt(int i) { + super.d(i); + } + + void writeUUID(UUID uuid) { + super.a(uuid); + } + + void writeIntList(IntList intList) { + super.a(intList); + } + + void writeIntArray(int... array) { + super.a(array); + } + + void writeDataWatcherEntries(DataWatcherEntry... dataWatcherEntries) { + for (DataWatcherEntry dataWatcherItem : dataWatcherEntries) { + writeDataWatcherEntry(dataWatcherItem); + } + writeByte(255); // End of data watcher entries + } + + private void writeDataWatcherEntry(DataWatcherEntry dataWatcherItem) { + writeByte(dataWatcherItem.getKey().getKeyIndex()); + writeVarInt(dataWatcherItem.getKey().getSerializerTypeID()); + dataWatcherItem.getKey().getSerializer().a(this, dataWatcherItem.getValue()); + } + +} diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionNMSEntityHelper.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionNMSEntityHelper.java deleted file mode 100644 index ee04fc01..00000000 --- a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionNMSEntityHelper.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_17_R1; - -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntityHelper; -import net.minecraft.network.protocol.Packet; -import net.minecraft.server.level.PlayerChunkMap.EntityTracker; -import net.minecraft.server.level.WorldServer; -import net.minecraft.server.network.PlayerConnection; -import net.minecraft.world.entity.Entity; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; - -public class VersionNMSEntityHelper extends NMSEntityHelper { - - private final Entity entity; - - public VersionNMSEntityHelper(Entity entity) { - this.entity = entity; - } - - @Override - protected EntityTracker getTracker0() { - return ((WorldServer) entity.getWorld()).getChunkProvider().a /* playerChunkMap */.G /* trackedEntities */.get(entity.getId()); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - EntityTracker tracker = getTracker(); - if (tracker != null) { - PlayerConnection playerConnection = ((CraftPlayer) bukkitPlayer).getHandle().b /* playerConnection */; - return tracker.f /* trackedPlayerConnections */.contains(playerConnection); - } else { - return false; - } - } - - public void broadcastPacket(Packet packet) { - EntityTracker tracker = getTracker(); - if (tracker != null) { - tracker.broadcast(packet); - } - } - -} diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionNMSManager.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionNMSManager.java index 84843d20..5d3d17ee 100644 --- a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionNMSManager.java +++ b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionNMSManager.java @@ -5,122 +5,50 @@ */ package me.filoghost.holographicdisplays.nms.v1_17_R1; -import me.filoghost.fcommons.Preconditions; -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; +import me.filoghost.fcommons.logging.ErrorCollector; +import me.filoghost.fcommons.logging.Log; +import me.filoghost.fcommons.reflection.ReflectField; +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.FallbackEntityIDGenerator; +import me.filoghost.holographicdisplays.common.nms.NMSErrors; import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; -import me.filoghost.holographicdisplays.common.nms.SpawnFailedException; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntity; -import me.filoghost.holographicdisplays.common.nms.entity.NMSItem; -import net.minecraft.server.level.WorldServer; -import net.minecraft.util.MathHelper; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.Entity.RemovalReason; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_17_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity; -import org.bukkit.inventory.ItemStack; + +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Supplier; public class VersionNMSManager implements NMSManager { - private final ProtocolPacketSettings protocolPacketSettings; + private static final ReflectField ENTITY_ID_COUNTER_FIELD = ReflectField.lookup(AtomicInteger.class, Entity.class, "b"); + private final Supplier entityIDGenerator; - public VersionNMSManager(ProtocolPacketSettings protocolPacketSettings) { - this.protocolPacketSettings = protocolPacketSettings; + public VersionNMSManager(ErrorCollector errorCollector) { + this.entityIDGenerator = getEntityIDGenerator(errorCollector); + + // Force initialization of class to eventually throw exceptions early + DataWatcherKey.ENTITY_STATUS.getKeyIndex(); } - @Override - public void setup() {} - - @Override - public NMSItem spawnNMSItem( - World bukkitWorld, double x, double y, double z, - StandardItemLine parentHologramLine, - ItemStack stack) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSItem item = new EntityNMSItem(nmsWorld, parentHologramLine); - 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 parentHologramLine) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSSlime slime = new EntityNMSSlime(nmsWorld, parentHologramLine); - slime.setLocationNMS(x, y, z); - addEntityToWorld(nmsWorld, slime); - return slime; - } - - @Override - public NMSArmorStand spawnNMSArmorStand( - World world, double x, double y, double z, - StandardHologramLine parentHologramLine) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) world).getHandle(); - EntityNMSArmorStand armorStand = new EntityNMSArmorStand(nmsWorld, parentHologramLine, protocolPacketSettings); - armorStand.setLocationNMS(x, y, z); - addEntityToWorld(nmsWorld, armorStand); - return armorStand; - } - - 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); - final int chunkZ = MathHelper.floor(nmsEntity.locZ() / 16.0); - - if (!nmsWorld.isChunkLoaded(chunkX, chunkZ)) { - // This should never happen - nmsEntity.setRemoved(RemovalReason.b /* DISCARDED */); - throw new SpawnFailedException(SpawnFailedException.CHUNK_NOT_LOADED); - } - + private Supplier getEntityIDGenerator(ErrorCollector errorCollector) { try { - nmsWorld.G.a(nmsEntity) /* entityManager.addNewEntity() */; - } catch (Exception e) { - nmsEntity.setRemoved(RemovalReason.b /* DISCARDED */); - throw new SpawnFailedException(SpawnFailedException.REGISTER_ENTITY_FAIL, e); + AtomicInteger nmsEntityIDCounter = ENTITY_ID_COUNTER_FIELD.getStatic(); + return nmsEntityIDCounter::incrementAndGet; + } catch (ReflectiveOperationException e) { + Log.warning(NMSErrors.GETTING_ENTITY_ID_GENERATOR_SHORT, e); + errorCollector.add(NMSErrors.GETTING_ENTITY_ID_GENERATOR_LONG); + return new FallbackEntityIDGenerator(); } } @Override - public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntity; + public EntityID newEntityID() { + return new EntityID(entityIDGenerator); } @Override - public NMSEntity getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - - if (nmsEntity instanceof NMSEntity) { - return (NMSEntity) nmsEntity; - } else { - return null; - } - } - - @Override - public NMSEntity getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - Entity nmsEntity = nmsWorld.getEntity(entityID); - - if (nmsEntity instanceof NMSEntity) { - return (NMSEntity) nmsEntity; - } else { - return null; - } - } - - @Override - public Object createCustomNameNMSObject(String customName) { - return EntityNMSArmorStand.createCustomNameNMSObject(customName); + public NMSPacketList createPacketList() { + return new VersionNMSPacketList(); } } diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionNMSPacket.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionNMSPacket.java new file mode 100644 index 00000000..4c1e76c1 --- /dev/null +++ b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionNMSPacket.java @@ -0,0 +1,22 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_17_R1; + +import me.filoghost.holographicdisplays.common.nms.NMSPacket; +import net.minecraft.network.protocol.Packet; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; + +abstract class VersionNMSPacket implements NMSPacket { + + @Override + public void sendTo(Player player) { + ((CraftPlayer) player).getHandle().b.sendPacket(getRawPacket()); + } + + abstract Packet getRawPacket(); + +} diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionNMSPacketList.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionNMSPacketList.java new file mode 100644 index 00000000..8ecc7fa5 --- /dev/null +++ b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionNMSPacketList.java @@ -0,0 +1,145 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_17_R1; + +import me.filoghost.fcommons.Strings; +import me.filoghost.fcommons.logging.Log; +import me.filoghost.holographicdisplays.common.nms.AbstractNMSPacketList; +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.IndividualCustomName; +import me.filoghost.holographicdisplays.common.nms.IndividualNMSPacket; +import net.minecraft.network.chat.IChatBaseComponent; +import net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy; +import org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.IntList; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_17_R1.util.CraftChatMessage; +import org.bukkit.inventory.ItemStack; + +import java.lang.reflect.Field; +import java.util.Optional; + +class VersionNMSPacketList extends AbstractNMSPacketList { + + private static final DataWatcherEntry ENTITY_STATUS_INVISIBLE = new DataWatcherEntry<>(DataWatcherKey.ENTITY_STATUS, (byte) 0x20); + private static final DataWatcherEntry CUSTOM_NAME_VISIBLE = new DataWatcherEntry<>(DataWatcherKey.CUSTOM_NAME_VISIBILITY, true); + private static final DataWatcherEntry CUSTOM_NAME_INVISIBLE = new DataWatcherEntry<>(DataWatcherKey.CUSTOM_NAME_VISIBILITY, false); + private static final DataWatcherEntry ARMOR_STAND_STATUS_MARKER = new DataWatcherEntry<>(DataWatcherKey.ARMOR_STAND_STATUS, (byte) (0x01 | 0x08 | 0x10)); // Small, no base plate, marker + + private static final boolean USE_ENTITY_LIST_DESTROY_PACKET = useEntityListDestroyPacket(); + + @Override + public void addArmorStandSpawnPackets(EntityID entityID, double locationX, double locationY, double locationZ) { + add(new EntityLivingSpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, locationX, locationY, locationZ)); + add(new EntityMetadataNMSPacket(entityID, + ENTITY_STATUS_INVISIBLE, + ARMOR_STAND_STATUS_MARKER + )); + } + + @Override + public void addArmorStandSpawnPackets(EntityID entityID, double locationX, double locationY, double locationZ, String customName) { + add(new EntityLivingSpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, locationX, locationY, locationZ)); + add(createFullArmorStandMetadataPacket(entityID, customName)); + } + + @Override + public void addArmorStandSpawnPackets(EntityID entityID, double locationX, double locationY, double locationZ, IndividualCustomName individualCustomName) { + add(new EntityLivingSpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, locationX, locationY, locationZ)); + add(new IndividualNMSPacket(player -> createFullArmorStandMetadataPacket(entityID, individualCustomName.get(player)))); + } + + private EntityMetadataNMSPacket createFullArmorStandMetadataPacket(EntityID entityID, String customName) { + return new EntityMetadataNMSPacket(entityID, + ENTITY_STATUS_INVISIBLE, + new DataWatcherEntry<>(DataWatcherKey.CUSTOM_NAME, getCustomNameDataWatcherValue(customName)), + Strings.isEmpty(customName) ? CUSTOM_NAME_INVISIBLE : CUSTOM_NAME_VISIBLE, + ARMOR_STAND_STATUS_MARKER + ); + } + + @Override + public void addArmorStandNameChangePackets(EntityID entityID, String customName) { + add(createPartialArmorStandMetadataPacket(entityID, customName)); + } + + @Override + public void addArmorStandNameChangePackets(EntityID entityID, IndividualCustomName individualCustomName) { + add(new IndividualNMSPacket(player -> createPartialArmorStandMetadataPacket(entityID, individualCustomName.get(player)))); + } + + private EntityMetadataNMSPacket createPartialArmorStandMetadataPacket(EntityID entityID, String customName) { + return new EntityMetadataNMSPacket(entityID, + new DataWatcherEntry<>(DataWatcherKey.CUSTOM_NAME, getCustomNameDataWatcherValue(customName)), + Strings.isEmpty(customName) ? CUSTOM_NAME_INVISIBLE : CUSTOM_NAME_VISIBLE + ); + } + + private Optional getCustomNameDataWatcherValue(String customName) { + customName = Strings.truncate(customName, 300); + if (!Strings.isEmpty(customName)) { + return Optional.of(CraftChatMessage.fromString(customName, false, true)[0]); + } else { + return Optional.empty(); + } + } + + @Override + public void addItemSpawnPackets(EntityID entityID, double locationX, double locationY, double locationZ, ItemStack itemStack) { + add(new EntitySpawnNMSPacket(entityID, EntityTypeID.ITEM, locationX, locationY, locationZ)); + add(new EntityMetadataNMSPacket(entityID, + new DataWatcherEntry<>(DataWatcherKey.ITEM_STACK, CraftItemStack.asNMSCopy(itemStack)) + )); + } + + @Override + public void addItemStackChangePackets(EntityID entityID, ItemStack itemStack) { + add(new EntityMetadataNMSPacket(entityID, + new DataWatcherEntry<>(DataWatcherKey.ITEM_STACK, CraftItemStack.asNMSCopy(itemStack)) + )); + } + + @Override + public void addSlimeSpawnPackets(EntityID entityID, double locationX, double locationY, double locationZ) { + add(new EntityLivingSpawnNMSPacket(entityID, EntityTypeID.SLIME, locationX, locationY, locationZ)); + add(new EntityMetadataNMSPacket(entityID, ENTITY_STATUS_INVISIBLE)); + } + + @Override + public void addEntityDestroyPackets(EntityID... entityIDs) { + if (USE_ENTITY_LIST_DESTROY_PACKET) { + add(new EntityListDestroyNMSPacket(entityIDs)); + } else { + for (EntityID entityID : entityIDs) { + add(new EntityDestroyNMSPacket(entityID)); + } + } + } + + @Override + public void addTeleportPackets(EntityID entityID, double locationX, double locationY, double locationZ) { + add(new EntityTeleportNMSPacket(entityID, locationX, locationY, locationZ)); + } + + @Override + public void addMountPackets(EntityID vehicleEntityID, EntityID passengerEntityID) { + add(new EntityMountNMSPacket(vehicleEntityID, passengerEntityID)); + } + + private static boolean useEntityListDestroyPacket() { + try { + for (Field field : PacketPlayOutEntityDestroy.class.getDeclaredFields()) { + if (field.getType() == IntList.class) { + return true; + } + } + return false; + } catch (Throwable t) { + Log.warning("Could not detect PacketPlayOutEntityDestroy details, error can be ignored if on Minecraft 1.17.1+", t); + return true; // Assume newer Minecraft version + } + } + +} diff --git a/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/CraftNMSArmorStand.java b/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/CraftNMSArmorStand.java deleted file mode 100644 index 82175272..00000000 --- a/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/CraftNMSArmorStand.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_8_R2; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_8_R2.CraftServer; -import org.bukkit.craftbukkit.v1_8_R2.entity.CraftArmorStand; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.ItemStack; -import org.bukkit.potion.PotionEffect; -import org.bukkit.util.EulerAngle; -import org.bukkit.util.Vector; - -import java.util.Collection; - -public class CraftNMSArmorStand extends CraftArmorStand { - - public CraftNMSArmorStand(CraftServer server, EntityNMSArmorStand entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // 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 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 effects) { return false; } - @Override public void setRemoveWhenFarAway(boolean remove) {} - - // Methods from Entity - @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 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 setLastDamageCause(EntityDamageEvent event) {} - -} diff --git a/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/CraftNMSItem.java b/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/CraftNMSItem.java deleted file mode 100644 index b213fc3f..00000000 --- a/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/CraftNMSItem.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_8_R2; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_8_R2.CraftServer; -import org.bukkit.craftbukkit.v1_8_R2.entity.CraftItem; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; - -public class CraftNMSItem extends CraftItem { - - public CraftNMSItem(CraftServer server, EntityNMSItem entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // Methods from Entity - @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 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 setLastDamageCause(EntityDamageEvent event) {} - - // Methods from Item - @Override public void setItemStack(ItemStack stack) {} - @Override public void setPickupDelay(int delay) {} -} diff --git a/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/CraftNMSSlime.java b/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/CraftNMSSlime.java deleted file mode 100644 index 2573d570..00000000 --- a/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/CraftNMSSlime.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_8_R2; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_8_R2.CraftServer; -import org.bukkit.craftbukkit.v1_8_R2.entity.CraftSlime; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.potion.PotionEffect; -import org.bukkit.util.Vector; - -import java.util.Collection; - -public class CraftNMSSlime extends CraftSlime { - - public CraftNMSSlime(CraftServer server, EntityNMSSlime entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // 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 effects) { return false; } - @Override public void setRemoveWhenFarAway(boolean remove) {} - - // Methods from Entity - @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 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 setLastDamageCause(EntityDamageEvent event) {} - - // Methods from Slime - @Override public void setSize(int size) {} -} diff --git a/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/EntityNMSArmorStand.java b/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/EntityNMSArmorStand.java deleted file mode 100644 index 750dbb90..00000000 --- a/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/EntityNMSArmorStand.java +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_8_R2; - -import me.filoghost.fcommons.Preconditions; -import me.filoghost.fcommons.Strings; -import me.filoghost.fcommons.reflection.ReflectField; -import me.filoghost.fcommons.reflection.ReflectMethod; -import me.filoghost.holographicdisplays.common.DebugLogger; -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.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.ItemStack; -import net.minecraft.server.v1_8_R2.NBTTagCompound; -import net.minecraft.server.v1_8_R2.PacketPlayOutEntityTeleport; -import net.minecraft.server.v1_8_R2.Vec3D; -import net.minecraft.server.v1_8_R2.World; -import org.bukkit.craftbukkit.v1_8_R2.entity.CraftEntity; -import org.bukkit.entity.Player; - -import java.util.Objects; - -public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand { - - private static final ReflectMethod SET_MARKER_METHOD - = ReflectMethod.lookup(void.class, EntityArmorStand.class, "n", boolean.class); - private static final ReflectField PASSENGER_PITCH_DELTA = ReflectField.lookup(double.class, Entity.class, "ar"); - private static final ReflectField PASSENGER_YAW_DELTA = ReflectField.lookup(double.class, Entity.class, "as"); - - private final StandardHologramLine parentHologramLine; - private final ProtocolPacketSettings protocolPacketSettings; - private final VersionNMSEntityHelper helper; - private String customName; - - public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, ProtocolPacketSettings protocolPacketSettings) { - super(world); - this.parentHologramLine = parentHologramLine; - this.protocolPacketSettings = protocolPacketSettings; - this.helper = new VersionNMSEntityHelper(this); - - super.setInvisible(true); - super.setSmall(true); - super.setArms(false); - super.setGravity(true); - super.setBasePlate(true); - try { - SET_MARKER_METHOD.invoke(this, true); - } catch (ReflectiveOperationException e) { - DebugLogger.cannotSetArmorStandAsMarker(e); - // It will still work, but the offset will be wrong - } - super.noclip = true; - super.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet - forceSetBoundingBox(new NullBoundingBox()); - } - - @Override - public void t_() { - // Disable normal ticking for this entity - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity - if (super.onGround) { - super.onGround = false; - } - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity - if (super.onGround) { - super.onGround = false; - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public void e(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public void setCustomName(String customName) { - // Prevents changes to custom name - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Prevents changes to custom name visibility - } - - @Override - public boolean a(EntityHuman human, Vec3D vec3d) { - // Prevent armor stand from being equipped - return true; - } - - @Override - public boolean d(int i, ItemStack item) { - // Prevent armor stand from being equipped - return false; - } - - @Override - public void setEquipment(int i, ItemStack item) { - // Prevent armor stand from being equipped - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Prevent changes to bounding box - } - - public void forceSetBoundingBox(AxisAlignedBB boundingBox) { - super.a(boundingBox); - } - - @Override - public void makeSound(String sound, float f1, float f2) { - // Remove sounds - } - - @Override - public void setCustomNameNMS(String customName) { - if (Objects.equals(this.customName, customName)) { - return; - } - this.customName = customName; - super.setCustomName(createCustomNameNMSObject(customName)); - super.setCustomNameVisible(customName != null && !customName.isEmpty()); - } - - protected static String createCustomNameNMSObject(String customName) { - return customName != null ? Strings.truncate(customName, 256) : ""; - } - - @Override - public String getCustomNameStringNMS() { - return this.customName; - } - - @Override - public String getCustomNameObjectNMS() { - return super.getCustomName(); - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSArmorStand(super.world.getServer(), this); - } - return super.bukkitEntity; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - if (protocolPacketSettings.sendAccurateLocationPackets()) { - helper.broadcastPacket(new PacketPlayOutEntityTeleport(this)); - } - } - - @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; - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - -} diff --git a/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/EntityNMSItem.java b/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/EntityNMSItem.java deleted file mode 100644 index 8bfa188e..00000000 --- a/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/EntityNMSItem.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_8_R2; - -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; -import me.filoghost.holographicdisplays.common.nms.NMSCommons; -import me.filoghost.holographicdisplays.common.nms.entity.NMSItem; -import net.minecraft.server.v1_8_R2.Blocks; -import net.minecraft.server.v1_8_R2.DamageSource; -import net.minecraft.server.v1_8_R2.EntityHuman; -import net.minecraft.server.v1_8_R2.EntityItem; -import net.minecraft.server.v1_8_R2.EntityPlayer; -import net.minecraft.server.v1_8_R2.ItemStack; -import net.minecraft.server.v1_8_R2.NBTTagCompound; -import net.minecraft.server.v1_8_R2.NBTTagList; -import net.minecraft.server.v1_8_R2.NBTTagString; -import net.minecraft.server.v1_8_R2.World; -import org.bukkit.craftbukkit.v1_8_R2.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack; -import org.bukkit.entity.Player; - -public class EntityNMSItem extends EntityItem implements NMSItem { - - private final StandardItemLine parentHologramLine; - private final VersionNMSEntityHelper helper; - - public EntityNMSItem(World world, StandardItemLine parentHologramLine) { - super(world); - this.parentHologramLine = parentHologramLine; - this.helper = new VersionNMSEntityHelper(this); - - super.pickupDelay = Integer.MAX_VALUE; - } - - @Override - public void t_() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - // Method called when a player is near - @Override - public void d(EntityHuman human) { - if (human.locY < this.locY - 1.5 || human.locY > this.locY + 1.0) { - // Too low or too high, it's a bit weird - return; - } - - if (human instanceof EntityPlayer) { - parentHologramLine.onPickup(((EntityPlayer) human).getBukkitEntity()); - // It is never added to the inventory - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public void e(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public boolean isAlive() { - // This override prevents items from being picked up by hoppers (should have no side effects) - return false; - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSItem(super.world.getServer(), this); - } - return super.bukkitEntity; - } - - @Override - public boolean isDeadNMS() { - return this.dead; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - } - - @Override - public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) { - ItemStack newItem = CraftItemStack.asNMSCopy(stack); - - if (newItem == null) { - newItem = new ItemStack(Blocks.BEDROCK); - } - - if (newItem.getTag() == null) { - newItem.setTag(new NBTTagCompound()); - } - NBTTagCompound display = newItem.getTag().getCompound("display"); - - if (!newItem.getTag().hasKey("display")) { - newItem.getTag().set("display", display); - } - - NBTTagList tagList = new NBTTagList(); - tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE)); - display.set("Lore", tagList); - - super.setItemStack(newItem); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - - @Override - public Object getRawItemStack() { - return super.getItemStack(); - } - -} diff --git a/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/EntityNMSSlime.java b/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/EntityNMSSlime.java deleted file mode 100644 index 610d8d0c..00000000 --- a/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/EntityNMSSlime.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_8_R2; - -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.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.EntityDamageSource; -import net.minecraft.server.v1_8_R2.EntityPlayer; -import net.minecraft.server.v1_8_R2.EntitySlime; -import net.minecraft.server.v1_8_R2.NBTTagCompound; -import net.minecraft.server.v1_8_R2.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_8_R2.entity.CraftEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.player.PlayerInteractEntityEvent; - -public class EntityNMSSlime extends EntitySlime implements NMSSlime { - - private final StandardHologramLine parentHologramLine; - private final VersionNMSEntityHelper helper; - - public EntityNMSSlime(World world, StandardHologramLine parentHologramLine) { - super(world); - this.parentHologramLine = parentHologramLine; - this.helper = new VersionNMSEntityHelper(this); - - super.persistent = true; - super.noclip = true; - super.a(0.0F, 0.0F); - super.setSize(1); - super.setInvisible(true); - forceSetBoundingBox(new NullBoundingBox()); - } - - @Override - public void t_() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - - // The slime dies without a vehicle - if (super.vehicle == null) { - killEntityNMS(); - } - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Prevent changes to bounding box - } - - public void forceSetBoundingBox(AxisAlignedBB boundingBox) { - super.a(boundingBox); - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public void e(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean damageEntity(DamageSource damageSource, float amount) { - if (damageSource instanceof EntityDamageSource) { - EntityDamageSource entityDamageSource = (EntityDamageSource) damageSource; - if (entityDamageSource.getEntity() instanceof EntityPlayer) { - Player player = ((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(); - PlayerInteractEntityEvent event = new PlayerInteractEntityEvent(player, getBukkitEntity()); - Bukkit.getPluginManager().callEvent(event); // Bukkit takes care of the exceptions - } - } - return false; - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public void setCustomName(String customName) { - // Prevents changes to custom name - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Prevents changes to custom name visibility - } - - @Override - public void makeSound(String sound, float volume, float pitch) { - // Remove sounds - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSSlime(super.world.getServer(), this); - } - return super.bukkitEntity; - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - -} diff --git a/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/NullBoundingBox.java b/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/NullBoundingBox.java deleted file mode 100644 index 9acc25e9..00000000 --- a/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/NullBoundingBox.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_8_R2; - -import net.minecraft.server.v1_8_R2.AxisAlignedBB; -import net.minecraft.server.v1_8_R2.MovingObjectPosition; -import net.minecraft.server.v1_8_R2.Vec3D; - -public class NullBoundingBox extends AxisAlignedBB { - - public NullBoundingBox() { - super(0, 0, 0, 0, 0, 0); - } - - @Override - public double a() { - return 0.0; - } - - @Override - public double a(AxisAlignedBB arg0, double arg1) { - return 0.0; - } - - @Override - public AxisAlignedBB a(AxisAlignedBB arg0) { - return this; - } - - @Override - public AxisAlignedBB a(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public MovingObjectPosition a(Vec3D arg0, Vec3D arg1) { - return super.a(arg0, arg1); - } - - @Override - public boolean a(Vec3D arg0) { - return false; - } - - @Override - public double b(AxisAlignedBB arg0, double arg1) { - return 0.0; - } - - @Override - public boolean b(AxisAlignedBB arg0) { - return false; - } - - @Override - public double c(AxisAlignedBB arg0, double arg1) { - return 0.0; - } - - @Override - public AxisAlignedBB c(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public AxisAlignedBB grow(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public AxisAlignedBB shrink(double arg0, double arg1, double arg2) { - return this; - } - -} diff --git a/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/VersionNMSEntityHelper.java b/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/VersionNMSEntityHelper.java deleted file mode 100644 index f23afa40..00000000 --- a/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/VersionNMSEntityHelper.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_8_R2; - -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntityHelper; -import net.minecraft.server.v1_8_R2.Entity; -import net.minecraft.server.v1_8_R2.EntityTrackerEntry; -import net.minecraft.server.v1_8_R2.Packet; -import net.minecraft.server.v1_8_R2.WorldServer; -import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer; -import org.bukkit.entity.Player; - -public class VersionNMSEntityHelper extends NMSEntityHelper { - - private final Entity entity; - - public VersionNMSEntityHelper(Entity entity) { - this.entity = entity; - } - - @Override - protected EntityTrackerEntry getTracker0() { - return ((WorldServer) entity.world).tracker.trackedEntities.get(entity.getId()); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - EntityTrackerEntry tracker = getTracker(); - if (tracker != null) { - return tracker.trackedPlayers.contains(((CraftPlayer) bukkitPlayer).getHandle()); - } else { - return false; - } - } - - public void broadcastPacket(Packet packet) { - EntityTrackerEntry tracker = getTracker(); - if (tracker != null) { - tracker.broadcast(packet); - } - } - -} diff --git a/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/VersionNMSManager.java b/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/VersionNMSManager.java index a0ab5dab..9230f456 100644 --- a/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/VersionNMSManager.java +++ b/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/VersionNMSManager.java @@ -5,155 +5,20 @@ */ package me.filoghost.holographicdisplays.nms.v1_8_R2; -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.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; +import me.filoghost.holographicdisplays.common.nms.EntityID; import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; -import me.filoghost.holographicdisplays.common.nms.SpawnFailedException; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntity; -import me.filoghost.holographicdisplays.common.nms.entity.NMSItem; -import net.minecraft.server.v1_8_R2.Entity; -import net.minecraft.server.v1_8_R2.EntityTypes; -import net.minecraft.server.v1_8_R2.MathHelper; -import net.minecraft.server.v1_8_R2.World; -import net.minecraft.server.v1_8_R2.WorldServer; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_8_R2.CraftWorld; -import org.bukkit.craftbukkit.v1_8_R2.entity.CraftEntity; -import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; -import org.bukkit.inventory.ItemStack; - -import java.util.Map; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; public class VersionNMSManager implements NMSManager { - private static final ReflectField, String>> ENTITY_NAMES_BY_CLASS_FIELD - = ReflectField.lookup(new ClassToken, String>>() {}, EntityTypes.class, "d"); - private static final ReflectField, Integer>> ENTITY_IDS_BY_CLASS_FIELD - = ReflectField.lookup(new ClassToken, Integer>>() {}, EntityTypes.class, "f"); - - private static final ReflectMethod REGISTER_ENTITY_METHOD = ReflectMethod.lookup(Object.class, World.class, "a", Entity.class); - - private final ProtocolPacketSettings protocolPacketSettings; - - public VersionNMSManager(ProtocolPacketSettings protocolPacketSettings) { - this.protocolPacketSettings = protocolPacketSettings; + @Override + public EntityID newEntityID() { + return null; } @Override - public void setup() throws Exception { - registerCustomEntity(EntityNMSArmorStand.class, "ArmorStand", 30); - registerCustomEntity(EntityNMSItem.class, "Item", 1); - registerCustomEntity(EntityNMSSlime.class, "Slime", 55); - } - - public void registerCustomEntity(Class entityClass, String name, int id) throws Exception { - ENTITY_NAMES_BY_CLASS_FIELD.getStatic().put(entityClass, name); - ENTITY_IDS_BY_CLASS_FIELD.getStatic().put(entityClass, id); - } - - @Override - public NMSItem spawnNMSItem( - org.bukkit.World bukkitWorld, double x, double y, double z, - StandardItemLine parentHologramLine, - ItemStack stack) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSItem item = new EntityNMSItem(nmsWorld, parentHologramLine); - 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 parentHologramLine) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSSlime slime = new EntityNMSSlime(nmsWorld, parentHologramLine); - 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 parentHologramLine) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) world).getHandle(); - EntityNMSArmorStand armorStand = new EntityNMSArmorStand(nmsWorld, parentHologramLine, protocolPacketSettings); - armorStand.setLocationNMS(x, y, z); - addEntityToWorld(nmsWorld, armorStand); - return armorStand; - } - - private void addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) throws SpawnFailedException { - Preconditions.checkState(Bukkit.isPrimaryThread(), "Async entity add"); - - 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); - final int chunkZ = MathHelper.floor(nmsEntity.locZ / 16.0); - - if (!nmsWorld.chunkProviderServer.isChunkLoaded(chunkX, chunkZ)) { - // This should never happen - nmsEntity.dead = true; - throw new SpawnFailedException(SpawnFailedException.CHUNK_NOT_LOADED); - } - - nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity); - nmsWorld.entityList.add(nmsEntity); - - try { - REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity); - } catch (ReflectiveOperationException e) { - 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 NMSEntity; - } - - @Override - public NMSEntity getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - - if (nmsEntity instanceof NMSEntity) { - return (NMSEntity) nmsEntity; - } else { - return null; - } - } - - @Override - public NMSEntity getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - Entity nmsEntity = nmsWorld.a(entityID); - - if (nmsEntity instanceof NMSEntity) { - return (NMSEntity) nmsEntity; - } else { - return null; - } - } - - @Override - public Object createCustomNameNMSObject(String customName) { - return EntityNMSArmorStand.createCustomNameNMSObject(customName); + public NMSPacketList createPacketList() { + return null; } } diff --git a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/CraftNMSArmorStand.java b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/CraftNMSArmorStand.java deleted file mode 100644 index 82c8597f..00000000 --- a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/CraftNMSArmorStand.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_8_R3; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_8_R3.CraftServer; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftArmorStand; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.ItemStack; -import org.bukkit.potion.PotionEffect; -import org.bukkit.util.EulerAngle; -import org.bukkit.util.Vector; - -import java.util.Collection; - -public class CraftNMSArmorStand extends CraftArmorStand { - - public CraftNMSArmorStand(CraftServer server, EntityNMSArmorStand entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // 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 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 effects) { return false; } - @Override public void setRemoveWhenFarAway(boolean remove) {} - - // Methods from Entity - @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 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 setLastDamageCause(EntityDamageEvent event) {} - -} diff --git a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/CraftNMSItem.java b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/CraftNMSItem.java deleted file mode 100644 index 1bd5a9bf..00000000 --- a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/CraftNMSItem.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_8_R3; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_8_R3.CraftServer; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftItem; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; - -public class CraftNMSItem extends CraftItem { - - public CraftNMSItem(CraftServer server, EntityNMSItem entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // Methods from Entity - @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 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 setLastDamageCause(EntityDamageEvent event) {} - - // Methods from Item - @Override public void setItemStack(ItemStack stack) {} - @Override public void setPickupDelay(int delay) {} -} diff --git a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/CraftNMSSlime.java b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/CraftNMSSlime.java deleted file mode 100644 index 52f89e15..00000000 --- a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/CraftNMSSlime.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_8_R3; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_8_R3.CraftServer; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftSlime; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.potion.PotionEffect; -import org.bukkit.util.Vector; - -import java.util.Collection; - -public class CraftNMSSlime extends CraftSlime { - - public CraftNMSSlime(CraftServer server, EntityNMSSlime entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // 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 effects) { return false; } - @Override public void setRemoveWhenFarAway(boolean remove) {} - - // Methods from Entity - @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 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 setLastDamageCause(EntityDamageEvent event) {} - - // Methods from Slime - @Override public void setSize(int size) {} -} diff --git a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityNMSArmorStand.java b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityNMSArmorStand.java deleted file mode 100644 index 0b098a13..00000000 --- a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityNMSArmorStand.java +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_8_R3; - -import me.filoghost.fcommons.Preconditions; -import me.filoghost.fcommons.Strings; -import me.filoghost.fcommons.reflection.ReflectField; -import me.filoghost.fcommons.reflection.ReflectMethod; -import me.filoghost.holographicdisplays.common.DebugLogger; -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntity; -import net.minecraft.server.v1_8_R3.AxisAlignedBB; -import net.minecraft.server.v1_8_R3.DamageSource; -import net.minecraft.server.v1_8_R3.Entity; -import net.minecraft.server.v1_8_R3.EntityArmorStand; -import net.minecraft.server.v1_8_R3.EntityHuman; -import net.minecraft.server.v1_8_R3.ItemStack; -import net.minecraft.server.v1_8_R3.NBTTagCompound; -import net.minecraft.server.v1_8_R3.PacketPlayOutEntityTeleport; -import net.minecraft.server.v1_8_R3.Vec3D; -import net.minecraft.server.v1_8_R3.World; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; -import org.bukkit.entity.Player; - -import java.util.Objects; - -public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand { - - private static final ReflectMethod SET_MARKER_METHOD - = ReflectMethod.lookup(void.class, EntityArmorStand.class, "n", boolean.class); - private static final ReflectField PASSENGER_PITCH_DELTA = ReflectField.lookup(double.class, Entity.class, "ar"); - private static final ReflectField PASSENGER_YAW_DELTA = ReflectField.lookup(double.class, Entity.class, "as"); - - private final StandardHologramLine parentHologramLine; - private final ProtocolPacketSettings protocolPacketSettings; - private final VersionNMSEntityHelper helper; - private String customName; - - public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, ProtocolPacketSettings protocolPacketSettings) { - super(world); - this.parentHologramLine = parentHologramLine; - this.protocolPacketSettings = protocolPacketSettings; - this.helper = new VersionNMSEntityHelper(this); - - super.setInvisible(true); - super.setSmall(true); - super.setArms(false); - super.setGravity(true); - super.setBasePlate(true); - try { - SET_MARKER_METHOD.invoke(this, true); - } catch (ReflectiveOperationException e) { - DebugLogger.cannotSetArmorStandAsMarker(e); - // It will still work, but the offset will be wrong - } - super.noclip = true; - super.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet - forceSetBoundingBox(new NullBoundingBox()); - } - - @Override - public void t_() { - // Disable normal ticking for this entity - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity - if (super.onGround) { - super.onGround = false; - } - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity - if (super.onGround) { - super.onGround = false; - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public void e(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public void setCustomName(String customName) { - // Prevents changes to custom name - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Prevents changes to custom name visibility - } - - @Override - public boolean a(EntityHuman human, Vec3D vec3d) { - // Prevent armor stand from being equipped - return true; - } - - @Override - public boolean d(int i, ItemStack item) { - // Prevent armor stand from being equipped - return false; - } - - @Override - public void setEquipment(int i, ItemStack item) { - // Prevent armor stand from being equipped - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Prevent changes to bounding box - } - - public void forceSetBoundingBox(AxisAlignedBB boundingBox) { - super.a(boundingBox); - } - - @Override - public void makeSound(String sound, float f1, float f2) { - // Remove sounds - } - - @Override - public void setCustomNameNMS(String customName) { - if (Objects.equals(this.customName, customName)) { - return; - } - this.customName = customName; - super.setCustomName(createCustomNameNMSObject(customName)); - super.setCustomNameVisible(customName != null && !customName.isEmpty()); - } - - protected static String createCustomNameNMSObject(String customName) { - return customName != null ? Strings.truncate(customName, 256) : ""; - } - - @Override - public String getCustomNameStringNMS() { - return this.customName; - } - - @Override - public String getCustomNameObjectNMS() { - return super.getCustomName(); - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSArmorStand(super.world.getServer(), this); - } - return super.bukkitEntity; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - if (protocolPacketSettings.sendAccurateLocationPackets()) { - helper.broadcastPacket(new PacketPlayOutEntityTeleport(this)); - } - } - - @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; - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - -} diff --git a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityNMSItem.java b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityNMSItem.java deleted file mode 100644 index b6f41bf3..00000000 --- a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityNMSItem.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_8_R3; - -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; -import me.filoghost.holographicdisplays.common.nms.NMSCommons; -import me.filoghost.holographicdisplays.common.nms.entity.NMSItem; -import net.minecraft.server.v1_8_R3.Blocks; -import net.minecraft.server.v1_8_R3.DamageSource; -import net.minecraft.server.v1_8_R3.EntityHuman; -import net.minecraft.server.v1_8_R3.EntityItem; -import net.minecraft.server.v1_8_R3.EntityPlayer; -import net.minecraft.server.v1_8_R3.ItemStack; -import net.minecraft.server.v1_8_R3.NBTTagCompound; -import net.minecraft.server.v1_8_R3.NBTTagList; -import net.minecraft.server.v1_8_R3.NBTTagString; -import net.minecraft.server.v1_8_R3.World; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack; -import org.bukkit.entity.Player; - -public class EntityNMSItem extends EntityItem implements NMSItem { - - private final StandardItemLine parentHologramLine; - private final VersionNMSEntityHelper helper; - - public EntityNMSItem(World world, StandardItemLine parentHologramLine) { - super(world); - this.parentHologramLine = parentHologramLine; - this.helper = new VersionNMSEntityHelper(this); - - super.pickupDelay = Integer.MAX_VALUE; - } - - @Override - public void t_() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - // Method called when a player is near - @Override - public void d(EntityHuman human) { - if (human.locY < this.locY - 1.5 || human.locY > this.locY + 1.0) { - // Too low or too high, it's a bit weird - return; - } - - if (human instanceof EntityPlayer) { - parentHologramLine.onPickup(((EntityPlayer) human).getBukkitEntity()); - // It is never added to the inventory - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public void e(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public boolean isAlive() { - // This override prevents items from being picked up by hoppers (should have no side effects) - return false; - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSItem(super.world.getServer(), this); - } - return super.bukkitEntity; - } - - @Override - public boolean isDeadNMS() { - return this.dead; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - } - - @Override - public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) { - ItemStack newItem = CraftItemStack.asNMSCopy(stack); - - if (newItem == null) { - newItem = new ItemStack(Blocks.BEDROCK); - } - - if (newItem.getTag() == null) { - newItem.setTag(new NBTTagCompound()); - } - NBTTagCompound display = newItem.getTag().getCompound("display"); - - if (!newItem.getTag().hasKey("display")) { - newItem.getTag().set("display", display); - } - - NBTTagList tagList = new NBTTagList(); - tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE)); - display.set("Lore", tagList); - - super.setItemStack(newItem); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - - @Override - public Object getRawItemStack() { - return super.getItemStack(); - } - -} diff --git a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityNMSSlime.java b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityNMSSlime.java deleted file mode 100644 index 82f767e4..00000000 --- a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityNMSSlime.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_8_R3; - -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.nms.entity.NMSSlime; -import net.minecraft.server.v1_8_R3.AxisAlignedBB; -import net.minecraft.server.v1_8_R3.DamageSource; -import net.minecraft.server.v1_8_R3.EntityDamageSource; -import net.minecraft.server.v1_8_R3.EntityPlayer; -import net.minecraft.server.v1_8_R3.EntitySlime; -import net.minecraft.server.v1_8_R3.NBTTagCompound; -import net.minecraft.server.v1_8_R3.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.player.PlayerInteractEntityEvent; - -public class EntityNMSSlime extends EntitySlime implements NMSSlime { - - private final StandardHologramLine parentHologramLine; - private final VersionNMSEntityHelper helper; - - public EntityNMSSlime(World world, StandardHologramLine parentHologramLine) { - super(world); - this.parentHologramLine = parentHologramLine; - this.helper = new VersionNMSEntityHelper(this); - - super.persistent = true; - super.noclip = true; - super.a(0.0F, 0.0F); - super.setSize(1); - super.setInvisible(true); - forceSetBoundingBox(new NullBoundingBox()); - } - - @Override - public void t_() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - - // The slime dies without a vehicle - if (super.vehicle == null) { - killEntityNMS(); - } - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Prevent changes to bounding box - } - - public void forceSetBoundingBox(AxisAlignedBB boundingBox) { - super.a(boundingBox); - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public void e(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean damageEntity(DamageSource damageSource, float amount) { - if (damageSource instanceof EntityDamageSource) { - EntityDamageSource entityDamageSource = (EntityDamageSource) damageSource; - if (entityDamageSource.getEntity() instanceof EntityPlayer) { - Player player = ((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(); - PlayerInteractEntityEvent event = new PlayerInteractEntityEvent(player, getBukkitEntity()); - Bukkit.getPluginManager().callEvent(event); // Bukkit takes care of the exceptions - } - } - return false; - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public void setCustomName(String customName) { - // Prevents changes to custom name - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Prevents changes to custom name visibility - } - - @Override - public void makeSound(String sound, float volume, float pitch) { - // Remove sounds - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSSlime(super.world.getServer(), this); - } - return super.bukkitEntity; - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - -} diff --git a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/NullBoundingBox.java b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/NullBoundingBox.java deleted file mode 100644 index e524a5b4..00000000 --- a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/NullBoundingBox.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_8_R3; - -import net.minecraft.server.v1_8_R3.AxisAlignedBB; -import net.minecraft.server.v1_8_R3.MovingObjectPosition; -import net.minecraft.server.v1_8_R3.Vec3D; - -public class NullBoundingBox extends AxisAlignedBB { - - public NullBoundingBox() { - super(0, 0, 0, 0, 0, 0); - } - - @Override - public double a() { - return 0.0; - } - - @Override - public double a(AxisAlignedBB arg0, double arg1) { - return 0.0; - } - - @Override - public AxisAlignedBB a(AxisAlignedBB arg0) { - return this; - } - - @Override - public AxisAlignedBB a(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public MovingObjectPosition a(Vec3D arg0, Vec3D arg1) { - return super.a(arg0, arg1); - } - - @Override - public boolean a(Vec3D arg0) { - return false; - } - - @Override - public double b(AxisAlignedBB arg0, double arg1) { - return 0.0; - } - - @Override - public boolean b(AxisAlignedBB arg0) { - return false; - } - - @Override - public double c(AxisAlignedBB arg0, double arg1) { - return 0.0; - } - - @Override - public AxisAlignedBB c(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public AxisAlignedBB grow(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public AxisAlignedBB shrink(double arg0, double arg1, double arg2) { - return this; - } - -} diff --git a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionNMSEntityHelper.java b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionNMSEntityHelper.java deleted file mode 100644 index 9e8c13e8..00000000 --- a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionNMSEntityHelper.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_8_R3; - -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntityHelper; -import net.minecraft.server.v1_8_R3.Entity; -import net.minecraft.server.v1_8_R3.EntityTrackerEntry; -import net.minecraft.server.v1_8_R3.Packet; -import net.minecraft.server.v1_8_R3.WorldServer; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; -import org.bukkit.entity.Player; - -public class VersionNMSEntityHelper extends NMSEntityHelper { - - private final Entity entity; - - public VersionNMSEntityHelper(Entity entity) { - this.entity = entity; - } - - @Override - protected EntityTrackerEntry getTracker0() { - return ((WorldServer) entity.world).tracker.trackedEntities.get(entity.getId()); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - EntityTrackerEntry tracker = getTracker(); - if (tracker != null) { - return tracker.trackedPlayers.contains(((CraftPlayer) bukkitPlayer).getHandle()); - } else { - return false; - } - } - - public void broadcastPacket(Packet packet) { - EntityTrackerEntry tracker = getTracker(); - if (tracker != null) { - tracker.broadcast(packet); - } - } - -} diff --git a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionNMSManager.java b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionNMSManager.java index 3c0fa6fc..7d4e5b9d 100644 --- a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionNMSManager.java +++ b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionNMSManager.java @@ -5,155 +5,20 @@ */ package me.filoghost.holographicdisplays.nms.v1_8_R3; -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.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; +import me.filoghost.holographicdisplays.common.nms.EntityID; import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; -import me.filoghost.holographicdisplays.common.nms.SpawnFailedException; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntity; -import me.filoghost.holographicdisplays.common.nms.entity.NMSItem; -import net.minecraft.server.v1_8_R3.Entity; -import net.minecraft.server.v1_8_R3.EntityTypes; -import net.minecraft.server.v1_8_R3.MathHelper; -import net.minecraft.server.v1_8_R3.World; -import net.minecraft.server.v1_8_R3.WorldServer; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; -import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; -import org.bukkit.inventory.ItemStack; - -import java.util.Map; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; public class VersionNMSManager implements NMSManager { - private static final ReflectField, String>> ENTITY_NAMES_BY_CLASS_FIELD - = ReflectField.lookup(new ClassToken, String>>() {}, EntityTypes.class, "d"); - private static final ReflectField, Integer>> ENTITY_IDS_BY_CLASS_FIELD - = ReflectField.lookup(new ClassToken, Integer>>() {}, EntityTypes.class, "f"); - - private static final ReflectMethod REGISTER_ENTITY_METHOD = ReflectMethod.lookup(Object.class, World.class, "a", Entity.class); - - private final ProtocolPacketSettings protocolPacketSettings; - - public VersionNMSManager(ProtocolPacketSettings protocolPacketSettings) { - this.protocolPacketSettings = protocolPacketSettings; + @Override + public EntityID newEntityID() { + return null; } @Override - public void setup() throws Exception { - registerCustomEntity(EntityNMSArmorStand.class, "ArmorStand", 30); - registerCustomEntity(EntityNMSItem.class, "Item", 1); - registerCustomEntity(EntityNMSSlime.class, "Slime", 55); - } - - public void registerCustomEntity(Class entityClass, String name, int id) throws Exception { - ENTITY_NAMES_BY_CLASS_FIELD.getStatic().put(entityClass, name); - ENTITY_IDS_BY_CLASS_FIELD.getStatic().put(entityClass, id); - } - - @Override - public NMSItem spawnNMSItem( - org.bukkit.World bukkitWorld, double x, double y, double z, - StandardItemLine parentHologramLine, - ItemStack stack) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSItem item = new EntityNMSItem(nmsWorld, parentHologramLine); - 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 parentHologramLine) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSSlime slime = new EntityNMSSlime(nmsWorld, parentHologramLine); - 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 parentHologramLine) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) world).getHandle(); - EntityNMSArmorStand armorStand = new EntityNMSArmorStand(nmsWorld, parentHologramLine, protocolPacketSettings); - armorStand.setLocationNMS(x, y, z); - addEntityToWorld(nmsWorld, armorStand); - return armorStand; - } - - private void addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) throws SpawnFailedException { - Preconditions.checkState(Bukkit.isPrimaryThread(), "Async entity add"); - - 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); - final int chunkZ = MathHelper.floor(nmsEntity.locZ / 16.0); - - if (!nmsWorld.chunkProviderServer.isChunkLoaded(chunkX, chunkZ)) { - // This should never happen - nmsEntity.dead = true; - throw new SpawnFailedException(SpawnFailedException.CHUNK_NOT_LOADED); - } - - nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity); - nmsWorld.entityList.add(nmsEntity); - - try { - REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity); - } catch (ReflectiveOperationException e) { - 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 NMSEntity; - } - - @Override - public NMSEntity getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - - if (nmsEntity instanceof NMSEntity) { - return (NMSEntity) nmsEntity; - } else { - return null; - } - } - - @Override - public NMSEntity getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - Entity nmsEntity = nmsWorld.a(entityID); - - if (nmsEntity instanceof NMSEntity) { - return (NMSEntity) nmsEntity; - } else { - return null; - } - } - - @Override - public Object createCustomNameNMSObject(String customName) { - return EntityNMSArmorStand.createCustomNameNMSObject(customName); + public NMSPacketList createPacketList() { + return null; } } diff --git a/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/CraftNMSArmorStand.java b/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/CraftNMSArmorStand.java deleted file mode 100644 index fd35074d..00000000 --- a/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/CraftNMSArmorStand.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_9_R1; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_9_R1.CraftServer; -import org.bukkit.craftbukkit.v1_9_R1.entity.CraftArmorStand; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.ItemStack; -import org.bukkit.potion.PotionEffect; -import org.bukkit.util.EulerAngle; -import org.bukkit.util.Vector; - -import java.util.Collection; - -public class CraftNMSArmorStand extends CraftArmorStand { - - public CraftNMSArmorStand(CraftServer server, EntityNMSArmorStand entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // 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 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 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 effects) { return false; } - @Override public void setRemoveWhenFarAway(boolean remove) {} - - // Methods from Entity - @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 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 setLastDamageCause(EntityDamageEvent event) {} - -} diff --git a/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/CraftNMSItem.java b/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/CraftNMSItem.java deleted file mode 100644 index 491695fa..00000000 --- a/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/CraftNMSItem.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_9_R1; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_9_R1.CraftServer; -import org.bukkit.craftbukkit.v1_9_R1.entity.CraftItem; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; - -public class CraftNMSItem extends CraftItem { - - public CraftNMSItem(CraftServer server, EntityNMSItem entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // Methods from Entity - @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 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 setLastDamageCause(EntityDamageEvent event) {} - - // Methods from Item - @Override public void setItemStack(ItemStack stack) {} - @Override public void setPickupDelay(int delay) {} - -} diff --git a/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/CraftNMSSlime.java b/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/CraftNMSSlime.java deleted file mode 100644 index 0f10252d..00000000 --- a/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/CraftNMSSlime.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_9_R1; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_9_R1.CraftServer; -import org.bukkit.craftbukkit.v1_9_R1.entity.CraftSlime; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.potion.PotionEffect; -import org.bukkit.util.Vector; - -import java.util.Collection; - -public class CraftNMSSlime extends CraftSlime { - - public CraftNMSSlime(CraftServer server, EntityNMSSlime entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // 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 effects) { return false; } - @Override public void setRemoveWhenFarAway(boolean remove) {} - - // Methods from Entity - @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 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 setLastDamageCause(EntityDamageEvent event) {} - - // Methods from Slime - @Override public void setSize(int size) {} - -} diff --git a/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/EntityNMSArmorStand.java b/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/EntityNMSArmorStand.java deleted file mode 100644 index 17bfa3c7..00000000 --- a/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/EntityNMSArmorStand.java +++ /dev/null @@ -1,261 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_9_R1; - -import me.filoghost.fcommons.Preconditions; -import me.filoghost.fcommons.Strings; -import me.filoghost.fcommons.reflection.ReflectField; -import me.filoghost.holographicdisplays.common.DebugLogger; -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntity; -import net.minecraft.server.v1_9_R1.AxisAlignedBB; -import net.minecraft.server.v1_9_R1.DamageSource; -import net.minecraft.server.v1_9_R1.Entity; -import net.minecraft.server.v1_9_R1.EntityArmorStand; -import net.minecraft.server.v1_9_R1.EntityHuman; -import net.minecraft.server.v1_9_R1.EnumHand; -import net.minecraft.server.v1_9_R1.EnumInteractionResult; -import net.minecraft.server.v1_9_R1.EnumItemSlot; -import net.minecraft.server.v1_9_R1.ItemStack; -import net.minecraft.server.v1_9_R1.NBTTagCompound; -import net.minecraft.server.v1_9_R1.PacketPlayOutEntityTeleport; -import net.minecraft.server.v1_9_R1.SoundEffect; -import net.minecraft.server.v1_9_R1.Vec3D; -import net.minecraft.server.v1_9_R1.World; -import org.bukkit.craftbukkit.v1_9_R1.entity.CraftEntity; -import org.bukkit.entity.Player; - -import java.util.Objects; - -public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand { - - private static final ReflectField VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "as"); - - private final StandardHologramLine parentHologramLine; - private final ProtocolPacketSettings protocolPacketSettings; - private final VersionNMSEntityHelper helper; - - private String customName; - - public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, ProtocolPacketSettings protocolPacketSettings) { - super(world); - this.parentHologramLine = parentHologramLine; - this.protocolPacketSettings = protocolPacketSettings; - this.helper = new VersionNMSEntityHelper(this); - - super.setInvisible(true); - super.setSmall(true); - super.setArms(false); - super.setGravity(true); - super.setBasePlate(true); - super.setMarker(true); - super.collides = false; - super.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet - forceSetBoundingBox(new NullBoundingBox()); - } - - @Override - public void m() { - // Disable normal ticking for this entity - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity - if (super.onGround) { - super.onGround = false; - } - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity - if (super.onGround) { - super.onGround = false; - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public void e(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public void f(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void a(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void setCustomName(String customName) { - // Prevents changes to custom name - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Prevents changes to custom name visibility - } - - @Override - public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, ItemStack itemstack, EnumHand enumhand) { - // Prevent armor stand from being equipped - return EnumInteractionResult.PASS; - } - - @Override - public boolean c(int i, ItemStack item) { - // Prevent armor stand from being equipped - return false; - } - - @Override - public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { - // Prevent armor stand from being equipped - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Prevent changes to bounding box - } - - public void forceSetBoundingBox(AxisAlignedBB boundingBox) { - super.a(boundingBox); - } - - @Override - public void a(SoundEffect soundeffect, float f, float f1) { - // Remove sounds - } - - @Override - public void setCustomNameNMS(String customName) { - if (Objects.equals(this.customName, customName)) { - return; - } - this.customName = customName; - super.setCustomName(createCustomNameNMSObject(customName)); - super.setCustomNameVisible(customName != null && !customName.isEmpty()); - } - - protected static String createCustomNameNMSObject(String customName) { - return customName != null ? Strings.truncate(customName, 256) : ""; - } - - @Override - public String getCustomNameStringNMS() { - return this.customName; - } - - @Override - public String getCustomNameObjectNMS() { - return super.getCustomName(); - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSArmorStand(super.world.getServer(), this); - } - return super.bukkitEntity; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - if (protocolPacketSettings.sendAccurateLocationPackets()) { - helper.broadcastPacket(new PacketPlayOutEntityTeleport(this)); - } - } - - @Override - public void setPassengerNMS(NMSEntity passenger) { - Preconditions.checkArgument(passenger instanceof Entity); - Entity passengerEntity = (Entity) passenger; - Preconditions.checkArgument(passengerEntity.by() == null); - Preconditions.checkState(super.passengers.isEmpty()); - - try { - VEHICLE_FIELD.set(passenger, this); - this.passengers.add(passengerEntity); - } catch (ReflectiveOperationException e) { - DebugLogger.cannotSetPassenger(e); - } - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - -} diff --git a/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/EntityNMSItem.java b/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/EntityNMSItem.java deleted file mode 100644 index 97c0f843..00000000 --- a/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/EntityNMSItem.java +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_9_R1; - -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; -import me.filoghost.holographicdisplays.common.nms.NMSCommons; -import me.filoghost.holographicdisplays.common.nms.entity.NMSItem; -import net.minecraft.server.v1_9_R1.Blocks; -import net.minecraft.server.v1_9_R1.DamageSource; -import net.minecraft.server.v1_9_R1.Entity; -import net.minecraft.server.v1_9_R1.EntityHuman; -import net.minecraft.server.v1_9_R1.EntityItem; -import net.minecraft.server.v1_9_R1.EntityPlayer; -import net.minecraft.server.v1_9_R1.ItemStack; -import net.minecraft.server.v1_9_R1.NBTTagCompound; -import net.minecraft.server.v1_9_R1.NBTTagList; -import net.minecraft.server.v1_9_R1.NBTTagString; -import net.minecraft.server.v1_9_R1.PacketPlayOutMount; -import net.minecraft.server.v1_9_R1.World; -import org.bukkit.craftbukkit.v1_9_R1.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftItemStack; -import org.bukkit.entity.Player; - -public class EntityNMSItem extends EntityItem implements NMSItem { - - private final StandardItemLine parentHologramLine; - private final VersionNMSEntityHelper helper; - - private int resendMountPacketTicks; - - public EntityNMSItem(World world, StandardItemLine parentHologramLine) { - super(world); - this.parentHologramLine = parentHologramLine; - this.helper = new VersionNMSEntityHelper(this); - - super.pickupDelay = Integer.MAX_VALUE; - } - - @Override - public void m() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - - if (resendMountPacketTicks++ > 20) { - resendMountPacketTicks = 0; - - Entity vehicle = by(); - if (vehicle != null) { - // Send a packet near to "remind" players that the item is riding the armor stand (Spigot bug or client bug) - helper.broadcastPacket(new PacketPlayOutMount(vehicle)); - } - } - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - // Method called when a player is near - @Override - public void d(EntityHuman human) { - if (human.locY < super.locY - 1.5 || human.locY > super.locY + 1.0) { - // Too low or too high, it's a bit weird - return; - } - - if (human instanceof EntityPlayer) { - parentHologramLine.onPickup(((EntityPlayer) human).getBukkitEntity()); - // It is never added to the inventory - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public void e(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public void f(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void a(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public boolean isAlive() { - // This override prevents items from being picked up by hoppers (should have no side effects) - return false; - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSItem(super.world.getServer(), this); - } - return super.bukkitEntity; - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - } - - @Override - public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) { - ItemStack newItem = CraftItemStack.asNMSCopy(stack); - - if (newItem == null) { - newItem = new ItemStack(Blocks.BEDROCK); - } - - if (newItem.getTag() == null) { - newItem.setTag(new NBTTagCompound()); - } - NBTTagCompound display = newItem.getTag().getCompound("display"); - - if (!newItem.getTag().hasKey("display")) { - newItem.getTag().set("display", display); - } - - NBTTagList tagList = new NBTTagList(); - tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE)); - display.set("Lore", tagList); - - super.setItemStack(newItem); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - - @Override - public Object getRawItemStack() { - return super.getItemStack(); - } - -} diff --git a/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/EntityNMSSlime.java b/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/EntityNMSSlime.java deleted file mode 100644 index 3bf4a83d..00000000 --- a/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/EntityNMSSlime.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_9_R1; - -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.nms.entity.NMSSlime; -import net.minecraft.server.v1_9_R1.AxisAlignedBB; -import net.minecraft.server.v1_9_R1.DamageSource; -import net.minecraft.server.v1_9_R1.Entity; -import net.minecraft.server.v1_9_R1.EntityDamageSource; -import net.minecraft.server.v1_9_R1.EntityPlayer; -import net.minecraft.server.v1_9_R1.EntitySlime; -import net.minecraft.server.v1_9_R1.NBTTagCompound; -import net.minecraft.server.v1_9_R1.PacketPlayOutMount; -import net.minecraft.server.v1_9_R1.SoundEffect; -import net.minecraft.server.v1_9_R1.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_9_R1.entity.CraftEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.player.PlayerInteractEntityEvent; - -public class EntityNMSSlime extends EntitySlime implements NMSSlime { - - private final StandardHologramLine parentHologramLine; - private final VersionNMSEntityHelper helper; - - private int resendMountPacketTicks; - - public EntityNMSSlime(World world, StandardHologramLine parentHologramLine) { - super(world); - this.parentHologramLine = parentHologramLine; - this.helper = new VersionNMSEntityHelper(this); - - super.persistent = true; - super.collides = false; - super.a(0.0F, 0.0F); - super.setSize(1); - super.setInvisible(true); - forceSetBoundingBox(new NullBoundingBox()); - } - - @Override - public void m() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - - if (resendMountPacketTicks++ > 20) { - resendMountPacketTicks = 0; - - Entity vehicle = by(); - if (vehicle != null) { - // Send a packet near to "remind" players that the slime is riding the armor stand (Spigot bug or client bug) - helper.broadcastPacket(new PacketPlayOutMount(vehicle)); - } - } - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Prevent changes to bounding box - } - - public void forceSetBoundingBox(AxisAlignedBB boundingBox) { - super.a(boundingBox); - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public void e(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public void f(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void a(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean damageEntity(DamageSource damageSource, float amount) { - if (damageSource instanceof EntityDamageSource) { - EntityDamageSource entityDamageSource = (EntityDamageSource) damageSource; - if (entityDamageSource.getEntity() instanceof EntityPlayer) { - Player player = ((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(); - PlayerInteractEntityEvent event = new PlayerInteractEntityEvent(player, getBukkitEntity()); - Bukkit.getPluginManager().callEvent(event); // Bukkit takes care of the exceptions - } - } - return false; - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void setCustomName(String customName) { - // Prevents changes to custom name - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Prevents changes to custom name visibility - } - - @Override - public void a(SoundEffect soundeffect, float f, float f1) { - // Remove sounds - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSSlime(super.world.getServer(), this); - } - return super.bukkitEntity; - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - -} diff --git a/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/NullBoundingBox.java b/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/NullBoundingBox.java deleted file mode 100644 index 90110ead..00000000 --- a/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/NullBoundingBox.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_9_R1; - -import net.minecraft.server.v1_9_R1.AxisAlignedBB; -import net.minecraft.server.v1_9_R1.BlockPosition; -import net.minecraft.server.v1_9_R1.MovingObjectPosition; -import net.minecraft.server.v1_9_R1.Vec3D; - -public class NullBoundingBox extends AxisAlignedBB { - - public NullBoundingBox() { - super(0, 0, 0, 0, 0, 0); - } - - @Override - public double a() { - return 0.0; - } - - @Override - public double a(AxisAlignedBB arg0, double arg1) { - return 0.0; - } - - @Override - public AxisAlignedBB a(AxisAlignedBB arg0) { - return this; - } - - @Override - public AxisAlignedBB a(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public MovingObjectPosition a(Vec3D arg0, Vec3D arg1) { - return super.a(arg0, arg1); - } - - @Override - public boolean a(Vec3D arg0) { - return false; - } - - @Override - public double b(AxisAlignedBB arg0, double arg1) { - return 0.0; - } - - @Override - public boolean b(AxisAlignedBB arg0) { - return false; - } - - @Override - public double c(AxisAlignedBB arg0, double arg1) { - return 0.0; - } - - @Override - public AxisAlignedBB c(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public AxisAlignedBB grow(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public AxisAlignedBB shrink(double arg0) { - return this; - } - - @Override - public AxisAlignedBB a(BlockPosition arg0) { - return this; - } - - @Override - public boolean a(double arg0, double arg1, double arg2, double arg3, double arg4, double arg5) { - return false; - } - - @Override - public boolean b(Vec3D arg0) { - return false; - } - - @Override - public boolean c(Vec3D arg0) { - return false; - } - - @Override - public boolean d(Vec3D arg0) { - return false; - } - - @Override - public AxisAlignedBB e(double arg0) { - return this; - } - - @Override - public AxisAlignedBB g(double arg0) { - return this; - } - -} diff --git a/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/VersionNMSEntityHelper.java b/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/VersionNMSEntityHelper.java deleted file mode 100644 index 7e6050f5..00000000 --- a/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/VersionNMSEntityHelper.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_9_R1; - -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntityHelper; -import net.minecraft.server.v1_9_R1.Entity; -import net.minecraft.server.v1_9_R1.EntityTrackerEntry; -import net.minecraft.server.v1_9_R1.Packet; -import net.minecraft.server.v1_9_R1.WorldServer; -import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; - -public class VersionNMSEntityHelper extends NMSEntityHelper { - - private final Entity entity; - - public VersionNMSEntityHelper(Entity entity) { - this.entity = entity; - } - - @Override - protected EntityTrackerEntry getTracker0() { - return ((WorldServer) entity.world).tracker.trackedEntities.get(entity.getId()); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - EntityTrackerEntry tracker = getTracker(); - if (tracker != null) { - return tracker.trackedPlayers.contains(((CraftPlayer) bukkitPlayer).getHandle()); - } else { - return false; - } - } - - public void broadcastPacket(Packet packet) { - EntityTrackerEntry tracker = getTracker(); - if (tracker != null) { - tracker.broadcast(packet); - } - } - -} diff --git a/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/VersionNMSManager.java b/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/VersionNMSManager.java index a5139bb6..9163f65d 100644 --- a/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/VersionNMSManager.java +++ b/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/VersionNMSManager.java @@ -5,146 +5,20 @@ */ package me.filoghost.holographicdisplays.nms.v1_9_R1; -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.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; +import me.filoghost.holographicdisplays.common.nms.EntityID; import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; -import me.filoghost.holographicdisplays.common.nms.SpawnFailedException; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntity; -import me.filoghost.holographicdisplays.common.nms.entity.NMSItem; -import net.minecraft.server.v1_9_R1.Entity; -import net.minecraft.server.v1_9_R1.EntityTypes; -import net.minecraft.server.v1_9_R1.MathHelper; -import net.minecraft.server.v1_9_R1.World; -import net.minecraft.server.v1_9_R1.WorldServer; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_9_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_9_R1.entity.CraftEntity; -import org.bukkit.inventory.ItemStack; - -import java.util.Map; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; public class VersionNMSManager implements NMSManager { - private static final ReflectField, String>> ENTITY_NAMES_BY_CLASS_FIELD - = ReflectField.lookup(new ClassToken, String>>() {}, EntityTypes.class, "d"); - private static final ReflectField, Integer>> ENTITY_IDS_BY_CLASS_FIELD - = ReflectField.lookup(new ClassToken, Integer>>() {}, EntityTypes.class, "f"); - - private static final ReflectMethod REGISTER_ENTITY_METHOD = ReflectMethod.lookup(Object.class, World.class, "b", Entity.class); - - private final ProtocolPacketSettings protocolPacketSettings; - - public VersionNMSManager(ProtocolPacketSettings protocolPacketSettings) { - this.protocolPacketSettings = protocolPacketSettings; + @Override + public EntityID newEntityID() { + return null; } @Override - public void setup() throws Exception { - registerCustomEntity(EntityNMSArmorStand.class, "ArmorStand", 30); - registerCustomEntity(EntityNMSItem.class, "Item", 1); - registerCustomEntity(EntityNMSSlime.class, "Slime", 55); - } - - public void registerCustomEntity(Class entityClass, String name, int id) throws Exception { - ENTITY_NAMES_BY_CLASS_FIELD.getStatic().put(entityClass, name); - ENTITY_IDS_BY_CLASS_FIELD.getStatic().put(entityClass, id); - } - - @Override - public NMSItem spawnNMSItem( - org.bukkit.World bukkitWorld, double x, double y, double z, - StandardItemLine parentHologramLine, - ItemStack stack) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSItem item = new EntityNMSItem(nmsWorld, parentHologramLine); - 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 parentHologramLine) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSSlime slime = new EntityNMSSlime(nmsWorld, parentHologramLine); - 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 parentHologramLine) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) world).getHandle(); - EntityNMSArmorStand armorStand = new EntityNMSArmorStand(nmsWorld, parentHologramLine, protocolPacketSettings); - armorStand.setLocationNMS(x, y, z); - addEntityToWorld(nmsWorld, armorStand); - return armorStand; - } - - 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); - final int chunkZ = MathHelper.floor(nmsEntity.locZ / 16.0); - - if (!nmsWorld.getChunkProviderServer().isChunkLoaded(chunkX, chunkZ)) { - // This should never happen - nmsEntity.dead = true; - throw new SpawnFailedException(SpawnFailedException.CHUNK_NOT_LOADED); - } - - nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity); - nmsWorld.entityList.add(nmsEntity); - - try { - REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity); - } catch (ReflectiveOperationException e) { - 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 NMSEntity; - } - - @Override - public NMSEntity getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - - if (nmsEntity instanceof NMSEntity) { - return (NMSEntity) nmsEntity; - } else { - return null; - } - } - - @Override - public NMSEntity getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - Entity nmsEntity = nmsWorld.getEntity(entityID); - - if (nmsEntity instanceof NMSEntity) { - return (NMSEntity) nmsEntity; - } else { - return null; - } - } - - @Override - public Object createCustomNameNMSObject(String customName) { - return EntityNMSArmorStand.createCustomNameNMSObject(customName); + public NMSPacketList createPacketList() { + return null; } } diff --git a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/CraftNMSArmorStand.java b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/CraftNMSArmorStand.java deleted file mode 100644 index 63b34dba..00000000 --- a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/CraftNMSArmorStand.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_9_R2; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_9_R2.CraftServer; -import org.bukkit.craftbukkit.v1_9_R2.entity.CraftArmorStand; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.ItemStack; -import org.bukkit.potion.PotionEffect; -import org.bukkit.util.EulerAngle; -import org.bukkit.util.Vector; - -import java.util.Collection; - -public class CraftNMSArmorStand extends CraftArmorStand { - - public CraftNMSArmorStand(CraftServer server, EntityNMSArmorStand entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // 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 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 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 effects) { return false; } - @Override public void setRemoveWhenFarAway(boolean remove) {} - - // Methods from Entity - @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 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 setLastDamageCause(EntityDamageEvent event) {} - -} diff --git a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/CraftNMSItem.java b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/CraftNMSItem.java deleted file mode 100644 index fc78fc37..00000000 --- a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/CraftNMSItem.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_9_R2; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_9_R2.CraftServer; -import org.bukkit.craftbukkit.v1_9_R2.entity.CraftItem; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; - -public class CraftNMSItem extends CraftItem { - - public CraftNMSItem(CraftServer server, EntityNMSItem entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // Methods from Entity - @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 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 setLastDamageCause(EntityDamageEvent event) {} - - // Methods from Item - @Override public void setItemStack(ItemStack stack) {} - @Override public void setPickupDelay(int delay) {} - -} diff --git a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/CraftNMSSlime.java b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/CraftNMSSlime.java deleted file mode 100644 index 7cc4ca43..00000000 --- a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/CraftNMSSlime.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_9_R2; - -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_9_R2.CraftServer; -import org.bukkit.craftbukkit.v1_9_R2.entity.CraftSlime; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.potion.PotionEffect; -import org.bukkit.util.Vector; - -import java.util.Collection; - -public class CraftNMSSlime extends CraftSlime { - - public CraftNMSSlime(CraftServer server, EntityNMSSlime entity) { - super(server, entity); - } - - // Disallow all the bukkit methods - - @Override - public void remove() { - // Cannot be removed, this is the most important to override - } - - // 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 effects) { return false; } - @Override public void setRemoveWhenFarAway(boolean remove) {} - - // Methods from Entity - @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 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 setLastDamageCause(EntityDamageEvent event) {} - - // Methods from Slime - @Override public void setSize(int size) {} - -} diff --git a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityNMSArmorStand.java b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityNMSArmorStand.java deleted file mode 100644 index 07acd261..00000000 --- a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityNMSArmorStand.java +++ /dev/null @@ -1,261 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_9_R2; - -import me.filoghost.fcommons.Preconditions; -import me.filoghost.fcommons.Strings; -import me.filoghost.fcommons.reflection.ReflectField; -import me.filoghost.holographicdisplays.common.DebugLogger; -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntity; -import net.minecraft.server.v1_9_R2.AxisAlignedBB; -import net.minecraft.server.v1_9_R2.DamageSource; -import net.minecraft.server.v1_9_R2.Entity; -import net.minecraft.server.v1_9_R2.EntityArmorStand; -import net.minecraft.server.v1_9_R2.EntityHuman; -import net.minecraft.server.v1_9_R2.EnumHand; -import net.minecraft.server.v1_9_R2.EnumInteractionResult; -import net.minecraft.server.v1_9_R2.EnumItemSlot; -import net.minecraft.server.v1_9_R2.ItemStack; -import net.minecraft.server.v1_9_R2.NBTTagCompound; -import net.minecraft.server.v1_9_R2.PacketPlayOutEntityTeleport; -import net.minecraft.server.v1_9_R2.SoundEffect; -import net.minecraft.server.v1_9_R2.Vec3D; -import net.minecraft.server.v1_9_R2.World; -import org.bukkit.craftbukkit.v1_9_R2.entity.CraftEntity; -import org.bukkit.entity.Player; - -import java.util.Objects; - -public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand { - - private static final ReflectField VEHICLE_FIELD = ReflectField.lookup(Entity.class, Entity.class, "at"); - - private final StandardHologramLine parentHologramLine; - private final ProtocolPacketSettings protocolPacketSettings; - private final VersionNMSEntityHelper helper; - private String customName; - - public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, ProtocolPacketSettings protocolPacketSettings) { - super(world); - this.parentHologramLine = parentHologramLine; - this.protocolPacketSettings = protocolPacketSettings; - this.helper = new VersionNMSEntityHelper(this); - - super.setInvisible(true); - super.setSmall(true); - super.setArms(false); - super.setGravity(true); - super.setBasePlate(true); - super.setMarker(true); - super.collides = false; - super.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet - forceSetBoundingBox(new NullBoundingBox()); - } - - @Override - public void m() { - // Disable normal ticking for this entity - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity - if (super.onGround) { - super.onGround = false; - } - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity - if (super.onGround) { - super.onGround = false; - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound e(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void f(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void a(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void setCustomName(String customName) { - // Prevents changes to custom name - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Prevents changes to custom name visibility - } - - @Override - public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, ItemStack itemstack, EnumHand enumhand) { - // Prevent armor stand from being equipped - return EnumInteractionResult.PASS; - } - - @Override - public boolean c(int i, ItemStack item) { - // Prevent armor stand from being equipped - return false; - } - - @Override - public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { - // Prevent armor stand from being equipped - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Prevent changes to bounding box - } - - public void forceSetBoundingBox(AxisAlignedBB boundingBox) { - super.a(boundingBox); - } - - @Override - public void a(SoundEffect soundeffect, float f, float f1) { - // Remove sounds - } - - @Override - public void setCustomNameNMS(String customName) { - if (Objects.equals(this.customName, customName)) { - return; - } - this.customName = customName; - super.setCustomName(createCustomNameNMSObject(customName)); - super.setCustomNameVisible(customName != null && !customName.isEmpty()); - } - - protected static String createCustomNameNMSObject(String customName) { - return customName != null ? Strings.truncate(customName, 256) : ""; - } - - @Override - public String getCustomNameStringNMS() { - return this.customName; - } - - @Override - public Object getCustomNameObjectNMS() { - return super.getCustomName(); - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSArmorStand(super.world.getServer(), this); - } - return super.bukkitEntity; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - if (protocolPacketSettings.sendAccurateLocationPackets()) { - helper.broadcastPacket(new PacketPlayOutEntityTeleport(this)); - } - } - - @Override - public void setPassengerNMS(NMSEntity passenger) { - Preconditions.checkArgument(passenger instanceof Entity); - Entity passengerEntity = (Entity) passenger; - Preconditions.checkArgument(passengerEntity.bz() == null); - Preconditions.checkState(super.passengers.isEmpty()); - - try { - VEHICLE_FIELD.set(passenger, this); - this.passengers.add(passengerEntity); - } catch (ReflectiveOperationException e) { - DebugLogger.cannotSetPassenger(e); - } - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - -} diff --git a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityNMSItem.java b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityNMSItem.java deleted file mode 100644 index 2032ec0e..00000000 --- a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityNMSItem.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_9_R2; - -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; -import me.filoghost.holographicdisplays.common.nms.NMSCommons; -import me.filoghost.holographicdisplays.common.nms.entity.NMSItem; -import net.minecraft.server.v1_9_R2.Blocks; -import net.minecraft.server.v1_9_R2.DamageSource; -import net.minecraft.server.v1_9_R2.Entity; -import net.minecraft.server.v1_9_R2.EntityHuman; -import net.minecraft.server.v1_9_R2.EntityItem; -import net.minecraft.server.v1_9_R2.EntityPlayer; -import net.minecraft.server.v1_9_R2.ItemStack; -import net.minecraft.server.v1_9_R2.NBTTagCompound; -import net.minecraft.server.v1_9_R2.NBTTagList; -import net.minecraft.server.v1_9_R2.NBTTagString; -import net.minecraft.server.v1_9_R2.PacketPlayOutMount; -import net.minecraft.server.v1_9_R2.World; -import org.bukkit.craftbukkit.v1_9_R2.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack; -import org.bukkit.entity.Player; - -public class EntityNMSItem extends EntityItem implements NMSItem { - - private final StandardItemLine parentHologramLine; - private final VersionNMSEntityHelper helper; - - private int resendMountPacketTicks; - - public EntityNMSItem(World world, StandardItemLine parentHologramLine) { - super(world); - this.parentHologramLine = parentHologramLine; - this.helper = new VersionNMSEntityHelper(this); - - super.pickupDelay = Integer.MAX_VALUE; - } - - @Override - public void m() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - - if (resendMountPacketTicks++ > 20) { - resendMountPacketTicks = 0; - - Entity vehicle = bz(); - if (vehicle != null) { - // Send a packet near to "remind" players that the item is riding the armor stand (Spigot bug or client bug) - helper.broadcastPacket(new PacketPlayOutMount(vehicle)); - } - } - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - // Method called when a player is near - @Override - public void d(EntityHuman human) { - if (human.locY < super.locY - 1.5 || human.locY > super.locY + 1.0) { - // Too low or too high, it's a bit weird - return; - } - - if (human instanceof EntityPlayer) { - parentHologramLine.onPickup(((EntityPlayer) human).getBukkitEntity()); - // It is never added to the inventory - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound e(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void f(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void a(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public boolean isAlive() { - // This override prevents items from being picked up by hoppers (should have no side effects) - return false; - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSItem(super.world.getServer(), this); - } - return super.bukkitEntity; - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - } - - @Override - public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) { - ItemStack newItem = CraftItemStack.asNMSCopy(stack); - - if (newItem == null) { - newItem = new ItemStack(Blocks.BEDROCK); - } - - if (newItem.getTag() == null) { - newItem.setTag(new NBTTagCompound()); - } - NBTTagCompound display = newItem.getTag().getCompound("display"); - - if (!newItem.getTag().hasKey("display")) { - newItem.getTag().set("display", display); - } - - NBTTagList tagList = new NBTTagList(); - tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE)); - display.set("Lore", tagList); - - super.setItemStack(newItem); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - - @Override - public Object getRawItemStack() { - return super.getItemStack(); - } - -} diff --git a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityNMSSlime.java b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityNMSSlime.java deleted file mode 100644 index 729c263c..00000000 --- a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityNMSSlime.java +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_9_R2; - -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.nms.entity.NMSSlime; -import net.minecraft.server.v1_9_R2.AxisAlignedBB; -import net.minecraft.server.v1_9_R2.DamageSource; -import net.minecraft.server.v1_9_R2.Entity; -import net.minecraft.server.v1_9_R2.EntityDamageSource; -import net.minecraft.server.v1_9_R2.EntityPlayer; -import net.minecraft.server.v1_9_R2.EntitySlime; -import net.minecraft.server.v1_9_R2.NBTTagCompound; -import net.minecraft.server.v1_9_R2.PacketPlayOutMount; -import net.minecraft.server.v1_9_R2.SoundEffect; -import net.minecraft.server.v1_9_R2.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_9_R2.entity.CraftEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.player.PlayerInteractEntityEvent; - -public class EntityNMSSlime extends EntitySlime implements NMSSlime { - - private final StandardHologramLine parentHologramLine; - private final VersionNMSEntityHelper helper; - - private int resendMountPacketTicks; - - public EntityNMSSlime(World world, StandardHologramLine parentHologramLine) { - super(world); - this.parentHologramLine = parentHologramLine; - this.helper = new VersionNMSEntityHelper(this); - - super.persistent = true; - super.collides = false; - super.a(0.0F, 0.0F); - super.setSize(1); - super.setInvisible(true); - forceSetBoundingBox(new NullBoundingBox()); - } - - @Override - public void m() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - - if (resendMountPacketTicks++ > 20) { - resendMountPacketTicks = 0; - - Entity vehicle = bz(); - if (vehicle != null) { - // Send a packet near to "remind" players that the slime is riding the armor stand (Spigot bug or client bug) - helper.broadcastPacket(new PacketPlayOutMount(vehicle)); - } - } - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity - - // So it won't get removed - ticksLived = 0; - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Prevent changes to bounding box - } - - public void forceSetBoundingBox(AxisAlignedBB boundingBox) { - super.a(boundingBox); - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT - return false; - } - - @Override - public NBTTagCompound e(NBTTagCompound nbttagcompound) { - // Do not save NBT - return nbttagcompound; - } - - @Override - public void f(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public void a(NBTTagCompound nbttagcompound) { - // Do not load NBT - } - - @Override - public boolean damageEntity(DamageSource damageSource, float amount) { - if (damageSource instanceof EntityDamageSource) { - EntityDamageSource entityDamageSource = (EntityDamageSource) damageSource; - if (entityDamageSource.getEntity() instanceof EntityPlayer) { - Player player = ((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(); - PlayerInteractEntityEvent event = new PlayerInteractEntityEvent(player, getBukkitEntity()); - Bukkit.getPluginManager().callEvent(event); // Bukkit takes care of the exceptions - } - } - return false; - } - - @Override - public boolean isInvulnerable(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean isCollidable() { - return false; - } - - @Override - public void setCustomName(String customName) { - // Prevents changes to custom name - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Prevents changes to custom name visibility - } - - @Override - public void a(SoundEffect soundeffect, float f, float f1) { - // Remove sounds - } - - @Override - public void die() { - // Prevent entity from dying - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSSlime(super.world.getServer(), this); - } - return super.bukkitEntity; - } - - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z) { - super.setPosition(x, y, z); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public StandardHologramLine getHologramLine() { - return parentHologramLine; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - return helper.isTrackedBy(bukkitPlayer); - } - -} diff --git a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/NullBoundingBox.java b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/NullBoundingBox.java deleted file mode 100644 index b61ac006..00000000 --- a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/NullBoundingBox.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_9_R2; - -import net.minecraft.server.v1_9_R2.AxisAlignedBB; -import net.minecraft.server.v1_9_R2.BlockPosition; -import net.minecraft.server.v1_9_R2.MovingObjectPosition; -import net.minecraft.server.v1_9_R2.Vec3D; - -public class NullBoundingBox extends AxisAlignedBB { - - public NullBoundingBox() { - super(0, 0, 0, 0, 0, 0); - } - - @Override - public double a() { - return 0.0; - } - - @Override - public double a(AxisAlignedBB arg0, double arg1) { - return 0.0; - } - - @Override - public AxisAlignedBB a(AxisAlignedBB arg0) { - return this; - } - - @Override - public AxisAlignedBB a(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public MovingObjectPosition a(Vec3D arg0, Vec3D arg1) { - return super.a(arg0, arg1); - } - - @Override - public boolean a(Vec3D arg0) { - return false; - } - - @Override - public double b(AxisAlignedBB arg0, double arg1) { - return 0.0; - } - - @Override - public boolean b(AxisAlignedBB arg0) { - return false; - } - - @Override - public double c(AxisAlignedBB arg0, double arg1) { - return 0.0; - } - - @Override - public AxisAlignedBB c(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public AxisAlignedBB grow(double arg0, double arg1, double arg2) { - return this; - } - - @Override - public AxisAlignedBB shrink(double arg0) { - return this; - } - - @Override - public AxisAlignedBB a(BlockPosition arg0) { - return this; - } - - @Override - public boolean a(double arg0, double arg1, double arg2, double arg3, double arg4, double arg5) { - return false; - } - - @Override - public boolean b(Vec3D arg0) { - return false; - } - - @Override - public boolean c(Vec3D arg0) { - return false; - } - - @Override - public boolean d(Vec3D arg0) { - return false; - } - - @Override - public AxisAlignedBB e(double arg0) { - return this; - } - - @Override - public AxisAlignedBB g(double arg0) { - return this; - } - -} diff --git a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionNMSEntityHelper.java b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionNMSEntityHelper.java deleted file mode 100644 index 6d412a7c..00000000 --- a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionNMSEntityHelper.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_9_R2; - -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntityHelper; -import net.minecraft.server.v1_9_R2.Entity; -import net.minecraft.server.v1_9_R2.EntityTrackerEntry; -import net.minecraft.server.v1_9_R2.Packet; -import net.minecraft.server.v1_9_R2.WorldServer; -import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer; -import org.bukkit.entity.Player; - -public class VersionNMSEntityHelper extends NMSEntityHelper { - - private final Entity entity; - - public VersionNMSEntityHelper(Entity entity) { - this.entity = entity; - } - - @Override - protected EntityTrackerEntry getTracker0() { - return ((WorldServer) entity.world).tracker.trackedEntities.get(entity.getId()); - } - - @Override - public boolean isTrackedBy(Player bukkitPlayer) { - EntityTrackerEntry tracker = getTracker(); - if (tracker != null) { - return tracker.trackedPlayers.contains(((CraftPlayer) bukkitPlayer).getHandle()); - } else { - return false; - } - } - - public void broadcastPacket(Packet packet) { - EntityTrackerEntry tracker = getTracker(); - if (tracker != null) { - tracker.broadcast(packet); - } - } - -} diff --git a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionNMSManager.java b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionNMSManager.java index 637e3767..94c9a940 100644 --- a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionNMSManager.java +++ b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionNMSManager.java @@ -5,146 +5,20 @@ */ package me.filoghost.holographicdisplays.nms.v1_9_R2; -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.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; +import me.filoghost.holographicdisplays.common.nms.EntityID; import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; -import me.filoghost.holographicdisplays.common.nms.SpawnFailedException; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntity; -import me.filoghost.holographicdisplays.common.nms.entity.NMSItem; -import net.minecraft.server.v1_9_R2.Entity; -import net.minecraft.server.v1_9_R2.EntityTypes; -import net.minecraft.server.v1_9_R2.MathHelper; -import net.minecraft.server.v1_9_R2.World; -import net.minecraft.server.v1_9_R2.WorldServer; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_9_R2.CraftWorld; -import org.bukkit.craftbukkit.v1_9_R2.entity.CraftEntity; -import org.bukkit.inventory.ItemStack; - -import java.util.Map; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; public class VersionNMSManager implements NMSManager { - private static final ReflectField, String>> ENTITY_NAMES_BY_CLASS_FIELD - = ReflectField.lookup(new ClassToken, String>>() {}, EntityTypes.class, "d"); - private static final ReflectField, Integer>> ENTITY_IDS_BY_CLASS_FIELD - = ReflectField.lookup(new ClassToken, Integer>>() {}, EntityTypes.class, "f"); - - private static final ReflectMethod REGISTER_ENTITY_METHOD = ReflectMethod.lookup(Object.class, World.class, "b", Entity.class); - - private final ProtocolPacketSettings protocolPacketSettings; - - public VersionNMSManager(ProtocolPacketSettings protocolPacketSettings) { - this.protocolPacketSettings = protocolPacketSettings; + @Override + public EntityID newEntityID() { + return null; } @Override - public void setup() throws Exception { - registerCustomEntity(EntityNMSArmorStand.class, "ArmorStand", 30); - registerCustomEntity(EntityNMSItem.class, "Item", 1); - registerCustomEntity(EntityNMSSlime.class, "Slime", 55); - } - - public void registerCustomEntity(Class entityClass, String name, int id) throws Exception { - ENTITY_NAMES_BY_CLASS_FIELD.getStatic().put(entityClass, name); - ENTITY_IDS_BY_CLASS_FIELD.getStatic().put(entityClass, id); - } - - @Override - public NMSItem spawnNMSItem( - org.bukkit.World bukkitWorld, double x, double y, double z, - StandardItemLine parentHologramLine, - ItemStack stack) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSItem item = new EntityNMSItem(nmsWorld, parentHologramLine); - 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 parentHologramLine) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSSlime slime = new EntityNMSSlime(nmsWorld, parentHologramLine); - 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 parentHologramLine) throws SpawnFailedException { - WorldServer nmsWorld = ((CraftWorld) world).getHandle(); - EntityNMSArmorStand armorStand = new EntityNMSArmorStand(nmsWorld, parentHologramLine, protocolPacketSettings); - armorStand.setLocationNMS(x, y, z); - addEntityToWorld(nmsWorld, armorStand); - return armorStand; - } - - 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); - final int chunkZ = MathHelper.floor(nmsEntity.locZ / 16.0); - - if (!nmsWorld.getChunkProviderServer().isLoaded(chunkX, chunkZ)) { - // This should never happen - nmsEntity.dead = true; - throw new SpawnFailedException(SpawnFailedException.CHUNK_NOT_LOADED); - } - - nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity); - nmsWorld.entityList.add(nmsEntity); - - try { - REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity); - } catch (ReflectiveOperationException e) { - 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 NMSEntity; - } - - @Override - public NMSEntity getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - - if (nmsEntity instanceof NMSEntity) { - return (NMSEntity) nmsEntity; - } else { - return null; - } - } - - @Override - public NMSEntity getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - Entity nmsEntity = nmsWorld.getEntity(entityID); - - if (nmsEntity instanceof NMSEntity) { - return (NMSEntity) nmsEntity; - } else { - return null; - } - } - - @Override - public Object createCustomNameNMSObject(String customName) { - return EntityNMSArmorStand.createCustomNameNMSObject(customName); + public NMSPacketList createPacketList() { + return null; } } diff --git a/plugin/pom.xml b/plugin/pom.xml index b30eef9d..5da7d133 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -114,11 +114,6 @@ spigot-api - - com.comphenix.protocol - ProtocolLib - - me.clip placeholderapi diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/HolographicDisplays.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/HolographicDisplays.java index 6d384767..bc2d56bd 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/HolographicDisplays.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/HolographicDisplays.java @@ -12,25 +12,20 @@ import me.filoghost.fcommons.config.exception.ConfigException; import me.filoghost.fcommons.logging.ErrorCollector; import me.filoghost.holographicdisplays.api.internal.HolographicDisplaysAPIProvider; import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; import me.filoghost.holographicdisplays.plugin.api.current.DefaultHolographicDisplaysAPIProvider; import me.filoghost.holographicdisplays.plugin.api.v2.V2HologramsAPIProvider; import me.filoghost.holographicdisplays.plugin.bridge.bungeecord.BungeeServerTracker; import me.filoghost.holographicdisplays.plugin.bridge.placeholderapi.PlaceholderAPIHook; -import me.filoghost.holographicdisplays.plugin.bridge.protocollib.ProtocolLibHook; import me.filoghost.holographicdisplays.plugin.commands.HologramCommandManager; -import me.filoghost.holographicdisplays.plugin.commands.InternalHologramEditor; import me.filoghost.holographicdisplays.plugin.disk.ConfigManager; import me.filoghost.holographicdisplays.plugin.disk.HologramDatabase; import me.filoghost.holographicdisplays.plugin.disk.Settings; import me.filoghost.holographicdisplays.plugin.disk.upgrade.LegacySymbolsUpgrade; -import me.filoghost.holographicdisplays.plugin.hologram.api.APIHologram; import me.filoghost.holographicdisplays.plugin.hologram.api.APIHologramManager; -import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologram; import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologramManager; +import me.filoghost.holographicdisplays.plugin.hologram.tracking.LineTrackerManager; import me.filoghost.holographicdisplays.plugin.listener.ChunkListener; -import me.filoghost.holographicdisplays.plugin.listener.InteractListener; -import me.filoghost.holographicdisplays.plugin.listener.SpawnListener; +import me.filoghost.holographicdisplays.plugin.listener.PlayerQuitListener; import me.filoghost.holographicdisplays.plugin.listener.UpdateNotificationListener; import me.filoghost.holographicdisplays.plugin.log.PrintableErrorCollector; import me.filoghost.holographicdisplays.plugin.placeholder.TickClock; @@ -38,7 +33,6 @@ import me.filoghost.holographicdisplays.plugin.placeholder.TickingTask; import me.filoghost.holographicdisplays.plugin.placeholder.internal.AnimationRegistry; import me.filoghost.holographicdisplays.plugin.placeholder.internal.DefaultPlaceholders; import me.filoghost.holographicdisplays.plugin.placeholder.registry.PlaceholderRegistry; -import me.filoghost.holographicdisplays.plugin.placeholder.tracking.PlaceholderLineTracker; import me.filoghost.holographicdisplays.plugin.placeholder.tracking.PlaceholderTracker; import me.filoghost.holographicdisplays.plugin.util.NMSVersion; import org.bstats.bukkit.MetricsLite; @@ -48,16 +42,16 @@ import org.bukkit.ChatColor; import java.io.IOException; import java.util.concurrent.TimeUnit; -public class HolographicDisplays extends FCommonsPlugin implements ProtocolPacketSettings { +public class HolographicDisplays extends FCommonsPlugin { private static HolographicDisplays instance; private ConfigManager configManager; private InternalHologramManager internalHologramManager; - private APIHologramManager apiHologramManager; private BungeeServerTracker bungeeServerTracker; private AnimationRegistry animationRegistry; private PlaceholderRegistry placeholderRegistry; + private LineTrackerManager lineTrackerManager; @Override public void onCheckedEnable() throws PluginEnableException { @@ -91,12 +85,13 @@ public class HolographicDisplays extends FCommonsPlugin implements ProtocolPacke "This can be caused by edits to plugin.yml or other plugins."); } + PrintableErrorCollector errorCollector = new PrintableErrorCollector(); + NMSManager nmsManager; try { - nmsManager = NMSVersion.createNMSManager(this); - nmsManager.setup(); - } catch (Exception e) { - throw new PluginEnableException(e, "Couldn't initialize the NMS manager."); + nmsManager = NMSVersion.getCurrent().createNMSManager(errorCollector); + } catch (Throwable t) { + throw new PluginEnableException(t, "Couldn't initialize the NMS manager."); } configManager = new ConfigManager(getDataFolder().toPath()); @@ -105,11 +100,9 @@ public class HolographicDisplays extends FCommonsPlugin implements ProtocolPacke placeholderRegistry = new PlaceholderRegistry(); TickClock tickClock = new TickClock(); PlaceholderTracker placeholderTracker = new PlaceholderTracker(placeholderRegistry, tickClock); - PlaceholderLineTracker placeholderLineTracker = new PlaceholderLineTracker(placeholderTracker); - internalHologramManager = new InternalHologramManager(nmsManager, placeholderLineTracker); - apiHologramManager = new APIHologramManager(nmsManager, placeholderLineTracker); - - PrintableErrorCollector errorCollector = new PrintableErrorCollector(); + lineTrackerManager = new LineTrackerManager(nmsManager, placeholderTracker); + internalHologramManager = new InternalHologramManager(lineTrackerManager); + APIHologramManager apiHologramManager = new APIHologramManager(lineTrackerManager); // Run only once at startup, before anything else try { @@ -120,21 +113,16 @@ public class HolographicDisplays extends FCommonsPlugin implements ProtocolPacke load(true, errorCollector); - ProtocolLibHook.setup(this, nmsManager, this, placeholderLineTracker, errorCollector); PlaceholderAPIHook.setup(); - TickingTask tickingTask = new TickingTask(tickClock, placeholderLineTracker); + TickingTask tickingTask = new TickingTask(tickClock, lineTrackerManager); Bukkit.getScheduler().scheduleSyncRepeatingTask(this, tickingTask, 0, 1); - HologramCommandManager commandManager = new HologramCommandManager( - this, - new InternalHologramEditor(internalHologramManager, configManager), - nmsManager); + HologramCommandManager commandManager = new HologramCommandManager(this, internalHologramManager, configManager); commandManager.register(this); - registerListener(new InteractListener(nmsManager)); - registerListener(new SpawnListener(nmsManager)); - registerListener(new ChunkListener(this, nmsManager, internalHologramManager, apiHologramManager)); + registerListener(new PlayerQuitListener(lineTrackerManager)); + registerListener(new ChunkListener(this, lineTrackerManager)); UpdateNotificationListener updateNotificationListener = new UpdateNotificationListener(); registerListener(updateNotificationListener); @@ -189,25 +177,11 @@ public class HolographicDisplays extends FCommonsPlugin implements ProtocolPacke @Override public void onDisable() { - if (internalHologramManager != null) { - for (InternalHologram hologram : internalHologramManager.getHolograms()) { - hologram.despawnEntities(); - } - } - if (apiHologramManager != null) { - for (APIHologram hologram : apiHologramManager.getHolograms()) { - hologram.despawnEntities(); - } - } + lineTrackerManager.clearTrackedPlayers(); } public static HolographicDisplays getInstance() { return instance; } - @Override - public boolean sendAccurateLocationPackets() { - return ProtocolLibHook.isEnabled(); - } - } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/api/current/DefaultHolographicDisplaysAPIProvider.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/api/current/DefaultHolographicDisplaysAPIProvider.java index 1ce0540f..21b4a288 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/api/current/DefaultHolographicDisplaysAPIProvider.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/api/current/DefaultHolographicDisplaysAPIProvider.java @@ -11,7 +11,6 @@ import me.filoghost.holographicdisplays.api.internal.HolographicDisplaysAPIProvi import me.filoghost.holographicdisplays.common.nms.NMSManager; import me.filoghost.holographicdisplays.plugin.hologram.api.APIHologramManager; import me.filoghost.holographicdisplays.plugin.placeholder.registry.PlaceholderRegistry; -import org.bukkit.entity.Entity; import org.bukkit.plugin.Plugin; import java.util.Map; @@ -44,11 +43,4 @@ public class DefaultHolographicDisplaysAPIProvider extends HolographicDisplaysAP new DefaultHolographicDisplaysAPI(pluginKey, apiHologramManager, placeholderRegistry)); } - @Override - public boolean isHologramEntity(Entity entity) { - Preconditions.notNull(entity, "entity"); - - return nmsManager.isNMSEntityBase(entity); - } - } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/api/v2/V2HologramsAPIProvider.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/api/v2/V2HologramsAPIProvider.java index 9f9b4d0f..3f941812 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/api/v2/V2HologramsAPIProvider.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/api/v2/V2HologramsAPIProvider.java @@ -114,7 +114,7 @@ public class V2HologramsAPIProvider extends HologramsAPIProvider { @Override public boolean isHologramEntity(Entity bukkitEntity) { Preconditions.notNull(bukkitEntity, "bukkitEntity"); - return nmsManager.isNMSEntityBase(bukkitEntity); + return false; } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/bridge/protocollib/DebugHelper.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/bridge/protocollib/DebugHelper.java deleted file mode 100644 index 87d533d8..00000000 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/bridge/protocollib/DebugHelper.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.plugin.bridge.protocollib; - -import com.comphenix.net.sf.cglib.proxy.Factory; -import com.comphenix.protocol.events.PacketContainer; -import com.comphenix.protocol.events.PacketEvent; -import com.comphenix.protocol.reflect.EquivalentConverter; -import com.comphenix.protocol.reflect.PrettyPrinter; -import com.comphenix.protocol.utility.HexDumper; -import com.comphenix.protocol.utility.MinecraftReflection; -import com.comphenix.protocol.wrappers.BukkitConverters; - -import java.util.Map; - -class DebugHelper { - - private static final int HEX_DUMP_THRESHOLD = 256; - - public static void printInformation(PacketEvent event) { - String verb = event.isServerPacket() ? "Sent" : "Received"; - String format = event.isServerPacket() - ? "%s %s to %s" - : "%s %s from %s"; - - String shortDescription = String.format(format, - event.isCancelled() ? "Cancelled" : verb, - event.getPacketType(), - event.getPlayer().getName() - ); - - // Detailed will print the packet's content too - try { - System.out.println(shortDescription + ":\n" + getPacketDescription(event.getPacket())); - } catch (IllegalAccessException e) { - e.printStackTrace(); - System.out.println("Unable to use reflection."); - } - } - - - private static String getPacketDescription(PacketContainer packetContainer) throws IllegalAccessException { - Object packet = packetContainer.getHandle(); - Class clazz = packet.getClass(); - - // Get the first Minecraft super class - while (clazz != null - && clazz != Object.class - && (!MinecraftReflection.isMinecraftClass(clazz) || Factory.class.isAssignableFrom(clazz))) { - clazz = clazz.getSuperclass(); - } - - return PrettyPrinter.printObject( - packet, - clazz, - MinecraftReflection.getPacketClass(), - PrettyPrinter.RECURSE_DEPTH, - (StringBuilder output, Object value) -> { - // Special case - if (value instanceof byte[]) { - byte[] data = (byte[]) value; - - if (data.length > HEX_DUMP_THRESHOLD) { - output.append("["); - HexDumper.defaultDumper().appendTo(output, data); - output.append("]"); - return true; - } - } else if (value != null) { - EquivalentConverter converter = findConverter(value.getClass()); - - if (converter != null) { - output.append(converter.getSpecific(value)); - return true; - } - } - return false; - }); - } - - - private static EquivalentConverter findConverter(Class clazz) { - Map, EquivalentConverter> converters = BukkitConverters.getConvertersForGeneric(); - - while (clazz != null) { - EquivalentConverter result = converters.get(clazz); - - if (result != null) { - return result; - } else { - clazz = clazz.getSuperclass(); - } - } - return null; - } - -} diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/bridge/protocollib/MetadataHelper.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/bridge/protocollib/MetadataHelper.java deleted file mode 100644 index 18698a4d..00000000 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/bridge/protocollib/MetadataHelper.java +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.plugin.bridge.protocollib; - -import com.comphenix.protocol.utility.MinecraftReflection; -import com.comphenix.protocol.wrappers.WrappedDataWatcher; -import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry; -import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer; -import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject; -import com.comphenix.protocol.wrappers.WrappedWatchableObject; -import me.filoghost.holographicdisplays.plugin.util.NMSVersion; - -import java.util.List; -import java.util.Optional; - -class MetadataHelper { - - private final int itemSlotIndex; - private final int entityStatusIndex; - private final int airLevelIndex; - private final int customNameIndex; - private final int customNameVisibleIndex; - private final int noGravityIndex; - private final int armorStandStatusIndex; - private final int slimeSizeIndex; - - private final boolean customNameUsesChatComponents; - - private Serializer itemSerializer; - private Serializer intSerializer; - private Serializer byteSerializer; - private Serializer stringSerializer; - private Serializer booleanSerializer; - private Serializer chatComponentSerializer; - - - MetadataHelper() { - if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_17_R1)) { - itemSlotIndex = 8; - } else if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_14_R1)) { - itemSlotIndex = 7; - } else if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_10_R1)) { - itemSlotIndex = 6; - } else if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_9_R1)) { - itemSlotIndex = 5; - } else { - itemSlotIndex = 10; - } - - if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_17_R1)) { - armorStandStatusIndex = 15; - } else if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_15_R1)) { - armorStandStatusIndex = 14; - } else { - armorStandStatusIndex = 11; - } - - entityStatusIndex = 0; - airLevelIndex = 1; - customNameIndex = 2; - customNameVisibleIndex = 3; - noGravityIndex = 5; - slimeSizeIndex = 15; - - if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_9_R1)) { - itemSerializer = Registry.get(MinecraftReflection.getItemStackClass()); - intSerializer = Registry.get(Integer.class); - byteSerializer = Registry.get(Byte.class); - stringSerializer = Registry.get(String.class); - booleanSerializer = Registry.get(Boolean.class); - } - - if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) { - customNameUsesChatComponents = true; - chatComponentSerializer = Registry.get(MinecraftReflection.getIChatBaseComponentClass(), true); - } else { - customNameUsesChatComponents = false; - } - } - - - public void setEntityStatus(WrappedDataWatcher dataWatcher, byte statusBitmask) { - requireMinimumVersion(NMSVersion.v1_9_R1); - dataWatcher.setObject(new WrappedDataWatcherObject(entityStatusIndex, byteSerializer), statusBitmask); - } - - - public WrappedWatchableObject getCustomNameWatchableObject(WrappedDataWatcher metadata) { - return metadata.getWatchableObject(customNameIndex); - } - - - public WrappedWatchableObject getCustomNameWatchableObject(List dataWatcherValues) { - for (WrappedWatchableObject watchableObject : dataWatcherValues) { - if (watchableObject.getIndex() == customNameIndex) { - return watchableObject; - } - } - - return null; - } - - - public Object getCustomNameNMSObject(WrappedWatchableObject customNameWatchableObject) { - Object customNameNMSObject = customNameWatchableObject.getRawValue(); - if (customNameNMSObject == null) { - return null; - } - - if (customNameUsesChatComponents) { - if (!(customNameNMSObject instanceof Optional)) { - throw new IllegalArgumentException("Expected custom name of type " + Optional.class); - } - - return ((Optional) customNameNMSObject).orElse(null); - - } else { - if (!(customNameNMSObject instanceof String)) { - throw new IllegalArgumentException("Expected custom name of type " + String.class); - } - - return customNameNMSObject; - } - } - - - public void setCustomNameNMSObject(WrappedWatchableObject customNameWatchableObject, Object customNameNMSObject) { - if (customNameUsesChatComponents) { - customNameWatchableObject.setValue(Optional.ofNullable(customNameNMSObject)); - } else { - customNameWatchableObject.setValue(customNameNMSObject); - } - } - - - public void setCustomNameNMSObject(WrappedDataWatcher dataWatcher, Object customNameNMSObject) { - requireMinimumVersion(NMSVersion.v1_9_R1); - - if (customNameUsesChatComponents) { - dataWatcher.setObject( - new WrappedDataWatcherObject(customNameIndex, chatComponentSerializer), - Optional.ofNullable(customNameNMSObject)); - } else { - dataWatcher.setObject( - new WrappedDataWatcherObject(customNameIndex, stringSerializer), - customNameNMSObject); - } - } - - public void setCustomNameVisible(WrappedDataWatcher dataWatcher, boolean customNameVisible) { - requireMinimumVersion(NMSVersion.v1_9_R1); - dataWatcher.setObject(new WrappedDataWatcherObject(customNameVisibleIndex, booleanSerializer), customNameVisible); - } - - - public void setNoGravity(WrappedDataWatcher dataWatcher, boolean noGravity) { - requireMinimumVersion(NMSVersion.v1_9_R1); - dataWatcher.setObject(new WrappedDataWatcherObject(noGravityIndex, booleanSerializer), noGravity); - } - - - public void setArmorStandStatus(WrappedDataWatcher dataWatcher, byte statusBitmask) { - requireMinimumVersion(NMSVersion.v1_9_R1); - dataWatcher.setObject(new WrappedDataWatcherObject(armorStandStatusIndex, byteSerializer), statusBitmask); - } - - - public void setItemMetadata(WrappedDataWatcher dataWatcher, Object nmsItemStack) { - if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_9_R1)) { - if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_11_R1)) { - dataWatcher.setObject( - new WrappedDataWatcherObject(itemSlotIndex, itemSerializer), - nmsItemStack); - } else { - dataWatcher.setObject( - new WrappedDataWatcherObject(itemSlotIndex, itemSerializer), - com.google.common.base.Optional.of(nmsItemStack)); - } - dataWatcher.setObject(new WrappedDataWatcherObject(airLevelIndex, intSerializer), 300); - dataWatcher.setObject(new WrappedDataWatcherObject(entityStatusIndex, byteSerializer), (byte) 0); - } else { - dataWatcher.setObject(itemSlotIndex, nmsItemStack); - dataWatcher.setObject(airLevelIndex, 300); - dataWatcher.setObject(entityStatusIndex, (byte) 0); - } - } - - - public void setSlimeSize(WrappedDataWatcher dataWatcher, int size) { - requireMinimumVersion(NMSVersion.v1_15_R1); - dataWatcher.setObject(new WrappedDataWatcherObject(slimeSizeIndex, intSerializer), size); - } - - - private static void requireMinimumVersion(NMSVersion minimumVersion) { - if (!NMSVersion.isGreaterEqualThan(minimumVersion)) { - throw new UnsupportedOperationException("Method only available from NMS version " + minimumVersion); - } - } - -} diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/bridge/protocollib/PacketListener.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/bridge/protocollib/PacketListener.java deleted file mode 100644 index cc1dc333..00000000 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/bridge/protocollib/PacketListener.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.plugin.bridge.protocollib; - -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.ProtocolLibrary; -import com.comphenix.protocol.events.ListenerPriority; -import com.comphenix.protocol.events.PacketAdapter; -import com.comphenix.protocol.events.PacketContainer; -import com.comphenix.protocol.events.PacketEvent; -import com.comphenix.protocol.wrappers.WrappedWatchableObject; -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardTextLine; -import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntity; -import me.filoghost.holographicdisplays.plugin.bridge.placeholderapi.PlaceholderAPIHook; -import me.filoghost.holographicdisplays.plugin.lib.packetwrapper.AbstractPacket; -import me.filoghost.holographicdisplays.plugin.lib.packetwrapper.WrapperPlayServerEntityMetadata; -import me.filoghost.holographicdisplays.plugin.lib.packetwrapper.WrapperPlayServerSpawnEntityLiving; -import me.filoghost.holographicdisplays.plugin.placeholder.tracking.PlaceholderLineTracker; -import me.filoghost.holographicdisplays.plugin.placeholder.tracking.TrackedLine; -import me.filoghost.holographicdisplays.plugin.util.NMSVersion; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - -class PacketListener extends PacketAdapter { - - private final NMSManager nmsManager; - private final MetadataHelper metadataHelper; - private final ProtocolPacketSettings packetSettings; - private final PlaceholderLineTracker placeholderLineTracker; - - PacketListener( - Plugin plugin, - NMSManager nmsManager, - MetadataHelper metadataHelper, - ProtocolPacketSettings packetSettings, - PlaceholderLineTracker placeholderLineTracker) { - super(PacketAdapter.params() - .plugin(plugin) - .types( - PacketType.Play.Server.SPAWN_ENTITY_LIVING, - PacketType.Play.Server.SPAWN_ENTITY, - PacketType.Play.Server.ENTITY_METADATA, - PacketType.Play.Server.REL_ENTITY_MOVE, - PacketType.Play.Server.REL_ENTITY_MOVE_LOOK) - .serverSide() - .listenerPriority(ListenerPriority.NORMAL)); - - this.nmsManager = nmsManager; - this.metadataHelper = metadataHelper; - this.packetSettings = packetSettings; - this.placeholderLineTracker = placeholderLineTracker; - } - - public void registerListener() { - ProtocolLibrary.getProtocolManager().addPacketListener(this); - } - - @Override - public void onPacketSending(PacketEvent event) { - if (event.isPlayerTemporary() || !Bukkit.isPrimaryThread()) { - return; - } - - PacketContainer packet = event.getPacket(); - PacketType packetType = packet.getType(); - Player player = event.getPlayer(); - - int entityID = packet.getIntegers().read(0); - if (entityID < 0) { - return; - } - - NMSEntity nmsEntity = nmsManager.getNMSEntityBaseFromID(event.getPlayer().getWorld(), entityID); - if (nmsEntity == null) { - return; // Entity not existing or not related to holograms - } - - if (packetType == PacketType.Play.Server.REL_ENTITY_MOVE || packetType == PacketType.Play.Server.REL_ENTITY_MOVE_LOOK) { - if (nmsEntity instanceof NMSArmorStand && packetSettings.sendAccurateLocationPackets()) { - event.setCancelled(true); // Don't send relative movement packets for armor stands, only keep precise teleport packets - } - return; - } - - StandardHologramLine hologramLine = nmsEntity.getHologramLine(); - - if (!hologramLine.getHologram().isVisibleTo(player)) { - event.setCancelled(true); - return; - } - - if (packetType == PacketType.Play.Server.SPAWN_ENTITY_LIVING && NMSVersion.isGreaterEqualThan(NMSVersion.v1_15_R1)) { - // There's no metadata field in 1.15+ on the spawn entity packet, ignore it - return; - } - - if (packetType == PacketType.Play.Server.SPAWN_ENTITY_LIVING || packetType == PacketType.Play.Server.ENTITY_METADATA) { - if (!(hologramLine instanceof StandardTextLine) || !(nmsEntity instanceof NMSArmorStand)) { - return; - } - - StandardTextLine textLine = (StandardTextLine) hologramLine; - - if (!textLine.isAllowPlaceholders()) { - return; - } - - NMSArmorStand nmsArmorStand = (NMSArmorStand) nmsEntity; - String customName = nmsArmorStand.getCustomNameStringNMS(); - - if (customName == null || customName.isEmpty()) { - return; - } - - String customNameWithIndividualPlaceholders = replaceIndividualPlaceholders(textLine, customName, player); - - if (customNameWithIndividualPlaceholders.equals(customName)) { - return; // No need to modify packets, custom name doesn't need changes - } - - WrappedWatchableObject customNameWatchableObject; - AbstractPacket packetWrapper; - - if (packetType == PacketType.Play.Server.ENTITY_METADATA) { - WrapperPlayServerEntityMetadata entityMetadataPacket = new WrapperPlayServerEntityMetadata(packet.deepClone()); - packetWrapper = entityMetadataPacket; - customNameWatchableObject = metadataHelper.getCustomNameWatchableObject(entityMetadataPacket.getEntityMetadata()); - } else { - WrapperPlayServerSpawnEntityLiving spawnEntityPacket = new WrapperPlayServerSpawnEntityLiving(packet.deepClone()); - packetWrapper = spawnEntityPacket; - customNameWatchableObject = metadataHelper.getCustomNameWatchableObject(spawnEntityPacket.getMetadata()); - } - - if (customNameWatchableObject == null) { - return; - } - - Object customNameNMSObject = nmsManager.createCustomNameNMSObject(customNameWithIndividualPlaceholders); - metadataHelper.setCustomNameNMSObject(customNameWatchableObject, customNameNMSObject); - event.setPacket(packetWrapper.getHandle()); - } - } - - private String replaceIndividualPlaceholders(StandardTextLine textLine, String text, Player player) { - TrackedLine trackedLine = placeholderLineTracker.getTrackedLine(textLine); - if (trackedLine == null) { - return text; - } - - text = trackedLine.replaceIndividualPlaceholders(player); - - if (PlaceholderAPIHook.isEnabled() && PlaceholderAPIHook.containsPlaceholders(text)) { - text = PlaceholderAPIHook.replacePlaceholders(player, text); - } - - return text; - } - -} diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/bridge/protocollib/PacketSender.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/bridge/protocollib/PacketSender.java deleted file mode 100644 index a30278c1..00000000 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/bridge/protocollib/PacketSender.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.plugin.bridge.protocollib; - -import com.comphenix.protocol.wrappers.WrappedDataWatcher; -import me.filoghost.holographicdisplays.common.hologram.StandardHologram; -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; -import me.filoghost.holographicdisplays.common.hologram.StandardTextLine; -import me.filoghost.holographicdisplays.common.hologram.StandardTouchableLine; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntity; -import me.filoghost.holographicdisplays.common.nms.entity.NMSItem; -import me.filoghost.holographicdisplays.common.nms.entity.NMSSlime; -import me.filoghost.holographicdisplays.plugin.lib.packetwrapper.AbstractPacket; -import me.filoghost.holographicdisplays.plugin.lib.packetwrapper.WrapperPlayServerAttachEntity; -import me.filoghost.holographicdisplays.plugin.lib.packetwrapper.WrapperPlayServerEntityDestroy; -import me.filoghost.holographicdisplays.plugin.lib.packetwrapper.WrapperPlayServerEntityMetadata; -import me.filoghost.holographicdisplays.plugin.lib.packetwrapper.WrapperPlayServerMount; -import me.filoghost.holographicdisplays.plugin.lib.packetwrapper.WrapperPlayServerSpawnEntity; -import me.filoghost.holographicdisplays.plugin.lib.packetwrapper.WrapperPlayServerSpawnEntity.ObjectTypes; -import me.filoghost.holographicdisplays.plugin.lib.packetwrapper.WrapperPlayServerSpawnEntityLiving; -import me.filoghost.holographicdisplays.plugin.util.NMSVersion; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.List; - -class PacketSender { - - private final MetadataHelper metadataHelper; - - PacketSender(MetadataHelper metadataHelper) { - this.metadataHelper = metadataHelper; - } - - public void sendDestroyEntitiesPacket(Player player, StandardHologram hologram) { - List ids = new ArrayList<>(); - for (StandardHologramLine line : hologram.getLines()) { - line.collectTrackedEntityIDs(player, ids); - } - - if (!ids.isEmpty()) { - sendDestroyEntitiesPacket(player, ids); - } - } - - public void sendCreateEntitiesPacket(Player player, StandardHologram hologram) { - for (StandardHologramLine line : hologram.getLines()) { - sendCreateEntitiesPacket(player, line); - } - } - - private void sendCreateEntitiesPacket(Player player, StandardHologramLine line) { - if (line instanceof StandardTextLine) { - StandardTextLine textLine = (StandardTextLine) line; - - NMSArmorStand armorStand = textLine.getNMSArmorStand(); - if (armorStand != null && armorStand.isTrackedBy(player)) { - sendSpawnArmorStandPacket(player, armorStand); - } - - } else if (line instanceof StandardItemLine) { - StandardItemLine itemLine = (StandardItemLine) line; - NMSArmorStand itemVehicle = itemLine.getNMSItemVehicle(); - NMSItem item = itemLine.getNMSItem(); - - if (itemVehicle != null && itemVehicle.isTrackedBy(player)) { - sendSpawnArmorStandPacket(player, itemVehicle); - } - - if (item != null && item.isTrackedBy(player)) { - sendSpawnItemPacket(player, item); - sendVehicleAttachPacket(player, itemVehicle, item); - sendItemMetadataPacket(player, item); - } - } else { - throw new IllegalArgumentException("Unexpected hologram line type: " + line.getClass().getName()); - } - - // All sub-types of lines are touchable, no need to check instance type - StandardTouchableLine touchableLine = (StandardTouchableLine) line; - NMSArmorStand slimeVehicle = touchableLine.getNMSSlimeVehicle(); - NMSSlime slime = touchableLine.getNMSSlime(); - - if (slimeVehicle != null && slimeVehicle.isTrackedBy(player)) { - sendSpawnArmorStandPacket(player, slimeVehicle); - } - - if (slime != null && slime.isTrackedBy(player)) { - sendSpawnSlimePacket(player, slime); - sendVehicleAttachPacket(player, slimeVehicle, slime); - } - } - - private void sendSpawnArmorStandPacket(Player receiver, NMSArmorStand armorStand) { - if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_11_R1)) { - AbstractPacket spawnPacket; - if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_14_R1)) { - spawnPacket = new WrapperPlayServerSpawnEntityLiving(armorStand.getBukkitEntityNMS()); - } else { - spawnPacket = new WrapperPlayServerSpawnEntity( - armorStand.getBukkitEntityNMS(), - WrapperPlayServerSpawnEntity.ObjectTypes.ARMOR_STAND, 1); - } - spawnPacket.sendPacket(receiver); - - WrapperPlayServerEntityMetadata dataPacket = new WrapperPlayServerEntityMetadata(); - WrappedDataWatcher dataWatcher = new WrappedDataWatcher(); - - metadataHelper.setEntityStatus(dataWatcher, (byte) 0x20); // Invisible - - String customName = armorStand.getCustomNameStringNMS(); - if (customName != null && !customName.isEmpty()) { - metadataHelper.setCustomNameNMSObject(dataWatcher, armorStand.getCustomNameObjectNMS()); - metadataHelper.setCustomNameVisible(dataWatcher, true); - } - - metadataHelper.setNoGravity(dataWatcher, true); - metadataHelper.setArmorStandStatus(dataWatcher, (byte) (0x01 | 0x08 | 0x10)); // Small, no base plate, marker - - dataPacket.setEntityMetadata(dataWatcher.getWatchableObjects()); - dataPacket.setEntityID(armorStand.getIdNMS()); - dataPacket.sendPacket(receiver); - - } else { - WrapperPlayServerSpawnEntityLiving spawnPacket = new WrapperPlayServerSpawnEntityLiving(armorStand.getBukkitEntityNMS()); - spawnPacket.sendPacket(receiver); - } - } - - - private void sendSpawnItemPacket(Player receiver, NMSItem item) { - AbstractPacket packet = new WrapperPlayServerSpawnEntity(item.getBukkitEntityNMS(), ObjectTypes.ITEM_STACK, 1); - packet.sendPacket(receiver); - } - - - private void sendSpawnSlimePacket(Player receiver, NMSSlime slime) { - AbstractPacket spawnPacket = new WrapperPlayServerSpawnEntityLiving(slime.getBukkitEntityNMS()); - spawnPacket.sendPacket(receiver); - - if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_15_R1)) { - WrapperPlayServerEntityMetadata dataPacket = new WrapperPlayServerEntityMetadata(); - WrappedDataWatcher dataWatcher = new WrappedDataWatcher(); - - metadataHelper.setEntityStatus(dataWatcher, (byte) 0x20); // Invisible - metadataHelper.setSlimeSize(dataWatcher, 1); // Size 1 = small - - dataPacket.setEntityMetadata(dataWatcher.getWatchableObjects()); - dataPacket.setEntityID(slime.getIdNMS()); - dataPacket.sendPacket(receiver); - } - } - - - private void sendItemMetadataPacket(Player receiver, NMSItem item) { - WrapperPlayServerEntityMetadata packet = new WrapperPlayServerEntityMetadata(); - - WrappedDataWatcher dataWatcher = new WrappedDataWatcher(); - metadataHelper.setItemMetadata(dataWatcher, item.getRawItemStack()); - packet.setEntityMetadata(dataWatcher.getWatchableObjects()); - - packet.setEntityID(item.getIdNMS()); - packet.sendPacket(receiver); - } - - - private void sendVehicleAttachPacket(Player receiver, NMSEntity vehicle, NMSEntity passenger) { - if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_9_R1)) { - WrapperPlayServerMount packet = new WrapperPlayServerMount(); - packet.setVehicleId(vehicle.getIdNMS()); - packet.setPassengers(new int[] {passenger.getIdNMS()}); - packet.sendPacket(receiver); - } else { - WrapperPlayServerAttachEntity packet = new WrapperPlayServerAttachEntity(); - packet.setVehicleId(vehicle.getIdNMS()); - packet.setEntityId(passenger.getIdNMS()); - packet.sendPacket(receiver); - } - } - - - private void sendDestroyEntitiesPacket(Player player, List ids) { - if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_17_R1)) { - // Requires multiple packets - for (Integer id : ids) { - WrapperPlayServerEntityDestroy packet = new WrapperPlayServerEntityDestroy(); - packet.setEntity(id); - packet.sendPacket(player); - } - } else { - WrapperPlayServerEntityDestroy packet = new WrapperPlayServerEntityDestroy(); - packet.setEntities(ids); - packet.sendPacket(player); - } - } - - -} diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/bridge/protocollib/ProtocolLibHook.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/bridge/protocollib/ProtocolLibHook.java deleted file mode 100644 index 0b5093d4..00000000 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/bridge/protocollib/ProtocolLibHook.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.plugin.bridge.protocollib; - -import me.filoghost.fcommons.Preconditions; -import me.filoghost.fcommons.logging.ErrorCollector; -import me.filoghost.fcommons.logging.Log; -import me.filoghost.holographicdisplays.common.hologram.StandardHologram; -import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; -import me.filoghost.holographicdisplays.plugin.placeholder.tracking.PlaceholderLineTracker; -import me.filoghost.holographicdisplays.plugin.util.VersionUtils; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class ProtocolLibHook { - - private static boolean enabled; - private static PacketSender packetSender; - - public static void setup( - Plugin plugin, - NMSManager nmsManager, - ProtocolPacketSettings packetSettings, - PlaceholderLineTracker placeholderLineTracker, - ErrorCollector errorCollector) { - if (!Bukkit.getPluginManager().isPluginEnabled("ProtocolLib")) { - return; - } - - try { - String protocolVersion = Bukkit.getPluginManager().getPlugin("ProtocolLib").getDescription().getVersion(); - Matcher versionNumbersMatcher = Pattern.compile("([0-9.])+").matcher(protocolVersion); - - if (!versionNumbersMatcher.find()) { - throw new IllegalArgumentException("unable to find pattern match"); - } - - String versionNumbers = versionNumbersMatcher.group(); - - if (!VersionUtils.isVersionGreaterEqual(versionNumbers, "4.4")) { - errorCollector.add("detected old unsupported version of ProtocolLib, support disabled." - + " You must use ProtocolLib 4.4.0 or higher"); - return; - } - - } catch (Exception e) { - errorCollector.add(e, "could not detect ProtocolLib version (" + e.getMessage() + ")," - + " enabling support anyway and hoping for the best"); - } - - try { - MetadataHelper metadataHelper = new MetadataHelper(); - new PacketListener(plugin, nmsManager, metadataHelper, packetSettings, placeholderLineTracker).registerListener(); - packetSender = new PacketSender(metadataHelper); - Log.info("Enabled per-player placeholders with ProtocolLib."); - } catch (Exception e) { - errorCollector.add(e, "failed to load ProtocolLib support, is it updated?"); - return; - } - - enabled = true; - } - - public static void sendDestroyEntitiesPacket(Player player, StandardHologram hologram) { - checkState(); - - if (shouldReceivePacket(player, hologram)) { - packetSender.sendDestroyEntitiesPacket(player, hologram); - } - } - - public static void sendCreateEntitiesPacket(Player player, StandardHologram hologram) { - checkState(); - - if (shouldReceivePacket(player, hologram)) { - packetSender.sendCreateEntitiesPacket(player, hologram); - } - } - - private static boolean shouldReceivePacket(Player player, StandardHologram hologram) { - if (!player.isOnline()) { - return false; - } - - if (!player.getWorld().equals(hologram.getWorld())) { - return false; - } - - Location playerLocation = player.getLocation(); - double distanceSquared = distanceSquared(playerLocation.getX(), hologram.getX(), playerLocation.getZ(), hologram.getZ()); - - // Approximate, more checks are done for single entities - return distanceSquared < 128 * 128; - } - - private static double distanceSquared(double locX1, double locX2, double locZ1, double locZ2) { - double xDiff = locX1 - locX2; - double zDiff = locZ1 - locZ2; - return xDiff * xDiff + zDiff * zDiff; - } - - public static boolean isEnabled() { - return enabled; - } - - private static void checkState() { - Preconditions.checkState(isEnabled(), "hook not enabled"); - } - -} diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/HologramCommandManager.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/HologramCommandManager.java index f61c233d..aeceebda 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/HologramCommandManager.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/HologramCommandManager.java @@ -9,7 +9,6 @@ import me.filoghost.fcommons.command.CommandContext; import me.filoghost.fcommons.command.sub.SubCommand; import me.filoghost.fcommons.command.sub.SubCommandContext; import me.filoghost.fcommons.command.sub.SubCommandManager; -import me.filoghost.holographicdisplays.common.nms.NMSManager; import me.filoghost.holographicdisplays.plugin.HolographicDisplays; import me.filoghost.holographicdisplays.plugin.commands.subs.AddlineCommand; import me.filoghost.holographicdisplays.plugin.commands.subs.AlignCommand; @@ -31,9 +30,11 @@ import me.filoghost.holographicdisplays.plugin.commands.subs.ReloadCommand; import me.filoghost.holographicdisplays.plugin.commands.subs.RemovelineCommand; import me.filoghost.holographicdisplays.plugin.commands.subs.SetlineCommand; import me.filoghost.holographicdisplays.plugin.commands.subs.TeleportCommand; +import me.filoghost.holographicdisplays.plugin.disk.ConfigManager; import me.filoghost.holographicdisplays.plugin.disk.Settings; import me.filoghost.holographicdisplays.plugin.format.ColorScheme; import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologram; +import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologramManager; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ComponentBuilder; @@ -54,8 +55,12 @@ public class HologramCommandManager extends SubCommandManager { private final List subCommands; private final HelpCommand helpCommand; - public HologramCommandManager(HolographicDisplays holographicDisplays, InternalHologramEditor hologramEditor, NMSManager nmsManager) { + public HologramCommandManager( + HolographicDisplays holographicDisplays, + InternalHologramManager internalHologramManager, + ConfigManager configManager) { setName("holograms"); + InternalHologramEditor hologramEditor = new InternalHologramEditor(internalHologramManager, configManager); this.holographicDisplays = holographicDisplays; this.helpCommand = new HelpCommand(this); this.subCommands = new ArrayList<>(); @@ -79,7 +84,7 @@ public class HologramCommandManager extends SubCommandManager { subCommands.add(new ReadimageCommand(hologramEditor)); subCommands.add(new InfoCommand(this, hologramEditor)); - subCommands.add(new DebugCommand(nmsManager)); + subCommands.add(new DebugCommand()); subCommands.add(helpCommand); } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/DebugCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/DebugCommand.java index 647f7cc0..626ba645 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/DebugCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/DebugCommand.java @@ -6,89 +6,21 @@ package me.filoghost.holographicdisplays.plugin.commands.subs; import me.filoghost.fcommons.command.sub.SubCommandContext; -import me.filoghost.holographicdisplays.common.hologram.StandardHologram; -import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntity; import me.filoghost.holographicdisplays.plugin.commands.HologramSubCommand; import me.filoghost.holographicdisplays.plugin.format.ColorScheme; -import org.bukkit.Bukkit; -import org.bukkit.Chunk; -import org.bukkit.World; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Entity; - -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; public class DebugCommand extends HologramSubCommand { - private final NMSManager nmsManager; - - public DebugCommand(NMSManager nmsManager) { + public DebugCommand() { super("debug"); setShowInHelpCommand(false); setDescription("Displays information useful for debugging."); - - this.nmsManager = nmsManager; } @Override public void execute(CommandSender sender, String[] args, SubCommandContext context) { - boolean foundAnyHologram = false; - - for (World world : Bukkit.getWorlds()) { - Map hologramsDebugInfo = new HashMap<>(); - - for (Chunk chunk : world.getLoadedChunks()) { - for (Entity entity : chunk.getEntities()) { - NMSEntity nmsEntity = nmsManager.getNMSEntityBase(entity); - - if (nmsEntity == null) { - continue; - } - - StandardHologram ownerHologram = nmsEntity.getHologramLine().getHologram(); - HologramDebugInfo hologramDebugInfo = hologramsDebugInfo.computeIfAbsent(ownerHologram, key -> new HologramDebugInfo()); - - if (nmsEntity.isDeadNMS()) { - hologramDebugInfo.deadEntities++; - } else { - hologramDebugInfo.aliveEntities++; - } - } - } - - if (!hologramsDebugInfo.isEmpty()) { - foundAnyHologram = true; - sender.sendMessage(ColorScheme.PRIMARY + "Holograms in world '" + world.getName() + "':"); - - for (Entry entry : hologramsDebugInfo.entrySet()) { - StandardHologram hologram = entry.getKey(); - HologramDebugInfo debugInfo = entry.getValue(); - sender.sendMessage(ColorScheme.PRIMARY_DARKER + "- '" + hologram.toFormattedString() + "':" - + " " + hologram.getLineCount() + " lines," - + " " + debugInfo.getTotalEntities() + " entities" - + " (" + debugInfo.aliveEntities + " alive, " + debugInfo.deadEntities + " dead)"); - } - } - } - - if (!foundAnyHologram) { - sender.sendMessage(ColorScheme.ERROR + "Couldn't find any loaded hologram (holograms may be in unloaded chunks)."); - } + sender.sendMessage(ColorScheme.ERROR + "This command is currently unused."); } - private static class HologramDebugInfo { - - private int aliveEntities; - private int deadEntities; - - public int getTotalEntities() { - return aliveEntities + deadEntities; - } - - } - - } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/api/APIHologram.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/api/APIHologram.java index bcda4202..eff987c2 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/api/APIHologram.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/api/APIHologram.java @@ -7,11 +7,10 @@ package me.filoghost.holographicdisplays.plugin.hologram.api; import me.filoghost.fcommons.Preconditions; import me.filoghost.holographicdisplays.api.hologram.Hologram; -import me.filoghost.holographicdisplays.common.nms.NMSManager; import me.filoghost.holographicdisplays.plugin.api.v2.V2HologramAdapter; import me.filoghost.holographicdisplays.plugin.disk.Settings; import me.filoghost.holographicdisplays.plugin.hologram.base.BaseHologram; -import me.filoghost.holographicdisplays.plugin.placeholder.tracking.PlaceholderLineTracker; +import me.filoghost.holographicdisplays.plugin.hologram.tracking.LineTrackerManager; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -34,14 +33,13 @@ public class APIHologram extends BaseHologram implements Hologr protected APIHologram( Location location, Plugin plugin, - NMSManager nmsManager, APIHologramManager apiHologramManager, - PlaceholderLineTracker placeholderLineTracker) { - super(location, nmsManager, placeholderLineTracker); + LineTrackerManager lineTrackerManager) { + super(location, lineTrackerManager); Preconditions.notNull(plugin, "plugin"); this.plugin = plugin; this.apiHologramManager = apiHologramManager; - this.visibilitySettings = new DefaultVisibilitySettings(this); + this.visibilitySettings = new DefaultVisibilitySettings(); this.creationTimestamp = System.currentTimeMillis(); this.v2Adapter = new V2HologramAdapter(this); } @@ -103,7 +101,6 @@ public class APIHologram extends BaseHologram implements Hologr } this.allowPlaceholders = allowPlaceholders; - refresh(true); } @Override @@ -148,11 +145,6 @@ public class APIHologram extends BaseHologram implements Hologr apiHologramManager.deleteHologram(this); } - @Override - public String toFormattedString() { - return plugin.getName() + "@" + Integer.toHexString(hashCode()); - } - public V2HologramAdapter getV2Adapter() { return v2Adapter; } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/api/APIHologramManager.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/api/APIHologramManager.java index 434edbd6..9a4b94ac 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/api/APIHologramManager.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/api/APIHologramManager.java @@ -6,9 +6,8 @@ package me.filoghost.holographicdisplays.plugin.hologram.api; import me.filoghost.holographicdisplays.api.hologram.Hologram; -import me.filoghost.holographicdisplays.common.nms.NMSManager; import me.filoghost.holographicdisplays.plugin.hologram.base.BaseHologramManager; -import me.filoghost.holographicdisplays.plugin.placeholder.tracking.PlaceholderLineTracker; +import me.filoghost.holographicdisplays.plugin.hologram.tracking.LineTrackerManager; import org.bukkit.Location; import org.bukkit.plugin.Plugin; @@ -19,16 +18,14 @@ import java.util.List; public class APIHologramManager extends BaseHologramManager { - private final NMSManager nmsManager; - private final PlaceholderLineTracker placeholderLineTracker; + private final LineTrackerManager lineTrackerManager; - public APIHologramManager(NMSManager nmsManager, PlaceholderLineTracker placeholderLineTracker) { - this.nmsManager = nmsManager; - this.placeholderLineTracker = placeholderLineTracker; + public APIHologramManager(LineTrackerManager lineTrackerManager) { + this.lineTrackerManager = lineTrackerManager; } public APIHologram createHologram(Location source, Plugin plugin) { - APIHologram hologram = new APIHologram(source, plugin, nmsManager, this, placeholderLineTracker); + APIHologram hologram = new APIHologram(source, plugin, this, lineTrackerManager); super.addHologram(hologram); return hologram; } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/api/DefaultVisibilitySettings.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/api/DefaultVisibilitySettings.java index 6785b0fb..b2cb4c40 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/api/DefaultVisibilitySettings.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/api/DefaultVisibilitySettings.java @@ -7,10 +7,7 @@ package me.filoghost.holographicdisplays.plugin.hologram.api; import me.filoghost.fcommons.Preconditions; import me.filoghost.holographicdisplays.api.hologram.VisibilitySettings; -import me.filoghost.holographicdisplays.common.hologram.StandardHologram; import me.filoghost.holographicdisplays.plugin.api.v2.V2VisibilityManagerAdapter; -import me.filoghost.holographicdisplays.plugin.bridge.protocollib.ProtocolLibHook; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -20,14 +17,11 @@ import java.util.concurrent.ConcurrentHashMap; public class DefaultVisibilitySettings implements VisibilitySettings { - private final StandardHologram hologram; private final V2VisibilityManagerAdapter v2Adapter; private Map visibilityByPlayer; private Visibility defaultVisibility; - public DefaultVisibilitySettings(StandardHologram hologram) { - Preconditions.notNull(hologram, "hologram"); - this.hologram = hologram; + public DefaultVisibilitySettings() { this.v2Adapter = new V2VisibilityManagerAdapter(this); this.defaultVisibility = Visibility.VISIBLE; } @@ -44,30 +38,15 @@ public class DefaultVisibilitySettings implements VisibilitySettings { } this.defaultVisibility = defaultVisibility; - - for (Player player : Bukkit.getOnlinePlayers()) { - if (visibilityByPlayer != null && visibilityByPlayer.containsKey(player.getUniqueId())) { - // Has a specific value set - continue; - } - - sendVisibilityChangePacket(hologram, player, defaultVisibility); - } } @Override public void setIndividualVisibility(@NotNull Player player, @NotNull Visibility visibility) { - Visibility oldVisibility = getVisibility(player); - // Lazy initialization if (visibilityByPlayer == null) { visibilityByPlayer = new ConcurrentHashMap<>(); } visibilityByPlayer.put(player.getUniqueId(), visibility); - - if (oldVisibility != visibility) { - sendVisibilityChangePacket(hologram, player, visibility); - } } @Override @@ -96,11 +75,7 @@ public class DefaultVisibilitySettings implements VisibilitySettings { return; } - Visibility oldVisibility = visibilityByPlayer.remove(player.getUniqueId()); - - if (oldVisibility != null && oldVisibility != defaultVisibility) { - sendVisibilityChangePacket(hologram, player, defaultVisibility); - } + visibilityByPlayer.remove(player.getUniqueId()); } @Override @@ -109,23 +84,7 @@ public class DefaultVisibilitySettings implements VisibilitySettings { return; } - for (Player player : Bukkit.getOnlinePlayers()) { - Visibility oldVisibility = getVisibility(player); - if (oldVisibility != defaultVisibility) { - sendVisibilityChangePacket(hologram, player, defaultVisibility); - } - } - visibilityByPlayer = null; - } - - private void sendVisibilityChangePacket(StandardHologram hologram, Player player, Visibility visibility) { - if (ProtocolLibHook.isEnabled()) { - if (visibility == Visibility.VISIBLE) { - ProtocolLibHook.sendCreateEntitiesPacket(player, hologram); - } else { - ProtocolLibHook.sendDestroyEntitiesPacket(player, hologram); - } - } + visibilityByPlayer.clear(); } @Override diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseHologram.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseHologram.java index 52ed4e67..574a6f3c 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseHologram.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseHologram.java @@ -8,9 +8,8 @@ package me.filoghost.holographicdisplays.plugin.hologram.base; import me.filoghost.fcommons.Preconditions; import me.filoghost.holographicdisplays.common.hologram.StandardHologram; import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.nms.NMSManager; import me.filoghost.holographicdisplays.plugin.disk.Settings; -import me.filoghost.holographicdisplays.plugin.placeholder.tracking.PlaceholderLineTracker; +import me.filoghost.holographicdisplays.plugin.hologram.tracking.LineTrackerManager; import org.bukkit.Location; import org.bukkit.World; import org.jetbrains.annotations.NotNull; @@ -22,41 +21,20 @@ import java.util.List; public abstract class BaseHologram extends BaseHologramComponent implements StandardHologram { - private final NMSManager nmsManager; - private final PlaceholderLineTracker placeholderLineTracker; + private final LineTrackerManager lineTrackerManager; private final List lines; private final List unmodifiableLinesView; - private boolean deleted; - - public BaseHologram(Location location, NMSManager nmsManager, PlaceholderLineTracker placeholderLineTracker) { - this.placeholderLineTracker = placeholderLineTracker; + public BaseHologram(Location location, LineTrackerManager lineTrackerManager) { Preconditions.notNull(location, "location"); this.setLocation(location); - this.nmsManager = nmsManager; + this.lineTrackerManager = lineTrackerManager; this.lines = new ArrayList<>(); this.unmodifiableLinesView = Collections.unmodifiableList(lines); } - protected final NMSManager getNMSManager() { - return nmsManager; - } - - protected final PlaceholderLineTracker getPlaceholderLineTracker() { - return placeholderLineTracker; - } - - @Override - public boolean isDeleted() { - return deleted; - } - - @Override - public void setDeleted() { - if (!deleted) { - deleted = true; - despawnEntities(); - } + protected final LineTrackerManager getTrackerManager() { + return lineTrackerManager; } @Override @@ -68,29 +46,29 @@ public abstract class BaseHologram extends BaseH checkNotDeleted(); lines.add(line); - refresh(); + updateLineLocations(); } public void addLines(List newLines) { checkNotDeleted(); lines.addAll(newLines); - refresh(); + updateLineLocations(); } public void insertLine(int afterIndex, T line) { checkNotDeleted(); lines.add(afterIndex, line); - refresh(); + updateLineLocations(); } public void setLine(int index, T line) { checkNotDeleted(); T previousLine = lines.set(index, line); - previousLine.despawn(); - refresh(); + previousLine.setDeleted(); + updateLineLocations(); } public void setLines(List newLines) { @@ -98,22 +76,22 @@ public abstract class BaseHologram extends BaseH clearLines(); lines.addAll(newLines); - refresh(); + updateLineLocations(); } public void removeLine(int index) { checkNotDeleted(); - lines.remove(index).despawn(); - refresh(); + lines.remove(index).setDeleted(); + updateLineLocations(); } public void removeLine(T line) { checkNotDeleted(); lines.remove(line); - line.despawn(); - refresh(); + line.setDeleted(); + updateLineLocations(); } public void clearLines() { @@ -123,7 +101,7 @@ public abstract class BaseHologram extends BaseH while (iterator.hasNext()) { T line = iterator.next(); iterator.remove(); - line.despawn(); + line.setDeleted(); } // No need to refresh, since there are no lines @@ -145,35 +123,14 @@ public abstract class BaseHologram extends BaseH Preconditions.notNull(world, "world"); setLocation(world, x, y, z); - refresh(); + updateLineLocations(); } - @Override - public void refresh() { - refresh(false); - } - - @Override - public void refresh(boolean forceRespawn) { - refresh(forceRespawn, isInLoadedChunk()); - } - - @Override - public void refresh(boolean forceRespawn, boolean isChunkLoaded) { - checkNotDeleted(); - - if (isChunkLoaded) { - respawnEntities(forceRespawn); - } else { - despawnEntities(); - } - } - - /* + /** * When spawning at a location, the top part of the first line should be exactly on that location. * The second line is below the first, and so on. */ - private void respawnEntities(boolean forceRespawn) { + private void updateLineLocations() { double currentLineY = getY(); for (int i = 0; i < lines.size(); i++) { @@ -184,32 +141,13 @@ public abstract class BaseHologram extends BaseH currentLineY -= Settings.spaceBetweenLines; } - if (forceRespawn) { - line.despawn(); - } - line.respawn(getWorld(), getX(), currentLineY, getZ()); + line.setLocation(getWorld(), getX(), currentLineY, getZ()); } } - @Override - public void despawnEntities() { - for (T line : lines) { - line.despawn(); - } - } - - private void checkNotDeleted() { - Preconditions.checkState(!deleted, "hologram is not usable after being deleted"); - } - @Override public String toString() { - return "BaseHologram [location=" + getLocation() + ", lines=" + lines + ", deleted=" + deleted + "]"; + return "BaseHologram [location=" + getLocation() + ", lines=" + lines + ", deleted=" + isDeleted() + "]"; } - /* - * Object.equals() and Object.hashCode() are not overridden: - * two holograms are equal only if they are the same exact instance. - */ - } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseHologramComponent.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseHologramComponent.java index 5197e8b0..b602a274 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseHologramComponent.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseHologramComponent.java @@ -6,36 +6,28 @@ package me.filoghost.holographicdisplays.plugin.hologram.base; import me.filoghost.fcommons.Preconditions; -import org.bukkit.Chunk; +import me.filoghost.holographicdisplays.common.hologram.StandardHologramComponent; import org.bukkit.Location; import org.bukkit.World; +import org.jetbrains.annotations.MustBeInvokedByOverriders; import org.jetbrains.annotations.NotNull; -public abstract class BaseHologramComponent { +public abstract class BaseHologramComponent implements StandardHologramComponent { private World world; private double x, y, z; private int chunkX, chunkZ; + private boolean deleted; - public boolean isInChunk(Chunk chunk) { - return world != null - && chunk.getWorld() == world - && chunk.getX() == chunkX - && chunk.getZ() == chunkZ; - } - - public boolean isInLoadedChunk() { - return world.isChunkLoaded(chunkX, chunkZ); - } - - public @NotNull Location getLocation() { + public final @NotNull Location getLocation() { return new Location(world, x, y, z); } - protected void setLocation(Location location) { + protected final void setLocation(Location location) { setLocation(location.getWorld(), location.getX(), location.getY(), location.getZ()); } + @MustBeInvokedByOverriders protected void setLocation(World world, double x, double y, double z) { Preconditions.notNull(world, "world"); @@ -43,29 +35,68 @@ public abstract class BaseHologramComponent { this.x = x; this.y = y; this.z = z; - this.chunkX = floor(x) >> 4; - this.chunkZ = floor(z) >> 4; + this.chunkX = getChunkCoord(x); + this.chunkZ = getChunkCoord(z); } - private static int floor(double num) { - int floor = (int) num; - return floor == num ? floor : floor - (int) (Double.doubleToRawLongBits(num) >>> 63); + private int getChunkCoord(double locationCoord) { + return Location.locToBlock(locationCoord) >> 4; } - public @NotNull World getWorld() { + @Override + public final World getWorld() { return world; } - public double getX() { + @Override + public final double getX() { return x; } - public double getY() { + @Override + public final double getY() { return y; } - public double getZ() { + @Override + public final double getZ() { return z; } + @Override + public final int getChunkX() { + return chunkX; + } + + @Override + public final int getChunkZ() { + return chunkZ; + } + + @Override + public final boolean isDeleted() { + return deleted; + } + + @Override + public final void setDeleted() { + deleted = true; + } + + protected final void checkNotDeleted() { + Preconditions.checkState(!deleted, "not usable after being deleted"); + } + + @Override + public final boolean equals(Object obj) { + // Use the default identity comparison: two different instances are never equal + return super.equals(obj); + } + + @Override + public final int hashCode() { + // Use the default identity hash code: each instance has a different hash code + return super.hashCode(); + } + } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseHologramLine.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseHologramLine.java index 9a211fd3..39baf1de 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseHologramLine.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseHologramLine.java @@ -6,80 +6,38 @@ package me.filoghost.holographicdisplays.plugin.hologram.base; import me.filoghost.fcommons.Preconditions; -import me.filoghost.holographicdisplays.common.DebugLogger; import me.filoghost.holographicdisplays.common.hologram.StandardHologram; import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.SpawnFailedException; -import me.filoghost.holographicdisplays.plugin.placeholder.tracking.PlaceholderLineTracker; +import me.filoghost.holographicdisplays.plugin.hologram.tracking.LineTracker; +import me.filoghost.holographicdisplays.plugin.hologram.tracking.LineTrackerManager; import org.bukkit.World; public abstract class BaseHologramLine extends BaseHologramComponent implements StandardHologramLine { private final BaseHologram hologram; - - private boolean isSpawned; + private final LineTracker tracker; protected BaseHologramLine(BaseHologram hologram) { Preconditions.notNull(hologram, "parent hologram"); this.hologram = hologram; + this.tracker = createTracker(hologram.getTrackerManager()); } + protected abstract LineTracker createTracker(LineTrackerManager trackerManager); + @Override public final StandardHologram getHologram() { return hologram; } - protected final NMSManager getNMSManager() { - return hologram.getNMSManager(); - } - - protected final PlaceholderLineTracker getPlaceholderLineTracker() { - return hologram.getPlaceholderLineTracker(); + protected void setChanged() { + tracker.setLineChanged(); } @Override - public final void respawn(World world, double x, double y, double z) { - Preconditions.notNull(world, "world"); - - boolean changedWorld = world != getWorld(); - setLocation(world, x, y, z); - - try { - if (changedWorld) { - // World has changed, entities must be fully respawned - despawnEntities(); - spawnEntities(world, x, y, z); - - } else if (isSpawned) { - // Line is already spawned, respawn can be avoided - teleportEntities(x, y, z); - - } else { - // Line is not spawned, entities must be spawned - spawnEntities(world, x, y, z); - } - } catch (SpawnFailedException e) { - DebugLogger.handleSpawnFail(e, this); - } - - isSpawned = true; + public final void setLocation(World world, double x, double y, double z) { + super.setLocation(world, x, y, z); + setChanged(); } - @Override - public final void despawn() { - despawnEntities(); - isSpawned = false; - } - - protected final boolean isSpawned() { - return isSpawned; - } - - protected abstract void spawnEntities(World world, double x, double y, double z) throws SpawnFailedException; - - protected abstract void teleportEntities(double x, double y, double z); - - protected abstract void despawnEntities(); - } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseHologramManager.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseHologramManager.java index 42069bda..82a14150 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseHologramManager.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseHologramManager.java @@ -5,9 +5,7 @@ */ package me.filoghost.holographicdisplays.plugin.hologram.base; -import me.filoghost.fcommons.Preconditions; import me.filoghost.holographicdisplays.common.hologram.StandardHologram; -import org.bukkit.Chunk; import java.util.ArrayList; import java.util.Collections; @@ -41,13 +39,4 @@ public abstract class BaseHologramManager { } } - public void onChunkLoad(Chunk chunk) { - // Load the holograms in that chunk - for (H hologram : holograms) { - if (hologram.isInChunk(chunk)) { - hologram.refresh(false, true); - } - } - } - } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseItemLine.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseItemLine.java index 5ceefc34..e84e7c2f 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseItemLine.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseItemLine.java @@ -8,24 +8,17 @@ package me.filoghost.holographicdisplays.plugin.hologram.base; import me.filoghost.fcommons.Preconditions; import me.filoghost.fcommons.logging.Log; import me.filoghost.holographicdisplays.api.hologram.PickupHandler; -import me.filoghost.holographicdisplays.common.DebugLogger; import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; -import me.filoghost.holographicdisplays.common.nms.SpawnFailedException; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.nms.entity.NMSItem; -import org.bukkit.World; +import me.filoghost.holographicdisplays.plugin.hologram.tracking.ItemLineTracker; +import me.filoghost.holographicdisplays.plugin.hologram.tracking.LineTrackerManager; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.MustBeInvokedByOverriders; import org.jetbrains.annotations.Nullable; -import java.util.Collection; - public abstract class BaseItemLine extends BaseTouchableLine implements StandardItemLine { private ItemStack itemStack; - - private NMSItem itemEntity; - private NMSArmorStand itemVehicleEntity; private PickupHandler pickupHandler; public BaseItemLine(BaseHologram hologram, ItemStack itemStack) { @@ -33,6 +26,11 @@ public abstract class BaseItemLine extends BaseTouchableLine implements Standard setItemStack(itemStack); } + @Override + public ItemLineTracker createTracker(LineTrackerManager trackerManager) { + return trackerManager.startTracking(this); + } + @Override public void onPickup(Player player) { if (pickupHandler == null || !getHologram().isVisibleTo(player)) { @@ -51,10 +49,12 @@ public abstract class BaseItemLine extends BaseTouchableLine implements Standard return pickupHandler; } + @MustBeInvokedByOverriders public void setPickupHandler(@Nullable PickupHandler pickupHandler) { this.pickupHandler = pickupHandler; } + @Override public @Nullable ItemStack getItemStack() { return itemStack; } @@ -64,74 +64,7 @@ public abstract class BaseItemLine extends BaseTouchableLine implements Standard Preconditions.checkArgument(0 < itemStack.getAmount() && itemStack.getAmount() <= 64, "itemStack's amount must be between 1 and 64"); } this.itemStack = itemStack; - - if (itemStack == null) { - // Despawn the entity (if existing) since the item shouldn't be visible - despawnItem(); - return; - } - - if (itemEntity != null) { - // Simply update the existing entity - itemEntity.setItemStackNMS(itemStack); - } else { - // Spawn the entity, if it needs to be spawned - if (super.isSpawned()) { - spawnItem(getWorld(), getX(), getY(), getZ()); - } - } - } - - @Override - public void spawnEntities(World world, double x, double y, double z) throws SpawnFailedException { - super.spawnEntities(world, x, y, z); - - if (itemStack != null) { - spawnItem(world, x, y, z); - } - } - - @Override - public void teleportEntities(double x, double y, double z) { - super.teleportEntities(x, y, z); - - if (itemVehicleEntity != null) { - itemVehicleEntity.setLocationNMS(x, y + getItemSpawnOffset(), z); - } - if (itemEntity != null) { - itemEntity.setLocationNMS(x, y + getItemSpawnOffset(), z); - } - } - - @Override - public void despawnEntities() { - super.despawnEntities(); - - despawnItem(); - } - - private void spawnItem(World world, double x, double y, double z) { - if (world != null) { - try { - itemEntity = getNMSManager().spawnNMSItem(world, x, y + getItemSpawnOffset(), z, this, itemStack); - itemVehicleEntity = getNMSManager().spawnNMSArmorStand(world, x, y + getItemSpawnOffset(), z, this); - itemVehicleEntity.setPassengerNMS(itemEntity); - } catch (SpawnFailedException e) { - DebugLogger.handleSpawnFail(e, this); - } - } - } - - private void despawnItem() { - if (itemVehicleEntity != null) { - itemVehicleEntity.killEntityNMS(); - itemVehicleEntity = null; - } - - if (itemEntity != null) { - itemEntity.killEntityNMS(); - itemEntity = null; - } + setChanged(); } @Override @@ -139,32 +72,6 @@ public abstract class BaseItemLine extends BaseTouchableLine implements Standard return 0.7; } - @Override - public void collectTrackedEntityIDs(Player player, Collection collector) { - super.collectTrackedEntityIDs(player, collector); - - if (itemVehicleEntity != null && itemVehicleEntity.isTrackedBy(player)) { - collector.add(itemVehicleEntity.getIdNMS()); - } - if (itemEntity != null && itemEntity.isTrackedBy(player)) { - collector.add(itemEntity.getIdNMS()); - } - } - - @Override - public NMSItem getNMSItem() { - return itemEntity; - } - - @Override - public NMSArmorStand getNMSItemVehicle() { - return itemVehicleEntity; - } - - private double getItemSpawnOffset() { - return 0; - } - @Override public String toString() { return "ItemLine [itemStack=" + itemStack + "]"; diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseTextLine.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseTextLine.java index 951b2513..ae9e70a1 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseTextLine.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseTextLine.java @@ -6,24 +6,24 @@ package me.filoghost.holographicdisplays.plugin.hologram.base; import me.filoghost.holographicdisplays.common.hologram.StandardTextLine; -import me.filoghost.holographicdisplays.common.nms.SpawnFailedException; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import org.bukkit.World; -import org.bukkit.entity.Player; +import me.filoghost.holographicdisplays.plugin.hologram.tracking.LineTrackerManager; +import me.filoghost.holographicdisplays.plugin.hologram.tracking.TextLineTracker; import org.jetbrains.annotations.Nullable; -import java.util.Collection; - public abstract class BaseTextLine extends BaseTouchableLine implements StandardTextLine { private String text; - private NMSArmorStand textEntity; public BaseTextLine(BaseHologram hologram, String text) { super(hologram); setText(text); } + @Override + protected TextLineTracker createTracker(LineTrackerManager trackerManager) { + return trackerManager.startTracking(this); + } + @Override public @Nullable String getText() { return text; @@ -31,43 +31,7 @@ public abstract class BaseTextLine extends BaseTouchableLine implements Standard public void setText(@Nullable String text) { this.text = text; - - if (textEntity != null) { - textEntity.setCustomNameNMS(text); - getPlaceholderLineTracker().onTextLineChange(this); - } - } - - @Override - public void spawnEntities(World world, double x, double y, double z) throws SpawnFailedException { - super.spawnEntities(world, x, y, z); - - textEntity = getNMSManager().spawnNMSArmorStand(world, x, y + getTextSpawnOffset(), z, this); - - if (text != null && !text.isEmpty()) { - textEntity.setCustomNameNMS(text); - } - - getPlaceholderLineTracker().onTextLineChange(this); - } - - @Override - public void teleportEntities(double x, double y, double z) { - super.teleportEntities(x, y, z); - - if (textEntity != null) { - textEntity.setLocationNMS(x, y + getTextSpawnOffset(), z); - } - } - - @Override - public void despawnEntities() { - super.despawnEntities(); - - if (textEntity != null) { - textEntity.killEntityNMS(); - textEntity = null; - } + setChanged(); } @Override @@ -75,24 +39,6 @@ public abstract class BaseTextLine extends BaseTouchableLine implements Standard return 0.23; } - @Override - public void collectTrackedEntityIDs(Player player, Collection collector) { - super.collectTrackedEntityIDs(player, collector); - - if (textEntity != null && textEntity.isTrackedBy(player)) { - collector.add(textEntity.getIdNMS()); - } - } - - @Override - public NMSArmorStand getNMSArmorStand() { - return textEntity; - } - - private double getTextSpawnOffset() { - return -0.29; - } - @Override public String toString() { return "TextLine [text=" + text + "]"; diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseTouchableLine.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseTouchableLine.java index b72f4e87..89e7ceb3 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseTouchableLine.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseTouchableLine.java @@ -7,16 +7,12 @@ package me.filoghost.holographicdisplays.plugin.hologram.base; import me.filoghost.fcommons.logging.Log; import me.filoghost.holographicdisplays.api.hologram.TouchHandler; -import me.filoghost.holographicdisplays.common.DebugLogger; import me.filoghost.holographicdisplays.common.hologram.StandardTouchableLine; -import me.filoghost.holographicdisplays.common.nms.SpawnFailedException; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.common.nms.entity.NMSSlime; -import org.bukkit.World; +import org.bukkit.GameMode; import org.bukkit.entity.Player; +import org.jetbrains.annotations.MustBeInvokedByOverriders; import org.jetbrains.annotations.Nullable; -import java.util.Collection; import java.util.Map; import java.util.WeakHashMap; @@ -26,22 +22,20 @@ import java.util.WeakHashMap; */ public abstract class BaseTouchableLine extends BaseHologramLine implements StandardTouchableLine { - private static final double SLIME_HEIGHT = 0.5; - private static final Map lastClickByPlayer = new WeakHashMap<>(); private TouchHandler touchHandler; - private NMSSlime slimeEntity; - private NMSArmorStand slimeVehicleEntity; - - protected BaseTouchableLine(BaseHologram hologram) { super(hologram); } @Override public void onTouch(Player player) { + if (player.getGameMode() == GameMode.SPECTATOR) { + return; + } + if (touchHandler == null || !getHologram().isVisibleTo(player)) { return; } @@ -62,97 +56,19 @@ public abstract class BaseTouchableLine extends BaseHologramLine implements Stan } } + @Override + public boolean hasTouchHandler() { + return touchHandler != null; + } + + @MustBeInvokedByOverriders public void setTouchHandler(@Nullable TouchHandler touchHandler) { this.touchHandler = touchHandler; - - if (touchHandler == null) { - // Despawn the entity (if existing) since there is no touch handler - despawnSlime(); - return; - } - - if (slimeEntity == null && super.isSpawned()) { - // Spawn the entity since it's not spawned - spawnSlime(getWorld(), getX(), getY(), getZ()); - } + setChanged(); } public @Nullable TouchHandler getTouchHandler() { - return this.touchHandler; - } - - @Override - public void spawnEntities(World world, double x, double y, double z) throws SpawnFailedException { - if (touchHandler != null) { - spawnSlime(world, x, y, z); - } - } - - @Override - public void teleportEntities(double x, double y, double z) { - if (slimeVehicleEntity != null) { - slimeVehicleEntity.setLocationNMS(x, getSlimeSpawnY(y), z); - } - if (slimeEntity != null) { - slimeEntity.setLocationNMS(x, getSlimeSpawnY(y), z); - } - } - - @Override - public void despawnEntities() { - despawnSlime(); - } - - private void spawnSlime(World world, double x, double y, double z) { - if (world != null) { - try { - slimeEntity = getNMSManager().spawnNMSSlime(world, x, getSlimeSpawnY(y), z, this); - slimeVehicleEntity = getNMSManager().spawnNMSArmorStand(world, x, getSlimeSpawnY(y), z, this); - slimeVehicleEntity.setPassengerNMS(slimeEntity); - } catch (SpawnFailedException e) { - DebugLogger.handleSpawnFail(e, this); - } - } - } - - private void despawnSlime() { - if (slimeEntity != null) { - slimeEntity.killEntityNMS(); - slimeEntity = null; - } - - if (slimeVehicleEntity != null) { - slimeVehicleEntity.killEntityNMS(); - slimeVehicleEntity = null; - } - } - - private double getSlimeSpawnY(double y) { - return y + ((getHeight() - SLIME_HEIGHT) / 2) + getSlimeSpawnOffset(); - } - - private double getSlimeSpawnOffset() { - return 0; - } - - @Override - public void collectTrackedEntityIDs(Player player, Collection collector) { - if (slimeVehicleEntity != null && slimeVehicleEntity.isTrackedBy(player)) { - collector.add(slimeVehicleEntity.getIdNMS()); - } - if (slimeEntity != null && slimeEntity.isTrackedBy(player)) { - collector.add(slimeEntity.getIdNMS()); - } - } - - @Override - public NMSArmorStand getNMSSlimeVehicle() { - return slimeVehicleEntity; - } - - @Override - public NMSSlime getNMSSlime() { - return slimeEntity; + return touchHandler; } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/internal/InternalHologram.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/internal/InternalHologram.java index 0ce43209..44dd4a59 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/internal/InternalHologram.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/internal/InternalHologram.java @@ -5,10 +5,9 @@ */ package me.filoghost.holographicdisplays.plugin.hologram.internal; -import me.filoghost.holographicdisplays.common.nms.NMSManager; import me.filoghost.holographicdisplays.plugin.HolographicDisplays; import me.filoghost.holographicdisplays.plugin.hologram.base.BaseHologram; -import me.filoghost.holographicdisplays.plugin.placeholder.tracking.PlaceholderLineTracker; +import me.filoghost.holographicdisplays.plugin.hologram.tracking.LineTrackerManager; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -18,8 +17,8 @@ public class InternalHologram extends BaseHologram { private final String name; - protected InternalHologram(Location location, String name, NMSManager nmsManager, PlaceholderLineTracker placeholderLineTracker) { - super(location, nmsManager, placeholderLineTracker); + protected InternalHologram(Location location, String name, LineTrackerManager lineTrackerManager) { + super(location, lineTrackerManager); this.name = name; } @@ -45,11 +44,6 @@ public class InternalHologram extends BaseHologram { return true; } - @Override - public String toFormattedString() { - return name; - } - @Override public String toString() { return "InternalHologram [name=" + name + ", super=" + super.toString() + "]"; diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/internal/InternalHologramManager.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/internal/InternalHologramManager.java index 155a45ca..26c00239 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/internal/InternalHologramManager.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/internal/InternalHologramManager.java @@ -5,23 +5,20 @@ */ package me.filoghost.holographicdisplays.plugin.hologram.internal; -import me.filoghost.holographicdisplays.common.nms.NMSManager; import me.filoghost.holographicdisplays.plugin.hologram.base.BaseHologramManager; -import me.filoghost.holographicdisplays.plugin.placeholder.tracking.PlaceholderLineTracker; +import me.filoghost.holographicdisplays.plugin.hologram.tracking.LineTrackerManager; import org.bukkit.Location; public class InternalHologramManager extends BaseHologramManager { - private final NMSManager nmsManager; - private final PlaceholderLineTracker placeholderLineTracker; + private final LineTrackerManager lineTrackerManager; - public InternalHologramManager(NMSManager nmsManager, PlaceholderLineTracker placeholderLineTracker) { - this.nmsManager = nmsManager; - this.placeholderLineTracker = placeholderLineTracker; + public InternalHologramManager(LineTrackerManager lineTrackerManager) { + this.lineTrackerManager = lineTrackerManager; } public InternalHologram createHologram(Location source, String name) { - InternalHologram hologram = new InternalHologram(source, name, nmsManager, placeholderLineTracker); + InternalHologram hologram = new InternalHologram(source, name, lineTrackerManager); super.addHologram(hologram); return hologram; } @@ -35,8 +32,4 @@ public class InternalHologramManager extends BaseHologramManager + placeholderTracker.updateAndGetIndividualReplacement(occurrence, player)); + + if (PlaceholderAPIHook.isEnabled() && PlaceholderAPIHook.containsPlaceholders(text)) { + text = PlaceholderAPIHook.replacePlaceholders(player, text); + } + + return text; + } + + boolean containsIndividualPlaceholders() { + if (textWithoutReplacements == null) { + return false; + } + + return placeholderTracker.containsIndividualPlaceholders(textWithoutReplacements) + || PlaceholderAPIHook.containsPlaceholders(textWithoutReplacements.getUnreplacedString()); + } + +} diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/ItemLineTracker.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/ItemLineTracker.java new file mode 100644 index 00000000..26de8566 --- /dev/null +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/ItemLineTracker.java @@ -0,0 +1,126 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.plugin.hologram.tracking; + +import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.NMSManager; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.MustBeInvokedByOverriders; + +import java.util.Objects; + +public class ItemLineTracker extends TouchableLineTracker { + + private final EntityID vehicleEntityID; + private final EntityID itemEntityID; + + private ItemStack itemStack; + private boolean itemStackChanged; + + private boolean spawnItemEntities; + private boolean spawnItemEntitiesChanged; + + public ItemLineTracker(StandardItemLine line, NMSManager nmsManager) { + super(line, nmsManager); + this.vehicleEntityID = nmsManager.newEntityID(); + this.itemEntityID = nmsManager.newEntityID(); + } + + @Override + protected boolean updatePlaceholders() { + return false; + } + + @MustBeInvokedByOverriders + @Override + protected void detectChanges() { + super.detectChanges(); + + ItemStack itemStack = line.getItemStack(); + if (!Objects.equals(this.itemStack, itemStack)) { + this.itemStack = itemStack; + this.itemStackChanged = true; + } + + boolean spawnItemEntities = itemStack != null; + if (this.spawnItemEntities != spawnItemEntities) { + this.spawnItemEntities = spawnItemEntities; + this.spawnItemEntitiesChanged = true; + } + } + + @MustBeInvokedByOverriders + @Override + protected void clearDetectedChanges() { + super.clearDetectedChanges(); + this.itemStackChanged = false; + this.spawnItemEntitiesChanged = false; + } + + @MustBeInvokedByOverriders + @Override + protected void addSpawnPackets(NMSPacketList packetList) { + super.addSpawnPackets(packetList); + + if (spawnItemEntities) { + addItemSpawnPackets(packetList); + } + } + + @MustBeInvokedByOverriders + @Override + protected void addDestroyPackets(NMSPacketList packetList) { + super.addDestroyPackets(packetList); + + if (spawnItemEntities) { + addItemDestroyPackets(packetList); + } + } + + @MustBeInvokedByOverriders + @Override + protected void addChangesPackets(NMSPacketList packetList) { + super.addChangesPackets(packetList); + + if (spawnItemEntitiesChanged) { + if (spawnItemEntities) { + addItemSpawnPackets(packetList); + } else { + addItemDestroyPackets(packetList); + } + } else if (itemStackChanged) { + // Only send item changes if full spawn/destroy packets we not sent + packetList.addItemStackChangePackets(itemEntityID, itemStack); + } + } + + @MustBeInvokedByOverriders + @Override + protected void addLocationChangePackets(NMSPacketList packetList) { + super.addLocationChangePackets(packetList); + + if (spawnItemEntities) { + packetList.addTeleportPackets(vehicleEntityID, locationX, getItemLocationY(), locationZ); + } + } + + private void addItemSpawnPackets(NMSPacketList packetList) { + packetList.addArmorStandSpawnPackets(vehicleEntityID, locationX, getItemLocationY(), locationZ); + packetList.addItemSpawnPackets(itemEntityID, locationX, getItemLocationY(), locationZ, itemStack); + packetList.addMountPackets(vehicleEntityID, itemEntityID); + } + + private void addItemDestroyPackets(NMSPacketList packetList) { + packetList.addEntityDestroyPackets(itemEntityID, vehicleEntityID); + } + + private double getItemLocationY() { + return locationY; + } + +} diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/LineTracker.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/LineTracker.java new file mode 100644 index 00000000..bb40563c --- /dev/null +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/LineTracker.java @@ -0,0 +1,147 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.plugin.hologram.tracking; + +import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; +import me.filoghost.holographicdisplays.common.nms.NMSManager; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import org.bukkit.Chunk; +import org.bukkit.entity.Player; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +public abstract class LineTracker { + + protected final T line; + private final Set trackedPlayers; + private final NMSManager nmsManager; + + /** + * Flag to indicate that the line has changed in some way and there could be the need to send update packets. + */ + private boolean lineChanged; + + LineTracker(T line, NMSManager nmsManager) { + this.line = line; + this.trackedPlayers = new HashSet<>(); + this.nmsManager = nmsManager; + } + + public final void setLineChanged() { + lineChanged = true; + } + + final void updateAndSendChanges(Collection onlinePlayers) { + boolean sendChangesPackets = false; + + // First, detect the changes if the flag is on and set it off + if (lineChanged) { + lineChanged = false; + detectChanges(); + sendChangesPackets = true; + } + + if (updatePlaceholders()) { + sendChangesPackets = true; + } + + // Then, send the changes (if any) to already tracked players + if (sendChangesPackets) { + if (hasTrackedPlayers()) { + NMSPacketList packetList = nmsManager.createPacketList(); + addChangesPackets(packetList); + broadcastPackets(packetList); + } + clearDetectedChanges(); + } + + // Finally, add/remove tracked players sending them the full spawn/destroy packets + updateTrackedPlayers(onlinePlayers); + } + + protected abstract void detectChanges(); + + protected abstract void clearDetectedChanges(); + + protected abstract boolean updatePlaceholders(); + + private void updateTrackedPlayers(Collection onlinePlayers) { + if (!isActive()) { + clearTrackedPlayers(); + return; + } + + // Lazy initialization + NMSPacketList spawnPacketList = null; + NMSPacketList destroyPacketList = null; + + for (Player player : onlinePlayers) { + if (shouldTrackPlayer(player)) { + if (trackedPlayers.add(player)) { + if (spawnPacketList == null) { + spawnPacketList = nmsManager.createPacketList(); + addSpawnPackets(spawnPacketList); + } + spawnPacketList.sendTo(player); + } + } else { + if (trackedPlayers.remove(player)) { + if (destroyPacketList == null) { + destroyPacketList = nmsManager.createPacketList(); + addDestroyPackets(destroyPacketList); + } + destroyPacketList.sendTo(player); + } + } + } + } + + final boolean isDeleted() { + return line.isDeleted() || line.getHologram().isDeleted(); + } + + protected abstract boolean isActive(); + + protected abstract boolean shouldTrackPlayer(Player player); + + private boolean hasTrackedPlayers() { + return !trackedPlayers.isEmpty(); + } + + protected final void removeTrackedPlayer(Player player) { + trackedPlayers.remove(player); + } + + protected final void clearTrackedPlayers() { + if (!hasTrackedPlayers()) { + return; + } + + NMSPacketList destroyPacketList = nmsManager.createPacketList(); + addDestroyPackets(destroyPacketList); + broadcastPackets(destroyPacketList); + trackedPlayers.clear(); + } + + private void broadcastPackets(NMSPacketList packetList) { + for (Player trackedPlayer : trackedPlayers) { + packetList.sendTo(trackedPlayer); + } + } + + protected abstract void addSpawnPackets(NMSPacketList packetList); + + protected abstract void addDestroyPackets(NMSPacketList packetList); + + protected abstract void addChangesPackets(NMSPacketList packetList); + + protected abstract void onChunkLoad(Chunk chunk); + + protected abstract void onChunkUnload(Chunk chunk); + +} diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/LineTrackerManager.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/LineTrackerManager.java new file mode 100644 index 00000000..87ed61e9 --- /dev/null +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/LineTrackerManager.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.plugin.hologram.tracking; + +import me.filoghost.holographicdisplays.common.hologram.StandardItemLine; +import me.filoghost.holographicdisplays.common.hologram.StandardTextLine; +import me.filoghost.holographicdisplays.common.nms.NMSManager; +import me.filoghost.holographicdisplays.plugin.placeholder.tracking.PlaceholderTracker; +import org.bukkit.Bukkit; +import org.bukkit.Chunk; +import org.bukkit.entity.Player; + +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedList; + +public class LineTrackerManager { + + private final NMSManager nmsManager; + private final PlaceholderTracker placeholderTracker; + private final Collection> lineTrackers; + + public LineTrackerManager(NMSManager nmsManager, PlaceholderTracker placeholderTracker) { + this.nmsManager = nmsManager; + this.placeholderTracker = placeholderTracker; + this.lineTrackers = new LinkedList<>(); + } + + public TextLineTracker startTracking(StandardTextLine line) { + TextLineTracker tracker = new TextLineTracker(line, nmsManager, placeholderTracker); + lineTrackers.add(tracker); + return tracker; + } + + public ItemLineTracker startTracking(StandardItemLine line) { + ItemLineTracker tracker = new ItemLineTracker(line, nmsManager); + lineTrackers.add(tracker); + return tracker; + } + + public void updateTrackersAndSendChanges() { + Collection onlinePlayers = Bukkit.getOnlinePlayers(); + + Iterator> iterator = lineTrackers.iterator(); + while (iterator.hasNext()) { + LineTracker lineTracker = iterator.next(); + + // Remove deleted trackers, sending destroy packets to tracked players + if (lineTracker.isDeleted()) { + lineTracker.clearTrackedPlayers(); + iterator.remove(); + continue; + } + + lineTracker.updateAndSendChanges(onlinePlayers); + } + } + + public void clearTrackedPlayers() { + for (LineTracker tracker : lineTrackers) { + tracker.clearTrackedPlayers(); + } + } + + public void onPlayerQuit(Player player) { + for (LineTracker tracker : lineTrackers) { + tracker.removeTrackedPlayer(player); + } + } + + public void onChunkLoad(Chunk chunk) { + for (LineTracker tracker : lineTrackers) { + tracker.onChunkLoad(chunk); + } + } + + public void onChunkUnload(Chunk chunk) { + for (LineTracker tracker : lineTrackers) { + tracker.onChunkUnload(chunk); + } + } + +} diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/LocationBasedLineTracker.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/LocationBasedLineTracker.java new file mode 100644 index 00000000..1bc9f2be --- /dev/null +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/LocationBasedLineTracker.java @@ -0,0 +1,103 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.plugin.hologram.tracking; + +import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; +import me.filoghost.holographicdisplays.common.nms.NMSManager; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import org.bukkit.Chunk; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.MustBeInvokedByOverriders; + +abstract class LocationBasedLineTracker extends LineTracker { + + private static final int ENTITY_VIEW_RANGE = 64; + + private World world; + protected double locationX; + protected double locationY; + protected double locationZ; + private int chunkX; + private int chunkZ; + private boolean chunkLoaded; + private boolean locationChanged; + + LocationBasedLineTracker(T line, NMSManager nmsManager) { + super(line, nmsManager); + } + + @Override + protected final boolean isActive() { + return chunkLoaded; + } + + @MustBeInvokedByOverriders + @Override + protected void detectChanges() { + World world = line.getWorld(); + int chunkX = line.getChunkX(); + int chunkZ = line.getChunkZ(); + if (this.world != world || this.chunkX != chunkX || this.chunkZ != chunkZ) { + this.world = world; + this.chunkX = chunkX; + this.chunkZ = chunkZ; + this.chunkLoaded = world != null && world.isChunkLoaded(chunkX, chunkZ); + this.locationChanged = true; + } + + double locationX = line.getX(); + double locationY = line.getY(); + double locationZ = line.getZ(); + if (this.locationX != locationX || this.locationY != locationY || this.locationZ != locationZ) { + this.locationX = locationX; + this.locationY = locationY; + this.locationZ = locationZ; + this.locationChanged = true; + } + } + + @MustBeInvokedByOverriders + @Override + protected void clearDetectedChanges() { + this.locationChanged = false; + } + + @Override + protected final boolean shouldTrackPlayer(Player player) { + Location playerLocation = player.getLocation(); + double diffX = Math.abs(playerLocation.getX() - locationX); + double diffZ = Math.abs(playerLocation.getZ() - locationZ); + + return playerLocation.getWorld() == world && diffX <= (double) ENTITY_VIEW_RANGE && diffZ <= (double) ENTITY_VIEW_RANGE; + } + + @MustBeInvokedByOverriders + @Override + protected void addChangesPackets(NMSPacketList packetList) { + if (locationChanged) { + addLocationChangePackets(packetList); + } + } + + protected abstract void addLocationChangePackets(NMSPacketList packetList); + + @Override + protected final void onChunkLoad(Chunk chunk) { + if (this.chunkX == chunk.getX() && this.chunkZ == chunk.getZ()) { + this.chunkLoaded = true; + } + } + + @Override + protected final void onChunkUnload(Chunk chunk) { + if (this.chunkX == chunk.getX() && this.chunkZ == chunk.getZ()) { + this.chunkLoaded = false; + } + } + +} diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/TextLineTracker.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/TextLineTracker.java new file mode 100644 index 00000000..48665f0a --- /dev/null +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/TextLineTracker.java @@ -0,0 +1,101 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.plugin.hologram.tracking; + +import me.filoghost.holographicdisplays.common.hologram.StandardTextLine; +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.NMSManager; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.plugin.placeholder.tracking.PlaceholderTracker; +import org.jetbrains.annotations.MustBeInvokedByOverriders; + +import java.util.Objects; + +public class TextLineTracker extends TouchableLineTracker { + + private final EntityID armorStandEntityID; + + private final DisplayText displayText; + private boolean displayTextChanged; + + public TextLineTracker(StandardTextLine line, NMSManager nmsManager, PlaceholderTracker placeholderTracker) { + super(line, nmsManager); + this.armorStandEntityID = nmsManager.newEntityID(); + this.displayText = new DisplayText(placeholderTracker); + } + + @Override + protected boolean updatePlaceholders() { + boolean placeholdersChanged = displayText.updateGlobalReplacements(); + if (placeholdersChanged) { + displayTextChanged = true; // Mark as changed to trigger a packet send with updated placeholders + } + return placeholdersChanged; + } + + @MustBeInvokedByOverriders + @Override + protected void detectChanges() { + super.detectChanges(); + + String displayText = line.getText(); + if (!Objects.equals(this.displayText.get(), displayText)) { + this.displayText.set(displayText); + this.displayTextChanged = true; + } + } + + @MustBeInvokedByOverriders + @Override + protected void clearDetectedChanges() { + super.clearDetectedChanges(); + this.displayTextChanged = false; + } + + @MustBeInvokedByOverriders + @Override + protected void addSpawnPackets(NMSPacketList packetList) { + super.addSpawnPackets(packetList); + + if (displayText.containsIndividualPlaceholders()) { + packetList.addArmorStandSpawnPackets(armorStandEntityID, locationX, getArmorStandLocationY(), locationZ, displayText::getWithIndividualReplacements); + } else { + packetList.addArmorStandSpawnPackets(armorStandEntityID, locationX, getArmorStandLocationY(), locationZ, displayText.getWithGlobalReplacements()); + } + } + + @MustBeInvokedByOverriders + @Override + protected void addDestroyPackets(NMSPacketList packetList) { + super.addDestroyPackets(packetList); + packetList.addEntityDestroyPackets(armorStandEntityID); + } + + @Override + protected void addChangesPackets(NMSPacketList packetList) { + super.addChangesPackets(packetList); + + if (displayTextChanged) { + if (displayText.containsIndividualPlaceholders()) { + packetList.addArmorStandNameChangePackets(armorStandEntityID, displayText::getWithIndividualReplacements); + } else { + packetList.addArmorStandNameChangePackets(armorStandEntityID, displayText.getWithGlobalReplacements()); + } + } + } + + @MustBeInvokedByOverriders + @Override + protected void addLocationChangePackets(NMSPacketList packetList) { + super.addLocationChangePackets(packetList); + packetList.addTeleportPackets(armorStandEntityID, locationX, getArmorStandLocationY(), locationZ); + } + + private double getArmorStandLocationY() { + return locationY - 0.29; + } + +} diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/TouchableLineTracker.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/TouchableLineTracker.java new file mode 100644 index 00000000..c0457dba --- /dev/null +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/TouchableLineTracker.java @@ -0,0 +1,101 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.plugin.hologram.tracking; + +import me.filoghost.holographicdisplays.common.hologram.StandardTouchableLine; +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.NMSManager; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import org.jetbrains.annotations.MustBeInvokedByOverriders; + +public abstract class TouchableLineTracker extends LocationBasedLineTracker { + + private static final double SLIME_HEIGHT = 0.5; + + private final EntityID vehicleEntityID; + private final EntityID slimeEntityID; + + private boolean spawnSlimeEntities; + private boolean spawnSlimeEntitiesChanged; + + public TouchableLineTracker(T line, NMSManager nmsManager) { + super(line, nmsManager); + this.vehicleEntityID = nmsManager.newEntityID(); + this.slimeEntityID = nmsManager.newEntityID(); + } + + @MustBeInvokedByOverriders + @Override + protected void detectChanges() { + super.detectChanges(); + + boolean spawnSlimeEntities = line.hasTouchHandler(); + if (this.spawnSlimeEntities != spawnSlimeEntities) { + this.spawnSlimeEntities = spawnSlimeEntities; + this.spawnSlimeEntitiesChanged = true; + } + } + + @MustBeInvokedByOverriders + @Override + protected void clearDetectedChanges() { + super.clearDetectedChanges(); + this.spawnSlimeEntitiesChanged = false; + } + + @MustBeInvokedByOverriders + @Override + protected void addSpawnPackets(NMSPacketList packetList) { + if (spawnSlimeEntities) { + addSlimeSpawnPackets(packetList); + } + } + + @MustBeInvokedByOverriders + @Override + protected void addDestroyPackets(NMSPacketList packetList) { + if (spawnSlimeEntities) { + addSlimeDestroyPackets(packetList); + } + } + + @MustBeInvokedByOverriders + @Override + protected void addChangesPackets(NMSPacketList packetList) { + super.addChangesPackets(packetList); + + if (spawnSlimeEntitiesChanged) { + if (spawnSlimeEntities) { + addSlimeSpawnPackets(packetList); + } else { + addSlimeDestroyPackets(packetList); + } + } + } + + @MustBeInvokedByOverriders + @Override + protected void addLocationChangePackets(NMSPacketList packetList) { + if (spawnSlimeEntities) { + packetList.addTeleportPackets(vehicleEntityID, locationX, getSlimeLocationY(), locationZ); + } + } + + private void addSlimeSpawnPackets(NMSPacketList packetList) { + packetList.addArmorStandSpawnPackets(vehicleEntityID, locationX, getSlimeLocationY(), locationZ); + packetList.addSlimeSpawnPackets(slimeEntityID, locationX, getSlimeLocationY(), locationZ); + packetList.addMountPackets(vehicleEntityID, slimeEntityID); + } + + private void addSlimeDestroyPackets(NMSPacketList packetList) { + packetList.addEntityDestroyPackets(slimeEntityID, vehicleEntityID); + } + + private double getSlimeLocationY() { + return locationY + ((line.getHeight() - SLIME_HEIGHT) / 2); + } + +} diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/lib/packetwrapper/AbstractPacket.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/lib/packetwrapper/AbstractPacket.java deleted file mode 100644 index 9425e9b8..00000000 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/lib/packetwrapper/AbstractPacket.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * PacketWrapper - Contains wrappers for each packet in Minecraft. - * Copyright (C) 2012 Kristian S. Stangeland - * - * This program is free software; you can redistribute it and/or modify it under the terms of the - * GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program; - * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - * 02111-1307 USA - */ -package me.filoghost.holographicdisplays.plugin.lib.packetwrapper; - -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.ProtocolLibrary; -import com.comphenix.protocol.events.PacketContainer; -import com.google.common.base.Objects; -import org.bukkit.entity.Player; - -import java.lang.reflect.InvocationTargetException; - -public abstract class AbstractPacket { - - // The packet we will be modifying - protected PacketContainer handle; - - /** - * Constructs a new strongly typed wrapper for the given packet. - */ - protected AbstractPacket(PacketContainer handle, PacketType type) { - // Make sure we're given a valid packet - if (handle == null) { - throw new IllegalArgumentException("Packet handle cannot be NULL."); - } - if (!Objects.equal(handle.getType(), type)) { - throw new IllegalArgumentException(handle.getHandle() + " is not a packet of type " + type); - } - - this.handle = handle; - } - - /** - * Retrieve a handle to the raw packet data. - */ - public PacketContainer getHandle() { - return handle; - } - - /** - * Send the current packet to the given receiver. - * - * @throws RuntimeException If the packet cannot be sent. - */ - public void sendPacket(Player receiver) { - try { - ProtocolLibrary.getProtocolManager().sendServerPacket(receiver, getHandle()); - } catch (InvocationTargetException e) { - throw new RuntimeException("Cannot send packet.", e); - } - } - - /** - * Simulate receiving the current packet from the given sender. - * - * @throws RuntimeException If the packet cannot be received. - */ - public void receivePacket(Player sender) { - try { - ProtocolLibrary.getProtocolManager().recieveClientPacket(sender, getHandle()); - } catch (Exception e) { - throw new RuntimeException("Cannot receive packet.", e); - } - } - -} diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/lib/packetwrapper/WrapperPlayServerAttachEntity.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/lib/packetwrapper/WrapperPlayServerAttachEntity.java deleted file mode 100644 index d4a58aec..00000000 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/lib/packetwrapper/WrapperPlayServerAttachEntity.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * PacketWrapper - Contains wrappers for each packet in Minecraft. - * Copyright (C) 2012 Kristian S. Stangeland - * - * This program is free software; you can redistribute it and/or modify it under the terms of the - * GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program; - * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - * 02111-1307 USA - */ -package me.filoghost.holographicdisplays.plugin.lib.packetwrapper; - -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.events.PacketContainer; -import com.comphenix.protocol.events.PacketEvent; -import org.bukkit.World; -import org.bukkit.entity.Entity; - -public class WrapperPlayServerAttachEntity extends AbstractPacket { - - public static final PacketType TYPE = PacketType.Play.Server.ATTACH_ENTITY; - - public WrapperPlayServerAttachEntity() { - super(new PacketContainer(TYPE), TYPE); - handle.getModifier().writeDefaults(); - } - - public WrapperPlayServerAttachEntity(PacketContainer packet) { - super(packet, TYPE); - } - - /** - * Retrieve whether or not the entity is leached onto the vehicle. - * - * @return TRUE if it is, FALSE otherwise. - */ - public boolean getLeached() { - return handle.getIntegers().read(0) != 0; - } - - /** - * Set whether or not the entity is leached onto the vehicle. - * - * @param value - TRUE if it is leached, FALSE otherwise. - */ - public void setLeached(boolean value) { - handle.getIntegers().write(0, value ? 1 : 0); - } - - /** - * Retrieve the player entity ID being attached. - * - * @return The current Entity ID - */ - public int getEntityId() { - return handle.getIntegers().read(1); - } - - /** - * Set the player entity ID being attached. - * - * @param value - new value. - */ - public void setEntityId(int value) { - handle.getIntegers().write(1, value); - } - - /** - * Retrieve the entity being attached. - * - * @param world - the current world of the entity. - * @return The entity. - */ - public Entity getEntity(World world) { - return handle.getEntityModifier(world).read(1); - } - - /** - * Retrieve the entity being attached. - * - * @param event - the packet event. - * @return The entity. - */ - public Entity getEntity(PacketEvent event) { - return getEntity(event.getPlayer().getWorld()); - } - - /** - * Retrieve the vehicle entity ID attached to (-1 for unattaching). - * - * @return The current Vehicle ID - */ - public int getVehicleId() { - return handle.getIntegers().read(2); - } - - /** - * Set the vehicle entity ID attached to (-1 for unattaching). - * - * @param value - new value. - */ - public void setVehicleId(int value) { - handle.getIntegers().write(2, value); - } - - /** - * Retrieve the vehicle entity attached to (NULL for unattaching). - * - * @param world - the current world of the entity. - * @return The vehicle. - */ - public Entity getVehicle(World world) { - return handle.getEntityModifier(world).read(2); - } - - /** - * Retrieve the vehicle entity attached to (NULL for unattaching). - * - * @param event - the packet event. - * @return The vehicle. - */ - public Entity getVehicle(PacketEvent event) { - return getVehicle(event.getPlayer().getWorld()); - } - -} diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/lib/packetwrapper/WrapperPlayServerEntityDestroy.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/lib/packetwrapper/WrapperPlayServerEntityDestroy.java deleted file mode 100644 index 68d6d17b..00000000 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/lib/packetwrapper/WrapperPlayServerEntityDestroy.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * PacketWrapper - Contains wrappers for each packet in Minecraft. - * Copyright (C) 2012 Kristian S. Stangeland - * - * This program is free software; you can redistribute it and/or modify it under the terms of the - * GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program; - * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - * 02111-1307 USA - */ -package me.filoghost.holographicdisplays.plugin.lib.packetwrapper; - -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.events.PacketContainer; -import com.google.common.primitives.Ints; - -import java.util.List; - -public class WrapperPlayServerEntityDestroy extends AbstractPacket { - - public static final PacketType TYPE = PacketType.Play.Server.ENTITY_DESTROY; - - public WrapperPlayServerEntityDestroy() { - super(new PacketContainer(TYPE), TYPE); - handle.getModifier().writeDefaults(); - } - - public WrapperPlayServerEntityDestroy(PacketContainer packet) { - super(packet, TYPE); - } - - /** - * Retrieve the IDs of the entities that will be destroyed. - */ - public List getEntities() { - return Ints.asList(handle.getIntegerArrays().read(0)); - } - - /** - * Set the entities that will be destroyed. - */ - public void setEntities(int[] entities) { - handle.getIntegerArrays().write(0, entities); - } - - /** - * Set the entities that will be destroyed. - */ - public void setEntities(List entities) { - setEntities(Ints.toArray(entities)); - } - - /** - * Set the entity that will be destroyed. To be used from Minecraft 1.17 and higher. - */ - public void setEntity(Integer entity) { - handle.getIntegers().write(0, entity); - } - -} diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/lib/packetwrapper/WrapperPlayServerEntityMetadata.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/lib/packetwrapper/WrapperPlayServerEntityMetadata.java deleted file mode 100644 index 52c03d8c..00000000 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/lib/packetwrapper/WrapperPlayServerEntityMetadata.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * PacketWrapper - Contains wrappers for each packet in Minecraft. - * Copyright (C) 2012 Kristian S. Stangeland - * - * This program is free software; you can redistribute it and/or modify it under the terms of the - * GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program; - * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - * 02111-1307 USA - */ -package me.filoghost.holographicdisplays.plugin.lib.packetwrapper; - -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.events.PacketContainer; -import com.comphenix.protocol.events.PacketEvent; -import com.comphenix.protocol.wrappers.WrappedDataWatcher; -import com.comphenix.protocol.wrappers.WrappedWatchableObject; -import org.bukkit.World; -import org.bukkit.entity.Entity; - -import java.util.List; - -public class WrapperPlayServerEntityMetadata extends AbstractPacket { - - public static final PacketType TYPE = PacketType.Play.Server.ENTITY_METADATA; - - public WrapperPlayServerEntityMetadata() { - super(new PacketContainer(TYPE), TYPE); - handle.getModifier().writeDefaults(); - } - - public WrapperPlayServerEntityMetadata(PacketContainer packet) { - super(packet, TYPE); - } - - /** - * Retrieve unique entity ID to update. - */ - public int getEntityID() { - return handle.getIntegers().read(0); - } - - /** - * Set unique entity ID to update. - */ - public void setEntityID(int value) { - handle.getIntegers().write(0, value); - } - - /** - * Retrieve the entity. - */ - public Entity getEntity(World world) { - return handle.getEntityModifier(world).read(0); - } - - /** - * Retrieve the entity. - */ - public Entity getEntity(PacketEvent event) { - return getEntity(event.getPlayer().getWorld()); - } - - /** - * Retrieve a list of all the watchable objects. - *

- * This can be converted to a data watcher using {@link WrappedDataWatcher#WrappedDataWatcher(List) - * WrappedDataWatcher(List)} - */ - public List getEntityMetadata() { - return handle.getWatchableCollectionModifier().read(0); - } - - /** - * Set the list of the watchable objects (meta data). - */ - public void setEntityMetadata(List value) { - handle.getWatchableCollectionModifier().write(0, value); - } - -} diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/lib/packetwrapper/WrapperPlayServerMount.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/lib/packetwrapper/WrapperPlayServerMount.java deleted file mode 100644 index 5c0aa3b3..00000000 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/lib/packetwrapper/WrapperPlayServerMount.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * PacketWrapper - Contains wrappers for each packet in Minecraft. - * Copyright (C) 2012 Kristian S. Stangeland - * - * This program is free software; you can redistribute it and/or modify it under the terms of the - * GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program; - * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - * 02111-1307 USA - */ -package me.filoghost.holographicdisplays.plugin.lib.packetwrapper; - -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.events.PacketContainer; -import com.google.common.primitives.Ints; - -import java.util.List; - -public class WrapperPlayServerMount extends AbstractPacket { - - public static final PacketType TYPE = PacketType.Play.Server.MOUNT; - - public WrapperPlayServerMount() { - super(new PacketContainer(TYPE), TYPE); - handle.getModifier().writeDefaults(); - } - - public WrapperPlayServerMount(PacketContainer packet) { - super(packet, TYPE); - } - - /** - * Retrieve the entity ID being attached. - */ - public int getVehicleId() { - return handle.getIntegers().read(0); - } - - /** - * Set the entity ID being attached. - */ - public void setVehicleId(int value) { - handle.getIntegers().write(0, value); - } - - /** - * Retrieve the IDs of the passenger entities. - */ - public List getPassengers() { - return Ints.asList(handle.getIntegerArrays().read(0)); - } - - /** - * Set the passenger entities. - */ - public void setPassengers(int[] entities) { - handle.getIntegerArrays().write(0, entities); - } - - /** - * Set the passenger entities. - */ - public void setPassengers(List entities) { - setPassengers(Ints.toArray(entities)); - } - -} diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/lib/packetwrapper/WrapperPlayServerSpawnEntity.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/lib/packetwrapper/WrapperPlayServerSpawnEntity.java deleted file mode 100644 index fa6965a4..00000000 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/lib/packetwrapper/WrapperPlayServerSpawnEntity.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * PacketWrapper - Contains wrappers for each packet in Minecraft. - * Copyright (C) 2012 Kristian S. Stangeland - * - * This program is free software; you can redistribute it and/or modify it under the terms of the - * GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program; - * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - * 02111-1307 USA - */ -package me.filoghost.holographicdisplays.plugin.lib.packetwrapper; - -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.ProtocolLibrary; -import com.comphenix.protocol.events.PacketContainer; -import com.comphenix.protocol.events.PacketEvent; -import com.comphenix.protocol.injector.PacketConstructor; -import com.comphenix.protocol.reflect.IntEnum; -import me.filoghost.holographicdisplays.plugin.util.NMSVersion; -import org.bukkit.World; -import org.bukkit.entity.Entity; - -public class WrapperPlayServerSpawnEntity extends AbstractPacket { - - public static final PacketType TYPE = PacketType.Play.Server.SPAWN_ENTITY; - - private static PacketConstructor entityConstructor; - - /** - * Represents the different object types. - * - * @author Kristian - */ - public static class ObjectTypes extends IntEnum { - - public static final int BOAT = 1; - public static final int ITEM_STACK = 2; - public static final int MINECART = 10; - public static final int MINECART_STORAGE = 11; - public static final int MINECART_POWERED = 12; - public static final int ACTIVATED_TNT = 50; - public static final int ENDER_CRYSTAL = 51; - public static final int ARROW_PROJECTILE = 60; - public static final int SNOWBALL_PROJECTILE = 61; - public static final int EGG_PROJECTILE = 62; - public static final int FIRE_BALL_GHAST = 63; - public static final int FIRE_BALL_BLAZE = 64; - public static final int THROWN_ENDERPEARL = 65; - public static final int WITHER_SKULL = 66; - public static final int FALLING_BLOCK = 70; - public static final int ITEM_FRAME = 71; - public static final int EYE_OF_ENDER = 72; - public static final int THROWN_POTION = 73; - public static final int FALLING_DRAGON_EGG = 74; - public static final int THROWN_EXP_BOTTLE = 75; - public static final int FIREWORK = 76; - public static final int ARMOR_STAND = 78; - public static final int FISHING_FLOAT = 90; - - /** - * The singleton instance. Can also be retrieved from the parent class. - */ - private static final ObjectTypes INSTANCE = new ObjectTypes(); - - /** - * Retrieve an instance of the object types enum. - */ - public static ObjectTypes getInstance() { - return INSTANCE; - } - - } - - public WrapperPlayServerSpawnEntity() { - super(new PacketContainer(TYPE), TYPE); - handle.getModifier().writeDefaults(); - } - - public WrapperPlayServerSpawnEntity(PacketContainer packet) { - super(packet, TYPE); - } - - public WrapperPlayServerSpawnEntity(Entity entity, int type, int objectData) { - super(fromEntity(entity, type, objectData), TYPE); - } - - // Useful constructor - private static PacketContainer fromEntity(Entity entity, int type, int objectData) { - if (entityConstructor == null) { - if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_14_R1)) { - entityConstructor = ProtocolLibrary.getProtocolManager().createPacketConstructor(TYPE, entity, objectData); - } else { - entityConstructor = ProtocolLibrary.getProtocolManager().createPacketConstructor(TYPE, entity, type, objectData); - } - } - - if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_14_R1)) { - return entityConstructor.createPacket(entity, objectData); - } else { - return entityConstructor.createPacket(entity, type, objectData); - } - } - - /** - * Retrieve entity ID of the Object. - */ - public int getEntityID() { - return handle.getIntegers().read(0); - } - - /** - * Retrieve the entity that will be spawned. - */ - public Entity getEntity(World world) { - return handle.getEntityModifier(world).read(0); - } - - /** - * Retrieve the entity that will be spawned. - */ - public Entity getEntity(PacketEvent event) { - return getEntity(event.getPlayer().getWorld()); - } - - /** - * Set entity ID of the Object. - */ - public void setEntityID(int value) { - handle.getIntegers().write(0, value); - } - - /** - * Retrieve the type of object. See {@link ObjectTypes} - */ - public int getType() { - return handle.getIntegers().read(6); - } - - /** - * Set the type of object. See {@link ObjectTypes}. - */ - public void setType(int value) { - handle.getIntegers().write(6, value); - } - -} diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/lib/packetwrapper/WrapperPlayServerSpawnEntityLiving.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/lib/packetwrapper/WrapperPlayServerSpawnEntityLiving.java deleted file mode 100644 index 7d4cd4ba..00000000 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/lib/packetwrapper/WrapperPlayServerSpawnEntityLiving.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * PacketWrapper - Contains wrappers for each packet in Minecraft. - * Copyright (C) 2012 Kristian S. Stangeland - * - * This program is free software; you can redistribute it and/or modify it under the terms of the - * GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program; - * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - * 02111-1307 USA - */ -package me.filoghost.holographicdisplays.plugin.lib.packetwrapper; - -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.ProtocolLibrary; -import com.comphenix.protocol.events.PacketContainer; -import com.comphenix.protocol.events.PacketEvent; -import com.comphenix.protocol.injector.PacketConstructor; -import com.comphenix.protocol.wrappers.WrappedDataWatcher; -import org.bukkit.World; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; - -public class WrapperPlayServerSpawnEntityLiving extends AbstractPacket { - - public static final PacketType TYPE = PacketType.Play.Server.SPAWN_ENTITY_LIVING; - - private static PacketConstructor entityConstructor; - - public WrapperPlayServerSpawnEntityLiving() { - super(new PacketContainer(TYPE), TYPE); - handle.getModifier().writeDefaults(); - } - - public WrapperPlayServerSpawnEntityLiving(PacketContainer packet) { - super(packet, TYPE); - } - - public WrapperPlayServerSpawnEntityLiving(Entity entity) { - super(fromEntity(entity), TYPE); - } - - // Useful constructor - private static PacketContainer fromEntity(Entity entity) { - if (entityConstructor == null) { - entityConstructor = ProtocolLibrary.getProtocolManager().createPacketConstructor(TYPE, entity); - } - return entityConstructor.createPacket(entity); - } - - /** - * Retrieve entity ID. - */ - public int getEntityID() { - return handle.getIntegers().read(0); - } - - /** - * Retrieve the entity that will be spawned. - */ - public Entity getEntity(World world) { - return handle.getEntityModifier(world).read(0); - } - - /** - * Retrieve the entity that will be spawned. - */ - public Entity getEntity(PacketEvent event) { - return getEntity(event.getPlayer().getWorld()); - } - - /** - * Set entity ID. - */ - public void setEntityID(int value) { - handle.getIntegers().write(0, value); - } - - /** - * Retrieve the type of mob. - */ - @SuppressWarnings("deprecation") - public EntityType getType() { - return EntityType.fromId(handle.getIntegers().read(1)); - } - - /** - * Set the type of mob. - */ - @SuppressWarnings("deprecation") - public void setType(EntityType value) { - handle.getIntegers().write(1, (int) value.getTypeId()); - } - - /** - * Retrieve the data watcher. - *

- * Content varies by mob, see Entities. - */ - public WrappedDataWatcher getMetadata() { - return handle.getDataWatcherModifier().read(0); - } - - /** - * Set the data watcher. - */ - public void setMetadata(WrappedDataWatcher value) { - handle.getDataWatcherModifier().write(0, value); - } - -} diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/listener/ChunkListener.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/listener/ChunkListener.java index e88d19c0..2e377379 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/listener/ChunkListener.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/listener/ChunkListener.java @@ -5,13 +5,9 @@ */ package me.filoghost.holographicdisplays.plugin.listener; -import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntity; -import me.filoghost.holographicdisplays.plugin.hologram.api.APIHologramManager; -import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologramManager; +import me.filoghost.holographicdisplays.plugin.hologram.tracking.LineTrackerManager; import org.bukkit.Bukkit; import org.bukkit.Chunk; -import org.bukkit.entity.Entity; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -22,32 +18,16 @@ import org.bukkit.plugin.Plugin; public class ChunkListener implements Listener { private final Plugin plugin; - private final NMSManager nmsManager; - private final InternalHologramManager internalHologramManager; - private final APIHologramManager apiHologramManager; + private final LineTrackerManager lineTrackerManager; - public ChunkListener( - Plugin plugin, - NMSManager nmsManager, - InternalHologramManager internalHologramManager, - APIHologramManager apiHologramManager) { + public ChunkListener(Plugin plugin, LineTrackerManager lineTrackerManager) { this.plugin = plugin; - this.nmsManager = nmsManager; - this.internalHologramManager = internalHologramManager; - this.apiHologramManager = apiHologramManager; + this.lineTrackerManager = lineTrackerManager; } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onChunkUnload(ChunkUnloadEvent event) { - for (Entity entity : event.getChunk().getEntities()) { - if (!entity.isDead()) { - NMSEntity entityBase = nmsManager.getNMSEntityBase(entity); - - if (entityBase != null) { - entityBase.getHologramLine().getHologram().despawnEntities(); - } - } - } + lineTrackerManager.onChunkUnload(event.getChunk()); } @EventHandler(priority = EventPriority.MONITOR) @@ -68,8 +48,7 @@ public class ChunkListener implements Listener { } private void onChunkLoad(Chunk chunk) { - internalHologramManager.onChunkLoad(chunk); - apiHologramManager.onChunkLoad(chunk); + lineTrackerManager.onChunkLoad(chunk); } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/listener/InteractListener.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/listener/InteractListener.java deleted file mode 100644 index 26dbb4d0..00000000 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/listener/InteractListener.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.plugin.listener; - -import me.filoghost.holographicdisplays.common.hologram.StandardHologramLine; -import me.filoghost.holographicdisplays.common.hologram.StandardTouchableLine; -import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.entity.NMSEntity; -import org.bukkit.GameMode; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerInteractEntityEvent; - -public class InteractListener implements Listener { - - private final NMSManager nmsManager; - - public InteractListener(NMSManager nmsManager) { - this.nmsManager = nmsManager; - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onSlimeInteract(PlayerInteractEntityEvent event) { - if (event.getRightClicked().getType() != EntityType.SLIME) { - return; - } - - Player clicker = event.getPlayer(); - if (clicker.getGameMode() == GameMode.SPECTATOR) { - return; - } - - NMSEntity entityBase = nmsManager.getNMSEntityBase(event.getRightClicked()); - if (entityBase == null) { - return; - } - - StandardHologramLine line = entityBase.getHologramLine(); - if (!(line instanceof StandardTouchableLine)) { - return; - } - - ((StandardTouchableLine) line).onTouch(clicker); - } - -} diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/listener/PlayerQuitListener.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/listener/PlayerQuitListener.java new file mode 100644 index 00000000..ff79516e --- /dev/null +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/listener/PlayerQuitListener.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.plugin.listener; + +import me.filoghost.holographicdisplays.plugin.hologram.tracking.LineTrackerManager; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerQuitEvent; + +public class PlayerQuitListener implements Listener { + + private final LineTrackerManager lineTrackerManager; + + public PlayerQuitListener(LineTrackerManager lineTrackerManager) { + this.lineTrackerManager = lineTrackerManager; + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + lineTrackerManager.onPlayerQuit(event.getPlayer()); + } + +} diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/listener/SpawnListener.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/listener/SpawnListener.java deleted file mode 100644 index c066452a..00000000 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/listener/SpawnListener.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.plugin.listener; - -import me.filoghost.holographicdisplays.common.nms.NMSManager; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.CreatureSpawnEvent; -import org.bukkit.event.entity.ItemSpawnEvent; -import org.bukkit.event.entity.ProjectileLaunchEvent; - -public class SpawnListener implements Listener { - - private final NMSManager nmsManager; - - public SpawnListener(NMSManager nmsManager) { - this.nmsManager = nmsManager; - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false) - public void onCreatureSpawn(CreatureSpawnEvent event) { - if (nmsManager.isNMSEntityBase(event.getEntity())) { - event.setCancelled(false); - } - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false) - public void onProjectileLaunch(ProjectileLaunchEvent event) { - if (nmsManager.isNMSEntityBase(event.getEntity())) { - event.setCancelled(false); - } - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false) - public void onItemSpawn(ItemSpawnEvent event) { - if (nmsManager.isNMSEntityBase(event.getEntity())) { - event.setCancelled(false); - } - } - -} diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/TickingTask.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/TickingTask.java index 176a64e2..5379d961 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/TickingTask.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/TickingTask.java @@ -5,22 +5,34 @@ */ package me.filoghost.holographicdisplays.plugin.placeholder; -import me.filoghost.holographicdisplays.plugin.placeholder.tracking.PlaceholderLineTracker; +import me.filoghost.fcommons.logging.Log; +import me.filoghost.holographicdisplays.plugin.hologram.tracking.LineTrackerManager; public class TickingTask implements Runnable { private final TickClock tickClock; - private final PlaceholderLineTracker placeholderLineTracker; + private final LineTrackerManager lineTrackerManager; - public TickingTask(TickClock tickClock, PlaceholderLineTracker placeholderLineTracker) { + private long lastErrorLogTick; + + public TickingTask(TickClock tickClock, LineTrackerManager lineTrackerManager) { this.tickClock = tickClock; - this.placeholderLineTracker = placeholderLineTracker; + this.lineTrackerManager = lineTrackerManager; } @Override public void run() { tickClock.incrementTick(); - placeholderLineTracker.updateEntitiesWithGlobalPlaceholders(); + + try { + lineTrackerManager.updateTrackersAndSendChanges(); + } catch (Throwable t) { + // Avoid spamming the console, log the error at most once every 20 ticks + if (tickClock.getCurrentTick() - lastErrorLogTick >= 20) { + lastErrorLogTick = tickClock.getCurrentTick(); + Log.severe("Error while ticking holograms", t); + } + } } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/parsing/StringWithPlaceholders.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/parsing/StringWithPlaceholders.java index 07613492..c64bdc76 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/parsing/StringWithPlaceholders.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/parsing/StringWithPlaceholders.java @@ -5,32 +5,38 @@ */ package me.filoghost.holographicdisplays.plugin.placeholder.parsing; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; import java.util.function.Predicate; -public class StringWithPlaceholders { +public final class StringWithPlaceholders { private static final char PLACEHOLDER_END_CHAR = '}'; private static final char PLACEHOLDER_START_CHAR = '{'; - private final String string; + private final @NotNull String string; private final List stringParts; - public StringWithPlaceholders(String string) { + @Contract("null -> null; !null -> !null") + public static StringWithPlaceholders of(@Nullable String string) { + return string != null ? new StringWithPlaceholders(string) : null; + } + + public StringWithPlaceholders(@NotNull String string) { this.string = string; this.stringParts = splitToParts(string); } - private StringWithPlaceholders(String string, List stringParts) { + private StringWithPlaceholders(@NotNull String string, @Nullable List stringParts) { this.string = string; this.stringParts = stringParts; } - @Override - public String toString() { + public String getUnreplacedString() { return string; } @@ -166,6 +172,24 @@ public class StringWithPlaceholders { return stringParts; } + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + + StringWithPlaceholders other = (StringWithPlaceholders) obj; + return this.string.equals(other.string); + } + + @Override + public int hashCode() { + return string.hashCode(); + } + private interface StringPart { diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/tracking/PlaceholderLineTracker.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/tracking/PlaceholderLineTracker.java deleted file mode 100644 index a6b572ae..00000000 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/tracking/PlaceholderLineTracker.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.plugin.placeholder.tracking; - -import me.filoghost.holographicdisplays.common.hologram.StandardTextLine; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.plugin.placeholder.parsing.StringWithPlaceholders; -import org.jetbrains.annotations.Nullable; - -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.Map; - -public class PlaceholderLineTracker { - - private final PlaceholderTracker replacementTracker; - private final Map trackedLines; - - public PlaceholderLineTracker(PlaceholderTracker replacementTracker) { - this.replacementTracker = replacementTracker; - this.trackedLines = new LinkedHashMap<>(); - } - - public void updateEntitiesWithGlobalPlaceholders() { - Iterator iterator = trackedLines.values().iterator(); - while (iterator.hasNext()) { - TrackedLine trackedLine = iterator.next(); - - if (trackedLine.shouldBeUntracked()) { - iterator.remove(); - continue; - } - - trackedLine.updateEntityWithGlobalPlaceholders(); - } - } - - public void onTextLineChange(StandardTextLine line) { - TrackedLine trackedLine = createTrackedLineIfNeeded(line); - - if (trackedLine != null) { - trackedLines.put(line, trackedLine); - trackedLine.updateEntityWithGlobalPlaceholders(); // Update placeholders instantly to avoid flashing the non-replaced text - } else { - TrackedLine untrackedLine = trackedLines.remove(line); - if (untrackedLine != null) { - untrackedLine.restoreOriginalName(); - } - } - } - - private @Nullable TrackedLine createTrackedLineIfNeeded(StandardTextLine textLine) { - if (!textLine.isAllowPlaceholders()) { - return null; - } - - String text = textLine.getText(); - if (text == null || text.isEmpty()) { - return null; - } - - NMSArmorStand entity = textLine.getNMSArmorStand(); - if (entity == null) { - return null; - } - - StringWithPlaceholders textWithPlaceholders = new StringWithPlaceholders(text); - if (!textWithPlaceholders.containsPlaceholders()) { - return null; - } - - return new TrackedLine(replacementTracker, textLine, entity, textWithPlaceholders); - } - - public TrackedLine getTrackedLine(StandardTextLine line) { - return trackedLines.get(line); - } - -} diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/tracking/TrackedLine.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/tracking/TrackedLine.java deleted file mode 100644 index 3b85de26..00000000 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/tracking/TrackedLine.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.plugin.placeholder.tracking; - -import me.filoghost.holographicdisplays.common.hologram.StandardTextLine; -import me.filoghost.holographicdisplays.common.nms.entity.NMSArmorStand; -import me.filoghost.holographicdisplays.plugin.placeholder.parsing.PlaceholderReplaceFunction; -import me.filoghost.holographicdisplays.plugin.placeholder.parsing.StringWithPlaceholders; -import org.bukkit.entity.Player; - -public class TrackedLine { - - private final PlaceholderTracker placeholderTracker; - private final StandardTextLine textLine; - private final NMSArmorStand entity; - private final StringWithPlaceholders textWithPlaceholders; - private final boolean containsIndividualPlaceholders; - private final PlaceholderReplaceFunction globalReplaceFunction; - - private StringWithPlaceholders textWithGlobalReplacements; - - TrackedLine( - PlaceholderTracker placeholderTracker, - StandardTextLine textLine, - NMSArmorStand entity, - StringWithPlaceholders textWithPlaceholders) { - this.placeholderTracker = placeholderTracker; - this.textLine = textLine; - this.entity = entity; - this.textWithPlaceholders = textWithPlaceholders; - this.containsIndividualPlaceholders = placeholderTracker.containsIndividualPlaceholders(textWithPlaceholders); - this.globalReplaceFunction = placeholderTracker::updateAndGetGlobalReplacement; - } - - void updateEntityWithGlobalPlaceholders() { - textWithGlobalReplacements = textWithPlaceholders.partiallyReplacePlaceholders(globalReplaceFunction); - entity.setCustomNameNMS(textWithGlobalReplacements.toString()); - } - - public String replaceIndividualPlaceholders(Player player) { - if (containsIndividualPlaceholders) { - return textWithGlobalReplacements.replacePlaceholders((occurrence) -> - placeholderTracker.updateAndGetIndividualReplacement(occurrence, player)); - } else { - return textWithGlobalReplacements.toString(); - } - } - - void restoreOriginalName() { - if (!entity.isDeadNMS()) { - entity.setCustomNameNMS(textLine.getText()); - } - } - - public boolean shouldBeUntracked() { - return entity.isDeadNMS(); - } - -} diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/util/NMSVersion.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/util/NMSVersion.java index 0b0a98d8..c93e197c 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/util/NMSVersion.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/util/NMSVersion.java @@ -6,8 +6,8 @@ package me.filoghost.holographicdisplays.plugin.util; import me.filoghost.fcommons.Preconditions; +import me.filoghost.fcommons.logging.ErrorCollector; import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings; import org.bukkit.Bukkit; import java.util.regex.Matcher; @@ -19,32 +19,41 @@ import java.util.regex.Pattern; public enum NMSVersion { // Not using shorter method reference syntax here because it initializes the class, causing a ClassNotFoundException - v1_8_R2(packetSettings -> new me.filoghost.holographicdisplays.nms.v1_8_R2.VersionNMSManager(packetSettings)), - v1_8_R3(packetSettings -> new me.filoghost.holographicdisplays.nms.v1_8_R3.VersionNMSManager(packetSettings)), - v1_9_R1(packetSettings -> new me.filoghost.holographicdisplays.nms.v1_9_R1.VersionNMSManager(packetSettings)), - v1_9_R2(packetSettings -> new me.filoghost.holographicdisplays.nms.v1_9_R2.VersionNMSManager(packetSettings)), - v1_10_R1(packetSettings -> new me.filoghost.holographicdisplays.nms.v1_10_R1.VersionNMSManager(packetSettings)), - v1_11_R1(packetSettings -> new me.filoghost.holographicdisplays.nms.v1_11_R1.VersionNMSManager(packetSettings)), - v1_12_R1(packetSettings -> new me.filoghost.holographicdisplays.nms.v1_12_R1.VersionNMSManager(packetSettings)), - v1_13_R1(packetSettings -> new me.filoghost.holographicdisplays.nms.v1_13_R1.VersionNMSManager(packetSettings)), - v1_13_R2(packetSettings -> new me.filoghost.holographicdisplays.nms.v1_13_R2.VersionNMSManager(packetSettings)), - v1_14_R1(packetSettings -> new me.filoghost.holographicdisplays.nms.v1_14_R1.VersionNMSManager(packetSettings)), - v1_15_R1(packetSettings -> new me.filoghost.holographicdisplays.nms.v1_15_R1.VersionNMSManager(packetSettings)), - v1_16_R1(packetSettings -> new me.filoghost.holographicdisplays.nms.v1_16_R1.VersionNMSManager(packetSettings)), - v1_16_R2(packetSettings -> new me.filoghost.holographicdisplays.nms.v1_16_R2.VersionNMSManager(packetSettings)), - v1_16_R3(packetSettings -> new me.filoghost.holographicdisplays.nms.v1_16_R3.VersionNMSManager(packetSettings)), - v1_17_R1(packetSettings -> new me.filoghost.holographicdisplays.nms.v1_17_R1.VersionNMSManager(packetSettings)); + v1_8_R2((errorCollector) -> new me.filoghost.holographicdisplays.nms.v1_8_R2.VersionNMSManager()), + v1_8_R3((errorCollector) -> new me.filoghost.holographicdisplays.nms.v1_8_R3.VersionNMSManager()), + v1_9_R1((errorCollector) -> new me.filoghost.holographicdisplays.nms.v1_9_R1.VersionNMSManager()), + v1_9_R2((errorCollector) -> new me.filoghost.holographicdisplays.nms.v1_9_R2.VersionNMSManager()), + v1_10_R1((errorCollector) -> new me.filoghost.holographicdisplays.nms.v1_10_R1.VersionNMSManager()), + v1_11_R1((errorCollector) -> new me.filoghost.holographicdisplays.nms.v1_11_R1.VersionNMSManager()), + v1_12_R1((errorCollector) -> new me.filoghost.holographicdisplays.nms.v1_12_R1.VersionNMSManager()), + v1_13_R1((errorCollector) -> new me.filoghost.holographicdisplays.nms.v1_13_R1.VersionNMSManager()), + v1_13_R2((errorCollector) -> new me.filoghost.holographicdisplays.nms.v1_13_R2.VersionNMSManager()), + v1_14_R1((errorCollector) -> new me.filoghost.holographicdisplays.nms.v1_14_R1.VersionNMSManager()), + v1_15_R1((errorCollector) -> new me.filoghost.holographicdisplays.nms.v1_15_R1.VersionNMSManager()), + v1_16_R1((errorCollector) -> new me.filoghost.holographicdisplays.nms.v1_16_R1.VersionNMSManager()), + v1_16_R2((errorCollector) -> new me.filoghost.holographicdisplays.nms.v1_16_R2.VersionNMSManager()), + v1_16_R3((errorCollector) -> new me.filoghost.holographicdisplays.nms.v1_16_R3.VersionNMSManager()), + v1_17_R1((errorCollector) -> new me.filoghost.holographicdisplays.nms.v1_17_R1.VersionNMSManager(errorCollector)); private static final NMSVersion CURRENT_VERSION = extractCurrentVersion(); - private final NMSManagerConstructor nmsManagerConstructor; + private final NMSManagerFactory nmsManagerFactory; - NMSVersion(NMSManagerConstructor nmsManagerConstructor) { - this.nmsManagerConstructor = nmsManagerConstructor; + NMSVersion(NMSManagerFactory nmsManagerFactory) { + this.nmsManagerFactory = nmsManagerFactory; } - public static NMSManager createNMSManager(ProtocolPacketSettings protocolPacketSettings) { - return getValid().nmsManagerConstructor.create(protocolPacketSettings); + public NMSManager createNMSManager(ErrorCollector errorCollector) { + return nmsManagerFactory.create(errorCollector); + } + + public static NMSVersion getCurrent() { + Preconditions.checkState(isValid(), "Current version is not valid"); + return CURRENT_VERSION; + } + + public static boolean isValid() { + return CURRENT_VERSION != null; } private static NMSVersion extractCurrentVersion() { @@ -61,23 +70,10 @@ public enum NMSVersion { } } - public static boolean isValid() { - return CURRENT_VERSION != null; - } - private static NMSVersion getValid() { - Preconditions.checkState(isValid(), "Current version is not valid"); - return CURRENT_VERSION; - } + private interface NMSManagerFactory { - public static boolean isGreaterEqualThan(NMSVersion other) { - return getValid().ordinal() >= other.ordinal(); - } - - - private interface NMSManagerConstructor { - - NMSManager create(ProtocolPacketSettings protocolPacketSettings); + NMSManager create(ErrorCollector errorCollector); } diff --git a/plugin/src/main/resources/plugin.yml b/plugin/src/main/resources/plugin.yml index 1234d28c..8021966a 100644 --- a/plugin/src/main/resources/plugin.yml +++ b/plugin/src/main/resources/plugin.yml @@ -4,7 +4,7 @@ author: filoghost version: ${pluginVersion} api-version: 1.13 -softdepend: [ProtocolLib, PlaceholderAPI] +softdepend: [PlaceholderAPI] commands: holograms: diff --git a/plugin/src/test/java/me/filoghost/holographicdisplays/plugin/api/v2/V2TouchableLineAdapterTest.java b/plugin/src/test/java/me/filoghost/holographicdisplays/plugin/api/v2/V2TouchableLineAdapterTest.java index 0594d88c..a4d795d1 100644 --- a/plugin/src/test/java/me/filoghost/holographicdisplays/plugin/api/v2/V2TouchableLineAdapterTest.java +++ b/plugin/src/test/java/me/filoghost/holographicdisplays/plugin/api/v2/V2TouchableLineAdapterTest.java @@ -8,8 +8,13 @@ package me.filoghost.holographicdisplays.plugin.api.v2; import com.gmail.filoghost.holographicdisplays.api.line.TextLine; import me.filoghost.holographicdisplays.api.hologram.TouchHandler; import me.filoghost.holographicdisplays.plugin.hologram.api.APIHologram; +import me.filoghost.holographicdisplays.plugin.hologram.api.APIHologramManager; import me.filoghost.holographicdisplays.plugin.hologram.api.APITextLine; +import me.filoghost.holographicdisplays.plugin.test.TestAPIHologramsManager; +import org.bukkit.Location; +import org.bukkit.World; import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Test; @@ -19,7 +24,12 @@ import static org.mockito.Mockito.*; @SuppressWarnings("deprecation") class V2TouchableLineAdapterTest { - APIHologram hologram = mock(APIHologram.class); + APIHologramManager apiHologramManager = new TestAPIHologramsManager(); + + APIHologram hologram = apiHologramManager.createHologram( + new Location(mock(World.class), 0, 0, 0), + mock(Plugin.class) + ); @Test void setNullV2TouchHandler() { diff --git a/plugin/src/test/java/me/filoghost/holographicdisplays/plugin/placeholder/parsing/StringWithPlaceholdersTest.java b/plugin/src/test/java/me/filoghost/holographicdisplays/plugin/placeholder/parsing/StringWithPlaceholdersTest.java index 1fe37ae6..ae11a11f 100644 --- a/plugin/src/test/java/me/filoghost/holographicdisplays/plugin/placeholder/parsing/StringWithPlaceholdersTest.java +++ b/plugin/src/test/java/me/filoghost/holographicdisplays/plugin/placeholder/parsing/StringWithPlaceholdersTest.java @@ -22,7 +22,7 @@ class StringWithPlaceholdersTest { @MethodSource("replacementsTestArguments") void replacements(String input, String expectedOutput) { boolean expectedContainsPlaceholders = expectedOutput.contains("#"); - StringWithPlaceholders s = new StringWithPlaceholders(input); + StringWithPlaceholders s = StringWithPlaceholders.of(input); assertThat(s.replacePlaceholders(occurrence -> "#")).isEqualTo(expectedOutput); assertThat(s.containsPlaceholders()).isEqualTo(expectedContainsPlaceholders); @@ -32,9 +32,9 @@ class StringWithPlaceholdersTest { @MethodSource("replacementsTestArguments") void partialReplacements(String input, String expectedOutput) { boolean expectedContainsPlaceholders = expectedOutput.contains("#"); - StringWithPlaceholders s = new StringWithPlaceholders(input); + StringWithPlaceholders s = StringWithPlaceholders.of(input); - assertThat(s.partiallyReplacePlaceholders(occurrence -> "#").toString()).isEqualTo(expectedOutput); + assertThat(s.partiallyReplacePlaceholders(occurrence -> "#").getUnreplacedString()).isEqualTo(expectedOutput); assertThat(s.containsPlaceholders()).isEqualTo(expectedContainsPlaceholders); } @@ -54,14 +54,14 @@ class StringWithPlaceholdersTest { @Test void skipReplacing() { String input = "{p} a {p} b {p}"; - StringWithPlaceholders s = new StringWithPlaceholders(input); + StringWithPlaceholders s = StringWithPlaceholders.of(input); assertThat(s.replacePlaceholders(occurrence -> null)).isEqualTo(input); } @ParameterizedTest(name = "[{index}] {0} -> {1}, {2}, {3}") @MethodSource("parsingTestArguments") void parsing(String input, String expectedPluginName, String expectedIdentifier, String expectedArgument) { - StringWithPlaceholders s = new StringWithPlaceholders(input); + StringWithPlaceholders s = StringWithPlaceholders.of(input); List placeholders = new ArrayList<>(); s.replacePlaceholders(occurrence -> { diff --git a/plugin/src/test/java/me/filoghost/holographicdisplays/plugin/test/TestAPIHologramsManager.java b/plugin/src/test/java/me/filoghost/holographicdisplays/plugin/test/TestAPIHologramsManager.java new file mode 100644 index 00000000..465bca2a --- /dev/null +++ b/plugin/src/test/java/me/filoghost/holographicdisplays/plugin/test/TestAPIHologramsManager.java @@ -0,0 +1,20 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.plugin.test; + +import me.filoghost.holographicdisplays.plugin.hologram.api.APIHologramManager; +import me.filoghost.holographicdisplays.plugin.hologram.tracking.LineTrackerManager; +import me.filoghost.holographicdisplays.plugin.placeholder.tracking.PlaceholderTracker; + +import static org.mockito.Mockito.*; + +public class TestAPIHologramsManager extends APIHologramManager { + + public TestAPIHologramsManager() { + super(new LineTrackerManager(new TestNMSManager(), mock(PlaceholderTracker.class))); + } + +} diff --git a/plugin/src/test/java/me/filoghost/holographicdisplays/plugin/test/TestNMSManager.java b/plugin/src/test/java/me/filoghost/holographicdisplays/plugin/test/TestNMSManager.java new file mode 100644 index 00000000..f2dda784 --- /dev/null +++ b/plugin/src/test/java/me/filoghost/holographicdisplays/plugin/test/TestNMSManager.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.plugin.test; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.NMSManager; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; + +import java.util.concurrent.atomic.AtomicInteger; + +import static org.mockito.Mockito.*; + +public class TestNMSManager implements NMSManager { + + private final AtomicInteger entityIDGenerator; + private final NMSPacketList packetList; + + public TestNMSManager() { + this.entityIDGenerator = new AtomicInteger(); + this.packetList = mock(NMSPacketList.class); + } + + @Override + public EntityID newEntityID() { + return new EntityID(entityIDGenerator::incrementAndGet); + } + + @Override + public NMSPacketList createPacketList() { + return packetList; + } + +} diff --git a/pom.xml b/pom.xml index ddd1c31a..6aaa206a 100644 --- a/pom.xml +++ b/pom.xml @@ -52,11 +52,6 @@ https://repo.codemc.io/repository/nms/ - - dmulloy2-repo - https://repo.dmulloy2.net/repository/public/ - - placeholderapi-repo https://repo.extendedclip.com/content/repositories/placeholderapi/ @@ -204,13 +199,6 @@ - - com.comphenix.protocol - ProtocolLib - 4.5.0 - provided - - me.clip placeholderapi