From 09f99be342a568e5e5426b4a9854a2c96b59b286 Mon Sep 17 00:00:00 2001 From: filoghost Date: Tue, 10 Nov 2020 10:27:41 +0100 Subject: [PATCH] Convert tabs to spaces --- api/pom.xml | 42 +- .../holographicdisplays/api/Hologram.java | 372 ++++----- .../holographicdisplays/api/HologramsAPI.java | 178 ++--- .../api/VisibilityManager.java | 110 +-- .../api/handler/PickupHandler.java | 12 +- .../api/handler/TouchHandler.java | 12 +- .../api/internal/BackendAPI.java | 44 +- .../api/line/CollectableLine.java | 30 +- .../api/line/HologramLine.java | 26 +- .../api/line/ItemLine.java | 26 +- .../api/line/TextLine.java | 28 +- .../api/line/TouchableLine.java | 28 +- .../api/placeholder/PlaceholderReplacer.java | 12 +- config/pom.xml | 50 +- .../holographicdisplays/disk/ConfigNode.java | 70 +- .../disk/Configuration.java | 360 ++++----- .../disk/LocationSerializer.java | 66 +- .../disk/ServerAddress.java | 38 +- .../disk/StringConverter.java | 116 +-- .../disk/UnicodeSymbols.java | 148 ++-- .../exception/InvalidFormatException.java | 2 +- .../exception/WorldNotFoundException.java | 10 +- example/death-holograms/pom.xml | 20 +- .../deathholograms/DeathHolograms.java | 48 +- example/pom.xml | 66 +- example/power-ups/pom.xml | 18 +- .../filoghost/example/powerups/PowerUps.java | 96 +-- legacy-v1/pom.xml | 62 +- .../filoghost/holograms/api/FloatingItem.java | 78 +- .../filoghost/holograms/api/Hologram.java | 112 +-- .../holograms/api/HolographicDisplaysAPI.java | 242 +++--- .../holograms/api/ItemTouchHandler.java | 6 +- .../holograms/api/PickupHandler.java | 6 +- .../filoghost/holograms/api/TouchHandler.java | 6 +- .../api/adapter/FloatingItemAdapter.java | 212 ++--- .../api/adapter/HologramAdapter.java | 290 +++---- .../adapter/HologramTouchHandlerAdapter.java | 24 +- .../api/adapter/ItemTouchHandlerAdapter.java | 22 +- .../api/adapter/PickupHandlerAdapter.java | 24 +- legacy-v2/pom.xml | 58 +- .../holographicdisplays/api/Hologram.java | 106 +-- .../holographicdisplays/api/HologramsAPI.java | 62 +- .../api/VisibilityManager.java | 42 +- .../api/handler/PickupHandler.java | 6 +- .../api/handler/TouchHandler.java | 6 +- .../api/internal/BackendAPI.java | 56 +- .../api/line/CollectableLine.java | 12 +- .../api/line/HologramLine.java | 10 +- .../api/line/ItemLine.java | 10 +- .../api/line/TextLine.java | 12 +- .../api/line/TouchableLine.java | 12 +- .../api/placeholder/PlaceholderReplacer.java | 6 +- nms/interfaces/pom.xml | 54 +- .../nms/interfaces/ChatComponentAdapter.java | 32 +- .../nms/interfaces/CustomNameHelper.java | 116 +-- .../nms/interfaces/ItemPickupManager.java | 4 +- .../nms/interfaces/NMSManager.java | 28 +- .../nms/interfaces/entity/NMSArmorStand.java | 6 +- .../nms/interfaces/entity/NMSCanMount.java | 8 +- .../nms/interfaces/entity/NMSEntityBase.java | 30 +- .../nms/interfaces/entity/NMSItem.java | 26 +- .../nms/interfaces/entity/NMSNameable.java | 18 +- .../nms/interfaces/entity/NMSSlime.java | 8 +- nms/pom.xml | 54 +- nms/v1_10_r1/pom.xml | 68 +- .../nms/v1_10_R1/CraftNMSArmorStand.java | 116 +-- .../nms/v1_10_R1/CraftNMSItem.java | 66 +- .../nms/v1_10_R1/CraftNMSSlime.java | 86 +- .../nms/v1_10_R1/EntityNMSArmorStand.java | 394 +++++----- .../nms/v1_10_R1/EntityNMSItem.java | 436 +++++------ .../nms/v1_10_R1/EntityNMSSlime.java | 392 +++++----- .../nms/v1_10_R1/NmsManagerImpl.java | 190 ++--- .../nms/v1_10_R1/NullBoundingBox.java | 162 ++-- nms/v1_11_r1/pom.xml | 68 +- .../nms/v1_11_R1/CraftNMSArmorStand.java | 116 +-- .../nms/v1_11_R1/CraftNMSItem.java | 66 +- .../nms/v1_11_R1/CraftNMSSlime.java | 86 +- .../nms/v1_11_R1/EntityNMSArmorStand.java | 394 +++++----- .../nms/v1_11_R1/EntityNMSItem.java | 386 ++++----- .../nms/v1_11_R1/EntityNMSSlime.java | 350 ++++----- .../nms/v1_11_R1/NmsManagerImpl.java | 202 ++--- .../nms/v1_11_R1/NullBoundingBox.java | 192 ++--- nms/v1_12_r1/pom.xml | 68 +- .../nms/v1_12_R1/CraftNMSArmorStand.java | 118 +-- .../nms/v1_12_R1/CraftNMSItem.java | 66 +- .../nms/v1_12_R1/CraftNMSSlime.java | 86 +- .../nms/v1_12_R1/EntityNMSArmorStand.java | 394 +++++----- .../nms/v1_12_R1/EntityNMSItem.java | 386 ++++----- .../nms/v1_12_R1/EntityNMSSlime.java | 348 ++++---- .../nms/v1_12_R1/NmsManagerImpl.java | 204 ++--- .../nms/v1_12_R1/NullBoundingBox.java | 192 ++--- nms/v1_13_r1/pom.xml | 68 +- .../nms/v1_13_R1/CraftNMSArmorStand.java | 122 +-- .../nms/v1_13_R1/CraftNMSItem.java | 66 +- .../nms/v1_13_R1/CraftNMSSlime.java | 92 +-- .../nms/v1_13_R1/EntityNMSArmorStand.java | 394 +++++----- .../nms/v1_13_R1/EntityNMSItem.java | 384 ++++----- .../nms/v1_13_R1/EntityNMSSlime.java | 352 ++++----- .../nms/v1_13_R1/NmsManagerImpl.java | 288 +++---- .../nms/v1_13_R1/NullBoundingBox.java | 176 ++--- nms/v1_13_r2/pom.xml | 68 +- .../nms/v1_13_R2/CraftNMSArmorStand.java | 124 +-- .../nms/v1_13_R2/CraftNMSItem.java | 68 +- .../nms/v1_13_R2/CraftNMSSlime.java | 100 +-- .../nms/v1_13_R2/EntityNMSArmorStand.java | 394 +++++----- .../nms/v1_13_R2/EntityNMSItem.java | 386 ++++----- .../nms/v1_13_R2/EntityNMSSlime.java | 352 ++++----- .../nms/v1_13_R2/NmsManagerImpl.java | 288 +++---- .../nms/v1_13_R2/NullBoundingBox.java | 176 ++--- nms/v1_14_r1/pom.xml | 68 +- .../nms/v1_14_R1/CraftNMSArmorStand.java | 124 +-- .../nms/v1_14_R1/CraftNMSItem.java | 70 +- .../nms/v1_14_R1/CraftNMSSlime.java | 102 +-- .../nms/v1_14_R1/EntityNMSArmorStand.java | 396 +++++----- .../nms/v1_14_R1/EntityNMSItem.java | 388 ++++----- .../nms/v1_14_R1/EntityNMSSlime.java | 352 ++++----- .../nms/v1_14_R1/NmsManagerImpl.java | 300 +++---- .../nms/v1_14_R1/NullBoundingBox.java | 188 ++--- nms/v1_15_r1/pom.xml | 68 +- .../nms/v1_15_R1/CraftNMSArmorStand.java | 124 +-- .../nms/v1_15_R1/CraftNMSItem.java | 70 +- .../nms/v1_15_R1/CraftNMSSlime.java | 102 +-- .../nms/v1_15_R1/EntityNMSArmorStand.java | 48 +- .../nms/v1_15_R1/EntityNMSItem.java | 14 +- .../nms/v1_15_R1/EntityNMSSlime.java | 352 ++++----- .../nms/v1_15_R1/NmsManagerImpl.java | 266 +++---- nms/v1_16_r1/pom.xml | 68 +- .../nms/v1_16_R1/CraftNMSArmorStand.java | 124 +-- .../nms/v1_16_R1/CraftNMSItem.java | 70 +- .../nms/v1_16_R1/CraftNMSSlime.java | 102 +-- .../nms/v1_16_R1/EntityNMSArmorStand.java | 48 +- .../nms/v1_16_R1/EntityNMSItem.java | 14 +- .../nms/v1_16_R1/EntityNMSSlime.java | 352 ++++----- .../nms/v1_16_R1/NmsManagerImpl.java | 268 +++---- nms/v1_16_r2/pom.xml | 68 +- .../nms/v1_16_R2/CraftNMSArmorStand.java | 124 +-- .../nms/v1_16_R2/CraftNMSItem.java | 70 +- .../nms/v1_16_R2/CraftNMSSlime.java | 102 +-- .../nms/v1_16_R2/EntityNMSArmorStand.java | 48 +- .../nms/v1_16_R2/EntityNMSItem.java | 14 +- .../nms/v1_16_R2/EntityNMSSlime.java | 352 ++++----- .../nms/v1_16_R2/NmsManagerImpl.java | 254 +++--- nms/v1_16_r3/pom.xml | 66 +- .../nms/v1_16_R3/CraftNMSArmorStand.java | 124 +-- .../nms/v1_16_R3/CraftNMSItem.java | 70 +- .../nms/v1_16_R3/CraftNMSSlime.java | 102 +-- .../nms/v1_16_R3/EntityNMSArmorStand.java | 48 +- .../nms/v1_16_R3/EntityNMSItem.java | 14 +- .../nms/v1_16_R3/EntityNMSSlime.java | 352 ++++----- .../nms/v1_16_R3/NmsManagerImpl.java | 254 +++--- nms/v1_8_r2/pom.xml | 66 +- .../nms/v1_8_R2/CraftNMSArmorStand.java | 94 +-- .../nms/v1_8_R2/CraftNMSItem.java | 52 +- .../nms/v1_8_R2/CraftNMSSlime.java | 66 +- .../nms/v1_8_R2/EntityNMSArmorStand.java | 388 ++++----- .../nms/v1_8_R2/EntityNMSItem.java | 354 ++++----- .../nms/v1_8_R2/EntityNMSSlime.java | 316 ++++---- .../nms/v1_8_R2/NmsManagerImpl.java | 200 ++--- .../nms/v1_8_R2/NullBoundingBox.java | 104 +-- nms/v1_8_r3/pom.xml | 68 +- .../nms/v1_8_R3/CraftNMSArmorStand.java | 94 +-- .../nms/v1_8_R3/CraftNMSItem.java | 52 +- .../nms/v1_8_R3/CraftNMSSlime.java | 66 +- .../nms/v1_8_R3/EntityNMSArmorStand.java | 386 ++++----- .../nms/v1_8_R3/EntityNMSItem.java | 356 ++++----- .../nms/v1_8_R3/EntityNMSSlime.java | 316 ++++---- .../nms/v1_8_R3/NmsManagerImpl.java | 198 ++--- .../nms/v1_8_R3/NullBoundingBox.java | 104 +-- nms/v1_9_r1/pom.xml | 68 +- .../nms/v1_9_R1/CraftNMSArmorStand.java | 96 +-- .../nms/v1_9_R1/CraftNMSItem.java | 54 +- .../nms/v1_9_R1/CraftNMSSlime.java | 68 +- .../nms/v1_9_R1/EntityNMSArmorStand.java | 406 +++++----- .../nms/v1_9_R1/EntityNMSItem.java | 434 +++++----- .../nms/v1_9_R1/EntityNMSSlime.java | 388 ++++----- .../nms/v1_9_R1/NmsManagerImpl.java | 192 ++--- .../nms/v1_9_R1/NullBoundingBox.java | 164 ++-- nms/v1_9_r2/pom.xml | 66 +- .../nms/v1_9_R2/CraftNMSArmorStand.java | 96 +-- .../nms/v1_9_R2/CraftNMSItem.java | 54 +- .../nms/v1_9_R2/CraftNMSSlime.java | 68 +- .../nms/v1_9_R2/EntityNMSArmorStand.java | 394 +++++----- .../nms/v1_9_R2/EntityNMSItem.java | 436 +++++------ .../nms/v1_9_R2/EntityNMSSlime.java | 390 ++++----- .../nms/v1_9_R2/NmsManagerImpl.java | 192 ++--- .../nms/v1_9_R2/NullBoundingBox.java | 164 ++-- plugin/pom.xml | 474 +++++------ .../HolographicDisplays.java | 432 +++++----- .../bridge/bungeecord/BungeeChannel.java | 124 +-- .../bridge/bungeecord/BungeeServerInfo.java | 130 +-- .../bungeecord/BungeeServerTracker.java | 340 ++++---- .../bungeecord/serverpinger/PacketUtils.java | 76 +- .../bungeecord/serverpinger/PingResponse.java | 132 ++-- .../bungeecord/serverpinger/ServerPinger.java | 74 +- .../bridge/protocollib/ProtocolLibHook.java | 20 +- .../protocollib/current/DebugHelper.java | 150 ++-- .../protocollib/current/MetadataHelper.java | 326 ++++---- .../protocollib/current/PacketHelper.java | 196 ++--- .../current/ProtocolLibHookImpl.java | 502 ++++++------ .../current/packet/AbstractPacket.java | 96 +-- .../packet/EntityRelatedPacketWrapper.java | 4 +- .../packet/WrapperPlayServerAttachEntity.java | 10 +- .../WrapperPlayServerEntityMetadata.java | 4 +- .../packet/WrapperPlayServerMount.java | 6 +- .../packet/WrapperPlayServerSpawnEntity.java | 92 +-- .../WrapperPlayServerSpawnEntityLiving.java | 12 +- .../holographicdisplays/commands/Colors.java | 24 +- .../commands/CommandValidator.java | 110 +-- .../holographicdisplays/commands/Strings.java | 34 +- .../commands/main/HologramSubCommand.java | 118 +-- .../main/HologramsCommandHandler.java | 156 ++-- .../commands/main/subs/AddlineCommand.java | 72 +- .../commands/main/subs/AlignCommand.java | 96 +-- .../commands/main/subs/CopyCommand.java | 82 +- .../commands/main/subs/CreateCommand.java | 122 +-- .../commands/main/subs/DebugCommand.java | 176 ++--- .../commands/main/subs/DeleteCommand.java | 64 +- .../commands/main/subs/EditCommand.java | 222 +++--- .../commands/main/subs/HelpCommand.java | 130 +-- .../commands/main/subs/InfoCommand.java | 68 +- .../commands/main/subs/InsertlineCommand.java | 100 +-- .../commands/main/subs/ListCommand.java | 102 +-- .../commands/main/subs/MovehereCommand.java | 74 +- .../commands/main/subs/NearCommand.java | 86 +- .../commands/main/subs/ReadimageCommand.java | 250 +++--- .../commands/main/subs/ReadtextCommand.java | 176 ++--- .../commands/main/subs/ReloadCommand.java | 144 ++-- .../commands/main/subs/RemovelineCommand.java | 80 +- .../commands/main/subs/SetlineCommand.java | 86 +- .../commands/main/subs/TeleportCommand.java | 64 +- .../disk/HologramDatabase.java | 174 ++-- .../disk/HologramLineParser.java | 162 ++-- .../event/HolographicDisplaysReloadEvent.java | 10 +- .../event/NamedHologramEditedEvent.java | 26 +- .../exception/CommandException.java | 8 +- .../exception/HologramLineParseException.java | 16 +- .../exception/HologramNotFoundException.java | 2 +- .../exception/TooWideException.java | 22 +- .../image/ImageMessage.java | 120 +-- .../listener/MainListener.java | 266 +++---- .../object/CraftHologram.java | 634 +++++++-------- .../object/CraftVisibilityManager.java | 298 +++---- .../object/DefaultBackendAPI.java | 86 +- .../object/NamedHologram.java | 42 +- .../object/NamedHologramManager.java | 122 +-- .../object/PluginHologram.java | 36 +- .../object/PluginHologramManager.java | 108 +-- .../object/line/CraftHologramLine.java | 124 +-- .../object/line/CraftItemLine.java | 222 +++--- .../object/line/CraftTextLine.java | 236 +++--- .../object/line/CraftTouchSlimeLine.java | 154 ++-- .../object/line/CraftTouchableLine.java | 112 +-- .../placeholder/AnimationsRegister.java | 138 ++-- .../CyclicPlaceholderReplacer.java | 36 +- .../placeholder/DynamicLineData.java | 110 +-- .../placeholder/Placeholder.java | 156 ++-- .../placeholder/PlaceholdersManager.java | 666 ++++++++-------- .../placeholder/PlaceholdersRegister.java | 160 ++-- .../placeholder/RelativePlaceholder.java | 94 +-- .../task/BungeeCleanupTask.java | 38 +- .../task/StartupLoadHologramsTask.java | 46 +- .../task/WorldPlayerCounterTask.java | 74 +- pom.xml | 568 +++++++------- utils/pom.xml | 52 +- .../exception/UnreadableImageException.java | 2 +- .../util/ConsoleLogger.java | 70 +- .../holographicdisplays/util/FileUtils.java | 130 +-- .../holographicdisplays/util/ItemUtils.java | 186 ++--- .../holographicdisplays/util/NMSVersion.java | 112 +-- .../holographicdisplays/util/Offsets.java | 22 +- .../holographicdisplays/util/Utils.java | 190 ++--- .../holographicdisplays/util/Validator.java | 24 +- .../util/VersionUtils.java | 146 ++-- .../holographicdisplays/util/nbt/NBTByte.java | 76 +- .../util/nbt/NBTByteArray.java | 88 +-- .../util/nbt/NBTCompound.java | 740 +++++++++--------- .../util/nbt/NBTDouble.java | 78 +- .../util/nbt/NBTFloat.java | 76 +- .../holographicdisplays/util/nbt/NBTInt.java | 76 +- .../util/nbt/NBTIntArray.java | 106 +-- .../holographicdisplays/util/nbt/NBTList.java | 294 +++---- .../holographicdisplays/util/nbt/NBTLong.java | 76 +- .../util/nbt/NBTLongArray.java | 98 +-- .../util/nbt/NBTShort.java | 76 +- .../util/nbt/NBTString.java | 94 +-- .../holographicdisplays/util/nbt/NBTTag.java | 88 +-- .../holographicdisplays/util/nbt/NBTType.java | 306 ++++---- .../nbt/parser/MojangsonParseException.java | 28 +- .../util/nbt/parser/MojangsonParser.java | 612 +++++++-------- .../util/reflection/ReflectField.java | 74 +- .../util/reflection/ReflectMethod.java | 58 +- 291 files changed, 20727 insertions(+), 20727 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index afeecb06..af959598 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -1,29 +1,29 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - - me.filoghost.holographicdisplays - holographicdisplays-parent - 3.0.0-SNAPSHOT - + + me.filoghost.holographicdisplays + holographicdisplays-parent + 3.0.0-SNAPSHOT + - holographicdisplays-api - HolographicDisplays API + holographicdisplays-api + HolographicDisplays API - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + - - - org.spigotmc - spigot-api - - + + + org.spigotmc + spigot-api + + diff --git a/api/src/main/java/me/filoghost/holographicdisplays/api/Hologram.java b/api/src/main/java/me/filoghost/holographicdisplays/api/Hologram.java index a9feeb4c..a1dfa7e9 100644 --- a/api/src/main/java/me/filoghost/holographicdisplays/api/Hologram.java +++ b/api/src/main/java/me/filoghost/holographicdisplays/api/Hologram.java @@ -27,193 +27,193 @@ import org.bukkit.inventory.ItemStack; * To create one, please see {@link HologramsAPI#createHologram(org.bukkit.plugin.Plugin, Location)}. */ public interface Hologram { - - /** - * Appends a text line to end of this hologram. - * - * @param text the content of the line, can be null for an empty line - * @return the new TextLine appended - */ - public TextLine appendTextLine(String text); - - - /** - * Appends an item line to end of this hologram. - * - * @param itemStack the content of the line - * @return the new ItemLine appended - */ - public ItemLine appendItemLine(ItemStack itemStack); - - - /** - * Inserts a text line in this hologram. - * - * @param index the line is inserted before this index. If 0, the new line will - * be inserted before the first line. - * @param text the content of the line, can be null for an empty line - * @return the new TextLine inserted - * @throws IndexOutOfBoundsException if the index is out of range (index < 0 || index >= size()) - */ - public TextLine insertTextLine(int index, String text); - - - /** - * Inserts an item line in this hologram. - * - * @param index the line is inserted before this index. If 0, the new line will - * be inserted before the first line. - * @param itemStack the content of the line - * @return the new ItemLine inserted - * @throws IndexOutOfBoundsException if the index is out of range (index < 0 || index >= size()) - */ - public ItemLine insertItemLine(int index, ItemStack itemStack); - - - /** - * Finds the element at a given index in the lines. - * - * @param index the index of the line to retrieve. - * @return the hologram line at the given index, can be an {@link ItemLine} or a {@link TextLine}. - * @throws IndexOutOfBoundsException if the index is out of range (index < 0 || index >= size()) - */ - public HologramLine getLine(int index); - - /** - * Removes a line at a given index. Since: v2.0.1 - * - * @param index the index of the line, that should be between 0 and size() - 1. - * @throws IndexOutOfBoundsException if the index is out of range (index < 0 || index >= size()) - */ - public void removeLine(int index); - - - /** - * Removes all the lines from this hologram. - */ - public void clearLines(); + + /** + * Appends a text line to end of this hologram. + * + * @param text the content of the line, can be null for an empty line + * @return the new TextLine appended + */ + public TextLine appendTextLine(String text); + + + /** + * Appends an item line to end of this hologram. + * + * @param itemStack the content of the line + * @return the new ItemLine appended + */ + public ItemLine appendItemLine(ItemStack itemStack); + + + /** + * Inserts a text line in this hologram. + * + * @param index the line is inserted before this index. If 0, the new line will + * be inserted before the first line. + * @param text the content of the line, can be null for an empty line + * @return the new TextLine inserted + * @throws IndexOutOfBoundsException if the index is out of range (index < 0 || index >= size()) + */ + public TextLine insertTextLine(int index, String text); + + + /** + * Inserts an item line in this hologram. + * + * @param index the line is inserted before this index. If 0, the new line will + * be inserted before the first line. + * @param itemStack the content of the line + * @return the new ItemLine inserted + * @throws IndexOutOfBoundsException if the index is out of range (index < 0 || index >= size()) + */ + public ItemLine insertItemLine(int index, ItemStack itemStack); + + + /** + * Finds the element at a given index in the lines. + * + * @param index the index of the line to retrieve. + * @return the hologram line at the given index, can be an {@link ItemLine} or a {@link TextLine}. + * @throws IndexOutOfBoundsException if the index is out of range (index < 0 || index >= size()) + */ + public HologramLine getLine(int index); + + /** + * Removes a line at a given index. Since: v2.0.1 + * + * @param index the index of the line, that should be between 0 and size() - 1. + * @throws IndexOutOfBoundsException if the index is out of range (index < 0 || index >= size()) + */ + public void removeLine(int index); + + + /** + * Removes all the lines from this hologram. + */ + public void clearLines(); - - /** - * Checks the amount of lines of the hologram. - * - * @return the amount of lines - */ - public int size(); - - - /** - * The physical height of the hologram, counting all the lines. Since: v2.1.4 - * - * @return the height of the hologram, counting all the lines and the gaps between them - */ - public double getHeight(); - - - /** - * Teleports a hologram to the given location. - * - * @param location the new location - */ - public void teleport(Location location); - - - /** - * Teleports a hologram to the given location. - * - * @param world the world where the hologram should be teleported, - * use {@link #getWorld()} to teleport it in the same world. - * @param x the X coordinate - * @param y the Y coordinate - * @param z the Z coordinate - */ - public void teleport(World world, double x, double y, double z); - - /** - * Returns the position of the hologram. - * - * @return the Location of the hologram - */ - public Location getLocation(); - - /** - * Returns the X coordinate. - * - * @return the X coordinate of the hologram - */ - public double getX(); - - - /** - * Returns the Y coordinate. - * - * @return the Y coordinate of the hologram - */ - public double getY(); - - - /** - * Returns the Z coordinate. - * - * @return the Z coordinate of the hologram - */ - public double getZ(); - - - /** - * Returns the world. - * - * @return the world of the hologram - */ - public World getWorld(); - - - /** - * Returns the {@link VisibilityManager} of this hologram. - *
Note: the usage of the VisibilityManager requires ProtocolLib. - * Without the plugin, holograms will be always visible. - * - * @return the VisibilityManager of this hologram - */ - public VisibilityManager getVisibilityManager(); - - - /** - * Returns when the hologram was created. Useful for removing old holograms. - * - * @return the timestamp of when the hologram was created, in milliseconds - */ - public long getCreationTimestamp(); + + /** + * Checks the amount of lines of the hologram. + * + * @return the amount of lines + */ + public int size(); + + + /** + * The physical height of the hologram, counting all the lines. Since: v2.1.4 + * + * @return the height of the hologram, counting all the lines and the gaps between them + */ + public double getHeight(); + + + /** + * Teleports a hologram to the given location. + * + * @param location the new location + */ + public void teleport(Location location); + + + /** + * Teleports a hologram to the given location. + * + * @param world the world where the hologram should be teleported, + * use {@link #getWorld()} to teleport it in the same world. + * @param x the X coordinate + * @param y the Y coordinate + * @param z the Z coordinate + */ + public void teleport(World world, double x, double y, double z); + + /** + * Returns the position of the hologram. + * + * @return the Location of the hologram + */ + public Location getLocation(); + + /** + * Returns the X coordinate. + * + * @return the X coordinate of the hologram + */ + public double getX(); + + + /** + * Returns the Y coordinate. + * + * @return the Y coordinate of the hologram + */ + public double getY(); + + + /** + * Returns the Z coordinate. + * + * @return the Z coordinate of the hologram + */ + public double getZ(); + + + /** + * Returns the world. + * + * @return the world of the hologram + */ + public World getWorld(); + + + /** + * Returns the {@link VisibilityManager} of this hologram. + *
Note: the usage of the VisibilityManager requires ProtocolLib. + * Without the plugin, holograms will be always visible. + * + * @return the VisibilityManager of this hologram + */ + public VisibilityManager getVisibilityManager(); + + + /** + * Returns when the hologram was created. Useful for removing old holograms. + * + * @return the timestamp of when the hologram was created, in milliseconds + */ + public long getCreationTimestamp(); - /** - * Checks if the hologram will track and replace placeholders. - * This is false by default. - * - * @return if the hologram allows placeholders - */ - public boolean isAllowPlaceholders(); + /** + * Checks if the hologram will track and replace placeholders. + * This is false by default. + * + * @return if the hologram allows placeholders + */ + public boolean isAllowPlaceholders(); - /** - * Sets if the hologram should track and replace placeholders. - * By default if will not track them. - * - * @param allowPlaceholders if the hologram should track placeholders - */ - public void setAllowPlaceholders(boolean allowPlaceholders); - - /** - * Deletes this hologram. Editing or teleporting the hologram when deleted - * will throw an exception. Lines will be automatically cleared. - * You should remove all the references of the hologram after deletion. - */ - public void delete(); - - - /** - * Checks if a hologram was deleted. - * - * @return true if this hologram was deleted - */ - public boolean isDeleted(); - + /** + * Sets if the hologram should track and replace placeholders. + * By default if will not track them. + * + * @param allowPlaceholders if the hologram should track placeholders + */ + public void setAllowPlaceholders(boolean allowPlaceholders); + + /** + * Deletes this hologram. Editing or teleporting the hologram when deleted + * will throw an exception. Lines will be automatically cleared. + * You should remove all the references of the hologram after deletion. + */ + public void delete(); + + + /** + * Checks if a hologram was deleted. + * + * @return true if this hologram was deleted + */ + public boolean isDeleted(); + } diff --git a/api/src/main/java/me/filoghost/holographicdisplays/api/HologramsAPI.java b/api/src/main/java/me/filoghost/holographicdisplays/api/HologramsAPI.java index f70148cb..396ecd55 100644 --- a/api/src/main/java/me/filoghost/holographicdisplays/api/HologramsAPI.java +++ b/api/src/main/java/me/filoghost/holographicdisplays/api/HologramsAPI.java @@ -27,94 +27,94 @@ import java.util.Collection; * It provides methods to create holograms and to register custom placeholders. */ public class HologramsAPI { - - - private HologramsAPI() { - // No constructor needed. - } - - - /** - * Creates a hologram at given location. - * - * @param plugin the plugin that creates it - * @param source the location where it will appear - * @return the new hologram created - */ - public static Hologram createHologram(Plugin plugin, Location source) { - return BackendAPI.getImplementation().createHologram(plugin, source); - } - - - /** - * Finds all the holograms created by a given plugin. - * - * @param plugin the plugin to search for in holograms - * @return the holograms created by a plugin. the Collection is a copy - * and modifying it has no effect on the holograms. - */ - public static Collection getHolograms(Plugin plugin) { - return BackendAPI.getImplementation().getHolograms(plugin); - } - - - /** - * Registers a new placeholder that can be used in holograms created with commands. - * With this method, you can basically expand the core of HolographicDisplays. - * - * @param plugin the owner plugin of the placeholder - * @param textPlaceholder the text that the placeholder will be associated to (e.g.: "{onlinePlayers}") - * @param refreshRate the refresh rate of the placeholder, in seconds. Keep in mind that the minimum is 0.1 seconds, and that will be rounded to tenths of seconds - * @param replacer the implementation that will return the text to replace the placeholder, where the update() method is called every refreshRate seconds - * @return true if the registration was successfull, false if it was already registered - */ - public static boolean registerPlaceholder(Plugin plugin, String textPlaceholder, double refreshRate, PlaceholderReplacer replacer) { - return BackendAPI.getImplementation().registerPlaceholder(plugin, textPlaceholder, refreshRate, replacer); - } - - - /** - * Finds all the placeholders registered by a given plugin. - * - * @param plugin the plugin to search for - * @return a collection of placeholders registered by the plugin - */ - public static Collection getRegisteredPlaceholders(Plugin plugin) { - return BackendAPI.getImplementation().getRegisteredPlaceholders(plugin); - } - - - /** - * Unregister a placeholder created by a plugin. - * - * @param plugin the plugin that owns the placeholder - * @param textPlaceholder the placeholder to remove - * @return true if found and removed, false otherwise - */ - public static boolean unregisterPlaceholder(Plugin plugin, String textPlaceholder) { - return BackendAPI.getImplementation().unregisterPlaceholder(plugin, textPlaceholder); - } - - - /** - * Resets and removes all the placeholders registered by a plugin. This is useful - * when you have configurable placeholders and you want to remove all of them. - * - * @param plugin the plugin that owns the placeholders - */ - public static void unregisterPlaceholders(Plugin plugin) { - BackendAPI.getImplementation().unregisterPlaceholders(plugin); - } - - - /** - * Checks if an entity is part of a hologram. - * - * @param bukkitEntity the entity to check - * @return true if the entity is a part of a hologram - */ - public static boolean isHologramEntity(Entity bukkitEntity) { - return BackendAPI.getImplementation().isHologramEntity(bukkitEntity); - } + + + private HologramsAPI() { + // No constructor needed. + } + + + /** + * Creates a hologram at given location. + * + * @param plugin the plugin that creates it + * @param source the location where it will appear + * @return the new hologram created + */ + public static Hologram createHologram(Plugin plugin, Location source) { + return BackendAPI.getImplementation().createHologram(plugin, source); + } + + + /** + * Finds all the holograms created by a given plugin. + * + * @param plugin the plugin to search for in holograms + * @return the holograms created by a plugin. the Collection is a copy + * and modifying it has no effect on the holograms. + */ + public static Collection getHolograms(Plugin plugin) { + return BackendAPI.getImplementation().getHolograms(plugin); + } + + + /** + * Registers a new placeholder that can be used in holograms created with commands. + * With this method, you can basically expand the core of HolographicDisplays. + * + * @param plugin the owner plugin of the placeholder + * @param textPlaceholder the text that the placeholder will be associated to (e.g.: "{onlinePlayers}") + * @param refreshRate the refresh rate of the placeholder, in seconds. Keep in mind that the minimum is 0.1 seconds, and that will be rounded to tenths of seconds + * @param replacer the implementation that will return the text to replace the placeholder, where the update() method is called every refreshRate seconds + * @return true if the registration was successfull, false if it was already registered + */ + public static boolean registerPlaceholder(Plugin plugin, String textPlaceholder, double refreshRate, PlaceholderReplacer replacer) { + return BackendAPI.getImplementation().registerPlaceholder(plugin, textPlaceholder, refreshRate, replacer); + } + + + /** + * Finds all the placeholders registered by a given plugin. + * + * @param plugin the plugin to search for + * @return a collection of placeholders registered by the plugin + */ + public static Collection getRegisteredPlaceholders(Plugin plugin) { + return BackendAPI.getImplementation().getRegisteredPlaceholders(plugin); + } + + + /** + * Unregister a placeholder created by a plugin. + * + * @param plugin the plugin that owns the placeholder + * @param textPlaceholder the placeholder to remove + * @return true if found and removed, false otherwise + */ + public static boolean unregisterPlaceholder(Plugin plugin, String textPlaceholder) { + return BackendAPI.getImplementation().unregisterPlaceholder(plugin, textPlaceholder); + } + + + /** + * Resets and removes all the placeholders registered by a plugin. This is useful + * when you have configurable placeholders and you want to remove all of them. + * + * @param plugin the plugin that owns the placeholders + */ + public static void unregisterPlaceholders(Plugin plugin) { + BackendAPI.getImplementation().unregisterPlaceholders(plugin); + } + + + /** + * Checks if an entity is part of a hologram. + * + * @param bukkitEntity the entity to check + * @return true if the entity is a part of a hologram + */ + public static boolean isHologramEntity(Entity bukkitEntity) { + return BackendAPI.getImplementation().isHologramEntity(bukkitEntity); + } } diff --git a/api/src/main/java/me/filoghost/holographicdisplays/api/VisibilityManager.java b/api/src/main/java/me/filoghost/holographicdisplays/api/VisibilityManager.java index 40c28819..900af421 100644 --- a/api/src/main/java/me/filoghost/holographicdisplays/api/VisibilityManager.java +++ b/api/src/main/java/me/filoghost/holographicdisplays/api/VisibilityManager.java @@ -22,59 +22,59 @@ import org.bukkit.entity.Player; * (when a hologram is not specifically being hidden/shown to a player) can be customized. */ public interface VisibilityManager { - - /** - * Returns if the hologram is visible by default. If not changed, this value - * is true by default so the hologram is visible to everyone. - * - * @return if the hologram hologram is visible by default - */ - public boolean isVisibleByDefault(); - - /** - * Sets if the hologram is visible by default. If not changed, this value - * is true by default so the hologram is visible to everyone. - * - * @param visibleByDefault the new behaviour - */ - public void setVisibleByDefault(boolean visibleByDefault); - - /** - * Shows the hologram to a player, overriding the value of {@link #isVisibleByDefault()}. - * This is persistent if the players goes offline. - * - * @param player the involved player - */ - public void showTo(Player player); - - /** - * Hides the hologram to a player, overriding the value of {@link #isVisibleByDefault()}. - * This is persistent if the players goes offline. - * - * @param player the involved player - */ - public void hideTo(Player player); - - /** - * Checks if a hologram is visible to a player. - * - * @param player the involved player - * @return if the player can see the hologram - */ - public boolean isVisibleTo(Player player); - - /** - * Resets the visibility to the default value. If you previously called {@link #showTo(Player)} - * or {@link #hideTo(Player)} to override the default visibility, this method will reset it - * to reflect the value of {@link #isVisibleByDefault()}. - * - * @param player the involved player - */ - public void resetVisibility(Player player); - - /** - * Resets the visibility for all the players. See {@link #resetVisibility(Player)} for more details. - */ - public void resetVisibilityAll(); - + + /** + * Returns if the hologram is visible by default. If not changed, this value + * is true by default so the hologram is visible to everyone. + * + * @return if the hologram hologram is visible by default + */ + public boolean isVisibleByDefault(); + + /** + * Sets if the hologram is visible by default. If not changed, this value + * is true by default so the hologram is visible to everyone. + * + * @param visibleByDefault the new behaviour + */ + public void setVisibleByDefault(boolean visibleByDefault); + + /** + * Shows the hologram to a player, overriding the value of {@link #isVisibleByDefault()}. + * This is persistent if the players goes offline. + * + * @param player the involved player + */ + public void showTo(Player player); + + /** + * Hides the hologram to a player, overriding the value of {@link #isVisibleByDefault()}. + * This is persistent if the players goes offline. + * + * @param player the involved player + */ + public void hideTo(Player player); + + /** + * Checks if a hologram is visible to a player. + * + * @param player the involved player + * @return if the player can see the hologram + */ + public boolean isVisibleTo(Player player); + + /** + * Resets the visibility to the default value. If you previously called {@link #showTo(Player)} + * or {@link #hideTo(Player)} to override the default visibility, this method will reset it + * to reflect the value of {@link #isVisibleByDefault()}. + * + * @param player the involved player + */ + public void resetVisibility(Player player); + + /** + * Resets the visibility for all the players. See {@link #resetVisibility(Player)} for more details. + */ + public void resetVisibilityAll(); + } diff --git a/api/src/main/java/me/filoghost/holographicdisplays/api/handler/PickupHandler.java b/api/src/main/java/me/filoghost/holographicdisplays/api/handler/PickupHandler.java index da4472fb..f05809f8 100644 --- a/api/src/main/java/me/filoghost/holographicdisplays/api/handler/PickupHandler.java +++ b/api/src/main/java/me/filoghost/holographicdisplays/api/handler/PickupHandler.java @@ -21,10 +21,10 @@ import org.bukkit.entity.Player; */ public interface PickupHandler { - /** - * Called when a player picks up the item. - * @param player the player who picked up the item - */ - public void onPickup(Player player); - + /** + * Called when a player picks up the item. + * @param player the player who picked up the item + */ + public void onPickup(Player player); + } diff --git a/api/src/main/java/me/filoghost/holographicdisplays/api/handler/TouchHandler.java b/api/src/main/java/me/filoghost/holographicdisplays/api/handler/TouchHandler.java index 67429267..ec83e174 100644 --- a/api/src/main/java/me/filoghost/holographicdisplays/api/handler/TouchHandler.java +++ b/api/src/main/java/me/filoghost/holographicdisplays/api/handler/TouchHandler.java @@ -21,10 +21,10 @@ import org.bukkit.entity.Player; */ public interface TouchHandler { - /** - * Called when a player interacts with the hologram (right click). - * @param player the player who interacts - */ - public void onTouch(Player player); - + /** + * Called when a player interacts with the hologram (right click). + * @param player the player who interacts + */ + public void onTouch(Player player); + } diff --git a/api/src/main/java/me/filoghost/holographicdisplays/api/internal/BackendAPI.java b/api/src/main/java/me/filoghost/holographicdisplays/api/internal/BackendAPI.java index 67910fff..fd821427 100644 --- a/api/src/main/java/me/filoghost/holographicdisplays/api/internal/BackendAPI.java +++ b/api/src/main/java/me/filoghost/holographicdisplays/api/internal/BackendAPI.java @@ -23,34 +23,34 @@ import org.bukkit.plugin.Plugin; import java.util.Collection; public abstract class BackendAPI { - - private static BackendAPI implementation; - - public static void setImplementation(BackendAPI implementation) { - BackendAPI.implementation = implementation; - } - - public static BackendAPI getImplementation() { - if (implementation == null) { - throw new IllegalStateException("No API implementation set. Is Holographic Displays enabled?"); - } - - return implementation; - } + + private static BackendAPI implementation; + + public static void setImplementation(BackendAPI implementation) { + BackendAPI.implementation = implementation; + } + + public static BackendAPI getImplementation() { + if (implementation == null) { + throw new IllegalStateException("No API implementation set. Is Holographic Displays enabled?"); + } + + return implementation; + } - public abstract Hologram createHologram(Plugin plugin, Location source); + public abstract Hologram createHologram(Plugin plugin, Location source); - public abstract Collection getHolograms(Plugin plugin); + public abstract Collection getHolograms(Plugin plugin); - public abstract boolean registerPlaceholder(Plugin plugin, String textPlaceholder, double refreshRate, PlaceholderReplacer replacer); + public abstract boolean registerPlaceholder(Plugin plugin, String textPlaceholder, double refreshRate, PlaceholderReplacer replacer); - public abstract Collection getRegisteredPlaceholders(Plugin plugin); + public abstract Collection getRegisteredPlaceholders(Plugin plugin); - public abstract boolean unregisterPlaceholder(Plugin plugin, String textPlaceholder); + public abstract boolean unregisterPlaceholder(Plugin plugin, String textPlaceholder); - public abstract void unregisterPlaceholders(Plugin plugin); + public abstract void unregisterPlaceholders(Plugin plugin); - public abstract boolean isHologramEntity(Entity bukkitEntity); - + public abstract boolean isHologramEntity(Entity bukkitEntity); + } diff --git a/api/src/main/java/me/filoghost/holographicdisplays/api/line/CollectableLine.java b/api/src/main/java/me/filoghost/holographicdisplays/api/line/CollectableLine.java index f7f93e02..2b1abf6b 100644 --- a/api/src/main/java/me/filoghost/holographicdisplays/api/line/CollectableLine.java +++ b/api/src/main/java/me/filoghost/holographicdisplays/api/line/CollectableLine.java @@ -20,19 +20,19 @@ import me.filoghost.holographicdisplays.api.handler.PickupHandler; * A line of a Hologram that can be picked up. */ public interface CollectableLine extends HologramLine { - - /** - * Sets the PickupHandler for this line. - * - * @param pickupHandler the new PickupHandler, can be null. - */ - public void setPickupHandler(PickupHandler pickupHandler); - - /** - * Returns the current PickupHandler of this line. - * - * @return the current PickupHandler, can be null. - */ - public PickupHandler getPickupHandler(); - + + /** + * Sets the PickupHandler for this line. + * + * @param pickupHandler the new PickupHandler, can be null. + */ + public void setPickupHandler(PickupHandler pickupHandler); + + /** + * Returns the current PickupHandler of this line. + * + * @return the current PickupHandler, can be null. + */ + public PickupHandler getPickupHandler(); + } diff --git a/api/src/main/java/me/filoghost/holographicdisplays/api/line/HologramLine.java b/api/src/main/java/me/filoghost/holographicdisplays/api/line/HologramLine.java index bb936cf5..c51f58d3 100644 --- a/api/src/main/java/me/filoghost/holographicdisplays/api/line/HologramLine.java +++ b/api/src/main/java/me/filoghost/holographicdisplays/api/line/HologramLine.java @@ -20,18 +20,18 @@ import me.filoghost.holographicdisplays.api.Hologram; * Interface to represent a line in a Hologram. */ public interface HologramLine { - - /** - * Returns the parent Hologram of this line. - * - * @return the parent Hologram. - */ - public Hologram getParent(); - - /** - * Removes this line from the parent Hologram. Since: v2.0.1 - * Do not call if the Hologram has been deleted, an exception will be thrown. - */ - public void removeLine(); + + /** + * Returns the parent Hologram of this line. + * + * @return the parent Hologram. + */ + public Hologram getParent(); + + /** + * Removes this line from the parent Hologram. Since: v2.0.1 + * Do not call if the Hologram has been deleted, an exception will be thrown. + */ + public void removeLine(); } diff --git a/api/src/main/java/me/filoghost/holographicdisplays/api/line/ItemLine.java b/api/src/main/java/me/filoghost/holographicdisplays/api/line/ItemLine.java index ac1db58f..08abbd21 100644 --- a/api/src/main/java/me/filoghost/holographicdisplays/api/line/ItemLine.java +++ b/api/src/main/java/me/filoghost/holographicdisplays/api/line/ItemLine.java @@ -18,18 +18,18 @@ import org.bukkit.inventory.ItemStack; public interface ItemLine extends CollectableLine, TouchableLine { - /** - * Returns the ItemStack of this ItemLine. - * - * @return the ItemStack if this ItemLine. - */ - public ItemStack getItemStack(); + /** + * Returns the ItemStack of this ItemLine. + * + * @return the ItemStack if this ItemLine. + */ + public ItemStack getItemStack(); - /** - * Sets the ItemStack for this ItemLine. - * - * @param itemStack the new item, should not be null. - */ - public void setItemStack(ItemStack itemStack); - + /** + * Sets the ItemStack for this ItemLine. + * + * @param itemStack the new item, should not be null. + */ + public void setItemStack(ItemStack itemStack); + } diff --git a/api/src/main/java/me/filoghost/holographicdisplays/api/line/TextLine.java b/api/src/main/java/me/filoghost/holographicdisplays/api/line/TextLine.java index a0da2015..10c48118 100644 --- a/api/src/main/java/me/filoghost/holographicdisplays/api/line/TextLine.java +++ b/api/src/main/java/me/filoghost/holographicdisplays/api/line/TextLine.java @@ -16,18 +16,18 @@ package me.filoghost.holographicdisplays.api.line; public interface TextLine extends TouchableLine { - /** - * Returns the current text of this TextLine. - * - * @return the current text of this line. - */ - public String getText(); - - /** - * Sets the text of this TextLine. - * - * @param text the new text of this line. - */ - public void setText(String text); - + /** + * Returns the current text of this TextLine. + * + * @return the current text of this line. + */ + public String getText(); + + /** + * Sets the text of this TextLine. + * + * @param text the new text of this line. + */ + public void setText(String text); + } diff --git a/api/src/main/java/me/filoghost/holographicdisplays/api/line/TouchableLine.java b/api/src/main/java/me/filoghost/holographicdisplays/api/line/TouchableLine.java index 085c6bc0..a3518c2b 100644 --- a/api/src/main/java/me/filoghost/holographicdisplays/api/line/TouchableLine.java +++ b/api/src/main/java/me/filoghost/holographicdisplays/api/line/TouchableLine.java @@ -21,18 +21,18 @@ import me.filoghost.holographicdisplays.api.handler.TouchHandler; */ public interface TouchableLine extends HologramLine { - /** - * Sets the TouchHandler for this line. - * - * @param touchHandler the new TouchHandler, can be null. - */ - public void setTouchHandler(TouchHandler touchHandler); - - /** - * Returns the current TouchHandler of this line. - * - * @return the current TouchHandler, can be null. - */ - public TouchHandler getTouchHandler(); - + /** + * Sets the TouchHandler for this line. + * + * @param touchHandler the new TouchHandler, can be null. + */ + public void setTouchHandler(TouchHandler touchHandler); + + /** + * Returns the current TouchHandler of this line. + * + * @return the current TouchHandler, can be null. + */ + public TouchHandler getTouchHandler(); + } diff --git a/api/src/main/java/me/filoghost/holographicdisplays/api/placeholder/PlaceholderReplacer.java b/api/src/main/java/me/filoghost/holographicdisplays/api/placeholder/PlaceholderReplacer.java index 2c16b150..0d7e9b7d 100644 --- a/api/src/main/java/me/filoghost/holographicdisplays/api/placeholder/PlaceholderReplacer.java +++ b/api/src/main/java/me/filoghost/holographicdisplays/api/placeholder/PlaceholderReplacer.java @@ -16,10 +16,10 @@ package me.filoghost.holographicdisplays.api.placeholder; public interface PlaceholderReplacer { - /** - * Called to update a placeholder's replacement. - * @return the replacement - */ - public String update(); - + /** + * Called to update a placeholder's replacement. + * @return the replacement + */ + public String update(); + } diff --git a/config/pom.xml b/config/pom.xml index 274df788..4a47dfb3 100644 --- a/config/pom.xml +++ b/config/pom.xml @@ -1,34 +1,34 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - - me.filoghost.holographicdisplays - holographicdisplays-parent - 3.0.0-SNAPSHOT - + + me.filoghost.holographicdisplays + holographicdisplays-parent + 3.0.0-SNAPSHOT + - holographicdisplays-config - HolographicDisplays Config + holographicdisplays-config + HolographicDisplays Config - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + - - - ${project.groupId} - holographicdisplays-utils - + + + ${project.groupId} + holographicdisplays-utils + - - org.spigotmc - spigot-api - - + + org.spigotmc + spigot-api + + diff --git a/config/src/main/java/me/filoghost/holographicdisplays/disk/ConfigNode.java b/config/src/main/java/me/filoghost/holographicdisplays/disk/ConfigNode.java index 33eeca56..a7b3620e 100644 --- a/config/src/main/java/me/filoghost/holographicdisplays/disk/ConfigNode.java +++ b/config/src/main/java/me/filoghost/holographicdisplays/disk/ConfigNode.java @@ -18,39 +18,39 @@ import java.util.Arrays; public enum ConfigNode { - SPACE_BETWEEN_LINES("space-between-lines", 0.02), - QUICK_EDIT_COMMANDS("quick-edit-commands", true), - IMAGES_SYMBOL("images.symbol", "[x]"), - TRANSPARENCY_SPACE("images.transparency.space", " [|] "), - TRANSPARENCY_COLOR("images.transparency.color", "&7"), - UPDATE_NOTIFICATION("update-notification", true), - BUNGEE_REFRESH_SECONDS("bungee.refresh-seconds", 3), - BUNGEE_USE_REDIS_BUNGEE("bungee.use-RedisBungee", false), - BUNGEE_USE_FULL_PINGER("bungee.pinger.enable", false), - BUNGEE_PINGER_TIMEOUT("bungee.pinger.timeout", 500), - BUNGEE_PINGER_OFFLINE_MOTD("bungee.pinger.offline-motd", "&cOffline, couldn't get the MOTD."), - BUNGEE_PINGER_ONLINE_FORMAT("bungee.pinger.status.online", "&aOnline"), - BUNGEE_PINGER_OFFLINE_FORMAT("bungee.pinger.status.offline", "&cOffline"), - BUNGEE_PINGER_TRIM_MOTD("bungee.pinger.motd-remove-leading-trailing-spaces", true), - BUNGEE_PINGER_SERVERS("bungee.pinger.servers", Arrays.asList("hub: 127.0.0.1:25565", "survival: 127.0.0.1:25566", "minigames: 127.0.0.1:25567")), - TIME_FORMAT("time.format", "H:mm"), - TIME_ZONE("time.zone", "GMT+1"), - DEBUG("debug", false); - - private final String path; - private final Object value; - - private ConfigNode(String path, Object defaultValue) { - this.path = path; - value = defaultValue; - } - - public String getPath() { - return path; - } - - public Object getDefaultValue() { - return value; - } - + SPACE_BETWEEN_LINES("space-between-lines", 0.02), + QUICK_EDIT_COMMANDS("quick-edit-commands", true), + IMAGES_SYMBOL("images.symbol", "[x]"), + TRANSPARENCY_SPACE("images.transparency.space", " [|] "), + TRANSPARENCY_COLOR("images.transparency.color", "&7"), + UPDATE_NOTIFICATION("update-notification", true), + BUNGEE_REFRESH_SECONDS("bungee.refresh-seconds", 3), + BUNGEE_USE_REDIS_BUNGEE("bungee.use-RedisBungee", false), + BUNGEE_USE_FULL_PINGER("bungee.pinger.enable", false), + BUNGEE_PINGER_TIMEOUT("bungee.pinger.timeout", 500), + BUNGEE_PINGER_OFFLINE_MOTD("bungee.pinger.offline-motd", "&cOffline, couldn't get the MOTD."), + BUNGEE_PINGER_ONLINE_FORMAT("bungee.pinger.status.online", "&aOnline"), + BUNGEE_PINGER_OFFLINE_FORMAT("bungee.pinger.status.offline", "&cOffline"), + BUNGEE_PINGER_TRIM_MOTD("bungee.pinger.motd-remove-leading-trailing-spaces", true), + BUNGEE_PINGER_SERVERS("bungee.pinger.servers", Arrays.asList("hub: 127.0.0.1:25565", "survival: 127.0.0.1:25566", "minigames: 127.0.0.1:25567")), + TIME_FORMAT("time.format", "H:mm"), + TIME_ZONE("time.zone", "GMT+1"), + DEBUG("debug", false); + + private final String path; + private final Object value; + + private ConfigNode(String path, Object defaultValue) { + this.path = path; + value = defaultValue; + } + + public String getPath() { + return path; + } + + public Object getDefaultValue() { + return value; + } + } diff --git a/config/src/main/java/me/filoghost/holographicdisplays/disk/Configuration.java b/config/src/main/java/me/filoghost/holographicdisplays/disk/Configuration.java index 0749def7..b2025c8f 100644 --- a/config/src/main/java/me/filoghost/holographicdisplays/disk/Configuration.java +++ b/config/src/main/java/me/filoghost/holographicdisplays/disk/Configuration.java @@ -35,186 +35,186 @@ import java.util.logging.Level; * Useful for fast access. */ public class Configuration { - - public static double spaceBetweenLines; - public static boolean quickEditCommands; - public static String imageSymbol; - public static String transparencySymbol; - public static boolean updateNotification; - public static ChatColor transparencyColor; - - public static SimpleDateFormat timeFormat; - - public static int bungeeRefreshSeconds; - public static boolean useRedisBungee; - - public static boolean pingerEnable; - public static int pingerTimeout; - public static String pingerOfflineMotd; - public static String pingerStatusOnline; - public static String pingerStatusOffline; - public static boolean pingerTrimMotd; - public static Map pingerServers; + + public static double spaceBetweenLines; + public static boolean quickEditCommands; + public static String imageSymbol; + public static String transparencySymbol; + public static boolean updateNotification; + public static ChatColor transparencyColor; + + public static SimpleDateFormat timeFormat; + + public static int bungeeRefreshSeconds; + public static boolean useRedisBungee; + + public static boolean pingerEnable; + public static int pingerTimeout; + public static String pingerOfflineMotd; + public static String pingerStatusOnline; + public static String pingerStatusOffline; + public static boolean pingerTrimMotd; + public static Map pingerServers; - - public static void load(Plugin plugin) { - File configFile = new File(plugin.getDataFolder(), "config.yml"); - if (!configFile.exists()) { - plugin.getDataFolder().mkdirs(); - plugin.saveResource("config.yml", true); - } - - YamlConfiguration config = new YamlConfiguration(); - try { - config.load(configFile); - } catch (InvalidConfigurationException e) { - e.printStackTrace(); - ConsoleLogger.log(Level.WARNING, "The configuration is not a valid YAML file! Please check it with a tool like http://yaml-online-parser.appspot.com/"); - return; - } catch (IOException e) { - e.printStackTrace(); - ConsoleLogger.log(Level.WARNING, "I/O error while reading the configuration. Was the file in use?"); - return; - } catch (Exception e) { - e.printStackTrace(); - ConsoleLogger.log(Level.WARNING, "Unhandled exception while reading the configuration!"); - return; - } - - boolean needsSave = false; - - for (ConfigNode node : ConfigNode.values()) { - if (!config.isSet(node.getPath())) { - needsSave = true; - config.set(node.getPath(), node.getDefaultValue()); - } - } - - // Check the old values. - List nodesToRemove = Arrays.asList( - "vertical-spacing", - "time-format", - "bungee-refresh-seconds", - "using-RedisBungee", - "bungee-online-format", - "bungee-offline-format", - "precise-hologram-movement" - ); + + public static void load(Plugin plugin) { + File configFile = new File(plugin.getDataFolder(), "config.yml"); + if (!configFile.exists()) { + plugin.getDataFolder().mkdirs(); + plugin.saveResource("config.yml", true); + } + + YamlConfiguration config = new YamlConfiguration(); + try { + config.load(configFile); + } catch (InvalidConfigurationException e) { + e.printStackTrace(); + ConsoleLogger.log(Level.WARNING, "The configuration is not a valid YAML file! Please check it with a tool like http://yaml-online-parser.appspot.com/"); + return; + } catch (IOException e) { + e.printStackTrace(); + ConsoleLogger.log(Level.WARNING, "I/O error while reading the configuration. Was the file in use?"); + return; + } catch (Exception e) { + e.printStackTrace(); + ConsoleLogger.log(Level.WARNING, "Unhandled exception while reading the configuration!"); + return; + } + + boolean needsSave = false; + + for (ConfigNode node : ConfigNode.values()) { + if (!config.isSet(node.getPath())) { + needsSave = true; + config.set(node.getPath(), node.getDefaultValue()); + } + } + + // Check the old values. + List nodesToRemove = Arrays.asList( + "vertical-spacing", + "time-format", + "bungee-refresh-seconds", + "using-RedisBungee", + "bungee-online-format", + "bungee-offline-format", + "precise-hologram-movement" + ); - for (String oldNode : nodesToRemove) { - if (config.isSet(oldNode)) { - config.set(oldNode, null); - needsSave = true; - } - } - - - - if (needsSave) { - config.options().header(String.join("\n", - ".", - ". Read the tutorial at: http://dev.bukkit.org/bukkit-plugins/holographic-displays/", - ".", - ". Plugin created by filoghost.", - ".")); - config.options().copyHeader(true); - try { - config.save(configFile); - } catch (IOException e) { - e.printStackTrace(); - ConsoleLogger.log(Level.WARNING, "I/O error while saving the configuration. Was the file in use?"); - } - } - - spaceBetweenLines = config.getDouble(ConfigNode.SPACE_BETWEEN_LINES.getPath()); - quickEditCommands = config.getBoolean(ConfigNode.QUICK_EDIT_COMMANDS.getPath()); - - updateNotification = config.getBoolean(ConfigNode.UPDATE_NOTIFICATION.getPath()); - - imageSymbol = StringConverter.toReadableFormat(config.getString(ConfigNode.IMAGES_SYMBOL.getPath())); - transparencySymbol = StringConverter.toReadableFormat(config.getString(ConfigNode.TRANSPARENCY_SPACE.getPath())); - bungeeRefreshSeconds = config.getInt(ConfigNode.BUNGEE_REFRESH_SECONDS.getPath()); - useRedisBungee = config.getBoolean(ConfigNode.BUNGEE_USE_REDIS_BUNGEE.getPath()); - - pingerEnable = config.getBoolean(ConfigNode.BUNGEE_USE_FULL_PINGER.getPath()); - pingerTimeout = config.getInt(ConfigNode.BUNGEE_PINGER_TIMEOUT.getPath()); - pingerTrimMotd = config.getBoolean(ConfigNode.BUNGEE_PINGER_TRIM_MOTD.getPath()); - - pingerOfflineMotd = StringConverter.toReadableFormat(config.getString(ConfigNode.BUNGEE_PINGER_OFFLINE_MOTD.getPath())); - pingerStatusOnline = StringConverter.toReadableFormat(config.getString(ConfigNode.BUNGEE_PINGER_ONLINE_FORMAT.getPath())); - pingerStatusOffline = StringConverter.toReadableFormat(config.getString(ConfigNode.BUNGEE_PINGER_OFFLINE_FORMAT.getPath())); - - if (pingerTimeout <= 0) { - pingerTimeout = 100; - } else if (pingerTimeout >= 10000) { - pingerTimeout = 10000; - } - - pingerServers = new HashMap<>(); - - if (pingerEnable) { - for (String singleServer : config.getStringList(ConfigNode.BUNGEE_PINGER_SERVERS.getPath())) { - String[] nameAndAddress = singleServer.split(":", 2); - if (nameAndAddress.length < 2) { - ConsoleLogger.log(Level.WARNING, "The server info \"" + singleServer + "\" is not valid. There should be a name and an address, separated by a colon."); - continue; - } - - String name = nameAndAddress[0].trim(); - String address = nameAndAddress[1].replace(" ", ""); - - String ip; - int port; - - if (address.contains(":")) { - String[] ipAndPort = address.split(":", 2); - ip = ipAndPort[0]; - try { - port = Integer.parseInt(ipAndPort[1]); - } catch (NumberFormatException e) { - ConsoleLogger.log(Level.WARNING, "Invalid port number in the server info \"" + singleServer + "\"."); - continue; - } - } else { - ip = address; - port = 25565; // The default Minecraft port. - } - - pingerServers.put(name, new ServerAddress(ip, port)); - } - } - - ConsoleLogger.setDebugEnabled(config.getBoolean(ConfigNode.DEBUG.getPath())); - - String tempColor = config.getString(ConfigNode.TRANSPARENCY_COLOR.getPath()).replace('&', ChatColor.COLOR_CHAR); - boolean foundColor = false; - for (ChatColor chatColor : ChatColor.values()) { - if (chatColor.toString().equals(tempColor)) { - Configuration.transparencyColor = chatColor; - foundColor = true; - } - } - if (!foundColor) { - Configuration.transparencyColor = ChatColor.GRAY; - ConsoleLogger.log(Level.WARNING, "You didn't set a valid chat color for transparency in the configuration, light gray (&7) will be used."); - } - - try { - timeFormat = new SimpleDateFormat(config.getString(ConfigNode.TIME_FORMAT.getPath())); - timeFormat.setTimeZone(TimeZone.getTimeZone(config.getString(ConfigNode.TIME_ZONE.getPath()))); - } catch (IllegalArgumentException ex) { - timeFormat = new SimpleDateFormat("H:mm"); - ConsoleLogger.log(Level.WARNING, "Time format not valid in the configuration, using the default."); - } - - if (bungeeRefreshSeconds < 1) { - ConsoleLogger.log(Level.WARNING, "The minimum interval for pinging BungeeCord's servers is 1 second. It has been automatically set."); - bungeeRefreshSeconds = 1; - } - - if (bungeeRefreshSeconds > 60) { - ConsoleLogger.log(Level.WARNING, "The maximum interval for pinging BungeeCord's servers is 60 seconds. It has been automatically set."); - bungeeRefreshSeconds = 60; - } - } + for (String oldNode : nodesToRemove) { + if (config.isSet(oldNode)) { + config.set(oldNode, null); + needsSave = true; + } + } + + + + if (needsSave) { + config.options().header(String.join("\n", + ".", + ". Read the tutorial at: http://dev.bukkit.org/bukkit-plugins/holographic-displays/", + ".", + ". Plugin created by filoghost.", + ".")); + config.options().copyHeader(true); + try { + config.save(configFile); + } catch (IOException e) { + e.printStackTrace(); + ConsoleLogger.log(Level.WARNING, "I/O error while saving the configuration. Was the file in use?"); + } + } + + spaceBetweenLines = config.getDouble(ConfigNode.SPACE_BETWEEN_LINES.getPath()); + quickEditCommands = config.getBoolean(ConfigNode.QUICK_EDIT_COMMANDS.getPath()); + + updateNotification = config.getBoolean(ConfigNode.UPDATE_NOTIFICATION.getPath()); + + imageSymbol = StringConverter.toReadableFormat(config.getString(ConfigNode.IMAGES_SYMBOL.getPath())); + transparencySymbol = StringConverter.toReadableFormat(config.getString(ConfigNode.TRANSPARENCY_SPACE.getPath())); + bungeeRefreshSeconds = config.getInt(ConfigNode.BUNGEE_REFRESH_SECONDS.getPath()); + useRedisBungee = config.getBoolean(ConfigNode.BUNGEE_USE_REDIS_BUNGEE.getPath()); + + pingerEnable = config.getBoolean(ConfigNode.BUNGEE_USE_FULL_PINGER.getPath()); + pingerTimeout = config.getInt(ConfigNode.BUNGEE_PINGER_TIMEOUT.getPath()); + pingerTrimMotd = config.getBoolean(ConfigNode.BUNGEE_PINGER_TRIM_MOTD.getPath()); + + pingerOfflineMotd = StringConverter.toReadableFormat(config.getString(ConfigNode.BUNGEE_PINGER_OFFLINE_MOTD.getPath())); + pingerStatusOnline = StringConverter.toReadableFormat(config.getString(ConfigNode.BUNGEE_PINGER_ONLINE_FORMAT.getPath())); + pingerStatusOffline = StringConverter.toReadableFormat(config.getString(ConfigNode.BUNGEE_PINGER_OFFLINE_FORMAT.getPath())); + + if (pingerTimeout <= 0) { + pingerTimeout = 100; + } else if (pingerTimeout >= 10000) { + pingerTimeout = 10000; + } + + pingerServers = new HashMap<>(); + + if (pingerEnable) { + for (String singleServer : config.getStringList(ConfigNode.BUNGEE_PINGER_SERVERS.getPath())) { + String[] nameAndAddress = singleServer.split(":", 2); + if (nameAndAddress.length < 2) { + ConsoleLogger.log(Level.WARNING, "The server info \"" + singleServer + "\" is not valid. There should be a name and an address, separated by a colon."); + continue; + } + + String name = nameAndAddress[0].trim(); + String address = nameAndAddress[1].replace(" ", ""); + + String ip; + int port; + + if (address.contains(":")) { + String[] ipAndPort = address.split(":", 2); + ip = ipAndPort[0]; + try { + port = Integer.parseInt(ipAndPort[1]); + } catch (NumberFormatException e) { + ConsoleLogger.log(Level.WARNING, "Invalid port number in the server info \"" + singleServer + "\"."); + continue; + } + } else { + ip = address; + port = 25565; // The default Minecraft port. + } + + pingerServers.put(name, new ServerAddress(ip, port)); + } + } + + ConsoleLogger.setDebugEnabled(config.getBoolean(ConfigNode.DEBUG.getPath())); + + String tempColor = config.getString(ConfigNode.TRANSPARENCY_COLOR.getPath()).replace('&', ChatColor.COLOR_CHAR); + boolean foundColor = false; + for (ChatColor chatColor : ChatColor.values()) { + if (chatColor.toString().equals(tempColor)) { + Configuration.transparencyColor = chatColor; + foundColor = true; + } + } + if (!foundColor) { + Configuration.transparencyColor = ChatColor.GRAY; + ConsoleLogger.log(Level.WARNING, "You didn't set a valid chat color for transparency in the configuration, light gray (&7) will be used."); + } + + try { + timeFormat = new SimpleDateFormat(config.getString(ConfigNode.TIME_FORMAT.getPath())); + timeFormat.setTimeZone(TimeZone.getTimeZone(config.getString(ConfigNode.TIME_ZONE.getPath()))); + } catch (IllegalArgumentException ex) { + timeFormat = new SimpleDateFormat("H:mm"); + ConsoleLogger.log(Level.WARNING, "Time format not valid in the configuration, using the default."); + } + + if (bungeeRefreshSeconds < 1) { + ConsoleLogger.log(Level.WARNING, "The minimum interval for pinging BungeeCord's servers is 1 second. It has been automatically set."); + bungeeRefreshSeconds = 1; + } + + if (bungeeRefreshSeconds > 60) { + ConsoleLogger.log(Level.WARNING, "The maximum interval for pinging BungeeCord's servers is 60 seconds. It has been automatically set."); + bungeeRefreshSeconds = 60; + } + } } diff --git a/config/src/main/java/me/filoghost/holographicdisplays/disk/LocationSerializer.java b/config/src/main/java/me/filoghost/holographicdisplays/disk/LocationSerializer.java index 6e37bc48..b09835e0 100644 --- a/config/src/main/java/me/filoghost/holographicdisplays/disk/LocationSerializer.java +++ b/config/src/main/java/me/filoghost/holographicdisplays/disk/LocationSerializer.java @@ -25,38 +25,38 @@ import java.text.DecimalFormatSymbols; import java.util.Locale; public class LocationSerializer { - - private static DecimalFormat numberFormat = new DecimalFormat("0.000", DecimalFormatSymbols.getInstance(Locale.ROOT)); + + private static DecimalFormat numberFormat = new DecimalFormat("0.000", DecimalFormatSymbols.getInstance(Locale.ROOT)); - public static Location locationFromString(String input) throws WorldNotFoundException, InvalidFormatException { - if (input == null) { - throw new InvalidFormatException(); - } - - String[] parts = input.split(","); - - if (parts.length != 4) { - throw new InvalidFormatException(); - } - - try { - double x = Double.parseDouble(parts[1].replace(" ", "")); - double y = Double.parseDouble(parts[2].replace(" ", "")); - double z = Double.parseDouble(parts[3].replace(" ", "")); - - World world = Bukkit.getWorld(parts[0].trim()); - if (world == null) { - throw new WorldNotFoundException(parts[0].trim()); - } - - return new Location(world, x, y, z); - - } catch (NumberFormatException ex) { - throw new InvalidFormatException(); - } - } - - public static String locationToString(Location loc) { - return (loc.getWorld().getName() + ", " + numberFormat.format(loc.getX()) + ", " + numberFormat.format(loc.getY()) + ", " + numberFormat.format(loc.getZ())); - } + public static Location locationFromString(String input) throws WorldNotFoundException, InvalidFormatException { + if (input == null) { + throw new InvalidFormatException(); + } + + String[] parts = input.split(","); + + if (parts.length != 4) { + throw new InvalidFormatException(); + } + + try { + double x = Double.parseDouble(parts[1].replace(" ", "")); + double y = Double.parseDouble(parts[2].replace(" ", "")); + double z = Double.parseDouble(parts[3].replace(" ", "")); + + World world = Bukkit.getWorld(parts[0].trim()); + if (world == null) { + throw new WorldNotFoundException(parts[0].trim()); + } + + return new Location(world, x, y, z); + + } catch (NumberFormatException ex) { + throw new InvalidFormatException(); + } + } + + public static String locationToString(Location loc) { + return (loc.getWorld().getName() + ", " + numberFormat.format(loc.getX()) + ", " + numberFormat.format(loc.getY()) + ", " + numberFormat.format(loc.getZ())); + } } diff --git a/config/src/main/java/me/filoghost/holographicdisplays/disk/ServerAddress.java b/config/src/main/java/me/filoghost/holographicdisplays/disk/ServerAddress.java index 9e42f88d..37dbea76 100644 --- a/config/src/main/java/me/filoghost/holographicdisplays/disk/ServerAddress.java +++ b/config/src/main/java/me/filoghost/holographicdisplays/disk/ServerAddress.java @@ -15,26 +15,26 @@ package me.filoghost.holographicdisplays.disk; public class ServerAddress { - - private String ip; - private int port; - - public ServerAddress(String ip, int port) { - this.ip = ip; - this.port = port; - } + + private String ip; + private int port; + + public ServerAddress(String ip, int port) { + this.ip = ip; + this.port = port; + } - public String getAddress() { - return ip; - } + public String getAddress() { + return ip; + } - public int getPort() { - return port; - } + public int getPort() { + return port; + } - @Override - public String toString() { - return ip + ":" + port; - } - + @Override + public String toString() { + return ip + ":" + port; + } + } diff --git a/config/src/main/java/me/filoghost/holographicdisplays/disk/StringConverter.java b/config/src/main/java/me/filoghost/holographicdisplays/disk/StringConverter.java index 7c914193..a4998ebf 100644 --- a/config/src/main/java/me/filoghost/holographicdisplays/disk/StringConverter.java +++ b/config/src/main/java/me/filoghost/holographicdisplays/disk/StringConverter.java @@ -19,80 +19,80 @@ import org.bukkit.ChatColor; public class StringConverter { - private static final boolean HEX_CHAT_COLORS_ENABLED = Utils.classExists("org.bukkit.entity.Strider"); - private static final int HEX_COLOR_LENGTH = 6; + private static final boolean HEX_CHAT_COLORS_ENABLED = Utils.classExists("org.bukkit.entity.Strider"); + private static final int HEX_COLOR_LENGTH = 6; - public static String toReadableFormat(String input) { - if (input == null) { - return null; - } + public static String toReadableFormat(String input) { + if (input == null) { + return null; + } - input = UnicodeSymbols.placeholdersToSymbols(input); - input = addColors(input); - return input; - } + input = UnicodeSymbols.placeholdersToSymbols(input); + input = addColors(input); + return input; + } - public static String addColors(String input) { - if (!input.contains("&")) { - return input; - } + public static String addColors(String input) { + if (!input.contains("&")) { + return input; + } - StringBuilder output = new StringBuilder(input.length()); + StringBuilder output = new StringBuilder(input.length()); - for (int i = 0; i < input.length(); i++) { - char current = input.charAt(i); + for (int i = 0; i < input.length(); i++) { + char current = input.charAt(i); - if (current == '&' && i + 1 < input.length()) { - char next = input.charAt(i + 1); + if (current == '&' && i + 1 < input.length()) { + char next = input.charAt(i + 1); - if (next == '#' && HEX_CHAT_COLORS_ENABLED && isValidHexColor(input, i + 2)) { - output.append(ChatColor.COLOR_CHAR); - output.append('x'); + if (next == '#' && HEX_CHAT_COLORS_ENABLED && isValidHexColor(input, i + 2)) { + output.append(ChatColor.COLOR_CHAR); + output.append('x'); - for (int j = 0; j < HEX_COLOR_LENGTH; j++) { - output.append(ChatColor.COLOR_CHAR); - output.append(Character.toLowerCase(input.charAt(i + 2 + j))); - } + for (int j = 0; j < HEX_COLOR_LENGTH; j++) { + output.append(ChatColor.COLOR_CHAR); + output.append(Character.toLowerCase(input.charAt(i + 2 + j))); + } - i += 1 + HEX_COLOR_LENGTH; // Skip '#' and hex string, which are already converted and added + i += 1 + HEX_COLOR_LENGTH; // Skip '#' and hex string, which are already converted and added - } else if (isColorCode(next)) { - output.append(ChatColor.COLOR_CHAR); - output.append(Character.toLowerCase(next)); + } else if (isColorCode(next)) { + output.append(ChatColor.COLOR_CHAR); + output.append(Character.toLowerCase(next)); - i++; // Skip next character, which is already added + i++; // Skip next character, which is already added - } else { - output.append(current); - } - } else { - output.append(current); - } - } + } else { + output.append(current); + } + } else { + output.append(current); + } + } - return output.toString(); - } + return output.toString(); + } - private static boolean isValidHexColor(String input, int startIndex) { - if (input.length() - startIndex < HEX_COLOR_LENGTH) { - return false; - } + private static boolean isValidHexColor(String input, int startIndex) { + if (input.length() - startIndex < HEX_COLOR_LENGTH) { + return false; + } - for (int i = 0; i < HEX_COLOR_LENGTH; i++) { - if (!isHexCode(input.charAt(startIndex + i))) { - return false; - } - } + for (int i = 0; i < HEX_COLOR_LENGTH; i++) { + if (!isHexCode(input.charAt(startIndex + i))) { + return false; + } + } - return true; - } + return true; + } - private static boolean isHexCode(char c) { - return "0123456789AaBbCcDdEeFf".indexOf(c) > -1; - } + private static boolean isHexCode(char c) { + return "0123456789AaBbCcDdEeFf".indexOf(c) > -1; + } - private static boolean isColorCode(char c) { - return "0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf(c) > -1; - } - + private static boolean isColorCode(char c) { + return "0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf(c) > -1; + } + } diff --git a/config/src/main/java/me/filoghost/holographicdisplays/disk/UnicodeSymbols.java b/config/src/main/java/me/filoghost/holographicdisplays/disk/UnicodeSymbols.java index 12df4e8c..8cc04055 100644 --- a/config/src/main/java/me/filoghost/holographicdisplays/disk/UnicodeSymbols.java +++ b/config/src/main/java/me/filoghost/holographicdisplays/disk/UnicodeSymbols.java @@ -29,79 +29,79 @@ import java.util.logging.Level; public class UnicodeSymbols { - private static Map placeholders = new HashMap<>(); - - public static void load(Plugin plugin) { - placeholders.clear(); - - File file = new File(plugin.getDataFolder(), "symbols.yml"); - - if (!file.exists()) { - plugin.getDataFolder().mkdirs(); - plugin.saveResource("symbols.yml", true); - } - - List lines; - try { - lines = FileUtils.readLines(file); - } catch (IOException e) { - ConsoleLogger.log(Level.WARNING, "I/O error while reading symbols.yml. Was the file in use?", e); - return; - } catch (Exception e) { - ConsoleLogger.log(Level.WARNING, "Unhandled exception while reading symbols.yml!", e); - return; - } - - for (String line : lines) { - - // Comment or empty line. - if (line.length() == 0 || line.startsWith("#")) { - continue; - } - - if (!line.contains(":")) { - ConsoleLogger.log(Level.WARNING, "Unable to parse a line(" + line + ") from symbols.yml: it must contain ':' to separate the placeholder and the replacement."); - continue; - } - - int indexOf = line.indexOf(':'); - String placeholder = unquote(line.substring(0, indexOf).trim()); - String replacement = StringEscapeUtils.unescapeJava(unquote(line.substring(indexOf + 1, line.length()).trim())); + private static Map placeholders = new HashMap<>(); + + public static void load(Plugin plugin) { + placeholders.clear(); + + File file = new File(plugin.getDataFolder(), "symbols.yml"); + + if (!file.exists()) { + plugin.getDataFolder().mkdirs(); + plugin.saveResource("symbols.yml", true); + } + + List lines; + try { + lines = FileUtils.readLines(file); + } catch (IOException e) { + ConsoleLogger.log(Level.WARNING, "I/O error while reading symbols.yml. Was the file in use?", e); + return; + } catch (Exception e) { + ConsoleLogger.log(Level.WARNING, "Unhandled exception while reading symbols.yml!", e); + return; + } + + for (String line : lines) { + + // Comment or empty line. + if (line.length() == 0 || line.startsWith("#")) { + continue; + } + + if (!line.contains(":")) { + ConsoleLogger.log(Level.WARNING, "Unable to parse a line(" + line + ") from symbols.yml: it must contain ':' to separate the placeholder and the replacement."); + continue; + } + + int indexOf = line.indexOf(':'); + String placeholder = unquote(line.substring(0, indexOf).trim()); + String replacement = StringEscapeUtils.unescapeJava(unquote(line.substring(indexOf + 1, line.length()).trim())); - if (placeholder.isEmpty() || replacement.isEmpty()) { - ConsoleLogger.log(Level.WARNING, "Unable to parse a line(" + line + ") from symbols.yml: the placeholder and the replacement must have both at least 1 character."); - continue; - } - - if (placeholder.length() > 30) { - ConsoleLogger.log(Level.WARNING, "Unable to parse a line(" + line + ") from symbols.yml: the placeholder cannot be longer than 30 characters."); - continue; - } - - placeholders.put(placeholder, replacement); - } - } - - - protected static String placeholdersToSymbols(String input) { - for (Entry entry : placeholders.entrySet()) { - input = input.replace(entry.getKey(), entry.getValue()); - } - return input; - } - - - private static String unquote(String input) { - if (input.length() < 2) { - // Cannot be quoted. - return input; - } - if (input.startsWith("'") && input.endsWith("'")) { - return input.substring(1, input.length() - 1); - } else if (input.startsWith("\"") && input.endsWith("\"")) { - return input.substring(1, input.length() - 1); - } - - return input; - } + if (placeholder.isEmpty() || replacement.isEmpty()) { + ConsoleLogger.log(Level.WARNING, "Unable to parse a line(" + line + ") from symbols.yml: the placeholder and the replacement must have both at least 1 character."); + continue; + } + + if (placeholder.length() > 30) { + ConsoleLogger.log(Level.WARNING, "Unable to parse a line(" + line + ") from symbols.yml: the placeholder cannot be longer than 30 characters."); + continue; + } + + placeholders.put(placeholder, replacement); + } + } + + + protected static String placeholdersToSymbols(String input) { + for (Entry entry : placeholders.entrySet()) { + input = input.replace(entry.getKey(), entry.getValue()); + } + return input; + } + + + private static String unquote(String input) { + if (input.length() < 2) { + // Cannot be quoted. + return input; + } + if (input.startsWith("'") && input.endsWith("'")) { + return input.substring(1, input.length() - 1); + } else if (input.startsWith("\"") && input.endsWith("\"")) { + return input.substring(1, input.length() - 1); + } + + return input; + } } diff --git a/config/src/main/java/me/filoghost/holographicdisplays/exception/InvalidFormatException.java b/config/src/main/java/me/filoghost/holographicdisplays/exception/InvalidFormatException.java index d03f9908..85ff0df5 100644 --- a/config/src/main/java/me/filoghost/holographicdisplays/exception/InvalidFormatException.java +++ b/config/src/main/java/me/filoghost/holographicdisplays/exception/InvalidFormatException.java @@ -16,6 +16,6 @@ package me.filoghost.holographicdisplays.exception; public class InvalidFormatException extends Exception { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; } diff --git a/config/src/main/java/me/filoghost/holographicdisplays/exception/WorldNotFoundException.java b/config/src/main/java/me/filoghost/holographicdisplays/exception/WorldNotFoundException.java index 1f0ba7cb..45d98cc2 100644 --- a/config/src/main/java/me/filoghost/holographicdisplays/exception/WorldNotFoundException.java +++ b/config/src/main/java/me/filoghost/holographicdisplays/exception/WorldNotFoundException.java @@ -16,10 +16,10 @@ package me.filoghost.holographicdisplays.exception; public class WorldNotFoundException extends Exception { - private static final long serialVersionUID = 1L; - - public WorldNotFoundException(String message) { - super(message); - } + private static final long serialVersionUID = 1L; + + public WorldNotFoundException(String message) { + super(message); + } } diff --git a/example/death-holograms/pom.xml b/example/death-holograms/pom.xml index c5622747..66b6c3bb 100644 --- a/example/death-holograms/pom.xml +++ b/example/death-holograms/pom.xml @@ -1,15 +1,15 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - - me.filoghost.holographicdisplays - holographicdisplays-example - 3.0.0-SNAPSHOT - + + me.filoghost.holographicdisplays + holographicdisplays-example + 3.0.0-SNAPSHOT + - holographicdisplays-example-deathholograms - HolographicDisplays Example DeathHolograms - + holographicdisplays-example-deathholograms + HolographicDisplays Example DeathHolograms + diff --git a/example/death-holograms/src/main/java/me/filoghost/example/deathholograms/DeathHolograms.java b/example/death-holograms/src/main/java/me/filoghost/example/deathholograms/DeathHolograms.java index 4747e8a0..21ec7a30 100644 --- a/example/death-holograms/src/main/java/me/filoghost/example/deathholograms/DeathHolograms.java +++ b/example/death-holograms/src/main/java/me/filoghost/example/deathholograms/DeathHolograms.java @@ -27,28 +27,28 @@ import java.text.SimpleDateFormat; import java.util.Date; public class DeathHolograms extends JavaPlugin implements Listener { - - public void onEnable() { - - if (!Bukkit.getPluginManager().isPluginEnabled("HolographicDisplays")) { - getLogger().severe("*** HolographicDisplays is not installed or not enabled. ***"); - getLogger().severe("*** This plugin will be disabled. ***"); - this.setEnabled(false); - return; - } - - Bukkit.getPluginManager().registerEvents(this, this); - - } - - - @EventHandler - public void onPlayerDeath(PlayerDeathEvent event) { - - Hologram hologram = HologramsAPI.createHologram(this, event.getEntity().getEyeLocation()); - - hologram.appendTextLine(ChatColor.RED + "Player " + ChatColor.GOLD + event.getEntity().getName() + ChatColor.RED + " died here!"); - hologram.appendTextLine(ChatColor.GRAY + "Time of death: " + new SimpleDateFormat("H:m").format(new Date())); - - } + + public void onEnable() { + + if (!Bukkit.getPluginManager().isPluginEnabled("HolographicDisplays")) { + getLogger().severe("*** HolographicDisplays is not installed or not enabled. ***"); + getLogger().severe("*** This plugin will be disabled. ***"); + this.setEnabled(false); + return; + } + + Bukkit.getPluginManager().registerEvents(this, this); + + } + + + @EventHandler + public void onPlayerDeath(PlayerDeathEvent event) { + + Hologram hologram = HologramsAPI.createHologram(this, event.getEntity().getEyeLocation()); + + hologram.appendTextLine(ChatColor.RED + "Player " + ChatColor.GOLD + event.getEntity().getName() + ChatColor.RED + " died here!"); + hologram.appendTextLine(ChatColor.GRAY + "Time of death: " + new SimpleDateFormat("H:m").format(new Date())); + + } } diff --git a/example/pom.xml b/example/pom.xml index 701f6fcd..2dfb1765 100644 --- a/example/pom.xml +++ b/example/pom.xml @@ -1,40 +1,40 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - - me.filoghost.holographicdisplays - holographicdisplays-parent - 3.0.0-SNAPSHOT - + + me.filoghost.holographicdisplays + holographicdisplays-parent + 3.0.0-SNAPSHOT + - holographicdisplays-example - HolographicDisplays Example - pom + holographicdisplays-example + HolographicDisplays Example + pom - - death-holograms - power-ups - - - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - + + death-holograms + power-ups + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + - - - ${project.groupId} - holographicdisplays-api - - - - org.spigotmc - spigot-api - - + + + ${project.groupId} + holographicdisplays-api + + + + org.spigotmc + spigot-api + + - \ No newline at end of file + diff --git a/example/power-ups/pom.xml b/example/power-ups/pom.xml index 8bc1bec8..a4fb3877 100644 --- a/example/power-ups/pom.xml +++ b/example/power-ups/pom.xml @@ -1,15 +1,15 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - - me.filoghost.holographicdisplays - holographicdisplays-example - 3.0.0-SNAPSHOT - + + me.filoghost.holographicdisplays + holographicdisplays-example + 3.0.0-SNAPSHOT + - holographicdisplays-example-powerups - HolographicDisplays Example PowerUps + holographicdisplays-example-powerups + HolographicDisplays Example PowerUps diff --git a/example/power-ups/src/main/java/me/filoghost/example/powerups/PowerUps.java b/example/power-ups/src/main/java/me/filoghost/example/powerups/PowerUps.java index bf5051de..737b57f1 100644 --- a/example/power-ups/src/main/java/me/filoghost/example/powerups/PowerUps.java +++ b/example/power-ups/src/main/java/me/filoghost/example/powerups/PowerUps.java @@ -33,53 +33,53 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; public class PowerUps extends JavaPlugin implements Listener { - - @Override - public void onEnable() { - - if (!Bukkit.getPluginManager().isPluginEnabled("HolographicDisplays")) { - getLogger().severe("*** HolographicDisplays is not installed or not enabled. ***"); - getLogger().severe("*** This plugin will be disabled. ***"); - this.setEnabled(false); - return; - } - - Bukkit.getPluginManager().registerEvents(this, this); - - } - - - @EventHandler - public void onEntityDeath(EntityDeathEvent event) { - - if (event.getEntityType() == EntityType.ZOMBIE) { + + @Override + public void onEnable() { + + if (!Bukkit.getPluginManager().isPluginEnabled("HolographicDisplays")) { + getLogger().severe("*** HolographicDisplays is not installed or not enabled. ***"); + getLogger().severe("*** This plugin will be disabled. ***"); + this.setEnabled(false); + return; + } + + Bukkit.getPluginManager().registerEvents(this, this); + + } + + + @EventHandler + public void onEntityDeath(EntityDeathEvent event) { + + if (event.getEntityType() == EntityType.ZOMBIE) { - // Remove normal drops and exp. - event.getDrops().clear(); - event.setDroppedExp(0); - - // Spawn the floating item with a label. - final Hologram hologram = HologramsAPI.createHologram(this, event.getEntity().getLocation().add(0.0, 0.9, 0.0)); - hologram.appendTextLine(ChatColor.AQUA + "" + ChatColor.BOLD + "Speed PowerUp"); - ItemLine icon = hologram.appendItemLine(new ItemStack(Material.SUGAR)); - - icon.setPickupHandler(new PickupHandler() { - - @Override - public void onPickup(Player player) { - - // Play an effect. - player.playEffect(hologram.getLocation(), Effect.MOBSPAWNER_FLAMES, null); - - // 30 seconds of speed II. - player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 30 * 20, 1), true); - - // Delete the hologram. - hologram.delete(); - - } - }); - - } - } + // Remove normal drops and exp. + event.getDrops().clear(); + event.setDroppedExp(0); + + // Spawn the floating item with a label. + final Hologram hologram = HologramsAPI.createHologram(this, event.getEntity().getLocation().add(0.0, 0.9, 0.0)); + hologram.appendTextLine(ChatColor.AQUA + "" + ChatColor.BOLD + "Speed PowerUp"); + ItemLine icon = hologram.appendItemLine(new ItemStack(Material.SUGAR)); + + icon.setPickupHandler(new PickupHandler() { + + @Override + public void onPickup(Player player) { + + // Play an effect. + player.playEffect(hologram.getLocation(), Effect.MOBSPAWNER_FLAMES, null); + + // 30 seconds of speed II. + player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 30 * 20, 1), true); + + // Delete the hologram. + hologram.delete(); + + } + }); + + } + } } diff --git a/legacy-v1/pom.xml b/legacy-v1/pom.xml index 315fe811..d04f3768 100644 --- a/legacy-v1/pom.xml +++ b/legacy-v1/pom.xml @@ -1,39 +1,39 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - - me.filoghost.holographicdisplays - holographicdisplays-parent - 3.0.0-SNAPSHOT - + + me.filoghost.holographicdisplays + holographicdisplays-parent + 3.0.0-SNAPSHOT + - holographicdisplays-legacy-v1 - HolographicDisplays Legacy v1 + holographicdisplays-legacy-v1 + HolographicDisplays Legacy v1 - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + - - - ${project.groupId} - holographicdisplays-api - - - - ${project.groupId} - holographicdisplays-utils - - - - org.spigotmc - spigot-api - - + + + ${project.groupId} + holographicdisplays-api + + + + ${project.groupId} + holographicdisplays-utils + + + + org.spigotmc + spigot-api + + diff --git a/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/FloatingItem.java b/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/FloatingItem.java index 25b61489..786db9ac 100644 --- a/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/FloatingItem.java +++ b/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/FloatingItem.java @@ -24,60 +24,60 @@ import org.bukkit.inventory.ItemStack; @Deprecated public interface FloatingItem { - @Deprecated - public boolean update(); + @Deprecated + public boolean update(); - @Deprecated - public void hide(); + @Deprecated + public void hide(); - @Deprecated - public void setItemStack(ItemStack itemstack); + @Deprecated + public void setItemStack(ItemStack itemstack); - @Deprecated - public ItemStack getItemStack(); + @Deprecated + public ItemStack getItemStack(); - @Deprecated - public Location getLocation(); + @Deprecated + public Location getLocation(); - @Deprecated - public double getX(); + @Deprecated + public double getX(); - @Deprecated - public double getY(); + @Deprecated + public double getY(); - @Deprecated - public double getZ(); + @Deprecated + public double getZ(); - @Deprecated - public World getWorld(); + @Deprecated + public World getWorld(); - @Deprecated - public void teleport(Location location); + @Deprecated + public void teleport(Location location); - @Deprecated - public void setTouchHandler(ItemTouchHandler handler); + @Deprecated + public void setTouchHandler(ItemTouchHandler handler); - @Deprecated - public ItemTouchHandler getTouchHandler(); + @Deprecated + public ItemTouchHandler getTouchHandler(); - @Deprecated - public boolean hasTouchHandler(); - - @Deprecated - public void setPickupHandler(PickupHandler handler); + @Deprecated + public boolean hasTouchHandler(); + + @Deprecated + public void setPickupHandler(PickupHandler handler); - @Deprecated - public PickupHandler getPickupHandler(); + @Deprecated + public PickupHandler getPickupHandler(); - @Deprecated - public boolean hasPickupHandler(); + @Deprecated + public boolean hasPickupHandler(); - @Deprecated - public long getCreationTimestamp(); + @Deprecated + public long getCreationTimestamp(); - @Deprecated - public void delete(); + @Deprecated + public void delete(); - @Deprecated - public boolean isDeleted(); + @Deprecated + public boolean isDeleted(); } diff --git a/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/Hologram.java b/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/Hologram.java index c1cddd2d..f2afca4a 100644 --- a/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/Hologram.java +++ b/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/Hologram.java @@ -23,70 +23,70 @@ import org.bukkit.World; @Deprecated public interface Hologram { - @Deprecated - public boolean update(); + @Deprecated + public boolean update(); - @Deprecated - public void hide(); - - @Deprecated - public void addLine(String text); + @Deprecated + public void hide(); + + @Deprecated + public void addLine(String text); - @Deprecated - public void removeLine(int index); + @Deprecated + public void removeLine(int index); - @Deprecated - public void setLine(int index, String text); + @Deprecated + public void setLine(int index, String text); - @Deprecated - public void insertLine(int index, String text); + @Deprecated + public void insertLine(int index, String text); - @Deprecated - public String[] getLines(); - - @Deprecated - public int getLinesLength(); - - @Deprecated - public void clearLines(); - - @Deprecated - public Location getLocation(); - - @Deprecated - public double getX(); - - @Deprecated - public double getY(); - - @Deprecated - public double getZ(); - - @Deprecated - public World getWorld(); + @Deprecated + public String[] getLines(); + + @Deprecated + public int getLinesLength(); + + @Deprecated + public void clearLines(); + + @Deprecated + public Location getLocation(); + + @Deprecated + public double getX(); + + @Deprecated + public double getY(); + + @Deprecated + public double getZ(); + + @Deprecated + public World getWorld(); - @Deprecated - public void setLocation(Location location); - - @Deprecated - public void teleport(Location location); - - @Deprecated - public void setTouchHandler(TouchHandler handler); + @Deprecated + public void setLocation(Location location); + + @Deprecated + public void teleport(Location location); + + @Deprecated + public void setTouchHandler(TouchHandler handler); - @Deprecated - public TouchHandler getTouchHandler(); - - @Deprecated - public boolean hasTouchHandler(); + @Deprecated + public TouchHandler getTouchHandler(); + + @Deprecated + public boolean hasTouchHandler(); - @Deprecated - public long getCreationTimestamp(); + @Deprecated + public long getCreationTimestamp(); - @Deprecated - public void delete(); + @Deprecated + public void delete(); - @Deprecated - public boolean isDeleted(); - + @Deprecated + public boolean isDeleted(); + } diff --git a/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/HolographicDisplaysAPI.java b/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/HolographicDisplaysAPI.java index b2fa535f..022a9f6a 100644 --- a/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/HolographicDisplaysAPI.java +++ b/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/HolographicDisplaysAPI.java @@ -40,128 +40,128 @@ import java.util.Set; */ @Deprecated public class HolographicDisplaysAPI { - - private static Set notifiedPlugins = new HashSet<>(); - - private static void notifyOldAPI(Plugin plugin) { - Validator.notNull(plugin, "plugin"); - - if (notifiedPlugins.add(plugin.getName())) { - Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[Holographic Displays] The plugin \"" + plugin.getName() + "\" is still using the old API of Holographic Displays. " - + "Please notify the author and ask them to update it, the old API will be removed soon."); - } - } - - @Deprecated - public static Hologram createHologram(Plugin plugin, Location source, String... lines) { - notifyOldAPI(plugin); - - validateLocation(source); - - me.filoghost.holographicdisplays.api.Hologram hologram = HologramsAPI.createHologram(plugin, source); - for (String line : lines) { - hologram.appendTextLine(line); - } - return new HologramAdapter(plugin, hologram); - } + + private static Set notifiedPlugins = new HashSet<>(); + + private static void notifyOldAPI(Plugin plugin) { + Validator.notNull(plugin, "plugin"); + + if (notifiedPlugins.add(plugin.getName())) { + Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[Holographic Displays] The plugin \"" + plugin.getName() + "\" is still using the old API of Holographic Displays. " + + "Please notify the author and ask them to update it, the old API will be removed soon."); + } + } + + @Deprecated + public static Hologram createHologram(Plugin plugin, Location source, String... lines) { + notifyOldAPI(plugin); + + validateLocation(source); + + me.filoghost.holographicdisplays.api.Hologram hologram = HologramsAPI.createHologram(plugin, source); + for (String line : lines) { + hologram.appendTextLine(line); + } + return new HologramAdapter(plugin, hologram); + } - @Deprecated - public static FloatingItem createFloatingItem(Plugin plugin, Location source, ItemStack itemstack) { - notifyOldAPI(plugin); - - validateLocation(source); - validateItem(itemstack); - - me.filoghost.holographicdisplays.api.Hologram hologram = HologramsAPI.createHologram(plugin, source); - ItemLine itemLine = hologram.appendItemLine(itemstack); - return new FloatingItemAdapter(plugin, hologram, itemLine); - } + @Deprecated + public static FloatingItem createFloatingItem(Plugin plugin, Location source, ItemStack itemstack) { + notifyOldAPI(plugin); + + validateLocation(source); + validateItem(itemstack); + + me.filoghost.holographicdisplays.api.Hologram hologram = HologramsAPI.createHologram(plugin, source); + ItemLine itemLine = hologram.appendItemLine(itemstack); + return new FloatingItemAdapter(plugin, hologram, itemLine); + } - @Deprecated - public static Hologram createIndividualHologram(Plugin plugin, Location source, Player whoCanSee, String... lines) { - notifyOldAPI(plugin); - - return createIndividualHologram(plugin, source, Arrays.asList(whoCanSee), lines); - } - - @Deprecated - public static Hologram createIndividualHologram(Plugin plugin, Location source, List whoCanSee, String... lines) { - notifyOldAPI(plugin); - - validateLocation(source); - - me.filoghost.holographicdisplays.api.Hologram hologram = HologramsAPI.createHologram(plugin, source); - - hologram.getVisibilityManager().setVisibleByDefault(false); - if (whoCanSee != null) { - for (Player player : whoCanSee) { - hologram.getVisibilityManager().showTo(player); - } - } - - for (String line : lines) { - hologram.appendTextLine(line); - } - - return new HologramAdapter(plugin, hologram); - } - - @Deprecated - public static FloatingItem createIndividualFloatingItem(Plugin plugin, Location source, Player whoCanSee, ItemStack itemstack) { - notifyOldAPI(plugin); - - return createIndividualFloatingItem(plugin, source, Arrays.asList(whoCanSee), itemstack); - } - - @Deprecated - public static FloatingItem createIndividualFloatingItem(Plugin plugin, Location source, List whoCanSee, ItemStack itemstack) { - notifyOldAPI(plugin); - - validateLocation(source); - validateItem(itemstack); - - me.filoghost.holographicdisplays.api.Hologram hologram = HologramsAPI.createHologram(plugin, source); - ItemLine itemLine = hologram.appendItemLine(itemstack); - - hologram.getVisibilityManager().setVisibleByDefault(false); - if (whoCanSee != null) { - for (Player player : whoCanSee) { - hologram.getVisibilityManager().showTo(player); - } - } - - return new FloatingItemAdapter(plugin, hologram, itemLine); - } - - @Deprecated - public static Hologram[] getHolograms(Plugin plugin) { - notifyOldAPI(plugin); - - Collection pluginHolograms = HologramAdapter.activeHolograms.getOrDefault(plugin, Collections.emptyList()); - return pluginHolograms.toArray(new HologramAdapter[0]); - } - - @Deprecated - public static FloatingItem[] getFloatingItems(Plugin plugin) { - notifyOldAPI(plugin); - - Collection pluginFloatingItems = FloatingItemAdapter.activeFloatingItems.getOrDefault(plugin, Collections.emptyList()); - return pluginFloatingItems.toArray(new FloatingItemAdapter[0]); - } - - @Deprecated - public static boolean isHologramEntity(Entity bukkitEntity) { - return HologramsAPI.isHologramEntity(bukkitEntity); - } - - private static void validateLocation(Location loc) { - Validator.notNull(loc, "location"); - Validator.notNull(loc.getWorld(), "location's world"); - } - - private static void validateItem(ItemStack itemstack) { - Validator.notNull(itemstack, "itemstack"); - Validator.isTrue(itemstack.getType() != Material.AIR, "itemstack cannot be AIR"); - } + @Deprecated + public static Hologram createIndividualHologram(Plugin plugin, Location source, Player whoCanSee, String... lines) { + notifyOldAPI(plugin); + + return createIndividualHologram(plugin, source, Arrays.asList(whoCanSee), lines); + } + + @Deprecated + public static Hologram createIndividualHologram(Plugin plugin, Location source, List whoCanSee, String... lines) { + notifyOldAPI(plugin); + + validateLocation(source); + + me.filoghost.holographicdisplays.api.Hologram hologram = HologramsAPI.createHologram(plugin, source); + + hologram.getVisibilityManager().setVisibleByDefault(false); + if (whoCanSee != null) { + for (Player player : whoCanSee) { + hologram.getVisibilityManager().showTo(player); + } + } + + for (String line : lines) { + hologram.appendTextLine(line); + } + + return new HologramAdapter(plugin, hologram); + } + + @Deprecated + public static FloatingItem createIndividualFloatingItem(Plugin plugin, Location source, Player whoCanSee, ItemStack itemstack) { + notifyOldAPI(plugin); + + return createIndividualFloatingItem(plugin, source, Arrays.asList(whoCanSee), itemstack); + } + + @Deprecated + public static FloatingItem createIndividualFloatingItem(Plugin plugin, Location source, List whoCanSee, ItemStack itemstack) { + notifyOldAPI(plugin); + + validateLocation(source); + validateItem(itemstack); + + me.filoghost.holographicdisplays.api.Hologram hologram = HologramsAPI.createHologram(plugin, source); + ItemLine itemLine = hologram.appendItemLine(itemstack); + + hologram.getVisibilityManager().setVisibleByDefault(false); + if (whoCanSee != null) { + for (Player player : whoCanSee) { + hologram.getVisibilityManager().showTo(player); + } + } + + return new FloatingItemAdapter(plugin, hologram, itemLine); + } + + @Deprecated + public static Hologram[] getHolograms(Plugin plugin) { + notifyOldAPI(plugin); + + Collection pluginHolograms = HologramAdapter.activeHolograms.getOrDefault(plugin, Collections.emptyList()); + return pluginHolograms.toArray(new HologramAdapter[0]); + } + + @Deprecated + public static FloatingItem[] getFloatingItems(Plugin plugin) { + notifyOldAPI(plugin); + + Collection pluginFloatingItems = FloatingItemAdapter.activeFloatingItems.getOrDefault(plugin, Collections.emptyList()); + return pluginFloatingItems.toArray(new FloatingItemAdapter[0]); + } + + @Deprecated + public static boolean isHologramEntity(Entity bukkitEntity) { + return HologramsAPI.isHologramEntity(bukkitEntity); + } + + private static void validateLocation(Location loc) { + Validator.notNull(loc, "location"); + Validator.notNull(loc.getWorld(), "location's world"); + } + + private static void validateItem(ItemStack itemstack) { + Validator.notNull(itemstack, "itemstack"); + Validator.isTrue(itemstack.getType() != Material.AIR, "itemstack cannot be AIR"); + } } diff --git a/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/ItemTouchHandler.java b/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/ItemTouchHandler.java index a9e4c087..5968b3f7 100644 --- a/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/ItemTouchHandler.java +++ b/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/ItemTouchHandler.java @@ -22,7 +22,7 @@ import org.bukkit.entity.Player; @Deprecated public interface ItemTouchHandler { - @Deprecated - public void onTouch(FloatingItem floatingItem, Player player); - + @Deprecated + public void onTouch(FloatingItem floatingItem, Player player); + } diff --git a/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/PickupHandler.java b/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/PickupHandler.java index cbb3db51..1a359853 100644 --- a/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/PickupHandler.java +++ b/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/PickupHandler.java @@ -22,7 +22,7 @@ import org.bukkit.entity.Player; @Deprecated public interface PickupHandler { - @Deprecated - public void onPickup(FloatingItem floatingItem, Player player); - + @Deprecated + public void onPickup(FloatingItem floatingItem, Player player); + } diff --git a/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/TouchHandler.java b/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/TouchHandler.java index f7ea94a2..ca3f2727 100644 --- a/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/TouchHandler.java +++ b/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/TouchHandler.java @@ -22,7 +22,7 @@ import org.bukkit.entity.Player; @Deprecated public interface TouchHandler { - @Deprecated - public void onTouch(Hologram hologram, Player player); - + @Deprecated + public void onTouch(Hologram hologram, Player player); + } diff --git a/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/adapter/FloatingItemAdapter.java b/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/adapter/FloatingItemAdapter.java index 44055567..18f7386b 100644 --- a/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/adapter/FloatingItemAdapter.java +++ b/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/adapter/FloatingItemAdapter.java @@ -31,130 +31,130 @@ import java.util.Map; @SuppressWarnings("deprecation") public class FloatingItemAdapter implements FloatingItem { - - public static Map> activeFloatingItems = new HashMap<>(); - - private Plugin plugin; - public Hologram hologram; - private ItemLine itemLine; - private ItemTouchHandler touchHandler; - private PickupHandler pickupHandler; - - public FloatingItemAdapter(Plugin plugin, Hologram delegateHologram, ItemLine delegateItemLine) { - this.plugin = plugin; - this.hologram = delegateHologram; - this.itemLine = delegateItemLine; - - activeFloatingItems.computeIfAbsent(plugin, __ -> new ArrayList<>()).add(this); - } + + public static Map> activeFloatingItems = new HashMap<>(); + + private Plugin plugin; + public Hologram hologram; + private ItemLine itemLine; + private ItemTouchHandler touchHandler; + private PickupHandler pickupHandler; + + public FloatingItemAdapter(Plugin plugin, Hologram delegateHologram, ItemLine delegateItemLine) { + this.plugin = plugin; + this.hologram = delegateHologram; + this.itemLine = delegateItemLine; + + activeFloatingItems.computeIfAbsent(plugin, __ -> new ArrayList<>()).add(this); + } - @Override - public boolean update() { - return true; - } + @Override + public boolean update() { + return true; + } - @Override - public void hide() { - - } + @Override + public void hide() { + + } - @Override - public void setItemStack(ItemStack itemstack) { - itemLine.setItemStack(itemstack); - } + @Override + public void setItemStack(ItemStack itemstack) { + itemLine.setItemStack(itemstack); + } - @Override - public ItemStack getItemStack() { - return itemLine.getItemStack(); - } + @Override + public ItemStack getItemStack() { + return itemLine.getItemStack(); + } - @Override - public Location getLocation() { - return hologram.getLocation(); - } + @Override + public Location getLocation() { + return hologram.getLocation(); + } - @Override - public double getX() { - return hologram.getX(); - } + @Override + public double getX() { + return hologram.getX(); + } - @Override - public double getY() { - return hologram.getY(); - } + @Override + public double getY() { + return hologram.getY(); + } - @Override - public double getZ() { - return hologram.getZ(); - } + @Override + public double getZ() { + return hologram.getZ(); + } - @Override - public World getWorld() { - return hologram.getWorld(); - } + @Override + public World getWorld() { + return hologram.getWorld(); + } - @Override - public void teleport(Location location) { - hologram.teleport(location); - } + @Override + public void teleport(Location location) { + hologram.teleport(location); + } - @Override - public void setTouchHandler(ItemTouchHandler handler) { - this.touchHandler = handler; - - if (handler != null) { - itemLine.setTouchHandler(new ItemTouchHandlerAdapter(this, handler)); - } else { - itemLine.setTouchHandler(null); - } - } + @Override + public void setTouchHandler(ItemTouchHandler handler) { + this.touchHandler = handler; + + if (handler != null) { + itemLine.setTouchHandler(new ItemTouchHandlerAdapter(this, handler)); + } else { + itemLine.setTouchHandler(null); + } + } - @Override - public ItemTouchHandler getTouchHandler() { - return touchHandler; - } + @Override + public ItemTouchHandler getTouchHandler() { + return touchHandler; + } - @Override - public boolean hasTouchHandler() { - return touchHandler != null; - } + @Override + public boolean hasTouchHandler() { + return touchHandler != null; + } - @Override - public void setPickupHandler(PickupHandler handler) { - this.pickupHandler = handler; - - if (handler != null) { - itemLine.setPickupHandler(new PickupHandlerAdapter(this, handler)); - } else { - itemLine.setPickupHandler(null); - } - } + @Override + public void setPickupHandler(PickupHandler handler) { + this.pickupHandler = handler; + + if (handler != null) { + itemLine.setPickupHandler(new PickupHandlerAdapter(this, handler)); + } else { + itemLine.setPickupHandler(null); + } + } - @Override - public PickupHandler getPickupHandler() { - return pickupHandler; - } + @Override + public PickupHandler getPickupHandler() { + return pickupHandler; + } - @Override - public boolean hasPickupHandler() { - return pickupHandler != null; - } + @Override + public boolean hasPickupHandler() { + return pickupHandler != null; + } - @Override - public long getCreationTimestamp() { - return hologram.getCreationTimestamp(); - } + @Override + public long getCreationTimestamp() { + return hologram.getCreationTimestamp(); + } - @Override - public void delete() { - hologram.delete(); - - activeFloatingItems.get(plugin).remove(this); - } + @Override + public void delete() { + hologram.delete(); + + activeFloatingItems.get(plugin).remove(this); + } - @Override - public boolean isDeleted() { - return hologram.isDeleted(); - } + @Override + public boolean isDeleted() { + return hologram.isDeleted(); + } } diff --git a/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/adapter/HologramAdapter.java b/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/adapter/HologramAdapter.java index 65dc21c0..faa1b880 100644 --- a/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/adapter/HologramAdapter.java +++ b/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/adapter/HologramAdapter.java @@ -30,172 +30,172 @@ import java.util.Map; @SuppressWarnings("deprecation") public class HologramAdapter implements Hologram { - - public static Map> activeHolograms = new HashMap<>(); - - private Plugin plugin; - private me.filoghost.holographicdisplays.api.Hologram hologram; - private TouchHandler touchHandler; - - public HologramAdapter(Plugin plugin, me.filoghost.holographicdisplays.api.Hologram delegate) { - this.plugin = plugin; - this.hologram = delegate; - - activeHolograms.computeIfAbsent(plugin, __ -> new ArrayList<>()).add(this); - } - - @Override - @Deprecated - public boolean update() { - return true; - } + + public static Map> activeHolograms = new HashMap<>(); + + private Plugin plugin; + private me.filoghost.holographicdisplays.api.Hologram hologram; + private TouchHandler touchHandler; + + public HologramAdapter(Plugin plugin, me.filoghost.holographicdisplays.api.Hologram delegate) { + this.plugin = plugin; + this.hologram = delegate; + + activeHolograms.computeIfAbsent(plugin, __ -> new ArrayList<>()).add(this); + } + + @Override + @Deprecated + public boolean update() { + return true; + } - @Override - @Deprecated - public void hide() { - - } + @Override + @Deprecated + public void hide() { + + } - @Override - @Deprecated - public void addLine(String text) { - hologram.appendTextLine(text); - updateTouchHandler(); - } + @Override + @Deprecated + public void addLine(String text) { + hologram.appendTextLine(text); + updateTouchHandler(); + } - @Override - @Deprecated - public void setLine(int index, String text) { - hologram.removeLine(index); - hologram.insertTextLine(index, text); - updateTouchHandler(); - } + @Override + @Deprecated + public void setLine(int index, String text) { + hologram.removeLine(index); + hologram.insertTextLine(index, text); + updateTouchHandler(); + } - @Override - @Deprecated - public void insertLine(int index, String text) { - hologram.insertTextLine(index, text); - updateTouchHandler(); - } + @Override + @Deprecated + public void insertLine(int index, String text) { + hologram.insertTextLine(index, text); + updateTouchHandler(); + } - @Override - @Deprecated - public String[] getLines() { - String[] lines = new String[hologram.size()]; - for (int i = 0; i < lines.length; i++) { - HologramLine lineObject = hologram.getLine(i); - if (lineObject instanceof TextLine) { - lines[i] = ((TextLine) lineObject).getText(); - } else { - lines[i] = ""; - } - } - return lines; - } + @Override + @Deprecated + public String[] getLines() { + String[] lines = new String[hologram.size()]; + for (int i = 0; i < lines.length; i++) { + HologramLine lineObject = hologram.getLine(i); + if (lineObject instanceof TextLine) { + lines[i] = ((TextLine) lineObject).getText(); + } else { + lines[i] = ""; + } + } + return lines; + } - @Override - @Deprecated - public int getLinesLength() { - return hologram.size(); - } + @Override + @Deprecated + public int getLinesLength() { + return hologram.size(); + } - @Override - @Deprecated - public void setLocation(Location location) { - hologram.teleport(location); - } + @Override + @Deprecated + public void setLocation(Location location) { + hologram.teleport(location); + } - @Override - @Deprecated - public void setTouchHandler(TouchHandler handler) { - this.touchHandler = handler; - updateTouchHandler(); - } + @Override + @Deprecated + public void setTouchHandler(TouchHandler handler) { + this.touchHandler = handler; + updateTouchHandler(); + } - private void updateTouchHandler() { - for (int i = 0; i < hologram.size(); i++) { - HologramLine line = hologram.getLine(i); - if (!(line instanceof TouchableLine)) { - continue; - } - - TouchableLine touchableLine = (TouchableLine) line; - - if (touchHandler != null) { - touchableLine.setTouchHandler(new HologramTouchHandlerAdapter(this, touchHandler)); - } else { - touchableLine.setTouchHandler(null); - } - } - } + private void updateTouchHandler() { + for (int i = 0; i < hologram.size(); i++) { + HologramLine line = hologram.getLine(i); + if (!(line instanceof TouchableLine)) { + continue; + } + + TouchableLine touchableLine = (TouchableLine) line; + + if (touchHandler != null) { + touchableLine.setTouchHandler(new HologramTouchHandlerAdapter(this, touchHandler)); + } else { + touchableLine.setTouchHandler(null); + } + } + } - @Override - @Deprecated - public TouchHandler getTouchHandler() { - return touchHandler; - } + @Override + @Deprecated + public TouchHandler getTouchHandler() { + return touchHandler; + } - @Override - @Deprecated - public boolean hasTouchHandler() { - return touchHandler != null; - } + @Override + @Deprecated + public boolean hasTouchHandler() { + return touchHandler != null; + } - @Override - public void removeLine(int index) { - hologram.removeLine(index); - } + @Override + public void removeLine(int index) { + hologram.removeLine(index); + } - @Override - public void clearLines() { - hologram.clearLines(); - } + @Override + public void clearLines() { + hologram.clearLines(); + } - @Override - public Location getLocation() { - return hologram.getLocation(); - } + @Override + public Location getLocation() { + return hologram.getLocation(); + } - @Override - public double getX() { - return hologram.getX(); - } + @Override + public double getX() { + return hologram.getX(); + } - @Override - public double getY() { - return hologram.getY(); - } + @Override + public double getY() { + return hologram.getY(); + } - @Override - public double getZ() { - return hologram.getZ(); - } + @Override + public double getZ() { + return hologram.getZ(); + } - @Override - public World getWorld() { - return hologram.getWorld(); - } + @Override + public World getWorld() { + return hologram.getWorld(); + } - @Override - public void teleport(Location location) { - hologram.teleport(location); - } + @Override + public void teleport(Location location) { + hologram.teleport(location); + } - @Override - public long getCreationTimestamp() { - return hologram.getCreationTimestamp(); - } + @Override + public long getCreationTimestamp() { + return hologram.getCreationTimestamp(); + } - @Override - public void delete() { - hologram.delete(); - - activeHolograms.get(plugin).remove(this); - } + @Override + public void delete() { + hologram.delete(); + + activeHolograms.get(plugin).remove(this); + } - @Override - public boolean isDeleted() { - return hologram.isDeleted(); - } + @Override + public boolean isDeleted() { + return hologram.isDeleted(); + } } diff --git a/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/adapter/HologramTouchHandlerAdapter.java b/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/adapter/HologramTouchHandlerAdapter.java index 1452b423..7a85de19 100644 --- a/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/adapter/HologramTouchHandlerAdapter.java +++ b/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/adapter/HologramTouchHandlerAdapter.java @@ -21,17 +21,17 @@ import org.bukkit.entity.Player; @SuppressWarnings("deprecation") public class HologramTouchHandlerAdapter implements me.filoghost.holographicdisplays.api.handler.TouchHandler { - protected TouchHandler oldHandler; - private Hologram hologram; - - public HologramTouchHandlerAdapter(Hologram hologram, TouchHandler oldHandler) { - this.hologram = hologram; - this.oldHandler = oldHandler; - } - - @Override - public void onTouch(Player player) { - oldHandler.onTouch(hologram, player); - } + protected TouchHandler oldHandler; + private Hologram hologram; + + public HologramTouchHandlerAdapter(Hologram hologram, TouchHandler oldHandler) { + this.hologram = hologram; + this.oldHandler = oldHandler; + } + + @Override + public void onTouch(Player player) { + oldHandler.onTouch(hologram, player); + } } diff --git a/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/adapter/ItemTouchHandlerAdapter.java b/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/adapter/ItemTouchHandlerAdapter.java index 3d5ea3f3..835fe3bc 100644 --- a/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/adapter/ItemTouchHandlerAdapter.java +++ b/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/adapter/ItemTouchHandlerAdapter.java @@ -22,17 +22,17 @@ import org.bukkit.entity.Player; @SuppressWarnings("deprecation") public class ItemTouchHandlerAdapter implements TouchHandler { - protected ItemTouchHandler oldHandler; - private FloatingItem item; - - public ItemTouchHandlerAdapter(FloatingItem item, ItemTouchHandler oldHandler) { - this.item = item; - this.oldHandler = oldHandler; - } + protected ItemTouchHandler oldHandler; + private FloatingItem item; + + public ItemTouchHandlerAdapter(FloatingItem item, ItemTouchHandler oldHandler) { + this.item = item; + this.oldHandler = oldHandler; + } - @Override - public void onTouch(Player player) { - oldHandler.onTouch(item, player); - } + @Override + public void onTouch(Player player) { + oldHandler.onTouch(item, player); + } } diff --git a/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/adapter/PickupHandlerAdapter.java b/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/adapter/PickupHandlerAdapter.java index 0b176794..cfc02c91 100644 --- a/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/adapter/PickupHandlerAdapter.java +++ b/legacy-v1/src/main/java/com/gmail/filoghost/holograms/api/adapter/PickupHandlerAdapter.java @@ -21,17 +21,17 @@ import org.bukkit.entity.Player; @SuppressWarnings("deprecation") public class PickupHandlerAdapter implements me.filoghost.holographicdisplays.api.handler.PickupHandler { - public PickupHandler oldHandler; - private FloatingItem item; - - public PickupHandlerAdapter(FloatingItem item, PickupHandler oldPickupHandler) { - this.item = item; - this.oldHandler = oldPickupHandler; - } - - @Override - public void onPickup(Player player) { - oldHandler.onPickup(item, player); - } + public PickupHandler oldHandler; + private FloatingItem item; + + public PickupHandlerAdapter(FloatingItem item, PickupHandler oldPickupHandler) { + this.item = item; + this.oldHandler = oldPickupHandler; + } + + @Override + public void onPickup(Player player) { + oldHandler.onPickup(item, player); + } } diff --git a/legacy-v2/pom.xml b/legacy-v2/pom.xml index e22c8f7c..4c49410e 100644 --- a/legacy-v2/pom.xml +++ b/legacy-v2/pom.xml @@ -1,39 +1,39 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - - me.filoghost.holographicdisplays - holographicdisplays-parent - 3.0.0-SNAPSHOT - + + me.filoghost.holographicdisplays + holographicdisplays-parent + 3.0.0-SNAPSHOT + - holographicdisplays-legacy-v2 - HolographicDisplays Legacy v2 + holographicdisplays-legacy-v2 + HolographicDisplays Legacy v2 - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + - - - ${project.groupId} - holographicdisplays-api - + + + ${project.groupId} + holographicdisplays-api + - - ${project.groupId} - holographicdisplays-utils - + + ${project.groupId} + holographicdisplays-utils + - - org.spigotmc - spigot-api - - + + org.spigotmc + spigot-api + + diff --git a/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/Hologram.java b/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/Hologram.java index ba2f1794..2b3ca71b 100644 --- a/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/Hologram.java +++ b/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/Hologram.java @@ -27,70 +27,70 @@ import org.bukkit.inventory.ItemStack; @Deprecated public interface Hologram { - @Deprecated - public TextLine appendTextLine(String text); + @Deprecated + public TextLine appendTextLine(String text); - @Deprecated - public ItemLine appendItemLine(ItemStack itemStack); - - @Deprecated - public TextLine insertTextLine(int index, String text); + @Deprecated + public ItemLine appendItemLine(ItemStack itemStack); + + @Deprecated + public TextLine insertTextLine(int index, String text); - @Deprecated - public ItemLine insertItemLine(int index, ItemStack itemStack); + @Deprecated + public ItemLine insertItemLine(int index, ItemStack itemStack); - @Deprecated - public HologramLine getLine(int index); - - @Deprecated - public void removeLine(int index); + @Deprecated + public HologramLine getLine(int index); + + @Deprecated + public void removeLine(int index); - @Deprecated - public void clearLines(); + @Deprecated + public void clearLines(); - @Deprecated - public int size(); + @Deprecated + public int size(); - @Deprecated - public double getHeight(); + @Deprecated + public double getHeight(); - @Deprecated - public void teleport(Location location); - - @Deprecated - public void teleport(World world, double x, double y, double z); - - @Deprecated - public Location getLocation(); - - @Deprecated - public double getX(); + @Deprecated + public void teleport(Location location); + + @Deprecated + public void teleport(World world, double x, double y, double z); + + @Deprecated + public Location getLocation(); + + @Deprecated + public double getX(); - @Deprecated - public double getY(); + @Deprecated + public double getY(); - @Deprecated - public double getZ(); - - @Deprecated - public World getWorld(); + @Deprecated + public double getZ(); + + @Deprecated + public World getWorld(); - @Deprecated - public VisibilityManager getVisibilityManager(); + @Deprecated + public VisibilityManager getVisibilityManager(); - @Deprecated - public long getCreationTimestamp(); + @Deprecated + public long getCreationTimestamp(); - @Deprecated - public boolean isAllowPlaceholders(); + @Deprecated + public boolean isAllowPlaceholders(); - @Deprecated - public void setAllowPlaceholders(boolean allowPlaceholders); - - @Deprecated - public void delete(); - - @Deprecated - public boolean isDeleted(); - + @Deprecated + public void setAllowPlaceholders(boolean allowPlaceholders); + + @Deprecated + public void delete(); + + @Deprecated + public boolean isDeleted(); + } diff --git a/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/HologramsAPI.java b/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/HologramsAPI.java index 08650445..fda6bbf7 100644 --- a/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/HologramsAPI.java +++ b/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/HologramsAPI.java @@ -28,41 +28,41 @@ import java.util.Collection; @Deprecated public class HologramsAPI { - private HologramsAPI() {} + private HologramsAPI() {} - @Deprecated - public static Hologram createHologram(Plugin plugin, Location source) { - return BackendAPI.getImplementation().createHologram(plugin, source); - } + @Deprecated + public static Hologram createHologram(Plugin plugin, Location source) { + return BackendAPI.getImplementation().createHologram(plugin, source); + } - @Deprecated - public static Collection getHolograms(Plugin plugin) { - return BackendAPI.getImplementation().getHolograms(plugin); - } + @Deprecated + public static Collection getHolograms(Plugin plugin) { + return BackendAPI.getImplementation().getHolograms(plugin); + } - @Deprecated - public static boolean registerPlaceholder(Plugin plugin, String textPlaceholder, double refreshRate, PlaceholderReplacer replacer) { - return BackendAPI.getImplementation().registerPlaceholder(plugin, textPlaceholder, refreshRate, replacer); - } - - @Deprecated - public static Collection getRegisteredPlaceholders(Plugin plugin) { - return BackendAPI.getImplementation().getRegisteredPlaceholders(plugin); - } + @Deprecated + public static boolean registerPlaceholder(Plugin plugin, String textPlaceholder, double refreshRate, PlaceholderReplacer replacer) { + return BackendAPI.getImplementation().registerPlaceholder(plugin, textPlaceholder, refreshRate, replacer); + } + + @Deprecated + public static Collection getRegisteredPlaceholders(Plugin plugin) { + return BackendAPI.getImplementation().getRegisteredPlaceholders(plugin); + } - @Deprecated - public static boolean unregisterPlaceholder(Plugin plugin, String textPlaceholder) { - return BackendAPI.getImplementation().unregisterPlaceholder(plugin, textPlaceholder); - } - - @Deprecated - public static void unregisterPlaceholders(Plugin plugin) { - BackendAPI.getImplementation().unregisterPlaceholders(plugin); - } + @Deprecated + public static boolean unregisterPlaceholder(Plugin plugin, String textPlaceholder) { + return BackendAPI.getImplementation().unregisterPlaceholder(plugin, textPlaceholder); + } + + @Deprecated + public static void unregisterPlaceholders(Plugin plugin) { + BackendAPI.getImplementation().unregisterPlaceholders(plugin); + } - @Deprecated - public static boolean isHologramEntity(Entity bukkitEntity) { - return BackendAPI.getImplementation().isHologramEntity(bukkitEntity); - } + @Deprecated + public static boolean isHologramEntity(Entity bukkitEntity) { + return BackendAPI.getImplementation().isHologramEntity(bukkitEntity); + } } diff --git a/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/VisibilityManager.java b/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/VisibilityManager.java index 951dd67b..069cfd74 100644 --- a/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/VisibilityManager.java +++ b/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/VisibilityManager.java @@ -22,25 +22,25 @@ import org.bukkit.entity.Player; @Deprecated public interface VisibilityManager { - @Deprecated - public boolean isVisibleByDefault(); - - @Deprecated - public void setVisibleByDefault(boolean visibleByDefault); - - @Deprecated - public void showTo(Player player); - - @Deprecated - public void hideTo(Player player); - - @Deprecated - public boolean isVisibleTo(Player player); - - @Deprecated - public void resetVisibility(Player player); - - @Deprecated - public void resetVisibilityAll(); - + @Deprecated + public boolean isVisibleByDefault(); + + @Deprecated + public void setVisibleByDefault(boolean visibleByDefault); + + @Deprecated + public void showTo(Player player); + + @Deprecated + public void hideTo(Player player); + + @Deprecated + public boolean isVisibleTo(Player player); + + @Deprecated + public void resetVisibility(Player player); + + @Deprecated + public void resetVisibilityAll(); + } diff --git a/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/handler/PickupHandler.java b/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/handler/PickupHandler.java index 3097d7e6..4a072678 100644 --- a/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/handler/PickupHandler.java +++ b/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/handler/PickupHandler.java @@ -22,7 +22,7 @@ import org.bukkit.entity.Player; @Deprecated public interface PickupHandler { - @Deprecated - public void onPickup(Player player); - + @Deprecated + public void onPickup(Player player); + } diff --git a/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/handler/TouchHandler.java b/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/handler/TouchHandler.java index 5e04d0b7..31b88d47 100644 --- a/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/handler/TouchHandler.java +++ b/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/handler/TouchHandler.java @@ -22,7 +22,7 @@ import org.bukkit.entity.Player; @Deprecated public interface TouchHandler { - @Deprecated - public void onTouch(Player player); - + @Deprecated + public void onTouch(Player player); + } diff --git a/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/internal/BackendAPI.java b/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/internal/BackendAPI.java index f84ac212..c85ee249 100644 --- a/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/internal/BackendAPI.java +++ b/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/internal/BackendAPI.java @@ -27,42 +27,42 @@ import java.util.Collection; */ @Deprecated public abstract class BackendAPI { - - private static BackendAPI implementation; + + private static BackendAPI implementation; - @Deprecated - public static void setImplementation(BackendAPI implementation) { - BackendAPI.implementation = implementation; - } + @Deprecated + public static void setImplementation(BackendAPI implementation) { + BackendAPI.implementation = implementation; + } - @Deprecated - public static BackendAPI getImplementation() { - if (implementation == null) { - throw new IllegalStateException("No API implementation set. Is Holographic Displays enabled?"); - } - - return implementation; - } + @Deprecated + public static BackendAPI getImplementation() { + if (implementation == null) { + throw new IllegalStateException("No API implementation set. Is Holographic Displays enabled?"); + } + + return implementation; + } - @Deprecated - public abstract Hologram createHologram(Plugin plugin, Location source); + @Deprecated + public abstract Hologram createHologram(Plugin plugin, Location source); - @Deprecated - public abstract Collection getHolograms(Plugin plugin); + @Deprecated + public abstract Collection getHolograms(Plugin plugin); - @Deprecated - public abstract boolean registerPlaceholder(Plugin plugin, String textPlaceholder, double refreshRate, PlaceholderReplacer replacer); + @Deprecated + public abstract boolean registerPlaceholder(Plugin plugin, String textPlaceholder, double refreshRate, PlaceholderReplacer replacer); - @Deprecated - public abstract Collection getRegisteredPlaceholders(Plugin plugin); + @Deprecated + public abstract Collection getRegisteredPlaceholders(Plugin plugin); - @Deprecated - public abstract boolean unregisterPlaceholder(Plugin plugin, String textPlaceholder); + @Deprecated + public abstract boolean unregisterPlaceholder(Plugin plugin, String textPlaceholder); - @Deprecated - public abstract void unregisterPlaceholders(Plugin plugin); + @Deprecated + public abstract void unregisterPlaceholders(Plugin plugin); - @Deprecated - public abstract boolean isHologramEntity(Entity bukkitEntity); + @Deprecated + public abstract boolean isHologramEntity(Entity bukkitEntity); } diff --git a/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/line/CollectableLine.java b/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/line/CollectableLine.java index 2e3fc12a..9f4147c9 100644 --- a/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/line/CollectableLine.java +++ b/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/line/CollectableLine.java @@ -22,10 +22,10 @@ import com.gmail.filoghost.holographicdisplays.api.handler.PickupHandler; @Deprecated public interface CollectableLine extends HologramLine { - @Deprecated - public void setPickupHandler(PickupHandler pickupHandler); - - @Deprecated - public PickupHandler getPickupHandler(); - + @Deprecated + public void setPickupHandler(PickupHandler pickupHandler); + + @Deprecated + public PickupHandler getPickupHandler(); + } diff --git a/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/line/HologramLine.java b/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/line/HologramLine.java index ff59b7a0..bfaf20c9 100644 --- a/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/line/HologramLine.java +++ b/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/line/HologramLine.java @@ -22,10 +22,10 @@ import com.gmail.filoghost.holographicdisplays.api.Hologram; @Deprecated public interface HologramLine { - @Deprecated - public Hologram getParent(); - - @Deprecated - public void removeLine(); + @Deprecated + public Hologram getParent(); + + @Deprecated + public void removeLine(); } diff --git a/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/line/ItemLine.java b/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/line/ItemLine.java index ae91b116..2287dce2 100644 --- a/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/line/ItemLine.java +++ b/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/line/ItemLine.java @@ -22,10 +22,10 @@ import org.bukkit.inventory.ItemStack; @Deprecated public interface ItemLine extends CollectableLine, TouchableLine { - @Deprecated - public ItemStack getItemStack(); + @Deprecated + public ItemStack getItemStack(); - @Deprecated - public void setItemStack(ItemStack itemStack); - + @Deprecated + public void setItemStack(ItemStack itemStack); + } diff --git a/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/line/TextLine.java b/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/line/TextLine.java index bef1460e..35e704e5 100644 --- a/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/line/TextLine.java +++ b/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/line/TextLine.java @@ -20,10 +20,10 @@ package com.gmail.filoghost.holographicdisplays.api.line; @Deprecated public interface TextLine extends TouchableLine { - @Deprecated - public String getText(); - - @Deprecated - public void setText(String text); - + @Deprecated + public String getText(); + + @Deprecated + public void setText(String text); + } diff --git a/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/line/TouchableLine.java b/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/line/TouchableLine.java index e9a3c81c..25a6f3cb 100644 --- a/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/line/TouchableLine.java +++ b/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/line/TouchableLine.java @@ -22,10 +22,10 @@ import com.gmail.filoghost.holographicdisplays.api.handler.TouchHandler; @Deprecated public interface TouchableLine extends HologramLine { - @Deprecated - public void setTouchHandler(TouchHandler touchHandler); - - @Deprecated - public TouchHandler getTouchHandler(); - + @Deprecated + public void setTouchHandler(TouchHandler touchHandler); + + @Deprecated + public TouchHandler getTouchHandler(); + } diff --git a/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/placeholder/PlaceholderReplacer.java b/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/placeholder/PlaceholderReplacer.java index 72a364a4..9a74aade 100644 --- a/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/placeholder/PlaceholderReplacer.java +++ b/legacy-v2/src/main/java/com/gmail/filoghost/holographicdisplays/api/placeholder/PlaceholderReplacer.java @@ -20,7 +20,7 @@ package com.gmail.filoghost.holographicdisplays.api.placeholder; @Deprecated public interface PlaceholderReplacer { - @Deprecated - public String update(); - + @Deprecated + public String update(); + } diff --git a/nms/interfaces/pom.xml b/nms/interfaces/pom.xml index 7a15f4b0..bc9fff05 100644 --- a/nms/interfaces/pom.xml +++ b/nms/interfaces/pom.xml @@ -1,33 +1,33 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - - me.filoghost.holographicdisplays - holographicdisplays-nms - 3.0.0-SNAPSHOT - + + me.filoghost.holographicdisplays + holographicdisplays-nms + 3.0.0-SNAPSHOT + - holographicdisplays-nms-interfaces - HolographicDisplays NMS Interfaces + holographicdisplays-nms-interfaces + HolographicDisplays NMS Interfaces - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + - - - ${project.groupId} - holographicdisplays-api - - - - org.spigotmc - spigot-api - - - \ No newline at end of file + + + ${project.groupId} + holographicdisplays-api + + + + org.spigotmc + spigot-api + + + diff --git a/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/ChatComponentAdapter.java b/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/ChatComponentAdapter.java index dca1429d..0133de63 100644 --- a/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/ChatComponentAdapter.java +++ b/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/ChatComponentAdapter.java @@ -17,19 +17,19 @@ package me.filoghost.holographicdisplays.nms.interfaces; import java.util.List; public interface ChatComponentAdapter { - - T cast(Object chatComponentObject); - - String getText(T chatComponent); - - List getSiblings(T chatComponent); - - void addSibling(T chatComponent, T newSibling); - - default T cloneComponent(T chatComponent) { - return cloneComponent(chatComponent, getText(chatComponent)); - } - - T cloneComponent(T chatComponent, String newText); - -} \ No newline at end of file + + T cast(Object chatComponentObject); + + String getText(T chatComponent); + + List getSiblings(T chatComponent); + + void addSibling(T chatComponent, T newSibling); + + default T cloneComponent(T chatComponent) { + return cloneComponent(chatComponent, getText(chatComponent)); + } + + T cloneComponent(T chatComponent, String newText); + +} diff --git a/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/CustomNameHelper.java b/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/CustomNameHelper.java index 34e8b4fa..116cecc6 100644 --- a/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/CustomNameHelper.java +++ b/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/CustomNameHelper.java @@ -17,64 +17,64 @@ package me.filoghost.holographicdisplays.nms.interfaces; import java.util.List; public class CustomNameHelper { - - - public static String replaceCustomNameString(Object customNameObject, String target, String replacement) { - String customName = (String) customNameObject; - if (customName.contains(target)) { - return customName.replace(target, replacement); - } else { - return customName; - } - } - - public static T replaceCustomNameChatComponent(ChatComponentAdapter versionAdapter, Object customNameObject, String target, String replacement) { - // Custom name is expected to be a ChatComponentText with empty text and child components (called "siblings") that do not contain more components. - T rootComponent = versionAdapter.cast(customNameObject); - if (!versionAdapter.getText(rootComponent).isEmpty()) { - throw new IllegalArgumentException("Expected root component with empty text"); - } - - boolean[] childrenContainingTarget = null; - List children = versionAdapter.getSiblings(rootComponent); - int childrenSize = children.size(); - - for (int i = 0; i < childrenSize; i++) { - T childComponent = versionAdapter.cast(children.get(i)); + + + public static String replaceCustomNameString(Object customNameObject, String target, String replacement) { + String customName = (String) customNameObject; + if (customName.contains(target)) { + return customName.replace(target, replacement); + } else { + return customName; + } + } + + public static T replaceCustomNameChatComponent(ChatComponentAdapter versionAdapter, Object customNameObject, String target, String replacement) { + // Custom name is expected to be a ChatComponentText with empty text and child components (called "siblings") that do not contain more components. + T rootComponent = versionAdapter.cast(customNameObject); + if (!versionAdapter.getText(rootComponent).isEmpty()) { + throw new IllegalArgumentException("Expected root component with empty text"); + } + + boolean[] childrenContainingTarget = null; + List children = versionAdapter.getSiblings(rootComponent); + int childrenSize = children.size(); + + for (int i = 0; i < childrenSize; i++) { + T childComponent = versionAdapter.cast(children.get(i)); - if (!versionAdapter.getSiblings(childComponent).isEmpty()) { - throw new IllegalArgumentException("Expected child component without sub-nodes"); - } - - if (versionAdapter.getText(childComponent).contains(target)) { - // Lazy initialization for performance, since this method can be called frequently. - if (childrenContainingTarget == null) { - childrenContainingTarget = new boolean[childrenSize]; - } - childrenContainingTarget[i] = true; - } - } - - if (childrenContainingTarget == null) { - // No match found, return original unmodified object. - return rootComponent; - } - - // Clone all the objects and apply replacements where needed. - T clonedRoot = versionAdapter.cloneComponent(rootComponent); - for (int i = 0; i < childrenSize; i++) { - T childComponent = children.get(i); - - String newText = versionAdapter.getText(childComponent); - if (childrenContainingTarget[i]) { - newText = newText.replace(target, replacement); - } - - T clonedChild = versionAdapter.cloneComponent(childComponent, newText); - versionAdapter.addSibling(clonedRoot, clonedChild); - } - - return clonedRoot; - } + if (!versionAdapter.getSiblings(childComponent).isEmpty()) { + throw new IllegalArgumentException("Expected child component without sub-nodes"); + } + + if (versionAdapter.getText(childComponent).contains(target)) { + // Lazy initialization for performance, since this method can be called frequently. + if (childrenContainingTarget == null) { + childrenContainingTarget = new boolean[childrenSize]; + } + childrenContainingTarget[i] = true; + } + } + + if (childrenContainingTarget == null) { + // No match found, return original unmodified object. + return rootComponent; + } + + // Clone all the objects and apply replacements where needed. + T clonedRoot = versionAdapter.cloneComponent(rootComponent); + for (int i = 0; i < childrenSize; i++) { + T childComponent = children.get(i); + + String newText = versionAdapter.getText(childComponent); + if (childrenContainingTarget[i]) { + newText = newText.replace(target, replacement); + } + + T clonedChild = versionAdapter.cloneComponent(childComponent, newText); + versionAdapter.addSibling(clonedRoot, clonedChild); + } + + return clonedRoot; + } } diff --git a/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/ItemPickupManager.java b/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/ItemPickupManager.java index 4c9aa037..12f36b56 100644 --- a/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/ItemPickupManager.java +++ b/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/ItemPickupManager.java @@ -20,6 +20,6 @@ import org.bukkit.entity.Player; public interface ItemPickupManager { - public void handleItemLinePickup(Player player, PickupHandler pickupHandler, Hologram hologram); - + public void handleItemLinePickup(Player player, PickupHandler pickupHandler, Hologram hologram); + } diff --git a/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/NMSManager.java b/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/NMSManager.java index a2041da6..ae8ae4d0 100644 --- a/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/NMSManager.java +++ b/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/NMSManager.java @@ -24,22 +24,22 @@ import org.bukkit.World; import org.bukkit.inventory.ItemStack; public interface NMSManager { - - // A method to register all the custom entities of the plugin, it may fail. - public void setup() throws Exception; - - public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket); - - public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager); - - public NMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramLine parentPiece); - - public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity); + + // A method to register all the custom entities of the plugin, it may fail. + public void setup() throws Exception; + + public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket); + + public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager); + + public NMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramLine parentPiece); + + public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity); - public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity); + public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity); - public NMSEntityBase getNMSEntityBaseFromID(World bukkitWorld, int entityID); + public NMSEntityBase getNMSEntityBaseFromID(World bukkitWorld, int entityID); - public Object replaceCustomNameText(Object customNameObject, String target, String replacement); + public Object replaceCustomNameText(Object customNameObject, String target, String replacement); } diff --git a/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/entity/NMSArmorStand.java b/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/entity/NMSArmorStand.java index 96588be2..4cd9659d 100644 --- a/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/entity/NMSArmorStand.java +++ b/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/entity/NMSArmorStand.java @@ -15,8 +15,8 @@ package me.filoghost.holographicdisplays.nms.interfaces.entity; public interface NMSArmorStand extends NMSNameable { - - // Sets the location through NMS and optionally broadcast an additional teleport packet containing the location. - public void setLocationNMS(double x, double y, double z, boolean broadcastLocationPacket); + + // Sets the location through NMS and optionally broadcast an additional teleport packet containing the location. + public void setLocationNMS(double x, double y, double z, boolean broadcastLocationPacket); } diff --git a/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/entity/NMSCanMount.java b/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/entity/NMSCanMount.java index feb8f538..cd60d6b0 100644 --- a/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/entity/NMSCanMount.java +++ b/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/entity/NMSCanMount.java @@ -15,8 +15,8 @@ package me.filoghost.holographicdisplays.nms.interfaces.entity; public interface NMSCanMount extends NMSEntityBase { - - // Sets the passenger of this entity through NMS. - public void setPassengerOfNMS(NMSEntityBase vehicleBase); - + + // Sets the passenger of this entity through NMS. + public void setPassengerOfNMS(NMSEntityBase vehicleBase); + } diff --git a/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/entity/NMSEntityBase.java b/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/entity/NMSEntityBase.java index 34cdc313..74b1e157 100644 --- a/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/entity/NMSEntityBase.java +++ b/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/entity/NMSEntityBase.java @@ -20,20 +20,20 @@ import me.filoghost.holographicdisplays.api.line.HologramLine; * An interface to represent a custom NMS entity being part of a hologram. */ public interface NMSEntityBase { - - // Returns the linked CraftHologramLine, all the entities are part of a piece. Should never be null. - public HologramLine getHologramLine(); - - // Returns if the entity is dead through NMS. - public boolean isDeadNMS(); - - // Kills the entity through NMS. - public void killEntityNMS(); - - // The entity ID. - public int getIdNMS(); - - // Returns the bukkit entity. - public org.bukkit.entity.Entity getBukkitEntityNMS(); + + // Returns the linked CraftHologramLine, all the entities are part of a piece. Should never be null. + public HologramLine getHologramLine(); + + // Returns if the entity is dead through NMS. + public boolean isDeadNMS(); + + // Kills the entity through NMS. + public void killEntityNMS(); + + // The entity ID. + public int getIdNMS(); + + // Returns the bukkit entity. + public org.bukkit.entity.Entity getBukkitEntityNMS(); } diff --git a/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/entity/NMSItem.java b/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/entity/NMSItem.java index 13b25438..26add5d6 100644 --- a/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/entity/NMSItem.java +++ b/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/entity/NMSItem.java @@ -17,17 +17,17 @@ package me.filoghost.holographicdisplays.nms.interfaces.entity; import org.bukkit.inventory.ItemStack; public interface NMSItem extends NMSEntityBase, NMSCanMount { - - // Sets the location through NMS. - public void setLocationNMS(double x, double y, double z); - - // Sets the bukkit ItemStack for this item. - public void setItemStackNMS(ItemStack stack); - - // Sets if this item can be picked up by players. - public void allowPickup(boolean pickup); - - // The raw NMS ItemStack object. - public Object getRawItemStack(); - + + // Sets the location through NMS. + public void setLocationNMS(double x, double y, double z); + + // Sets the bukkit ItemStack for this item. + public void setItemStackNMS(ItemStack stack); + + // Sets if this item can be picked up by players. + public void allowPickup(boolean pickup); + + // The raw NMS ItemStack object. + public Object getRawItemStack(); + } diff --git a/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/entity/NMSNameable.java b/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/entity/NMSNameable.java index b6e4c7fb..5660fb9b 100644 --- a/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/entity/NMSNameable.java +++ b/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/entity/NMSNameable.java @@ -15,14 +15,14 @@ package me.filoghost.holographicdisplays.nms.interfaces.entity; public interface NMSNameable extends NMSEntityBase { - - // Sets a custom name as a String. - public void setCustomNameNMS(String name); - - // Returns the custom name as a String. - public String getCustomNameStringNMS(); + + // Sets a custom name as a String. + public void setCustomNameNMS(String name); + + // Returns the custom name as a String. + public String getCustomNameStringNMS(); - // Returns the custom name as version-dependent NMS object (String for MC 1.12 and below, ChatComponent for MC 1.13+ a ChatComponent). - public Object getCustomNameObjectNMS(); - + // Returns the custom name as version-dependent NMS object (String for MC 1.12 and below, ChatComponent for MC 1.13+ a ChatComponent). + public Object getCustomNameObjectNMS(); + } diff --git a/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/entity/NMSSlime.java b/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/entity/NMSSlime.java index 38f31476..89e15592 100644 --- a/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/entity/NMSSlime.java +++ b/nms/interfaces/src/main/java/me/filoghost/holographicdisplays/nms/interfaces/entity/NMSSlime.java @@ -15,8 +15,8 @@ package me.filoghost.holographicdisplays.nms.interfaces.entity; public interface NMSSlime extends NMSEntityBase, NMSCanMount { - - // Sets the location through NMS. - public void setLocationNMS(double x, double y, double z); - + + // Sets the location through NMS. + public void setLocationNMS(double x, double y, double z); + } diff --git a/nms/pom.xml b/nms/pom.xml index f9887807..6f02bde7 100644 --- a/nms/pom.xml +++ b/nms/pom.xml @@ -1,34 +1,34 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - - me.filoghost.holographicdisplays - holographicdisplays-parent - 3.0.0-SNAPSHOT - + + me.filoghost.holographicdisplays + holographicdisplays-parent + 3.0.0-SNAPSHOT + - holographicdisplays-nms - HolographicDisplays NMS - pom + holographicdisplays-nms + HolographicDisplays NMS + pom - - interfaces - v1_8_r2 - v1_8_r3 - v1_9_r1 - v1_9_r2 - v1_10_r1 - v1_11_r1 - v1_12_r1 - v1_13_r1 - v1_13_r2 - v1_14_r1 - v1_15_r1 - v1_16_r1 - v1_16_r2 - v1_16_r3 - + + interfaces + v1_8_r2 + v1_8_r3 + v1_9_r1 + v1_9_r2 + v1_10_r1 + v1_11_r1 + v1_12_r1 + v1_13_r1 + v1_13_r2 + v1_14_r1 + v1_15_r1 + v1_16_r1 + v1_16_r2 + v1_16_r3 + diff --git a/nms/v1_10_r1/pom.xml b/nms/v1_10_r1/pom.xml index b13deeac..4980185c 100644 --- a/nms/v1_10_r1/pom.xml +++ b/nms/v1_10_r1/pom.xml @@ -1,41 +1,41 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - - me.filoghost.holographicdisplays - holographicdisplays-nms - 3.0.0-SNAPSHOT - + + me.filoghost.holographicdisplays + holographicdisplays-nms + 3.0.0-SNAPSHOT + - holographicdisplays-nms-v1_10_r1 - HolographicDisplays NMS v1_10_R1 + holographicdisplays-nms-v1_10_r1 + HolographicDisplays NMS v1_10_R1 - - - nms-repo - https://repo.codemc.io/repository/nms/ - - + + + nms-repo + https://repo.codemc.io/repository/nms/ + + - - - ${project.groupId} - holographicdisplays-nms-interfaces - - - - ${project.groupId} - holographicdisplays-utils - - - - org.spigotmc - spigot - 1.10.2-R0.1-SNAPSHOT - provided - - + + + ${project.groupId} + holographicdisplays-nms-interfaces + + + + ${project.groupId} + holographicdisplays-utils + + + + org.spigotmc + spigot + 1.10.2-R0.1-SNAPSHOT + provided + + - \ No newline at end of file + 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 index 93f3602f..5573e233 100644 --- 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 @@ -29,64 +29,64 @@ 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. - } + 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 Armor stand class - @Override public void setArms(boolean arms) { } - @Override public void setBasePlate(boolean basePlate) { } - @Override public void setBodyPose(EulerAngle pose) { } - @Override public void setBoots(ItemStack item) { } - @Override public void setChestplate(ItemStack item) { } - @Override public void setHeadPose(EulerAngle pose) { } - @Override public void setHelmet(ItemStack item) { } - @Override public void setItemInHand(ItemStack item) { } - @Override public void setLeftArmPose(EulerAngle pose) { } - @Override public void setLeftLegPose(EulerAngle pose) { } - @Override public void setLeggings(ItemStack item) { } - @Override public void setRightArmPose(EulerAngle pose) { } - @Override public void setRightLegPose(EulerAngle pose) { } - @Override public void setSmall(boolean small) { } - @Override public void setVisible(boolean visible) { } - @Override public void setMarker(boolean marker) { } + // Methods from Armor stand class + @Override public void setArms(boolean arms) { } + @Override public void setBasePlate(boolean basePlate) { } + @Override public void setBodyPose(EulerAngle pose) { } + @Override public void setBoots(ItemStack item) { } + @Override public void setChestplate(ItemStack item) { } + @Override public void setHeadPose(EulerAngle pose) { } + @Override public void setHelmet(ItemStack item) { } + @Override public void setItemInHand(ItemStack item) { } + @Override public void setLeftArmPose(EulerAngle pose) { } + @Override public void setLeftLegPose(EulerAngle pose) { } + @Override public void setLeggings(ItemStack item) { } + @Override public void setRightArmPose(EulerAngle pose) { } + @Override public void setRightLegPose(EulerAngle pose) { } + @Override public void setSmall(boolean small) { } + @Override public void setVisible(boolean visible) { } + @Override public void setMarker(boolean marker) { } - // 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 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 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 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 index 4abc4445..533ad6c2 100644 --- 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 @@ -25,39 +25,39 @@ import org.bukkit.util.Vector; public class CraftNMSItem extends CraftItem { - public CraftNMSItem(CraftServer server, EntityNMSItem entity) { - super(server, entity); - } + 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. - } + // 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 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) { } - + // 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 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 index 6382f8f4..69a887ab 100644 --- 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 @@ -27,49 +27,49 @@ 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; } + 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 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 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 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) { } - + // 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 index de04f83e..59263276 100644 --- 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 @@ -35,208 +35,208 @@ import org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity; public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand { - private HologramLine parentPiece; - private String customName; - - public EntityNMSArmorStand(World world, HologramLine parentPiece) { - super(world); - super.setInvisible(true); - super.setSmall(true); - super.setArms(false); - super.setNoGravity(true); - super.setBasePlate(true); - super.setMarker(true); - super.collides = false; - this.parentPiece = parentPiece; - forceSetBoundingBox(new NullBoundingBox()); - - this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet. - } - - @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 (this.onGround) { - this.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 (this.onGround) { - this.onGround = false; - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT. - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT. - return false; - } + private HologramLine parentPiece; + private String customName; + + public EntityNMSArmorStand(World world, HologramLine parentPiece) { + super(world); + super.setInvisible(true); + super.setSmall(true); + super.setArms(false); + super.setNoGravity(true); + super.setBasePlate(true); + super.setMarker(true); + super.collides = false; + this.parentPiece = parentPiece; + forceSetBoundingBox(new NullBoundingBox()); + + this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet. + } + + @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 (this.onGround) { + this.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 (this.onGround) { + this.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) { - // Locks the custom name. - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Locks the custom name. - } + @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) { + // Locks the custom name. + } + + @Override + public void setCustomNameVisible(boolean visible) { + // Locks the custom name. + } - @Override - public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, ItemStack itemstack, EnumHand enumhand) { - // Prevent stand being equipped - return EnumInteractionResult.PASS; - } + @Override + public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, ItemStack itemstack, EnumHand enumhand) { + // Prevent stand being equipped + return EnumInteractionResult.PASS; + } - @Override - public boolean c(int i, ItemStack item) { - // Prevent stand being equipped - return false; - } + @Override + public boolean c(int i, ItemStack item) { + // Prevent stand being equipped + return false; + } - @Override - public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { - // Prevent stand being equipped - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Do not change it! - } - - 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 name) { - this.customName = Utils.limitLength(name, 300); - super.setCustomName(customName); - super.setCustomNameVisible(customName != null && !customName.isEmpty()); - } - - @Override - public String getCustomNameStringNMS() { - return this.customName; - } - - @Override - public Object getCustomNameObjectNMS() { - return super.getCustomName(); - } - - @Override - public void die() { - // Prevent being killed. - } - - @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, boolean broadcastLocationPacket) { - super.setPosition(x, y, z); - if (broadcastLocationPacket) { - broadcastLocationPacketNMS(); - } - } - - private void broadcastLocationPacketNMS() { - PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); - - for (Object obj : super.world.players) { - if (obj instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) obj; + @Override + public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { + // Prevent stand being equipped + } + + @Override + public void a(AxisAlignedBB boundingBox) { + // Do not change it! + } + + 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 name) { + this.customName = Utils.limitLength(name, 300); + super.setCustomName(customName); + super.setCustomNameVisible(customName != null && !customName.isEmpty()); + } + + @Override + public String getCustomNameStringNMS() { + return this.customName; + } + + @Override + public Object getCustomNameObjectNMS() { + return super.getCustomName(); + } + + @Override + public void die() { + // Prevent being killed. + } + + @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, boolean broadcastLocationPacket) { + super.setPosition(x, y, z); + if (broadcastLocationPacket) { + broadcastLocationPacketNMS(); + } + } + + private void broadcastLocationPacketNMS() { + PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); + + for (Object obj : super.world.players) { + if (obj instanceof EntityPlayer) { + EntityPlayer nmsPlayer = (EntityPlayer) obj; - double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ); - if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(teleportPacket); - } - } - } - } + double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ); + if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) { + nmsPlayer.playerConnection.sendPacket(teleportPacket); + } + } + } + } - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public int getIdNMS() { - return super.getId(); - } + @Override + public boolean isDeadNMS() { + return super.dead; + } + + @Override + public int getIdNMS() { + return super.getId(); + } - @Override - public HologramLine getHologramLine() { - return parentPiece; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } + @Override + public HologramLine getHologramLine() { + return parentPiece; + } + + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } } 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 index d621ba47..2f40c618 100644 --- 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 @@ -41,230 +41,230 @@ import org.bukkit.entity.Player; import java.util.logging.Level; public class EntityNMSItem extends EntityItem implements NMSItem { - - private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "au"); - - private ItemLine parentPiece; - private ItemPickupManager itemPickupManager; - - private int resendMountPacketTicks; - - public EntityNMSItem(World world, ItemLine piece, ItemPickupManager itemPickupManager) { - super(world); - super.pickupDelay = Integer.MAX_VALUE; - this.parentPiece = piece; - this.itemPickupManager = itemPickupManager; - } - - @Override - public void m() { - // Disable normal ticking for this entity. - - // So it won't get removed. - ticksLived = 0; - - if (resendMountPacketTicks++ > 20) { - resendMountPacketTicks = 0; - - if (bB() != null) { - // Send a packet near to "remind" players that the item is riding the armor stand (Spigot bug or client bug) - PacketPlayOutMount mountPacket = new PacketPlayOutMount(bB()); - - for (Object obj : super.world.players) { - if (obj instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) obj; - - double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ); - if (distanceSquared < 1024 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(mountPacket); - } - } - } - } - } - } - - @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 (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) { - itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent()); - // 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; - } + + private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "au"); + + private ItemLine parentPiece; + private ItemPickupManager itemPickupManager; + + private int resendMountPacketTicks; + + public EntityNMSItem(World world, ItemLine piece, ItemPickupManager itemPickupManager) { + super(world); + super.pickupDelay = Integer.MAX_VALUE; + this.parentPiece = piece; + this.itemPickupManager = itemPickupManager; + } + + @Override + public void m() { + // Disable normal ticking for this entity. + + // So it won't get removed. + ticksLived = 0; + + if (resendMountPacketTicks++ > 20) { + resendMountPacketTicks = 0; + + if (bB() != null) { + // Send a packet near to "remind" players that the item is riding the armor stand (Spigot bug or client bug) + PacketPlayOutMount mountPacket = new PacketPlayOutMount(bB()); + + for (Object obj : super.world.players) { + if (obj instanceof EntityPlayer) { + EntityPlayer nmsPlayer = (EntityPlayer) obj; + + double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ); + if (distanceSquared < 1024 && nmsPlayer.playerConnection != null) { + nmsPlayer.playerConnection.sendPacket(mountPacket); + } + } + } + } + } + } + + @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 (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) { + itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent()); + // 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 being killed. - } - - @Override - public boolean isAlive() { - // This override prevents items from being picked up by hoppers. - // Should have no side effects. - 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 being killed. + } + + @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 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 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(ItemUtils.ANTISTACK_LORE)); // Antistack lore - display.set("Lore", tagList); - - setItemStack(newItem); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public ItemLine getHologramLine() { - return parentPiece; - } - - @Override - public void allowPickup(boolean pickup) { - if (pickup) { - super.pickupDelay = 0; - } else { - super.pickupDelay = Integer.MAX_VALUE; - } - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public void setPassengerOfNMS(NMSEntityBase vehicleBase) { - if (vehicleBase == null || !(vehicleBase instanceof Entity)) { - // It should never dismount - return; - } - - Entity entity = (Entity) vehicleBase; + @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(ItemUtils.ANTISTACK_LORE)); // Antistack lore + display.set("Lore", tagList); + + setItemStack(newItem); + } + + @Override + public int getIdNMS() { + return super.getId(); + } + + @Override + public ItemLine getHologramLine() { + return parentPiece; + } + + @Override + public void allowPickup(boolean pickup) { + if (pickup) { + super.pickupDelay = 0; + } else { + super.pickupDelay = Integer.MAX_VALUE; + } + } + + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } + + @Override + public void setPassengerOfNMS(NMSEntityBase vehicleBase) { + if (vehicleBase == null || !(vehicleBase instanceof Entity)) { + // It should never dismount + return; + } + + Entity entity = (Entity) vehicleBase; - try { - if (super.bB() != null) { - Entity oldVehicle = super.bB(); - VEHICLE_FIELD.set(this, null); - oldVehicle.passengers.remove(this); - } + try { + if (super.bB() != null) { + Entity oldVehicle = super.bB(); + VEHICLE_FIELD.set(this, null); + oldVehicle.passengers.remove(this); + } - VEHICLE_FIELD.set(this, entity); - entity.passengers.clear(); - entity.passengers.add(this); + VEHICLE_FIELD.set(this, entity); + entity.passengers.clear(); + entity.passengers.add(this); - } catch (Throwable t) { - ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); - } - } + } catch (Throwable t) { + ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); + } + } - @Override - public Object getRawItemStack() { - return super.getItemStack(); - } + @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 index e2c1715f..0e310ab1 100644 --- 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 @@ -37,208 +37,208 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import java.util.logging.Level; public class EntityNMSSlime extends EntitySlime implements NMSSlime { - - private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "au"); + + private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "au"); - private HologramLine parentPiece; - - private int resendMountPacketTicks; - - public EntityNMSSlime(World world, HologramLine parentPiece) { - super(world); - super.persistent = true; - super.collides = false; - a(0.0F, 0.0F); - setSize(1); - setInvisible(true); - this.parentPiece = parentPiece; - 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; + private HologramLine parentPiece; + + private int resendMountPacketTicks; + + public EntityNMSSlime(World world, HologramLine parentPiece) { + super(world); + super.persistent = true; + super.collides = false; + a(0.0F, 0.0F); + setSize(1); + setInvisible(true); + this.parentPiece = parentPiece; + 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; - if (bB() != null) { - // Send a packet near to "remind" players that the slime is riding the armor stand (Spigot bug or client bug) - PacketPlayOutMount mountPacket = new PacketPlayOutMount(bB()); - - for (Object obj : super.world.players) { - if (obj instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) obj; - - double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ); - if (distanceSquared < 1024 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(mountPacket); - } - } - } - } - } - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity. - - // So it won't get removed. - ticksLived = 0; - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Do not change it! - } - - 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; - } + if (bB() != null) { + // Send a packet near to "remind" players that the slime is riding the armor stand (Spigot bug or client bug) + PacketPlayOutMount mountPacket = new PacketPlayOutMount(bB()); + + for (Object obj : super.world.players) { + if (obj instanceof EntityPlayer) { + EntityPlayer nmsPlayer = (EntityPlayer) obj; + + double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ); + if (distanceSquared < 1024 && nmsPlayer.playerConnection != null) { + nmsPlayer.playerConnection.sendPacket(mountPacket); + } + } + } + } + } + } + + @Override + public void inactiveTick() { + // Disable normal ticking for this entity. + + // So it won't get removed. + ticksLived = 0; + } + + @Override + public void a(AxisAlignedBB boundingBox) { + // Do not change it! + } + + 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) { - Bukkit.getPluginManager().callEvent(new PlayerInteractEntityEvent(((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(), getBukkitEntity())); // 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 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) { + Bukkit.getPluginManager().callEvent(new PlayerInteractEntityEvent(((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(), getBukkitEntity())); // 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) { - // Locks the custom name. - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Locks the custom name. - } - - @Override - public void a(SoundEffect soundeffect, float f, float f1) { - // Remove sounds. - } - - @Override - public void die() { - // Prevent being killed. - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSSlime(super.world.getServer(), this); - } - return super.bukkitEntity; - } + @Override + public void setCustomName(String customName) { + // Locks the custom name. + } + + @Override + public void setCustomNameVisible(boolean visible) { + // Locks the custom name. + } + + @Override + public void a(SoundEffect soundeffect, float f, float f1) { + // Remove sounds. + } + + @Override + public void die() { + // Prevent being killed. + } + + @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 HologramLine getHologramLine() { - return parentPiece; - } + @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 HologramLine getHologramLine() { + return parentPiece; + } - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public void setPassengerOfNMS(NMSEntityBase vehicleBase) { - if (vehicleBase == null || !(vehicleBase instanceof Entity)) { - // It should never dismount - return; - } - - Entity entity = (Entity) vehicleBase; - - try { - if (super.bB() != null) { - Entity oldVehicle = super.bB(); - VEHICLE_FIELD.set(this, null); - oldVehicle.passengers.remove(this); - } + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } + + @Override + public void setPassengerOfNMS(NMSEntityBase vehicleBase) { + if (vehicleBase == null || !(vehicleBase instanceof Entity)) { + // It should never dismount + return; + } + + Entity entity = (Entity) vehicleBase; + + try { + if (super.bB() != null) { + Entity oldVehicle = super.bB(); + VEHICLE_FIELD.set(this, null); + oldVehicle.passengers.remove(this); + } - VEHICLE_FIELD.set(this, entity); - entity.passengers.clear(); - entity.passengers.add(this); + VEHICLE_FIELD.set(this, entity); + entity.passengers.clear(); + entity.passengers.add(this); - } catch (Throwable t) { - ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); - } - } + } catch (Throwable t) { + ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); + } + } } diff --git a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/NmsManagerImpl.java b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/NmsManagerImpl.java index 32f1abf9..a2e8d6db 100644 --- a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/NmsManagerImpl.java +++ b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/NmsManagerImpl.java @@ -39,69 +39,69 @@ import java.lang.reflect.Method; import java.util.Map; public class NmsManagerImpl implements NMSManager { - - private static final ReflectField, String>> ENTITY_NAMES_BY_CLASS_FIELD = new ReflectField<>(EntityTypes.class, "d"); - private static final ReflectField, Integer>> ENTITY_IDS_BY_CLASS_FIELD = new ReflectField<>(EntityTypes.class, "f"); + + private static final ReflectField, String>> ENTITY_NAMES_BY_CLASS_FIELD = new ReflectField<>(EntityTypes.class, "d"); + private static final ReflectField, Integer>> ENTITY_IDS_BY_CLASS_FIELD = new ReflectField<>(EntityTypes.class, "f"); - private Method validateEntityMethod; - - @Override - public void setup() throws Exception { - registerCustomEntity(EntityNMSArmorStand.class, "ArmorStand", 30); - registerCustomEntity(EntityNMSItem.class, "Item", 1); - registerCustomEntity(EntityNMSSlime.class, "Slime", 55); - - validateEntityMethod = World.class.getDeclaredMethod("b", Entity.class); - validateEntityMethod.setAccessible(true); - } - - 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, Integer.valueOf(id)); - } - - @Override - public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager); - customItem.setLocationNMS(x, y, z); - customItem.setItemStackNMS(stack); - if (!addEntityToWorld(nmsWorld, customItem)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return customItem; - } - - @Override - public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramLine parentPiece) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece); - touchSlime.setLocationNMS(x, y, z); - if (!addEntityToWorld(nmsWorld, touchSlime)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return touchSlime; - } - - @Override - public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) { - WorldServer nmsWorld = ((CraftWorld) world).getHandle(); - EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece); - invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket); - if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return invisibleArmorStand; - } - - private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { - Validator.isTrue(Bukkit.isPrimaryThread(), "Async entity add"); - + private Method validateEntityMethod; + + @Override + public void setup() throws Exception { + registerCustomEntity(EntityNMSArmorStand.class, "ArmorStand", 30); + registerCustomEntity(EntityNMSItem.class, "Item", 1); + registerCustomEntity(EntityNMSSlime.class, "Slime", 55); + + validateEntityMethod = World.class.getDeclaredMethod("b", Entity.class); + validateEntityMethod.setAccessible(true); + } + + 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, Integer.valueOf(id)); + } + + @Override + public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager); + customItem.setLocationNMS(x, y, z); + customItem.setItemStackNMS(stack); + if (!addEntityToWorld(nmsWorld, customItem)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return customItem; + } + + @Override + public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramLine parentPiece) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece); + touchSlime.setLocationNMS(x, y, z); + if (!addEntityToWorld(nmsWorld, touchSlime)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return touchSlime; + } + + @Override + public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) { + WorldServer nmsWorld = ((CraftWorld) world).getHandle(); + EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece); + invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket); + if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return invisibleArmorStand; + } + + private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { + Validator.isTrue(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 + // This should never happen nmsEntity.dead = true; return false; } @@ -110,45 +110,45 @@ public class NmsManagerImpl implements NMSManager { nmsWorld.entityList.add(nmsEntity); try { - validateEntityMethod.invoke(nmsWorld, nmsEntity); - } catch (Exception e) { - e.printStackTrace(); - return false; - } + validateEntityMethod.invoke(nmsWorld, nmsEntity); + } catch (Exception e) { + e.printStackTrace(); + return false; + } return true; } - - @Override - public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase; - } + + @Override + public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { + return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase; + } - @Override - public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - - if (nmsEntity instanceof NMSEntityBase) { - return ((NMSEntityBase) nmsEntity); - } else { - return null; - } - } - - @Override - public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - Entity nmsEntity = nmsWorld.getEntity(entityID); - - if (nmsEntity instanceof NMSEntityBase) { - return ((NMSEntityBase) nmsEntity); - } else { - return null; - } - } - - @Override - public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { - return CustomNameHelper.replaceCustomNameString(customNameObject, target, replacement); - } + @Override + public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { + Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); + + if (nmsEntity instanceof NMSEntityBase) { + return ((NMSEntityBase) nmsEntity); + } else { + return null; + } + } + + @Override + public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + Entity nmsEntity = nmsWorld.getEntity(entityID); + + if (nmsEntity instanceof NMSEntityBase) { + return ((NMSEntityBase) nmsEntity); + } else { + return null; + } + } + + @Override + public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { + return CustomNameHelper.replaceCustomNameString(customNameObject, target, replacement); + } } 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 index bfb84c11..9a940419 100644 --- 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 @@ -21,103 +21,103 @@ import net.minecraft.server.v1_10_R1.Vec3D; public class NullBoundingBox extends AxisAlignedBB { - public NullBoundingBox() { - super(0, 0, 0, 0, 0, 0); - } + public NullBoundingBox() { + super(0, 0, 0, 0, 0, 0); + } - @Override - public double a() { - return 0.0; - } + @Override + public double a() { + return 0.0; + } - @Override - public double a(AxisAlignedBB arg0, double arg1) { - 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(AxisAlignedBB arg0) { + return this; + } - @Override - public AxisAlignedBB a(double arg0, double arg1, double arg2) { - 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 MovingObjectPosition b(Vec3D arg0, Vec3D arg1) { + return null; + } - @Override - public boolean a(Vec3D arg0) { - return false; - } + @Override + public boolean a(Vec3D arg0) { + return false; + } - @Override - public double b(AxisAlignedBB arg0, double arg1) { - return 0.0; - } + @Override + public double b(AxisAlignedBB arg0, double arg1) { + return 0.0; + } - @Override - public boolean b(AxisAlignedBB arg0) { - return false; - } + @Override + public boolean b(AxisAlignedBB arg0) { + return false; + } - @Override - public double c(AxisAlignedBB arg0, double arg1) { - return 0.0; - } + @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 c(double arg0, double arg1, double arg2) { + return this; + } - @Override - public AxisAlignedBB grow(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 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 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 b(Vec3D arg0) { + return false; + } - @Override - public boolean c(Vec3D arg0) { - return false; - } + @Override + public boolean c(Vec3D arg0) { + return false; + } - @Override - public boolean d(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 e(double arg0) { + return this; + } + + @Override + public AxisAlignedBB g(double arg0) { + return this; + } } diff --git a/nms/v1_11_r1/pom.xml b/nms/v1_11_r1/pom.xml index b3254684..97644e86 100644 --- a/nms/v1_11_r1/pom.xml +++ b/nms/v1_11_r1/pom.xml @@ -1,41 +1,41 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - - me.filoghost.holographicdisplays - holographicdisplays-nms - 3.0.0-SNAPSHOT - + + me.filoghost.holographicdisplays + holographicdisplays-nms + 3.0.0-SNAPSHOT + - holographicdisplays-nms-v1_11_r1 - HolographicDisplays NMS v1_11_R1 + holographicdisplays-nms-v1_11_r1 + HolographicDisplays NMS v1_11_R1 - - - nms-repo - https://repo.codemc.io/repository/nms/ - - + + + nms-repo + https://repo.codemc.io/repository/nms/ + + - - - ${project.groupId} - holographicdisplays-nms-interfaces - - - - ${project.groupId} - holographicdisplays-utils - - - - org.spigotmc - spigot - 1.11-R0.1-SNAPSHOT - provided - - + + + ${project.groupId} + holographicdisplays-nms-interfaces + + + + ${project.groupId} + holographicdisplays-utils + + + + org.spigotmc + spigot + 1.11-R0.1-SNAPSHOT + provided + + - \ No newline at end of file + 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 index 38d4bbae..bf770d4e 100644 --- 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 @@ -29,64 +29,64 @@ 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. - } + 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 Armor stand class - @Override public void setArms(boolean arms) { } - @Override public void setBasePlate(boolean basePlate) { } - @Override public void setBodyPose(EulerAngle pose) { } - @Override public void setBoots(ItemStack item) { } - @Override public void setChestplate(ItemStack item) { } - @Override public void setHeadPose(EulerAngle pose) { } - @Override public void setHelmet(ItemStack item) { } - @Override public void setItemInHand(ItemStack item) { } - @Override public void setLeftArmPose(EulerAngle pose) { } - @Override public void setLeftLegPose(EulerAngle pose) { } - @Override public void setLeggings(ItemStack item) { } - @Override public void setRightArmPose(EulerAngle pose) { } - @Override public void setRightLegPose(EulerAngle pose) { } - @Override public void setSmall(boolean small) { } - @Override public void setVisible(boolean visible) { } - @Override public void setMarker(boolean marker) { } + // Methods from Armor stand class + @Override public void setArms(boolean arms) { } + @Override public void setBasePlate(boolean basePlate) { } + @Override public void setBodyPose(EulerAngle pose) { } + @Override public void setBoots(ItemStack item) { } + @Override public void setChestplate(ItemStack item) { } + @Override public void setHeadPose(EulerAngle pose) { } + @Override public void setHelmet(ItemStack item) { } + @Override public void setItemInHand(ItemStack item) { } + @Override public void setLeftArmPose(EulerAngle pose) { } + @Override public void setLeftLegPose(EulerAngle pose) { } + @Override public void setLeggings(ItemStack item) { } + @Override public void setRightArmPose(EulerAngle pose) { } + @Override public void setRightLegPose(EulerAngle pose) { } + @Override public void setSmall(boolean small) { } + @Override public void setVisible(boolean visible) { } + @Override public void setMarker(boolean marker) { } - // 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 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 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 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 index 37338eb5..6bf00e11 100644 --- 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 @@ -25,39 +25,39 @@ import org.bukkit.util.Vector; public class CraftNMSItem extends CraftItem { - public CraftNMSItem(CraftServer server, EntityNMSItem entity) { - super(server, entity); - } + 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. - } + // 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 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) { } - + // 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 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 index 53a52fcd..66251971 100644 --- 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 @@ -27,49 +27,49 @@ 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; } + 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 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 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 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) { } - + // 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 index f3dd3587..188fa14a 100644 --- 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 @@ -35,208 +35,208 @@ import org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity; public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand { - private HologramLine parentPiece; - private String customName; - - public EntityNMSArmorStand(World world, HologramLine parentPiece) { - super(world); - super.setInvisible(true); - super.setSmall(true); - super.setArms(false); - super.setNoGravity(true); - super.setBasePlate(true); - super.setMarker(true); - super.collides = false; - this.parentPiece = parentPiece; - forceSetBoundingBox(new NullBoundingBox()); - - this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet. - } - - @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 (this.onGround) { - this.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 (this.onGround) { - this.onGround = false; - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT. - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT. - return false; - } + private HologramLine parentPiece; + private String customName; + + public EntityNMSArmorStand(World world, HologramLine parentPiece) { + super(world); + super.setInvisible(true); + super.setSmall(true); + super.setArms(false); + super.setNoGravity(true); + super.setBasePlate(true); + super.setMarker(true); + super.collides = false; + this.parentPiece = parentPiece; + forceSetBoundingBox(new NullBoundingBox()); + + this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet. + } + + @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 (this.onGround) { + this.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 (this.onGround) { + this.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) { - // Locks the custom name. - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Locks the custom name. - } + @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) { + // Locks the custom name. + } + + @Override + public void setCustomNameVisible(boolean visible) { + // Locks the custom name. + } - @Override - public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) { - // Prevent stand being equipped - return EnumInteractionResult.PASS; - } + @Override + public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) { + // Prevent stand being equipped + return EnumInteractionResult.PASS; + } - @Override - public boolean c(int i, ItemStack item) { - // Prevent stand being equipped - return false; - } + @Override + public boolean c(int i, ItemStack item) { + // Prevent stand being equipped + return false; + } - @Override - public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { - // Prevent stand being equipped - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Do not change it! - } - - 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 name) { - this.customName = Utils.limitLength(name, 300); - super.setCustomName(customName); - super.setCustomNameVisible(customName != null && !customName.isEmpty()); - } - - @Override - public String getCustomNameStringNMS() { - return this.customName; - } - - @Override - public Object getCustomNameObjectNMS() { - return super.getCustomName(); - } - - @Override - public void die() { - // Prevent being killed. - } - - @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, boolean broadcastLocationPacket) { - super.setPosition(x, y, z); - if (broadcastLocationPacket) { - broadcastLocationPacketNMS(); - } - } - - private void broadcastLocationPacketNMS() { - PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); - - for (Object obj : super.world.players) { - if (obj instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) obj; + @Override + public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { + // Prevent stand being equipped + } + + @Override + public void a(AxisAlignedBB boundingBox) { + // Do not change it! + } + + 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 name) { + this.customName = Utils.limitLength(name, 300); + super.setCustomName(customName); + super.setCustomNameVisible(customName != null && !customName.isEmpty()); + } + + @Override + public String getCustomNameStringNMS() { + return this.customName; + } + + @Override + public Object getCustomNameObjectNMS() { + return super.getCustomName(); + } + + @Override + public void die() { + // Prevent being killed. + } + + @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, boolean broadcastLocationPacket) { + super.setPosition(x, y, z); + if (broadcastLocationPacket) { + broadcastLocationPacketNMS(); + } + } + + private void broadcastLocationPacketNMS() { + PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); + + for (Object obj : super.world.players) { + if (obj instanceof EntityPlayer) { + EntityPlayer nmsPlayer = (EntityPlayer) obj; - double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ); - if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(teleportPacket); - } - } - } - } + double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ); + if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) { + nmsPlayer.playerConnection.sendPacket(teleportPacket); + } + } + } + } - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public int getIdNMS() { - return super.getId(); - } + @Override + public boolean isDeadNMS() { + return super.dead; + } + + @Override + public int getIdNMS() { + return super.getId(); + } - @Override - public HologramLine getHologramLine() { - return parentPiece; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } + @Override + public HologramLine getHologramLine() { + return parentPiece; + } + + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } } 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 index e635c401..471e93b8 100644 --- 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 @@ -39,207 +39,207 @@ import org.bukkit.entity.Player; import java.util.logging.Level; public class EntityNMSItem extends EntityItem implements NMSItem { - - private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "au"); - - private ItemLine parentPiece; - private ItemPickupManager itemPickupManager; - - public EntityNMSItem(World world, ItemLine piece, ItemPickupManager itemPickupManager) { - super(world); - super.pickupDelay = 32767; // Lock the item pickup delay, also prevents entities from picking up the item - this.parentPiece = piece; - this.itemPickupManager = itemPickupManager; - } - - @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 (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) { - itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent()); - // 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; - } + + private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "au"); + + private ItemLine parentPiece; + private ItemPickupManager itemPickupManager; + + public EntityNMSItem(World world, ItemLine piece, ItemPickupManager itemPickupManager) { + super(world); + super.pickupDelay = 32767; // Lock the item pickup delay, also prevents entities from picking up the item + this.parentPiece = piece; + this.itemPickupManager = itemPickupManager; + } + + @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 (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) { + itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent()); + // 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 being killed. - } - - @Override - public boolean isAlive() { - // This override prevents items from being picked up by hoppers. - // Should have no side effects. - 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 being killed. + } + + @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 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 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); // ItemStack.a is returned if the stack is null, invalid or the material is not an Item - - if (newItem == null || newItem == ItemStack.a) { - newItem = new ItemStack(Blocks.BEDROCK); - } + @Override + public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) { + ItemStack newItem = CraftItemStack.asNMSCopy(stack); // ItemStack.a is returned if the stack is null, invalid or the material is not an Item + + if (newItem == null || newItem == ItemStack.a) { + 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); - } + 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(ItemUtils.ANTISTACK_LORE)); // Antistack lore - display.set("Lore", tagList); - - setItemStack(newItem); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public ItemLine getHologramLine() { - return parentPiece; - } - - @Override - public void allowPickup(boolean pickup) { - if (pickup) { - super.pickupDelay = 0; - } else { - super.pickupDelay = 32767; - } - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public void setPassengerOfNMS(NMSEntityBase vehicleBase) { - if (vehicleBase == null || !(vehicleBase instanceof Entity)) { - // It should never dismount - return; - } - - Entity entity = (Entity) vehicleBase; + NBTTagList tagList = new NBTTagList(); + tagList.add(new NBTTagString(ItemUtils.ANTISTACK_LORE)); // Antistack lore + display.set("Lore", tagList); + + setItemStack(newItem); + } + + @Override + public int getIdNMS() { + return super.getId(); + } + + @Override + public ItemLine getHologramLine() { + return parentPiece; + } + + @Override + public void allowPickup(boolean pickup) { + if (pickup) { + super.pickupDelay = 0; + } else { + super.pickupDelay = 32767; + } + } + + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } + + @Override + public void setPassengerOfNMS(NMSEntityBase vehicleBase) { + if (vehicleBase == null || !(vehicleBase instanceof Entity)) { + // It should never dismount + return; + } + + Entity entity = (Entity) vehicleBase; - try { - if (super.bB() != null) { - Entity oldVehicle = super.bB(); - VEHICLE_FIELD.set(this, null); - oldVehicle.passengers.remove(this); - } + try { + if (super.bB() != null) { + Entity oldVehicle = super.bB(); + VEHICLE_FIELD.set(this, null); + oldVehicle.passengers.remove(this); + } - VEHICLE_FIELD.set(this, entity); - entity.passengers.clear(); - entity.passengers.add(this); + VEHICLE_FIELD.set(this, entity); + entity.passengers.clear(); + entity.passengers.add(this); - } catch (Throwable t) { - ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); - } - } + } catch (Throwable t) { + ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); + } + } - @Override - public Object getRawItemStack() { - return super.getItemStack(); - } + @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 index 93eb148f..28d82270 100644 --- 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 @@ -35,186 +35,186 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import java.util.logging.Level; public class EntityNMSSlime extends EntitySlime implements NMSSlime { - - private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "au"); + + private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "au"); - private HologramLine parentPiece; - - public EntityNMSSlime(World world, HologramLine parentPiece) { - super(world); - super.persistent = true; - super.collides = false; - a(0.0F, 0.0F); - setSize(1, false); - setInvisible(true); - this.parentPiece = parentPiece; - 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) { - // Do not change it! - } - - 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; - } + private HologramLine parentPiece; + + public EntityNMSSlime(World world, HologramLine parentPiece) { + super(world); + super.persistent = true; + super.collides = false; + a(0.0F, 0.0F); + setSize(1, false); + setInvisible(true); + this.parentPiece = parentPiece; + 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) { + // Do not change it! + } + + 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) { - Bukkit.getPluginManager().callEvent(new PlayerInteractEntityEvent(((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(), getBukkitEntity())); // 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 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) { + Bukkit.getPluginManager().callEvent(new PlayerInteractEntityEvent(((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(), getBukkitEntity())); // 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) { - // Locks the custom name. - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Locks the custom name. - } - - @Override - public void a(SoundEffect soundeffect, float f, float f1) { - // Remove sounds. - } - - @Override - public void die() { - // Prevent being killed. - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSSlime(super.world.getServer(), this); - } - return super.bukkitEntity; - } + @Override + public void setCustomName(String customName) { + // Locks the custom name. + } + + @Override + public void setCustomNameVisible(boolean visible) { + // Locks the custom name. + } + + @Override + public void a(SoundEffect soundeffect, float f, float f1) { + // Remove sounds. + } + + @Override + public void die() { + // Prevent being killed. + } + + @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 HologramLine getHologramLine() { - return parentPiece; - } + @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 HologramLine getHologramLine() { + return parentPiece; + } - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public void setPassengerOfNMS(NMSEntityBase vehicleBase) { - if (vehicleBase == null || !(vehicleBase instanceof Entity)) { - // It should never dismount - return; - } - - Entity entity = (Entity) vehicleBase; - - try { - if (super.bB() != null) { - Entity oldVehicle = super.bB(); - VEHICLE_FIELD.set(this, null); - oldVehicle.passengers.remove(this); - } + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } + + @Override + public void setPassengerOfNMS(NMSEntityBase vehicleBase) { + if (vehicleBase == null || !(vehicleBase instanceof Entity)) { + // It should never dismount + return; + } + + Entity entity = (Entity) vehicleBase; + + try { + if (super.bB() != null) { + Entity oldVehicle = super.bB(); + VEHICLE_FIELD.set(this, null); + oldVehicle.passengers.remove(this); + } - VEHICLE_FIELD.set(this, entity); - entity.passengers.clear(); - entity.passengers.add(this); + VEHICLE_FIELD.set(this, entity); + entity.passengers.clear(); + entity.passengers.add(this); - } catch (Throwable t) { - ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); - } - } + } catch (Throwable t) { + ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); + } + } } diff --git a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/NmsManagerImpl.java b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/NmsManagerImpl.java index 075a1867..c29853c4 100644 --- a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/NmsManagerImpl.java +++ b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/NmsManagerImpl.java @@ -40,77 +40,77 @@ import org.bukkit.inventory.ItemStack; import java.lang.reflect.Method; public class NmsManagerImpl implements NMSManager { - - private static final ReflectField>> REGISTRY_ID_FIELD = new ReflectField<>(RegistryMaterials.class, "a"); - private static final ReflectField ID_TO_CLASS_MAP_FIELD = new ReflectField<>(RegistryID.class, "d"); + + private static final ReflectField>> REGISTRY_ID_FIELD = new ReflectField<>(RegistryMaterials.class, "a"); + private static final ReflectField ID_TO_CLASS_MAP_FIELD = new ReflectField<>(RegistryID.class, "d"); - private Method validateEntityMethod; - - @Override - public void setup() throws Exception { - validateEntityMethod = World.class.getDeclaredMethod("b", Entity.class); - validateEntityMethod.setAccessible(true); - - 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]; + private Method validateEntityMethod; + + @Override + public void setup() throws Exception { + validateEntityMethod = World.class.getDeclaredMethod("b", Entity.class); + validateEntityMethod.setAccessible(true); + + 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); + // 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, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager); - customItem.setLocationNMS(x, y, z); - customItem.setItemStackNMS(stack); - if (!addEntityToWorld(nmsWorld, customItem)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return customItem; - } - - @Override - public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramLine parentPiece) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece); - touchSlime.setLocationNMS(x, y, z); - if (!addEntityToWorld(nmsWorld, touchSlime)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return touchSlime; - } - - @Override - public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) { - WorldServer nmsWorld = ((CraftWorld) world).getHandle(); - EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece); - invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket); - if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return invisibleArmorStand; - } - - private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { - Validator.isTrue(Bukkit.isPrimaryThread(), "Async entity add"); - + // Restore the ID -> entity class mapping. + idToClassMap[id] = oldValue; + } + + @Override + public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager); + customItem.setLocationNMS(x, y, z); + customItem.setItemStackNMS(stack); + if (!addEntityToWorld(nmsWorld, customItem)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return customItem; + } + + @Override + public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramLine parentPiece) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece); + touchSlime.setLocationNMS(x, y, z); + if (!addEntityToWorld(nmsWorld, touchSlime)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return touchSlime; + } + + @Override + public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) { + WorldServer nmsWorld = ((CraftWorld) world).getHandle(); + EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece); + invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket); + if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return invisibleArmorStand; + } + + private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { + Validator.isTrue(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 + // This should never happen nmsEntity.dead = true; return false; } @@ -119,45 +119,45 @@ public class NmsManagerImpl implements NMSManager { nmsWorld.entityList.add(nmsEntity); try { - validateEntityMethod.invoke(nmsWorld, nmsEntity); - } catch (Exception e) { - e.printStackTrace(); - return false; - } + validateEntityMethod.invoke(nmsWorld, nmsEntity); + } catch (Exception e) { + e.printStackTrace(); + return false; + } return true; } - - @Override - public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase; - } + + @Override + public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { + return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase; + } - @Override - public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - - if (nmsEntity instanceof NMSEntityBase) { - return ((NMSEntityBase) nmsEntity); - } else { - return null; - } - } - - @Override - public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - Entity nmsEntity = nmsWorld.getEntity(entityID); - - if (nmsEntity instanceof NMSEntityBase) { - return ((NMSEntityBase) nmsEntity); - } else { - return null; - } - } - - @Override - public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { - return CustomNameHelper.replaceCustomNameString(customNameObject, target, replacement); - } + @Override + public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { + Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); + + if (nmsEntity instanceof NMSEntityBase) { + return ((NMSEntityBase) nmsEntity); + } else { + return null; + } + } + + @Override + public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + Entity nmsEntity = nmsWorld.getEntity(entityID); + + if (nmsEntity instanceof NMSEntityBase) { + return ((NMSEntityBase) nmsEntity); + } else { + return null; + } + } + + @Override + public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { + return CustomNameHelper.replaceCustomNameString(customNameObject, target, replacement); + } } 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 index 91f8f542..c813d0f7 100644 --- 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 @@ -21,121 +21,121 @@ import net.minecraft.server.v1_11_R1.Vec3D; public class NullBoundingBox extends AxisAlignedBB { - public NullBoundingBox() { - super(0, 0, 0, 0, 0, 0); - } + public NullBoundingBox() { + super(0, 0, 0, 0, 0, 0); + } - @Override - public double a() { - return 0.0; - } + @Override + public double a() { + return 0.0; + } - @Override - public double a(AxisAlignedBB arg0, double arg1) { - 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(AxisAlignedBB arg0) { + return this; + } - @Override - public AxisAlignedBB a(double arg0, double arg1, double arg2) { - 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 MovingObjectPosition b(Vec3D arg0, Vec3D arg1) { + return null; + } - @Override - public double b(AxisAlignedBB arg0, double arg1) { - return 0.0; - } + @Override + public double b(AxisAlignedBB arg0, double arg1) { + return 0.0; + } - @Override - public double c(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 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 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 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 b(Vec3D arg0) { + return false; + } - @Override - public boolean c(Vec3D arg0) { - return false; - } + @Override + public boolean c(Vec3D arg0) { + return false; + } - @Override - public boolean d(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 e(double arg0) { + return this; + } + + @Override + public AxisAlignedBB g(double arg0) { + return this; + } - @Override - public AxisAlignedBB a(Vec3D arg0) { - return this; - } + @Override + public AxisAlignedBB a(Vec3D arg0) { + return this; + } - @Override - public AxisAlignedBB b(AxisAlignedBB 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 AxisAlignedBB b(double arg0, double arg1, double arg2) { + return this; + } - @Override - public boolean c(AxisAlignedBB arg0) { - return false; - } + @Override + public boolean c(AxisAlignedBB arg0) { + return false; + } - @Override - public AxisAlignedBB d(double arg0, double arg1, double arg2) { - return this; - } + @Override + public AxisAlignedBB d(double arg0, double arg1, double arg2) { + return this; + } - @Override - public boolean e(Vec3D arg0) { - return false; - } - - - + @Override + public boolean e(Vec3D arg0) { + return false; + } + + + } diff --git a/nms/v1_12_r1/pom.xml b/nms/v1_12_r1/pom.xml index 2ad2a380..f989b5c9 100644 --- a/nms/v1_12_r1/pom.xml +++ b/nms/v1_12_r1/pom.xml @@ -1,41 +1,41 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - - me.filoghost.holographicdisplays - holographicdisplays-nms - 3.0.0-SNAPSHOT - + + me.filoghost.holographicdisplays + holographicdisplays-nms + 3.0.0-SNAPSHOT + - holographicdisplays-nms-v1_12_r1 - HolographicDisplays NMS v1_12_R1 + holographicdisplays-nms-v1_12_r1 + HolographicDisplays NMS v1_12_R1 - - - nms-repo - https://repo.codemc.io/repository/nms/ - - + + + nms-repo + https://repo.codemc.io/repository/nms/ + + - - - ${project.groupId} - holographicdisplays-nms-interfaces - - - - ${project.groupId} - holographicdisplays-utils - - - - org.spigotmc - spigot - 1.12-R0.1-SNAPSHOT - provided - - + + + ${project.groupId} + holographicdisplays-nms-interfaces + + + + ${project.groupId} + holographicdisplays-utils + + + + org.spigotmc + spigot + 1.12-R0.1-SNAPSHOT + provided + + - \ No newline at end of file + 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 index 5c3f510a..41b33dd2 100644 --- 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 @@ -29,65 +29,65 @@ 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. - } + 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 Armor stand class - - @Override public void setArms(boolean arms) { } - @Override public void setBasePlate(boolean basePlate) { } - @Override public void setBodyPose(EulerAngle pose) { } - @Override public void setBoots(ItemStack item) { } - @Override public void setChestplate(ItemStack item) { } - @Override public void setHeadPose(EulerAngle pose) { } - @Override public void setHelmet(ItemStack item) { } - @Override public void setItemInHand(ItemStack item) { } - @Override public void setLeftArmPose(EulerAngle pose) { } - @Override public void setLeftLegPose(EulerAngle pose) { } - @Override public void setLeggings(ItemStack item) { } - @Override public void setRightArmPose(EulerAngle pose) { } - @Override public void setRightLegPose(EulerAngle pose) { } - @Override public void setSmall(boolean small) { } - @Override public void setVisible(boolean visible) { } - @Override public void setMarker(boolean marker) { } + // Methods from Armor stand class + + @Override public void setArms(boolean arms) { } + @Override public void setBasePlate(boolean basePlate) { } + @Override public void setBodyPose(EulerAngle pose) { } + @Override public void setBoots(ItemStack item) { } + @Override public void setChestplate(ItemStack item) { } + @Override public void setHeadPose(EulerAngle pose) { } + @Override public void setHelmet(ItemStack item) { } + @Override public void setItemInHand(ItemStack item) { } + @Override public void setLeftArmPose(EulerAngle pose) { } + @Override public void setLeftLegPose(EulerAngle pose) { } + @Override public void setLeggings(ItemStack item) { } + @Override public void setRightArmPose(EulerAngle pose) { } + @Override public void setRightLegPose(EulerAngle pose) { } + @Override public void setSmall(boolean small) { } + @Override public void setVisible(boolean visible) { } + @Override public void setMarker(boolean marker) { } - // 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 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 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 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 index 69468e26..cdc8d330 100644 --- 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 @@ -25,39 +25,39 @@ import org.bukkit.util.Vector; public class CraftNMSItem extends CraftItem { - public CraftNMSItem(CraftServer server, EntityNMSItem entity) { - super(server, entity); - } + 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. - } + // 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 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) { } - + // 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 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 index fca48a19..1ea51ad8 100644 --- 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 @@ -27,49 +27,49 @@ 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; } + 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 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 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 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) { } - + // 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 index 2365af55..d45fbcf5 100644 --- 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 @@ -35,208 +35,208 @@ import org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity; public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand { - private HologramLine parentPiece; - private String customName; - - public EntityNMSArmorStand(World world, HologramLine parentPiece) { - super(world); - super.setInvisible(true); - super.setSmall(true); - super.setArms(false); - super.setNoGravity(true); - super.setBasePlate(true); - super.setMarker(true); - super.collides = false; - this.parentPiece = parentPiece; - forceSetBoundingBox(new NullBoundingBox()); - - this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet. - } - - @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 (this.onGround) { - this.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 (this.onGround) { - this.onGround = false; - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT. - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT. - return false; - } + private HologramLine parentPiece; + private String customName; + + public EntityNMSArmorStand(World world, HologramLine parentPiece) { + super(world); + super.setInvisible(true); + super.setSmall(true); + super.setArms(false); + super.setNoGravity(true); + super.setBasePlate(true); + super.setMarker(true); + super.collides = false; + this.parentPiece = parentPiece; + forceSetBoundingBox(new NullBoundingBox()); + + this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet. + } + + @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 (this.onGround) { + this.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 (this.onGround) { + this.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) { - // Locks the custom name. - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Locks the custom name. - } + @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) { + // Locks the custom name. + } + + @Override + public void setCustomNameVisible(boolean visible) { + // Locks the custom name. + } - @Override - public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) { - // Prevent stand being equipped - return EnumInteractionResult.PASS; - } + @Override + public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) { + // Prevent stand being equipped + return EnumInteractionResult.PASS; + } - @Override - public boolean c(int i, ItemStack item) { - // Prevent stand being equipped - return false; - } + @Override + public boolean c(int i, ItemStack item) { + // Prevent stand being equipped + return false; + } - @Override - public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { - // Prevent stand being equipped - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Do not change it! - } - - 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 name) { - this.customName = Utils.limitLength(name, 300); - super.setCustomName(customName); - super.setCustomNameVisible(customName != null && !customName.isEmpty()); - } - - @Override - public String getCustomNameStringNMS() { - return this.customName; - } - - @Override - public Object getCustomNameObjectNMS() { - return super.getCustomName(); - } - - @Override - public void die() { - // Prevent being killed. - } - - @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, boolean broadcastLocationPacket) { - super.setPosition(x, y, z); - if (broadcastLocationPacket) { - broadcastLocationPacketNMS(); - } - } - - private void broadcastLocationPacketNMS() { - PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); - - for (Object obj : super.world.players) { - if (obj instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) obj; + @Override + public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { + // Prevent stand being equipped + } + + @Override + public void a(AxisAlignedBB boundingBox) { + // Do not change it! + } + + 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 name) { + this.customName = Utils.limitLength(name, 300); + super.setCustomName(customName); + super.setCustomNameVisible(customName != null && !customName.isEmpty()); + } + + @Override + public String getCustomNameStringNMS() { + return this.customName; + } + + @Override + public Object getCustomNameObjectNMS() { + return super.getCustomName(); + } + + @Override + public void die() { + // Prevent being killed. + } + + @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, boolean broadcastLocationPacket) { + super.setPosition(x, y, z); + if (broadcastLocationPacket) { + broadcastLocationPacketNMS(); + } + } + + private void broadcastLocationPacketNMS() { + PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); + + for (Object obj : super.world.players) { + if (obj instanceof EntityPlayer) { + EntityPlayer nmsPlayer = (EntityPlayer) obj; - double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ); - if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(teleportPacket); - } - } - } - } + double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ); + if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) { + nmsPlayer.playerConnection.sendPacket(teleportPacket); + } + } + } + } - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public int getIdNMS() { - return super.getId(); - } + @Override + public boolean isDeadNMS() { + return super.dead; + } + + @Override + public int getIdNMS() { + return super.getId(); + } - @Override - public HologramLine getHologramLine() { - return parentPiece; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } + @Override + public HologramLine getHologramLine() { + return parentPiece; + } + + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } } 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 index 24878f3d..97e1aef0 100644 --- 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 @@ -39,207 +39,207 @@ import org.bukkit.entity.Player; import java.util.logging.Level; public class EntityNMSItem extends EntityItem implements NMSItem { - - private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "au"); - - private ItemLine parentPiece; - private ItemPickupManager itemPickupManager; - - public EntityNMSItem(World world, ItemLine piece, ItemPickupManager itemPickupManager) { - super(world); - super.pickupDelay = 32767; // Lock the item pickup delay, also prevents entities from picking up the item - this.parentPiece = piece; - this.itemPickupManager = itemPickupManager; - } - - @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 (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) { - itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent()); - // 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; - } + + private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "au"); + + private ItemLine parentPiece; + private ItemPickupManager itemPickupManager; + + public EntityNMSItem(World world, ItemLine piece, ItemPickupManager itemPickupManager) { + super(world); + super.pickupDelay = 32767; // Lock the item pickup delay, also prevents entities from picking up the item + this.parentPiece = piece; + this.itemPickupManager = itemPickupManager; + } + + @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 (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) { + itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent()); + // 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 being killed. - } - - @Override - public boolean isAlive() { - // This override prevents items from being picked up by hoppers. - // Should have no side effects. - 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 being killed. + } + + @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 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 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); // ItemStack.a is returned if the stack is null, invalid or the material is not an Item - - if (newItem == null || newItem == ItemStack.a) { - newItem = new ItemStack(Blocks.BEDROCK); - } + @Override + public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) { + ItemStack newItem = CraftItemStack.asNMSCopy(stack); // ItemStack.a is returned if the stack is null, invalid or the material is not an Item + + if (newItem == null || newItem == ItemStack.a) { + 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); - } + 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(ItemUtils.ANTISTACK_LORE)); // Antistack lore - display.set("Lore", tagList); - - setItemStack(newItem); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public ItemLine getHologramLine() { - return parentPiece; - } - - @Override - public void allowPickup(boolean pickup) { - if (pickup) { - super.pickupDelay = 0; - } else { - super.pickupDelay = 32767; - } - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public void setPassengerOfNMS(NMSEntityBase vehicleBase) { - if (vehicleBase == null || !(vehicleBase instanceof Entity)) { - // It should never dismount - return; - } - - Entity entity = (Entity) vehicleBase; + NBTTagList tagList = new NBTTagList(); + tagList.add(new NBTTagString(ItemUtils.ANTISTACK_LORE)); // Antistack lore + display.set("Lore", tagList); + + setItemStack(newItem); + } + + @Override + public int getIdNMS() { + return super.getId(); + } + + @Override + public ItemLine getHologramLine() { + return parentPiece; + } + + @Override + public void allowPickup(boolean pickup) { + if (pickup) { + super.pickupDelay = 0; + } else { + super.pickupDelay = 32767; + } + } + + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } + + @Override + public void setPassengerOfNMS(NMSEntityBase vehicleBase) { + if (vehicleBase == null || !(vehicleBase instanceof Entity)) { + // It should never dismount + return; + } + + Entity entity = (Entity) vehicleBase; - try { - if (super.bJ() != null) { - Entity oldVehicle = super.bJ(); - VEHICLE_FIELD.set(this, null); - oldVehicle.passengers.remove(this); - } + try { + if (super.bJ() != null) { + Entity oldVehicle = super.bJ(); + VEHICLE_FIELD.set(this, null); + oldVehicle.passengers.remove(this); + } - VEHICLE_FIELD.set(this, entity); - entity.passengers.clear(); - entity.passengers.add(this); + VEHICLE_FIELD.set(this, entity); + entity.passengers.clear(); + entity.passengers.add(this); - } catch (Throwable t) { - ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); - } - } + } catch (Throwable t) { + ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); + } + } - @Override - public Object getRawItemStack() { - return super.getItemStack(); - } + @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 index d13b69c3..113b06f7 100644 --- 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 @@ -35,186 +35,186 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import java.util.logging.Level; public class EntityNMSSlime extends EntitySlime implements NMSSlime { - - private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "au"); + + private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "au"); - private HologramLine parentPiece; - - public EntityNMSSlime(World world, HologramLine parentPiece) { - super(world); - super.persistent = true; - super.collides = false; - a(0.0F, 0.0F); - setSize(1, false); - setInvisible(true); - this.parentPiece = parentPiece; - 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) { - // Do not change it! - } - - 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; - } + private HologramLine parentPiece; + + public EntityNMSSlime(World world, HologramLine parentPiece) { + super(world); + super.persistent = true; + super.collides = false; + a(0.0F, 0.0F); + setSize(1, false); + setInvisible(true); + this.parentPiece = parentPiece; + 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) { + // Do not change it! + } + + 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) { - Bukkit.getPluginManager().callEvent(new PlayerInteractEntityEvent(((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(), getBukkitEntity())); // 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 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) { + Bukkit.getPluginManager().callEvent(new PlayerInteractEntityEvent(((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(), getBukkitEntity())); // 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) { - // Locks the custom name. - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Locks the custom name. - } - - @Override - public void a(SoundEffect soundeffect, float f, float f1) { - // Remove sounds. - } + @Override + public void setCustomName(String customName) { + // Locks the custom name. + } + + @Override + public void setCustomNameVisible(boolean visible) { + // Locks the custom name. + } + + @Override + public void a(SoundEffect soundeffect, float f, float f1) { + // Remove sounds. + } - @Override - public void die() { - // Prevent being killed. - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSSlime(super.world.getServer(), this); - } - return super.bukkitEntity; - } + @Override + public void die() { + // Prevent being killed. + } + + @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 HologramLine getHologramLine() { - return parentPiece; - } + @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 HologramLine getHologramLine() { + return parentPiece; + } - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public void setPassengerOfNMS(NMSEntityBase vehicleBase) { - if (vehicleBase == null || !(vehicleBase instanceof Entity)) { - // It should never dismount - return; - } - - Entity entity = (Entity) vehicleBase; - - try { - if (super.bJ() != null) { - Entity oldVehicle = super.bJ(); - VEHICLE_FIELD.set(this, null); - oldVehicle.passengers.remove(this); - } + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } + + @Override + public void setPassengerOfNMS(NMSEntityBase vehicleBase) { + if (vehicleBase == null || !(vehicleBase instanceof Entity)) { + // It should never dismount + return; + } + + Entity entity = (Entity) vehicleBase; + + try { + if (super.bJ() != null) { + Entity oldVehicle = super.bJ(); + VEHICLE_FIELD.set(this, null); + oldVehicle.passengers.remove(this); + } - VEHICLE_FIELD.set(this, entity); - entity.passengers.clear(); - entity.passengers.add(this); + VEHICLE_FIELD.set(this, entity); + entity.passengers.clear(); + entity.passengers.add(this); - } catch (Throwable t) { - ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); - } - } + } catch (Throwable t) { + ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); + } + } } diff --git a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/NmsManagerImpl.java b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/NmsManagerImpl.java index 4e811a5d..93cbc60b 100644 --- a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/NmsManagerImpl.java +++ b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/NmsManagerImpl.java @@ -40,77 +40,77 @@ import org.bukkit.inventory.ItemStack; import java.lang.reflect.Method; public class NmsManagerImpl implements NMSManager { - - private static final ReflectField>> REGISTRY_ID_FIELD = new ReflectField<>(RegistryMaterials.class, "a"); - private static final ReflectField ID_TO_CLASS_MAP_FIELD = new ReflectField<>(RegistryID.class, "d"); + + private static final ReflectField>> REGISTRY_ID_FIELD = new ReflectField<>(RegistryMaterials.class, "a"); + private static final ReflectField ID_TO_CLASS_MAP_FIELD = new ReflectField<>(RegistryID.class, "d"); - private Method validateEntityMethod; - - @Override - public void setup() throws Exception { - validateEntityMethod = World.class.getDeclaredMethod("b", Entity.class); - validateEntityMethod.setAccessible(true); - - 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]; + private Method validateEntityMethod; + + @Override + public void setup() throws Exception { + validateEntityMethod = World.class.getDeclaredMethod("b", Entity.class); + validateEntityMethod.setAccessible(true); + + 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); + // 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, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager); - customItem.setLocationNMS(x, y, z); - customItem.setItemStackNMS(stack); - if (!addEntityToWorld(nmsWorld, customItem)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return customItem; - } - - @Override - public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramLine parentPiece) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece); - touchSlime.setLocationNMS(x, y, z); - if (!addEntityToWorld(nmsWorld, touchSlime)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return touchSlime; - } - - @Override - public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) { - WorldServer nmsWorld = ((CraftWorld) world).getHandle(); - EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece); - invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket); - if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return invisibleArmorStand; - } - - private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { - Validator.isTrue(Bukkit.isPrimaryThread(), "Async entity add"); - + // Restore the ID -> entity class mapping. + idToClassMap[id] = oldValue; + } + + @Override + public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager); + customItem.setLocationNMS(x, y, z); + customItem.setItemStackNMS(stack); + if (!addEntityToWorld(nmsWorld, customItem)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return customItem; + } + + @Override + public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramLine parentPiece) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece); + touchSlime.setLocationNMS(x, y, z); + if (!addEntityToWorld(nmsWorld, touchSlime)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return touchSlime; + } + + @Override + public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) { + WorldServer nmsWorld = ((CraftWorld) world).getHandle(); + EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece); + invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket); + if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return invisibleArmorStand; + } + + private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { + Validator.isTrue(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 + // This should never happen nmsEntity.dead = true; return false; } @@ -119,45 +119,45 @@ public class NmsManagerImpl implements NMSManager { nmsWorld.entityList.add(nmsEntity); try { - validateEntityMethod.invoke(nmsWorld, nmsEntity); - } catch (Exception e) { - e.printStackTrace(); - return false; - } + validateEntityMethod.invoke(nmsWorld, nmsEntity); + } catch (Exception e) { + e.printStackTrace(); + return false; + } return true; } - - @Override - public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase; - } + + @Override + public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { + return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase; + } - @Override - public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - - if (nmsEntity instanceof NMSEntityBase) { - return ((NMSEntityBase) nmsEntity); - } else { - return null; - } - } - - @Override - public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - Entity nmsEntity = nmsWorld.getEntity(entityID); - - if (nmsEntity instanceof NMSEntityBase) { - return ((NMSEntityBase) nmsEntity); - } else { - return null; - } - } - - @Override - public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { - return CustomNameHelper.replaceCustomNameString(customNameObject, target, replacement); - } - + @Override + public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { + Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); + + if (nmsEntity instanceof NMSEntityBase) { + return ((NMSEntityBase) nmsEntity); + } else { + return null; + } + } + + @Override + public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + Entity nmsEntity = nmsWorld.getEntity(entityID); + + if (nmsEntity instanceof NMSEntityBase) { + return ((NMSEntityBase) nmsEntity); + } else { + return null; + } + } + + @Override + public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { + return CustomNameHelper.replaceCustomNameString(customNameObject, target, replacement); + } + } 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 index d361c47d..0fb7cccd 100644 --- 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 @@ -21,121 +21,121 @@ import net.minecraft.server.v1_12_R1.Vec3D; public class NullBoundingBox extends AxisAlignedBB { - public NullBoundingBox() { - super(0, 0, 0, 0, 0, 0); - } + public NullBoundingBox() { + super(0, 0, 0, 0, 0, 0); + } - @Override - public double a() { - return 0.0; - } + @Override + public double a() { + return 0.0; + } - @Override - public double a(AxisAlignedBB arg0, double arg1) { - 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(AxisAlignedBB arg0) { + return this; + } - @Override - public AxisAlignedBB a(double arg0, double arg1, double arg2) { - 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 MovingObjectPosition b(Vec3D arg0, Vec3D arg1) { + return null; + } - @Override - public double b(AxisAlignedBB arg0, double arg1) { - return 0.0; - } + @Override + public double b(AxisAlignedBB arg0, double arg1) { + return 0.0; + } - @Override - public double c(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 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 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 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 b(Vec3D arg0) { + return false; + } - @Override - public boolean c(Vec3D arg0) { - return false; - } + @Override + public boolean c(Vec3D arg0) { + return false; + } - @Override - public boolean d(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 e(double arg0) { + return this; + } + + @Override + public AxisAlignedBB g(double arg0) { + return this; + } - @Override - public AxisAlignedBB a(Vec3D arg0) { - return this; - } + @Override + public AxisAlignedBB a(Vec3D arg0) { + return this; + } - @Override - public AxisAlignedBB b(AxisAlignedBB 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 AxisAlignedBB b(double arg0, double arg1, double arg2) { + return this; + } - @Override - public boolean c(AxisAlignedBB arg0) { - return false; - } + @Override + public boolean c(AxisAlignedBB arg0) { + return false; + } - @Override - public AxisAlignedBB d(double arg0, double arg1, double arg2) { - return this; - } + @Override + public AxisAlignedBB d(double arg0, double arg1, double arg2) { + return this; + } - @Override - public boolean e(Vec3D arg0) { - return false; - } - - - + @Override + public boolean e(Vec3D arg0) { + return false; + } + + + } diff --git a/nms/v1_13_r1/pom.xml b/nms/v1_13_r1/pom.xml index 151b380b..1bf68f64 100644 --- a/nms/v1_13_r1/pom.xml +++ b/nms/v1_13_r1/pom.xml @@ -1,41 +1,41 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - - me.filoghost.holographicdisplays - holographicdisplays-nms - 3.0.0-SNAPSHOT - + + me.filoghost.holographicdisplays + holographicdisplays-nms + 3.0.0-SNAPSHOT + - holographicdisplays-nms-v1_13_r1 - HolographicDisplays NMS v1_13_R1 + holographicdisplays-nms-v1_13_r1 + HolographicDisplays NMS v1_13_R1 - - - nms-repo - https://repo.codemc.io/repository/nms/ - - + + + nms-repo + https://repo.codemc.io/repository/nms/ + + - - - ${project.groupId} - holographicdisplays-nms-interfaces - - - - ${project.groupId} - holographicdisplays-utils - - - - org.spigotmc - spigot - 1.13-R0.1-SNAPSHOT - provided - - + + + ${project.groupId} + holographicdisplays-nms-interfaces + + + + ${project.groupId} + holographicdisplays-utils + + + + org.spigotmc + spigot + 1.13-R0.1-SNAPSHOT + provided + + - \ No newline at end of file + 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 index 2b6317f2..0b20aa62 100644 --- 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 @@ -29,67 +29,67 @@ 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. - } + 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 Armor stand class - - @Override public void setArms(boolean arms) { } - @Override public void setBasePlate(boolean basePlate) { } - @Override public void setBodyPose(EulerAngle pose) { } - @Override public void setBoots(ItemStack item) { } - @Override public void setChestplate(ItemStack item) { } - @Override public void setHeadPose(EulerAngle pose) { } - @Override public void setHelmet(ItemStack item) { } - @Override public void setItemInHand(ItemStack item) { } - @Override public void setLeftArmPose(EulerAngle pose) { } - @Override public void setLeftLegPose(EulerAngle pose) { } - @Override public void setLeggings(ItemStack item) { } - @Override public void setRightArmPose(EulerAngle pose) { } - @Override public void setRightLegPose(EulerAngle pose) { } - @Override public void setSmall(boolean small) { } - @Override public void setVisible(boolean visible) { } - @Override public void setMarker(boolean marker) { } + // Methods from Armor stand class + + @Override public void setArms(boolean arms) { } + @Override public void setBasePlate(boolean basePlate) { } + @Override public void setBodyPose(EulerAngle pose) { } + @Override public void setBoots(ItemStack item) { } + @Override public void setChestplate(ItemStack item) { } + @Override public void setHeadPose(EulerAngle pose) { } + @Override public void setHelmet(ItemStack item) { } + @Override public void setItemInHand(ItemStack item) { } + @Override public void setLeftArmPose(EulerAngle pose) { } + @Override public void setLeftLegPose(EulerAngle pose) { } + @Override public void setLeggings(ItemStack item) { } + @Override public void setRightArmPose(EulerAngle pose) { } + @Override public void setRightLegPose(EulerAngle pose) { } + @Override public void setSmall(boolean small) { } + @Override public void setVisible(boolean visible) { } + @Override public void setMarker(boolean marker) { } - // 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 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 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 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 index 1593d03e..5457f560 100644 --- 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 @@ -25,39 +25,39 @@ import org.bukkit.util.Vector; public class CraftNMSItem extends CraftItem { - public CraftNMSItem(CraftServer server, EntityNMSItem entity) { - super(server, entity); - } + 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. - } + // 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 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) { } - + // 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 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 index 5da922ec..9c76b5f2 100644 --- 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 @@ -28,52 +28,52 @@ 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) { } + 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 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 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 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) { } - + // 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 index fdd1dc2b..b41172c7 100644 --- 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 @@ -37,208 +37,208 @@ import org.bukkit.craftbukkit.v1_13_R1.util.CraftChatMessage; public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand { - private HologramLine parentPiece; - private String customName; - - public EntityNMSArmorStand(World world, HologramLine parentPiece) { - super(world); - super.setInvisible(true); - super.setSmall(true); - super.setArms(false); - super.setNoGravity(true); - super.setBasePlate(true); - super.setMarker(true); - super.collides = false; - this.parentPiece = parentPiece; - forceSetBoundingBox(new NullBoundingBox()); - - this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet. - } - - @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 (this.onGround) { - this.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 (this.onGround) { - this.onGround = false; - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT. - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT. - return false; - } + private HologramLine parentPiece; + private String customName; + + public EntityNMSArmorStand(World world, HologramLine parentPiece) { + super(world); + super.setInvisible(true); + super.setSmall(true); + super.setArms(false); + super.setNoGravity(true); + super.setBasePlate(true); + super.setMarker(true); + super.collides = false; + this.parentPiece = parentPiece; + forceSetBoundingBox(new NullBoundingBox()); + + this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet. + } + + @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 (this.onGround) { + this.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 (this.onGround) { + this.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) { - // Locks the custom name. - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Locks the custom name. - } + @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) { + // Locks the custom name. + } + + @Override + public void setCustomNameVisible(boolean visible) { + // Locks the custom name. + } - @Override - public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) { - // Prevent stand being equipped - return EnumInteractionResult.PASS; - } + @Override + public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) { + // Prevent stand being equipped + return EnumInteractionResult.PASS; + } - @Override - public boolean c(int i, ItemStack item) { - // Prevent stand being equipped - return false; - } + @Override + public boolean c(int i, ItemStack item) { + // Prevent stand being equipped + return false; + } - @Override - public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { - // Prevent stand being equipped - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Do not change it! - } - - 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 name) { - this.customName = Utils.limitLength(name, 300); - super.setCustomName(CraftChatMessage.fromStringOrNull(customName)); - super.setCustomNameVisible(customName != null && !customName.isEmpty()); - } - - @Override - public String getCustomNameStringNMS() { - return this.customName; - } - - @Override - public Object getCustomNameObjectNMS() { - return super.getCustomName(); - } - - @Override - public void die() { - // Prevent being killed. - } - - @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, boolean broadcastLocationPacket) { - super.setPosition(x, y, z); - if (broadcastLocationPacket) { - broadcastLocationPacketNMS(); - } - } - - private void broadcastLocationPacketNMS() { - PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); - - for (Object obj : super.world.players) { - if (obj instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) obj; + @Override + public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { + // Prevent stand being equipped + } + + @Override + public void a(AxisAlignedBB boundingBox) { + // Do not change it! + } + + 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 name) { + this.customName = Utils.limitLength(name, 300); + super.setCustomName(CraftChatMessage.fromStringOrNull(customName)); + super.setCustomNameVisible(customName != null && !customName.isEmpty()); + } + + @Override + public String getCustomNameStringNMS() { + return this.customName; + } + + @Override + public Object getCustomNameObjectNMS() { + return super.getCustomName(); + } + + @Override + public void die() { + // Prevent being killed. + } + + @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, boolean broadcastLocationPacket) { + super.setPosition(x, y, z); + if (broadcastLocationPacket) { + broadcastLocationPacketNMS(); + } + } + + private void broadcastLocationPacketNMS() { + PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); + + for (Object obj : super.world.players) { + if (obj instanceof EntityPlayer) { + EntityPlayer nmsPlayer = (EntityPlayer) obj; - double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ); - if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(teleportPacket); - } - } - } - } + double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ); + if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) { + nmsPlayer.playerConnection.sendPacket(teleportPacket); + } + } + } + } - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public int getIdNMS() { - return super.getId(); - } + @Override + public boolean isDeadNMS() { + return super.dead; + } + + @Override + public int getIdNMS() { + return super.getId(); + } - @Override - public HologramLine getHologramLine() { - return parentPiece; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } + @Override + public HologramLine getHologramLine() { + return parentPiece; + } + + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } } 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 index 7bfa7c9f..4defe6ed 100644 --- 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 @@ -39,207 +39,207 @@ import org.bukkit.entity.Player; import java.util.logging.Level; public class EntityNMSItem extends EntityItem implements NMSItem { - - private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "ax"); - - private ItemLine parentPiece; - private ItemPickupManager itemPickupManager; - - public EntityNMSItem(World world, ItemLine piece, ItemPickupManager itemPickupManager) { - super(world); - super.pickupDelay = 32767; // Lock the item pickup delay, also prevents entities from picking up the item - this.parentPiece = piece; - this.itemPickupManager = itemPickupManager; - } - - @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 (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) { - itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent()); - // 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; - } + + private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "ax"); + + private ItemLine parentPiece; + private ItemPickupManager itemPickupManager; + + public EntityNMSItem(World world, ItemLine piece, ItemPickupManager itemPickupManager) { + super(world); + super.pickupDelay = 32767; // Lock the item pickup delay, also prevents entities from picking up the item + this.parentPiece = piece; + this.itemPickupManager = itemPickupManager; + } + + @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 (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) { + itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent()); + // 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 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 being killed. - } - - @Override - public boolean isAlive() { - // This override prevents items from being picked up by hoppers. - // Should have no side effects. - return false; - } + @Override + public void die() { + // Prevent being killed. + } + + @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 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 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); // ItemStack.a is returned if the stack is null, invalid or the material is not an Item - - if (newItem == null || newItem == ItemStack.a) { - newItem = new ItemStack(Blocks.BEDROCK); - } + @Override + public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) { + ItemStack newItem = CraftItemStack.asNMSCopy(stack); // ItemStack.a is returned if the stack is null, invalid or the material is not an Item + + if (newItem == null || newItem == ItemStack.a) { + 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); - } + 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(ItemUtils.ANTISTACK_LORE)); // Antistack lore - display.set("Lore", tagList); - - setItemStack(newItem); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public ItemLine getHologramLine() { - return parentPiece; - } - - @Override - public void allowPickup(boolean pickup) { - if (pickup) { - super.pickupDelay = 0; - } else { - super.pickupDelay = 32767; - } - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public void setPassengerOfNMS(NMSEntityBase vehicleBase) { - if (vehicleBase == null || !(vehicleBase instanceof Entity)) { - // It should never dismount - return; - } - - Entity entity = (Entity) vehicleBase; + NBTTagList tagList = new NBTTagList(); + tagList.add(new NBTTagString(ItemUtils.ANTISTACK_LORE)); // Antistack lore + display.set("Lore", tagList); + + setItemStack(newItem); + } + + @Override + public int getIdNMS() { + return super.getId(); + } + + @Override + public ItemLine getHologramLine() { + return parentPiece; + } + + @Override + public void allowPickup(boolean pickup) { + if (pickup) { + super.pickupDelay = 0; + } else { + super.pickupDelay = 32767; + } + } + + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } + + @Override + public void setPassengerOfNMS(NMSEntityBase vehicleBase) { + if (vehicleBase == null || !(vehicleBase instanceof Entity)) { + // It should never dismount + return; + } + + Entity entity = (Entity) vehicleBase; - try { - if (super.getVehicle() != null) { - Entity oldVehicle = super.getVehicle(); - VEHICLE_FIELD.set(this, null); - oldVehicle.passengers.remove(this); - } + try { + if (super.getVehicle() != null) { + Entity oldVehicle = super.getVehicle(); + VEHICLE_FIELD.set(this, null); + oldVehicle.passengers.remove(this); + } - VEHICLE_FIELD.set(this, entity); - entity.passengers.clear(); - entity.passengers.add(this); + VEHICLE_FIELD.set(this, entity); + entity.passengers.clear(); + entity.passengers.add(this); - } catch (Throwable t) { - ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); - } - } + } catch (Throwable t) { + ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); + } + } - @Override - public Object getRawItemStack() { - return super.getItemStack(); - } + @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 index 19e222bb..2b86b9c5 100644 --- 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 @@ -36,186 +36,186 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import java.util.logging.Level; public class EntityNMSSlime extends EntitySlime implements NMSSlime { - - private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "ax"); - - private HologramLine parentPiece; - - public EntityNMSSlime(World world, HologramLine parentPiece) { - super(world); - super.persistent = true; - super.collides = false; - a(0.0F, 0.0F); - setSize(1, false); - setInvisible(true); - this.parentPiece = parentPiece; - 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) { - // Do not change it! - } - - 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; - } + + private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "ax"); + + private HologramLine parentPiece; + + public EntityNMSSlime(World world, HologramLine parentPiece) { + super(world); + super.persistent = true; + super.collides = false; + a(0.0F, 0.0F); + setSize(1, false); + setInvisible(true); + this.parentPiece = parentPiece; + 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) { + // Do not change it! + } + + 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) { - Bukkit.getPluginManager().callEvent(new PlayerInteractEntityEvent(((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(), getBukkitEntity())); // 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 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) { + Bukkit.getPluginManager().callEvent(new PlayerInteractEntityEvent(((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(), getBukkitEntity())); // 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) { - // Locks the custom name. - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Locks the custom name. - } - - @Override - public void a(SoundEffect soundeffect, float f, float f1) { - // Remove sounds. - } - - @Override - public void die() { - // Prevent being killed. - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSSlime(super.world.getServer(), this); - } - return super.bukkitEntity; - } + @Override + public void setCustomName(IChatBaseComponent ichatbasecomponent) { + // Locks the custom name. + } + + @Override + public void setCustomNameVisible(boolean visible) { + // Locks the custom name. + } + + @Override + public void a(SoundEffect soundeffect, float f, float f1) { + // Remove sounds. + } + + @Override + public void die() { + // Prevent being killed. + } + + @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 HologramLine getHologramLine() { - return parentPiece; - } + @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 HologramLine getHologramLine() { + return parentPiece; + } - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public void setPassengerOfNMS(NMSEntityBase vehicleBase) { - if (vehicleBase == null || !(vehicleBase instanceof Entity)) { - // It should never dismount - return; - } - - Entity entity = (Entity) vehicleBase; - - try { - if (super.getVehicle() != null) { - Entity oldVehicle = super.getVehicle(); - VEHICLE_FIELD.set(this, null); - oldVehicle.passengers.remove(this); - } + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } + + @Override + public void setPassengerOfNMS(NMSEntityBase vehicleBase) { + if (vehicleBase == null || !(vehicleBase instanceof Entity)) { + // It should never dismount + return; + } + + Entity entity = (Entity) vehicleBase; + + try { + if (super.getVehicle() != null) { + Entity oldVehicle = super.getVehicle(); + VEHICLE_FIELD.set(this, null); + oldVehicle.passengers.remove(this); + } - VEHICLE_FIELD.set(this, entity); - entity.passengers.clear(); - entity.passengers.add(this); + VEHICLE_FIELD.set(this, entity); + entity.passengers.clear(); + entity.passengers.add(this); - } catch (Throwable t) { - ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); - } - } + } catch (Throwable t) { + ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); + } + } } diff --git a/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/NmsManagerImpl.java b/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/NmsManagerImpl.java index 072706cf..acb0f737 100644 --- a/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/NmsManagerImpl.java +++ b/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/NmsManagerImpl.java @@ -45,169 +45,169 @@ import java.lang.reflect.Method; import java.util.List; public class NmsManagerImpl implements NMSManager { - - private static final ReflectField>> REGISTRY_ID_FIELD = new ReflectField<>(RegistryMaterials.class, "a"); - private static final ReflectField ID_TO_CLASS_MAP_FIELD = new ReflectField<>(RegistryID.class, "d"); - private static final ReflectField> ENTITY_LIST_FIELD = new ReflectField<>(World.class, "entityList"); + + private static final ReflectField>> REGISTRY_ID_FIELD = new ReflectField<>(RegistryMaterials.class, "a"); + private static final ReflectField ID_TO_CLASS_MAP_FIELD = new ReflectField<>(RegistryID.class, "d"); + private static final ReflectField> ENTITY_LIST_FIELD = new ReflectField<>(World.class, "entityList"); - private Method validateEntityMethod; - - @Override - public void setup() throws Exception { - validateEntityMethod = World.class.getDeclaredMethod("b", Entity.class); - validateEntityMethod.setAccessible(true); - - 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]; + private Method validateEntityMethod; + + @Override + public void setup() throws Exception { + validateEntityMethod = World.class.getDeclaredMethod("b", Entity.class); + validateEntityMethod.setAccessible(true); + + 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); + // 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, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager); - customItem.setLocationNMS(x, y, z); - customItem.setItemStackNMS(stack); - if (!addEntityToWorld(nmsWorld, customItem)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return customItem; - } - - @Override - public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramLine parentPiece) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece); - touchSlime.setLocationNMS(x, y, z); - if (!addEntityToWorld(nmsWorld, touchSlime)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return touchSlime; - } - - @Override - public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) { - WorldServer nmsWorld = ((CraftWorld) world).getHandle(); - EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece); - invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket); - if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return invisibleArmorStand; - } - - private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { - Validator.isTrue(Bukkit.isPrimaryThread(), "Async entity add"); - + // Restore the ID -> EntityTypes mapping. + idToClassMap[id] = oldValue; + } + + @Override + public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager); + customItem.setLocationNMS(x, y, z); + customItem.setItemStackNMS(stack); + if (!addEntityToWorld(nmsWorld, customItem)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return customItem; + } + + @Override + public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramLine parentPiece) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece); + touchSlime.setLocationNMS(x, y, z); + if (!addEntityToWorld(nmsWorld, touchSlime)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return touchSlime; + } + + @Override + public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) { + WorldServer nmsWorld = ((CraftWorld) world).getHandle(); + EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece); + invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket); + if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return invisibleArmorStand; + } + + private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { + Validator.isTrue(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 + // This should never happen nmsEntity.dead = true; return false; } nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity); if (VersionUtils.isPaperServer()) { - 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 (Exception e) { - e.printStackTrace(); - return false; - } + 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 (Exception e) { + e.printStackTrace(); + return false; + } } else { - nmsWorld.entityList.add(nmsEntity); + nmsWorld.entityList.add(nmsEntity); } try { - validateEntityMethod.invoke(nmsWorld, nmsEntity); - } catch (Exception e) { - e.printStackTrace(); - return false; - } + validateEntityMethod.invoke(nmsWorld, nmsEntity); + } catch (Exception e) { + e.printStackTrace(); + return false; + } return true; } - - @Override - public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase; - } + + @Override + public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { + return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase; + } - @Override - public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - - if (nmsEntity instanceof NMSEntityBase) { - return ((NMSEntityBase) nmsEntity); - } else { - return null; - } - } - - @Override - public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - Entity nmsEntity = nmsWorld.getEntity(entityID); - - if (nmsEntity instanceof NMSEntityBase) { - return ((NMSEntityBase) nmsEntity); - } else { - return null; - } - } - - @Override - public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { - return CustomNameHelper.replaceCustomNameChatComponent(NMSChatComponentAdapter.INSTANCE, customNameObject, target, replacement); - } - - private static enum NMSChatComponentAdapter implements ChatComponentAdapter { + @Override + public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { + Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); + + if (nmsEntity instanceof NMSEntityBase) { + return ((NMSEntityBase) nmsEntity); + } else { + return null; + } + } + + @Override + public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + Entity nmsEntity = nmsWorld.getEntity(entityID); + + if (nmsEntity instanceof NMSEntityBase) { + return ((NMSEntityBase) nmsEntity); + } else { + return null; + } + } + + @Override + public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { + return CustomNameHelper.replaceCustomNameChatComponent(NMSChatComponentAdapter.INSTANCE, customNameObject, target, replacement); + } + + private static enum NMSChatComponentAdapter implements ChatComponentAdapter { - INSTANCE { - - public ChatComponentText cast(Object chatComponentObject) { - return (ChatComponentText) chatComponentObject; - } - - @Override - public String getText(IChatBaseComponent chatComponent) { - return chatComponent.getText(); - } - - @Override - public List getSiblings(IChatBaseComponent chatComponent) { - return chatComponent.a(); - } - - @Override - public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) { - chatComponent.addSibling(newSibling); - } - - @Override - public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) { - ChatComponentText clonedChatComponent = new ChatComponentText(newText); - clonedChatComponent.setChatModifier(chatComponent.getChatModifier().clone()); - return clonedChatComponent; - } - - } - - } - + INSTANCE { + + public ChatComponentText cast(Object chatComponentObject) { + return (ChatComponentText) chatComponentObject; + } + + @Override + public String getText(IChatBaseComponent chatComponent) { + return chatComponent.getText(); + } + + @Override + public List getSiblings(IChatBaseComponent chatComponent) { + return chatComponent.a(); + } + + @Override + public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) { + chatComponent.addSibling(newSibling); + } + + @Override + public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) { + ChatComponentText clonedChatComponent = new ChatComponentText(newText); + clonedChatComponent.setChatModifier(chatComponent.getChatModifier().clone()); + return clonedChatComponent; + } + + } + + } + } 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 index 55b76ef4..18e13b10 100644 --- 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 @@ -22,111 +22,111 @@ import net.minecraft.server.v1_13_R1.Vec3D; public class NullBoundingBox extends AxisAlignedBB { - public NullBoundingBox() { - super(0, 0, 0, 0, 0, 0); - } + public NullBoundingBox() { + super(0, 0, 0, 0, 0, 0); + } - @Override - public double a() { - return 0.0; - } + @Override + public double a() { + return 0.0; + } - @Override - public AxisAlignedBB a(AxisAlignedBB arg0) { - return this; - } + @Override + public AxisAlignedBB a(AxisAlignedBB arg0) { + return this; + } - @Override - public AxisAlignedBB a(double arg0, double arg1, double arg2) { - 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 MovingObjectPosition b(Vec3D arg0, Vec3D arg1) { + return null; + } - @Override - public AxisAlignedBB grow(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 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 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 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 a(Vec3D arg0) { + return this; + } - @Override - public AxisAlignedBB b(AxisAlignedBB 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 AxisAlignedBB b(double arg0, double arg1, double arg2) { + return this; + } - @Override - public boolean c(AxisAlignedBB arg0) { - return false; - } + @Override + public boolean c(AxisAlignedBB arg0) { + return false; + } - @Override - public AxisAlignedBB d(double arg0, double arg1, double arg2) { - return this; - } + @Override + public AxisAlignedBB d(double arg0, double arg1, double arg2) { + return this; + } - @Override - public double a(EnumAxis arg0) { - return 0.0; - } + @Override + public double a(EnumAxis arg0) { + return 0.0; + } - @Override - public MovingObjectPosition a(Vec3D arg0, Vec3D arg1, BlockPosition arg2) { - return null; - } + @Override + public MovingObjectPosition a(Vec3D arg0, Vec3D arg1, BlockPosition arg2) { + return null; + } - @Override - public double b(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 boolean e(double arg0, double arg1, double arg2) { + return false; + } - @Override - public AxisAlignedBB f(double arg0, double arg1, double arg2) { - return this; - } - - - + @Override + public AxisAlignedBB f(double arg0, double arg1, double arg2) { + return this; + } + + + } diff --git a/nms/v1_13_r2/pom.xml b/nms/v1_13_r2/pom.xml index eedd7b62..e6213dd6 100644 --- a/nms/v1_13_r2/pom.xml +++ b/nms/v1_13_r2/pom.xml @@ -1,41 +1,41 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - - me.filoghost.holographicdisplays - holographicdisplays-nms - 3.0.0-SNAPSHOT - + + me.filoghost.holographicdisplays + holographicdisplays-nms + 3.0.0-SNAPSHOT + - holographicdisplays-nms-v1_13_r2 - HolographicDisplays NMS v1_13_R2 + holographicdisplays-nms-v1_13_r2 + HolographicDisplays NMS v1_13_R2 - - - nms-repo - https://repo.codemc.io/repository/nms/ - - + + + nms-repo + https://repo.codemc.io/repository/nms/ + + - - - ${project.groupId} - holographicdisplays-nms-interfaces - - - - ${project.groupId} - holographicdisplays-utils - - - - org.spigotmc - spigot - 1.13.1-R0.1-SNAPSHOT - provided - - + + + ${project.groupId} + holographicdisplays-nms-interfaces + + + + ${project.groupId} + holographicdisplays-utils + + + + org.spigotmc + spigot + 1.13.1-R0.1-SNAPSHOT + provided + + - \ No newline at end of file + 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 index dc916b79..6a9011af 100644 --- 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 @@ -29,68 +29,68 @@ 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. - } + 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 Armor stand class - - @Override public void setArms(boolean arms) { } - @Override public void setBasePlate(boolean basePlate) { } - @Override public void setBodyPose(EulerAngle pose) { } - @Override public void setBoots(ItemStack item) { } - @Override public void setChestplate(ItemStack item) { } - @Override public void setHeadPose(EulerAngle pose) { } - @Override public void setHelmet(ItemStack item) { } - @Override public void setItemInHand(ItemStack item) { } - @Override public void setLeftArmPose(EulerAngle pose) { } - @Override public void setLeftLegPose(EulerAngle pose) { } - @Override public void setLeggings(ItemStack item) { } - @Override public void setRightArmPose(EulerAngle pose) { } - @Override public void setRightLegPose(EulerAngle pose) { } - @Override public void setSmall(boolean small) { } - @Override public void setVisible(boolean visible) { } - @Override public void setMarker(boolean marker) { } + // Methods from Armor stand class + + @Override public void setArms(boolean arms) { } + @Override public void setBasePlate(boolean basePlate) { } + @Override public void setBodyPose(EulerAngle pose) { } + @Override public void setBoots(ItemStack item) { } + @Override public void setChestplate(ItemStack item) { } + @Override public void setHeadPose(EulerAngle pose) { } + @Override public void setHelmet(ItemStack item) { } + @Override public void setItemInHand(ItemStack item) { } + @Override public void setLeftArmPose(EulerAngle pose) { } + @Override public void setLeftLegPose(EulerAngle pose) { } + @Override public void setLeggings(ItemStack item) { } + @Override public void setRightArmPose(EulerAngle pose) { } + @Override public void setRightLegPose(EulerAngle pose) { } + @Override public void setSmall(boolean small) { } + @Override public void setVisible(boolean visible) { } + @Override public void setMarker(boolean marker) { } - // 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 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 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 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 index 44955fac..0ba18c21 100644 --- 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 @@ -25,40 +25,40 @@ import org.bukkit.util.Vector; public class CraftNMSItem extends CraftItem { - public CraftNMSItem(CraftServer server, EntityNMSItem entity) { - super(server, entity); - } + 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. - } + // 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 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) { } - + // 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 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 index 9fab8c15..56792a65 100644 --- 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 @@ -29,56 +29,56 @@ 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) { } + 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 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 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 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) { } - + // 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 index 2a9ad0de..64bd1912 100644 --- 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 @@ -37,208 +37,208 @@ import org.bukkit.craftbukkit.v1_13_R2.util.CraftChatMessage; public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand { - private HologramLine parentPiece; - private String customName; - - public EntityNMSArmorStand(World world, HologramLine parentPiece) { - super(world); - super.setInvisible(true); - super.setSmall(true); - super.setArms(false); - super.setNoGravity(true); - super.setBasePlate(true); - super.setMarker(true); - super.collides = false; - this.parentPiece = parentPiece; - forceSetBoundingBox(new NullBoundingBox()); - - this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet. - } - - @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 (this.onGround) { - this.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 (this.onGround) { - this.onGround = false; - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT. - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT. - return false; - } + private HologramLine parentPiece; + private String customName; + + public EntityNMSArmorStand(World world, HologramLine parentPiece) { + super(world); + super.setInvisible(true); + super.setSmall(true); + super.setArms(false); + super.setNoGravity(true); + super.setBasePlate(true); + super.setMarker(true); + super.collides = false; + this.parentPiece = parentPiece; + forceSetBoundingBox(new NullBoundingBox()); + + this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet. + } + + @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 (this.onGround) { + this.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 (this.onGround) { + this.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) { - // Locks the custom name. - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Locks the custom name. - } + @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) { + // Locks the custom name. + } + + @Override + public void setCustomNameVisible(boolean visible) { + // Locks the custom name. + } - @Override - public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) { - // Prevent stand being equipped - return EnumInteractionResult.PASS; - } + @Override + public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) { + // Prevent stand being equipped + return EnumInteractionResult.PASS; + } - @Override - public boolean c(int i, ItemStack item) { - // Prevent stand being equipped - return false; - } + @Override + public boolean c(int i, ItemStack item) { + // Prevent stand being equipped + return false; + } - @Override - public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { - // Prevent stand being equipped - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Do not change it! - } - - 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 name) { - this.customName = Utils.limitLength(name, 300); - super.setCustomName(CraftChatMessage.fromStringOrNull(customName)); - super.setCustomNameVisible(customName != null && !customName.isEmpty()); - } - - @Override - public String getCustomNameStringNMS() { - return this.customName; - } - - @Override - public Object getCustomNameObjectNMS() { - return super.getCustomName(); - } - - @Override - public void die() { - // Prevent being killed. - } - - @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, boolean broadcastLocationPacket) { - super.setPosition(x, y, z); - if (broadcastLocationPacket) { - broadcastLocationPacketNMS(); - } - } - - private void broadcastLocationPacketNMS() { - PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); - - for (Object obj : super.world.players) { - if (obj instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) obj; + @Override + public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { + // Prevent stand being equipped + } + + @Override + public void a(AxisAlignedBB boundingBox) { + // Do not change it! + } + + 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 name) { + this.customName = Utils.limitLength(name, 300); + super.setCustomName(CraftChatMessage.fromStringOrNull(customName)); + super.setCustomNameVisible(customName != null && !customName.isEmpty()); + } + + @Override + public String getCustomNameStringNMS() { + return this.customName; + } + + @Override + public Object getCustomNameObjectNMS() { + return super.getCustomName(); + } + + @Override + public void die() { + // Prevent being killed. + } + + @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, boolean broadcastLocationPacket) { + super.setPosition(x, y, z); + if (broadcastLocationPacket) { + broadcastLocationPacketNMS(); + } + } + + private void broadcastLocationPacketNMS() { + PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); + + for (Object obj : super.world.players) { + if (obj instanceof EntityPlayer) { + EntityPlayer nmsPlayer = (EntityPlayer) obj; - double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ); - if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(teleportPacket); - } - } - } - } + double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ); + if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) { + nmsPlayer.playerConnection.sendPacket(teleportPacket); + } + } + } + } - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public int getIdNMS() { - return super.getId(); - } + @Override + public boolean isDeadNMS() { + return super.dead; + } + + @Override + public int getIdNMS() { + return super.getId(); + } - @Override - public HologramLine getHologramLine() { - return parentPiece; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } + @Override + public HologramLine getHologramLine() { + return parentPiece; + } + + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } } 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 index f3fd15a6..00d903f3 100644 --- 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 @@ -39,207 +39,207 @@ import org.bukkit.entity.Player; import java.util.logging.Level; public class EntityNMSItem extends EntityItem implements NMSItem { - - private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "vehicle"); - - private ItemLine parentPiece; - private ItemPickupManager itemPickupManager; - - public EntityNMSItem(World world, ItemLine piece, ItemPickupManager itemPickupManager) { - super(world); - super.pickupDelay = 32767; // Lock the item pickup delay, also prevents entities from picking up the item - this.parentPiece = piece; - this.itemPickupManager = itemPickupManager; - } - - @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 (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) { - itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent()); - // 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; - } + + private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "vehicle"); + + private ItemLine parentPiece; + private ItemPickupManager itemPickupManager; + + public EntityNMSItem(World world, ItemLine piece, ItemPickupManager itemPickupManager) { + super(world); + super.pickupDelay = 32767; // Lock the item pickup delay, also prevents entities from picking up the item + this.parentPiece = piece; + this.itemPickupManager = itemPickupManager; + } + + @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 (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) { + itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent()); + // 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 being killed. - } - - @Override - public boolean isAlive() { - // This override prevents items from being picked up by hoppers. - // Should have no side effects. - 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 being killed. + } + + @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 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 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); // ItemStack.a is returned if the stack is null, invalid or the material is not an Item - - if (newItem == null || newItem == ItemStack.a) { - newItem = new ItemStack(Blocks.BEDROCK); - } + @Override + public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) { + ItemStack newItem = CraftItemStack.asNMSCopy(stack); // ItemStack.a is returned if the stack is null, invalid or the material is not an Item + + if (newItem == null || newItem == ItemStack.a) { + 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); - } + 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(ItemUtils.ANTISTACK_LORE)); // Antistack lore - display.set("Lore", tagList); - - setItemStack(newItem); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public ItemLine getHologramLine() { - return parentPiece; - } - - @Override - public void allowPickup(boolean pickup) { - if (pickup) { - super.pickupDelay = 0; - } else { - super.pickupDelay = 32767; - } - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public void setPassengerOfNMS(NMSEntityBase vehicleBase) { - if (vehicleBase == null || !(vehicleBase instanceof Entity)) { - // It should never dismount - return; - } - - Entity entity = (Entity) vehicleBase; + NBTTagList tagList = new NBTTagList(); + tagList.add(new NBTTagString(ItemUtils.ANTISTACK_LORE)); // Antistack lore + display.set("Lore", tagList); + + setItemStack(newItem); + } + + @Override + public int getIdNMS() { + return super.getId(); + } + + @Override + public ItemLine getHologramLine() { + return parentPiece; + } + + @Override + public void allowPickup(boolean pickup) { + if (pickup) { + super.pickupDelay = 0; + } else { + super.pickupDelay = 32767; + } + } + + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } + + @Override + public void setPassengerOfNMS(NMSEntityBase vehicleBase) { + if (vehicleBase == null || !(vehicleBase instanceof Entity)) { + // It should never dismount + return; + } + + Entity entity = (Entity) vehicleBase; - try { - if (super.getVehicle() != null) { - Entity oldVehicle = super.getVehicle(); - VEHICLE_FIELD.set(this, null); - oldVehicle.passengers.remove(this); - } + try { + if (super.getVehicle() != null) { + Entity oldVehicle = super.getVehicle(); + VEHICLE_FIELD.set(this, null); + oldVehicle.passengers.remove(this); + } - VEHICLE_FIELD.set(this, entity); - entity.passengers.clear(); - entity.passengers.add(this); + VEHICLE_FIELD.set(this, entity); + entity.passengers.clear(); + entity.passengers.add(this); - } catch (Throwable t) { - ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); - } - } + } catch (Throwable t) { + ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); + } + } - @Override - public Object getRawItemStack() { - return super.getItemStack(); - } + @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 index a375d97f..82f7c3c5 100644 --- 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 @@ -36,186 +36,186 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import java.util.logging.Level; public class EntityNMSSlime extends EntitySlime implements NMSSlime { - - private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "vehicle"); + + private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "vehicle"); - private HologramLine parentPiece; - - public EntityNMSSlime(World world, HologramLine parentPiece) { - super(world); - super.persistent = true; - super.collides = false; - a(0.0F, 0.0F); - setSize(1, false); - setInvisible(true); - this.parentPiece = parentPiece; - 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) { - // Do not change it! - } - - 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; - } + private HologramLine parentPiece; + + public EntityNMSSlime(World world, HologramLine parentPiece) { + super(world); + super.persistent = true; + super.collides = false; + a(0.0F, 0.0F); + setSize(1, false); + setInvisible(true); + this.parentPiece = parentPiece; + 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) { + // Do not change it! + } + + 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) { - Bukkit.getPluginManager().callEvent(new PlayerInteractEntityEvent(((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(), getBukkitEntity())); // 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) { - // Locks the custom name. - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Locks the custom name. - } - - @Override - public void a(SoundEffect soundeffect, float f, float f1) { - // Remove sounds. - } - - @Override - public void die() { - // Prevent being killed. - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSSlime(super.world.getServer(), this); - } - return super.bukkitEntity; - } + @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) { + Bukkit.getPluginManager().callEvent(new PlayerInteractEntityEvent(((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(), getBukkitEntity())); // 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) { + // Locks the custom name. + } + + @Override + public void setCustomNameVisible(boolean visible) { + // Locks the custom name. + } + + @Override + public void a(SoundEffect soundeffect, float f, float f1) { + // Remove sounds. + } + + @Override + public void die() { + // Prevent being killed. + } + + @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 HologramLine getHologramLine() { - return parentPiece; - } + @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 HologramLine getHologramLine() { + return parentPiece; + } - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public void setPassengerOfNMS(NMSEntityBase vehicleBase) { - if (vehicleBase == null || !(vehicleBase instanceof Entity)) { - // It should never dismount - return; - } - - Entity entity = (Entity) vehicleBase; - - try { - if (super.getVehicle() != null) { - Entity oldVehicle = super.getVehicle(); - VEHICLE_FIELD.set(this, null); - oldVehicle.passengers.remove(this); - } + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } + + @Override + public void setPassengerOfNMS(NMSEntityBase vehicleBase) { + if (vehicleBase == null || !(vehicleBase instanceof Entity)) { + // It should never dismount + return; + } + + Entity entity = (Entity) vehicleBase; + + try { + if (super.getVehicle() != null) { + Entity oldVehicle = super.getVehicle(); + VEHICLE_FIELD.set(this, null); + oldVehicle.passengers.remove(this); + } - VEHICLE_FIELD.set(this, entity); - entity.passengers.clear(); - entity.passengers.add(this); + VEHICLE_FIELD.set(this, entity); + entity.passengers.clear(); + entity.passengers.add(this); - } catch (Throwable t) { - ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); - } - } + } catch (Throwable t) { + ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); + } + } } diff --git a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/NmsManagerImpl.java b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/NmsManagerImpl.java index c5431a16..8a4ab64a 100644 --- a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/NmsManagerImpl.java +++ b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/NmsManagerImpl.java @@ -46,169 +46,169 @@ import java.lang.reflect.Method; import java.util.List; public class NmsManagerImpl implements NMSManager { - - private static final ReflectField>> REGISTRY_ID_FIELD = new ReflectField<>(RegistryMaterials.class, "b"); - private static final ReflectField ID_TO_CLASS_MAP_FIELD = new ReflectField<>(RegistryID.class, "d"); - private static final ReflectField> ENTITY_LIST_FIELD = new ReflectField<>(World.class, "entityList"); + + private static final ReflectField>> REGISTRY_ID_FIELD = new ReflectField<>(RegistryMaterials.class, "b"); + private static final ReflectField ID_TO_CLASS_MAP_FIELD = new ReflectField<>(RegistryID.class, "d"); + private static final ReflectField> ENTITY_LIST_FIELD = new ReflectField<>(World.class, "entityList"); - private Method validateEntityMethod; - - @Override - public void setup() throws Exception { - validateEntityMethod = World.class.getDeclaredMethod("b", Entity.class); - validateEntityMethod.setAccessible(true); - - 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]; + private Method validateEntityMethod; + + @Override + public void setup() throws Exception { + validateEntityMethod = World.class.getDeclaredMethod("b", Entity.class); + validateEntityMethod.setAccessible(true); + + 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); + // 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, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager); - customItem.setLocationNMS(x, y, z); - customItem.setItemStackNMS(stack); - if (!addEntityToWorld(nmsWorld, customItem)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return customItem; - } - - @Override - public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramLine parentPiece) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece); - touchSlime.setLocationNMS(x, y, z); - if (!addEntityToWorld(nmsWorld, touchSlime)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return touchSlime; - } - - @Override - public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) { - WorldServer nmsWorld = ((CraftWorld) world).getHandle(); - EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece); - invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket); - if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return invisibleArmorStand; - } - - private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { - Validator.isTrue(Bukkit.isPrimaryThread(), "Async entity add"); - + // Restore the ID -> EntityTypes mapping. + idToClassMap[id] = oldValue; + } + + @Override + public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager); + customItem.setLocationNMS(x, y, z); + customItem.setItemStackNMS(stack); + if (!addEntityToWorld(nmsWorld, customItem)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return customItem; + } + + @Override + public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramLine parentPiece) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece); + touchSlime.setLocationNMS(x, y, z); + if (!addEntityToWorld(nmsWorld, touchSlime)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return touchSlime; + } + + @Override + public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) { + WorldServer nmsWorld = ((CraftWorld) world).getHandle(); + EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece); + invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket); + if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return invisibleArmorStand; + } + + private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { + Validator.isTrue(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 + // This should never happen nmsEntity.dead = true; return false; } nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity); if (VersionUtils.isPaperServer()) { - 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 (Exception e) { - e.printStackTrace(); - return false; - } + 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 (Exception e) { + e.printStackTrace(); + return false; + } } else { - nmsWorld.entityList.add(nmsEntity); + nmsWorld.entityList.add(nmsEntity); } try { - validateEntityMethod.invoke(nmsWorld, nmsEntity); - } catch (Exception e) { - e.printStackTrace(); - return false; - } + validateEntityMethod.invoke(nmsWorld, nmsEntity); + } catch (Exception e) { + e.printStackTrace(); + return false; + } return true; } - - @Override - public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase; - } + + @Override + public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { + return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase; + } - @Override - public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - - if (nmsEntity instanceof NMSEntityBase) { - return ((NMSEntityBase) nmsEntity); - } else { - return null; - } - } - - @Override - public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - Entity nmsEntity = nmsWorld.getEntity(entityID); - - if (nmsEntity instanceof NMSEntityBase) { - return ((NMSEntityBase) nmsEntity); - } else { - return null; - } - } - - @Override - public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { - return CustomNameHelper.replaceCustomNameChatComponent(NMSChatComponentAdapter.INSTANCE, customNameObject, target, replacement); - } - - private static enum NMSChatComponentAdapter implements ChatComponentAdapter { + @Override + public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { + Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); + + if (nmsEntity instanceof NMSEntityBase) { + return ((NMSEntityBase) nmsEntity); + } else { + return null; + } + } + + @Override + public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + Entity nmsEntity = nmsWorld.getEntity(entityID); + + if (nmsEntity instanceof NMSEntityBase) { + return ((NMSEntityBase) nmsEntity); + } else { + return null; + } + } + + @Override + public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { + return CustomNameHelper.replaceCustomNameChatComponent(NMSChatComponentAdapter.INSTANCE, customNameObject, target, replacement); + } + + private static enum NMSChatComponentAdapter implements ChatComponentAdapter { - INSTANCE { - - public ChatComponentText cast(Object chatComponentObject) { - return (ChatComponentText) chatComponentObject; - } - - @Override - public String getText(IChatBaseComponent chatComponent) { - return chatComponent.getText(); - } - - @Override - public List getSiblings(IChatBaseComponent chatComponent) { - return chatComponent.a(); - } - - @Override - public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) { - chatComponent.addSibling(newSibling); - } - - @Override - public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) { - ChatComponentText clonedChatComponent = new ChatComponentText(newText); - clonedChatComponent.setChatModifier(chatComponent.getChatModifier().clone()); - return clonedChatComponent; - } - - } - - } - + INSTANCE { + + public ChatComponentText cast(Object chatComponentObject) { + return (ChatComponentText) chatComponentObject; + } + + @Override + public String getText(IChatBaseComponent chatComponent) { + return chatComponent.getText(); + } + + @Override + public List getSiblings(IChatBaseComponent chatComponent) { + return chatComponent.a(); + } + + @Override + public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) { + chatComponent.addSibling(newSibling); + } + + @Override + public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) { + ChatComponentText clonedChatComponent = new ChatComponentText(newText); + clonedChatComponent.setChatModifier(chatComponent.getChatModifier().clone()); + return clonedChatComponent; + } + + } + + } + } 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 index cac16764..6126ce4b 100644 --- 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 @@ -22,111 +22,111 @@ import net.minecraft.server.v1_13_R2.Vec3D; public class NullBoundingBox extends AxisAlignedBB { - public NullBoundingBox() { - super(0, 0, 0, 0, 0, 0); - } + public NullBoundingBox() { + super(0, 0, 0, 0, 0, 0); + } - @Override - public double a() { - return 0.0; - } + @Override + public double a() { + return 0.0; + } - @Override - public AxisAlignedBB a(AxisAlignedBB arg0) { - return this; - } + @Override + public AxisAlignedBB a(AxisAlignedBB arg0) { + return this; + } - @Override - public AxisAlignedBB a(double arg0, double arg1, double arg2) { - 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 MovingObjectPosition b(Vec3D arg0, Vec3D arg1) { + return null; + } - @Override - public AxisAlignedBB grow(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 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 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 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 a(Vec3D arg0) { + return this; + } - @Override - public AxisAlignedBB b(AxisAlignedBB 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 AxisAlignedBB b(double arg0, double arg1, double arg2) { + return this; + } - @Override - public boolean c(AxisAlignedBB arg0) { - return false; - } + @Override + public boolean c(AxisAlignedBB arg0) { + return false; + } - @Override - public AxisAlignedBB d(double arg0, double arg1, double arg2) { - return this; - } + @Override + public AxisAlignedBB d(double arg0, double arg1, double arg2) { + return this; + } - @Override - public double a(EnumAxis arg0) { - return 0.0; - } + @Override + public double a(EnumAxis arg0) { + return 0.0; + } - @Override - public MovingObjectPosition a(Vec3D arg0, Vec3D arg1, BlockPosition arg2) { - return null; - } + @Override + public MovingObjectPosition a(Vec3D arg0, Vec3D arg1, BlockPosition arg2) { + return null; + } - @Override - public double b(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 boolean e(double arg0, double arg1, double arg2) { + return false; + } - @Override - public AxisAlignedBB f(double arg0, double arg1, double arg2) { - return this; - } - - - + @Override + public AxisAlignedBB f(double arg0, double arg1, double arg2) { + return this; + } + + + } diff --git a/nms/v1_14_r1/pom.xml b/nms/v1_14_r1/pom.xml index 282b0255..141d6095 100644 --- a/nms/v1_14_r1/pom.xml +++ b/nms/v1_14_r1/pom.xml @@ -1,41 +1,41 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - - me.filoghost.holographicdisplays - holographicdisplays-nms - 3.0.0-SNAPSHOT - + + me.filoghost.holographicdisplays + holographicdisplays-nms + 3.0.0-SNAPSHOT + - holographicdisplays-nms-v1_14_r1 - HolographicDisplays NMS v1_14_R1 + holographicdisplays-nms-v1_14_r1 + HolographicDisplays NMS v1_14_R1 - - - nms-repo - https://repo.codemc.io/repository/nms/ - - + + + nms-repo + https://repo.codemc.io/repository/nms/ + + - - - ${project.groupId} - holographicdisplays-nms-interfaces - - - - ${project.groupId} - holographicdisplays-utils - - - - org.spigotmc - spigot - 1.14.4-R0.1-SNAPSHOT - provided - - + + + ${project.groupId} + holographicdisplays-nms-interfaces + + + + ${project.groupId} + holographicdisplays-utils + + + + org.spigotmc + spigot + 1.14.4-R0.1-SNAPSHOT + provided + + - \ No newline at end of file + 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 index e7b5cda1..ab4712e5 100644 --- 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 @@ -29,68 +29,68 @@ 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. - } + 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 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 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) { } - - + // 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 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 index 0370fcb3..7136ebba 100644 --- 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 @@ -25,41 +25,41 @@ import org.bukkit.util.Vector; public class CraftNMSItem extends CraftItem { - public CraftNMSItem(CraftServer server, EntityNMSItem entity) { - super(server, entity); - } + 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) { } + // 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 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) { } - + // 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 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 index 73557f43..81db889f 100644 --- 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 @@ -29,57 +29,57 @@ 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) { } + 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 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) { } + // 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 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 index 4b74ce3b..07c0f99f 100644 --- 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 @@ -37,210 +37,210 @@ import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_14_R1.util.CraftChatMessage; public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand { - - private HologramLine parentPiece; - private CraftEntity customBukkitEntity; - private String customName; - - public EntityNMSArmorStand(World world, HologramLine parentPiece) { - super(EntityTypes.ARMOR_STAND, world); - super.setInvisible(true); - super.setSmall(true); - super.setArms(false); - super.setNoGravity(true); - super.setBasePlate(true); - super.setMarker(true); - super.collides = false; - this.parentPiece = parentPiece; - forceSetBoundingBox(new NullBoundingBox()); - - this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet. - } - - @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 (this.onGround) { - this.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 (this.onGround) { - this.onGround = false; - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT. - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT. - return false; - } + + private HologramLine parentPiece; + private CraftEntity customBukkitEntity; + private String customName; + + public EntityNMSArmorStand(World world, HologramLine parentPiece) { + super(EntityTypes.ARMOR_STAND, world); + super.setInvisible(true); + super.setSmall(true); + super.setArms(false); + super.setNoGravity(true); + super.setBasePlate(true); + super.setMarker(true); + super.collides = false; + this.parentPiece = parentPiece; + forceSetBoundingBox(new NullBoundingBox()); + + this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet. + } + + @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 (this.onGround) { + this.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 (this.onGround) { + this.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) { - // Locks the custom name. - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Locks the custom name. - } + @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) { + // Locks the custom name. + } + + @Override + public void setCustomNameVisible(boolean visible) { + // Locks the custom name. + } - @Override - public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) { - // Prevent stand being equipped - return EnumInteractionResult.PASS; - } + @Override + public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) { + // Prevent stand being equipped + return EnumInteractionResult.PASS; + } - @Override - public boolean a_(int i, ItemStack item) { - // Prevent stand being equipped - return false; - } + @Override + public boolean a_(int i, ItemStack item) { + // Prevent stand being equipped + return false; + } - @Override - public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { - // Prevent stand being equipped - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Do not change it! - } - - 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 name) { - this.customName = Utils.limitLength(name, 300); - super.setCustomName(CraftChatMessage.fromStringOrNull(customName)); - super.setCustomNameVisible(customName != null && !customName.isEmpty()); - } - - @Override - public String getCustomNameStringNMS() { - return this.customName; - } - - @Override - public Object getCustomNameObjectNMS() { - return super.getCustomName(); - } + @Override + public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { + // Prevent stand being equipped + } + + @Override + public void a(AxisAlignedBB boundingBox) { + // Do not change it! + } + + 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 name) { + this.customName = Utils.limitLength(name, 300); + super.setCustomName(CraftChatMessage.fromStringOrNull(customName)); + super.setCustomNameVisible(customName != null && !customName.isEmpty()); + } + + @Override + public String getCustomNameStringNMS() { + return this.customName; + } + + @Override + public Object getCustomNameObjectNMS() { + return super.getCustomName(); + } - @Override - public void die() { - // Prevent being killed. - } - - @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, boolean broadcastLocationPacket) { - super.setPosition(x, y, z); - if (broadcastLocationPacket) { - broadcastLocationPacketNMS(); - } - } - - private void broadcastLocationPacketNMS() { - PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); - - for (Object obj : super.world.getPlayers()) { - if (obj instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) obj; + @Override + public void die() { + // Prevent being killed. + } + + @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, boolean broadcastLocationPacket) { + super.setPosition(x, y, z); + if (broadcastLocationPacket) { + broadcastLocationPacketNMS(); + } + } + + private void broadcastLocationPacketNMS() { + PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); + + for (Object obj : super.world.getPlayers()) { + if (obj instanceof EntityPlayer) { + EntityPlayer nmsPlayer = (EntityPlayer) obj; - double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ); - if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(teleportPacket); - } - } - } - } + double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ); + if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) { + nmsPlayer.playerConnection.sendPacket(teleportPacket); + } + } + } + } - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public int getIdNMS() { - return super.getId(); - } + @Override + public boolean isDeadNMS() { + return super.dead; + } + + @Override + public int getIdNMS() { + return super.getId(); + } - @Override - public HologramLine getHologramLine() { - return parentPiece; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } + @Override + public HologramLine getHologramLine() { + return parentPiece; + } + + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } } 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 index f2718d34..bc4efe08 100644 --- 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 @@ -40,208 +40,208 @@ import org.bukkit.entity.Player; import java.util.logging.Level; public class EntityNMSItem extends EntityItem implements NMSItem { - - private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "vehicle"); - - private ItemLine parentPiece; - private ItemPickupManager itemPickupManager; - private CraftEntity customBukkitEntity; - - public EntityNMSItem(World world, ItemLine piece, ItemPickupManager itemPickupManager) { - super(EntityTypes.ITEM, world); - super.pickupDelay = 32767; // Lock the item pickup delay, also prevents entities from picking up the item - this.parentPiece = piece; - this.itemPickupManager = itemPickupManager; - } - - @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 (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) { - itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent()); - // 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; - } + + private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "vehicle"); + + private ItemLine parentPiece; + private ItemPickupManager itemPickupManager; + private CraftEntity customBukkitEntity; + + public EntityNMSItem(World world, ItemLine piece, ItemPickupManager itemPickupManager) { + super(EntityTypes.ITEM, world); + super.pickupDelay = 32767; // Lock the item pickup delay, also prevents entities from picking up the item + this.parentPiece = piece; + this.itemPickupManager = itemPickupManager; + } + + @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 (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) { + itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent()); + // 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 being killed. - } - - @Override - public boolean isAlive() { - // This override prevents items from being picked up by hoppers. - // Should have no side effects. - 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 being killed. + } + + @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 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 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); // ItemStack.a is returned if the stack is null, invalid or the material is not an Item - - if (newItem == null || newItem == ItemStack.a) { - newItem = new ItemStack(Blocks.BEDROCK); - } + @Override + public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) { + ItemStack newItem = CraftItemStack.asNMSCopy(stack); // ItemStack.a is returned if the stack is null, invalid or the material is not an Item + + if (newItem == null || newItem == ItemStack.a) { + 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); - } + 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(ItemUtils.ANTISTACK_LORE)); // Antistack lore - display.set("Lore", tagList); - - setItemStack(newItem); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public ItemLine getHologramLine() { - return parentPiece; - } - - @Override - public void allowPickup(boolean pickup) { - if (pickup) { - super.pickupDelay = 0; - } else { - super.pickupDelay = 32767; - } - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public void setPassengerOfNMS(NMSEntityBase vehicleBase) { - if (vehicleBase == null || !(vehicleBase instanceof Entity)) { - // It should never dismount - return; - } - - Entity entity = (Entity) vehicleBase; + NBTTagList tagList = new NBTTagList(); + tagList.add(new NBTTagString(ItemUtils.ANTISTACK_LORE)); // Antistack lore + display.set("Lore", tagList); + + setItemStack(newItem); + } + + @Override + public int getIdNMS() { + return super.getId(); + } + + @Override + public ItemLine getHologramLine() { + return parentPiece; + } + + @Override + public void allowPickup(boolean pickup) { + if (pickup) { + super.pickupDelay = 0; + } else { + super.pickupDelay = 32767; + } + } + + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } + + @Override + public void setPassengerOfNMS(NMSEntityBase vehicleBase) { + if (vehicleBase == null || !(vehicleBase instanceof Entity)) { + // It should never dismount + return; + } + + Entity entity = (Entity) vehicleBase; - try { - if (super.getVehicle() != null) { - Entity oldVehicle = super.getVehicle(); - VEHICLE_FIELD.set(this, null); - oldVehicle.passengers.remove(this); - } + try { + if (super.getVehicle() != null) { + Entity oldVehicle = super.getVehicle(); + VEHICLE_FIELD.set(this, null); + oldVehicle.passengers.remove(this); + } - VEHICLE_FIELD.set(this, entity); - entity.passengers.clear(); - entity.passengers.add(this); + VEHICLE_FIELD.set(this, entity); + entity.passengers.clear(); + entity.passengers.add(this); - } catch (Throwable t) { - ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); - } - } + } catch (Throwable t) { + ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); + } + } - @Override - public Object getRawItemStack() { - return super.getItemStack(); - } + @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 index d5f554cd..d78b4452 100644 --- 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 @@ -37,187 +37,187 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import java.util.logging.Level; public class EntityNMSSlime extends EntitySlime implements NMSSlime { - - private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "vehicle"); + + private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "vehicle"); - private HologramLine parentPiece; - private CraftEntity customBukkitEntity; - - public EntityNMSSlime(World world, HologramLine parentPiece) { - super(EntityTypes.SLIME, world); - super.persistent = true; - super.collides = false; - a(0.0F, 0.0F); - setSize(1, false); - setInvisible(true); - this.parentPiece = parentPiece; - 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) { - // Do not change it! - } - - 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; - } + private HologramLine parentPiece; + private CraftEntity customBukkitEntity; + + public EntityNMSSlime(World world, HologramLine parentPiece) { + super(EntityTypes.SLIME, world); + super.persistent = true; + super.collides = false; + a(0.0F, 0.0F); + setSize(1, false); + setInvisible(true); + this.parentPiece = parentPiece; + 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) { + // Do not change it! + } + + 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) { - Bukkit.getPluginManager().callEvent(new PlayerInteractEntityEvent(((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(), getBukkitEntity())); // 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 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) { + Bukkit.getPluginManager().callEvent(new PlayerInteractEntityEvent(((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(), getBukkitEntity())); // 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) { - // Locks the custom name. - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Locks the custom name. - } - - @Override - public void a(SoundEffect soundeffect, float f, float f1) { - // Remove sounds. - } - - @Override - public void die() { - // Prevent being killed. - } - - @Override - public CraftEntity getBukkitEntity() { - if (customBukkitEntity == null) { - customBukkitEntity = new CraftNMSSlime(super.world.getServer(), this); - } - return customBukkitEntity; - } + @Override + public void setCustomName(IChatBaseComponent ichatbasecomponent) { + // Locks the custom name. + } + + @Override + public void setCustomNameVisible(boolean visible) { + // Locks the custom name. + } + + @Override + public void a(SoundEffect soundeffect, float f, float f1) { + // Remove sounds. + } + + @Override + public void die() { + // Prevent being killed. + } + + @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 HologramLine getHologramLine() { - return parentPiece; - } + @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 HologramLine getHologramLine() { + return parentPiece; + } - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public void setPassengerOfNMS(NMSEntityBase vehicleBase) { - if (vehicleBase == null || !(vehicleBase instanceof Entity)) { - // It should never dismount - return; - } - - Entity entity = (Entity) vehicleBase; - - try { - if (super.getVehicle() != null) { - Entity oldVehicle = super.getVehicle(); - VEHICLE_FIELD.set(this, null); - oldVehicle.passengers.remove(this); - } + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } + + @Override + public void setPassengerOfNMS(NMSEntityBase vehicleBase) { + if (vehicleBase == null || !(vehicleBase instanceof Entity)) { + // It should never dismount + return; + } + + Entity entity = (Entity) vehicleBase; + + try { + if (super.getVehicle() != null) { + Entity oldVehicle = super.getVehicle(); + VEHICLE_FIELD.set(this, null); + oldVehicle.passengers.remove(this); + } - VEHICLE_FIELD.set(this, entity); - entity.passengers.clear(); - entity.passengers.add(this); + VEHICLE_FIELD.set(this, entity); + entity.passengers.clear(); + entity.passengers.add(this); - } catch (Throwable t) { - ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); - } - } + } catch (Throwable t) { + ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); + } + } } diff --git a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/NmsManagerImpl.java b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/NmsManagerImpl.java index c3f76143..010c6c0f 100644 --- a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/NmsManagerImpl.java +++ b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/NmsManagerImpl.java @@ -46,169 +46,169 @@ import org.bukkit.inventory.ItemStack; import java.util.List; public class NmsManagerImpl implements NMSManager { - - private static final ReflectField>> REGISTRY_ID_FIELD = new ReflectField<>(RegistryMaterials.class, "b"); - private static final ReflectField ID_TO_CLASS_MAP_FIELD = new ReflectField<>(RegistryID.class, "d"); - private static final ReflectMethod REGISTER_ENTITY_METHOD = new ReflectMethod<>(WorldServer.class, "registerEntity", Entity.class); - - @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]; + + private static final ReflectField>> REGISTRY_ID_FIELD = new ReflectField<>(RegistryMaterials.class, "b"); + private static final ReflectField ID_TO_CLASS_MAP_FIELD = new ReflectField<>(RegistryID.class, "d"); + private static final ReflectMethod REGISTER_ENTITY_METHOD = new ReflectMethod<>(WorldServer.class, "registerEntity", Entity.class); + + @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); + // 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(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager); - customItem.setLocationNMS(x, y, z); - customItem.setItemStackNMS(stack); - if (!addEntityToWorld(nmsWorld, customItem)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return customItem; - } - - @Override - public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramLine parentPiece) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece); - touchSlime.setLocationNMS(x, y, z); - if (!addEntityToWorld(nmsWorld, touchSlime)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return touchSlime; - } - - @Override - public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) { - WorldServer nmsWorld = ((CraftWorld) world).getHandle(); - EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece); - invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket); - if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return invisibleArmorStand; - } - - private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { - Validator.isTrue(Bukkit.isPrimaryThread(), "Async entity add"); - + // Restore the ID -> EntityTypes mapping. + idToClassMap[id] = oldValue; + } + + @Override + public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager); + customItem.setLocationNMS(x, y, z); + customItem.setItemStackNMS(stack); + if (!addEntityToWorld(nmsWorld, customItem)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return customItem; + } + + @Override + public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramLine parentPiece) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece); + touchSlime.setLocationNMS(x, y, z); + if (!addEntityToWorld(nmsWorld, touchSlime)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return touchSlime; + } + + @Override + public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) { + WorldServer nmsWorld = ((CraftWorld) world).getHandle(); + EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece); + invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket); + if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return invisibleArmorStand; + } + + private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { + Validator.isTrue(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 + // This should never happen nmsEntity.dead = true; return false; } nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity); try { - REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity); - return true; - } catch (Exception e) { - e.printStackTrace(); - return false; - } + REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + @Override + public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { + return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase; } - - @Override - public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase; - } - @Override - public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - - if (nmsEntity instanceof NMSEntityBase) { - return ((NMSEntityBase) nmsEntity); - } else { - return null; - } - } - - @Override - public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - Entity nmsEntity = nmsWorld.getEntity(entityID); - - if (nmsEntity instanceof NMSEntityBase) { - return ((NMSEntityBase) nmsEntity); - } else { - return null; - } - } - - @Override - public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { - return CustomNameHelper.replaceCustomNameChatComponent(NMSChatComponentAdapter.INSTANCE, customNameObject, target, replacement); - } - - private static enum NMSChatComponentAdapter implements ChatComponentAdapter { + @Override + public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { + Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); + + if (nmsEntity instanceof NMSEntityBase) { + return ((NMSEntityBase) nmsEntity); + } else { + return null; + } + } + + @Override + public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + Entity nmsEntity = nmsWorld.getEntity(entityID); + + if (nmsEntity instanceof NMSEntityBase) { + return ((NMSEntityBase) nmsEntity); + } else { + return null; + } + } + + @Override + public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { + return CustomNameHelper.replaceCustomNameChatComponent(NMSChatComponentAdapter.INSTANCE, customNameObject, target, replacement); + } + + private static enum NMSChatComponentAdapter implements ChatComponentAdapter { - INSTANCE { - - private boolean useNewGetSiblingsMethod = true; - private final ReflectField> OLD_SIBLINGS_FIELD = new ReflectField<>(ChatBaseComponent.class, "a"); - - public ChatComponentText cast(Object chatComponentObject) { - return (ChatComponentText) chatComponentObject; - } - - @Override - public String getText(IChatBaseComponent chatComponent) { - return chatComponent.getText(); - } - - @Override - public List getSiblings(IChatBaseComponent chatComponent) { - if (useNewGetSiblingsMethod) { - try { - return chatComponent.getSiblings(); - } catch (NoSuchMethodError e) { - // The method was named differently in older 1.14 versions, use workaround. - useNewGetSiblingsMethod = false; - } - } - - // Access siblings field directly in older 1.14 versions. - try { - return OLD_SIBLINGS_FIELD.get(chatComponent); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - @Override - public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) { - chatComponent.addSibling(newSibling); - } - - @Override - public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) { - ChatComponentText clonedChatComponent = new ChatComponentText(newText); - clonedChatComponent.setChatModifier(chatComponent.getChatModifier().clone()); - return clonedChatComponent; - } - - } - - } - + INSTANCE { + + private boolean useNewGetSiblingsMethod = true; + private final ReflectField> OLD_SIBLINGS_FIELD = new ReflectField<>(ChatBaseComponent.class, "a"); + + public ChatComponentText cast(Object chatComponentObject) { + return (ChatComponentText) chatComponentObject; + } + + @Override + public String getText(IChatBaseComponent chatComponent) { + return chatComponent.getText(); + } + + @Override + public List getSiblings(IChatBaseComponent chatComponent) { + if (useNewGetSiblingsMethod) { + try { + return chatComponent.getSiblings(); + } catch (NoSuchMethodError e) { + // The method was named differently in older 1.14 versions, use workaround. + useNewGetSiblingsMethod = false; + } + } + + // Access siblings field directly in older 1.14 versions. + try { + return OLD_SIBLINGS_FIELD.get(chatComponent); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) { + chatComponent.addSibling(newSibling); + } + + @Override + public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) { + ChatComponentText clonedChatComponent = new ChatComponentText(newText); + clonedChatComponent.setChatModifier(chatComponent.getChatModifier().clone()); + return clonedChatComponent; + } + + } + + } + } 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 index e7e43955..bf9824d0 100644 --- 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 @@ -21,116 +21,116 @@ import net.minecraft.server.v1_14_R1.Vec3D; public class NullBoundingBox extends AxisAlignedBB { - public NullBoundingBox() { - super(0, 0, 0, 0, 0, 0); - } + public NullBoundingBox() { + super(0, 0, 0, 0, 0, 0); + } - @Override - public double a() { - return 0.0; - } + @Override + public double a() { + return 0.0; + } - @Override - public AxisAlignedBB a(AxisAlignedBB arg0) { - return this; - } + @Override + public AxisAlignedBB a(AxisAlignedBB arg0) { + return this; + } - @Override - public AxisAlignedBB a(double arg0, double arg1, double arg2) { - 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 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 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 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 a(Vec3D arg0) { + return this; + } - @Override - public AxisAlignedBB b(AxisAlignedBB 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 AxisAlignedBB b(double arg0, double arg1, double arg2) { + return this; + } - @Override - public boolean c(AxisAlignedBB arg0) { - return false; - } + @Override + public boolean c(AxisAlignedBB arg0) { + return false; + } - @Override - public AxisAlignedBB d(double arg0, double arg1, double arg2) { - return this; - } + @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 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 boolean e(double arg0, double arg1, double arg2) { + return false; + } - @Override - public double b() { - return 0.0; - } + @Override + public double b() { + return 0.0; + } - @Override - public double c() { - return 0.0; - } - - @Override - public double d() { - 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 boolean c(Vec3D var0) { + return false; + } - @Override - public Vec3D f() { - return Vec3D.a; - } - - - + @Override + public Vec3D f() { + return Vec3D.a; + } + + + } diff --git a/nms/v1_15_r1/pom.xml b/nms/v1_15_r1/pom.xml index b3aee6cf..c3f7d593 100644 --- a/nms/v1_15_r1/pom.xml +++ b/nms/v1_15_r1/pom.xml @@ -1,41 +1,41 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - - me.filoghost.holographicdisplays - holographicdisplays-nms - 3.0.0-SNAPSHOT - + + me.filoghost.holographicdisplays + holographicdisplays-nms + 3.0.0-SNAPSHOT + - holographicdisplays-nms-v1_15_r1 - HolographicDisplays NMS v1_15_R1 + holographicdisplays-nms-v1_15_r1 + HolographicDisplays NMS v1_15_R1 - - - nms-repo - https://repo.codemc.io/repository/nms/ - - + + + nms-repo + https://repo.codemc.io/repository/nms/ + + - - - ${project.groupId} - holographicdisplays-nms-interfaces - - - - ${project.groupId} - holographicdisplays-utils - - - - org.spigotmc - spigot - 1.15-R0.1-SNAPSHOT - provided - - + + + ${project.groupId} + holographicdisplays-nms-interfaces + + + + ${project.groupId} + holographicdisplays-utils + + + + org.spigotmc + spigot + 1.15-R0.1-SNAPSHOT + provided + + - \ No newline at end of file + 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 index ed659f68..6ec0061f 100644 --- 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 @@ -29,68 +29,68 @@ 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. - } + 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 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 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) { } - - + // 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 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 index 6cdb9232..c0596433 100644 --- 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 @@ -25,41 +25,41 @@ import org.bukkit.util.Vector; public class CraftNMSItem extends CraftItem { - public CraftNMSItem(CraftServer server, EntityNMSItem entity) { - super(server, entity); - } + 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) { } + // 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 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) { } - + // 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 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 index 605b8a9e..b4f19f72 100644 --- 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 @@ -29,57 +29,57 @@ 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) { } + 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 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) { } + // 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 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 index e9cbd721..795c0ef6 100644 --- 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 @@ -57,25 +57,25 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet. } - @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 (this.onGround) { - this.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 (this.onGround) { - this.onGround = false; - } - } + @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 (this.onGround) { + this.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 (this.onGround) { + this.onGround = false; + } + } @Override public void b(NBTTagCompound nbttagcompound) { @@ -178,10 +178,10 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta return this.customName; } - @Override - public Object getCustomNameObjectNMS() { - return super.getCustomName(); - } + @Override + public Object getCustomNameObjectNMS() { + return super.getCustomName(); + } @Override public void die() { @@ -205,7 +205,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta public void setLocationNMS(double x, double y, double z, boolean broadcastLocationPacket) { super.setPosition(x, y, z); if (broadcastLocationPacket) { - broadcastLocationPacketNMS(); + broadcastLocationPacketNMS(); } } 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 index 3c046696..fcf537bf 100644 --- 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 @@ -56,19 +56,19 @@ public class EntityNMSItem extends EntityItem implements NMSItem { @Override public void tick() { - // Disable normal ticking for this entity. + // 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; - } + 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 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 index ee0337a4..376d0e74 100644 --- 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 @@ -37,187 +37,187 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import java.util.logging.Level; public class EntityNMSSlime extends EntitySlime implements NMSSlime { - - private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "vehicle"); + + private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "vehicle"); - private HologramLine parentPiece; - private CraftEntity customBukkitEntity; - - public EntityNMSSlime(World world, HologramLine parentPiece) { - super(EntityTypes.SLIME, world); - super.persistent = true; - super.collides = false; - a(0.0F, 0.0F); - setSize(1, false); - setInvisible(true); - this.parentPiece = parentPiece; - 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) { - // Do not change it! - } - - 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; - } + private HologramLine parentPiece; + private CraftEntity customBukkitEntity; + + public EntityNMSSlime(World world, HologramLine parentPiece) { + super(EntityTypes.SLIME, world); + super.persistent = true; + super.collides = false; + a(0.0F, 0.0F); + setSize(1, false); + setInvisible(true); + this.parentPiece = parentPiece; + 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) { + // Do not change it! + } + + 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) { - Bukkit.getPluginManager().callEvent(new PlayerInteractEntityEvent(((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(), getBukkitEntity())); // 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 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) { + Bukkit.getPluginManager().callEvent(new PlayerInteractEntityEvent(((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(), getBukkitEntity())); // 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) { - // Locks the custom name. - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Locks the custom name. - } - - @Override - public void a(SoundEffect soundeffect, float f, float f1) { - // Remove sounds. - } - - @Override - public void die() { - // Prevent being killed. - } - - @Override - public CraftEntity getBukkitEntity() { - if (customBukkitEntity == null) { - customBukkitEntity = new CraftNMSSlime(super.world.getServer(), this); - } - return customBukkitEntity; - } + @Override + public void setCustomName(IChatBaseComponent ichatbasecomponent) { + // Locks the custom name. + } + + @Override + public void setCustomNameVisible(boolean visible) { + // Locks the custom name. + } + + @Override + public void a(SoundEffect soundeffect, float f, float f1) { + // Remove sounds. + } + + @Override + public void die() { + // Prevent being killed. + } + + @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 HologramLine getHologramLine() { - return parentPiece; - } + @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 HologramLine getHologramLine() { + return parentPiece; + } - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public void setPassengerOfNMS(NMSEntityBase vehicleBase) { - if (vehicleBase == null || !(vehicleBase instanceof Entity)) { - // It should never dismount - return; - } - - Entity entity = (Entity) vehicleBase; - - try { - if (super.getVehicle() != null) { - Entity oldVehicle = super.getVehicle(); - VEHICLE_FIELD.set(this, null); - oldVehicle.passengers.remove(this); - } + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } + + @Override + public void setPassengerOfNMS(NMSEntityBase vehicleBase) { + if (vehicleBase == null || !(vehicleBase instanceof Entity)) { + // It should never dismount + return; + } + + Entity entity = (Entity) vehicleBase; + + try { + if (super.getVehicle() != null) { + Entity oldVehicle = super.getVehicle(); + VEHICLE_FIELD.set(this, null); + oldVehicle.passengers.remove(this); + } - VEHICLE_FIELD.set(this, entity); - entity.passengers.clear(); - entity.passengers.add(this); + VEHICLE_FIELD.set(this, entity); + entity.passengers.clear(); + entity.passengers.add(this); - } catch (Throwable t) { - ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); - } - } + } catch (Throwable t) { + ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); + } + } } diff --git a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/NmsManagerImpl.java b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/NmsManagerImpl.java index f6857e5d..21189f08 100644 --- a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/NmsManagerImpl.java +++ b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/NmsManagerImpl.java @@ -45,152 +45,152 @@ import org.bukkit.inventory.ItemStack; import java.util.List; public class NmsManagerImpl implements NMSManager { - - private static final ReflectField>> REGISTRY_ID_FIELD = new ReflectField<>(RegistryMaterials.class, "b"); - private static final ReflectField ID_TO_CLASS_MAP_FIELD = new ReflectField<>(RegistryID.class, "d"); - private static final ReflectMethod REGISTER_ENTITY_METHOD = new ReflectMethod<>(WorldServer.class, "registerEntity", Entity.class); - - @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]; + + private static final ReflectField>> REGISTRY_ID_FIELD = new ReflectField<>(RegistryMaterials.class, "b"); + private static final ReflectField ID_TO_CLASS_MAP_FIELD = new ReflectField<>(RegistryID.class, "d"); + private static final ReflectMethod REGISTER_ENTITY_METHOD = new ReflectMethod<>(WorldServer.class, "registerEntity", Entity.class); + + @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); + // 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(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager); - customItem.setLocationNMS(x, y, z); - customItem.setItemStackNMS(stack); - if (!addEntityToWorld(nmsWorld, customItem)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return customItem; - } - - @Override - public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramLine parentPiece) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece); - touchSlime.setLocationNMS(x, y, z); - if (!addEntityToWorld(nmsWorld, touchSlime)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return touchSlime; - } - - @Override - public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) { - WorldServer nmsWorld = ((CraftWorld) world).getHandle(); - EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece); - invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket); - if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return invisibleArmorStand; - } - - private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { - Validator.isTrue(Bukkit.isPrimaryThread(), "Async entity add"); - + // Restore the ID -> EntityTypes mapping. + idToClassMap[id] = oldValue; + } + + @Override + public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager); + customItem.setLocationNMS(x, y, z); + customItem.setItemStackNMS(stack); + if (!addEntityToWorld(nmsWorld, customItem)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return customItem; + } + + @Override + public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramLine parentPiece) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece); + touchSlime.setLocationNMS(x, y, z); + if (!addEntityToWorld(nmsWorld, touchSlime)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return touchSlime; + } + + @Override + public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) { + WorldServer nmsWorld = ((CraftWorld) world).getHandle(); + EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece); + invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket); + if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return invisibleArmorStand; + } + + private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { + Validator.isTrue(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 + // This should never happen nmsEntity.dead = true; return false; } nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity); try { - REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity); - return true; - } catch (Exception e) { - e.printStackTrace(); - return false; - } + REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + @Override + public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { + return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase; } - - @Override - public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase; - } - @Override - public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - - if (nmsEntity instanceof NMSEntityBase) { - return ((NMSEntityBase) nmsEntity); - } else { - return null; - } - } - - @Override - public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - Entity nmsEntity = nmsWorld.getEntity(entityID); - - if (nmsEntity instanceof NMSEntityBase) { - return ((NMSEntityBase) nmsEntity); - } else { - return null; - } - } - - @Override - public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { - return CustomNameHelper.replaceCustomNameChatComponent(NMSChatComponentAdapter.INSTANCE, customNameObject, target, replacement); - } - - private static enum NMSChatComponentAdapter implements ChatComponentAdapter { + @Override + public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { + Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); + + if (nmsEntity instanceof NMSEntityBase) { + return ((NMSEntityBase) nmsEntity); + } else { + return null; + } + } + + @Override + public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + Entity nmsEntity = nmsWorld.getEntity(entityID); + + if (nmsEntity instanceof NMSEntityBase) { + return ((NMSEntityBase) nmsEntity); + } else { + return null; + } + } + + @Override + public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { + return CustomNameHelper.replaceCustomNameChatComponent(NMSChatComponentAdapter.INSTANCE, customNameObject, target, replacement); + } + + private static enum NMSChatComponentAdapter implements ChatComponentAdapter { - INSTANCE { - - public ChatComponentText cast(Object chatComponentObject) { - return (ChatComponentText) chatComponentObject; - } - - @Override - public String getText(IChatBaseComponent chatComponent) { - return chatComponent.getText(); - } - - @Override - public List getSiblings(IChatBaseComponent chatComponent) { - return chatComponent.getSiblings(); - } - - @Override - public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) { - chatComponent.addSibling(newSibling); - } - - @Override - public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) { - ChatComponentText clonedChatComponent = new ChatComponentText(newText); - clonedChatComponent.setChatModifier(chatComponent.getChatModifier().clone()); - return clonedChatComponent; - } - - } - - } - + INSTANCE { + + public ChatComponentText cast(Object chatComponentObject) { + return (ChatComponentText) chatComponentObject; + } + + @Override + public String getText(IChatBaseComponent chatComponent) { + return chatComponent.getText(); + } + + @Override + public List getSiblings(IChatBaseComponent chatComponent) { + return chatComponent.getSiblings(); + } + + @Override + public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) { + chatComponent.addSibling(newSibling); + } + + @Override + public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) { + ChatComponentText clonedChatComponent = new ChatComponentText(newText); + clonedChatComponent.setChatModifier(chatComponent.getChatModifier().clone()); + return clonedChatComponent; + } + + } + + } + } diff --git a/nms/v1_16_r1/pom.xml b/nms/v1_16_r1/pom.xml index 69cde156..134debaa 100644 --- a/nms/v1_16_r1/pom.xml +++ b/nms/v1_16_r1/pom.xml @@ -1,41 +1,41 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - - me.filoghost.holographicdisplays - holographicdisplays-nms - 3.0.0-SNAPSHOT - + + me.filoghost.holographicdisplays + holographicdisplays-nms + 3.0.0-SNAPSHOT + - holographicdisplays-nms-v1_16_r1 - HolographicDisplays NMS v1_16_R1 + holographicdisplays-nms-v1_16_r1 + HolographicDisplays NMS v1_16_R1 - - - nms-repo - https://repo.codemc.io/repository/nms/ - - + + + nms-repo + https://repo.codemc.io/repository/nms/ + + - - - ${project.groupId} - holographicdisplays-nms-interfaces - - - - ${project.groupId} - holographicdisplays-utils - - - - org.spigotmc - spigot - 1.16.1-R0.1-SNAPSHOT - provided - - + + + ${project.groupId} + holographicdisplays-nms-interfaces + + + + ${project.groupId} + holographicdisplays-utils + + + + org.spigotmc + spigot + 1.16.1-R0.1-SNAPSHOT + provided + + - \ No newline at end of file + 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 index fdca6e6c..b403b3e0 100644 --- 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 @@ -29,68 +29,68 @@ 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. - } + 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 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 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) { } - - + // 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 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 index bdbf7da5..6a03f3ef 100644 --- 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 @@ -25,41 +25,41 @@ import org.bukkit.util.Vector; public class CraftNMSItem extends CraftItem { - public CraftNMSItem(CraftServer server, EntityNMSItem entity) { - super(server, entity); - } + 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) { } + // 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 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) { } - + // 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 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 index cda1838d..129948a3 100644 --- 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 @@ -29,57 +29,57 @@ 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) { } + 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 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) { } + // 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 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 index bfc4cba1..c944a2b3 100644 --- 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 @@ -57,25 +57,25 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet. } - @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 (this.onGround) { - this.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 (this.onGround) { - this.onGround = false; - } - } + @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 (this.onGround) { + this.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 (this.onGround) { + this.onGround = false; + } + } @Override public void saveData(NBTTagCompound nbttagcompound) { @@ -178,10 +178,10 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta return this.customName; } - @Override - public Object getCustomNameObjectNMS() { - return super.getCustomName(); - } + @Override + public Object getCustomNameObjectNMS() { + return super.getCustomName(); + } @Override public void die() { @@ -205,7 +205,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta public void setLocationNMS(double x, double y, double z, boolean broadcastLocationPacket) { super.setPosition(x, y, z); if (broadcastLocationPacket) { - broadcastLocationPacketNMS(); + broadcastLocationPacketNMS(); } } 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 index 8e5d7bb4..8845438c 100644 --- 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 @@ -56,19 +56,19 @@ public class EntityNMSItem extends EntityItem implements NMSItem { @Override public void tick() { - // Disable normal ticking for this entity. + // 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; - } + 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 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 index 7c1463a0..a0dfb278 100644 --- 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 @@ -37,187 +37,187 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import java.util.logging.Level; public class EntityNMSSlime extends EntitySlime implements NMSSlime { - - private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "vehicle"); + + private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "vehicle"); - private HologramLine parentPiece; - private CraftEntity customBukkitEntity; - - public EntityNMSSlime(World world, HologramLine parentPiece) { - super(EntityTypes.SLIME, world); - super.persistent = true; - super.collides = false; - a(0.0F, 0.0F); - setSize(1, false); - setInvisible(true); - this.parentPiece = parentPiece; - 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) { - // 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 a_(NBTTagCompound nbttagcompound) { - // Do not save NBT. - return false; - } + private HologramLine parentPiece; + private CraftEntity customBukkitEntity; + + public EntityNMSSlime(World world, HologramLine parentPiece) { + super(EntityTypes.SLIME, world); + super.persistent = true; + super.collides = false; + a(0.0F, 0.0F); + setSize(1, false); + setInvisible(true); + this.parentPiece = parentPiece; + 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) { + // 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 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) { - Bukkit.getPluginManager().callEvent(new PlayerInteractEntityEvent(((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(), getBukkitEntity())); // 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 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) { + Bukkit.getPluginManager().callEvent(new PlayerInteractEntityEvent(((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(), getBukkitEntity())); // 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) { - // Locks the custom name. - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Locks the custom name. - } - - @Override - public void playSound(SoundEffect soundeffect, float f, float f1) { - // Remove sounds. - } - - @Override - public void die() { - // Prevent being killed. - } - - @Override - public CraftEntity getBukkitEntity() { - if (customBukkitEntity == null) { - customBukkitEntity = new CraftNMSSlime(super.world.getServer(), this); - } - return customBukkitEntity; - } + @Override + public void setCustomName(IChatBaseComponent ichatbasecomponent) { + // Locks the custom name. + } + + @Override + public void setCustomNameVisible(boolean visible) { + // Locks the custom name. + } + + @Override + public void playSound(SoundEffect soundeffect, float f, float f1) { + // Remove sounds. + } + + @Override + public void die() { + // Prevent being killed. + } + + @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 HologramLine getHologramLine() { - return parentPiece; - } + @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 HologramLine getHologramLine() { + return parentPiece; + } - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public void setPassengerOfNMS(NMSEntityBase vehicleBase) { - if (vehicleBase == null || !(vehicleBase instanceof Entity)) { - // It should never dismount - return; - } - - Entity entity = (Entity) vehicleBase; - - try { - if (super.getVehicle() != null) { - Entity oldVehicle = super.getVehicle(); - VEHICLE_FIELD.set(this, null); - oldVehicle.passengers.remove(this); - } + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } + + @Override + public void setPassengerOfNMS(NMSEntityBase vehicleBase) { + if (vehicleBase == null || !(vehicleBase instanceof Entity)) { + // It should never dismount + return; + } + + Entity entity = (Entity) vehicleBase; + + try { + if (super.getVehicle() != null) { + Entity oldVehicle = super.getVehicle(); + VEHICLE_FIELD.set(this, null); + oldVehicle.passengers.remove(this); + } - VEHICLE_FIELD.set(this, entity); - entity.passengers.clear(); - entity.passengers.add(this); + VEHICLE_FIELD.set(this, entity); + entity.passengers.clear(); + entity.passengers.add(this); - } catch (Throwable t) { - ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); - } - } + } catch (Throwable t) { + ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); + } + } } diff --git a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/NmsManagerImpl.java b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/NmsManagerImpl.java index affcb445..a8b340cc 100644 --- a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/NmsManagerImpl.java +++ b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/NmsManagerImpl.java @@ -45,153 +45,153 @@ import org.bukkit.inventory.ItemStack; import java.util.List; public class NmsManagerImpl implements NMSManager { - - private static final ReflectField>> REGISTRY_ID_FIELD = new ReflectField<>(RegistryMaterials.class, "b"); - private static final ReflectField ID_TO_CLASS_MAP_FIELD = new ReflectField<>(RegistryID.class, "d"); - private static final ReflectMethod REGISTER_ENTITY_METHOD = new ReflectMethod<>(WorldServer.class, "registerEntity", Entity.class); - - @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]; + + private static final ReflectField>> REGISTRY_ID_FIELD = new ReflectField<>(RegistryMaterials.class, "b"); + private static final ReflectField ID_TO_CLASS_MAP_FIELD = new ReflectField<>(RegistryID.class, "d"); + private static final ReflectMethod REGISTER_ENTITY_METHOD = new ReflectMethod<>(WorldServer.class, "registerEntity", Entity.class); + + @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); + // 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(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager); - customItem.setLocationNMS(x, y, z); - customItem.setItemStackNMS(stack); - if (!addEntityToWorld(nmsWorld, customItem)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return customItem; - } - - @Override - public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramLine parentPiece) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece); - touchSlime.setLocationNMS(x, y, z); - if (!addEntityToWorld(nmsWorld, touchSlime)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return touchSlime; - } - - @Override - public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) { - WorldServer nmsWorld = ((CraftWorld) world).getHandle(); - EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece); - invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket); - if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return invisibleArmorStand; - } - - private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { - Validator.isTrue(Bukkit.isPrimaryThread(), "Async entity add"); - + // Restore the ID -> EntityTypes mapping. + idToClassMap[id] = oldValue; + } + + @Override + public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager); + customItem.setLocationNMS(x, y, z); + customItem.setItemStackNMS(stack); + if (!addEntityToWorld(nmsWorld, customItem)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return customItem; + } + + @Override + public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramLine parentPiece) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece); + touchSlime.setLocationNMS(x, y, z); + if (!addEntityToWorld(nmsWorld, touchSlime)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return touchSlime; + } + + @Override + public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) { + WorldServer nmsWorld = ((CraftWorld) world).getHandle(); + EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece); + invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket); + if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return invisibleArmorStand; + } + + private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { + Validator.isTrue(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 + // This should never happen nmsEntity.dead = true; return false; } nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity); try { - REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity); - return true; - } catch (Exception e) { - e.printStackTrace(); - return false; - } + REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + @Override + public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { + return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase; } - - @Override - public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase; - } - @Override - public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - - if (nmsEntity instanceof NMSEntityBase) { - return ((NMSEntityBase) nmsEntity); - } else { - return null; - } - } - - @Override - public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - Entity nmsEntity = nmsWorld.getEntity(entityID); - - if (nmsEntity instanceof NMSEntityBase) { - return ((NMSEntityBase) nmsEntity); - } else { - return null; - } - } - - @Override - public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { - return CustomNameHelper.replaceCustomNameChatComponent(NMSChatComponentAdapter.INSTANCE, customNameObject, target, replacement); - } - - private static enum NMSChatComponentAdapter implements ChatComponentAdapter { + @Override + public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { + Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); + + if (nmsEntity instanceof NMSEntityBase) { + return ((NMSEntityBase) nmsEntity); + } else { + return null; + } + } + + @Override + public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + Entity nmsEntity = nmsWorld.getEntity(entityID); + + if (nmsEntity instanceof NMSEntityBase) { + return ((NMSEntityBase) nmsEntity); + } else { + return null; + } + } + + @Override + public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { + return CustomNameHelper.replaceCustomNameChatComponent(NMSChatComponentAdapter.INSTANCE, customNameObject, target, replacement); + } + + private static enum NMSChatComponentAdapter implements ChatComponentAdapter { - INSTANCE { - - public ChatComponentText cast(Object chatComponentObject) { - return (ChatComponentText) chatComponentObject; - } - - @Override - public String getText(IChatBaseComponent chatComponent) { - return chatComponent.getText(); - } - - @Override - public List getSiblings(IChatBaseComponent chatComponent) { - return chatComponent.getSiblings(); - } - - @Override - public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) { - newSibling.getChatModifier().setChatModifier(chatComponent.getChatModifier()); - chatComponent.getSiblings().add(newSibling); - } - - @Override - public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) { - ChatComponentText clonedChatComponent = new ChatComponentText(newText); - clonedChatComponent.setChatModifier(chatComponent.getChatModifier().a()); - return clonedChatComponent; - } - - } - - } - + INSTANCE { + + public ChatComponentText cast(Object chatComponentObject) { + return (ChatComponentText) chatComponentObject; + } + + @Override + public String getText(IChatBaseComponent chatComponent) { + return chatComponent.getText(); + } + + @Override + public List getSiblings(IChatBaseComponent chatComponent) { + return chatComponent.getSiblings(); + } + + @Override + public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) { + newSibling.getChatModifier().setChatModifier(chatComponent.getChatModifier()); + chatComponent.getSiblings().add(newSibling); + } + + @Override + public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) { + ChatComponentText clonedChatComponent = new ChatComponentText(newText); + clonedChatComponent.setChatModifier(chatComponent.getChatModifier().a()); + return clonedChatComponent; + } + + } + + } + } diff --git a/nms/v1_16_r2/pom.xml b/nms/v1_16_r2/pom.xml index 73a0b15e..00158eb5 100644 --- a/nms/v1_16_r2/pom.xml +++ b/nms/v1_16_r2/pom.xml @@ -1,41 +1,41 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - - me.filoghost.holographicdisplays - holographicdisplays-nms - 3.0.0-SNAPSHOT - + + me.filoghost.holographicdisplays + holographicdisplays-nms + 3.0.0-SNAPSHOT + - holographicdisplays-nms-v1_16_r2 - HolographicDisplays NMS v1_16_R2 + holographicdisplays-nms-v1_16_r2 + HolographicDisplays NMS v1_16_R2 - - - nms-repo - https://repo.codemc.io/repository/nms/ - - + + + nms-repo + https://repo.codemc.io/repository/nms/ + + - - - ${project.groupId} - holographicdisplays-nms-interfaces - - - - ${project.groupId} - holographicdisplays-utils - - - - org.spigotmc - spigot - 1.16.2-R0.1-SNAPSHOT - provided - - + + + ${project.groupId} + holographicdisplays-nms-interfaces + + + + ${project.groupId} + holographicdisplays-utils + + + + org.spigotmc + spigot + 1.16.2-R0.1-SNAPSHOT + provided + + - \ No newline at end of file + 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 index a8f36276..50ef79d8 100644 --- 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 @@ -29,68 +29,68 @@ 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. - } + 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 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 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) { } - - + // 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 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 index e8a9a729..8245da0b 100644 --- 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 @@ -25,41 +25,41 @@ import org.bukkit.util.Vector; public class CraftNMSItem extends CraftItem { - public CraftNMSItem(CraftServer server, EntityNMSItem entity) { - super(server, entity); - } + 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) { } + // 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 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) { } - + // 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 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 index baf4f1c7..854b4bcd 100644 --- 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 @@ -29,57 +29,57 @@ 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) { } + 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 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) { } + // 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 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 index c2c2e8bf..97cc4328 100644 --- 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 @@ -57,25 +57,25 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet. } - @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 (this.onGround) { - this.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 (this.onGround) { - this.onGround = false; - } - } + @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 (this.onGround) { + this.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 (this.onGround) { + this.onGround = false; + } + } @Override public void saveData(NBTTagCompound nbttagcompound) { @@ -178,10 +178,10 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta return this.customName; } - @Override - public Object getCustomNameObjectNMS() { - return super.getCustomName(); - } + @Override + public Object getCustomNameObjectNMS() { + return super.getCustomName(); + } @Override public void die() { @@ -205,7 +205,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta public void setLocationNMS(double x, double y, double z, boolean broadcastLocationPacket) { super.setPosition(x, y, z); if (broadcastLocationPacket) { - broadcastLocationPacketNMS(); + broadcastLocationPacketNMS(); } } 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 index 29621ab5..bbb7f808 100644 --- 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 @@ -56,19 +56,19 @@ public class EntityNMSItem extends EntityItem implements NMSItem { @Override public void tick() { - // Disable normal ticking for this entity. + // 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; - } + 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 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 index a5f9c159..fde54352 100644 --- 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 @@ -37,187 +37,187 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import java.util.logging.Level; public class EntityNMSSlime extends EntitySlime implements NMSSlime { - - private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "vehicle"); + + private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "vehicle"); - private HologramLine parentPiece; - private CraftEntity customBukkitEntity; - - public EntityNMSSlime(World world, HologramLine parentPiece) { - super(EntityTypes.SLIME, world); - super.persistent = true; - super.collides = false; - a(0.0F, 0.0F); - setSize(1, false); - setInvisible(true); - this.parentPiece = parentPiece; - 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) { - // 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 a_(NBTTagCompound nbttagcompound) { - // Do not save NBT. - return false; - } + private HologramLine parentPiece; + private CraftEntity customBukkitEntity; + + public EntityNMSSlime(World world, HologramLine parentPiece) { + super(EntityTypes.SLIME, world); + super.persistent = true; + super.collides = false; + a(0.0F, 0.0F); + setSize(1, false); + setInvisible(true); + this.parentPiece = parentPiece; + 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) { + // 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 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) { - Bukkit.getPluginManager().callEvent(new PlayerInteractEntityEvent(((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(), getBukkitEntity())); // 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 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) { + Bukkit.getPluginManager().callEvent(new PlayerInteractEntityEvent(((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(), getBukkitEntity())); // 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) { - // Locks the custom name. - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Locks the custom name. - } - - @Override - public void playSound(SoundEffect soundeffect, float f, float f1) { - // Remove sounds. - } - - @Override - public void die() { - // Prevent being killed. - } - - @Override - public CraftEntity getBukkitEntity() { - if (customBukkitEntity == null) { - customBukkitEntity = new CraftNMSSlime(super.world.getServer(), this); - } - return customBukkitEntity; - } + @Override + public void setCustomName(IChatBaseComponent ichatbasecomponent) { + // Locks the custom name. + } + + @Override + public void setCustomNameVisible(boolean visible) { + // Locks the custom name. + } + + @Override + public void playSound(SoundEffect soundeffect, float f, float f1) { + // Remove sounds. + } + + @Override + public void die() { + // Prevent being killed. + } + + @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 HologramLine getHologramLine() { - return parentPiece; - } + @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 HologramLine getHologramLine() { + return parentPiece; + } - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public void setPassengerOfNMS(NMSEntityBase vehicleBase) { - if (vehicleBase == null || !(vehicleBase instanceof Entity)) { - // It should never dismount - return; - } - - Entity entity = (Entity) vehicleBase; - - try { - if (super.getVehicle() != null) { - Entity oldVehicle = super.getVehicle(); - VEHICLE_FIELD.set(this, null); - oldVehicle.passengers.remove(this); - } + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } + + @Override + public void setPassengerOfNMS(NMSEntityBase vehicleBase) { + if (vehicleBase == null || !(vehicleBase instanceof Entity)) { + // It should never dismount + return; + } + + Entity entity = (Entity) vehicleBase; + + try { + if (super.getVehicle() != null) { + Entity oldVehicle = super.getVehicle(); + VEHICLE_FIELD.set(this, null); + oldVehicle.passengers.remove(this); + } - VEHICLE_FIELD.set(this, entity); - entity.passengers.clear(); - entity.passengers.add(this); + VEHICLE_FIELD.set(this, entity); + entity.passengers.clear(); + entity.passengers.add(this); - } catch (Throwable t) { - ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); - } - } + } catch (Throwable t) { + ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); + } + } } diff --git a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/NmsManagerImpl.java b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/NmsManagerImpl.java index f7ad56a3..721c1b0f 100644 --- a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/NmsManagerImpl.java +++ b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/NmsManagerImpl.java @@ -45,144 +45,144 @@ import java.util.List; import java.util.Map; public class NmsManagerImpl implements NMSManager { - - private static final ReflectField, Integer>> REGISTRY_TO_ID_FIELD = new ReflectField<>(RegistryMaterials.class, "bg"); - private static final ReflectMethod REGISTER_ENTITY_METHOD = new ReflectMethod<>(WorldServer.class, "registerEntity", Entity.class); - - @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(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager); - customItem.setLocationNMS(x, y, z); - customItem.setItemStackNMS(stack); - if (!addEntityToWorld(nmsWorld, customItem)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return customItem; - } - - @Override - public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramLine parentPiece) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece); - touchSlime.setLocationNMS(x, y, z); - if (!addEntityToWorld(nmsWorld, touchSlime)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return touchSlime; - } - - @Override - public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) { - WorldServer nmsWorld = ((CraftWorld) world).getHandle(); - EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece); - invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket); - if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return invisibleArmorStand; - } - - private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { - Validator.isTrue(Bukkit.isPrimaryThread(), "Async entity add"); - + + private static final ReflectField, Integer>> REGISTRY_TO_ID_FIELD = new ReflectField<>(RegistryMaterials.class, "bg"); + private static final ReflectMethod REGISTER_ENTITY_METHOD = new ReflectMethod<>(WorldServer.class, "registerEntity", Entity.class); + + @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(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager); + customItem.setLocationNMS(x, y, z); + customItem.setItemStackNMS(stack); + if (!addEntityToWorld(nmsWorld, customItem)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return customItem; + } + + @Override + public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramLine parentPiece) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece); + touchSlime.setLocationNMS(x, y, z); + if (!addEntityToWorld(nmsWorld, touchSlime)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return touchSlime; + } + + @Override + public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) { + WorldServer nmsWorld = ((CraftWorld) world).getHandle(); + EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece); + invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket); + if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return invisibleArmorStand; + } + + private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { + Validator.isTrue(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 + // This should never happen nmsEntity.dead = true; return false; } nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity); try { - REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity); - return true; - } catch (Exception e) { - e.printStackTrace(); - return false; - } + REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + @Override + public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { + return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase; } - - @Override - public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase; - } - @Override - public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - - if (nmsEntity instanceof NMSEntityBase) { - return ((NMSEntityBase) nmsEntity); - } else { - return null; - } - } - - @Override - public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - Entity nmsEntity = nmsWorld.getEntity(entityID); - - if (nmsEntity instanceof NMSEntityBase) { - return ((NMSEntityBase) nmsEntity); - } else { - return null; - } - } - - @Override - public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { - return CustomNameHelper.replaceCustomNameChatComponent(NMSChatComponentAdapter.INSTANCE, customNameObject, target, replacement); - } - - private static enum NMSChatComponentAdapter implements ChatComponentAdapter { + @Override + public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { + Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); + + if (nmsEntity instanceof NMSEntityBase) { + return ((NMSEntityBase) nmsEntity); + } else { + return null; + } + } + + @Override + public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + Entity nmsEntity = nmsWorld.getEntity(entityID); + + if (nmsEntity instanceof NMSEntityBase) { + return ((NMSEntityBase) nmsEntity); + } else { + return null; + } + } + + @Override + public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { + return CustomNameHelper.replaceCustomNameChatComponent(NMSChatComponentAdapter.INSTANCE, customNameObject, target, replacement); + } + + private static enum NMSChatComponentAdapter implements ChatComponentAdapter { - INSTANCE { - - public ChatComponentText cast(Object chatComponentObject) { - return (ChatComponentText) chatComponentObject; - } - - @Override - public String getText(IChatBaseComponent chatComponent) { - return chatComponent.getText(); - } - - @Override - public List getSiblings(IChatBaseComponent chatComponent) { - return chatComponent.getSiblings(); - } - - @Override - public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) { - newSibling.getChatModifier().setChatModifier(chatComponent.getChatModifier()); - chatComponent.getSiblings().add(newSibling); - } - - @Override - public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) { - ChatComponentText clonedChatComponent = new ChatComponentText(newText); - clonedChatComponent.setChatModifier(chatComponent.getChatModifier().a()); - return clonedChatComponent; - } - - } - - } - + INSTANCE { + + public ChatComponentText cast(Object chatComponentObject) { + return (ChatComponentText) chatComponentObject; + } + + @Override + public String getText(IChatBaseComponent chatComponent) { + return chatComponent.getText(); + } + + @Override + public List getSiblings(IChatBaseComponent chatComponent) { + return chatComponent.getSiblings(); + } + + @Override + public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) { + newSibling.getChatModifier().setChatModifier(chatComponent.getChatModifier()); + chatComponent.getSiblings().add(newSibling); + } + + @Override + public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) { + ChatComponentText clonedChatComponent = new ChatComponentText(newText); + clonedChatComponent.setChatModifier(chatComponent.getChatModifier().a()); + return clonedChatComponent; + } + + } + + } + } diff --git a/nms/v1_16_r3/pom.xml b/nms/v1_16_r3/pom.xml index 59083b6c..60436f0a 100644 --- a/nms/v1_16_r3/pom.xml +++ b/nms/v1_16_r3/pom.xml @@ -1,41 +1,41 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - - me.filoghost.holographicdisplays - holographicdisplays-nms - 3.0.0-SNAPSHOT - + + me.filoghost.holographicdisplays + holographicdisplays-nms + 3.0.0-SNAPSHOT + - holographicdisplays-nms-v1_16_r3 - HolographicDisplays NMS v1_16_R3 + holographicdisplays-nms-v1_16_r3 + HolographicDisplays NMS v1_16_R3 - - - nms-repo - https://repo.codemc.io/repository/nms/ - - + + + nms-repo + https://repo.codemc.io/repository/nms/ + + - - - ${project.groupId} - holographicdisplays-nms-interfaces - - - - ${project.groupId} - holographicdisplays-utils - - - - org.spigotmc - spigot - 1.16.4-R0.1-SNAPSHOT - provided - - + + + ${project.groupId} + holographicdisplays-nms-interfaces + + + + ${project.groupId} + holographicdisplays-utils + + + + org.spigotmc + spigot + 1.16.4-R0.1-SNAPSHOT + provided + + 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 index d81307a6..268c239f 100644 --- 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 @@ -29,68 +29,68 @@ 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. - } + 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 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 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) { } - - + // 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 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 index 1fbccf42..0ef45715 100644 --- 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 @@ -25,41 +25,41 @@ import org.bukkit.util.Vector; public class CraftNMSItem extends CraftItem { - public CraftNMSItem(CraftServer server, EntityNMSItem entity) { - super(server, entity); - } + 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) { } + // 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 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) { } - + // 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 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 index 14b68ba7..c28998f4 100644 --- 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 @@ -29,57 +29,57 @@ 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) { } + 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 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) { } + // 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 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 index cd7e4293..ebee84ff 100644 --- 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 @@ -57,25 +57,25 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet. } - @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 (this.onGround) { - this.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 (this.onGround) { - this.onGround = false; - } - } + @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 (this.onGround) { + this.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 (this.onGround) { + this.onGround = false; + } + } @Override public void saveData(NBTTagCompound nbttagcompound) { @@ -178,10 +178,10 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta return this.customName; } - @Override - public Object getCustomNameObjectNMS() { - return super.getCustomName(); - } + @Override + public Object getCustomNameObjectNMS() { + return super.getCustomName(); + } @Override public void die() { @@ -205,7 +205,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta public void setLocationNMS(double x, double y, double z, boolean broadcastLocationPacket) { super.setPosition(x, y, z); if (broadcastLocationPacket) { - broadcastLocationPacketNMS(); + broadcastLocationPacketNMS(); } } 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 index ac0e4579..935c16da 100644 --- 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 @@ -56,19 +56,19 @@ public class EntityNMSItem extends EntityItem implements NMSItem { @Override public void tick() { - // Disable normal ticking for this entity. + // 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; - } + 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 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 index 04eacf6b..05cd1eea 100644 --- 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 @@ -37,187 +37,187 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import java.util.logging.Level; public class EntityNMSSlime extends EntitySlime implements NMSSlime { - - private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "vehicle"); + + private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "vehicle"); - private HologramLine parentPiece; - private CraftEntity customBukkitEntity; - - public EntityNMSSlime(World world, HologramLine parentPiece) { - super(EntityTypes.SLIME, world); - super.persistent = true; - super.collides = false; - a(0.0F, 0.0F); - setSize(1, false); - setInvisible(true); - this.parentPiece = parentPiece; - 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) { - // 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 a_(NBTTagCompound nbttagcompound) { - // Do not save NBT. - return false; - } + private HologramLine parentPiece; + private CraftEntity customBukkitEntity; + + public EntityNMSSlime(World world, HologramLine parentPiece) { + super(EntityTypes.SLIME, world); + super.persistent = true; + super.collides = false; + a(0.0F, 0.0F); + setSize(1, false); + setInvisible(true); + this.parentPiece = parentPiece; + 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) { + // 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 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) { - Bukkit.getPluginManager().callEvent(new PlayerInteractEntityEvent(((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(), getBukkitEntity())); // 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 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) { + Bukkit.getPluginManager().callEvent(new PlayerInteractEntityEvent(((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(), getBukkitEntity())); // 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) { - // Locks the custom name. - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Locks the custom name. - } - - @Override - public void playSound(SoundEffect soundeffect, float f, float f1) { - // Remove sounds. - } - - @Override - public void die() { - // Prevent being killed. - } - - @Override - public CraftEntity getBukkitEntity() { - if (customBukkitEntity == null) { - customBukkitEntity = new CraftNMSSlime(super.world.getServer(), this); - } - return customBukkitEntity; - } + @Override + public void setCustomName(IChatBaseComponent ichatbasecomponent) { + // Locks the custom name. + } + + @Override + public void setCustomNameVisible(boolean visible) { + // Locks the custom name. + } + + @Override + public void playSound(SoundEffect soundeffect, float f, float f1) { + // Remove sounds. + } + + @Override + public void die() { + // Prevent being killed. + } + + @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 HologramLine getHologramLine() { - return parentPiece; - } + @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 HologramLine getHologramLine() { + return parentPiece; + } - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public void setPassengerOfNMS(NMSEntityBase vehicleBase) { - if (vehicleBase == null || !(vehicleBase instanceof Entity)) { - // It should never dismount - return; - } - - Entity entity = (Entity) vehicleBase; - - try { - if (super.getVehicle() != null) { - Entity oldVehicle = super.getVehicle(); - VEHICLE_FIELD.set(this, null); - oldVehicle.passengers.remove(this); - } + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } + + @Override + public void setPassengerOfNMS(NMSEntityBase vehicleBase) { + if (vehicleBase == null || !(vehicleBase instanceof Entity)) { + // It should never dismount + return; + } + + Entity entity = (Entity) vehicleBase; + + try { + if (super.getVehicle() != null) { + Entity oldVehicle = super.getVehicle(); + VEHICLE_FIELD.set(this, null); + oldVehicle.passengers.remove(this); + } - VEHICLE_FIELD.set(this, entity); - entity.passengers.clear(); - entity.passengers.add(this); + VEHICLE_FIELD.set(this, entity); + entity.passengers.clear(); + entity.passengers.add(this); - } catch (Throwable t) { - ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); - } - } + } catch (Throwable t) { + ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); + } + } } diff --git a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/NmsManagerImpl.java b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/NmsManagerImpl.java index 0a70251c..030c3171 100644 --- a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/NmsManagerImpl.java +++ b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/NmsManagerImpl.java @@ -45,144 +45,144 @@ import java.util.List; import java.util.Map; public class NmsManagerImpl implements NMSManager { - - private static final ReflectField, Integer>> REGISTRY_TO_ID_FIELD = new ReflectField<>(RegistryMaterials.class, "bg"); - private static final ReflectMethod REGISTER_ENTITY_METHOD = new ReflectMethod<>(WorldServer.class, "registerEntity", Entity.class); - - @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(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager); - customItem.setLocationNMS(x, y, z); - customItem.setItemStackNMS(stack); - if (!addEntityToWorld(nmsWorld, customItem)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return customItem; - } - - @Override - public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramLine parentPiece) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece); - touchSlime.setLocationNMS(x, y, z); - if (!addEntityToWorld(nmsWorld, touchSlime)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return touchSlime; - } - - @Override - public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) { - WorldServer nmsWorld = ((CraftWorld) world).getHandle(); - EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece); - invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket); - if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return invisibleArmorStand; - } - - private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { - Validator.isTrue(Bukkit.isPrimaryThread(), "Async entity add"); - + + private static final ReflectField, Integer>> REGISTRY_TO_ID_FIELD = new ReflectField<>(RegistryMaterials.class, "bg"); + private static final ReflectMethod REGISTER_ENTITY_METHOD = new ReflectMethod<>(WorldServer.class, "registerEntity", Entity.class); + + @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(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager); + customItem.setLocationNMS(x, y, z); + customItem.setItemStackNMS(stack); + if (!addEntityToWorld(nmsWorld, customItem)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return customItem; + } + + @Override + public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramLine parentPiece) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece); + touchSlime.setLocationNMS(x, y, z); + if (!addEntityToWorld(nmsWorld, touchSlime)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return touchSlime; + } + + @Override + public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) { + WorldServer nmsWorld = ((CraftWorld) world).getHandle(); + EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece); + invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket); + if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return invisibleArmorStand; + } + + private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { + Validator.isTrue(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 + // This should never happen nmsEntity.dead = true; return false; } nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity); try { - REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity); - return true; - } catch (Exception e) { - e.printStackTrace(); - return false; - } + REGISTER_ENTITY_METHOD.invoke(nmsWorld, nmsEntity); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + @Override + public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { + return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase; } - - @Override - public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase; - } - @Override - public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - - if (nmsEntity instanceof NMSEntityBase) { - return ((NMSEntityBase) nmsEntity); - } else { - return null; - } - } - - @Override - public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - Entity nmsEntity = nmsWorld.getEntity(entityID); - - if (nmsEntity instanceof NMSEntityBase) { - return ((NMSEntityBase) nmsEntity); - } else { - return null; - } - } - - @Override - public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { - return CustomNameHelper.replaceCustomNameChatComponent(NMSChatComponentAdapter.INSTANCE, customNameObject, target, replacement); - } - - private static enum NMSChatComponentAdapter implements ChatComponentAdapter { + @Override + public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { + Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); + + if (nmsEntity instanceof NMSEntityBase) { + return ((NMSEntityBase) nmsEntity); + } else { + return null; + } + } + + @Override + public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + Entity nmsEntity = nmsWorld.getEntity(entityID); + + if (nmsEntity instanceof NMSEntityBase) { + return ((NMSEntityBase) nmsEntity); + } else { + return null; + } + } + + @Override + public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { + return CustomNameHelper.replaceCustomNameChatComponent(NMSChatComponentAdapter.INSTANCE, customNameObject, target, replacement); + } + + private static enum NMSChatComponentAdapter implements ChatComponentAdapter { - INSTANCE { - - public ChatComponentText cast(Object chatComponentObject) { - return (ChatComponentText) chatComponentObject; - } - - @Override - public String getText(IChatBaseComponent chatComponent) { - return chatComponent.getText(); - } - - @Override - public List getSiblings(IChatBaseComponent chatComponent) { - return chatComponent.getSiblings(); - } - - @Override - public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) { - newSibling.getChatModifier().setChatModifier(chatComponent.getChatModifier()); - chatComponent.getSiblings().add(newSibling); - } - - @Override - public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) { - ChatComponentText clonedChatComponent = new ChatComponentText(newText); - clonedChatComponent.setChatModifier(chatComponent.getChatModifier().a()); - return clonedChatComponent; - } - - } - - } - + INSTANCE { + + public ChatComponentText cast(Object chatComponentObject) { + return (ChatComponentText) chatComponentObject; + } + + @Override + public String getText(IChatBaseComponent chatComponent) { + return chatComponent.getText(); + } + + @Override + public List getSiblings(IChatBaseComponent chatComponent) { + return chatComponent.getSiblings(); + } + + @Override + public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) { + newSibling.getChatModifier().setChatModifier(chatComponent.getChatModifier()); + chatComponent.getSiblings().add(newSibling); + } + + @Override + public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) { + ChatComponentText clonedChatComponent = new ChatComponentText(newText); + clonedChatComponent.setChatModifier(chatComponent.getChatModifier().a()); + return clonedChatComponent; + } + + } + + } + } diff --git a/nms/v1_8_r2/pom.xml b/nms/v1_8_r2/pom.xml index 4054d320..dcac9e5d 100644 --- a/nms/v1_8_r2/pom.xml +++ b/nms/v1_8_r2/pom.xml @@ -1,41 +1,41 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - - me.filoghost.holographicdisplays - holographicdisplays-nms - 3.0.0-SNAPSHOT - + + me.filoghost.holographicdisplays + holographicdisplays-nms + 3.0.0-SNAPSHOT + - holographicdisplays-nms-v1_8_r2 - HolographicDisplays NMS v1_8_R2 + holographicdisplays-nms-v1_8_r2 + HolographicDisplays NMS v1_8_R2 - - - nms-repo - https://repo.codemc.io/repository/nms/ - - + + + nms-repo + https://repo.codemc.io/repository/nms/ + + - - - ${project.groupId} - holographicdisplays-nms-interfaces - - - - ${project.groupId} - holographicdisplays-utils - + + + ${project.groupId} + holographicdisplays-nms-interfaces + + + + ${project.groupId} + holographicdisplays-utils + - - org.spigotmc - spigot - 1.8.3-R0.1-SNAPSHOT - provided - - + + org.spigotmc + spigot + 1.8.3-R0.1-SNAPSHOT + provided + + - \ No newline at end of file + 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 index ff4163c9..ac009da4 100644 --- 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 @@ -29,53 +29,53 @@ 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. - } + 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 Armor stand class - @Override public void setArms(boolean arms) { } - @Override public void setBasePlate(boolean basePlate) { } - @Override public void setBodyPose(EulerAngle pose) { } - @Override public void setBoots(ItemStack item) { } - @Override public void setChestplate(ItemStack item) { } - @Override public void setGravity(boolean gravity) { } - @Override public void setHeadPose(EulerAngle pose) { } - @Override public void setHelmet(ItemStack item) { } - @Override public void setItemInHand(ItemStack item) { } - @Override public void setLeftArmPose(EulerAngle pose) { } - @Override public void setLeftLegPose(EulerAngle pose) { } - @Override public void setLeggings(ItemStack item) { } - @Override public void setRightArmPose(EulerAngle pose) { } - @Override public void setRightLegPose(EulerAngle pose) { } - @Override public void setSmall(boolean small) { } - @Override public void setVisible(boolean visible) { } + // Methods from Armor stand class + @Override public void setArms(boolean arms) { } + @Override public void setBasePlate(boolean basePlate) { } + @Override public void setBodyPose(EulerAngle pose) { } + @Override public void setBoots(ItemStack item) { } + @Override public void setChestplate(ItemStack item) { } + @Override public void setGravity(boolean gravity) { } + @Override public void setHeadPose(EulerAngle pose) { } + @Override public void setHelmet(ItemStack item) { } + @Override public void setItemInHand(ItemStack item) { } + @Override public void setLeftArmPose(EulerAngle pose) { } + @Override public void setLeftLegPose(EulerAngle pose) { } + @Override public void setLeggings(ItemStack item) { } + @Override public void setRightArmPose(EulerAngle pose) { } + @Override public void setRightLegPose(EulerAngle pose) { } + @Override public void setSmall(boolean small) { } + @Override public void setVisible(boolean visible) { } - // 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) { } - + // 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) { } + } 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 index ce18479b..f8c2a956 100644 --- 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 @@ -25,32 +25,32 @@ import org.bukkit.util.Vector; public class CraftNMSItem extends CraftItem { - public CraftNMSItem(CraftServer server, EntityNMSItem entity) { - super(server, entity); - } + 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. - } + // 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) { } - - // Methods from Item - @Override public void setItemStack(ItemStack stack) { } - @Override public void setPickupDelay(int delay) { } + // 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) { } + + // 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 index f8f556cf..7179d212 100644 --- 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 @@ -27,37 +27,37 @@ 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) { } - - // Methods from Slime - @Override public void setSize(int size) { } + 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) { } + + // 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 index 636cdf10..8660cc0c 100644 --- 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 @@ -35,206 +35,206 @@ import org.bukkit.craftbukkit.v1_8_R2.entity.CraftEntity; import java.util.logging.Level; public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand { - - private static final ReflectField DISABLED_SLOTS_FIELD = new ReflectField<>(EntityArmorStand.class, "bi"); - private static final ReflectMethod SET_MARKER_METHOD = new ReflectMethod<>(EntityArmorStand.class, "n", boolean.class); + + private static final ReflectField DISABLED_SLOTS_FIELD = new ReflectField<>(EntityArmorStand.class, "bi"); + private static final ReflectMethod SET_MARKER_METHOD = new ReflectMethod<>(EntityArmorStand.class, "n", boolean.class); - private HologramLine parentPiece; - private String customName; - - public EntityNMSArmorStand(World world, HologramLine parentPiece) { - super(world); - setInvisible(true); - setSmall(true); - setArms(false); - setGravity(true); - setBasePlate(true); - try { - SET_MARKER_METHOD.invoke(this, true); - } catch (Throwable t) { - ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set armor stand as marker", t); - // It will still work, but the offset will be wrong. - } - this.parentPiece = parentPiece; - try { - DISABLED_SLOTS_FIELD.set(this, Integer.MAX_VALUE); - } catch (Exception e) { - // There's still the overridden method. - } - forceSetBoundingBox(new NullBoundingBox()); - - this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet. - } - - @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 (this.onGround) { - this.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 (this.onGround) { - this.onGround = false; - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT. - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT. - return false; - } + private HologramLine parentPiece; + private String customName; + + public EntityNMSArmorStand(World world, HologramLine parentPiece) { + super(world); + setInvisible(true); + setSmall(true); + setArms(false); + setGravity(true); + setBasePlate(true); + try { + SET_MARKER_METHOD.invoke(this, true); + } catch (Throwable t) { + ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set armor stand as marker", t); + // It will still work, but the offset will be wrong. + } + this.parentPiece = parentPiece; + try { + DISABLED_SLOTS_FIELD.set(this, Integer.MAX_VALUE); + } catch (Exception e) { + // There's still the overridden method. + } + forceSetBoundingBox(new NullBoundingBox()); + + this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet. + } + + @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 (this.onGround) { + this.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 (this.onGround) { + this.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) { - // Locks the custom name. - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Locks the custom name. - } + @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) { + // Locks the custom name. + } + + @Override + public void setCustomNameVisible(boolean visible) { + // Locks the custom name. + } - @Override - public boolean a(EntityHuman human, Vec3D vec3d) { - // Prevent stand being equipped - return true; - } + @Override + public boolean a(EntityHuman human, Vec3D vec3d) { + // Prevent stand being equipped + return true; + } - @Override - public boolean d(int i, ItemStack item) { - // Prevent stand being equipped - return false; - } + @Override + public boolean d(int i, ItemStack item) { + // Prevent stand being equipped + return false; + } - @Override - public void setEquipment(int i, ItemStack item) { - // Prevent stand being equipped - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Do not change it! - } - - 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 name) { - this.customName = Utils.limitLength(name, 300); - super.setCustomName(customName); - super.setCustomNameVisible(customName != null && !customName.isEmpty()); - } - - @Override - public String getCustomNameStringNMS() { - return this.customName; - } - - @Override - public Object getCustomNameObjectNMS() { - return super.getCustomName(); - } - - @Override - public void die() { - // Prevent being killed. - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - this.bukkitEntity = new CraftNMSArmorStand(this.world.getServer(), this); - } - return this.bukkitEntity; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z, boolean broadcastLocationPacket) { - super.setPosition(x, y, z); - if (broadcastLocationPacket) { - broadcastLocationPacketNMS(); - } - } - - private void broadcastLocationPacketNMS() { - PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); - - for (Object obj : this.world.players) { - if (obj instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) obj; + @Override + public void setEquipment(int i, ItemStack item) { + // Prevent stand being equipped + } + + @Override + public void a(AxisAlignedBB boundingBox) { + // Do not change it! + } + + 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 name) { + this.customName = Utils.limitLength(name, 300); + super.setCustomName(customName); + super.setCustomNameVisible(customName != null && !customName.isEmpty()); + } + + @Override + public String getCustomNameStringNMS() { + return this.customName; + } + + @Override + public Object getCustomNameObjectNMS() { + return super.getCustomName(); + } + + @Override + public void die() { + // Prevent being killed. + } + + @Override + public CraftEntity getBukkitEntity() { + if (super.bukkitEntity == null) { + this.bukkitEntity = new CraftNMSArmorStand(this.world.getServer(), this); + } + return this.bukkitEntity; + } + + @Override + public void killEntityNMS() { + super.dead = true; + } + + @Override + public void setLocationNMS(double x, double y, double z, boolean broadcastLocationPacket) { + super.setPosition(x, y, z); + if (broadcastLocationPacket) { + broadcastLocationPacketNMS(); + } + } + + private void broadcastLocationPacketNMS() { + PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); + + for (Object obj : this.world.players) { + if (obj instanceof EntityPlayer) { + EntityPlayer nmsPlayer = (EntityPlayer) obj; - double distanceSquared = Utils.square(nmsPlayer.locX - this.locX) + Utils.square(nmsPlayer.locZ - this.locZ); - if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(teleportPacket); - } - } - } - } + double distanceSquared = Utils.square(nmsPlayer.locX - this.locX) + Utils.square(nmsPlayer.locZ - this.locZ); + if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) { + nmsPlayer.playerConnection.sendPacket(teleportPacket); + } + } + } + } - @Override - public boolean isDeadNMS() { - return this.dead; - } - - @Override - public int getIdNMS() { - return super.getId(); - } + @Override + public boolean isDeadNMS() { + return this.dead; + } + + @Override + public int getIdNMS() { + return super.getId(); + } - @Override - public HologramLine getHologramLine() { - return parentPiece; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } + @Override + public HologramLine getHologramLine() { + return parentPiece; + } + + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } } 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 index d26cad4d..d845fe6a 100644 --- 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 @@ -39,192 +39,192 @@ import org.bukkit.entity.Player; import java.util.logging.Level; public class EntityNMSItem extends EntityItem implements NMSItem { - - private static final ReflectField RIDER_PITCH_DELTA = new ReflectField<>(Entity.class, "ar"); - private static final ReflectField RIDER_YAW_DELTA = new ReflectField<>(Entity.class, "as"); - - private ItemLine parentPiece; - private ItemPickupManager itemPickupManager; - - public EntityNMSItem(World world, ItemLine piece, ItemPickupManager itemPickupManager) { - super(world); - super.pickupDelay = Integer.MAX_VALUE; - this.parentPiece = piece; - this.itemPickupManager = itemPickupManager; - } - - @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 (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) { - itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent()); - // 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; - } + + private static final ReflectField RIDER_PITCH_DELTA = new ReflectField<>(Entity.class, "ar"); + private static final ReflectField RIDER_YAW_DELTA = new ReflectField<>(Entity.class, "as"); + + private ItemLine parentPiece; + private ItemPickupManager itemPickupManager; + + public EntityNMSItem(World world, ItemLine piece, ItemPickupManager itemPickupManager) { + super(world); + super.pickupDelay = Integer.MAX_VALUE; + this.parentPiece = piece; + this.itemPickupManager = itemPickupManager; + } + + @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 (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) { + itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent()); + // 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 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 being killed. - } - - @Override - public boolean isAlive() { - // This override prevents items from being picked up by hoppers. - // Should have no side effects. - return false; - } + @Override + public void die() { + // Prevent being killed. + } + + @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) { - this.bukkitEntity = new CraftNMSItem(this.world.getServer(), this); - } - return this.bukkitEntity; - } + @Override + public CraftEntity getBukkitEntity() { + if (super.bukkitEntity == null) { + this.bukkitEntity = new CraftNMSItem(this.world.getServer(), this); + } + return this.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 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(ItemUtils.ANTISTACK_LORE)); // Antistack lore - display.set("Lore", tagList); - - setItemStack(newItem); - } - - @Override - public int getIdNMS() { - return this.getId(); - } - - @Override - public ItemLine getHologramLine() { - return parentPiece; - } - - @Override - public void allowPickup(boolean pickup) { - if (pickup) { - super.pickupDelay = 0; - } else { - super.pickupDelay = Integer.MAX_VALUE; - } - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public void setPassengerOfNMS(NMSEntityBase vehicleBase) { - if (vehicleBase == null || !(vehicleBase instanceof Entity)) { - // It should never dismount - return; - } - - Entity entity = (Entity) vehicleBase; - - try { - RIDER_PITCH_DELTA.set(this, 0.0); - RIDER_YAW_DELTA.set(this, 0.0); - } catch (Throwable t) { - ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set rider pitch and yaw", t); - } + @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(ItemUtils.ANTISTACK_LORE)); // Antistack lore + display.set("Lore", tagList); + + setItemStack(newItem); + } + + @Override + public int getIdNMS() { + return this.getId(); + } + + @Override + public ItemLine getHologramLine() { + return parentPiece; + } + + @Override + public void allowPickup(boolean pickup) { + if (pickup) { + super.pickupDelay = 0; + } else { + super.pickupDelay = Integer.MAX_VALUE; + } + } + + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } + + @Override + public void setPassengerOfNMS(NMSEntityBase vehicleBase) { + if (vehicleBase == null || !(vehicleBase instanceof Entity)) { + // It should never dismount + return; + } + + Entity entity = (Entity) vehicleBase; + + try { + RIDER_PITCH_DELTA.set(this, 0.0); + RIDER_YAW_DELTA.set(this, 0.0); + } catch (Throwable t) { + ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set rider pitch and yaw", t); + } if (this.vehicle != null) { - this.vehicle.passenger = null; + this.vehicle.passenger = null; } this.vehicle = entity; entity.passenger = this; - } - - @Override - public Object getRawItemStack() { - return super.getItemStack(); - } + } + + @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 index 1996420f..54b4073f 100644 --- 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 @@ -34,174 +34,174 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import java.util.logging.Level; public class EntityNMSSlime extends EntitySlime implements NMSSlime { - - private static final ReflectField RIDER_PITCH_DELTA = new ReflectField<>(Entity.class, "ar"); - private static final ReflectField RIDER_YAW_DELTA = new ReflectField<>(Entity.class, "as"); + + private static final ReflectField RIDER_PITCH_DELTA = new ReflectField<>(Entity.class, "ar"); + private static final ReflectField RIDER_YAW_DELTA = new ReflectField<>(Entity.class, "as"); - private HologramLine parentPiece; - - public EntityNMSSlime(World world, HologramLine parentPiece) { - super(world); - super.persistent = true; - a(0.0F, 0.0F); - setSize(1); - setInvisible(true); - this.parentPiece = parentPiece; - forceSetBoundingBox(new NullBoundingBox()); - } - - @Override - public void t_() { - // Disable normal ticking for this entity. - - // So it won't get removed. - ticksLived = 0; + private HologramLine parentPiece; + + public EntityNMSSlime(World world, HologramLine parentPiece) { + super(world); + super.persistent = true; + a(0.0F, 0.0F); + setSize(1); + setInvisible(true); + this.parentPiece = parentPiece; + 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 (this.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) { - // Do not change it! - } - - 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; - } + // The slime dies without a vehicle. + if (this.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) { + // Do not change it! + } + + 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) { - Bukkit.getPluginManager().callEvent(new PlayerInteractEntityEvent(((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(), getBukkitEntity())); - } - } - 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 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) { + Bukkit.getPluginManager().callEvent(new PlayerInteractEntityEvent(((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(), getBukkitEntity())); + } + } + 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) { - // Locks the custom name. - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Locks the custom name. - } - - @Override - public void makeSound(String sound, float volume, float pitch) { - // Remove sounds. - } - - @Override - public void die() { - // Prevent being killed. - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - this.bukkitEntity = new CraftNMSSlime(this.world.getServer(), this); - } - return this.bukkitEntity; - } + @Override + public void setCustomName(String customName) { + // Locks the custom name. + } + + @Override + public void setCustomNameVisible(boolean visible) { + // Locks the custom name. + } + + @Override + public void makeSound(String sound, float volume, float pitch) { + // Remove sounds. + } + + @Override + public void die() { + // Prevent being killed. + } + + @Override + public CraftEntity getBukkitEntity() { + if (super.bukkitEntity == null) { + this.bukkitEntity = new CraftNMSSlime(this.world.getServer(), this); + } + return this.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 this.getId(); - } - - @Override - public HologramLine getHologramLine() { - return parentPiece; - } + @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 this.getId(); + } + + @Override + public HologramLine getHologramLine() { + return parentPiece; + } - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public void setPassengerOfNMS(NMSEntityBase vehicleBase) { - if (vehicleBase == null || !(vehicleBase instanceof Entity)) { - // It should never dismount - return; - } - - Entity entity = (Entity) vehicleBase; - - try { - RIDER_PITCH_DELTA.set(this, 0.0); - RIDER_YAW_DELTA.set(this, 0.0); - } catch (Throwable t) { - ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set rider pitch and yaw", t); - } + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } + + @Override + public void setPassengerOfNMS(NMSEntityBase vehicleBase) { + if (vehicleBase == null || !(vehicleBase instanceof Entity)) { + // It should never dismount + return; + } + + Entity entity = (Entity) vehicleBase; + + try { + RIDER_PITCH_DELTA.set(this, 0.0); + RIDER_YAW_DELTA.set(this, 0.0); + } catch (Throwable t) { + ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set rider pitch and yaw", t); + } if (this.vehicle != null) { - this.vehicle.passenger = null; + this.vehicle.passenger = null; } this.vehicle = entity; entity.passenger = this; - } + } } diff --git a/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/NmsManagerImpl.java b/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/NmsManagerImpl.java index e0d7bd7d..96ae6897 100644 --- a/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/NmsManagerImpl.java +++ b/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/NmsManagerImpl.java @@ -40,73 +40,73 @@ import java.lang.reflect.Method; import java.util.Map; public class NmsManagerImpl implements NMSManager { - - private static final ReflectField, String>> ENTITY_NAMES_BY_CLASS_FIELD = new ReflectField<>(EntityTypes.class, "d"); - private static final ReflectField, Integer>> ENTITY_IDS_BY_CLASS_FIELD = new ReflectField<>(EntityTypes.class, "f"); + + private static final ReflectField, String>> ENTITY_NAMES_BY_CLASS_FIELD = new ReflectField<>(EntityTypes.class, "d"); + private static final ReflectField, Integer>> ENTITY_IDS_BY_CLASS_FIELD = new ReflectField<>(EntityTypes.class, "f"); - private Method validateEntityMethod; - - @Override - public void setup() throws Exception { - registerCustomEntity(EntityNMSArmorStand.class, "ArmorStand", 30); - registerCustomEntity(EntityNMSItem.class, "Item", 1); - registerCustomEntity(EntityNMSSlime.class, "Slime", 55); - - validateEntityMethod = World.class.getDeclaredMethod("a", Entity.class); - validateEntityMethod.setAccessible(true); - } - - 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, Integer.valueOf(id)); - } - - @Override - public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager); - customItem.setLocationNMS(x, y, z); - customItem.setItemStackNMS(stack); - if (!addEntityToWorld(nmsWorld, customItem)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return customItem; - } - - @Override - public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramLine parentPiece) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece); - touchSlime.setLocationNMS(x, y, z); - if (!addEntityToWorld(nmsWorld, touchSlime)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return touchSlime; - } - - @Override - public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) { - WorldServer nmsWorld = ((CraftWorld) world).getHandle(); - EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece); - invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket); - if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return invisibleArmorStand; - } - - private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { - Validator.isTrue(Bukkit.isPrimaryThread(), "Async entity add"); - - if (validateEntityMethod == null) { - return nmsWorld.addEntity(nmsEntity, SpawnReason.CUSTOM); - } - + private Method validateEntityMethod; + + @Override + public void setup() throws Exception { + registerCustomEntity(EntityNMSArmorStand.class, "ArmorStand", 30); + registerCustomEntity(EntityNMSItem.class, "Item", 1); + registerCustomEntity(EntityNMSSlime.class, "Slime", 55); + + validateEntityMethod = World.class.getDeclaredMethod("a", Entity.class); + validateEntityMethod.setAccessible(true); + } + + 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, Integer.valueOf(id)); + } + + @Override + public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager); + customItem.setLocationNMS(x, y, z); + customItem.setItemStackNMS(stack); + if (!addEntityToWorld(nmsWorld, customItem)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return customItem; + } + + @Override + public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramLine parentPiece) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece); + touchSlime.setLocationNMS(x, y, z); + if (!addEntityToWorld(nmsWorld, touchSlime)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return touchSlime; + } + + @Override + public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) { + WorldServer nmsWorld = ((CraftWorld) world).getHandle(); + EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece); + invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket); + if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return invisibleArmorStand; + } + + private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { + Validator.isTrue(Bukkit.isPrimaryThread(), "Async entity add"); + + if (validateEntityMethod == null) { + return nmsWorld.addEntity(nmsEntity, SpawnReason.CUSTOM); + } + 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 + // This should never happen nmsEntity.dead = true; return false; } @@ -115,45 +115,45 @@ public class NmsManagerImpl implements NMSManager { nmsWorld.entityList.add(nmsEntity); try { - validateEntityMethod.invoke(nmsWorld, nmsEntity); - } catch (Exception e) { - e.printStackTrace(); - return false; - } + validateEntityMethod.invoke(nmsWorld, nmsEntity); + } catch (Exception e) { + e.printStackTrace(); + return false; + } return true; } - - @Override - public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase; - } + + @Override + public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { + return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase; + } - @Override - public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - - if (nmsEntity instanceof NMSEntityBase) { - return ((NMSEntityBase) nmsEntity); - } else { - return null; - } - } - - @Override - public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - Entity nmsEntity = nmsWorld.a(entityID); - - if (nmsEntity instanceof NMSEntityBase) { - return ((NMSEntityBase) nmsEntity); - } else { - return null; - } - } - - @Override - public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { - return CustomNameHelper.replaceCustomNameString(customNameObject, target, replacement); - } - + @Override + public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { + Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); + + if (nmsEntity instanceof NMSEntityBase) { + return ((NMSEntityBase) nmsEntity); + } else { + return null; + } + } + + @Override + public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + Entity nmsEntity = nmsWorld.a(entityID); + + if (nmsEntity instanceof NMSEntityBase) { + return ((NMSEntityBase) nmsEntity); + } else { + return null; + } + } + + @Override + public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { + return CustomNameHelper.replaceCustomNameString(customNameObject, target, replacement); + } + } 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 index 7d446cba..934cd2a6 100644 --- 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 @@ -20,70 +20,70 @@ import net.minecraft.server.v1_8_R2.Vec3D; public class NullBoundingBox extends AxisAlignedBB { - public NullBoundingBox() { - super(0, 0, 0, 0, 0, 0); - } + public NullBoundingBox() { + super(0, 0, 0, 0, 0, 0); + } - @Override - public double a() { - return 0.0; - } + @Override + public double a() { + return 0.0; + } - @Override - public double a(AxisAlignedBB arg0, double arg1) { - 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(AxisAlignedBB arg0) { + return this; + } - @Override - public AxisAlignedBB a(double arg0, double arg1, double arg2) { - 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 MovingObjectPosition a(Vec3D arg0, Vec3D arg1) { + return super.a(arg0, arg1); + } - @Override - public boolean a(Vec3D arg0) { - return false; - } + @Override + public boolean a(Vec3D arg0) { + return false; + } - @Override - public double b(AxisAlignedBB arg0, double arg1) { - return 0.0; - } + @Override + public double b(AxisAlignedBB arg0, double arg1) { + return 0.0; + } - @Override - public boolean b(AxisAlignedBB arg0) { - return false; - } + @Override + public boolean b(AxisAlignedBB arg0) { + return false; + } - @Override - public double c(AxisAlignedBB arg0, double arg1) { - return 0.0; - } + @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 c(double arg0, double arg1, double arg2) { + return this; + } - @Override - public AxisAlignedBB grow(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; - } + @Override + public AxisAlignedBB shrink(double arg0, double arg1, double arg2) { + return this; + } - + } diff --git a/nms/v1_8_r3/pom.xml b/nms/v1_8_r3/pom.xml index 11aa9559..f6d6e3d6 100644 --- a/nms/v1_8_r3/pom.xml +++ b/nms/v1_8_r3/pom.xml @@ -1,41 +1,41 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - - me.filoghost.holographicdisplays - holographicdisplays-nms - 3.0.0-SNAPSHOT - + + me.filoghost.holographicdisplays + holographicdisplays-nms + 3.0.0-SNAPSHOT + - holographicdisplays-nms-v1_8_r3 - HolographicDisplays NMS v1_8_R3 + holographicdisplays-nms-v1_8_r3 + HolographicDisplays NMS v1_8_R3 - - - nms-repo - https://repo.codemc.io/repository/nms/ - - + + + nms-repo + https://repo.codemc.io/repository/nms/ + + - - - ${project.groupId} - holographicdisplays-nms-interfaces - - - - ${project.groupId} - holographicdisplays-utils - - - - org.spigotmc - spigot - 1.8.8-R0.1-SNAPSHOT - provided - - + + + ${project.groupId} + holographicdisplays-nms-interfaces + + + + ${project.groupId} + holographicdisplays-utils + + + + org.spigotmc + spigot + 1.8.8-R0.1-SNAPSHOT + provided + + - \ No newline at end of file + 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 index 2330b111..15e5e362 100644 --- 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 @@ -29,53 +29,53 @@ 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. - } + 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 Armor stand class - @Override public void setArms(boolean arms) { } - @Override public void setBasePlate(boolean basePlate) { } - @Override public void setBodyPose(EulerAngle pose) { } - @Override public void setBoots(ItemStack item) { } - @Override public void setChestplate(ItemStack item) { } - @Override public void setGravity(boolean gravity) { } - @Override public void setHeadPose(EulerAngle pose) { } - @Override public void setHelmet(ItemStack item) { } - @Override public void setItemInHand(ItemStack item) { } - @Override public void setLeftArmPose(EulerAngle pose) { } - @Override public void setLeftLegPose(EulerAngle pose) { } - @Override public void setLeggings(ItemStack item) { } - @Override public void setRightArmPose(EulerAngle pose) { } - @Override public void setRightLegPose(EulerAngle pose) { } - @Override public void setSmall(boolean small) { } - @Override public void setVisible(boolean visible) { } + // Methods from Armor stand class + @Override public void setArms(boolean arms) { } + @Override public void setBasePlate(boolean basePlate) { } + @Override public void setBodyPose(EulerAngle pose) { } + @Override public void setBoots(ItemStack item) { } + @Override public void setChestplate(ItemStack item) { } + @Override public void setGravity(boolean gravity) { } + @Override public void setHeadPose(EulerAngle pose) { } + @Override public void setHelmet(ItemStack item) { } + @Override public void setItemInHand(ItemStack item) { } + @Override public void setLeftArmPose(EulerAngle pose) { } + @Override public void setLeftLegPose(EulerAngle pose) { } + @Override public void setLeggings(ItemStack item) { } + @Override public void setRightArmPose(EulerAngle pose) { } + @Override public void setRightLegPose(EulerAngle pose) { } + @Override public void setSmall(boolean small) { } + @Override public void setVisible(boolean visible) { } - // 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) { } - + // 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) { } + } 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 index 2bd0218e..b28752dd 100644 --- 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 @@ -25,32 +25,32 @@ import org.bukkit.util.Vector; public class CraftNMSItem extends CraftItem { - public CraftNMSItem(CraftServer server, EntityNMSItem entity) { - super(server, entity); - } + 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. - } + // 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) { } - - // Methods from Item - @Override public void setItemStack(ItemStack stack) { } - @Override public void setPickupDelay(int delay) { } + // 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) { } + + // 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 index 98df1f9f..a2a5826f 100644 --- 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 @@ -27,37 +27,37 @@ 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) { } - - // Methods from Slime - @Override public void setSize(int size) { } + 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) { } + + // 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 index 3d05da29..4501c388 100644 --- 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 @@ -35,206 +35,206 @@ import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; import java.util.logging.Level; public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand { - - private static final ReflectField DISABLED_SLOTS_FIELD = new ReflectField<>(EntityArmorStand.class, "bi"); - private static final ReflectMethod SET_MARKER_METHOD = new ReflectMethod<>(EntityArmorStand.class, "n", boolean.class); + + private static final ReflectField DISABLED_SLOTS_FIELD = new ReflectField<>(EntityArmorStand.class, "bi"); + private static final ReflectMethod SET_MARKER_METHOD = new ReflectMethod<>(EntityArmorStand.class, "n", boolean.class); - private HologramLine parentPiece; - private String customName; - - public EntityNMSArmorStand(World world, HologramLine parentPiece) { - super(world); - setInvisible(true); - setSmall(true); - setArms(false); - setGravity(true); - setBasePlate(true); - try { - SET_MARKER_METHOD.invoke(this, true); - } catch (Throwable t) { - ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set armor stand as marker", t); - // It will still work, but the offset will be wrong. - } - this.parentPiece = parentPiece; - try { - DISABLED_SLOTS_FIELD.set(this, Integer.MAX_VALUE); - } catch (Exception e) { - // There's still the overridden method. - } - forceSetBoundingBox(new NullBoundingBox()); - - this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet. - } - - @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 (this.onGround) { - this.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 (this.onGround) { - this.onGround = false; - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT. - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT. - return false; - } + private HologramLine parentPiece; + private String customName; + + public EntityNMSArmorStand(World world, HologramLine parentPiece) { + super(world); + setInvisible(true); + setSmall(true); + setArms(false); + setGravity(true); + setBasePlate(true); + try { + SET_MARKER_METHOD.invoke(this, true); + } catch (Throwable t) { + ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set armor stand as marker", t); + // It will still work, but the offset will be wrong. + } + this.parentPiece = parentPiece; + try { + DISABLED_SLOTS_FIELD.set(this, Integer.MAX_VALUE); + } catch (Exception e) { + // There's still the overridden method. + } + forceSetBoundingBox(new NullBoundingBox()); + + this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet. + } + + @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 (this.onGround) { + this.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 (this.onGround) { + this.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) { - // Locks the custom name. - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Locks the custom name. - } + @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) { + // Locks the custom name. + } + + @Override + public void setCustomNameVisible(boolean visible) { + // Locks the custom name. + } - @Override - public boolean a(EntityHuman human, Vec3D vec3d) { - // Prevent stand being equipped - return true; - } + @Override + public boolean a(EntityHuman human, Vec3D vec3d) { + // Prevent stand being equipped + return true; + } - @Override - public boolean d(int i, ItemStack item) { - // Prevent stand being equipped - return false; - } + @Override + public boolean d(int i, ItemStack item) { + // Prevent stand being equipped + return false; + } - @Override - public void setEquipment(int i, ItemStack item) { - // Prevent stand being equipped - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Do not change it! - } - - 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 name) { - this.customName = Utils.limitLength(name, 300); - super.setCustomName(customName); - super.setCustomNameVisible(customName != null && !customName.isEmpty()); - } - - @Override - public String getCustomNameStringNMS() { - return this.customName; - } - - @Override - public Object getCustomNameObjectNMS() { - return super.getCustomName(); - } - - @Override - public void die() { - // Prevent being killed. - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - this.bukkitEntity = new CraftNMSArmorStand(this.world.getServer(), this); - } - return this.bukkitEntity; - } - - @Override - public void killEntityNMS() { - super.dead = true; - } - - @Override - public void setLocationNMS(double x, double y, double z, boolean broadcastLocationPacket) { - super.setPosition(x, y, z); - if (broadcastLocationPacket) { - broadcastLocationPacketNMS(); - } - } - - private void broadcastLocationPacketNMS() { - PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); + @Override + public void setEquipment(int i, ItemStack item) { + // Prevent stand being equipped + } + + @Override + public void a(AxisAlignedBB boundingBox) { + // Do not change it! + } + + 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 name) { + this.customName = Utils.limitLength(name, 300); + super.setCustomName(customName); + super.setCustomNameVisible(customName != null && !customName.isEmpty()); + } + + @Override + public String getCustomNameStringNMS() { + return this.customName; + } + + @Override + public Object getCustomNameObjectNMS() { + return super.getCustomName(); + } + + @Override + public void die() { + // Prevent being killed. + } + + @Override + public CraftEntity getBukkitEntity() { + if (super.bukkitEntity == null) { + this.bukkitEntity = new CraftNMSArmorStand(this.world.getServer(), this); + } + return this.bukkitEntity; + } + + @Override + public void killEntityNMS() { + super.dead = true; + } + + @Override + public void setLocationNMS(double x, double y, double z, boolean broadcastLocationPacket) { + super.setPosition(x, y, z); + if (broadcastLocationPacket) { + broadcastLocationPacketNMS(); + } + } + + private void broadcastLocationPacketNMS() { + PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); - for (Object obj : this.world.players) { - if (obj instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) obj; + for (Object obj : this.world.players) { + if (obj instanceof EntityPlayer) { + EntityPlayer nmsPlayer = (EntityPlayer) obj; - double distanceSquared = Utils.square(nmsPlayer.locX - this.locX) + Utils.square(nmsPlayer.locZ - this.locZ); - if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(teleportPacket); - } - } - } - } + double distanceSquared = Utils.square(nmsPlayer.locX - this.locX) + Utils.square(nmsPlayer.locZ - this.locZ); + if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) { + nmsPlayer.playerConnection.sendPacket(teleportPacket); + } + } + } + } - @Override - public boolean isDeadNMS() { - return this.dead; - } - - @Override - public int getIdNMS() { - return super.getId(); - } + @Override + public boolean isDeadNMS() { + return this.dead; + } + + @Override + public int getIdNMS() { + return super.getId(); + } - @Override - public HologramLine getHologramLine() { - return parentPiece; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } + @Override + public HologramLine getHologramLine() { + return parentPiece; + } + + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } } 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 index f9a58b6f..6d6ca5a3 100644 --- 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 @@ -39,192 +39,192 @@ import org.bukkit.entity.Player; import java.util.logging.Level; public class EntityNMSItem extends EntityItem implements NMSItem { - - private static final ReflectField RIDER_PITCH_DELTA = new ReflectField<>(Entity.class, "ar"); - private static final ReflectField RIDER_YAW_DELTA = new ReflectField<>(Entity.class, "as"); - - private ItemLine parentPiece; - private ItemPickupManager itemPickupManager; - - public EntityNMSItem(World world, ItemLine piece, ItemPickupManager itemPickupManager) { - super(world); - super.pickupDelay = Integer.MAX_VALUE; - this.parentPiece = piece; - this.itemPickupManager = itemPickupManager; - } - - @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 (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) { - itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent()); - // 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; - } + + private static final ReflectField RIDER_PITCH_DELTA = new ReflectField<>(Entity.class, "ar"); + private static final ReflectField RIDER_YAW_DELTA = new ReflectField<>(Entity.class, "as"); + + private ItemLine parentPiece; + private ItemPickupManager itemPickupManager; + + public EntityNMSItem(World world, ItemLine piece, ItemPickupManager itemPickupManager) { + super(world); + super.pickupDelay = Integer.MAX_VALUE; + this.parentPiece = piece; + this.itemPickupManager = itemPickupManager; + } + + @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 (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) { + itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent()); + // 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 being killed. - } - - @Override - public boolean isAlive() { - // This override prevents items from being picked up by hoppers. - // Should have no side effects. - 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 being killed. + } + + @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) { - this.bukkitEntity = new CraftNMSItem(this.world.getServer(), this); - } - return this.bukkitEntity; - } + @Override + public CraftEntity getBukkitEntity() { + if (super.bukkitEntity == null) { + this.bukkitEntity = new CraftNMSItem(this.world.getServer(), this); + } + return this.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 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(ItemUtils.ANTISTACK_LORE)); // Antistack lore - display.set("Lore", tagList); - - setItemStack(newItem); - } - - @Override - public int getIdNMS() { - return this.getId(); - } - - @Override - public ItemLine getHologramLine() { - return parentPiece; - } - - @Override - public void allowPickup(boolean pickup) { - if (pickup) { - super.pickupDelay = 0; - } else { - super.pickupDelay = Integer.MAX_VALUE; - } - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public void setPassengerOfNMS(NMSEntityBase vehicleBase) { - if (vehicleBase == null || !(vehicleBase instanceof Entity)) { - // It should never dismount - return; - } - - Entity entity = (Entity) vehicleBase; - - try { - RIDER_PITCH_DELTA.set(this, 0.0); - RIDER_YAW_DELTA.set(this, 0.0); - } catch (Throwable t) { - ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set rider pitch and yaw", t); - } + @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(ItemUtils.ANTISTACK_LORE)); // Antistack lore + display.set("Lore", tagList); + + setItemStack(newItem); + } + + @Override + public int getIdNMS() { + return this.getId(); + } + + @Override + public ItemLine getHologramLine() { + return parentPiece; + } + + @Override + public void allowPickup(boolean pickup) { + if (pickup) { + super.pickupDelay = 0; + } else { + super.pickupDelay = Integer.MAX_VALUE; + } + } + + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } + + @Override + public void setPassengerOfNMS(NMSEntityBase vehicleBase) { + if (vehicleBase == null || !(vehicleBase instanceof Entity)) { + // It should never dismount + return; + } + + Entity entity = (Entity) vehicleBase; + + try { + RIDER_PITCH_DELTA.set(this, 0.0); + RIDER_YAW_DELTA.set(this, 0.0); + } catch (Throwable t) { + ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set rider pitch and yaw", t); + } if (this.vehicle != null) { - this.vehicle.passenger = null; + this.vehicle.passenger = null; } this.vehicle = entity; entity.passenger = this; - } - - @Override - public Object getRawItemStack() { - return super.getItemStack(); - } + } + + @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 index 25434b65..dec36ea1 100644 --- 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 @@ -34,174 +34,174 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import java.util.logging.Level; public class EntityNMSSlime extends EntitySlime implements NMSSlime { - - private static final ReflectField RIDER_PITCH_DELTA = new ReflectField<>(Entity.class, "ar"); - private static final ReflectField RIDER_YAW_DELTA = new ReflectField<>(Entity.class, "as"); + + private static final ReflectField RIDER_PITCH_DELTA = new ReflectField<>(Entity.class, "ar"); + private static final ReflectField RIDER_YAW_DELTA = new ReflectField<>(Entity.class, "as"); - private HologramLine parentPiece; - - public EntityNMSSlime(World world, HologramLine parentPiece) { - super(world); - super.persistent = true; - a(0.0F, 0.0F); - setSize(1); - setInvisible(true); - this.parentPiece = parentPiece; - forceSetBoundingBox(new NullBoundingBox()); - } - - @Override - public void t_() { - // Disable normal ticking for this entity. - - // So it won't get removed. - ticksLived = 0; + private HologramLine parentPiece; + + public EntityNMSSlime(World world, HologramLine parentPiece) { + super(world); + super.persistent = true; + a(0.0F, 0.0F); + setSize(1); + setInvisible(true); + this.parentPiece = parentPiece; + 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 (this.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) { - // Do not change it! - } - - 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; - } + // The slime dies without a vehicle. + if (this.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) { + // Do not change it! + } + + 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) { - Bukkit.getPluginManager().callEvent(new PlayerInteractEntityEvent(((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(), getBukkitEntity())); - } - } - 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 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) { + Bukkit.getPluginManager().callEvent(new PlayerInteractEntityEvent(((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(), getBukkitEntity())); + } + } + 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) { - // Locks the custom name. - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Locks the custom name. - } - - @Override - public void makeSound(String sound, float volume, float pitch) { - // Remove sounds. - } - - @Override - public void die() { - // Prevent being killed. - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - this.bukkitEntity = new CraftNMSSlime(this.world.getServer(), this); - } - return this.bukkitEntity; - } + @Override + public void setCustomName(String customName) { + // Locks the custom name. + } + + @Override + public void setCustomNameVisible(boolean visible) { + // Locks the custom name. + } + + @Override + public void makeSound(String sound, float volume, float pitch) { + // Remove sounds. + } + + @Override + public void die() { + // Prevent being killed. + } + + @Override + public CraftEntity getBukkitEntity() { + if (super.bukkitEntity == null) { + this.bukkitEntity = new CraftNMSSlime(this.world.getServer(), this); + } + return this.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 this.getId(); - } - - @Override - public HologramLine getHologramLine() { - return parentPiece; - } + @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 this.getId(); + } + + @Override + public HologramLine getHologramLine() { + return parentPiece; + } - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public void setPassengerOfNMS(NMSEntityBase vehicleBase) { - if (vehicleBase == null || !(vehicleBase instanceof Entity)) { - // It should never dismount - return; - } - - Entity entity = (Entity) vehicleBase; - - try { - RIDER_PITCH_DELTA.set(this, 0.0); - RIDER_YAW_DELTA.set(this, 0.0); - } catch (Throwable t) { - ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set rider pitch and yaw", t); - } + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } + + @Override + public void setPassengerOfNMS(NMSEntityBase vehicleBase) { + if (vehicleBase == null || !(vehicleBase instanceof Entity)) { + // It should never dismount + return; + } + + Entity entity = (Entity) vehicleBase; + + try { + RIDER_PITCH_DELTA.set(this, 0.0); + RIDER_YAW_DELTA.set(this, 0.0); + } catch (Throwable t) { + ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set rider pitch and yaw", t); + } if (this.vehicle != null) { - this.vehicle.passenger = null; + this.vehicle.passenger = null; } this.vehicle = entity; entity.passenger = this; - } + } } diff --git a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/NmsManagerImpl.java b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/NmsManagerImpl.java index 4ccf42de..4bf3562d 100644 --- a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/NmsManagerImpl.java +++ b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/NmsManagerImpl.java @@ -40,73 +40,73 @@ import java.lang.reflect.Method; import java.util.Map; public class NmsManagerImpl implements NMSManager { - - private static final ReflectField, String>> ENTITY_NAMES_BY_CLASS_FIELD = new ReflectField<>(EntityTypes.class, "d"); - private static final ReflectField, Integer>> ENTITY_IDS_BY_CLASS_FIELD = new ReflectField<>(EntityTypes.class, "f"); + + private static final ReflectField, String>> ENTITY_NAMES_BY_CLASS_FIELD = new ReflectField<>(EntityTypes.class, "d"); + private static final ReflectField, Integer>> ENTITY_IDS_BY_CLASS_FIELD = new ReflectField<>(EntityTypes.class, "f"); - private Method validateEntityMethod; - - @Override - public void setup() throws Exception { - registerCustomEntity(EntityNMSArmorStand.class, "ArmorStand", 30); - registerCustomEntity(EntityNMSItem.class, "Item", 1); - registerCustomEntity(EntityNMSSlime.class, "Slime", 55); - - validateEntityMethod = World.class.getDeclaredMethod("a", Entity.class); - validateEntityMethod.setAccessible(true); - } - - 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, Integer.valueOf(id)); - } - - @Override - public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager); - customItem.setLocationNMS(x, y, z); - customItem.setItemStackNMS(stack); - if (!addEntityToWorld(nmsWorld, customItem)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return customItem; - } - - @Override - public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramLine parentPiece) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece); - touchSlime.setLocationNMS(x, y, z); - if (!addEntityToWorld(nmsWorld, touchSlime)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return touchSlime; - } - - @Override - public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) { - WorldServer nmsWorld = ((CraftWorld) world).getHandle(); - EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece); - invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket); - if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return invisibleArmorStand; - } - - private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { - Validator.isTrue(Bukkit.isPrimaryThread(), "Async entity add"); - - if (validateEntityMethod == null) { - return nmsWorld.addEntity(nmsEntity, SpawnReason.CUSTOM); - } - + private Method validateEntityMethod; + + @Override + public void setup() throws Exception { + registerCustomEntity(EntityNMSArmorStand.class, "ArmorStand", 30); + registerCustomEntity(EntityNMSItem.class, "Item", 1); + registerCustomEntity(EntityNMSSlime.class, "Slime", 55); + + validateEntityMethod = World.class.getDeclaredMethod("a", Entity.class); + validateEntityMethod.setAccessible(true); + } + + 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, Integer.valueOf(id)); + } + + @Override + public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager); + customItem.setLocationNMS(x, y, z); + customItem.setItemStackNMS(stack); + if (!addEntityToWorld(nmsWorld, customItem)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return customItem; + } + + @Override + public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramLine parentPiece) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece); + touchSlime.setLocationNMS(x, y, z); + if (!addEntityToWorld(nmsWorld, touchSlime)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return touchSlime; + } + + @Override + public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) { + WorldServer nmsWorld = ((CraftWorld) world).getHandle(); + EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece); + invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket); + if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return invisibleArmorStand; + } + + private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { + Validator.isTrue(Bukkit.isPrimaryThread(), "Async entity add"); + + if (validateEntityMethod == null) { + return nmsWorld.addEntity(nmsEntity, SpawnReason.CUSTOM); + } + 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 + // This should never happen nmsEntity.dead = true; return false; } @@ -115,45 +115,45 @@ public class NmsManagerImpl implements NMSManager { nmsWorld.entityList.add(nmsEntity); try { - validateEntityMethod.invoke(nmsWorld, nmsEntity); - } catch (Exception e) { - e.printStackTrace(); - return false; - } + validateEntityMethod.invoke(nmsWorld, nmsEntity); + } catch (Exception e) { + e.printStackTrace(); + return false; + } return true; } - - @Override - public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase; - } + + @Override + public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { + return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase; + } - @Override - public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - - if (nmsEntity instanceof NMSEntityBase) { - return ((NMSEntityBase) nmsEntity); - } else { - return null; - } - } - - @Override - public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - Entity nmsEntity = nmsWorld.a(entityID); - - if (nmsEntity instanceof NMSEntityBase) { - return ((NMSEntityBase) nmsEntity); - } else { - return null; - } - } - - @Override - public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { - return CustomNameHelper.replaceCustomNameString(customNameObject, target, replacement); - } + @Override + public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { + Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); + + if (nmsEntity instanceof NMSEntityBase) { + return ((NMSEntityBase) nmsEntity); + } else { + return null; + } + } + + @Override + public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + Entity nmsEntity = nmsWorld.a(entityID); + + if (nmsEntity instanceof NMSEntityBase) { + return ((NMSEntityBase) nmsEntity); + } else { + return null; + } + } + + @Override + public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { + return CustomNameHelper.replaceCustomNameString(customNameObject, target, replacement); + } } 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 index 2d0762c2..663d134b 100644 --- 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 @@ -20,70 +20,70 @@ import net.minecraft.server.v1_8_R3.Vec3D; public class NullBoundingBox extends AxisAlignedBB { - public NullBoundingBox() { - super(0, 0, 0, 0, 0, 0); - } + public NullBoundingBox() { + super(0, 0, 0, 0, 0, 0); + } - @Override - public double a() { - return 0.0; - } + @Override + public double a() { + return 0.0; + } - @Override - public double a(AxisAlignedBB arg0, double arg1) { - 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(AxisAlignedBB arg0) { + return this; + } - @Override - public AxisAlignedBB a(double arg0, double arg1, double arg2) { - 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 MovingObjectPosition a(Vec3D arg0, Vec3D arg1) { + return super.a(arg0, arg1); + } - @Override - public boolean a(Vec3D arg0) { - return false; - } + @Override + public boolean a(Vec3D arg0) { + return false; + } - @Override - public double b(AxisAlignedBB arg0, double arg1) { - return 0.0; - } + @Override + public double b(AxisAlignedBB arg0, double arg1) { + return 0.0; + } - @Override - public boolean b(AxisAlignedBB arg0) { - return false; - } + @Override + public boolean b(AxisAlignedBB arg0) { + return false; + } - @Override - public double c(AxisAlignedBB arg0, double arg1) { - return 0.0; - } + @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 c(double arg0, double arg1, double arg2) { + return this; + } - @Override - public AxisAlignedBB grow(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; - } + @Override + public AxisAlignedBB shrink(double arg0, double arg1, double arg2) { + return this; + } - + } diff --git a/nms/v1_9_r1/pom.xml b/nms/v1_9_r1/pom.xml index 8bea3212..c19a2e8a 100644 --- a/nms/v1_9_r1/pom.xml +++ b/nms/v1_9_r1/pom.xml @@ -1,41 +1,41 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - - me.filoghost.holographicdisplays - holographicdisplays-nms - 3.0.0-SNAPSHOT - + + me.filoghost.holographicdisplays + holographicdisplays-nms + 3.0.0-SNAPSHOT + - holographicdisplays-nms-v1_9_r1 - HolographicDisplays NMS v1_9_R1 + holographicdisplays-nms-v1_9_r1 + HolographicDisplays NMS v1_9_R1 - - - nms-repo - https://repo.codemc.io/repository/nms/ - - + + + nms-repo + https://repo.codemc.io/repository/nms/ + + - - - ${project.groupId} - holographicdisplays-nms-interfaces - - - - ${project.groupId} - holographicdisplays-utils - - - - org.spigotmc - spigot - 1.9-R0.1-SNAPSHOT - provided - - + + + ${project.groupId} + holographicdisplays-nms-interfaces + + + + ${project.groupId} + holographicdisplays-utils + + + + org.spigotmc + spigot + 1.9-R0.1-SNAPSHOT + provided + + - \ No newline at end of file + 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 index 271e4270..cf77a567 100644 --- 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 @@ -29,54 +29,54 @@ 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. - } + 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 Armor stand class - @Override public void setArms(boolean arms) { } - @Override public void setBasePlate(boolean basePlate) { } - @Override public void setBodyPose(EulerAngle pose) { } - @Override public void setBoots(ItemStack item) { } - @Override public void setChestplate(ItemStack item) { } - @Override public void setGravity(boolean gravity) { } - @Override public void setHeadPose(EulerAngle pose) { } - @Override public void setHelmet(ItemStack item) { } - @Override public void setItemInHand(ItemStack item) { } - @Override public void setLeftArmPose(EulerAngle pose) { } - @Override public void setLeftLegPose(EulerAngle pose) { } - @Override public void setLeggings(ItemStack item) { } - @Override public void setRightArmPose(EulerAngle pose) { } - @Override public void setRightLegPose(EulerAngle pose) { } - @Override public void setSmall(boolean small) { } - @Override public void setVisible(boolean visible) { } - @Override public void setMarker(boolean marker) { } + // Methods from Armor stand class + @Override public void setArms(boolean arms) { } + @Override public void setBasePlate(boolean basePlate) { } + @Override public void setBodyPose(EulerAngle pose) { } + @Override public void setBoots(ItemStack item) { } + @Override public void setChestplate(ItemStack item) { } + @Override public void setGravity(boolean gravity) { } + @Override public void setHeadPose(EulerAngle pose) { } + @Override public void setHelmet(ItemStack item) { } + @Override public void setItemInHand(ItemStack item) { } + @Override public void setLeftArmPose(EulerAngle pose) { } + @Override public void setLeftLegPose(EulerAngle pose) { } + @Override public void setLeggings(ItemStack item) { } + @Override public void setRightArmPose(EulerAngle pose) { } + @Override public void setRightLegPose(EulerAngle pose) { } + @Override public void setSmall(boolean small) { } + @Override public void setVisible(boolean visible) { } + @Override public void 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) { } - + // 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) { } + } 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 index b6978dc4..85f03605 100644 --- 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 @@ -25,33 +25,33 @@ import org.bukkit.util.Vector; public class CraftNMSItem extends CraftItem { - public CraftNMSItem(CraftServer server, EntityNMSItem entity) { - super(server, entity); - } + 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. - } + // 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) { } - - // Methods from Item - @Override public void setItemStack(ItemStack stack) { } - @Override public void setPickupDelay(int delay) { } - + // 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) { } + + // 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 index fb2b8e58..14507ed0 100644 --- 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 @@ -27,38 +27,38 @@ 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) { } - - // Methods from Slime - @Override public void setSize(int size) { } - + 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) { } + + // 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 index e773a42c..42c004df 100644 --- 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 @@ -35,216 +35,216 @@ import net.minecraft.server.v1_9_R1.World; import org.bukkit.craftbukkit.v1_9_R1.entity.CraftEntity; public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand { - - private static final ReflectField DISABLED_SLOTS_FIELD = new ReflectField<>(EntityArmorStand.class, "bz"); + + private static final ReflectField DISABLED_SLOTS_FIELD = new ReflectField<>(EntityArmorStand.class, "bz"); - private HologramLine parentPiece; + private HologramLine parentPiece; - private String customName; - - public EntityNMSArmorStand(World world, HologramLine parentPiece) { - super(world); - super.setInvisible(true); - super.setSmall(true); - super.setArms(false); - super.setGravity(true); - super.setBasePlate(true); - super.setMarker(true); - this.parentPiece = parentPiece; - try { - DISABLED_SLOTS_FIELD.set(this, Integer.MAX_VALUE); - } catch (Exception e) { - // There's still the overridden method. - } - forceSetBoundingBox(new NullBoundingBox()); - - this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet. - } - - @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 (this.onGround) { - this.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 (this.onGround) { - this.onGround = false; - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT. - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT. - return false; - } + private String customName; + + public EntityNMSArmorStand(World world, HologramLine parentPiece) { + super(world); + super.setInvisible(true); + super.setSmall(true); + super.setArms(false); + super.setGravity(true); + super.setBasePlate(true); + super.setMarker(true); + this.parentPiece = parentPiece; + try { + DISABLED_SLOTS_FIELD.set(this, Integer.MAX_VALUE); + } catch (Exception e) { + // There's still the overridden method. + } + forceSetBoundingBox(new NullBoundingBox()); + + this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet. + } + + @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 (this.onGround) { + this.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 (this.onGround) { + this.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) { - // Locks the custom name. - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Locks the custom name. - } + @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) { + // Locks the custom name. + } + + @Override + public void setCustomNameVisible(boolean visible) { + // Locks the custom name. + } - @Override - public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, ItemStack itemstack, EnumHand enumhand) { - // Prevent stand being equipped - return EnumInteractionResult.PASS; - } + @Override + public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, ItemStack itemstack, EnumHand enumhand) { + // Prevent stand being equipped + return EnumInteractionResult.PASS; + } - @Override - public boolean c(int i, ItemStack item) { - // Prevent stand being equipped - return false; - } + @Override + public boolean c(int i, ItemStack item) { + // Prevent stand being equipped + return false; + } - @Override - public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { - // Prevent stand being equipped - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Do not change it! - } - - 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 name) { - this.customName = Utils.limitLength(name, 300); - super.setCustomName(customName); - super.setCustomNameVisible(customName != null && !customName.isEmpty()); - } - - @Override - public String getCustomNameStringNMS() { - return this.customName; - } - - @Override - public Object getCustomNameObjectNMS() { - return super.getCustomName(); - } - - @Override - public void die() { - // Prevent being killed. - } - - @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, boolean broadcastLocationPacket) { - super.setPosition(x, y, z); - if (broadcastLocationPacket) { - broadcastLocationPacketNMS(); - } - } - - private void broadcastLocationPacketNMS() { - PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); - - for (Object obj : super.world.players) { - if (obj instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) obj; + @Override + public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { + // Prevent stand being equipped + } + + @Override + public void a(AxisAlignedBB boundingBox) { + // Do not change it! + } + + 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 name) { + this.customName = Utils.limitLength(name, 300); + super.setCustomName(customName); + super.setCustomNameVisible(customName != null && !customName.isEmpty()); + } + + @Override + public String getCustomNameStringNMS() { + return this.customName; + } + + @Override + public Object getCustomNameObjectNMS() { + return super.getCustomName(); + } + + @Override + public void die() { + // Prevent being killed. + } + + @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, boolean broadcastLocationPacket) { + super.setPosition(x, y, z); + if (broadcastLocationPacket) { + broadcastLocationPacketNMS(); + } + } + + private void broadcastLocationPacketNMS() { + PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); + + for (Object obj : super.world.players) { + if (obj instanceof EntityPlayer) { + EntityPlayer nmsPlayer = (EntityPlayer) obj; - double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ); - if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(teleportPacket); - } - } - } - } + double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ); + if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) { + nmsPlayer.playerConnection.sendPacket(teleportPacket); + } + } + } + } - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public int getIdNMS() { - return super.getId(); - } + @Override + public boolean isDeadNMS() { + return super.dead; + } + + @Override + public int getIdNMS() { + return super.getId(); + } - @Override - public HologramLine getHologramLine() { - return parentPiece; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } + @Override + public HologramLine getHologramLine() { + return parentPiece; + } + + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } } 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 index 1f3f6f3b..0761e167 100644 --- 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 @@ -41,229 +41,229 @@ import org.bukkit.entity.Player; import java.util.logging.Level; public class EntityNMSItem extends EntityItem implements NMSItem { - - private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "as"); - - private ItemLine parentPiece; - private ItemPickupManager itemPickupManager; - - private int resendMountPacketTicks; - - public EntityNMSItem(World world, ItemLine piece, ItemPickupManager itemPickupManager) { - super(world); - super.pickupDelay = Integer.MAX_VALUE; - this.parentPiece = piece; - this.itemPickupManager = itemPickupManager; - } - - @Override - public void m() { - // Disable normal ticking for this entity. - - // So it won't get removed. - ticksLived = 0; - - if (resendMountPacketTicks++ > 20) { - resendMountPacketTicks = 0; - - if (by() != null) { - // Send a packet near to "remind" players that the item is riding the armor stand (Spigot bug or client bug) - PacketPlayOutMount mountPacket = new PacketPlayOutMount(by()); - - for (Object obj : super.world.players) { - if (obj instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) obj; - - double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ); - if (distanceSquared < 1024 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(mountPacket); - } - } - } - } - } - } - - @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 (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) { - itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent()); - // 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; - } + + private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "as"); + + private ItemLine parentPiece; + private ItemPickupManager itemPickupManager; + + private int resendMountPacketTicks; + + public EntityNMSItem(World world, ItemLine piece, ItemPickupManager itemPickupManager) { + super(world); + super.pickupDelay = Integer.MAX_VALUE; + this.parentPiece = piece; + this.itemPickupManager = itemPickupManager; + } + + @Override + public void m() { + // Disable normal ticking for this entity. + + // So it won't get removed. + ticksLived = 0; + + if (resendMountPacketTicks++ > 20) { + resendMountPacketTicks = 0; + + if (by() != null) { + // Send a packet near to "remind" players that the item is riding the armor stand (Spigot bug or client bug) + PacketPlayOutMount mountPacket = new PacketPlayOutMount(by()); + + for (Object obj : super.world.players) { + if (obj instanceof EntityPlayer) { + EntityPlayer nmsPlayer = (EntityPlayer) obj; + + double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ); + if (distanceSquared < 1024 && nmsPlayer.playerConnection != null) { + nmsPlayer.playerConnection.sendPacket(mountPacket); + } + } + } + } + } + } + + @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 (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) { + itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent()); + // 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 being killed. - } - - @Override - public boolean isAlive() { - // This override prevents items from being picked up by hoppers. - // Should have no side effects. - 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 being killed. + } + + @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 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 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(ItemUtils.ANTISTACK_LORE)); // Antistack lore - display.set("Lore", tagList); - - setItemStack(newItem); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public ItemLine getHologramLine() { - return parentPiece; - } - - @Override - public void allowPickup(boolean pickup) { - if (pickup) { - super.pickupDelay = 0; - } else { - super.pickupDelay = Integer.MAX_VALUE; - } - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public void setPassengerOfNMS(NMSEntityBase vehicleBase) { - if (vehicleBase == null || !(vehicleBase instanceof Entity)) { - // It should never dismount - return; - } - - Entity entity = (Entity) vehicleBase; + @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(ItemUtils.ANTISTACK_LORE)); // Antistack lore + display.set("Lore", tagList); + + setItemStack(newItem); + } + + @Override + public int getIdNMS() { + return super.getId(); + } + + @Override + public ItemLine getHologramLine() { + return parentPiece; + } + + @Override + public void allowPickup(boolean pickup) { + if (pickup) { + super.pickupDelay = 0; + } else { + super.pickupDelay = Integer.MAX_VALUE; + } + } + + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } + + @Override + public void setPassengerOfNMS(NMSEntityBase vehicleBase) { + if (vehicleBase == null || !(vehicleBase instanceof Entity)) { + // It should never dismount + return; + } + + Entity entity = (Entity) vehicleBase; - try { - if (super.by() != null) { - Entity oldVehicle = super.by(); - VEHICLE_FIELD.set(this, null); - oldVehicle.passengers.remove(this); - } + try { + if (super.by() != null) { + Entity oldVehicle = super.by(); + VEHICLE_FIELD.set(this, null); + oldVehicle.passengers.remove(this); + } - VEHICLE_FIELD.set(this, entity); - entity.passengers.clear(); - entity.passengers.add(this); + VEHICLE_FIELD.set(this, entity); + entity.passengers.clear(); + entity.passengers.add(this); - } catch (Throwable t) { - ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); - } - } + } catch (Throwable t) { + ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); + } + } - @Override - public Object getRawItemStack() { - return super.getItemStack(); - } + @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 index a8174c0d..7c366ffc 100644 --- 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 @@ -37,206 +37,206 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import java.util.logging.Level; public class EntityNMSSlime extends EntitySlime implements NMSSlime { - - private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "as"); + + private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "as"); - private HologramLine parentPiece; - - private int resendMountPacketTicks; - - public EntityNMSSlime(World world, HologramLine parentPiece) { - super(world); - super.persistent = true; - a(0.0F, 0.0F); - setSize(1); - setInvisible(true); - this.parentPiece = parentPiece; - 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; + private HologramLine parentPiece; + + private int resendMountPacketTicks; + + public EntityNMSSlime(World world, HologramLine parentPiece) { + super(world); + super.persistent = true; + a(0.0F, 0.0F); + setSize(1); + setInvisible(true); + this.parentPiece = parentPiece; + 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; - if (by() != null) { - // Send a packet near to "remind" players that the slime is riding the armor stand (Spigot bug or client bug) - PacketPlayOutMount mountPacket = new PacketPlayOutMount(by()); - - for (Object obj : super.world.players) { - if (obj instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) obj; - - double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ); - if (distanceSquared < 1024 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(mountPacket); - } - } - } - } - } - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity. - - // So it won't get removed. - ticksLived = 0; - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Do not change it! - } - - 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; - } + if (by() != null) { + // Send a packet near to "remind" players that the slime is riding the armor stand (Spigot bug or client bug) + PacketPlayOutMount mountPacket = new PacketPlayOutMount(by()); + + for (Object obj : super.world.players) { + if (obj instanceof EntityPlayer) { + EntityPlayer nmsPlayer = (EntityPlayer) obj; + + double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ); + if (distanceSquared < 1024 && nmsPlayer.playerConnection != null) { + nmsPlayer.playerConnection.sendPacket(mountPacket); + } + } + } + } + } + } + + @Override + public void inactiveTick() { + // Disable normal ticking for this entity. + + // So it won't get removed. + ticksLived = 0; + } + + @Override + public void a(AxisAlignedBB boundingBox) { + // Do not change it! + } + + 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) { - Bukkit.getPluginManager().callEvent(new PlayerInteractEntityEvent(((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(), getBukkitEntity())); // 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 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) { + Bukkit.getPluginManager().callEvent(new PlayerInteractEntityEvent(((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(), getBukkitEntity())); // 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) { - // Locks the custom name. - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Locks the custom name. - } - - @Override - public void a(SoundEffect soundeffect, float f, float f1) { - // Remove sounds. - } - - @Override - public void die() { - // Prevent being killed. - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSSlime(super.world.getServer(), this); - } - return super.bukkitEntity; - } + @Override + public void setCustomName(String customName) { + // Locks the custom name. + } + + @Override + public void setCustomNameVisible(boolean visible) { + // Locks the custom name. + } + + @Override + public void a(SoundEffect soundeffect, float f, float f1) { + // Remove sounds. + } + + @Override + public void die() { + // Prevent being killed. + } + + @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 HologramLine getHologramLine() { - return parentPiece; - } + @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 HologramLine getHologramLine() { + return parentPiece; + } - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public void setPassengerOfNMS(NMSEntityBase vehicleBase) { - if (vehicleBase == null || !(vehicleBase instanceof Entity)) { - // It should never dismount - return; - } - - Entity entity = (Entity) vehicleBase; - - try { - if (super.by() != null) { - Entity oldVehicle = super.by(); - VEHICLE_FIELD.set(this, null); - oldVehicle.passengers.remove(this); - } + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } + + @Override + public void setPassengerOfNMS(NMSEntityBase vehicleBase) { + if (vehicleBase == null || !(vehicleBase instanceof Entity)) { + // It should never dismount + return; + } + + Entity entity = (Entity) vehicleBase; + + try { + if (super.by() != null) { + Entity oldVehicle = super.by(); + VEHICLE_FIELD.set(this, null); + oldVehicle.passengers.remove(this); + } - VEHICLE_FIELD.set(this, entity); - entity.passengers.clear(); - entity.passengers.add(this); + VEHICLE_FIELD.set(this, entity); + entity.passengers.clear(); + entity.passengers.add(this); - } catch (Throwable t) { - ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); - } - } + } catch (Throwable t) { + ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); + } + } } diff --git a/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/NmsManagerImpl.java b/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/NmsManagerImpl.java index 1b706c56..384a6d7c 100644 --- a/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/NmsManagerImpl.java +++ b/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/NmsManagerImpl.java @@ -39,69 +39,69 @@ import java.lang.reflect.Method; import java.util.Map; public class NmsManagerImpl implements NMSManager { - - private static final ReflectField, String>> ENTITY_NAMES_BY_CLASS_FIELD = new ReflectField<>(EntityTypes.class, "d"); - private static final ReflectField, Integer>> ENTITY_IDS_BY_CLASS_FIELD = new ReflectField<>(EntityTypes.class, "f"); + + private static final ReflectField, String>> ENTITY_NAMES_BY_CLASS_FIELD = new ReflectField<>(EntityTypes.class, "d"); + private static final ReflectField, Integer>> ENTITY_IDS_BY_CLASS_FIELD = new ReflectField<>(EntityTypes.class, "f"); - private Method validateEntityMethod; - - @Override - public void setup() throws Exception { - registerCustomEntity(EntityNMSArmorStand.class, "ArmorStand", 30); - registerCustomEntity(EntityNMSItem.class, "Item", 1); - registerCustomEntity(EntityNMSSlime.class, "Slime", 55); - - validateEntityMethod = World.class.getDeclaredMethod("b", Entity.class); - validateEntityMethod.setAccessible(true); - } - - 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, Integer.valueOf(id)); - } - - @Override - public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager); - customItem.setLocationNMS(x, y, z); - customItem.setItemStackNMS(stack); - if (!addEntityToWorld(nmsWorld, customItem)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return customItem; - } - - @Override - public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramLine parentPiece) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece); - touchSlime.setLocationNMS(x, y, z); - if (!addEntityToWorld(nmsWorld, touchSlime)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return touchSlime; - } - - @Override - public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) { - WorldServer nmsWorld = ((CraftWorld) world).getHandle(); - EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece); - invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket); - if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return invisibleArmorStand; - } - - private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { - Validator.isTrue(Bukkit.isPrimaryThread(), "Async entity add"); - + private Method validateEntityMethod; + + @Override + public void setup() throws Exception { + registerCustomEntity(EntityNMSArmorStand.class, "ArmorStand", 30); + registerCustomEntity(EntityNMSItem.class, "Item", 1); + registerCustomEntity(EntityNMSSlime.class, "Slime", 55); + + validateEntityMethod = World.class.getDeclaredMethod("b", Entity.class); + validateEntityMethod.setAccessible(true); + } + + 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, Integer.valueOf(id)); + } + + @Override + public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager); + customItem.setLocationNMS(x, y, z); + customItem.setItemStackNMS(stack); + if (!addEntityToWorld(nmsWorld, customItem)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return customItem; + } + + @Override + public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramLine parentPiece) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece); + touchSlime.setLocationNMS(x, y, z); + if (!addEntityToWorld(nmsWorld, touchSlime)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return touchSlime; + } + + @Override + public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) { + WorldServer nmsWorld = ((CraftWorld) world).getHandle(); + EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece); + invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket); + if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return invisibleArmorStand; + } + + private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { + Validator.isTrue(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 + // This should never happen nmsEntity.dead = true; return false; } @@ -110,45 +110,45 @@ public class NmsManagerImpl implements NMSManager { nmsWorld.entityList.add(nmsEntity); try { - validateEntityMethod.invoke(nmsWorld, nmsEntity); - } catch (Exception e) { - e.printStackTrace(); - return false; - } + validateEntityMethod.invoke(nmsWorld, nmsEntity); + } catch (Exception e) { + e.printStackTrace(); + return false; + } return true; } - - @Override - public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase; - } + + @Override + public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { + return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase; + } - @Override - public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - - if (nmsEntity instanceof NMSEntityBase) { - return ((NMSEntityBase) nmsEntity); - } else { - return null; - } - } - - @Override - public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - Entity nmsEntity = nmsWorld.getEntity(entityID); - - if (nmsEntity instanceof NMSEntityBase) { - return ((NMSEntityBase) nmsEntity); - } else { - return null; - } - } - - @Override - public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { - return CustomNameHelper.replaceCustomNameString(customNameObject, target, replacement); - } - + @Override + public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { + Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); + + if (nmsEntity instanceof NMSEntityBase) { + return ((NMSEntityBase) nmsEntity); + } else { + return null; + } + } + + @Override + public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + Entity nmsEntity = nmsWorld.getEntity(entityID); + + if (nmsEntity instanceof NMSEntityBase) { + return ((NMSEntityBase) nmsEntity); + } else { + return null; + } + } + + @Override + public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { + return CustomNameHelper.replaceCustomNameString(customNameObject, target, replacement); + } + } 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 index ca03217b..0006ab64 100644 --- 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 @@ -21,105 +21,105 @@ import net.minecraft.server.v1_9_R1.Vec3D; public class NullBoundingBox extends AxisAlignedBB { - public NullBoundingBox() { - super(0, 0, 0, 0, 0, 0); - } + public NullBoundingBox() { + super(0, 0, 0, 0, 0, 0); + } - @Override - public double a() { - return 0.0; - } + @Override + public double a() { + return 0.0; + } - @Override - public double a(AxisAlignedBB arg0, double arg1) { - 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(AxisAlignedBB arg0) { + return this; + } - @Override - public AxisAlignedBB a(double arg0, double arg1, double arg2) { - 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 MovingObjectPosition a(Vec3D arg0, Vec3D arg1) { + return super.a(arg0, arg1); + } - @Override - public boolean a(Vec3D arg0) { - return false; - } + @Override + public boolean a(Vec3D arg0) { + return false; + } - @Override - public double b(AxisAlignedBB arg0, double arg1) { - return 0.0; - } + @Override + public double b(AxisAlignedBB arg0, double arg1) { + return 0.0; + } - @Override - public boolean b(AxisAlignedBB arg0) { - return false; - } + @Override + public boolean b(AxisAlignedBB arg0) { + return false; + } - @Override - public double c(AxisAlignedBB arg0, double arg1) { - return 0.0; - } + @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 c(double arg0, double arg1, double arg2) { + return this; + } - @Override - public AxisAlignedBB grow(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 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 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 b(Vec3D arg0) { + return false; + } - @Override - public boolean c(Vec3D arg0) { - return false; - } + @Override + public boolean c(Vec3D arg0) { + return false; + } - @Override - public boolean d(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 e(double arg0) { + return this; + } + + @Override + public AxisAlignedBB g(double arg0) { + return this; + } - + } diff --git a/nms/v1_9_r2/pom.xml b/nms/v1_9_r2/pom.xml index 50f87c6f..f52b5fbe 100644 --- a/nms/v1_9_r2/pom.xml +++ b/nms/v1_9_r2/pom.xml @@ -1,40 +1,40 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - - me.filoghost.holographicdisplays - holographicdisplays-nms - 3.0.0-SNAPSHOT - + + me.filoghost.holographicdisplays + holographicdisplays-nms + 3.0.0-SNAPSHOT + - holographicdisplays-nms-v1_9_r2 - HolographicDisplays NMS v1_9_R2 + holographicdisplays-nms-v1_9_r2 + HolographicDisplays NMS v1_9_R2 - - - nms-repo - https://repo.codemc.io/repository/nms/ - - + + + nms-repo + https://repo.codemc.io/repository/nms/ + + - - - ${project.groupId} - holographicdisplays-nms-interfaces - + + + ${project.groupId} + holographicdisplays-nms-interfaces + - - ${project.groupId} - holographicdisplays-utils - - - - org.spigotmc - spigot - 1.9.4-R0.1-SNAPSHOT - provided - - - \ No newline at end of file + + ${project.groupId} + holographicdisplays-utils + + + + org.spigotmc + spigot + 1.9.4-R0.1-SNAPSHOT + provided + + + 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 index 8c747652..02bdbd17 100644 --- 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 @@ -29,54 +29,54 @@ 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. - } + 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 Armor stand class - @Override public void setArms(boolean arms) { } - @Override public void setBasePlate(boolean basePlate) { } - @Override public void setBodyPose(EulerAngle pose) { } - @Override public void setBoots(ItemStack item) { } - @Override public void setChestplate(ItemStack item) { } - @Override public void setGravity(boolean gravity) { } - @Override public void setHeadPose(EulerAngle pose) { } - @Override public void setHelmet(ItemStack item) { } - @Override public void setItemInHand(ItemStack item) { } - @Override public void setLeftArmPose(EulerAngle pose) { } - @Override public void setLeftLegPose(EulerAngle pose) { } - @Override public void setLeggings(ItemStack item) { } - @Override public void setRightArmPose(EulerAngle pose) { } - @Override public void setRightLegPose(EulerAngle pose) { } - @Override public void setSmall(boolean small) { } - @Override public void setVisible(boolean visible) { } - @Override public void setMarker(boolean marker) { } + // Methods from Armor stand class + @Override public void setArms(boolean arms) { } + @Override public void setBasePlate(boolean basePlate) { } + @Override public void setBodyPose(EulerAngle pose) { } + @Override public void setBoots(ItemStack item) { } + @Override public void setChestplate(ItemStack item) { } + @Override public void setGravity(boolean gravity) { } + @Override public void setHeadPose(EulerAngle pose) { } + @Override public void setHelmet(ItemStack item) { } + @Override public void setItemInHand(ItemStack item) { } + @Override public void setLeftArmPose(EulerAngle pose) { } + @Override public void setLeftLegPose(EulerAngle pose) { } + @Override public void setLeggings(ItemStack item) { } + @Override public void setRightArmPose(EulerAngle pose) { } + @Override public void setRightLegPose(EulerAngle pose) { } + @Override public void setSmall(boolean small) { } + @Override public void setVisible(boolean visible) { } + @Override public void 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) { } - + // 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) { } + } 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 index de558185..df99eab7 100644 --- 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 @@ -25,33 +25,33 @@ import org.bukkit.util.Vector; public class CraftNMSItem extends CraftItem { - public CraftNMSItem(CraftServer server, EntityNMSItem entity) { - super(server, entity); - } + 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. - } + // 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) { } - - // Methods from Item - @Override public void setItemStack(ItemStack stack) { } - @Override public void setPickupDelay(int delay) { } - + // 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) { } + + // 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 index b7a4824b..591969dc 100644 --- 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 @@ -27,38 +27,38 @@ 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) { } - - // Methods from Slime - @Override public void setSize(int size) { } - + 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) { } + + // 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 index 3b30c86d..33069665 100644 --- 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 @@ -35,208 +35,208 @@ import org.bukkit.craftbukkit.v1_9_R2.entity.CraftEntity; public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand { - private HologramLine parentPiece; - private String customName; - - public EntityNMSArmorStand(World world, HologramLine parentPiece) { - super(world); - super.setInvisible(true); - super.setSmall(true); - super.setArms(false); - super.setGravity(true); - super.setBasePlate(true); - super.setMarker(true); - this.parentPiece = parentPiece; - forceSetBoundingBox(new NullBoundingBox()); - - this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet. - } - - @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 (this.onGround) { - this.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 (this.onGround) { - this.onGround = false; - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT. - } - - @Override - public boolean c(NBTTagCompound nbttagcompound) { - // Do not save NBT. - return false; - } + private HologramLine parentPiece; + private String customName; + + public EntityNMSArmorStand(World world, HologramLine parentPiece) { + super(world); + super.setInvisible(true); + super.setSmall(true); + super.setArms(false); + super.setGravity(true); + super.setBasePlate(true); + super.setMarker(true); + this.parentPiece = parentPiece; + forceSetBoundingBox(new NullBoundingBox()); + + this.onGround = true; // Workaround to force EntityTrackerEntry to send a teleport packet. + } + + @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 (this.onGround) { + this.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 (this.onGround) { + this.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) { - // Locks the custom name. - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Locks the custom name. - } + @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) { + // Locks the custom name. + } + + @Override + public void setCustomNameVisible(boolean visible) { + // Locks the custom name. + } - @Override - public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, ItemStack itemstack, EnumHand enumhand) { - // Prevent stand being equipped - return EnumInteractionResult.PASS; - } + @Override + public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, ItemStack itemstack, EnumHand enumhand) { + // Prevent stand being equipped + return EnumInteractionResult.PASS; + } - @Override - public boolean c(int i, ItemStack item) { - // Prevent stand being equipped - return false; - } + @Override + public boolean c(int i, ItemStack item) { + // Prevent stand being equipped + return false; + } - @Override - public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { - // Prevent stand being equipped - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Do not change it! - } - - 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 name) { - this.customName = Utils.limitLength(name, 300); - super.setCustomName(customName); - super.setCustomNameVisible(customName != null && !customName.isEmpty()); - } - - @Override - public String getCustomNameStringNMS() { - return this.customName; - } - - @Override - public Object getCustomNameObjectNMS() { - return super.getCustomName(); - } - - @Override - public void die() { - // Prevent being killed. - } - - @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, boolean broadcastLocationPacket) { - super.setPosition(x, y, z); - if (broadcastLocationPacket) { - broadcastLocationPacketNMS(); - } - } - - private void broadcastLocationPacketNMS() { - PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); - - for (Object obj : super.world.players) { - if (obj instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) obj; + @Override + public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { + // Prevent stand being equipped + } + + @Override + public void a(AxisAlignedBB boundingBox) { + // Do not change it! + } + + 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 name) { + this.customName = Utils.limitLength(name, 300); + super.setCustomName(customName); + super.setCustomNameVisible(customName != null && !customName.isEmpty()); + } + + @Override + public String getCustomNameStringNMS() { + return this.customName; + } + + @Override + public Object getCustomNameObjectNMS() { + return super.getCustomName(); + } + + @Override + public void die() { + // Prevent being killed. + } + + @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, boolean broadcastLocationPacket) { + super.setPosition(x, y, z); + if (broadcastLocationPacket) { + broadcastLocationPacketNMS(); + } + } + + private void broadcastLocationPacketNMS() { + PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); + + for (Object obj : super.world.players) { + if (obj instanceof EntityPlayer) { + EntityPlayer nmsPlayer = (EntityPlayer) obj; - double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ); - if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(teleportPacket); - } - } - } - } + double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ); + if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) { + nmsPlayer.playerConnection.sendPacket(teleportPacket); + } + } + } + } - @Override - public boolean isDeadNMS() { - return super.dead; - } - - @Override - public int getIdNMS() { - return super.getId(); - } + @Override + public boolean isDeadNMS() { + return super.dead; + } + + @Override + public int getIdNMS() { + return super.getId(); + } - @Override - public HologramLine getHologramLine() { - return parentPiece; - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } + @Override + public HologramLine getHologramLine() { + return parentPiece; + } + + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } } 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 index a35e1158..baf384f8 100644 --- 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 @@ -41,230 +41,230 @@ import org.bukkit.entity.Player; import java.util.logging.Level; public class EntityNMSItem extends EntityItem implements NMSItem { - - private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "at"); - - private ItemLine parentPiece; - private ItemPickupManager itemPickupManager; - - private int resendMountPacketTicks; - - public EntityNMSItem(World world, ItemLine piece, ItemPickupManager itemPickupManager) { - super(world); - super.pickupDelay = Integer.MAX_VALUE; - this.parentPiece = piece; - this.itemPickupManager = itemPickupManager; - } - - @Override - public void m() { - // Disable normal ticking for this entity. - - // So it won't get removed. - ticksLived = 0; - - if (resendMountPacketTicks++ > 20) { - resendMountPacketTicks = 0; - - if (bz() != null) { - // Send a packet near to "remind" players that the item is riding the armor stand (Spigot bug or client bug) - PacketPlayOutMount mountPacket = new PacketPlayOutMount(bz()); - - for (Object obj : super.world.players) { - if (obj instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) obj; - - double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ); - if (distanceSquared < 1024 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(mountPacket); - } - } - } - } - } - } - - @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 (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) { - itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent()); - // 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; - } + + private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "at"); + + private ItemLine parentPiece; + private ItemPickupManager itemPickupManager; + + private int resendMountPacketTicks; + + public EntityNMSItem(World world, ItemLine piece, ItemPickupManager itemPickupManager) { + super(world); + super.pickupDelay = Integer.MAX_VALUE; + this.parentPiece = piece; + this.itemPickupManager = itemPickupManager; + } + + @Override + public void m() { + // Disable normal ticking for this entity. + + // So it won't get removed. + ticksLived = 0; + + if (resendMountPacketTicks++ > 20) { + resendMountPacketTicks = 0; + + if (bz() != null) { + // Send a packet near to "remind" players that the item is riding the armor stand (Spigot bug or client bug) + PacketPlayOutMount mountPacket = new PacketPlayOutMount(bz()); + + for (Object obj : super.world.players) { + if (obj instanceof EntityPlayer) { + EntityPlayer nmsPlayer = (EntityPlayer) obj; + + double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ); + if (distanceSquared < 1024 && nmsPlayer.playerConnection != null) { + nmsPlayer.playerConnection.sendPacket(mountPacket); + } + } + } + } + } + } + + @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 (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) { + itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent()); + // 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 being killed. - } - - @Override - public boolean isAlive() { - // This override prevents items from being picked up by hoppers. - // Should have no side effects. - 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 being killed. + } + + @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 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 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(ItemUtils.ANTISTACK_LORE)); // Antistack lore - display.set("Lore", tagList); - - setItemStack(newItem); - } - - @Override - public int getIdNMS() { - return super.getId(); - } - - @Override - public ItemLine getHologramLine() { - return parentPiece; - } - - @Override - public void allowPickup(boolean pickup) { - if (pickup) { - super.pickupDelay = 0; - } else { - super.pickupDelay = Integer.MAX_VALUE; - } - } - - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public void setPassengerOfNMS(NMSEntityBase vehicleBase) { - if (vehicleBase == null || !(vehicleBase instanceof Entity)) { - // It should never dismount - return; - } - - Entity entity = (Entity) vehicleBase; + @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(ItemUtils.ANTISTACK_LORE)); // Antistack lore + display.set("Lore", tagList); + + setItemStack(newItem); + } + + @Override + public int getIdNMS() { + return super.getId(); + } + + @Override + public ItemLine getHologramLine() { + return parentPiece; + } + + @Override + public void allowPickup(boolean pickup) { + if (pickup) { + super.pickupDelay = 0; + } else { + super.pickupDelay = Integer.MAX_VALUE; + } + } + + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } + + @Override + public void setPassengerOfNMS(NMSEntityBase vehicleBase) { + if (vehicleBase == null || !(vehicleBase instanceof Entity)) { + // It should never dismount + return; + } + + Entity entity = (Entity) vehicleBase; - try { - if (super.bz() != null) { - Entity oldVehicle = super.bz(); - VEHICLE_FIELD.set(this, null); - oldVehicle.passengers.remove(this); - } + try { + if (super.bz() != null) { + Entity oldVehicle = super.bz(); + VEHICLE_FIELD.set(this, null); + oldVehicle.passengers.remove(this); + } - VEHICLE_FIELD.set(this, entity); - entity.passengers.clear(); - entity.passengers.add(this); + VEHICLE_FIELD.set(this, entity); + entity.passengers.clear(); + entity.passengers.add(this); - } catch (Throwable t) { - ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); - } - } + } catch (Throwable t) { + ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); + } + } - @Override - public Object getRawItemStack() { - return super.getItemStack(); - } + @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 index 78b767af..93cabfca 100644 --- 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 @@ -37,207 +37,207 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import java.util.logging.Level; public class EntityNMSSlime extends EntitySlime implements NMSSlime { - - private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "at"); + + private static final ReflectField VEHICLE_FIELD = new ReflectField<>(Entity.class, "at"); - private HologramLine parentPiece; - - private int resendMountPacketTicks; - - public EntityNMSSlime(World world, HologramLine parentPiece) { - super(world); - super.persistent = true; - a(0.0F, 0.0F); - setSize(1); - setInvisible(true); - this.parentPiece = parentPiece; - 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; + private HologramLine parentPiece; + + private int resendMountPacketTicks; + + public EntityNMSSlime(World world, HologramLine parentPiece) { + super(world); + super.persistent = true; + a(0.0F, 0.0F); + setSize(1); + setInvisible(true); + this.parentPiece = parentPiece; + 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; - if (bz() != null) { - // Send a packet near to "remind" players that the slime is riding the armor stand (Spigot bug or client bug) - PacketPlayOutMount mountPacket = new PacketPlayOutMount(bz()); - - for (Object obj : super.world.players) { - if (obj instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) obj; - - double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ); - if (distanceSquared < 1024 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(mountPacket); - } - } - } - } - } - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity. - - // So it won't get removed. - ticksLived = 0; - } - - @Override - public void a(AxisAlignedBB boundingBox) { - // Do not change it! - } - - 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; - } + if (bz() != null) { + // Send a packet near to "remind" players that the slime is riding the armor stand (Spigot bug or client bug) + PacketPlayOutMount mountPacket = new PacketPlayOutMount(bz()); + + for (Object obj : super.world.players) { + if (obj instanceof EntityPlayer) { + EntityPlayer nmsPlayer = (EntityPlayer) obj; + + double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ); + if (distanceSquared < 1024 && nmsPlayer.playerConnection != null) { + nmsPlayer.playerConnection.sendPacket(mountPacket); + } + } + } + } + } + } + + @Override + public void inactiveTick() { + // Disable normal ticking for this entity. + + // So it won't get removed. + ticksLived = 0; + } + + @Override + public void a(AxisAlignedBB boundingBox) { + // Do not change it! + } + + 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) { - Bukkit.getPluginManager().callEvent(new PlayerInteractEntityEvent(((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(), getBukkitEntity())); // 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 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) { + Bukkit.getPluginManager().callEvent(new PlayerInteractEntityEvent(((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(), getBukkitEntity())); // 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) { - // Locks the custom name. - } - - @Override - public void setCustomNameVisible(boolean visible) { - // Locks the custom name. - } - - @Override - public void a(SoundEffect soundeffect, float f, float f1) { - // Remove sounds. - } - - @Override - public void die() { - // Prevent being killed. - } - - @Override - public CraftEntity getBukkitEntity() { - if (super.bukkitEntity == null) { - super.bukkitEntity = new CraftNMSSlime(super.world.getServer(), this); - } - return super.bukkitEntity; - } + @Override + public void setCustomName(String customName) { + // Locks the custom name. + } + + @Override + public void setCustomNameVisible(boolean visible) { + // Locks the custom name. + } + + @Override + public void a(SoundEffect soundeffect, float f, float f1) { + // Remove sounds. + } + + @Override + public void die() { + // Prevent being killed. + } + + @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 HologramLine getHologramLine() { - return parentPiece; - } + @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 HologramLine getHologramLine() { + return parentPiece; + } - @Override - public org.bukkit.entity.Entity getBukkitEntityNMS() { - return getBukkitEntity(); - } - - @Override - public void setPassengerOfNMS(NMSEntityBase vehicleBase) { - if (vehicleBase == null || !(vehicleBase instanceof Entity)) { - // It should never dismount - return; - } - - Entity entity = (Entity) vehicleBase; - - try { - if (super.bz() != null) { - Entity oldVehicle = super.bz(); - VEHICLE_FIELD.set(this, null); - oldVehicle.passengers.remove(this); - } + @Override + public org.bukkit.entity.Entity getBukkitEntityNMS() { + return getBukkitEntity(); + } + + @Override + public void setPassengerOfNMS(NMSEntityBase vehicleBase) { + if (vehicleBase == null || !(vehicleBase instanceof Entity)) { + // It should never dismount + return; + } + + Entity entity = (Entity) vehicleBase; + + try { + if (super.bz() != null) { + Entity oldVehicle = super.bz(); + VEHICLE_FIELD.set(this, null); + oldVehicle.passengers.remove(this); + } - VEHICLE_FIELD.set(this, entity); - entity.passengers.clear(); - entity.passengers.add(this); + VEHICLE_FIELD.set(this, entity); + entity.passengers.clear(); + entity.passengers.add(this); - } catch (Throwable t) { - ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); - } - } + } catch (Throwable t) { + ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set passenger", t); + } + } } diff --git a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/NmsManagerImpl.java b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/NmsManagerImpl.java index 33064cc4..d4c90c48 100644 --- a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/NmsManagerImpl.java +++ b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/NmsManagerImpl.java @@ -40,68 +40,68 @@ import java.util.Map; public class NmsManagerImpl implements NMSManager { - private static final ReflectField, String>> ENTITY_NAMES_BY_CLASS_FIELD = new ReflectField<>(EntityTypes.class, "d"); - private static final ReflectField, Integer>> ENTITY_IDS_BY_CLASS_FIELD = new ReflectField<>(EntityTypes.class, "f"); - - private Method validateEntityMethod; - - @Override - public void setup() throws Exception { - registerCustomEntity(EntityNMSArmorStand.class, "ArmorStand", 30); - registerCustomEntity(EntityNMSItem.class, "Item", 1); - registerCustomEntity(EntityNMSSlime.class, "Slime", 55); - - validateEntityMethod = World.class.getDeclaredMethod("b", Entity.class); - validateEntityMethod.setAccessible(true); - } - - 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, Integer.valueOf(id)); - } - - @Override - public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager); - customItem.setLocationNMS(x, y, z); - customItem.setItemStackNMS(stack); - if (!addEntityToWorld(nmsWorld, customItem)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return customItem; - } - - @Override - public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramLine parentPiece) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece); - touchSlime.setLocationNMS(x, y, z); - if (!addEntityToWorld(nmsWorld, touchSlime)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return touchSlime; - } - - @Override - public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) { - WorldServer nmsWorld = ((CraftWorld) world).getHandle(); - EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece); - invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket); - if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) { - ConsoleLogger.handleSpawnFail(parentPiece); - } - return invisibleArmorStand; - } - - private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { - Validator.isTrue(Bukkit.isPrimaryThread(), "Async entity add"); - + private static final ReflectField, String>> ENTITY_NAMES_BY_CLASS_FIELD = new ReflectField<>(EntityTypes.class, "d"); + private static final ReflectField, Integer>> ENTITY_IDS_BY_CLASS_FIELD = new ReflectField<>(EntityTypes.class, "f"); + + private Method validateEntityMethod; + + @Override + public void setup() throws Exception { + registerCustomEntity(EntityNMSArmorStand.class, "ArmorStand", 30); + registerCustomEntity(EntityNMSItem.class, "Item", 1); + registerCustomEntity(EntityNMSSlime.class, "Slime", 55); + + validateEntityMethod = World.class.getDeclaredMethod("b", Entity.class); + validateEntityMethod.setAccessible(true); + } + + 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, Integer.valueOf(id)); + } + + @Override + public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager); + customItem.setLocationNMS(x, y, z); + customItem.setItemStackNMS(stack); + if (!addEntityToWorld(nmsWorld, customItem)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return customItem; + } + + @Override + public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramLine parentPiece) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece); + touchSlime.setLocationNMS(x, y, z); + if (!addEntityToWorld(nmsWorld, touchSlime)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return touchSlime; + } + + @Override + public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece, boolean broadcastLocationPacket) { + WorldServer nmsWorld = ((CraftWorld) world).getHandle(); + EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece); + invisibleArmorStand.setLocationNMS(x, y, z, broadcastLocationPacket); + if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) { + ConsoleLogger.handleSpawnFail(parentPiece); + } + return invisibleArmorStand; + } + + private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { + Validator.isTrue(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 + // This should never happen nmsEntity.dead = true; return false; } @@ -110,45 +110,45 @@ public class NmsManagerImpl implements NMSManager { nmsWorld.entityList.add(nmsEntity); try { - validateEntityMethod.invoke(nmsWorld, nmsEntity); - } catch (Exception e) { - e.printStackTrace(); - return false; - } + validateEntityMethod.invoke(nmsWorld, nmsEntity); + } catch (Exception e) { + e.printStackTrace(); + return false; + } return true; } - - @Override - public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase; - } + + @Override + public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { + return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase; + } - @Override - public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { - Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - - if (nmsEntity instanceof NMSEntityBase) { - return ((NMSEntityBase) nmsEntity); - } else { - return null; - } - } - - @Override - public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { - WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); - Entity nmsEntity = nmsWorld.getEntity(entityID); - - if (nmsEntity instanceof NMSEntityBase) { - return ((NMSEntityBase) nmsEntity); - } else { - return null; - } - } - - @Override - public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { - return CustomNameHelper.replaceCustomNameString(customNameObject, target, replacement); - } - + @Override + public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) { + Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); + + if (nmsEntity instanceof NMSEntityBase) { + return ((NMSEntityBase) nmsEntity); + } else { + return null; + } + } + + @Override + public NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID) { + WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle(); + Entity nmsEntity = nmsWorld.getEntity(entityID); + + if (nmsEntity instanceof NMSEntityBase) { + return ((NMSEntityBase) nmsEntity); + } else { + return null; + } + } + + @Override + public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { + return CustomNameHelper.replaceCustomNameString(customNameObject, target, replacement); + } + } 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 index 3fac00e1..d85e75aa 100644 --- 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 @@ -21,105 +21,105 @@ import net.minecraft.server.v1_9_R2.Vec3D; public class NullBoundingBox extends AxisAlignedBB { - public NullBoundingBox() { - super(0, 0, 0, 0, 0, 0); - } + public NullBoundingBox() { + super(0, 0, 0, 0, 0, 0); + } - @Override - public double a() { - return 0.0; - } + @Override + public double a() { + return 0.0; + } - @Override - public double a(AxisAlignedBB arg0, double arg1) { - 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(AxisAlignedBB arg0) { + return this; + } - @Override - public AxisAlignedBB a(double arg0, double arg1, double arg2) { - 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 MovingObjectPosition a(Vec3D arg0, Vec3D arg1) { + return super.a(arg0, arg1); + } - @Override - public boolean a(Vec3D arg0) { - return false; - } + @Override + public boolean a(Vec3D arg0) { + return false; + } - @Override - public double b(AxisAlignedBB arg0, double arg1) { - return 0.0; - } + @Override + public double b(AxisAlignedBB arg0, double arg1) { + return 0.0; + } - @Override - public boolean b(AxisAlignedBB arg0) { - return false; - } + @Override + public boolean b(AxisAlignedBB arg0) { + return false; + } - @Override - public double c(AxisAlignedBB arg0, double arg1) { - return 0.0; - } + @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 c(double arg0, double arg1, double arg2) { + return this; + } - @Override - public AxisAlignedBB grow(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 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 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 b(Vec3D arg0) { + return false; + } - @Override - public boolean c(Vec3D arg0) { - return false; - } + @Override + public boolean c(Vec3D arg0) { + return false; + } - @Override - public boolean d(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 e(double arg0) { + return this; + } + + @Override + public AxisAlignedBB g(double arg0) { + return this; + } - + } diff --git a/plugin/pom.xml b/plugin/pom.xml index 3eab4927..25a99ca5 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -1,258 +1,258 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - - me.filoghost.holographicdisplays - holographicdisplays-parent - 3.0.0-SNAPSHOT - + + me.filoghost.holographicdisplays + holographicdisplays-parent + 3.0.0-SNAPSHOT + - holographicdisplays-plugin - HolographicDisplays Plugin + holographicdisplays-plugin + HolographicDisplays Plugin - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + - - dmulloy2-repo - https://repo.dmulloy2.net/nexus/repository/public/ - - - - codemc-repo - https://repo.codemc.io/repository/maven-public/ - - + + dmulloy2-repo + https://repo.dmulloy2.net/nexus/repository/public/ + + + + codemc-repo + https://repo.codemc.io/repository/maven-public/ + + - - - ${project.groupId} - holographicdisplays-api - + + + ${project.groupId} + holographicdisplays-api + - - ${project.groupId} - holographicdisplays-utils - + + ${project.groupId} + holographicdisplays-utils + - - ${project.groupId} - holographicdisplays-legacy-v1 - runtime - + + ${project.groupId} + holographicdisplays-legacy-v1 + runtime + - - ${project.groupId} - holographicdisplays-legacy-v2 - runtime - - - - ${project.groupId} - holographicdisplays-config - + + ${project.groupId} + holographicdisplays-legacy-v2 + runtime + + + + ${project.groupId} + holographicdisplays-config + - - ${project.groupId} - holographicdisplays-nms-interfaces - - - - ${project.groupId} - holographicdisplays-nms-v1_8_r2 - - - - ${project.groupId} - holographicdisplays-nms-v1_8_r3 - - - - ${project.groupId} - holographicdisplays-nms-v1_9_r1 - - - - ${project.groupId} - holographicdisplays-nms-v1_9_r2 - - - - ${project.groupId} - holographicdisplays-nms-v1_10_r1 - - - - ${project.groupId} - holographicdisplays-nms-v1_11_r1 - - - - ${project.groupId} - holographicdisplays-nms-v1_12_r1 - - - - ${project.groupId} - holographicdisplays-nms-v1_13_r1 - - - - ${project.groupId} - holographicdisplays-nms-v1_13_r2 - - - - ${project.groupId} - holographicdisplays-nms-v1_14_r1 - + + ${project.groupId} + holographicdisplays-nms-interfaces + + + + ${project.groupId} + holographicdisplays-nms-v1_8_r2 + + + + ${project.groupId} + holographicdisplays-nms-v1_8_r3 + + + + ${project.groupId} + holographicdisplays-nms-v1_9_r1 + + + + ${project.groupId} + holographicdisplays-nms-v1_9_r2 + + + + ${project.groupId} + holographicdisplays-nms-v1_10_r1 + + + + ${project.groupId} + holographicdisplays-nms-v1_11_r1 + + + + ${project.groupId} + holographicdisplays-nms-v1_12_r1 + + + + ${project.groupId} + holographicdisplays-nms-v1_13_r1 + + + + ${project.groupId} + holographicdisplays-nms-v1_13_r2 + + + + ${project.groupId} + holographicdisplays-nms-v1_14_r1 + - - ${project.groupId} - holographicdisplays-nms-v1_15_r1 - + + ${project.groupId} + holographicdisplays-nms-v1_15_r1 + - - ${project.groupId} - holographicdisplays-nms-v1_16_r1 - + + ${project.groupId} + holographicdisplays-nms-v1_16_r1 + - - ${project.groupId} - holographicdisplays-nms-v1_16_r2 - + + ${project.groupId} + holographicdisplays-nms-v1_16_r2 + - - ${project.groupId} - holographicdisplays-nms-v1_16_r3 - + + ${project.groupId} + holographicdisplays-nms-v1_16_r3 + - - org.spigotmc - spigot-api - + + org.spigotmc + spigot-api + - - com.comphenix.protocol - ProtocolLib - + + com.comphenix.protocol + ProtocolLib + - - org.bstats - bstats-bukkit-lite - - - - me.filoghost.updatechecker - updatechecker - - + + org.bstats + bstats-bukkit-lite + + + + me.filoghost.updatechecker + updatechecker + + - - - - src/main/resources - true - - - .. - - LICENSE.txt - THIRD-PARTY.txt - - - - - - - org.apache.maven.plugins - maven-antrun-plugin - - - - set-plugin-version - validate - - run - - - true - - - - - - - - - - - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - - true - - - ${project.pluginVersion} - - - - - - - org.apache.maven.plugins - maven-shade-plugin - - false - false - - - ${project.groupId}:* - org.bstats - me.filoghost.updatechecker - - - - - *:* - - META-INF/maven/ - - - - - - org.bstats - me.filoghost.holographicdisplays.metrics - - - me.filoghost.updatechecker - me.filoghost.holographicdisplays.updater - - - - - - package - - shade - - - - - - + + + + src/main/resources + true + + + .. + + LICENSE.txt + THIRD-PARTY.txt + + + + + + + org.apache.maven.plugins + maven-antrun-plugin + + + + set-plugin-version + validate + + run + + + true + + + + + + + + + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + true + + + ${project.pluginVersion} + + + + + + + org.apache.maven.plugins + maven-shade-plugin + + false + false + + + ${project.groupId}:* + org.bstats + me.filoghost.updatechecker + + + + + *:* + + META-INF/maven/ + + + + + + org.bstats + me.filoghost.holographicdisplays.metrics + + + me.filoghost.updatechecker + me.filoghost.holographicdisplays.updater + + + + + + package + + shade + + + + + + diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/HolographicDisplays.java b/plugin/src/main/java/me/filoghost/holographicdisplays/HolographicDisplays.java index 1d168d22..62cad595 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/HolographicDisplays.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/HolographicDisplays.java @@ -49,229 +49,229 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; public class HolographicDisplays extends JavaPlugin { - - // The main instance of the plugin. - private static HolographicDisplays instance; - - // The manager for net.minecraft.server access. - private static NMSManager nmsManager; - - // The listener for all the Bukkit and NMS events. - private static MainListener mainListener; - - // The command handler, just in case a plugin wants to register more commands. - private static HologramsCommandHandler commandHandler; - - // The new version found by the updater, null if there is no new version. - private static String newVersion; - - // Not null if ProtocolLib is installed and successfully loaded. - private static ProtocolLibHook protocolLibHook; - - @Override - public void onEnable() { - - // Warn about plugin reloaders and the /reload command. - if (instance != null || System.getProperty("HolographicDisplaysLoaded") != null) { - Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[HolographicDisplays] Please do not use /reload or plugin reloaders. Use the command \"/holograms reload\" instead. You will receive no support for doing this operation."); - } - - System.setProperty("HolographicDisplaysLoaded", "true"); - instance = this; - ConsoleLogger.setLogger(instance.getLogger()); - - // Load placeholders.yml. - UnicodeSymbols.load(this); + + // The main instance of the plugin. + private static HolographicDisplays instance; + + // The manager for net.minecraft.server access. + private static NMSManager nmsManager; + + // The listener for all the Bukkit and NMS events. + private static MainListener mainListener; + + // The command handler, just in case a plugin wants to register more commands. + private static HologramsCommandHandler commandHandler; + + // The new version found by the updater, null if there is no new version. + private static String newVersion; + + // Not null if ProtocolLib is installed and successfully loaded. + private static ProtocolLibHook protocolLibHook; + + @Override + public void onEnable() { + + // Warn about plugin reloaders and the /reload command. + if (instance != null || System.getProperty("HolographicDisplaysLoaded") != null) { + Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[HolographicDisplays] Please do not use /reload or plugin reloaders. Use the command \"/holograms reload\" instead. You will receive no support for doing this operation."); + } + + System.setProperty("HolographicDisplaysLoaded", "true"); + instance = this; + ConsoleLogger.setLogger(instance.getLogger()); + + // Load placeholders.yml. + UnicodeSymbols.load(this); - // Load the configuration. - Configuration.load(this); - - if (Configuration.updateNotification) { - UpdateChecker.run(this, 75097, (String newVersion) -> { - HolographicDisplays.newVersion = newVersion; - ConsoleLogger.log(Level.INFO, "Found a new version available: " + newVersion); - ConsoleLogger.log(Level.INFO, "Download it on Bukkit Dev:"); - ConsoleLogger.log(Level.INFO, "dev.bukkit.org/projects/holographic-displays"); - }); - } - - // The bungee chat API is required. - try { - Class.forName("net.md_5.bungee.api.chat.ComponentBuilder"); - } catch (ClassNotFoundException e) { - criticalShutdown( - "Holographic Displays requires the new chat API.", - "You are probably running CraftBukkit instead of Spigot."); - return; - } - - if (!NMSVersion.isValid()) { - criticalShutdown( - "Holographic Displays does not support this server version.", - "Supported Spigot versions: from 1.8.3 to 1.16.4."); - return; - } - - try { - nmsManager = (NMSManager) Class.forName("me.filoghost.holographicdisplays.nms." + NMSVersion.getCurrent() + ".NmsManagerImpl").getConstructor().newInstance(); - } catch (Throwable t) { - t.printStackTrace(); - criticalShutdown( - "Holographic Displays was unable to initialize the NMS manager."); - return; - } + // Load the configuration. + Configuration.load(this); + + if (Configuration.updateNotification) { + UpdateChecker.run(this, 75097, (String newVersion) -> { + HolographicDisplays.newVersion = newVersion; + ConsoleLogger.log(Level.INFO, "Found a new version available: " + newVersion); + ConsoleLogger.log(Level.INFO, "Download it on Bukkit Dev:"); + ConsoleLogger.log(Level.INFO, "dev.bukkit.org/projects/holographic-displays"); + }); + } + + // The bungee chat API is required. + try { + Class.forName("net.md_5.bungee.api.chat.ComponentBuilder"); + } catch (ClassNotFoundException e) { + criticalShutdown( + "Holographic Displays requires the new chat API.", + "You are probably running CraftBukkit instead of Spigot."); + return; + } + + if (!NMSVersion.isValid()) { + criticalShutdown( + "Holographic Displays does not support this server version.", + "Supported Spigot versions: from 1.8.3 to 1.16.4."); + return; + } + + try { + nmsManager = (NMSManager) Class.forName("me.filoghost.holographicdisplays.nms." + NMSVersion.getCurrent() + ".NmsManagerImpl").getConstructor().newInstance(); + } catch (Throwable t) { + t.printStackTrace(); + criticalShutdown( + "Holographic Displays was unable to initialize the NMS manager."); + return; + } - try { - nmsManager.setup(); - } catch (Exception e) { - e.printStackTrace(); - criticalShutdown( - "Holographic Displays was unable to register custom entities."); - return; - } - - // ProtocolLib check. - hookProtocolLib(); - - // Load animation files and the placeholder manager. - PlaceholdersManager.load(this); - try { - AnimationsRegister.loadAnimations(this); - } catch (Exception ex) { - ConsoleLogger.log(Level.WARNING, "Failed to load animation files!", ex); - } - - // Initalize other static classes. - HologramDatabase.loadYamlFile(this); - BungeeServerTracker.startTask(Configuration.bungeeRefreshSeconds); - - // Start repeating tasks. - Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new BungeeCleanupTask(), 5 * 60 * 20, 5 * 60 * 20); - Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new WorldPlayerCounterTask(), 0L, 3 * 20); - - if (getCommand("holograms") == null) { - criticalShutdown( - "Holographic Displays was unable to register the command \"holograms\".", - "This can be caused by edits to plugin.yml or other plugins."); - return; - } - - getCommand("holograms").setExecutor(commandHandler = new HologramsCommandHandler()); - Bukkit.getPluginManager().registerEvents(mainListener = new MainListener(nmsManager), this); + try { + nmsManager.setup(); + } catch (Exception e) { + e.printStackTrace(); + criticalShutdown( + "Holographic Displays was unable to register custom entities."); + return; + } + + // ProtocolLib check. + hookProtocolLib(); + + // Load animation files and the placeholder manager. + PlaceholdersManager.load(this); + try { + AnimationsRegister.loadAnimations(this); + } catch (Exception ex) { + ConsoleLogger.log(Level.WARNING, "Failed to load animation files!", ex); + } + + // Initalize other static classes. + HologramDatabase.loadYamlFile(this); + BungeeServerTracker.startTask(Configuration.bungeeRefreshSeconds); + + // Start repeating tasks. + Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new BungeeCleanupTask(), 5 * 60 * 20, 5 * 60 * 20); + Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new WorldPlayerCounterTask(), 0L, 3 * 20); + + if (getCommand("holograms") == null) { + criticalShutdown( + "Holographic Displays was unable to register the command \"holograms\".", + "This can be caused by edits to plugin.yml or other plugins."); + return; + } + + getCommand("holograms").setExecutor(commandHandler = new HologramsCommandHandler()); + Bukkit.getPluginManager().registerEvents(mainListener = new MainListener(nmsManager), this); - // Register bStats metrics - int pluginID = 3123; - new MetricsLite(this, pluginID); - - // Holograms are loaded later, when the worlds are ready. - Bukkit.getScheduler().runTask(this, new StartupLoadHologramsTask()); - - // Enable the API. - BackendAPI.setImplementation(new DefaultBackendAPI()); - } - + // Register bStats metrics + int pluginID = 3123; + new MetricsLite(this, pluginID); + + // Holograms are loaded later, when the worlds are ready. + Bukkit.getScheduler().runTask(this, new StartupLoadHologramsTask()); + + // Enable the API. + BackendAPI.setImplementation(new DefaultBackendAPI()); + } + - @Override - public void onDisable() { - for (NamedHologram hologram : NamedHologramManager.getHolograms()) { - hologram.despawnEntities(); - } - for (PluginHologram hologram : PluginHologramManager.getHolograms()) { - hologram.despawnEntities(); - } - } - - public static NMSManager getNMSManager() { - return nmsManager; - } - - public static MainListener getMainListener() { - return mainListener; - } + @Override + public void onDisable() { + for (NamedHologram hologram : NamedHologramManager.getHolograms()) { + hologram.despawnEntities(); + } + for (PluginHologram hologram : PluginHologramManager.getHolograms()) { + hologram.despawnEntities(); + } + } + + public static NMSManager getNMSManager() { + return nmsManager; + } + + public static MainListener getMainListener() { + return mainListener; + } - public static HologramsCommandHandler getCommandHandler() { - return commandHandler; - } - - private static void criticalShutdown(String... errorMessage) { - String separator = "****************************************************************************"; - StringBuffer output = new StringBuffer("\n "); - output.append("\n" + separator); - for (String line : errorMessage) { - output.append("\n " + line); - } - output.append("\n "); - output.append("\n This plugin has been disabled."); - output.append("\n" + separator); - output.append("\n "); - - System.out.println(output); - - try { - Thread.sleep(5000); - } catch (InterruptedException ex) { } - instance.setEnabled(false); - } + public static HologramsCommandHandler getCommandHandler() { + return commandHandler; + } + + private static void criticalShutdown(String... errorMessage) { + String separator = "****************************************************************************"; + StringBuffer output = new StringBuffer("\n "); + output.append("\n" + separator); + for (String line : errorMessage) { + output.append("\n " + line); + } + output.append("\n "); + output.append("\n This plugin has been disabled."); + output.append("\n" + separator); + output.append("\n "); + + System.out.println(output); + + try { + Thread.sleep(5000); + } catch (InterruptedException ex) { } + instance.setEnabled(false); + } - public static HolographicDisplays getInstance() { - return instance; - } + public static HolographicDisplays getInstance() { + return instance; + } - public static String getNewVersion() { - return newVersion; - } - - - public void hookProtocolLib() { - if (!Bukkit.getPluginManager().isPluginEnabled("ProtocolLib")) { - return; - } + public static String getNewVersion() { + return newVersion; + } + + + public void hookProtocolLib() { + 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("could not find version numbers pattern"); - } - - String versionNumbers = versionNumbersMatcher.group(); - - if (!VersionUtils.isVersionGreaterEqual(versionNumbers, "4.1")) { - Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[Holographic Displays] Detected old version of ProtocolLib, support disabled. You must use ProtocolLib 4.1 or higher."); - return; - } - - } catch (Exception e) { - ConsoleLogger.log(Level.WARNING, "Could not detect ProtocolLib version (" + e.getClass().getName() + ": " + e.getMessage() + "), enabling support anyway and hoping for the best. If you get errors, please contact the author."); - } - - try { - ProtocolLibHook protocolLibHook = new ProtocolLibHookImpl(); - - if (protocolLibHook.hook(this, nmsManager)) { - HolographicDisplays.protocolLibHook = protocolLibHook; - ConsoleLogger.log(Level.INFO, "Enabled player relative placeholders with ProtocolLib."); - } - } catch (Exception e) { - ConsoleLogger.log(Level.WARNING, "Failed to load ProtocolLib support. Is it updated?", e); - } - } - - - public static boolean hasProtocolLibHook() { - return protocolLibHook != null; - } - - - public static ProtocolLibHook getProtocolLibHook() { - return protocolLibHook; - } - - - public static boolean isConfigFile(File file) { - return file.getName().toLowerCase().endsWith(".yml") && instance.getResource(file.getName()) != null; - } - + try { + String protocolVersion = Bukkit.getPluginManager().getPlugin("ProtocolLib").getDescription().getVersion(); + Matcher versionNumbersMatcher = Pattern.compile("([0-9\\.])+").matcher(protocolVersion); + + if (!versionNumbersMatcher.find()) { + throw new IllegalArgumentException("could not find version numbers pattern"); + } + + String versionNumbers = versionNumbersMatcher.group(); + + if (!VersionUtils.isVersionGreaterEqual(versionNumbers, "4.1")) { + Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[Holographic Displays] Detected old version of ProtocolLib, support disabled. You must use ProtocolLib 4.1 or higher."); + return; + } + + } catch (Exception e) { + ConsoleLogger.log(Level.WARNING, "Could not detect ProtocolLib version (" + e.getClass().getName() + ": " + e.getMessage() + "), enabling support anyway and hoping for the best. If you get errors, please contact the author."); + } + + try { + ProtocolLibHook protocolLibHook = new ProtocolLibHookImpl(); + + if (protocolLibHook.hook(this, nmsManager)) { + HolographicDisplays.protocolLibHook = protocolLibHook; + ConsoleLogger.log(Level.INFO, "Enabled player relative placeholders with ProtocolLib."); + } + } catch (Exception e) { + ConsoleLogger.log(Level.WARNING, "Failed to load ProtocolLib support. Is it updated?", e); + } + } + + + public static boolean hasProtocolLibHook() { + return protocolLibHook != null; + } + + + public static ProtocolLibHook getProtocolLibHook() { + return protocolLibHook; + } + + + public static boolean isConfigFile(File file) { + return file.getName().toLowerCase().endsWith(".yml") && instance.getResource(file.getName()) != null; + } + } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/bungeecord/BungeeChannel.java b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/bungeecord/BungeeChannel.java index 100caa7d..b0b29456 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/bungeecord/BungeeChannel.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/bungeecord/BungeeChannel.java @@ -32,79 +32,79 @@ import java.util.Collection; import java.util.logging.Level; public class BungeeChannel implements PluginMessageListener { - - private static final String BUNGEECORD_CHANNEL = "BungeeCord"; - private static final String REDISBUNGEE_CHANNEL = "legacy:redisbungee"; + + private static final String BUNGEECORD_CHANNEL = "BungeeCord"; + private static final String REDISBUNGEE_CHANNEL = "legacy:redisbungee"; - private static BungeeChannel instance; + private static BungeeChannel instance; - public static BungeeChannel getInstance() { - if (instance == null) { - instance = new BungeeChannel(HolographicDisplays.getInstance()); - } - return instance; - } + public static BungeeChannel getInstance() { + if (instance == null) { + instance = new BungeeChannel(HolographicDisplays.getInstance()); + } + return instance; + } - private BungeeChannel(Plugin plugin) { - Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, BUNGEECORD_CHANNEL); - Bukkit.getMessenger().registerIncomingPluginChannel(plugin, BUNGEECORD_CHANNEL, this); + private BungeeChannel(Plugin plugin) { + Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, BUNGEECORD_CHANNEL); + Bukkit.getMessenger().registerIncomingPluginChannel(plugin, BUNGEECORD_CHANNEL, this); - Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, REDISBUNGEE_CHANNEL); - Bukkit.getMessenger().registerIncomingPluginChannel(plugin, REDISBUNGEE_CHANNEL, this); - } - - private String getTargetChannel() { - if (Configuration.useRedisBungee) { - return REDISBUNGEE_CHANNEL; - } else { - return BUNGEECORD_CHANNEL; - } - } + Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, REDISBUNGEE_CHANNEL); + Bukkit.getMessenger().registerIncomingPluginChannel(plugin, REDISBUNGEE_CHANNEL, this); + } + + private String getTargetChannel() { + if (Configuration.useRedisBungee) { + return REDISBUNGEE_CHANNEL; + } else { + return BUNGEECORD_CHANNEL; + } + } - @Override - public void onPluginMessageReceived(String channel, Player player, byte[] message) { - if (channel.equals(getTargetChannel())) { - DataInputStream in = new DataInputStream(new ByteArrayInputStream(message)); + @Override + public void onPluginMessageReceived(String channel, Player player, byte[] message) { + if (channel.equals(getTargetChannel())) { + DataInputStream in = new DataInputStream(new ByteArrayInputStream(message)); - try { - String subChannel = in.readUTF(); + try { + String subChannel = in.readUTF(); - if (subChannel.equals("PlayerCount")) { - String server = in.readUTF(); + if (subChannel.equals("PlayerCount")) { + String server = in.readUTF(); - if (in.available() > 0) { - int online = in.readInt(); + if (in.available() > 0) { + int online = in.readInt(); - BungeeServerInfo serverInfo = BungeeServerTracker.getOrCreateServerInfo(server); - serverInfo.setOnlinePlayers(online); - } - } + BungeeServerInfo serverInfo = BungeeServerTracker.getOrCreateServerInfo(server); + serverInfo.setOnlinePlayers(online); + } + } - } catch (EOFException e) { - // Do nothing. - } catch (IOException e) { - // This should never happen. - e.printStackTrace(); - } - } - } + } catch (EOFException e) { + // Do nothing. + } catch (IOException e) { + // This should never happen. + e.printStackTrace(); + } + } + } - public void askPlayerCount(String server) { - ByteArrayOutputStream b = new ByteArrayOutputStream(); - DataOutputStream out = new DataOutputStream(b); + public void askPlayerCount(String server) { + ByteArrayOutputStream b = new ByteArrayOutputStream(); + DataOutputStream out = new DataOutputStream(b); - try { - out.writeUTF("PlayerCount"); - out.writeUTF(server); - } catch (IOException e) { - // It should not happen. - ConsoleLogger.log(Level.WARNING, "I/O Exception while asking for player count on server '" + server + "'.", e); - } + try { + out.writeUTF("PlayerCount"); + out.writeUTF(server); + } catch (IOException e) { + // It should not happen. + ConsoleLogger.log(Level.WARNING, "I/O Exception while asking for player count on server '" + server + "'.", e); + } - // OR, if you don't need to send it to a specific player - Collection players = Bukkit.getOnlinePlayers(); - if (players.size() > 0) { - players.iterator().next().sendPluginMessage(HolographicDisplays.getInstance(), getTargetChannel(), b.toByteArray()); - } - } + // OR, if you don't need to send it to a specific player + Collection players = Bukkit.getOnlinePlayers(); + if (players.size() > 0) { + players.iterator().next().sendPluginMessage(HolographicDisplays.getInstance(), getTargetChannel(), b.toByteArray()); + } + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/bungeecord/BungeeServerInfo.java b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/bungeecord/BungeeServerInfo.java index ca660781..25665c28 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/bungeecord/BungeeServerInfo.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/bungeecord/BungeeServerInfo.java @@ -18,81 +18,81 @@ import me.filoghost.holographicdisplays.disk.Configuration; public class BungeeServerInfo { - private volatile boolean isOnline; - private volatile int onlinePlayers; - private volatile int maxPlayers; - - // The two lines of a motd - private volatile String motd1; // Should never be null - private volatile String motd2; // Should never be null - - private volatile long lastRequest; + private volatile boolean isOnline; + private volatile int onlinePlayers; + private volatile int maxPlayers; + + // The two lines of a motd + private volatile String motd1; // Should never be null + private volatile String motd2; // Should never be null + + private volatile long lastRequest; - protected BungeeServerInfo() { - isOnline = false; - this.motd1 = ""; - this.motd2 = ""; - updateLastRequest(); - } - - public boolean isOnline() { - return isOnline; - } + protected BungeeServerInfo() { + isOnline = false; + this.motd1 = ""; + this.motd2 = ""; + updateLastRequest(); + } + + public boolean isOnline() { + return isOnline; + } - public void setOnline(boolean isOnline) { - this.isOnline = isOnline; - } + public void setOnline(boolean isOnline) { + this.isOnline = isOnline; + } - public int getOnlinePlayers() { - return onlinePlayers; - } + public int getOnlinePlayers() { + return onlinePlayers; + } - public void setOnlinePlayers(int onlinePlayers) { - this.onlinePlayers = onlinePlayers; - } - - public int getMaxPlayers() { - return maxPlayers; - } + public void setOnlinePlayers(int onlinePlayers) { + this.onlinePlayers = onlinePlayers; + } + + public int getMaxPlayers() { + return maxPlayers; + } - public void setMaxPlayers(int maxPlayers) { - this.maxPlayers = maxPlayers; - } + public void setMaxPlayers(int maxPlayers) { + this.maxPlayers = maxPlayers; + } - public String getMotd1() { - return motd1; - } - - public String getMotd2() { - return motd2; - } + public String getMotd1() { + return motd1; + } + + public String getMotd2() { + return motd2; + } - public void setMotd(String motd) { + public void setMotd(String motd) { - if (motd == null) { - this.motd1 = ""; - this.motd2 = ""; - return; - } + if (motd == null) { + this.motd1 = ""; + this.motd2 = ""; + return; + } - int separatorIndex = motd.indexOf("\n"); - if (separatorIndex >= 0) { - String line1 = motd.substring(0, separatorIndex); - String line2 = motd.substring(separatorIndex + 1); - this.motd1 = Configuration.pingerTrimMotd ? line1.trim() : line1; - this.motd2 = Configuration.pingerTrimMotd ? line2.trim() : line2; - } else { - this.motd1 = Configuration.pingerTrimMotd ? motd.trim() : motd; - this.motd2 = ""; - } - } + int separatorIndex = motd.indexOf("\n"); + if (separatorIndex >= 0) { + String line1 = motd.substring(0, separatorIndex); + String line2 = motd.substring(separatorIndex + 1); + this.motd1 = Configuration.pingerTrimMotd ? line1.trim() : line1; + this.motd2 = Configuration.pingerTrimMotd ? line2.trim() : line2; + } else { + this.motd1 = Configuration.pingerTrimMotd ? motd.trim() : motd; + this.motd2 = ""; + } + } - public long getLastRequest() { - return lastRequest; - } + public long getLastRequest() { + return lastRequest; + } - public void updateLastRequest() { - this.lastRequest = System.currentTimeMillis(); - } + public void updateLastRequest() { + this.lastRequest = System.currentTimeMillis(); + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/bungeecord/BungeeServerTracker.java b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/bungeecord/BungeeServerTracker.java index 403b9257..2d7b440e 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/bungeecord/BungeeServerTracker.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/bungeecord/BungeeServerTracker.java @@ -31,177 +31,177 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; public class BungeeServerTracker { - - private static Map trackedServers = new ConcurrentHashMap<>(); - private static int taskID = -1; - - public static void resetTrackedServers() { - trackedServers.clear(); - } - - public static void track(String server) { - if (!trackedServers.containsKey(server)) { - BungeeServerInfo info = new BungeeServerInfo(); - info.setMotd(Configuration.pingerOfflineMotd); - trackedServers.put(server, info); - - if (!Configuration.pingerEnable) { - BungeeChannel.getInstance().askPlayerCount(server); - } - } - } - - public static void untrack(String server) { - trackedServers.remove(server); - } - - protected static BungeeServerInfo getOrCreateServerInfo(String server) { - BungeeServerInfo info = trackedServers.get(server); - if (info == null) { - info = new BungeeServerInfo(); - info.setMotd(Configuration.pingerOfflineMotd); - trackedServers.put(server, info); - } - - return info; - } + + private static Map trackedServers = new ConcurrentHashMap<>(); + private static int taskID = -1; + + public static void resetTrackedServers() { + trackedServers.clear(); + } + + public static void track(String server) { + if (!trackedServers.containsKey(server)) { + BungeeServerInfo info = new BungeeServerInfo(); + info.setMotd(Configuration.pingerOfflineMotd); + trackedServers.put(server, info); + + if (!Configuration.pingerEnable) { + BungeeChannel.getInstance().askPlayerCount(server); + } + } + } + + public static void untrack(String server) { + trackedServers.remove(server); + } + + protected static BungeeServerInfo getOrCreateServerInfo(String server) { + BungeeServerInfo info = trackedServers.get(server); + if (info == null) { + info = new BungeeServerInfo(); + info.setMotd(Configuration.pingerOfflineMotd); + trackedServers.put(server, info); + } + + return info; + } - public static int getPlayersOnline(String server) { - BungeeServerInfo info = trackedServers.get(server); - if (info != null) { - info.updateLastRequest(); - return info.getOnlinePlayers(); - } else { - // It was not tracked, add it. - track(server); - return 0; - } - } - - public static String getMaxPlayers(String server) { - - if (!Configuration.pingerEnable) { - return "[Please enable pinger]"; - } - - BungeeServerInfo info = trackedServers.get(server); - if (info != null) { - info.updateLastRequest(); - return String.valueOf(info.getMaxPlayers()); - } else { - // It was not tracked, add it. - track(server); - return "0"; - } - } - - public static String getMotd1(String server) { - - if (!Configuration.pingerEnable) { - return "[Please enable pinger]"; - } - - BungeeServerInfo info = trackedServers.get(server); - if (info != null) { - info.updateLastRequest(); - return info.getMotd1(); - } else { - // It was not tracked, add it. - track(server); - return Configuration.pingerOfflineMotd; - } - } - - public static String getMotd2(String server) { - - if (!Configuration.pingerEnable) { - return "[Please enable pinger]"; - } - - BungeeServerInfo info = trackedServers.get(server); - if (info != null) { - info.updateLastRequest(); - return info.getMotd2(); - } else { - // It was not tracked, add it. - track(server); - return ""; - } - } - - public static String getOnlineStatus(String server) { - - if (!Configuration.pingerEnable) { - return "[Please enable pinger]"; - } - - BungeeServerInfo info = trackedServers.get(server); - if (info != null) { - info.updateLastRequest(); - return info.isOnline() ? Configuration.pingerStatusOnline : Configuration.pingerStatusOffline; - } else { - // It was not tracked, add it. - track(server); - return "0"; - } - } + public static int getPlayersOnline(String server) { + BungeeServerInfo info = trackedServers.get(server); + if (info != null) { + info.updateLastRequest(); + return info.getOnlinePlayers(); + } else { + // It was not tracked, add it. + track(server); + return 0; + } + } + + public static String getMaxPlayers(String server) { + + if (!Configuration.pingerEnable) { + return "[Please enable pinger]"; + } + + BungeeServerInfo info = trackedServers.get(server); + if (info != null) { + info.updateLastRequest(); + return String.valueOf(info.getMaxPlayers()); + } else { + // It was not tracked, add it. + track(server); + return "0"; + } + } + + public static String getMotd1(String server) { + + if (!Configuration.pingerEnable) { + return "[Please enable pinger]"; + } + + BungeeServerInfo info = trackedServers.get(server); + if (info != null) { + info.updateLastRequest(); + return info.getMotd1(); + } else { + // It was not tracked, add it. + track(server); + return Configuration.pingerOfflineMotd; + } + } + + public static String getMotd2(String server) { + + if (!Configuration.pingerEnable) { + return "[Please enable pinger]"; + } + + BungeeServerInfo info = trackedServers.get(server); + if (info != null) { + info.updateLastRequest(); + return info.getMotd2(); + } else { + // It was not tracked, add it. + track(server); + return ""; + } + } + + public static String getOnlineStatus(String server) { + + if (!Configuration.pingerEnable) { + return "[Please enable pinger]"; + } + + BungeeServerInfo info = trackedServers.get(server); + if (info != null) { + info.updateLastRequest(); + return info.isOnline() ? Configuration.pingerStatusOnline : Configuration.pingerStatusOffline; + } else { + // It was not tracked, add it. + track(server); + return "0"; + } + } - public static Map getTrackedServers() { - return trackedServers; - } - - public static void startTask(int refreshSeconds) { - if (taskID != -1) { - Bukkit.getScheduler().cancelTask(taskID); - } - - taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(HolographicDisplays.getInstance(), () -> { - - if (Configuration.pingerEnable) { - Bukkit.getScheduler().runTaskAsynchronously(HolographicDisplays.getInstance(), () -> { - - for (Entry entry : Configuration.pingerServers.entrySet()) { - BungeeServerInfo serverInfo = getOrCreateServerInfo(entry.getKey()); - boolean displayOffline = false; - - try { - PingResponse data = ServerPinger.fetchData(entry.getValue(), Configuration.pingerTimeout); - - if (data.isOnline()) { - serverInfo.setOnline(true); - serverInfo.setOnlinePlayers(data.getOnlinePlayers()); - serverInfo.setMaxPlayers(data.getMaxPlayers()); - serverInfo.setMotd(data.getMotd()); - } else { - displayOffline = true; - } - } catch (SocketTimeoutException e) { - displayOffline = true; - } catch (UnknownHostException e) { - ConsoleLogger.log(Level.WARNING, "Couldn't fetch data from " + entry.getKey() + "(" + entry.getValue().toString() + "): unknown host address."); - displayOffline = true; - } catch (IOException e) { - displayOffline = true; - } catch (Throwable t) { - displayOffline = true; - ConsoleLogger.log(Level.WARNING, "Couldn't fetch data from " + entry.getKey() + "(" + entry.getValue().toString() + ")", t); - } - - if (displayOffline) { - serverInfo.setOnline(false); - serverInfo.setOnlinePlayers(0); - serverInfo.setMaxPlayers(0); - serverInfo.setMotd(Configuration.pingerOfflineMotd); - } - } - }); - - } else { - for (String server : trackedServers.keySet()) { - BungeeChannel.getInstance().askPlayerCount(server); - } - } + public static Map getTrackedServers() { + return trackedServers; + } + + public static void startTask(int refreshSeconds) { + if (taskID != -1) { + Bukkit.getScheduler().cancelTask(taskID); + } + + taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(HolographicDisplays.getInstance(), () -> { + + if (Configuration.pingerEnable) { + Bukkit.getScheduler().runTaskAsynchronously(HolographicDisplays.getInstance(), () -> { + + for (Entry entry : Configuration.pingerServers.entrySet()) { + BungeeServerInfo serverInfo = getOrCreateServerInfo(entry.getKey()); + boolean displayOffline = false; + + try { + PingResponse data = ServerPinger.fetchData(entry.getValue(), Configuration.pingerTimeout); + + if (data.isOnline()) { + serverInfo.setOnline(true); + serverInfo.setOnlinePlayers(data.getOnlinePlayers()); + serverInfo.setMaxPlayers(data.getMaxPlayers()); + serverInfo.setMotd(data.getMotd()); + } else { + displayOffline = true; + } + } catch (SocketTimeoutException e) { + displayOffline = true; + } catch (UnknownHostException e) { + ConsoleLogger.log(Level.WARNING, "Couldn't fetch data from " + entry.getKey() + "(" + entry.getValue().toString() + "): unknown host address."); + displayOffline = true; + } catch (IOException e) { + displayOffline = true; + } catch (Throwable t) { + displayOffline = true; + ConsoleLogger.log(Level.WARNING, "Couldn't fetch data from " + entry.getKey() + "(" + entry.getValue().toString() + ")", t); + } + + if (displayOffline) { + serverInfo.setOnline(false); + serverInfo.setOnlinePlayers(0); + serverInfo.setMaxPlayers(0); + serverInfo.setMotd(Configuration.pingerOfflineMotd); + } + } + }); + + } else { + for (String server : trackedServers.keySet()) { + BungeeChannel.getInstance().askPlayerCount(server); + } + } - }, 1, refreshSeconds * 20); - } + }, 1, refreshSeconds * 20); + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/bungeecord/serverpinger/PacketUtils.java b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/bungeecord/serverpinger/PacketUtils.java index 1afc1f7b..d9e1b830 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/bungeecord/serverpinger/PacketUtils.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/bungeecord/serverpinger/PacketUtils.java @@ -21,47 +21,47 @@ import java.io.IOException; import java.nio.charset.Charset; class PacketUtils { - - public static final Charset UTF8 = Charset.forName("UTF-8"); + + public static final Charset UTF8 = Charset.forName("UTF-8"); - public static void writeString(final DataOutputStream out, final String s, final Charset charset) throws IOException { - if (charset == PacketUtils.UTF8) { - writeVarInt(out, s.length()); - } else { - out.writeShort(s.length()); - } - out.write(s.getBytes(charset)); - } + public static void writeString(final DataOutputStream out, final String s, final Charset charset) throws IOException { + if (charset == PacketUtils.UTF8) { + writeVarInt(out, s.length()); + } else { + out.writeShort(s.length()); + } + out.write(s.getBytes(charset)); + } - public static int readVarInt(final DataInputStream in) throws IOException { - int i = 0; - int j = 0; - while (true) { - final int k = in.readByte(); - i |= (k & 0x7F) << j++ * 7; - if (j > 5) { - throw new RuntimeException("VarInt too big"); - } - if ((k & 0x80) != 0x80) { - return i; - } - } - } + public static int readVarInt(final DataInputStream in) throws IOException { + int i = 0; + int j = 0; + while (true) { + final int k = in.readByte(); + i |= (k & 0x7F) << j++ * 7; + if (j > 5) { + throw new RuntimeException("VarInt too big"); + } + if ((k & 0x80) != 0x80) { + return i; + } + } + } - public static void writeVarInt(final DataOutputStream out, int paramInt) throws IOException { - while ((paramInt & 0xFFFFFF80) != 0x0) { - out.write((paramInt & 0x7F) | 0x80); - paramInt >>>= 7; - } - out.write(paramInt); - } + public static void writeVarInt(final DataOutputStream out, int paramInt) throws IOException { + while ((paramInt & 0xFFFFFF80) != 0x0) { + out.write((paramInt & 0x7F) | 0x80); + paramInt >>>= 7; + } + out.write(paramInt); + } - public static void closeQuietly(Closeable closeable) { - try { - if (closeable != null) { - closeable.close(); - } - } catch (IOException e) {} - } + public static void closeQuietly(Closeable closeable) { + try { + if (closeable != null) { + closeable.close(); + } + } catch (IOException e) {} + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/bungeecord/serverpinger/PingResponse.java b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/bungeecord/serverpinger/PingResponse.java index 7f0faf17..b612ca96 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/bungeecord/serverpinger/PingResponse.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/bungeecord/serverpinger/PingResponse.java @@ -23,86 +23,86 @@ import java.util.logging.Level; public class PingResponse { - private boolean isOnline; + private boolean isOnline; private String motd; private int onlinePlayers; private int maxPlayers; public PingResponse(boolean isOnline, String motd, int onlinePlayers, int maxPlayers) { - this.isOnline = isOnline; - this.motd = motd; - this.onlinePlayers = onlinePlayers; - this.maxPlayers = maxPlayers; - } + this.isOnline = isOnline; + this.motd = motd; + this.onlinePlayers = onlinePlayers; + this.maxPlayers = maxPlayers; + } - public PingResponse(String jsonString, ServerAddress address) { - - if (jsonString == null || jsonString.isEmpty()) { - motd = "Invalid ping response"; - ConsoleLogger.logDebug(Level.WARNING, "Received empty Json response from IP \"" + address.toString() + "\"!"); - return; - } - - Object jsonObject = JSONValue.parse(jsonString); - - if (!(jsonObject instanceof JSONObject)) { - motd = "Invalid ping response"; - ConsoleLogger.logDebug(Level.WARNING, "Received invalid Json response from IP \"" + address.toString() + "\": " + jsonString); - return; - } - - JSONObject json = (JSONObject) jsonObject; - isOnline = true; - - Object descriptionObject = json.get("description"); - - if (descriptionObject != null) { - if (descriptionObject instanceof JSONObject) { - Object text = ((JSONObject) descriptionObject).get("text"); - if (text != null) { - motd = text.toString(); - } else { - motd = "Invalid ping response (text not found)"; - } - } else { - motd = descriptionObject.toString(); - } - } else { - motd = "Invalid ping response (description not found)"; - ConsoleLogger.logDebug(Level.WARNING, "Received invalid Json response from IP \"" + address.toString() + "\": " + jsonString); - } + public PingResponse(String jsonString, ServerAddress address) { + + if (jsonString == null || jsonString.isEmpty()) { + motd = "Invalid ping response"; + ConsoleLogger.logDebug(Level.WARNING, "Received empty Json response from IP \"" + address.toString() + "\"!"); + return; + } + + Object jsonObject = JSONValue.parse(jsonString); + + if (!(jsonObject instanceof JSONObject)) { + motd = "Invalid ping response"; + ConsoleLogger.logDebug(Level.WARNING, "Received invalid Json response from IP \"" + address.toString() + "\": " + jsonString); + return; + } + + JSONObject json = (JSONObject) jsonObject; + isOnline = true; + + Object descriptionObject = json.get("description"); + + if (descriptionObject != null) { + if (descriptionObject instanceof JSONObject) { + Object text = ((JSONObject) descriptionObject).get("text"); + if (text != null) { + motd = text.toString(); + } else { + motd = "Invalid ping response (text not found)"; + } + } else { + motd = descriptionObject.toString(); + } + } else { + motd = "Invalid ping response (description not found)"; + ConsoleLogger.logDebug(Level.WARNING, "Received invalid Json response from IP \"" + address.toString() + "\": " + jsonString); + } Object playersObject = json.get("players"); - if (playersObject instanceof JSONObject) { - JSONObject playersJson = (JSONObject) playersObject; - - Object onlineObject = playersJson.get("online"); - if (onlineObject instanceof Number) { - onlinePlayers = ((Number) onlineObject).intValue(); - } - - Object maxObject = playersJson.get("max"); - if (maxObject instanceof Number) { - maxPlayers = ((Number) maxObject).intValue(); - } + if (playersObject instanceof JSONObject) { + JSONObject playersJson = (JSONObject) playersObject; + + Object onlineObject = playersJson.get("online"); + if (onlineObject instanceof Number) { + onlinePlayers = ((Number) onlineObject).intValue(); + } + + Object maxObject = playersJson.get("max"); + if (maxObject instanceof Number) { + maxPlayers = ((Number) maxObject).intValue(); + } } } - public boolean isOnline() { - return isOnline; - } + public boolean isOnline() { + return isOnline; + } - public String getMotd() { - return motd; - } + public String getMotd() { + return motd; + } - public int getOnlinePlayers() { - return onlinePlayers; - } + public int getOnlinePlayers() { + return onlinePlayers; + } - public int getMaxPlayers() { - return maxPlayers; - } + public int getMaxPlayers() { + return maxPlayers; + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/bungeecord/serverpinger/ServerPinger.java b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/bungeecord/serverpinger/ServerPinger.java index 4ccf81f1..11c6b35c 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/bungeecord/serverpinger/ServerPinger.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/bungeecord/serverpinger/ServerPinger.java @@ -26,42 +26,42 @@ import java.net.UnknownHostException; public class ServerPinger { - public static PingResponse fetchData(final ServerAddress serverAddress, int timeout) throws SocketTimeoutException, UnknownHostException, IOException, Exception { - - Socket socket = null; - DataOutputStream dataOut = null; - DataInputStream dataIn = null; - - try { - socket = new Socket(serverAddress.getAddress(), serverAddress.getPort()); - socket.setSoTimeout(timeout); - dataOut = new DataOutputStream(socket.getOutputStream()); - dataIn = new DataInputStream(socket.getInputStream()); - final ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); - final DataOutputStream handshake = new DataOutputStream(byteOut); - handshake.write(0); - PacketUtils.writeVarInt(handshake, 4); - PacketUtils.writeString(handshake, serverAddress.getAddress(), PacketUtils.UTF8); - handshake.writeShort(serverAddress.getPort()); - PacketUtils.writeVarInt(handshake, 1); - byte[] bytes = byteOut.toByteArray(); - PacketUtils.writeVarInt(dataOut, bytes.length); - dataOut.write(bytes); - bytes = new byte[] { 0 }; - PacketUtils.writeVarInt(dataOut, bytes.length); - dataOut.write(bytes); - PacketUtils.readVarInt(dataIn); - PacketUtils.readVarInt(dataIn); - final byte[] responseData = new byte[PacketUtils.readVarInt(dataIn)]; - dataIn.readFully(responseData); - final String jsonString = new String(responseData, PacketUtils.UTF8); - return new PingResponse(jsonString, serverAddress); - } - finally { - PacketUtils.closeQuietly(dataOut); - PacketUtils.closeQuietly(dataIn); - PacketUtils.closeQuietly(socket); - } - } + public static PingResponse fetchData(final ServerAddress serverAddress, int timeout) throws SocketTimeoutException, UnknownHostException, IOException, Exception { + + Socket socket = null; + DataOutputStream dataOut = null; + DataInputStream dataIn = null; + + try { + socket = new Socket(serverAddress.getAddress(), serverAddress.getPort()); + socket.setSoTimeout(timeout); + dataOut = new DataOutputStream(socket.getOutputStream()); + dataIn = new DataInputStream(socket.getInputStream()); + final ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + final DataOutputStream handshake = new DataOutputStream(byteOut); + handshake.write(0); + PacketUtils.writeVarInt(handshake, 4); + PacketUtils.writeString(handshake, serverAddress.getAddress(), PacketUtils.UTF8); + handshake.writeShort(serverAddress.getPort()); + PacketUtils.writeVarInt(handshake, 1); + byte[] bytes = byteOut.toByteArray(); + PacketUtils.writeVarInt(dataOut, bytes.length); + dataOut.write(bytes); + bytes = new byte[] { 0 }; + PacketUtils.writeVarInt(dataOut, bytes.length); + dataOut.write(bytes); + PacketUtils.readVarInt(dataIn); + PacketUtils.readVarInt(dataIn); + final byte[] responseData = new byte[PacketUtils.readVarInt(dataIn)]; + dataIn.readFully(responseData); + final String jsonString = new String(responseData, PacketUtils.UTF8); + return new PingResponse(jsonString, serverAddress); + } + finally { + PacketUtils.closeQuietly(dataOut); + PacketUtils.closeQuietly(dataIn); + PacketUtils.closeQuietly(socket); + } + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/ProtocolLibHook.java b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/ProtocolLibHook.java index 5eacf907..d33b5dd6 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/ProtocolLibHook.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/ProtocolLibHook.java @@ -21,15 +21,15 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; public interface ProtocolLibHook { - - public boolean hook(Plugin plugin, NMSManager nmsManager); - - public void sendDestroyEntitiesPacket(Player player, CraftHologram hologram); - - public void sendDestroyEntitiesPacket(Player player, CraftHologramLine line); - - public void sendCreateEntitiesPacket(Player player, CraftHologram hologram); - - public void sendCreateEntitiesPacket(Player player, CraftHologramLine line); + + public boolean hook(Plugin plugin, NMSManager nmsManager); + + public void sendDestroyEntitiesPacket(Player player, CraftHologram hologram); + + public void sendDestroyEntitiesPacket(Player player, CraftHologramLine line); + + public void sendCreateEntitiesPacket(Player player, CraftHologram hologram); + + public void sendCreateEntitiesPacket(Player player, CraftHologramLine line); } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/DebugHelper.java b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/DebugHelper.java index 6f71ae79..c88f69ef 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/DebugHelper.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/DebugHelper.java @@ -27,81 +27,81 @@ import com.comphenix.protocol.wrappers.BukkitConverters; import java.util.Map; public 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, new ObjectPrinter() { - @Override - public boolean print(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()); + + 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, new ObjectPrinter() { + @Override + public boolean print(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; - } + 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/bridge/protocollib/current/MetadataHelper.java b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/MetadataHelper.java index 6b8a9815..447f68fb 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/MetadataHelper.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/MetadataHelper.java @@ -26,174 +26,174 @@ import java.util.List; import java.util.Optional; public class MetadataHelper { - - private Serializer itemSerializer; - private Serializer intSerializer; - private Serializer byteSerializer; - private Serializer stringSerializer; - private Serializer booleanSerializer; - private Serializer chatComponentSerializer; + + private Serializer itemSerializer; + private Serializer intSerializer; + private Serializer byteSerializer; + private Serializer stringSerializer; + private Serializer booleanSerializer; + private Serializer chatComponentSerializer; - private int itemSlotIndex; - private int entityStatusIndex; - private int airLevelWatcherIndex; - private int customNameIndex; - private int customNameVisibleIndex; - private int noGravityIndex; - private int armorStandStatusIndex; - private int slimeSizeIndex; - - - public MetadataHelper() { - 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_15_R1)) { - armorStandStatusIndex = 14; - } else { - armorStandStatusIndex = 11; - } - - entityStatusIndex = 0; - airLevelWatcherIndex = 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)) { - chatComponentSerializer = Registry.get(MinecraftReflection.getIChatBaseComponentClass(), true); - } - } - - - public void setEntityStatus(WrappedDataWatcher dataWatcher, byte statusBitmask) { - requireMinimumVersion(NMSVersion.v1_9_R1); - dataWatcher.setObject(new WrappedDataWatcherObject(entityStatusIndex, byteSerializer), statusBitmask); - } - + private int itemSlotIndex; + private int entityStatusIndex; + private int airLevelWatcherIndex; + private int customNameIndex; + private int customNameVisibleIndex; + private int noGravityIndex; + private int armorStandStatusIndex; + private int slimeSizeIndex; + + + public MetadataHelper() { + 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_15_R1)) { + armorStandStatusIndex = 14; + } else { + armorStandStatusIndex = 11; + } + + entityStatusIndex = 0; + airLevelWatcherIndex = 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)) { + chatComponentSerializer = Registry.get(MinecraftReflection.getIChatBaseComponentClass(), true); + } + } + + + public void setEntityStatus(WrappedDataWatcher dataWatcher, byte statusBitmask) { + requireMinimumVersion(NMSVersion.v1_9_R1); + dataWatcher.setObject(new WrappedDataWatcherObject(entityStatusIndex, byteSerializer), statusBitmask); + } + - public WrappedWatchableObject getCustomNameWacthableObject(WrappedDataWatcher metadata) { - return metadata.getWatchableObject(customNameIndex); - } - - - public WrappedWatchableObject getCustomNameWatchableObject(List dataWatcherValues) { - for (int i = 0; i < dataWatcherValues.size(); i++) { - WrappedWatchableObject watchableObject = dataWatcherValues.get(i); - - if (watchableObject.getIndex() == customNameIndex) { - return watchableObject; - } - } - - return null; - } - - - public Object getCustomNameNMSObject(WrappedWatchableObject customNameWatchableObject) { - Object customNameNMSObject = customNameWatchableObject.getRawValue(); - if (customNameNMSObject == null) { - return null; - } - - if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) { - 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 (String) customNameNMSObject; - } - } - - - public void setCustomNameNMSObject(WrappedWatchableObject customNameWatchableObject, Object customNameNMSObject) { - if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) { - customNameWatchableObject.setValue(Optional.ofNullable(customNameNMSObject)); - } else { - customNameWatchableObject.setValue(customNameNMSObject); - } - } + public WrappedWatchableObject getCustomNameWacthableObject(WrappedDataWatcher metadata) { + return metadata.getWatchableObject(customNameIndex); + } + + + public WrappedWatchableObject getCustomNameWatchableObject(List dataWatcherValues) { + for (int i = 0; i < dataWatcherValues.size(); i++) { + WrappedWatchableObject watchableObject = dataWatcherValues.get(i); + + if (watchableObject.getIndex() == customNameIndex) { + return watchableObject; + } + } + + return null; + } + + + public Object getCustomNameNMSObject(WrappedWatchableObject customNameWatchableObject) { + Object customNameNMSObject = customNameWatchableObject.getRawValue(); + if (customNameNMSObject == null) { + return null; + } + + if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) { + 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 (String) customNameNMSObject; + } + } + + + public void setCustomNameNMSObject(WrappedWatchableObject customNameWatchableObject, Object customNameNMSObject) { + if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) { + customNameWatchableObject.setValue(Optional.ofNullable(customNameNMSObject)); + } else { + customNameWatchableObject.setValue(customNameNMSObject); + } + } - - public void setCustomNameNMSObject(WrappedDataWatcher dataWatcher, Object customNameNMSObject) { - requireMinimumVersion(NMSVersion.v1_9_R1); - - if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) { - dataWatcher.setObject(new WrappedDataWatcherObject(customNameIndex, chatComponentSerializer), Optional.ofNullable(customNameNMSObject)); - } else { - dataWatcher.setObject(new WrappedDataWatcherObject(customNameIndex, stringSerializer), customNameNMSObject); - } - } + + public void setCustomNameNMSObject(WrappedDataWatcher dataWatcher, Object customNameNMSObject) { + requireMinimumVersion(NMSVersion.v1_9_R1); + + if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) { + 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 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 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 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(airLevelWatcherIndex, intSerializer), 300); - dataWatcher.setObject(new WrappedDataWatcherObject(entityStatusIndex, byteSerializer), (byte) 0); - } else { - dataWatcher.setObject(itemSlotIndex, nmsItemStack); - dataWatcher.setObject(airLevelWatcherIndex, 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); - } - } - + + 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(airLevelWatcherIndex, intSerializer), 300); + dataWatcher.setObject(new WrappedDataWatcherObject(entityStatusIndex, byteSerializer), (byte) 0); + } else { + dataWatcher.setObject(itemSlotIndex, nmsItemStack); + dataWatcher.setObject(airLevelWatcherIndex, 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/bridge/protocollib/current/PacketHelper.java b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/PacketHelper.java index 062236fa..84680821 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/PacketHelper.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/PacketHelper.java @@ -33,104 +33,104 @@ import org.bukkit.entity.Player; import java.util.List; public class PacketHelper { - - private MetadataHelper metadataHelper; - - public PacketHelper(MetadataHelper metadataHelper) { - this.metadataHelper = metadataHelper; - } - - public 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 + + private MetadataHelper metadataHelper; + + public PacketHelper(MetadataHelper metadataHelper) { + this.metadataHelper = metadataHelper; + } + + public 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); - } - } - - - public void sendSpawnItemPacket(Player receiver, NMSItem item) { - AbstractPacket packet = new WrapperPlayServerSpawnEntity(item.getBukkitEntityNMS(), ObjectTypes.ITEM_STACK, 1); - packet.sendPacket(receiver); - } - - - public void sendSpawnSlimePacket(Player receiver, NMSSlime slime) { - 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); - } - } - - - public 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); - } - - - public void sendVehicleAttachPacket(Player receiver, NMSEntityBase vehicle, NMSEntityBase 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); - } - } - - - public void sendDestroyEntitiesPacket(Player player, List ids) { - WrapperPlayServerEntityDestroy packet = new WrapperPlayServerEntityDestroy(); - packet.setEntities(ids); - packet.sendPacket(player); - } - + 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); + } + } + + + public void sendSpawnItemPacket(Player receiver, NMSItem item) { + AbstractPacket packet = new WrapperPlayServerSpawnEntity(item.getBukkitEntityNMS(), ObjectTypes.ITEM_STACK, 1); + packet.sendPacket(receiver); + } + + + public void sendSpawnSlimePacket(Player receiver, NMSSlime slime) { + 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); + } + } + + + public 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); + } + + + public void sendVehicleAttachPacket(Player receiver, NMSEntityBase vehicle, NMSEntityBase 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); + } + } + + + public void sendDestroyEntitiesPacket(Player player, List ids) { + WrapperPlayServerEntityDestroy packet = new WrapperPlayServerEntityDestroy(); + packet.setEntities(ids); + packet.sendPacket(player); + } + } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/ProtocolLibHookImpl.java b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/ProtocolLibHookImpl.java index a693c8ab..43cfc32d 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/ProtocolLibHookImpl.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/ProtocolLibHookImpl.java @@ -52,259 +52,259 @@ import java.util.List; * This is for the ProtocolLib versions containing the WrappedDataWatcher.WrappedDataWatcherObject class. */ public class ProtocolLibHookImpl implements ProtocolLibHook { - - private NMSManager nmsManager; - private PacketHelper packetHelper; - private MetadataHelper metadataHelper; - - - @Override - public boolean hook(Plugin plugin, NMSManager nmsManager) { - this.nmsManager = nmsManager; - this.metadataHelper = new MetadataHelper(); - this.packetHelper = new PacketHelper(metadataHelper); + + private NMSManager nmsManager; + private PacketHelper packetHelper; + private MetadataHelper metadataHelper; + + + @Override + public boolean hook(Plugin plugin, NMSManager nmsManager) { + this.nmsManager = nmsManager; + this.metadataHelper = new MetadataHelper(); + this.packetHelper = new PacketHelper(metadataHelper); - AdapterParameteters params = PacketAdapter - .params() - .plugin(plugin) - .types( - PacketType.Play.Server.SPAWN_ENTITY_LIVING, - PacketType.Play.Server.SPAWN_ENTITY, - PacketType.Play.Server.ENTITY_METADATA, - PacketType.Play.Server.REL_ENTITY_MOVE, - PacketType.Play.Server.REL_ENTITY_MOVE_LOOK) - .serverSide() - .listenerPriority(ListenerPriority.NORMAL); - - ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(params) { - - @Override - public void onPacketSending(PacketEvent event) { - PacketContainer packet = event.getPacket(); - Player player = event.getPlayer(); - - if (player instanceof Factory) { - return; // Ignore temporary players (reference: https://github.com/dmulloy2/ProtocolLib/issues/349) - } + AdapterParameteters params = PacketAdapter + .params() + .plugin(plugin) + .types( + PacketType.Play.Server.SPAWN_ENTITY_LIVING, + PacketType.Play.Server.SPAWN_ENTITY, + PacketType.Play.Server.ENTITY_METADATA, + PacketType.Play.Server.REL_ENTITY_MOVE, + PacketType.Play.Server.REL_ENTITY_MOVE_LOOK) + .serverSide() + .listenerPriority(ListenerPriority.NORMAL); + + ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(params) { + + @Override + public void onPacketSending(PacketEvent event) { + PacketContainer packet = event.getPacket(); + Player player = event.getPlayer(); + + if (player instanceof Factory) { + return; // Ignore temporary players (reference: https://github.com/dmulloy2/ProtocolLib/issues/349) + } - // Spawn entity packet - if (packet.getType() == PacketType.Play.Server.SPAWN_ENTITY_LIVING) { - WrapperPlayServerSpawnEntityLiving spawnEntityPacket = new WrapperPlayServerSpawnEntityLiving(packet); - CraftHologramLine hologramLine = getHologramLine(event, spawnEntityPacket); - - if (hologramLine == null) { - return; - } - - if (!hologramLine.getParent().getVisibilityManager().isVisibleTo(player)) { - event.setCancelled(true); - return; - } - - if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_15_R1)) { - // There's no metadata field in 1.15+ on the spawn entity packet - return; - } - - if (!hologramLine.getParent().isAllowPlaceholders() || !hologramLine.hasRelativePlaceholders()) { - return; - } - - spawnEntityPacket = new WrapperPlayServerSpawnEntityLiving(packet.deepClone()); - WrappedWatchableObject customNameWatchableObject = metadataHelper.getCustomNameWacthableObject(spawnEntityPacket.getMetadata()); - - if (customNameWatchableObject == null) { - return; - } - - replaceRelativePlaceholders(customNameWatchableObject, player, hologramLine.getRelativePlaceholders()); - event.setPacket(spawnEntityPacket.getHandle()); + // Spawn entity packet + if (packet.getType() == PacketType.Play.Server.SPAWN_ENTITY_LIVING) { + WrapperPlayServerSpawnEntityLiving spawnEntityPacket = new WrapperPlayServerSpawnEntityLiving(packet); + CraftHologramLine hologramLine = getHologramLine(event, spawnEntityPacket); + + if (hologramLine == null) { + return; + } + + if (!hologramLine.getParent().getVisibilityManager().isVisibleTo(player)) { + event.setCancelled(true); + return; + } + + if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_15_R1)) { + // There's no metadata field in 1.15+ on the spawn entity packet + return; + } + + if (!hologramLine.getParent().isAllowPlaceholders() || !hologramLine.hasRelativePlaceholders()) { + return; + } + + spawnEntityPacket = new WrapperPlayServerSpawnEntityLiving(packet.deepClone()); + WrappedWatchableObject customNameWatchableObject = metadataHelper.getCustomNameWacthableObject(spawnEntityPacket.getMetadata()); + + if (customNameWatchableObject == null) { + return; + } + + replaceRelativePlaceholders(customNameWatchableObject, player, hologramLine.getRelativePlaceholders()); + event.setPacket(spawnEntityPacket.getHandle()); - } else if (packet.getType() == PacketType.Play.Server.SPAWN_ENTITY) { - WrapperPlayServerSpawnEntity spawnEntityPacket = new WrapperPlayServerSpawnEntity(packet); - CraftHologramLine hologramLine = getHologramLine(event, spawnEntityPacket); - - if (hologramLine == null) { - return; - } - - if (!hologramLine.getParent().getVisibilityManager().isVisibleTo(player)) { - event.setCancelled(true); - return; - } - - } else if (packet.getType() == PacketType.Play.Server.ENTITY_METADATA) { - WrapperPlayServerEntityMetadata entityMetadataPacket = new WrapperPlayServerEntityMetadata(packet); - CraftHologramLine hologramLine = getHologramLine(event, entityMetadataPacket); - - if (hologramLine == null) { - return; - } - - if (!hologramLine.getParent().getVisibilityManager().isVisibleTo(player)) { - event.setCancelled(true); - return; - } - - if (!hologramLine.getParent().isAllowPlaceholders() || !hologramLine.hasRelativePlaceholders()) { - return; - } - - entityMetadataPacket = new WrapperPlayServerEntityMetadata(packet.deepClone()); - WrappedWatchableObject customNameWatchableObject = metadataHelper.getCustomNameWatchableObject(entityMetadataPacket.getEntityMetadata()); - - if (customNameWatchableObject == null) { - return; - } - - boolean modified = replaceRelativePlaceholders(customNameWatchableObject, player, hologramLine.getRelativePlaceholders()); - if (modified) { - event.setPacket(entityMetadataPacket.getHandle()); - } - - } else if (packet.getType() == PacketType.Play.Server.REL_ENTITY_MOVE || packet.getType() == PacketType.Play.Server.REL_ENTITY_MOVE_LOOK) { - int entityID = packet.getIntegers().read(0); - NMSEntityBase nmsEntityBase = getNMSEntityBase(event.getPlayer().getWorld(), entityID); - - if (nmsEntityBase instanceof NMSArmorStand) { - event.setCancelled(true); // Don't send relative movement packets for armor stands, only keep precise teleport packets. - } - } - } - }); - - return true; - } - - - private boolean replaceRelativePlaceholders(WrappedWatchableObject customNameWatchableObject, Player player, Collection relativePlaceholders) { - if (customNameWatchableObject == null) { - return false; - } - - final Object originalCustomNameNMSObject = metadataHelper.getCustomNameNMSObject(customNameWatchableObject); - if (originalCustomNameNMSObject == null) { - return false; - } - - Object replacedCustomNameNMSObject = originalCustomNameNMSObject; - for (RelativePlaceholder relativePlaceholder : relativePlaceholders) { - replacedCustomNameNMSObject = nmsManager.replaceCustomNameText(replacedCustomNameNMSObject, relativePlaceholder.getTextPlaceholder(), relativePlaceholder.getReplacement(player)); - } - - if (replacedCustomNameNMSObject == originalCustomNameNMSObject) { - // It means nothing has been replaced, since original custom name has been returned. - return false; - } - - metadataHelper.setCustomNameNMSObject(customNameWatchableObject, replacedCustomNameNMSObject); - return true; - } - - - @Override - public void sendDestroyEntitiesPacket(Player player, CraftHologram hologram) { - List ids = new ArrayList<>(); - for (CraftHologramLine line : hologram.getLinesUnsafe()) { - if (line.isSpawned()) { - for (int id : line.getEntitiesIDs()) { - ids.add(id); - } - } - } - - if (!ids.isEmpty()) { - packetHelper.sendDestroyEntitiesPacket(player, ids); - } - } - - - @Override - public void sendDestroyEntitiesPacket(Player player, CraftHologramLine line) { - if (!line.isSpawned()) { - return; - } - - List ids = new ArrayList<>(); - for (int id : line.getEntitiesIDs()) { - ids.add(id); - } - - if (!ids.isEmpty()) { - packetHelper.sendDestroyEntitiesPacket(player, ids); - } - } - - - @Override - public void sendCreateEntitiesPacket(Player player, CraftHologram hologram) { - for (CraftHologramLine line : hologram.getLinesUnsafe()) { - sendCreateEntitiesPacket(player, line); - } - } - - - @Override - public void sendCreateEntitiesPacket(Player player, CraftHologramLine line) { - if (!line.isSpawned()) { - return; - } - - CraftTouchableLine touchableLine; - - if (line instanceof CraftTextLine) { - CraftTextLine textLine = (CraftTextLine) line; - touchableLine = textLine; - - if (textLine.isSpawned()) { - packetHelper.sendSpawnArmorStandPacket(player, (NMSArmorStand) textLine.getNmsNameable()); - } - - } else if (line instanceof CraftItemLine) { - CraftItemLine itemLine = (CraftItemLine) line; - touchableLine = itemLine; - - if (itemLine.isSpawned()) { - packetHelper.sendSpawnArmorStandPacket(player, (NMSArmorStand) itemLine.getNmsVehicle()); - packetHelper.sendSpawnItemPacket(player, itemLine.getNmsItem()); - packetHelper.sendVehicleAttachPacket(player, itemLine.getNmsVehicle(), itemLine.getNmsItem()); - packetHelper.sendItemMetadataPacket(player, itemLine.getNmsItem()); - } - } else { - throw new IllegalArgumentException("Unexpected hologram line type: " + line.getClass().getName()); - } - - if (touchableLine != null && touchableLine.isSpawned() && touchableLine.getTouchSlime() != null) { - CraftTouchSlimeLine touchSlime = touchableLine.getTouchSlime(); - - if (touchSlime.isSpawned()) { - packetHelper.sendSpawnArmorStandPacket(player, (NMSArmorStand) touchSlime.getNmsVehicle()); - packetHelper.sendSpawnSlimePacket(player, touchSlime.getNmsSlime()); - packetHelper.sendVehicleAttachPacket(player, touchSlime.getNmsVehicle(), touchSlime.getNmsSlime()); - } - } - } - - - private CraftHologramLine getHologramLine(PacketEvent packetEvent, EntityRelatedPacketWrapper packetWrapper) { - return getHologramLine(packetEvent.getPlayer().getWorld(), packetWrapper.getEntityID()); - } - - private CraftHologramLine getHologramLine(World world, int entityID) { - if (entityID < 0) { - return null; - } + } else if (packet.getType() == PacketType.Play.Server.SPAWN_ENTITY) { + WrapperPlayServerSpawnEntity spawnEntityPacket = new WrapperPlayServerSpawnEntity(packet); + CraftHologramLine hologramLine = getHologramLine(event, spawnEntityPacket); + + if (hologramLine == null) { + return; + } + + if (!hologramLine.getParent().getVisibilityManager().isVisibleTo(player)) { + event.setCancelled(true); + return; + } + + } else if (packet.getType() == PacketType.Play.Server.ENTITY_METADATA) { + WrapperPlayServerEntityMetadata entityMetadataPacket = new WrapperPlayServerEntityMetadata(packet); + CraftHologramLine hologramLine = getHologramLine(event, entityMetadataPacket); + + if (hologramLine == null) { + return; + } + + if (!hologramLine.getParent().getVisibilityManager().isVisibleTo(player)) { + event.setCancelled(true); + return; + } + + if (!hologramLine.getParent().isAllowPlaceholders() || !hologramLine.hasRelativePlaceholders()) { + return; + } + + entityMetadataPacket = new WrapperPlayServerEntityMetadata(packet.deepClone()); + WrappedWatchableObject customNameWatchableObject = metadataHelper.getCustomNameWatchableObject(entityMetadataPacket.getEntityMetadata()); + + if (customNameWatchableObject == null) { + return; + } + + boolean modified = replaceRelativePlaceholders(customNameWatchableObject, player, hologramLine.getRelativePlaceholders()); + if (modified) { + event.setPacket(entityMetadataPacket.getHandle()); + } + + } else if (packet.getType() == PacketType.Play.Server.REL_ENTITY_MOVE || packet.getType() == PacketType.Play.Server.REL_ENTITY_MOVE_LOOK) { + int entityID = packet.getIntegers().read(0); + NMSEntityBase nmsEntityBase = getNMSEntityBase(event.getPlayer().getWorld(), entityID); + + if (nmsEntityBase instanceof NMSArmorStand) { + event.setCancelled(true); // Don't send relative movement packets for armor stands, only keep precise teleport packets. + } + } + } + }); + + return true; + } + + + private boolean replaceRelativePlaceholders(WrappedWatchableObject customNameWatchableObject, Player player, Collection relativePlaceholders) { + if (customNameWatchableObject == null) { + return false; + } + + final Object originalCustomNameNMSObject = metadataHelper.getCustomNameNMSObject(customNameWatchableObject); + if (originalCustomNameNMSObject == null) { + return false; + } + + Object replacedCustomNameNMSObject = originalCustomNameNMSObject; + for (RelativePlaceholder relativePlaceholder : relativePlaceholders) { + replacedCustomNameNMSObject = nmsManager.replaceCustomNameText(replacedCustomNameNMSObject, relativePlaceholder.getTextPlaceholder(), relativePlaceholder.getReplacement(player)); + } + + if (replacedCustomNameNMSObject == originalCustomNameNMSObject) { + // It means nothing has been replaced, since original custom name has been returned. + return false; + } + + metadataHelper.setCustomNameNMSObject(customNameWatchableObject, replacedCustomNameNMSObject); + return true; + } + + + @Override + public void sendDestroyEntitiesPacket(Player player, CraftHologram hologram) { + List ids = new ArrayList<>(); + for (CraftHologramLine line : hologram.getLinesUnsafe()) { + if (line.isSpawned()) { + for (int id : line.getEntitiesIDs()) { + ids.add(id); + } + } + } + + if (!ids.isEmpty()) { + packetHelper.sendDestroyEntitiesPacket(player, ids); + } + } + + + @Override + public void sendDestroyEntitiesPacket(Player player, CraftHologramLine line) { + if (!line.isSpawned()) { + return; + } + + List ids = new ArrayList<>(); + for (int id : line.getEntitiesIDs()) { + ids.add(id); + } + + if (!ids.isEmpty()) { + packetHelper.sendDestroyEntitiesPacket(player, ids); + } + } + + + @Override + public void sendCreateEntitiesPacket(Player player, CraftHologram hologram) { + for (CraftHologramLine line : hologram.getLinesUnsafe()) { + sendCreateEntitiesPacket(player, line); + } + } + + + @Override + public void sendCreateEntitiesPacket(Player player, CraftHologramLine line) { + if (!line.isSpawned()) { + return; + } + + CraftTouchableLine touchableLine; + + if (line instanceof CraftTextLine) { + CraftTextLine textLine = (CraftTextLine) line; + touchableLine = textLine; + + if (textLine.isSpawned()) { + packetHelper.sendSpawnArmorStandPacket(player, (NMSArmorStand) textLine.getNmsNameable()); + } + + } else if (line instanceof CraftItemLine) { + CraftItemLine itemLine = (CraftItemLine) line; + touchableLine = itemLine; + + if (itemLine.isSpawned()) { + packetHelper.sendSpawnArmorStandPacket(player, (NMSArmorStand) itemLine.getNmsVehicle()); + packetHelper.sendSpawnItemPacket(player, itemLine.getNmsItem()); + packetHelper.sendVehicleAttachPacket(player, itemLine.getNmsVehicle(), itemLine.getNmsItem()); + packetHelper.sendItemMetadataPacket(player, itemLine.getNmsItem()); + } + } else { + throw new IllegalArgumentException("Unexpected hologram line type: " + line.getClass().getName()); + } + + if (touchableLine != null && touchableLine.isSpawned() && touchableLine.getTouchSlime() != null) { + CraftTouchSlimeLine touchSlime = touchableLine.getTouchSlime(); + + if (touchSlime.isSpawned()) { + packetHelper.sendSpawnArmorStandPacket(player, (NMSArmorStand) touchSlime.getNmsVehicle()); + packetHelper.sendSpawnSlimePacket(player, touchSlime.getNmsSlime()); + packetHelper.sendVehicleAttachPacket(player, touchSlime.getNmsVehicle(), touchSlime.getNmsSlime()); + } + } + } + + + private CraftHologramLine getHologramLine(PacketEvent packetEvent, EntityRelatedPacketWrapper packetWrapper) { + return getHologramLine(packetEvent.getPlayer().getWorld(), packetWrapper.getEntityID()); + } + + private CraftHologramLine getHologramLine(World world, int entityID) { + if (entityID < 0) { + return null; + } - NMSEntityBase nmsEntity = getNMSEntityBase(world, entityID); - if (nmsEntity == null) { - return null; // Entity not existing or not related to holograms. - } - - return (CraftHologramLine) nmsEntity.getHologramLine(); - } - - private NMSEntityBase getNMSEntityBase(World world, int entityID) { - return HolographicDisplays.getNMSManager().getNMSEntityBaseFromID(world, entityID); - } - + NMSEntityBase nmsEntity = getNMSEntityBase(world, entityID); + if (nmsEntity == null) { + return null; // Entity not existing or not related to holograms. + } + + return (CraftHologramLine) nmsEntity.getHologramLine(); + } + + private NMSEntityBase getNMSEntityBase(World world, int entityID) { + return HolographicDisplays.getNMSManager().getNMSEntityBaseFromID(world, entityID); + } + } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/packet/AbstractPacket.java b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/packet/AbstractPacket.java index cea9e8e2..4f9f7d41 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/packet/AbstractPacket.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/packet/AbstractPacket.java @@ -26,56 +26,56 @@ import org.bukkit.entity.Player; import java.lang.reflect.InvocationTargetException; public abstract class AbstractPacket { - // The packet we will be modifying - protected PacketContainer handle; + // The packet we will be modifying + protected PacketContainer handle; - /** - * Constructs a new strongly typed wrapper for the given packet. - * @param handle - handle to the raw packet data. - * @param type - the packet type. - */ - 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); + /** + * Constructs a new strongly typed wrapper for the given packet. + * @param handle - handle to the raw packet data. + * @param type - the packet type. + */ + 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; - } + this.handle = handle; + } - /** - * Retrieve a handle to the raw packet data. - * @return Raw packet data. - */ - public PacketContainer getHandle() { - return handle; - } + /** + * Retrieve a handle to the raw packet data. + * @return Raw packet data. + */ + public PacketContainer getHandle() { + return handle; + } - /** - * Send the current packet to the given receiver. - * @param receiver - the 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); - } - } + /** + * Send the current packet to the given receiver. + * @param receiver - the 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. - * @param sender - the sender. - * @throws RuntimeException If the packet cannot be received. - */ - public void recievePacket(Player sender) { - try { - ProtocolLibrary.getProtocolManager().recieveClientPacket(sender, getHandle()); - } catch (Exception e) { - throw new RuntimeException("Cannot recieve packet.", e); - } - } -} \ No newline at end of file + /** + * Simulate receiving the current packet from the given sender. + * @param sender - the sender. + * @throws RuntimeException If the packet cannot be received. + */ + public void recievePacket(Player sender) { + try { + ProtocolLibrary.getProtocolManager().recieveClientPacket(sender, getHandle()); + } catch (Exception e) { + throw new RuntimeException("Cannot recieve packet.", e); + } + } +} diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/packet/EntityRelatedPacketWrapper.java b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/packet/EntityRelatedPacketWrapper.java index 7662ed69..fe48e2b1 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/packet/EntityRelatedPacketWrapper.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/packet/EntityRelatedPacketWrapper.java @@ -16,6 +16,6 @@ package me.filoghost.holographicdisplays.bridge.protocollib.current.packet; public interface EntityRelatedPacketWrapper { - public int getEntityID(); - + public int getEntityID(); + } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/packet/WrapperPlayServerAttachEntity.java b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/packet/WrapperPlayServerAttachEntity.java index cffa9b6e..4a8904e2 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/packet/WrapperPlayServerAttachEntity.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/packet/WrapperPlayServerAttachEntity.java @@ -73,7 +73,7 @@ public class WrapperPlayServerAttachEntity extends AbstractPacket { * @return The entity. */ public Entity getEntity(World world) { - return handle.getEntityModifier(world).read(1); + return handle.getEntityModifier(world).read(1); } /** @@ -82,7 +82,7 @@ public class WrapperPlayServerAttachEntity extends AbstractPacket { * @return The entity. */ public Entity getEntity(PacketEvent event) { - return getEntity(event.getPlayer().getWorld()); + return getEntity(event.getPlayer().getWorld()); } /** @@ -107,7 +107,7 @@ public class WrapperPlayServerAttachEntity extends AbstractPacket { * @return The vehicle. */ public Entity getVehicle(World world) { - return handle.getEntityModifier(world).read(2); + return handle.getEntityModifier(world).read(2); } /** @@ -116,6 +116,6 @@ public class WrapperPlayServerAttachEntity extends AbstractPacket { * @return The vehicle. */ public Entity getVehicle(PacketEvent event) { - return getVehicle(event.getPlayer().getWorld()); + return getVehicle(event.getPlayer().getWorld()); } -} \ No newline at end of file +} diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/packet/WrapperPlayServerEntityMetadata.java b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/packet/WrapperPlayServerEntityMetadata.java index 1112d199..66bee11f 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/packet/WrapperPlayServerEntityMetadata.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/packet/WrapperPlayServerEntityMetadata.java @@ -61,7 +61,7 @@ public class WrapperPlayServerEntityMetadata extends AbstractPacket implements E * @return The entity. */ public Entity getEntity(World world) { - return handle.getEntityModifier(world).read(0); + return handle.getEntityModifier(world).read(0); } /** @@ -70,7 +70,7 @@ public class WrapperPlayServerEntityMetadata extends AbstractPacket implements E * @return The entity. */ public Entity getEntity(PacketEvent event) { - return getEntity(event.getPlayer().getWorld()); + return getEntity(event.getPlayer().getWorld()); } /** diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/packet/WrapperPlayServerMount.java b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/packet/WrapperPlayServerMount.java index e4d2bb86..9a85869c 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/packet/WrapperPlayServerMount.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/packet/WrapperPlayServerMount.java @@ -24,7 +24,7 @@ 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() { @@ -73,6 +73,6 @@ public class WrapperPlayServerMount extends AbstractPacket { * @param value - new value. */ public void setPassengers(List entities) { - setPassengers(Ints.toArray(entities)); + setPassengers(Ints.toArray(entities)); } -} \ No newline at end of file +} diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/packet/WrapperPlayServerSpawnEntity.java b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/packet/WrapperPlayServerSpawnEntity.java index acd7a83c..a1187383 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/packet/WrapperPlayServerSpawnEntity.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/packet/WrapperPlayServerSpawnEntity.java @@ -38,42 +38,42 @@ public class WrapperPlayServerSpawnEntity extends AbstractPacket implements Enti * @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; + 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 ObjectTypes INSTANCE = new ObjectTypes(); - - /** - * Retrieve an instance of the object types enum. - * @return Object type enum. - */ - public static ObjectTypes getInstance() { - return INSTANCE; - } + /** + * The singleton instance. Can also be retrieved from the parent class. + */ + private static ObjectTypes INSTANCE = new ObjectTypes(); + + /** + * Retrieve an instance of the object types enum. + * @return Object type enum. + */ + public static ObjectTypes getInstance() { + return INSTANCE; + } } public WrapperPlayServerSpawnEntity() { @@ -86,23 +86,23 @@ public class WrapperPlayServerSpawnEntity extends AbstractPacket implements Enti } public WrapperPlayServerSpawnEntity(Entity entity, int type, int objectData) { - super(fromEntity(entity, type, objectData), TYPE); + 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)) { + 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); + return entityConstructor.createPacket(entity, objectData); } else { - return entityConstructor.createPacket(entity, type, objectData); + return entityConstructor.createPacket(entity, type, objectData); } } @@ -120,7 +120,7 @@ public class WrapperPlayServerSpawnEntity extends AbstractPacket implements Enti * @return The spawned entity. */ public Entity getEntity(World world) { - return handle.getEntityModifier(world).read(0); + return handle.getEntityModifier(world).read(0); } /** @@ -129,7 +129,7 @@ public class WrapperPlayServerSpawnEntity extends AbstractPacket implements Enti * @return The spawned entity. */ public Entity getEntity(PacketEvent event) { - return getEntity(event.getPlayer().getWorld()); + return getEntity(event.getPlayer().getWorld()); } /** @@ -156,4 +156,4 @@ public class WrapperPlayServerSpawnEntity extends AbstractPacket implements Enti handle.getIntegers().write(6, value); } -} \ No newline at end of file +} diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/packet/WrapperPlayServerSpawnEntityLiving.java b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/packet/WrapperPlayServerSpawnEntityLiving.java index 13956216..3c0a3f46 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/packet/WrapperPlayServerSpawnEntityLiving.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/current/packet/WrapperPlayServerSpawnEntityLiving.java @@ -48,7 +48,7 @@ public class WrapperPlayServerSpawnEntityLiving extends AbstractPacket implement // Useful constructor private static PacketContainer fromEntity(Entity entity) { if (entityConstructor == null) - entityConstructor = ProtocolLibrary.getProtocolManager().createPacketConstructor(TYPE, entity); + entityConstructor = ProtocolLibrary.getProtocolManager().createPacketConstructor(TYPE, entity); return entityConstructor.createPacket(entity); } @@ -66,7 +66,7 @@ public class WrapperPlayServerSpawnEntityLiving extends AbstractPacket implement * @return The spawned entity. */ public Entity getEntity(World world) { - return handle.getEntityModifier(world).read(0); + return handle.getEntityModifier(world).read(0); } /** @@ -75,7 +75,7 @@ public class WrapperPlayServerSpawnEntityLiving extends AbstractPacket implement * @return The spawned entity. */ public Entity getEntity(PacketEvent event) { - return getEntity(event.getPlayer().getWorld()); + return getEntity(event.getPlayer().getWorld()); } /** @@ -91,7 +91,7 @@ public class WrapperPlayServerSpawnEntityLiving extends AbstractPacket implement * @return The current Type */ @SuppressWarnings("deprecation") - public EntityType getType() { + public EntityType getType() { return EntityType.fromId(handle.getIntegers().read(1)); } @@ -100,7 +100,7 @@ public class WrapperPlayServerSpawnEntityLiving extends AbstractPacket implement * @param value - new value. */ @SuppressWarnings("deprecation") - public void setType(EntityType value) { + public void setType(EntityType value) { handle.getIntegers().write(1, (int) value.getTypeId()); } @@ -121,4 +121,4 @@ public class WrapperPlayServerSpawnEntityLiving extends AbstractPacket implement public void setMetadata(WrappedDataWatcher value) { handle.getDataWatcherModifier().write(0, value); } -} \ No newline at end of file +} diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/Colors.java b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/Colors.java index 29a438f8..d68e2d9c 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/Colors.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/Colors.java @@ -18,16 +18,16 @@ import org.bukkit.ChatColor; public class Colors { - public static final String - - PRIMARY = "" + ChatColor.AQUA, - PRIMARY_SHADOW = "" + ChatColor.DARK_AQUA, - - SECONDARY = "" + ChatColor.WHITE, - SECONDARY_SHADOW = "" + ChatColor.GRAY, - - BOLD = "" + ChatColor.BOLD, - - ERROR = "" + ChatColor.RED; - + public static final String + + PRIMARY = "" + ChatColor.AQUA, + PRIMARY_SHADOW = "" + ChatColor.DARK_AQUA, + + SECONDARY = "" + ChatColor.WHITE, + SECONDARY_SHADOW = "" + ChatColor.GRAY, + + BOLD = "" + ChatColor.BOLD, + + ERROR = "" + ChatColor.RED; + } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/CommandValidator.java b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/CommandValidator.java index 76f9ccde..a3fbf308 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/CommandValidator.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/CommandValidator.java @@ -24,60 +24,60 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; public class CommandValidator { - - public static CraftHologramLine parseHologramLine(NamedHologram hologram, String serializedLine, boolean validateMaterial) throws CommandException { - try { - return HologramLineParser.parseLine(hologram, serializedLine, validateMaterial); - } catch (HologramLineParseException e) { - throw new CommandException(e.getMessage()); - } - } - - public static NamedHologram getNamedHologram(String hologramName) throws CommandException { - NamedHologram hologram = NamedHologramManager.getHologram(hologramName); - notNull(hologram, Strings.noSuchHologram(hologramName)); - return hologram; - } - - public static void notNull(Object obj, String string) throws CommandException { - if (obj == null) { - throw new CommandException(string); - } - } - - public static void isTrue(boolean b, String string) throws CommandException { - if (!b) { - throw new CommandException(string); - } - } + + public static CraftHologramLine parseHologramLine(NamedHologram hologram, String serializedLine, boolean validateMaterial) throws CommandException { + try { + return HologramLineParser.parseLine(hologram, serializedLine, validateMaterial); + } catch (HologramLineParseException e) { + throw new CommandException(e.getMessage()); + } + } + + public static NamedHologram getNamedHologram(String hologramName) throws CommandException { + NamedHologram hologram = NamedHologramManager.getHologram(hologramName); + notNull(hologram, Strings.noSuchHologram(hologramName)); + return hologram; + } + + public static void notNull(Object obj, String string) throws CommandException { + if (obj == null) { + throw new CommandException(string); + } + } + + public static void isTrue(boolean b, String string) throws CommandException { + if (!b) { + throw new CommandException(string); + } + } - public static int getInteger(String integer) throws CommandException { - try { - return Integer.parseInt(integer); - } catch (NumberFormatException ex) { - throw new CommandException("Invalid number: '" + integer + "'."); - } - } - - public static boolean isInteger(String integer) { - try { - Integer.parseInt(integer); - return true; - } catch (NumberFormatException ex) { - return false; - } - } - - public static Player getPlayerSender(CommandSender sender) throws CommandException { - if (sender instanceof Player) { - return (Player) sender; - } else { - throw new CommandException("You must be a player to use this command."); - } - } - - public static boolean isPlayerSender(CommandSender sender) { - return sender instanceof Player; - } - + public static int getInteger(String integer) throws CommandException { + try { + return Integer.parseInt(integer); + } catch (NumberFormatException ex) { + throw new CommandException("Invalid number: '" + integer + "'."); + } + } + + public static boolean isInteger(String integer) { + try { + Integer.parseInt(integer); + return true; + } catch (NumberFormatException ex) { + return false; + } + } + + public static Player getPlayerSender(CommandSender sender) throws CommandException { + if (sender instanceof Player) { + return (Player) sender; + } else { + throw new CommandException("You must be a player to use this command."); + } + } + + public static boolean isPlayerSender(CommandSender sender) { + return sender instanceof Player; + } + } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/Strings.java b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/Strings.java index 944873b4..b6d10092 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/Strings.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/Strings.java @@ -19,21 +19,21 @@ import org.bukkit.command.CommandSender; public class Strings { - public static final String BASE_PERM = "holograms."; - - public static final String TIP_PREFIX = "" + ChatColor.YELLOW + ChatColor.BOLD + "TIP:" + Colors.SECONDARY_SHADOW + " "; - - - public static String formatTitle(String input) { - return "" + Colors.PRIMARY_SHADOW + ChatColor.BOLD + "----- " + input + Colors.PRIMARY_SHADOW + ChatColor.BOLD + " -----"; - } - - public static String noSuchHologram(String name) { - return ChatColor.RED + "Cannot find a hologram named \"" + name + "\"."; - } - - public static void sendWarning(CommandSender recipient, String warning) { - recipient.sendMessage(ChatColor.RED + "( " + ChatColor.DARK_RED + ChatColor.BOLD + "!" + ChatColor.RED + " ) " + Colors.SECONDARY_SHADOW + warning); - } - + public static final String BASE_PERM = "holograms."; + + public static final String TIP_PREFIX = "" + ChatColor.YELLOW + ChatColor.BOLD + "TIP:" + Colors.SECONDARY_SHADOW + " "; + + + public static String formatTitle(String input) { + return "" + Colors.PRIMARY_SHADOW + ChatColor.BOLD + "----- " + input + Colors.PRIMARY_SHADOW + ChatColor.BOLD + " -----"; + } + + public static String noSuchHologram(String name) { + return ChatColor.RED + "Cannot find a hologram named \"" + name + "\"."; + } + + public static void sendWarning(CommandSender recipient, String warning) { + recipient.sendMessage(ChatColor.RED + "( " + ChatColor.DARK_RED + ChatColor.BOLD + "!" + ChatColor.RED + " ) " + Colors.SECONDARY_SHADOW + warning); + } + } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/HologramSubCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/HologramSubCommand.java index 5f1d98c8..991e4276 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/HologramSubCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/HologramSubCommand.java @@ -20,66 +20,66 @@ import org.bukkit.command.CommandSender; import java.util.List; public abstract class HologramSubCommand { - - private String name; - private String permission; - private String[] aliases; - - public HologramSubCommand(String name) { - this(name, new String[0]); - } - - public HologramSubCommand(String name, String... aliases) { - this.name = name; - this.aliases = aliases; - } - - public String getName() { - return name; - } - - public void setPermission(String permission) { - this.permission = permission; - } - - public String getPermission() { - return permission; - } - - public final boolean hasPermission(CommandSender sender) { - if (permission == null) return true; - return sender.hasPermission(permission); - } - - public abstract String getPossibleArguments(); + + private String name; + private String permission; + private String[] aliases; + + public HologramSubCommand(String name) { + this(name, new String[0]); + } + + public HologramSubCommand(String name, String... aliases) { + this.name = name; + this.aliases = aliases; + } + + public String getName() { + return name; + } + + public void setPermission(String permission) { + this.permission = permission; + } + + public String getPermission() { + return permission; + } + + public final boolean hasPermission(CommandSender sender) { + if (permission == null) return true; + return sender.hasPermission(permission); + } + + public abstract String getPossibleArguments(); - public abstract int getMinimumArguments(); + public abstract int getMinimumArguments(); - public abstract void execute(CommandSender sender, String label, String[] args) throws CommandException; - - public abstract List getTutorial(); - - public abstract SubCommandType getType(); - - public enum SubCommandType { - GENERIC, EDIT_LINES, HIDDEN - } - - - public final boolean isValidTrigger(String name) { - if (this.name.equalsIgnoreCase(name)) { - return true; - } - - if (aliases != null) { - for (String alias : aliases) { - if (alias.equalsIgnoreCase(name)) { - return true; - } - } - } - - return false; - } + public abstract void execute(CommandSender sender, String label, String[] args) throws CommandException; + + public abstract List getTutorial(); + + public abstract SubCommandType getType(); + + public enum SubCommandType { + GENERIC, EDIT_LINES, HIDDEN + } + + + public final boolean isValidTrigger(String name) { + if (this.name.equalsIgnoreCase(name)) { + return true; + } + + if (aliases != null) { + for (String alias : aliases) { + if (alias.equalsIgnoreCase(name)) { + return true; + } + } + } + + return false; + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/HologramsCommandHandler.java b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/HologramsCommandHandler.java index 2b864ef7..9e5fcf14 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/HologramsCommandHandler.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/HologramsCommandHandler.java @@ -49,83 +49,83 @@ import java.util.Map; public class HologramsCommandHandler implements CommandExecutor { - private List subCommands; - private Map, HologramSubCommand> subCommandsByClass; + private List subCommands; + private Map, HologramSubCommand> subCommandsByClass; - public HologramsCommandHandler() { - subCommands = new ArrayList<>(); - subCommandsByClass = new HashMap<>(); - - registerSubCommand(new AddlineCommand()); - registerSubCommand(new CreateCommand()); - registerSubCommand(new DeleteCommand()); - registerSubCommand(new EditCommand()); - registerSubCommand(new ListCommand()); - registerSubCommand(new NearCommand()); - registerSubCommand(new TeleportCommand()); - registerSubCommand(new MovehereCommand()); - registerSubCommand(new AlignCommand()); - registerSubCommand(new CopyCommand()); - registerSubCommand(new ReloadCommand()); - - registerSubCommand(new RemovelineCommand()); - registerSubCommand(new SetlineCommand()); - registerSubCommand(new InsertlineCommand()); - registerSubCommand(new ReadtextCommand()); - registerSubCommand(new ReadimageCommand()); - registerSubCommand(new InfoCommand()); - - registerSubCommand(new DebugCommand()); - registerSubCommand(new HelpCommand()); - } - - public void registerSubCommand(HologramSubCommand subCommand) { - subCommands.add(subCommand); - subCommandsByClass.put(subCommand.getClass(), subCommand); - } - - public List getSubCommands() { - return new ArrayList<>(subCommands); - } - - public HologramSubCommand getSubCommand(Class subCommandClass) { - return subCommandsByClass.get(subCommandClass); - } - - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - - if (args.length == 0) { - sender.sendMessage(Colors.PRIMARY_SHADOW + "Server is running " + Colors.PRIMARY + "Holographic Displays " + Colors.PRIMARY_SHADOW + "v" + HolographicDisplays.getInstance().getDescription().getVersion() + " by " + Colors.PRIMARY + "filoghost"); - if (sender.hasPermission(Strings.BASE_PERM + "help")) { - sender.sendMessage(Colors.PRIMARY_SHADOW + "Commands: " + Colors.PRIMARY + "/" + label + " help"); - } - return true; - } - - for (HologramSubCommand subCommand : subCommands) { - if (subCommand.isValidTrigger(args[0])) { - - if (!subCommand.hasPermission(sender)) { - sender.sendMessage(Colors.ERROR + "You don't have permission."); - return true; - } - - if (args.length - 1 >= subCommand.getMinimumArguments()) { - try { - subCommand.execute(sender, label, Arrays.copyOfRange(args, 1, args.length)); - } catch (CommandException e) { - sender.sendMessage(Colors.ERROR + e.getMessage()); - } - } else { - sender.sendMessage(Colors.ERROR + "Usage: /" + label + " " + subCommand.getName() + " " + subCommand.getPossibleArguments()); - } - - return true; - } - } - - sender.sendMessage(Colors.ERROR + "Unknown sub-command. Type \"/" + label + " help\" for a list of commands."); - return true; - } + public HologramsCommandHandler() { + subCommands = new ArrayList<>(); + subCommandsByClass = new HashMap<>(); + + registerSubCommand(new AddlineCommand()); + registerSubCommand(new CreateCommand()); + registerSubCommand(new DeleteCommand()); + registerSubCommand(new EditCommand()); + registerSubCommand(new ListCommand()); + registerSubCommand(new NearCommand()); + registerSubCommand(new TeleportCommand()); + registerSubCommand(new MovehereCommand()); + registerSubCommand(new AlignCommand()); + registerSubCommand(new CopyCommand()); + registerSubCommand(new ReloadCommand()); + + registerSubCommand(new RemovelineCommand()); + registerSubCommand(new SetlineCommand()); + registerSubCommand(new InsertlineCommand()); + registerSubCommand(new ReadtextCommand()); + registerSubCommand(new ReadimageCommand()); + registerSubCommand(new InfoCommand()); + + registerSubCommand(new DebugCommand()); + registerSubCommand(new HelpCommand()); + } + + public void registerSubCommand(HologramSubCommand subCommand) { + subCommands.add(subCommand); + subCommandsByClass.put(subCommand.getClass(), subCommand); + } + + public List getSubCommands() { + return new ArrayList<>(subCommands); + } + + public HologramSubCommand getSubCommand(Class subCommandClass) { + return subCommandsByClass.get(subCommandClass); + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + + if (args.length == 0) { + sender.sendMessage(Colors.PRIMARY_SHADOW + "Server is running " + Colors.PRIMARY + "Holographic Displays " + Colors.PRIMARY_SHADOW + "v" + HolographicDisplays.getInstance().getDescription().getVersion() + " by " + Colors.PRIMARY + "filoghost"); + if (sender.hasPermission(Strings.BASE_PERM + "help")) { + sender.sendMessage(Colors.PRIMARY_SHADOW + "Commands: " + Colors.PRIMARY + "/" + label + " help"); + } + return true; + } + + for (HologramSubCommand subCommand : subCommands) { + if (subCommand.isValidTrigger(args[0])) { + + if (!subCommand.hasPermission(sender)) { + sender.sendMessage(Colors.ERROR + "You don't have permission."); + return true; + } + + if (args.length - 1 >= subCommand.getMinimumArguments()) { + try { + subCommand.execute(sender, label, Arrays.copyOfRange(args, 1, args.length)); + } catch (CommandException e) { + sender.sendMessage(Colors.ERROR + e.getMessage()); + } + } else { + sender.sendMessage(Colors.ERROR + "Usage: /" + label + " " + subCommand.getName() + " " + subCommand.getPossibleArguments()); + } + + return true; + } + } + + sender.sendMessage(Colors.ERROR + "Unknown sub-command. Type \"/" + label + " help\" for a list of commands."); + return true; + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/AddlineCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/AddlineCommand.java index 2ba8cd77..f6c03dad 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/AddlineCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/AddlineCommand.java @@ -32,46 +32,46 @@ import java.util.List; public class AddlineCommand extends HologramSubCommand { - public AddlineCommand() { - super("addline"); - setPermission(Strings.BASE_PERM + "addline"); - } + public AddlineCommand() { + super("addline"); + setPermission(Strings.BASE_PERM + "addline"); + } - @Override - public String getPossibleArguments() { - return " "; - } + @Override + public String getPossibleArguments() { + return " "; + } - @Override - public int getMinimumArguments() { - return 2; - } + @Override + public int getMinimumArguments() { + return 2; + } - @Override - public void execute(CommandSender sender, String label, String[] args) throws CommandException { - NamedHologram hologram = CommandValidator.getNamedHologram(args[0]); - String serializedLine = Utils.join(args, " ", 1, args.length); - - CraftHologramLine line = CommandValidator.parseHologramLine(hologram, serializedLine, true); - hologram.getLinesUnsafe().add(line); - hologram.refreshAll(); - - HologramDatabase.saveHologram(hologram); - HologramDatabase.trySaveToDisk(); - Bukkit.getPluginManager().callEvent(new NamedHologramEditedEvent(hologram)); - - sender.sendMessage(Colors.PRIMARY + "Line added!"); - EditCommand.sendQuickEditCommands(sender, label, hologram.getName()); - } + @Override + public void execute(CommandSender sender, String label, String[] args) throws CommandException { + NamedHologram hologram = CommandValidator.getNamedHologram(args[0]); + String serializedLine = Utils.join(args, " ", 1, args.length); + + CraftHologramLine line = CommandValidator.parseHologramLine(hologram, serializedLine, true); + hologram.getLinesUnsafe().add(line); + hologram.refreshAll(); + + HologramDatabase.saveHologram(hologram); + HologramDatabase.trySaveToDisk(); + Bukkit.getPluginManager().callEvent(new NamedHologramEditedEvent(hologram)); + + sender.sendMessage(Colors.PRIMARY + "Line added!"); + EditCommand.sendQuickEditCommands(sender, label, hologram.getName()); + } - @Override - public List getTutorial() { - return Arrays.asList("Adds a line to an existing hologram."); - } + @Override + public List getTutorial() { + return Arrays.asList("Adds a line to an existing hologram."); + } - @Override - public SubCommandType getType() { - return SubCommandType.EDIT_LINES; - } + @Override + public SubCommandType getType() { + return SubCommandType.EDIT_LINES; + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/AlignCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/AlignCommand.java index f086b90b..fa51e759 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/AlignCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/AlignCommand.java @@ -29,60 +29,60 @@ import java.util.List; public class AlignCommand extends HologramSubCommand { - public AlignCommand() { - super("align"); - setPermission(Strings.BASE_PERM + "align"); - } + public AlignCommand() { + super("align"); + setPermission(Strings.BASE_PERM + "align"); + } - @Override - public String getPossibleArguments() { - return " "; - } + @Override + public String getPossibleArguments() { + return " "; + } - @Override - public int getMinimumArguments() { - return 3; - } + @Override + public int getMinimumArguments() { + return 3; + } - @Override - public void execute(CommandSender sender, String label, String[] args) throws CommandException { - NamedHologram hologram = CommandValidator.getNamedHologram(args[1]); - NamedHologram referenceHologram = CommandValidator.getNamedHologram(args[2]); - - CommandValidator.isTrue(hologram != referenceHologram, "The hologram must not be the same!"); + @Override + public void execute(CommandSender sender, String label, String[] args) throws CommandException { + NamedHologram hologram = CommandValidator.getNamedHologram(args[1]); + NamedHologram referenceHologram = CommandValidator.getNamedHologram(args[2]); + + CommandValidator.isTrue(hologram != referenceHologram, "The hologram must not be the same!"); - Location loc = hologram.getLocation(); - - if (args[0].equalsIgnoreCase("x")) { - loc.setX(referenceHologram.getX()); - } else if (args[0].equalsIgnoreCase("y")) { - loc.setY(referenceHologram.getY()); - } else if (args[0].equalsIgnoreCase("z")) { - loc.setZ(referenceHologram.getZ()); - } else if (args[0].equalsIgnoreCase("xz")) { - loc.setX(referenceHologram.getX()); - loc.setZ(referenceHologram.getZ()); - } else { - throw new CommandException("You must specify either X, Y, Z or XZ, " + args[0] + " is not a valid axis."); - } + Location loc = hologram.getLocation(); + + if (args[0].equalsIgnoreCase("x")) { + loc.setX(referenceHologram.getX()); + } else if (args[0].equalsIgnoreCase("y")) { + loc.setY(referenceHologram.getY()); + } else if (args[0].equalsIgnoreCase("z")) { + loc.setZ(referenceHologram.getZ()); + } else if (args[0].equalsIgnoreCase("xz")) { + loc.setX(referenceHologram.getX()); + loc.setZ(referenceHologram.getZ()); + } else { + throw new CommandException("You must specify either X, Y, Z or XZ, " + args[0] + " is not a valid axis."); + } - hologram.teleport(loc.getWorld(), loc.getX(), loc.getY(), loc.getZ()); - hologram.despawnEntities(); - hologram.refreshAll(); - - HologramDatabase.saveHologram(hologram); - HologramDatabase.trySaveToDisk(); - sender.sendMessage(Colors.PRIMARY + "Hologram \"" + hologram.getName() + "\" aligned to the hologram \"" + referenceHologram.getName() + "\" on the " + args[0].toUpperCase() + " axis."); - } + hologram.teleport(loc.getWorld(), loc.getX(), loc.getY(), loc.getZ()); + hologram.despawnEntities(); + hologram.refreshAll(); + + HologramDatabase.saveHologram(hologram); + HologramDatabase.trySaveToDisk(); + sender.sendMessage(Colors.PRIMARY + "Hologram \"" + hologram.getName() + "\" aligned to the hologram \"" + referenceHologram.getName() + "\" on the " + args[0].toUpperCase() + " axis."); + } - @Override - public List getTutorial() { - return Arrays.asList("Aligns the first hologram to the second, in the specified axis."); - } + @Override + public List getTutorial() { + return Arrays.asList("Aligns the first hologram to the second, in the specified axis."); + } - @Override - public SubCommandType getType() { - return SubCommandType.GENERIC; - } + @Override + public SubCommandType getType() { + return SubCommandType.GENERIC; + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/CopyCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/CopyCommand.java index 2e823ed0..41b1f07c 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/CopyCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/CopyCommand.java @@ -28,50 +28,50 @@ import java.util.Arrays; import java.util.List; public class CopyCommand extends HologramSubCommand { - - public CopyCommand() { - super("copy"); - setPermission(Strings.BASE_PERM + "copy"); - } + + public CopyCommand() { + super("copy"); + setPermission(Strings.BASE_PERM + "copy"); + } - @Override - public String getPossibleArguments() { - return " "; - } + @Override + public String getPossibleArguments() { + return " "; + } - @Override - public int getMinimumArguments() { - return 2; - } + @Override + public int getMinimumArguments() { + return 2; + } - @Override - public void execute(CommandSender sender, String label, String[] args) throws CommandException { - NamedHologram fromHologram = CommandValidator.getNamedHologram(args[0]); - NamedHologram toHologram = CommandValidator.getNamedHologram(args[1]); - - toHologram.clearLines(); - for (CraftHologramLine line : fromHologram.getLinesUnsafe()) { - CraftHologramLine clonedLine = CommandValidator.parseHologramLine(toHologram, HologramDatabase.serializeHologramLine(line), false); - toHologram.getLinesUnsafe().add(clonedLine); - } - - toHologram.refreshAll(); - - HologramDatabase.saveHologram(toHologram); - HologramDatabase.trySaveToDisk(); - - sender.sendMessage(Colors.PRIMARY + "Hologram \"" + fromHologram.getName() + "\" copied into hologram \"" + toHologram.getName() + "\"!"); - } - - @Override - public List getTutorial() { - return Arrays.asList( - "Copies the contents of a hologram into another one."); - } + @Override + public void execute(CommandSender sender, String label, String[] args) throws CommandException { + NamedHologram fromHologram = CommandValidator.getNamedHologram(args[0]); + NamedHologram toHologram = CommandValidator.getNamedHologram(args[1]); + + toHologram.clearLines(); + for (CraftHologramLine line : fromHologram.getLinesUnsafe()) { + CraftHologramLine clonedLine = CommandValidator.parseHologramLine(toHologram, HologramDatabase.serializeHologramLine(line), false); + toHologram.getLinesUnsafe().add(clonedLine); + } + + toHologram.refreshAll(); + + HologramDatabase.saveHologram(toHologram); + HologramDatabase.trySaveToDisk(); + + sender.sendMessage(Colors.PRIMARY + "Hologram \"" + fromHologram.getName() + "\" copied into hologram \"" + toHologram.getName() + "\"!"); + } + + @Override + public List getTutorial() { + return Arrays.asList( + "Copies the contents of a hologram into another one."); + } - @Override - public SubCommandType getType() { - return SubCommandType.GENERIC; - } + @Override + public SubCommandType getType() { + return SubCommandType.GENERIC; + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/CreateCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/CreateCommand.java index dafbb0f7..75aaea22 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/CreateCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/CreateCommand.java @@ -33,80 +33,80 @@ import java.util.Arrays; import java.util.List; public class CreateCommand extends HologramSubCommand { - - public CreateCommand() { - super("create"); - setPermission(Strings.BASE_PERM + "create"); - } + + public CreateCommand() { + super("create"); + setPermission(Strings.BASE_PERM + "create"); + } - @Override - public String getPossibleArguments() { - return " [text]"; - } + @Override + public String getPossibleArguments() { + return " [text]"; + } - @Override - public int getMinimumArguments() { - return 1; - } + @Override + public int getMinimumArguments() { + return 1; + } - @SuppressWarnings("deprecation") - @Override - public void execute(CommandSender sender, String label, String[] args) throws CommandException { - Player player = CommandValidator.getPlayerSender(sender); - String hologramName = args[0]; + @SuppressWarnings("deprecation") + @Override + public void execute(CommandSender sender, String label, String[] args) throws CommandException { + Player player = CommandValidator.getPlayerSender(sender); + String hologramName = args[0]; - if (!hologramName.matches("[a-zA-Z0-9_\\-]+")) { - throw new CommandException("The name must contain only alphanumeric chars, underscores and hyphens."); - } + if (!hologramName.matches("[a-zA-Z0-9_\\-]+")) { + throw new CommandException("The name must contain only alphanumeric chars, underscores and hyphens."); + } - CommandValidator.isTrue(!NamedHologramManager.isExistingHologram(hologramName), "A hologram with that name already exists."); + CommandValidator.isTrue(!NamedHologramManager.isExistingHologram(hologramName), "A hologram with that name already exists."); - Location spawnLoc = player.getLocation(); - boolean moveUp = player.isOnGround(); + Location spawnLoc = player.getLocation(); + boolean moveUp = player.isOnGround(); - if (moveUp) { - spawnLoc.add(0.0, 1.2, 0.0); - } + if (moveUp) { + spawnLoc.add(0.0, 1.2, 0.0); + } - NamedHologram hologram = new NamedHologram(spawnLoc, hologramName); + NamedHologram hologram = new NamedHologram(spawnLoc, hologramName); - if (args.length > 1) { - String text = Utils.join(args, " ", 1, args.length); - CommandValidator.isTrue(!text.equalsIgnoreCase("{empty}"), "The first line should not be empty."); - - CraftHologramLine line = CommandValidator.parseHologramLine(hologram, text, true); - hologram.getLinesUnsafe().add(line); - player.sendMessage(Colors.SECONDARY_SHADOW + "(Change the lines with /" + label + " edit " + hologram.getName() + ")"); - } else { - hologram.appendTextLine("Default hologram. Change it with " + Colors.PRIMARY + "/" + label + " edit " + hologram.getName()); - } + if (args.length > 1) { + String text = Utils.join(args, " ", 1, args.length); + CommandValidator.isTrue(!text.equalsIgnoreCase("{empty}"), "The first line should not be empty."); + + CraftHologramLine line = CommandValidator.parseHologramLine(hologram, text, true); + hologram.getLinesUnsafe().add(line); + player.sendMessage(Colors.SECONDARY_SHADOW + "(Change the lines with /" + label + " edit " + hologram.getName() + ")"); + } else { + hologram.appendTextLine("Default hologram. Change it with " + Colors.PRIMARY + "/" + label + " edit " + hologram.getName()); + } - NamedHologramManager.addHologram(hologram); - hologram.refreshAll(); + NamedHologramManager.addHologram(hologram); + hologram.refreshAll(); - HologramDatabase.saveHologram(hologram); - HologramDatabase.trySaveToDisk(); - Location look = player.getLocation(); - look.setPitch(90); - player.teleport(look, TeleportCause.PLUGIN); - player.sendMessage(Colors.PRIMARY + "You created a hologram named '" + hologram.getName() + "'."); + HologramDatabase.saveHologram(hologram); + HologramDatabase.trySaveToDisk(); + Location look = player.getLocation(); + look.setPitch(90); + player.teleport(look, TeleportCause.PLUGIN); + player.sendMessage(Colors.PRIMARY + "You created a hologram named '" + hologram.getName() + "'."); - if (moveUp) { - player.sendMessage(Colors.SECONDARY_SHADOW + "(You were on the ground, the hologram was automatically moved up. If you use /" + label + " movehere " + hologram.getName() + ", the hologram will be moved to your feet)"); - } - } + if (moveUp) { + player.sendMessage(Colors.SECONDARY_SHADOW + "(You were on the ground, the hologram was automatically moved up. If you use /" + label + " movehere " + hologram.getName() + ", the hologram will be moved to your feet)"); + } + } - @Override - public List getTutorial() { - return Arrays.asList( - "Creates a new hologram with the given name, that must", - "be alphanumeric. The name will be used as reference to", - "that hologram for editing commands."); - } + @Override + public List getTutorial() { + return Arrays.asList( + "Creates a new hologram with the given name, that must", + "be alphanumeric. The name will be used as reference to", + "that hologram for editing commands."); + } - @Override - public SubCommandType getType() { - return SubCommandType.GENERIC; - } + @Override + public SubCommandType getType() { + return SubCommandType.GENERIC; + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/DebugCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/DebugCommand.java index e26c4d36..64fc6806 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/DebugCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/DebugCommand.java @@ -37,98 +37,98 @@ import java.util.Map.Entry; public class DebugCommand extends HologramSubCommand { - public DebugCommand() { - super("debug"); - setPermission(Strings.BASE_PERM + "debug"); - } + public DebugCommand() { + super("debug"); + setPermission(Strings.BASE_PERM + "debug"); + } - @Override - public String getPossibleArguments() { - return ""; - } + @Override + public String getPossibleArguments() { + return ""; + } - @Override - public int getMinimumArguments() { - return 0; - } + @Override + public int getMinimumArguments() { + return 0; + } - @Override - public void execute(CommandSender sender, String label, String[] args) throws CommandException { - boolean foundAnyHologram = false; - - for (World world : Bukkit.getWorlds()) { - Map hologramsDebugInfo = new HashMap<>(); - - for (Chunk chunk : world.getLoadedChunks()) { - for (Entity entity : chunk.getEntities()) { - NMSEntityBase nmsEntity = HolographicDisplays.getNMSManager().getNMSEntityBase(entity); - - if (nmsEntity == null) { - continue; - } - - Hologram ownerHologram = nmsEntity.getHologramLine().getParent(); - HologramDebugInfo hologramDebugInfo = hologramsDebugInfo.computeIfAbsent(ownerHologram, mapKey -> new HologramDebugInfo()); - - if (nmsEntity.isDeadNMS()) { - hologramDebugInfo.deadEntities++; - } else { - hologramDebugInfo.aliveEntities++; - } - } - } - - if (!hologramsDebugInfo.isEmpty()) { - foundAnyHologram = true; - sender.sendMessage(Colors.PRIMARY + "Holograms in world '" + world.getName() + "':"); - - for (Entry entry : hologramsDebugInfo.entrySet()) { - Hologram hologram = entry.getKey(); - String displayName = getHologramDisplayName(hologram); - HologramDebugInfo debugInfo = entry.getValue(); - sender.sendMessage(Colors.PRIMARY_SHADOW + "- '" + displayName + "': " + hologram.size() + " lines, " - + debugInfo.getTotalEntities() + " entities (" + debugInfo.aliveEntities + " alive, " + debugInfo.deadEntities + " dead)"); - } - } - } - - if (!foundAnyHologram) { - sender.sendMessage(Colors.ERROR + "Couldn't find any loaded hologram (holograms may be in unloaded chunks)."); - } - - } + @Override + public void execute(CommandSender sender, String label, String[] args) throws CommandException { + boolean foundAnyHologram = false; + + for (World world : Bukkit.getWorlds()) { + Map hologramsDebugInfo = new HashMap<>(); + + for (Chunk chunk : world.getLoadedChunks()) { + for (Entity entity : chunk.getEntities()) { + NMSEntityBase nmsEntity = HolographicDisplays.getNMSManager().getNMSEntityBase(entity); + + if (nmsEntity == null) { + continue; + } + + Hologram ownerHologram = nmsEntity.getHologramLine().getParent(); + HologramDebugInfo hologramDebugInfo = hologramsDebugInfo.computeIfAbsent(ownerHologram, mapKey -> new HologramDebugInfo()); + + if (nmsEntity.isDeadNMS()) { + hologramDebugInfo.deadEntities++; + } else { + hologramDebugInfo.aliveEntities++; + } + } + } + + if (!hologramsDebugInfo.isEmpty()) { + foundAnyHologram = true; + sender.sendMessage(Colors.PRIMARY + "Holograms in world '" + world.getName() + "':"); + + for (Entry entry : hologramsDebugInfo.entrySet()) { + Hologram hologram = entry.getKey(); + String displayName = getHologramDisplayName(hologram); + HologramDebugInfo debugInfo = entry.getValue(); + sender.sendMessage(Colors.PRIMARY_SHADOW + "- '" + displayName + "': " + hologram.size() + " lines, " + + debugInfo.getTotalEntities() + " entities (" + debugInfo.aliveEntities + " alive, " + debugInfo.deadEntities + " dead)"); + } + } + } + + if (!foundAnyHologram) { + sender.sendMessage(Colors.ERROR + "Couldn't find any loaded hologram (holograms may be in unloaded chunks)."); + } + + } - private String getHologramDisplayName(Hologram hologram) { - if (hologram instanceof NamedHologram) { - return ((NamedHologram) hologram).getName(); - } else if (hologram instanceof PluginHologram) { - return ((PluginHologram) hologram).getOwner().getName() + "@" + Integer.toHexString(hologram.hashCode()); - } else { - return hologram.toString(); - } - } + private String getHologramDisplayName(Hologram hologram) { + if (hologram instanceof NamedHologram) { + return ((NamedHologram) hologram).getName(); + } else if (hologram instanceof PluginHologram) { + return ((PluginHologram) hologram).getOwner().getName() + "@" + Integer.toHexString(hologram.hashCode()); + } else { + return hologram.toString(); + } + } - @Override - public List getTutorial() { - return Arrays.asList("Displays information useful for debugging."); - } - - @Override - public SubCommandType getType() { - return SubCommandType.HIDDEN; - } - - - private static class HologramDebugInfo { - - private int aliveEntities; - private int deadEntities; - - public int getTotalEntities() { - return aliveEntities + deadEntities; - } - - } - + @Override + public List getTutorial() { + return Arrays.asList("Displays information useful for debugging."); + } + + @Override + public SubCommandType getType() { + return SubCommandType.HIDDEN; + } + + + 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/commands/main/subs/DeleteCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/DeleteCommand.java index ba619161..d54df7de 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/DeleteCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/DeleteCommand.java @@ -29,43 +29,43 @@ import java.util.List; public class DeleteCommand extends HologramSubCommand { - public DeleteCommand() { - super("delete", "remove"); - setPermission(Strings.BASE_PERM + "delete"); - } + public DeleteCommand() { + super("delete", "remove"); + setPermission(Strings.BASE_PERM + "delete"); + } - @Override - public String getPossibleArguments() { - return ""; - } + @Override + public String getPossibleArguments() { + return ""; + } - @Override - public int getMinimumArguments() { - return 1; - } + @Override + public int getMinimumArguments() { + return 1; + } - @Override - public void execute(CommandSender sender, String label, String[] args) throws CommandException { - NamedHologram hologram = CommandValidator.getNamedHologram(args[0]); - - hologram.delete(); - NamedHologramManager.removeHologram(hologram); - HologramDatabase.deleteHologram(hologram.getName()); - - HologramDatabase.trySaveToDisk(); - sender.sendMessage(Colors.PRIMARY + "You deleted the hologram '" + hologram.getName() + "'."); - } + @Override + public void execute(CommandSender sender, String label, String[] args) throws CommandException { + NamedHologram hologram = CommandValidator.getNamedHologram(args[0]); + + hologram.delete(); + NamedHologramManager.removeHologram(hologram); + HologramDatabase.deleteHologram(hologram.getName()); + + HologramDatabase.trySaveToDisk(); + sender.sendMessage(Colors.PRIMARY + "You deleted the hologram '" + hologram.getName() + "'."); + } - @Override - public List getTutorial() { - return Arrays.asList("Deletes a hologram. Cannot be undone."); - } - - @Override - public SubCommandType getType() { - return SubCommandType.GENERIC; - } + @Override + public List getTutorial() { + return Arrays.asList("Deletes a hologram. Cannot be undone."); + } + + @Override + public SubCommandType getType() { + return SubCommandType.GENERIC; + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/EditCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/EditCommand.java index a9d44da7..185d5738 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/EditCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/EditCommand.java @@ -37,121 +37,121 @@ import java.util.Arrays; import java.util.List; public class EditCommand extends HologramSubCommand { - - private static final List QUICK_EDIT_COMMANDS = Lists.newArrayList( - new QuickCommandInfo("Add", AddlineCommand.class), - new QuickCommandInfo("Remove", RemovelineCommand.class), - new QuickCommandInfo("Set", SetlineCommand.class), - new QuickCommandInfo("Insert", InsertlineCommand.class), - new QuickCommandInfo("View", InfoCommand.class) - ); - - public EditCommand() { - super("edit"); - setPermission(Strings.BASE_PERM + "edit"); - } + + private static final List QUICK_EDIT_COMMANDS = Lists.newArrayList( + new QuickCommandInfo("Add", AddlineCommand.class), + new QuickCommandInfo("Remove", RemovelineCommand.class), + new QuickCommandInfo("Set", SetlineCommand.class), + new QuickCommandInfo("Insert", InsertlineCommand.class), + new QuickCommandInfo("View", InfoCommand.class) + ); + + public EditCommand() { + super("edit"); + setPermission(Strings.BASE_PERM + "edit"); + } - @Override - public String getPossibleArguments() { - return ""; - } + @Override + public String getPossibleArguments() { + return ""; + } - @Override - public int getMinimumArguments() { - return 1; - } + @Override + public int getMinimumArguments() { + return 1; + } - @Override - public void execute(CommandSender sender, String label, String[] args) throws CommandException { - NamedHologram hologram = CommandValidator.getNamedHologram(args[0]); - - sender.sendMessage(""); - sender.sendMessage(Strings.formatTitle("How to edit the hologram '" + hologram.getName() + "'")); - for (HologramSubCommand subCommand : HolographicDisplays.getCommandHandler().getSubCommands()) { - if (subCommand.getType() == SubCommandType.EDIT_LINES) { - String usage = "/" + label + " " + subCommand.getName() + (subCommand.getPossibleArguments().length() > 0 ? " " + subCommand.getPossibleArguments().replace("", hologram.getName()).replace("", hologram.getName()) : ""); - - if (CommandValidator.isPlayerSender(sender)) { - - List help = new ArrayList<>(); - help.add(Colors.PRIMARY + usage); - for (String tutLine : subCommand.getTutorial()) { - help.add(Colors.SECONDARY_SHADOW + tutLine); - } - - ((Player) sender).spigot().sendMessage(new ComponentBuilder(usage) - .color(ChatColor.AQUA) - .event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, usage)) - .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(String.join("\n", help)))) - .create()); - - } else { - sender.sendMessage(Colors.PRIMARY + usage); - } - } - } - - if (CommandValidator.isPlayerSender(sender)) { - HelpCommand.sendHoverTip((Player) sender); - } - } - - public static void sendQuickEditCommands(CommandSender sender, String label, String hologramName) { - if (!Configuration.quickEditCommands) { - return; - } - if (!(sender instanceof Player)) { - return; - } - - ComponentBuilder message = new ComponentBuilder("EDIT LINES:").color(ChatColor.GRAY).bold(true).append(" ", FormatRetention.NONE); - - for (QuickCommandInfo quickEditCommand : QUICK_EDIT_COMMANDS) { - HologramSubCommand subCommand = HolographicDisplays.getCommandHandler().getSubCommand(quickEditCommand.commandClass); - - // Assume first argument is always "" and remove it - String arguments = subCommand.getPossibleArguments(); - if (arguments.contains(" ")) { - arguments = arguments.substring(arguments.indexOf(" ") + 1); - } else { - arguments = ""; - } - - String usage = "/" + label + " " + subCommand.getName() + " " + hologramName + " "; - message.append("[" + quickEditCommand.chatName + "]").color(ChatColor.DARK_AQUA) - .event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, usage)) - .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText( - ChatColor.GRAY + "Click to insert in chat the highlighted part of the command:\n" + - ChatColor.YELLOW + usage + ChatColor.DARK_GRAY + arguments))); - message.append(" ", FormatRetention.NONE); - } - - ((Player) sender).spigot().sendMessage(message.create()); - } + @Override + public void execute(CommandSender sender, String label, String[] args) throws CommandException { + NamedHologram hologram = CommandValidator.getNamedHologram(args[0]); + + sender.sendMessage(""); + sender.sendMessage(Strings.formatTitle("How to edit the hologram '" + hologram.getName() + "'")); + for (HologramSubCommand subCommand : HolographicDisplays.getCommandHandler().getSubCommands()) { + if (subCommand.getType() == SubCommandType.EDIT_LINES) { + String usage = "/" + label + " " + subCommand.getName() + (subCommand.getPossibleArguments().length() > 0 ? " " + subCommand.getPossibleArguments().replace("", hologram.getName()).replace("", hologram.getName()) : ""); + + if (CommandValidator.isPlayerSender(sender)) { + + List help = new ArrayList<>(); + help.add(Colors.PRIMARY + usage); + for (String tutLine : subCommand.getTutorial()) { + help.add(Colors.SECONDARY_SHADOW + tutLine); + } + + ((Player) sender).spigot().sendMessage(new ComponentBuilder(usage) + .color(ChatColor.AQUA) + .event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, usage)) + .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(String.join("\n", help)))) + .create()); + + } else { + sender.sendMessage(Colors.PRIMARY + usage); + } + } + } + + if (CommandValidator.isPlayerSender(sender)) { + HelpCommand.sendHoverTip((Player) sender); + } + } + + public static void sendQuickEditCommands(CommandSender sender, String label, String hologramName) { + if (!Configuration.quickEditCommands) { + return; + } + if (!(sender instanceof Player)) { + return; + } + + ComponentBuilder message = new ComponentBuilder("EDIT LINES:").color(ChatColor.GRAY).bold(true).append(" ", FormatRetention.NONE); + + for (QuickCommandInfo quickEditCommand : QUICK_EDIT_COMMANDS) { + HologramSubCommand subCommand = HolographicDisplays.getCommandHandler().getSubCommand(quickEditCommand.commandClass); + + // Assume first argument is always "" and remove it + String arguments = subCommand.getPossibleArguments(); + if (arguments.contains(" ")) { + arguments = arguments.substring(arguments.indexOf(" ") + 1); + } else { + arguments = ""; + } + + String usage = "/" + label + " " + subCommand.getName() + " " + hologramName + " "; + message.append("[" + quickEditCommand.chatName + "]").color(ChatColor.DARK_AQUA) + .event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, usage)) + .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText( + ChatColor.GRAY + "Click to insert in chat the highlighted part of the command:\n" + + ChatColor.YELLOW + usage + ChatColor.DARK_GRAY + arguments))); + message.append(" ", FormatRetention.NONE); + } + + ((Player) sender).spigot().sendMessage(message.create()); + } - @Override - public List getTutorial() { - return Arrays.asList("Shows the commands to manipulate an existing hologram."); - } - - @Override - public SubCommandType getType() { - return SubCommandType.GENERIC; - } - - - - private static class QuickCommandInfo { - - private final String chatName; - private final Class commandClass; - - public QuickCommandInfo(String chatName, Class command) { - this.chatName = chatName; - this.commandClass = command; - } - - } + @Override + public List getTutorial() { + return Arrays.asList("Shows the commands to manipulate an existing hologram."); + } + + @Override + public SubCommandType getType() { + return SubCommandType.GENERIC; + } + + + + private static class QuickCommandInfo { + + private final String chatName; + private final Class commandClass; + + public QuickCommandInfo(String chatName, Class command) { + this.chatName = chatName; + this.commandClass = command; + } + + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/HelpCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/HelpCommand.java index 619ead4c..bf5c2806 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/HelpCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/HelpCommand.java @@ -34,77 +34,77 @@ import java.util.List; public class HelpCommand extends HologramSubCommand { - public HelpCommand() { - super("help"); - setPermission(Strings.BASE_PERM + "help"); - } + public HelpCommand() { + super("help"); + setPermission(Strings.BASE_PERM + "help"); + } - @Override - public String getPossibleArguments() { - return ""; - } + @Override + public String getPossibleArguments() { + return ""; + } - @Override - public int getMinimumArguments() { - return 0; - } + @Override + public int getMinimumArguments() { + return 0; + } - @Override - public void execute(CommandSender sender, String label, String[] args) throws CommandException { - sender.sendMessage(""); - sender.sendMessage(Strings.formatTitle("Holographic Displays Commands")); - for (HologramSubCommand subCommand : HolographicDisplays.getCommandHandler().getSubCommands()) { - if (subCommand.getType() == SubCommandType.GENERIC) { - String usage = "/" + label + " " + subCommand.getName() + (subCommand.getPossibleArguments().length() > 0 ? " " + subCommand.getPossibleArguments() : ""); - - if (CommandValidator.isPlayerSender(sender)) { - - List help = new ArrayList<>(); - help.add(Colors.PRIMARY + usage); - for (String tutLine : subCommand.getTutorial()) { - help.add(Colors.SECONDARY_SHADOW + tutLine); - } - - ((Player) sender).spigot().sendMessage(new ComponentBuilder(usage) - .color(ChatColor.AQUA) - .event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, usage)) - .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(String.join("\n", help)))) - .create()); - - } else { - sender.sendMessage(Colors.PRIMARY + usage); - } - } - } - - if (CommandValidator.isPlayerSender(sender)) { - sendHoverTip((Player) sender); - } - } - - public static void sendHoverTip(Player player) { - player.sendMessage(""); - player.spigot().sendMessage(new ComponentBuilder("TIP:").color(ChatColor.YELLOW).bold(true) - .append(" Try to ", FormatRetention.NONE).color(ChatColor.GRAY) - .append("hover").color(ChatColor.WHITE).underlined(true) - .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(ChatColor.LIGHT_PURPLE + "Hover on the commands to get info about them."))) - .append(" or ", FormatRetention.NONE).color(ChatColor.GRAY) - .append("click").color(ChatColor.WHITE).underlined(true) - .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(ChatColor.LIGHT_PURPLE + "Click on the commands to insert them in the chat."))) - .append(" on the commands!", FormatRetention.NONE).color(ChatColor.GRAY) - .create()); - } + @Override + public void execute(CommandSender sender, String label, String[] args) throws CommandException { + sender.sendMessage(""); + sender.sendMessage(Strings.formatTitle("Holographic Displays Commands")); + for (HologramSubCommand subCommand : HolographicDisplays.getCommandHandler().getSubCommands()) { + if (subCommand.getType() == SubCommandType.GENERIC) { + String usage = "/" + label + " " + subCommand.getName() + (subCommand.getPossibleArguments().length() > 0 ? " " + subCommand.getPossibleArguments() : ""); + + if (CommandValidator.isPlayerSender(sender)) { + + List help = new ArrayList<>(); + help.add(Colors.PRIMARY + usage); + for (String tutLine : subCommand.getTutorial()) { + help.add(Colors.SECONDARY_SHADOW + tutLine); + } + + ((Player) sender).spigot().sendMessage(new ComponentBuilder(usage) + .color(ChatColor.AQUA) + .event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, usage)) + .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(String.join("\n", help)))) + .create()); + + } else { + sender.sendMessage(Colors.PRIMARY + usage); + } + } + } + + if (CommandValidator.isPlayerSender(sender)) { + sendHoverTip((Player) sender); + } + } + + public static void sendHoverTip(Player player) { + player.sendMessage(""); + player.spigot().sendMessage(new ComponentBuilder("TIP:").color(ChatColor.YELLOW).bold(true) + .append(" Try to ", FormatRetention.NONE).color(ChatColor.GRAY) + .append("hover").color(ChatColor.WHITE).underlined(true) + .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(ChatColor.LIGHT_PURPLE + "Hover on the commands to get info about them."))) + .append(" or ", FormatRetention.NONE).color(ChatColor.GRAY) + .append("click").color(ChatColor.WHITE).underlined(true) + .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(ChatColor.LIGHT_PURPLE + "Click on the commands to insert them in the chat."))) + .append(" on the commands!", FormatRetention.NONE).color(ChatColor.GRAY) + .create()); + } - @Override - public List getTutorial() { - return null; - } + @Override + public List getTutorial() { + return null; + } - @Override - public SubCommandType getType() { - return SubCommandType.HIDDEN; - } + @Override + public SubCommandType getType() { + return SubCommandType.HIDDEN; + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/InfoCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/InfoCommand.java index 973d226c..2242bc02 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/InfoCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/InfoCommand.java @@ -29,44 +29,44 @@ import java.util.List; public class InfoCommand extends HologramSubCommand { - public InfoCommand() { - super("info", "details"); - setPermission(Strings.BASE_PERM + "info"); - } + public InfoCommand() { + super("info", "details"); + setPermission(Strings.BASE_PERM + "info"); + } - @Override - public String getPossibleArguments() { - return ""; - } + @Override + public String getPossibleArguments() { + return ""; + } - @Override - public int getMinimumArguments() { - return 1; - } + @Override + public int getMinimumArguments() { + return 1; + } - @Override - public void execute(CommandSender sender, String label, String[] args) throws CommandException { - NamedHologram hologram = CommandValidator.getNamedHologram(args[0]); - - sender.sendMessage(""); - sender.sendMessage(Strings.formatTitle("Lines of the hologram '" + hologram.getName() + "'")); - int index = 0; - - for (CraftHologramLine line : hologram.getLinesUnsafe()) { - sender.sendMessage(Colors.SECONDARY + Colors.BOLD + (++index) + Colors.SECONDARY_SHADOW + ". " + Colors.SECONDARY + HologramDatabase.serializeHologramLine(line)); - } - EditCommand.sendQuickEditCommands(sender, label, hologram.getName()); - } + @Override + public void execute(CommandSender sender, String label, String[] args) throws CommandException { + NamedHologram hologram = CommandValidator.getNamedHologram(args[0]); + + sender.sendMessage(""); + sender.sendMessage(Strings.formatTitle("Lines of the hologram '" + hologram.getName() + "'")); + int index = 0; + + for (CraftHologramLine line : hologram.getLinesUnsafe()) { + sender.sendMessage(Colors.SECONDARY + Colors.BOLD + (++index) + Colors.SECONDARY_SHADOW + ". " + Colors.SECONDARY + HologramDatabase.serializeHologramLine(line)); + } + EditCommand.sendQuickEditCommands(sender, label, hologram.getName()); + } - @Override - public List getTutorial() { - return Arrays.asList("Shows the lines of a hologram."); - } - - @Override - public SubCommandType getType() { - return SubCommandType.EDIT_LINES; - } + @Override + public List getTutorial() { + return Arrays.asList("Shows the lines of a hologram."); + } + + @Override + public SubCommandType getType() { + return SubCommandType.EDIT_LINES; + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/InsertlineCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/InsertlineCommand.java index 680ee56a..7e784f34 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/InsertlineCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/InsertlineCommand.java @@ -33,62 +33,62 @@ import java.util.List; public class InsertlineCommand extends HologramSubCommand { - public InsertlineCommand() { - super("insertline"); - setPermission(Strings.BASE_PERM + "insertline"); - } + public InsertlineCommand() { + super("insertline"); + setPermission(Strings.BASE_PERM + "insertline"); + } - @Override - public String getPossibleArguments() { - return " "; - } + @Override + public String getPossibleArguments() { + return " "; + } - @Override - public int getMinimumArguments() { - return 3; - } + @Override + public int getMinimumArguments() { + return 3; + } - @Override - public void execute(CommandSender sender, String label, String[] args) throws CommandException { - NamedHologram hologram = CommandValidator.getNamedHologram(args[0]); - int insertAfter = CommandValidator.getInteger(args[1]); - String serializedLine = Utils.join(args, " ", 2, args.length); - - int oldLinesAmount = hologram.size(); - - CommandValidator.isTrue(insertAfter >= 0 && insertAfter <= oldLinesAmount, "The number must be between 0 and " + hologram.size() + "(amount of lines of the hologram)."); + @Override + public void execute(CommandSender sender, String label, String[] args) throws CommandException { + NamedHologram hologram = CommandValidator.getNamedHologram(args[0]); + int insertAfter = CommandValidator.getInteger(args[1]); + String serializedLine = Utils.join(args, " ", 2, args.length); + + int oldLinesAmount = hologram.size(); + + CommandValidator.isTrue(insertAfter >= 0 && insertAfter <= oldLinesAmount, "The number must be between 0 and " + hologram.size() + "(amount of lines of the hologram)."); - CraftHologramLine line = CommandValidator.parseHologramLine(hologram, serializedLine, true); - hologram.getLinesUnsafe().add(insertAfter, line); - hologram.refreshAll(); - - HologramDatabase.saveHologram(hologram); - HologramDatabase.trySaveToDisk(); - - Bukkit.getPluginManager().callEvent(new NamedHologramEditedEvent(hologram)); - - if (insertAfter == 0) { - sender.sendMessage(Colors.PRIMARY + "Line inserted before line n.1!"); - } else if (insertAfter == oldLinesAmount) { - sender.sendMessage(Colors.PRIMARY + "Line appended at the end!"); - sender.sendMessage(Strings.TIP_PREFIX + "Next time use \"/" + label + " addline\" to add a line at the end."); - } else { - sender.sendMessage(Colors.PRIMARY + "Line inserted between lines " + insertAfter + " and " + (insertAfter + 1) + "!"); - } - EditCommand.sendQuickEditCommands(sender, label, hologram.getName()); - } + CraftHologramLine line = CommandValidator.parseHologramLine(hologram, serializedLine, true); + hologram.getLinesUnsafe().add(insertAfter, line); + hologram.refreshAll(); + + HologramDatabase.saveHologram(hologram); + HologramDatabase.trySaveToDisk(); + + Bukkit.getPluginManager().callEvent(new NamedHologramEditedEvent(hologram)); + + if (insertAfter == 0) { + sender.sendMessage(Colors.PRIMARY + "Line inserted before line n.1!"); + } else if (insertAfter == oldLinesAmount) { + sender.sendMessage(Colors.PRIMARY + "Line appended at the end!"); + sender.sendMessage(Strings.TIP_PREFIX + "Next time use \"/" + label + " addline\" to add a line at the end."); + } else { + sender.sendMessage(Colors.PRIMARY + "Line inserted between lines " + insertAfter + " and " + (insertAfter + 1) + "!"); + } + EditCommand.sendQuickEditCommands(sender, label, hologram.getName()); + } - @Override - public List getTutorial() { - return Arrays.asList("Inserts a line after the specified index.", - "If the index is 0, the line will be put before", - "the first line of the hologram."); - } + @Override + public List getTutorial() { + return Arrays.asList("Inserts a line after the specified index.", + "If the index is 0, the line will be put before", + "the first line of the hologram."); + } - @Override - public SubCommandType getType() { - return SubCommandType.EDIT_LINES; - } + @Override + public SubCommandType getType() { + return SubCommandType.EDIT_LINES; + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/ListCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/ListCommand.java index 5f346459..7afa7d69 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/ListCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/ListCommand.java @@ -28,67 +28,67 @@ import java.util.List; public class ListCommand extends HologramSubCommand { - private static final int HOLOGRAMS_PER_PAGE = 10; + private static final int HOLOGRAMS_PER_PAGE = 10; - public ListCommand() { - super("list"); - setPermission(Strings.BASE_PERM + "list"); - } + public ListCommand() { + super("list"); + setPermission(Strings.BASE_PERM + "list"); + } - @Override - public String getPossibleArguments() { - return "[page]"; - } + @Override + public String getPossibleArguments() { + return "[page]"; + } - @Override - public int getMinimumArguments() { - return 0; - } + @Override + public int getMinimumArguments() { + return 0; + } - @Override - public void execute(CommandSender sender, String label, String[] args) throws CommandException { + @Override + public void execute(CommandSender sender, String label, String[] args) throws CommandException { - int page = args.length > 0 ? CommandValidator.getInteger(args[0]) : 1; + int page = args.length > 0 ? CommandValidator.getInteger(args[0]) : 1; - if (page < 1) { - throw new CommandException("Page number must be 1 or greater."); - } + if (page < 1) { + throw new CommandException("Page number must be 1 or greater."); + } - int totalPages = NamedHologramManager.size() / HOLOGRAMS_PER_PAGE; - if (NamedHologramManager.size() % HOLOGRAMS_PER_PAGE != 0) { - totalPages++; - } - - - if (NamedHologramManager.size() == 0) { - throw new CommandException("There are no holograms yet. Create one with /" + label + " create."); - } + int totalPages = NamedHologramManager.size() / HOLOGRAMS_PER_PAGE; + if (NamedHologramManager.size() % HOLOGRAMS_PER_PAGE != 0) { + totalPages++; + } + + + if (NamedHologramManager.size() == 0) { + throw new CommandException("There are no holograms yet. Create one with /" + label + " create."); + } - sender.sendMessage(""); - sender.sendMessage(Strings.formatTitle("Holograms list " + Colors.SECONDARY + "(Page " + page + " of " + totalPages + ")")); - int fromIndex = (page - 1) * HOLOGRAMS_PER_PAGE; - int toIndex = fromIndex + HOLOGRAMS_PER_PAGE; + sender.sendMessage(""); + sender.sendMessage(Strings.formatTitle("Holograms list " + Colors.SECONDARY + "(Page " + page + " of " + totalPages + ")")); + int fromIndex = (page - 1) * HOLOGRAMS_PER_PAGE; + int toIndex = fromIndex + HOLOGRAMS_PER_PAGE; - for (int i = fromIndex; i < toIndex; i++) { - if (i < NamedHologramManager.size()) { - NamedHologram hologram = NamedHologramManager.get(i); - sender.sendMessage(Colors.SECONDARY_SHADOW + "- " + Colors.SECONDARY + Colors.BOLD + hologram.getName() + " " + Colors.SECONDARY_SHADOW + "at x: " + (int) hologram.getX() + ", y: " + (int) hologram.getY() + ", z: " + (int) hologram.getZ() + " (lines: " + hologram.size() + ", world: \"" + hologram.getWorld().getName() + "\")"); - } - } - if (page < totalPages) { - sender.sendMessage(Strings.TIP_PREFIX + "See the next page with /" + label + " list " + (page + 1)); - } + for (int i = fromIndex; i < toIndex; i++) { + if (i < NamedHologramManager.size()) { + NamedHologram hologram = NamedHologramManager.get(i); + sender.sendMessage(Colors.SECONDARY_SHADOW + "- " + Colors.SECONDARY + Colors.BOLD + hologram.getName() + " " + Colors.SECONDARY_SHADOW + "at x: " + (int) hologram.getX() + ", y: " + (int) hologram.getY() + ", z: " + (int) hologram.getZ() + " (lines: " + hologram.size() + ", world: \"" + hologram.getWorld().getName() + "\")"); + } + } + if (page < totalPages) { + sender.sendMessage(Strings.TIP_PREFIX + "See the next page with /" + label + " list " + (page + 1)); + } - } + } - @Override - public List getTutorial() { - return Arrays.asList("Lists all the existing holograms."); - } - - @Override - public SubCommandType getType() { - return SubCommandType.GENERIC; - } + @Override + public List getTutorial() { + return Arrays.asList("Lists all the existing holograms."); + } + + @Override + public SubCommandType getType() { + return SubCommandType.GENERIC; + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/MovehereCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/MovehereCommand.java index 7712c6e9..57ccdcd4 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/MovehereCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/MovehereCommand.java @@ -32,47 +32,47 @@ import java.util.List; public class MovehereCommand extends HologramSubCommand { - public MovehereCommand() { - super("movehere"); - setPermission(Strings.BASE_PERM + "movehere"); - } + public MovehereCommand() { + super("movehere"); + setPermission(Strings.BASE_PERM + "movehere"); + } - @Override - public String getPossibleArguments() { - return ""; - } + @Override + public String getPossibleArguments() { + return ""; + } - @Override - public int getMinimumArguments() { - return 1; - } + @Override + public int getMinimumArguments() { + return 1; + } - @Override - public void execute(CommandSender sender, String label, String[] args) throws CommandException { - Player player = CommandValidator.getPlayerSender(sender); - NamedHologram hologram = CommandValidator.getNamedHologram(args[0]); - - hologram.teleport(player.getWorld(), player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ()); - hologram.despawnEntities(); - hologram.refreshAll(); - - HologramDatabase.saveHologram(hologram); - HologramDatabase.trySaveToDisk(); - Location to = player.getLocation(); - to.setPitch(90); - player.teleport(to, TeleportCause.PLUGIN); - player.sendMessage(Colors.PRIMARY + "You moved the hologram '" + hologram.getName() + "' near to you."); - } + @Override + public void execute(CommandSender sender, String label, String[] args) throws CommandException { + Player player = CommandValidator.getPlayerSender(sender); + NamedHologram hologram = CommandValidator.getNamedHologram(args[0]); + + hologram.teleport(player.getWorld(), player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ()); + hologram.despawnEntities(); + hologram.refreshAll(); + + HologramDatabase.saveHologram(hologram); + HologramDatabase.trySaveToDisk(); + Location to = player.getLocation(); + to.setPitch(90); + player.teleport(to, TeleportCause.PLUGIN); + player.sendMessage(Colors.PRIMARY + "You moved the hologram '" + hologram.getName() + "' near to you."); + } - @Override - public List getTutorial() { - return Arrays.asList("Moves a hologram to your location."); - } - - @Override - public SubCommandType getType() { - return SubCommandType.GENERIC; - } + @Override + public List getTutorial() { + return Arrays.asList("Moves a hologram to your location."); + } + + @Override + public SubCommandType getType() { + return SubCommandType.GENERIC; + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/NearCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/NearCommand.java index 266ea7a5..1bc45eac 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/NearCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/NearCommand.java @@ -31,53 +31,53 @@ import java.util.List; public class NearCommand extends HologramSubCommand { - public NearCommand() { - super("near"); - setPermission(Strings.BASE_PERM + "near"); - } + public NearCommand() { + super("near"); + setPermission(Strings.BASE_PERM + "near"); + } - @Override - public String getPossibleArguments() { - return ""; - } + @Override + public String getPossibleArguments() { + return ""; + } - @Override - public int getMinimumArguments() { - return 1; - } + @Override + public int getMinimumArguments() { + return 1; + } - @Override - public void execute(CommandSender sender, String label, String[] args) throws CommandException { - Player player = CommandValidator.getPlayerSender(sender); - int radius = CommandValidator.getInteger(args[0]); - CommandValidator.isTrue(radius > 0, "Radius must be at least 1."); - - World world = player.getWorld(); - int radiusSquared = radius * radius; - List nearHolograms = new ArrayList<>(); - - for (NamedHologram hologram : NamedHologramManager.getHolograms()) { - if (hologram.getLocation().getWorld().equals(world) && hologram.getLocation().distanceSquared(player.getLocation()) <= radiusSquared) { - nearHolograms.add(hologram); - } - } - - CommandValidator.isTrue(!nearHolograms.isEmpty(), "There are no holograms in the given radius."); - - player.sendMessage(Strings.formatTitle("Near holograms")); - for (NamedHologram nearHologram : nearHolograms) { - player.sendMessage(Colors.SECONDARY_SHADOW + "- " + Colors.SECONDARY + Colors.BOLD + nearHologram.getName() + " " + Colors.SECONDARY_SHADOW + "at x: " + (int) nearHologram.getX() + ", y: " + (int) nearHologram.getY() + ", z: " + (int) nearHologram.getZ() + " (lines: " + nearHologram.size() + ")"); - } - } + @Override + public void execute(CommandSender sender, String label, String[] args) throws CommandException { + Player player = CommandValidator.getPlayerSender(sender); + int radius = CommandValidator.getInteger(args[0]); + CommandValidator.isTrue(radius > 0, "Radius must be at least 1."); + + World world = player.getWorld(); + int radiusSquared = radius * radius; + List nearHolograms = new ArrayList<>(); + + for (NamedHologram hologram : NamedHologramManager.getHolograms()) { + if (hologram.getLocation().getWorld().equals(world) && hologram.getLocation().distanceSquared(player.getLocation()) <= radiusSquared) { + nearHolograms.add(hologram); + } + } + + CommandValidator.isTrue(!nearHolograms.isEmpty(), "There are no holograms in the given radius."); + + player.sendMessage(Strings.formatTitle("Near holograms")); + for (NamedHologram nearHologram : nearHolograms) { + player.sendMessage(Colors.SECONDARY_SHADOW + "- " + Colors.SECONDARY + Colors.BOLD + nearHologram.getName() + " " + Colors.SECONDARY_SHADOW + "at x: " + (int) nearHologram.getX() + ", y: " + (int) nearHologram.getY() + ", z: " + (int) nearHologram.getZ() + " (lines: " + nearHologram.size() + ")"); + } + } - @Override - public List getTutorial() { - return Arrays.asList("Get a list of near holograms."); - } + @Override + public List getTutorial() { + return Arrays.asList("Get a list of near holograms."); + } - @Override - public SubCommandType getType() { - return SubCommandType.GENERIC; - } + @Override + public SubCommandType getType() { + return SubCommandType.GENERIC; + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/ReadimageCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/ReadimageCommand.java index ac28ca43..aa6ebe59 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/ReadimageCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/ReadimageCommand.java @@ -45,135 +45,135 @@ import java.util.List; public class ReadimageCommand extends HologramSubCommand { - public ReadimageCommand() { - super("readimage", "image"); - setPermission(Strings.BASE_PERM + "readimage"); - } + public ReadimageCommand() { + super("readimage", "image"); + setPermission(Strings.BASE_PERM + "readimage"); + } - @Override - public String getPossibleArguments() { - return " "; - } + @Override + public String getPossibleArguments() { + return " "; + } - @Override - public int getMinimumArguments() { - return 3; - } + @Override + public int getMinimumArguments() { + return 3; + } - @Override - public void execute(CommandSender sender, String label, String[] args) throws CommandException { - - boolean append = false; - - List newArgs = new ArrayList<>(); - - for (int i = 0; i < args.length; i++) { - if (args[i].equalsIgnoreCase("-a") || args[i].equalsIgnoreCase("-append")) { - append = true; - } else { - newArgs.add(args[i]); - } - } - - args = newArgs.toArray(new String[0]); - - NamedHologram hologram = CommandValidator.getNamedHologram(args[0]); - - int width = CommandValidator.getInteger(args[2]); - - CommandValidator.isTrue(width >= 2, "The width of the image must be 2 or greater."); + @Override + public void execute(CommandSender sender, String label, String[] args) throws CommandException { + + boolean append = false; + + List newArgs = new ArrayList<>(); + + for (int i = 0; i < args.length; i++) { + if (args[i].equalsIgnoreCase("-a") || args[i].equalsIgnoreCase("-append")) { + append = true; + } else { + newArgs.add(args[i]); + } + } + + args = newArgs.toArray(new String[0]); + + NamedHologram hologram = CommandValidator.getNamedHologram(args[0]); + + int width = CommandValidator.getInteger(args[2]); + + CommandValidator.isTrue(width >= 2, "The width of the image must be 2 or greater."); - boolean isUrl = false; - - try { - String fileName = args[1]; - BufferedImage image = null; - - if (fileName.startsWith("http://") || fileName.startsWith("https://")) { - isUrl = true; - image = FileUtils.readImage(new URL(fileName)); - } else { - - if (fileName.matches(".*[a-zA-Z0-9\\-]+\\.[a-zA-Z0-9\\-]{1,4}\\/.+")) { - Strings.sendWarning(sender, "The image path seems to be an URL. If so, please use http:// or https:// in the path."); - } - - File targetImage = new File(HolographicDisplays.getInstance().getDataFolder(), fileName); - CommandValidator.isTrue(FileUtils.isParentFolder(HolographicDisplays.getInstance().getDataFolder(), targetImage), "The image must be inside HolographicDisplays' folder."); - CommandValidator.isTrue(!HolographicDisplays.isConfigFile(targetImage), "Cannot read default configuration files."); - - image = FileUtils.readImage(targetImage); - } - - if (!append) { - hologram.clearLines(); - } - - ImageMessage imageMessage = new ImageMessage(image, width); - String[] newLines = imageMessage.getLines(); - for (int i = 0; i < newLines.length; i++) { - CraftTextLine line = new CraftTextLine(hologram, newLines[i]); - line.setSerializedConfigValue(newLines[i]); - hologram.getLinesUnsafe().add(line); - } - - hologram.refreshAll(); - - if (newLines.length < 5) { - sender.sendMessage(Strings.TIP_PREFIX + "The image has a very low height. You can increase it by increasing the width, it will scale automatically."); - } - - HologramDatabase.saveHologram(hologram); - HologramDatabase.trySaveToDisk(); - - if (append) { - sender.sendMessage(Colors.PRIMARY + "The image was appended int the end of the hologram!"); - } else { - sender.sendMessage(Colors.PRIMARY + "The image was drawn in the hologram!"); - } - Bukkit.getPluginManager().callEvent(new NamedHologramEditedEvent(hologram)); - - } catch (CommandException e) { - throw e; - } catch (MalformedURLException e) { - throw new CommandException("The provided URL was not valid."); - } catch (TooWideException e) { - throw new CommandException("The image is too large. Max width allowed is " + ImageMessage.MAX_WIDTH + " pixels."); - } catch (UnreadableImageException e) { - throw new CommandException("The plugin was unable to read the image. Be sure that the format is supported."); - } catch (FileNotFoundException e) { - throw new CommandException("The image \"" + args[1] + "\" doesn't exist in the plugin's folder."); - } catch (IOException e) { - e.printStackTrace(); - throw new CommandException("I/O exception while reading the image. " + (isUrl ? "Is the URL valid?" : "Is it in use?")); - } catch (Exception e) { - e.printStackTrace(); - throw new CommandException("Unhandled exception while reading the image! Please look the console."); - } - } - - @Override - public List getTutorial() { - return Arrays.asList("Reads an image from a file. Tutorial:", - "1) Move the image in the plugin's folder", - "2) Do not use spaces in the name", - "3) Do /holograms read ", - "4) Choose to automatically resize the image", - "5) (Optional) Use the flag '-a' if you only want to append", - " the image to the hologram without clearing the lines", - "", - "Example: you have an image named 'logo.png', you want to append", - "it to the lines of the hologram named 'test', with a width of", - "50 pixels. In this case you would execute the following command:", - ChatColor.YELLOW + "/holograms readimage test logo.png 50 -a", - "", - "The symbols used to create the image are taken from the config.yml."); - } - - @Override - public SubCommandType getType() { - return SubCommandType.EDIT_LINES; - } + boolean isUrl = false; + + try { + String fileName = args[1]; + BufferedImage image = null; + + if (fileName.startsWith("http://") || fileName.startsWith("https://")) { + isUrl = true; + image = FileUtils.readImage(new URL(fileName)); + } else { + + if (fileName.matches(".*[a-zA-Z0-9\\-]+\\.[a-zA-Z0-9\\-]{1,4}\\/.+")) { + Strings.sendWarning(sender, "The image path seems to be an URL. If so, please use http:// or https:// in the path."); + } + + File targetImage = new File(HolographicDisplays.getInstance().getDataFolder(), fileName); + CommandValidator.isTrue(FileUtils.isParentFolder(HolographicDisplays.getInstance().getDataFolder(), targetImage), "The image must be inside HolographicDisplays' folder."); + CommandValidator.isTrue(!HolographicDisplays.isConfigFile(targetImage), "Cannot read default configuration files."); + + image = FileUtils.readImage(targetImage); + } + + if (!append) { + hologram.clearLines(); + } + + ImageMessage imageMessage = new ImageMessage(image, width); + String[] newLines = imageMessage.getLines(); + for (int i = 0; i < newLines.length; i++) { + CraftTextLine line = new CraftTextLine(hologram, newLines[i]); + line.setSerializedConfigValue(newLines[i]); + hologram.getLinesUnsafe().add(line); + } + + hologram.refreshAll(); + + if (newLines.length < 5) { + sender.sendMessage(Strings.TIP_PREFIX + "The image has a very low height. You can increase it by increasing the width, it will scale automatically."); + } + + HologramDatabase.saveHologram(hologram); + HologramDatabase.trySaveToDisk(); + + if (append) { + sender.sendMessage(Colors.PRIMARY + "The image was appended int the end of the hologram!"); + } else { + sender.sendMessage(Colors.PRIMARY + "The image was drawn in the hologram!"); + } + Bukkit.getPluginManager().callEvent(new NamedHologramEditedEvent(hologram)); + + } catch (CommandException e) { + throw e; + } catch (MalformedURLException e) { + throw new CommandException("The provided URL was not valid."); + } catch (TooWideException e) { + throw new CommandException("The image is too large. Max width allowed is " + ImageMessage.MAX_WIDTH + " pixels."); + } catch (UnreadableImageException e) { + throw new CommandException("The plugin was unable to read the image. Be sure that the format is supported."); + } catch (FileNotFoundException e) { + throw new CommandException("The image \"" + args[1] + "\" doesn't exist in the plugin's folder."); + } catch (IOException e) { + e.printStackTrace(); + throw new CommandException("I/O exception while reading the image. " + (isUrl ? "Is the URL valid?" : "Is it in use?")); + } catch (Exception e) { + e.printStackTrace(); + throw new CommandException("Unhandled exception while reading the image! Please look the console."); + } + } + + @Override + public List getTutorial() { + return Arrays.asList("Reads an image from a file. Tutorial:", + "1) Move the image in the plugin's folder", + "2) Do not use spaces in the name", + "3) Do /holograms read ", + "4) Choose to automatically resize the image", + "5) (Optional) Use the flag '-a' if you only want to append", + " the image to the hologram without clearing the lines", + "", + "Example: you have an image named 'logo.png', you want to append", + "it to the lines of the hologram named 'test', with a width of", + "50 pixels. In this case you would execute the following command:", + ChatColor.YELLOW + "/holograms readimage test logo.png 50 -a", + "", + "The symbols used to create the image are taken from the config.yml."); + } + + @Override + public SubCommandType getType() { + return SubCommandType.EDIT_LINES; + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/ReadtextCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/ReadtextCommand.java index 34dc3172..d82492c2 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/ReadtextCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/ReadtextCommand.java @@ -41,97 +41,97 @@ import java.util.List; public class ReadtextCommand extends HologramSubCommand { - public ReadtextCommand() { - super("readtext", "readlines"); - setPermission(Strings.BASE_PERM + "readtext"); - } + public ReadtextCommand() { + super("readtext", "readlines"); + setPermission(Strings.BASE_PERM + "readtext"); + } - @Override - public String getPossibleArguments() { - return " "; - } + @Override + public String getPossibleArguments() { + return " "; + } - @Override - public int getMinimumArguments() { - return 2; - } + @Override + public int getMinimumArguments() { + return 2; + } - @Override - public void execute(CommandSender sender, String label, String[] args) throws CommandException { - NamedHologram hologram = CommandValidator.getNamedHologram(args[0]); - String fileName = args[1]; - - try { - File targetFile = new File(HolographicDisplays.getInstance().getDataFolder(), fileName); - CommandValidator.isTrue(FileUtils.isParentFolder(HolographicDisplays.getInstance().getDataFolder(), targetFile), "The file must be inside HolographicDisplays' folder."); - CommandValidator.isTrue(!HolographicDisplays.isConfigFile(targetFile), "Cannot read default configuration files."); - - List serializedLines = FileUtils.readLines(targetFile); - - int linesAmount = serializedLines.size(); - if (linesAmount > 40) { - Strings.sendWarning(sender, "The file contained more than 40 lines, that have been limited."); - linesAmount = 40; - } - - List linesToAdd = new ArrayList<>(); - for (int i = 0; i < linesAmount; i++) { - try { - CraftHologramLine line = HologramLineParser.parseLine(hologram, serializedLines.get(i), true); - linesToAdd.add(line); - } catch (HologramLineParseException e) { - throw new CommandException("Error at line " + (i + 1) + ": " + Utils.uncapitalize(e.getMessage())); - } - } - - hologram.clearLines(); - hologram.getLinesUnsafe().addAll(linesToAdd); - hologram.refreshAll(); + @Override + public void execute(CommandSender sender, String label, String[] args) throws CommandException { + NamedHologram hologram = CommandValidator.getNamedHologram(args[0]); + String fileName = args[1]; + + try { + File targetFile = new File(HolographicDisplays.getInstance().getDataFolder(), fileName); + CommandValidator.isTrue(FileUtils.isParentFolder(HolographicDisplays.getInstance().getDataFolder(), targetFile), "The file must be inside HolographicDisplays' folder."); + CommandValidator.isTrue(!HolographicDisplays.isConfigFile(targetFile), "Cannot read default configuration files."); + + List serializedLines = FileUtils.readLines(targetFile); + + int linesAmount = serializedLines.size(); + if (linesAmount > 40) { + Strings.sendWarning(sender, "The file contained more than 40 lines, that have been limited."); + linesAmount = 40; + } + + List linesToAdd = new ArrayList<>(); + for (int i = 0; i < linesAmount; i++) { + try { + CraftHologramLine line = HologramLineParser.parseLine(hologram, serializedLines.get(i), true); + linesToAdd.add(line); + } catch (HologramLineParseException e) { + throw new CommandException("Error at line " + (i + 1) + ": " + Utils.uncapitalize(e.getMessage())); + } + } + + hologram.clearLines(); + hologram.getLinesUnsafe().addAll(linesToAdd); + hologram.refreshAll(); - HologramDatabase.saveHologram(hologram); - HologramDatabase.trySaveToDisk(); - - if (args[1].contains(".")) { - if (isImageExtension(args[1].substring(args[1].lastIndexOf('.') + 1))) { - Strings.sendWarning(sender, "The read file has an image's extension. If it is an image, you should use /" + label + " readimage."); - } - } - - sender.sendMessage(Colors.PRIMARY + "The lines were pasted into the hologram!"); - Bukkit.getPluginManager().callEvent(new NamedHologramEditedEvent(hologram)); - - } catch (CommandException e) { - throw e; - } catch (FileNotFoundException e) { - throw new CommandException("A file named '" + args[1] + "' doesn't exist in the plugin's folder."); - } catch (IOException e) { - throw new CommandException("I/O exception while reading the file. Is it in use?"); - } catch (Exception e) { - e.printStackTrace(); - throw new CommandException("Unhandled exception while reading the file! Please look the console."); - } - } - - @Override - public List getTutorial() { - return Arrays.asList("Reads the lines from a text file. Tutorial:", - "1) Create a new text file in the plugin's folder", - "2) Do not use spaces in the name", - "3) Each line will be a line in the hologram", - "4) Do /holograms readlines ", - "", - "Example: you have a file named 'info.txt', and you want", - "to paste it in the hologram named 'test'. In this case you", - "would execute "+ ChatColor.YELLOW + "/holograms readlines test info.txt"); - } - - @Override - public SubCommandType getType() { - return SubCommandType.EDIT_LINES; - } + HologramDatabase.saveHologram(hologram); + HologramDatabase.trySaveToDisk(); + + if (args[1].contains(".")) { + if (isImageExtension(args[1].substring(args[1].lastIndexOf('.') + 1))) { + Strings.sendWarning(sender, "The read file has an image's extension. If it is an image, you should use /" + label + " readimage."); + } + } + + sender.sendMessage(Colors.PRIMARY + "The lines were pasted into the hologram!"); + Bukkit.getPluginManager().callEvent(new NamedHologramEditedEvent(hologram)); + + } catch (CommandException e) { + throw e; + } catch (FileNotFoundException e) { + throw new CommandException("A file named '" + args[1] + "' doesn't exist in the plugin's folder."); + } catch (IOException e) { + throw new CommandException("I/O exception while reading the file. Is it in use?"); + } catch (Exception e) { + e.printStackTrace(); + throw new CommandException("Unhandled exception while reading the file! Please look the console."); + } + } + + @Override + public List getTutorial() { + return Arrays.asList("Reads the lines from a text file. Tutorial:", + "1) Create a new text file in the plugin's folder", + "2) Do not use spaces in the name", + "3) Each line will be a line in the hologram", + "4) Do /holograms readlines ", + "", + "Example: you have a file named 'info.txt', and you want", + "to paste it in the hologram named 'test'. In this case you", + "would execute "+ ChatColor.YELLOW + "/holograms readlines test info.txt"); + } + + @Override + public SubCommandType getType() { + return SubCommandType.EDIT_LINES; + } - private boolean isImageExtension(String input) { - return Arrays.asList("jpg", "png", "jpeg", "gif").contains(input.toLowerCase()); - } - + private boolean isImageExtension(String input) { + return Arrays.asList("jpg", "png", "jpeg", "gif").contains(input.toLowerCase()); + } + } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/ReloadCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/ReloadCommand.java index b42e8187..e0e4c8fd 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/ReloadCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/ReloadCommand.java @@ -43,81 +43,81 @@ import java.util.Set; public class ReloadCommand extends HologramSubCommand { - public ReloadCommand() { - super("reload"); - setPermission(Strings.BASE_PERM + "reload"); - } + public ReloadCommand() { + super("reload"); + setPermission(Strings.BASE_PERM + "reload"); + } - @Override - public String getPossibleArguments() { - return ""; - } + @Override + public String getPossibleArguments() { + return ""; + } - @Override - public int getMinimumArguments() { - return 0; - } + @Override + public int getMinimumArguments() { + return 0; + } - @Override - public void execute(CommandSender sender, String label, String[] args) throws CommandException { - try { - - long startMillis = System.currentTimeMillis(); + @Override + public void execute(CommandSender sender, String label, String[] args) throws CommandException { + try { + + long startMillis = System.currentTimeMillis(); - UnicodeSymbols.load(HolographicDisplays.getInstance()); - Configuration.load(HolographicDisplays.getInstance()); - - BungeeServerTracker.resetTrackedServers(); - BungeeServerTracker.startTask(Configuration.bungeeRefreshSeconds); - - HologramDatabase.loadYamlFile(HolographicDisplays.getInstance()); - AnimationsRegister.loadAnimations(HolographicDisplays.getInstance()); - - PlaceholdersManager.untrackAll(); - NamedHologramManager.clearAll(); - - Set savedHolograms = HologramDatabase.getHolograms(); - if (savedHolograms != null && savedHolograms.size() > 0) { - for (String singleSavedHologram : savedHolograms) { - try { - NamedHologram singleHologramEntity = HologramDatabase.loadHologram(singleSavedHologram); - NamedHologramManager.addHologram(singleHologramEntity); - } catch (HologramNotFoundException e) { - Strings.sendWarning(sender, "Hologram '" + singleSavedHologram + "' not found, skipping it."); - } catch (InvalidFormatException e) { - Strings.sendWarning(sender, "Hologram '" + singleSavedHologram + "' has an invalid location format."); - } catch (HologramLineParseException e) { - Strings.sendWarning(sender, "Hologram '" + singleSavedHologram + "' has an invalid line: " + Utils.uncapitalize(e.getMessage())); - } catch (WorldNotFoundException e) { - Strings.sendWarning(sender, "Hologram '" + singleSavedHologram + "' was in the world '" + e.getMessage() + "' but it wasn't loaded."); - } - } - } - - for (CraftHologram hologram : NamedHologramManager.getHolograms()) { - hologram.refreshAll(); - } - - long endMillis = System.currentTimeMillis(); - - sender.sendMessage(Colors.PRIMARY + "Configuration reloaded successfully in " + (endMillis - startMillis) + "ms!"); - - } catch (Exception ex) { - ex.printStackTrace(); - throw new CommandException("Exception while reloading the configuration. Please look the console."); - } - - Bukkit.getPluginManager().callEvent(new HolographicDisplaysReloadEvent()); - } - - @Override - public List getTutorial() { - return Arrays.asList("Reloads the holograms from the database."); - } - - @Override - public SubCommandType getType() { - return SubCommandType.GENERIC; - } + UnicodeSymbols.load(HolographicDisplays.getInstance()); + Configuration.load(HolographicDisplays.getInstance()); + + BungeeServerTracker.resetTrackedServers(); + BungeeServerTracker.startTask(Configuration.bungeeRefreshSeconds); + + HologramDatabase.loadYamlFile(HolographicDisplays.getInstance()); + AnimationsRegister.loadAnimations(HolographicDisplays.getInstance()); + + PlaceholdersManager.untrackAll(); + NamedHologramManager.clearAll(); + + Set savedHolograms = HologramDatabase.getHolograms(); + if (savedHolograms != null && savedHolograms.size() > 0) { + for (String singleSavedHologram : savedHolograms) { + try { + NamedHologram singleHologramEntity = HologramDatabase.loadHologram(singleSavedHologram); + NamedHologramManager.addHologram(singleHologramEntity); + } catch (HologramNotFoundException e) { + Strings.sendWarning(sender, "Hologram '" + singleSavedHologram + "' not found, skipping it."); + } catch (InvalidFormatException e) { + Strings.sendWarning(sender, "Hologram '" + singleSavedHologram + "' has an invalid location format."); + } catch (HologramLineParseException e) { + Strings.sendWarning(sender, "Hologram '" + singleSavedHologram + "' has an invalid line: " + Utils.uncapitalize(e.getMessage())); + } catch (WorldNotFoundException e) { + Strings.sendWarning(sender, "Hologram '" + singleSavedHologram + "' was in the world '" + e.getMessage() + "' but it wasn't loaded."); + } + } + } + + for (CraftHologram hologram : NamedHologramManager.getHolograms()) { + hologram.refreshAll(); + } + + long endMillis = System.currentTimeMillis(); + + sender.sendMessage(Colors.PRIMARY + "Configuration reloaded successfully in " + (endMillis - startMillis) + "ms!"); + + } catch (Exception ex) { + ex.printStackTrace(); + throw new CommandException("Exception while reloading the configuration. Please look the console."); + } + + Bukkit.getPluginManager().callEvent(new HolographicDisplaysReloadEvent()); + } + + @Override + public List getTutorial() { + return Arrays.asList("Reloads the holograms from the database."); + } + + @Override + public SubCommandType getType() { + return SubCommandType.GENERIC; + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/RemovelineCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/RemovelineCommand.java index cde77f3a..8c4fded3 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/RemovelineCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/RemovelineCommand.java @@ -30,52 +30,52 @@ import java.util.List; public class RemovelineCommand extends HologramSubCommand { - public RemovelineCommand() { - super("removeline"); - setPermission(Strings.BASE_PERM + "removeline"); - } + public RemovelineCommand() { + super("removeline"); + setPermission(Strings.BASE_PERM + "removeline"); + } - @Override - public String getPossibleArguments() { - return " "; - } + @Override + public String getPossibleArguments() { + return " "; + } - @Override - public int getMinimumArguments() { - return 2; - } + @Override + public int getMinimumArguments() { + return 2; + } - @Override - public void execute(CommandSender sender, String label, String[] args) throws CommandException { - NamedHologram hologram = CommandValidator.getNamedHologram(args[0]); - - int lineNumber = CommandValidator.getInteger(args[1]); + @Override + public void execute(CommandSender sender, String label, String[] args) throws CommandException { + NamedHologram hologram = CommandValidator.getNamedHologram(args[0]); + + int lineNumber = CommandValidator.getInteger(args[1]); - CommandValidator.isTrue(lineNumber >= 1 && lineNumber <= hologram.size(), "The line number must be between 1 and " + hologram.size() + "."); - int index = lineNumber - 1; - - CommandValidator.isTrue(hologram.size() > 1, "The hologram should have at least 1 line. If you want to delete it, use /" + label + " delete."); + CommandValidator.isTrue(lineNumber >= 1 && lineNumber <= hologram.size(), "The line number must be between 1 and " + hologram.size() + "."); + int index = lineNumber - 1; + + CommandValidator.isTrue(hologram.size() > 1, "The hologram should have at least 1 line. If you want to delete it, use /" + label + " delete."); - hologram.removeLine(index); - hologram.refreshAll(); - - HologramDatabase.saveHologram(hologram); - HologramDatabase.trySaveToDisk(); - Bukkit.getPluginManager().callEvent(new NamedHologramEditedEvent(hologram)); - - sender.sendMessage(Colors.PRIMARY + "Line " + lineNumber + " removed!"); - EditCommand.sendQuickEditCommands(sender, label, hologram.getName()); - } + hologram.removeLine(index); + hologram.refreshAll(); + + HologramDatabase.saveHologram(hologram); + HologramDatabase.trySaveToDisk(); + Bukkit.getPluginManager().callEvent(new NamedHologramEditedEvent(hologram)); + + sender.sendMessage(Colors.PRIMARY + "Line " + lineNumber + " removed!"); + EditCommand.sendQuickEditCommands(sender, label, hologram.getName()); + } - @Override - public List getTutorial() { - return Arrays.asList("Removes a line from a hologram."); - } - - @Override - public SubCommandType getType() { - return SubCommandType.EDIT_LINES; - } + @Override + public List getTutorial() { + return Arrays.asList("Removes a line from a hologram."); + } + + @Override + public SubCommandType getType() { + return SubCommandType.EDIT_LINES; + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/SetlineCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/SetlineCommand.java index 96981ddd..c495fcdc 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/SetlineCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/SetlineCommand.java @@ -32,54 +32,54 @@ import java.util.List; public class SetlineCommand extends HologramSubCommand { - public SetlineCommand() { - super("setline"); - setPermission(Strings.BASE_PERM + "setline"); - } + public SetlineCommand() { + super("setline"); + setPermission(Strings.BASE_PERM + "setline"); + } - @Override - public String getPossibleArguments() { - return " "; - } + @Override + public String getPossibleArguments() { + return " "; + } - @Override - public int getMinimumArguments() { - return 3; - } + @Override + public int getMinimumArguments() { + return 3; + } - @Override - public void execute(CommandSender sender, String label, String[] args) throws CommandException { - NamedHologram hologram = CommandValidator.getNamedHologram(args[0]); - String serializedLine = Utils.join(args, " ", 2, args.length); - - int lineNumber = CommandValidator.getInteger(args[1]); - CommandValidator.isTrue(lineNumber >= 1 && lineNumber <= hologram.size(), "The line number must be between 1 and " + hologram.size() + "."); - int index = lineNumber - 1; - - CraftHologramLine line = CommandValidator.parseHologramLine(hologram, serializedLine, true); - - hologram.getLinesUnsafe().get(index).despawn(); - hologram.getLinesUnsafe().set(index, line); - hologram.refreshAll(); + @Override + public void execute(CommandSender sender, String label, String[] args) throws CommandException { + NamedHologram hologram = CommandValidator.getNamedHologram(args[0]); + String serializedLine = Utils.join(args, " ", 2, args.length); + + int lineNumber = CommandValidator.getInteger(args[1]); + CommandValidator.isTrue(lineNumber >= 1 && lineNumber <= hologram.size(), "The line number must be between 1 and " + hologram.size() + "."); + int index = lineNumber - 1; + + CraftHologramLine line = CommandValidator.parseHologramLine(hologram, serializedLine, true); + + hologram.getLinesUnsafe().get(index).despawn(); + hologram.getLinesUnsafe().set(index, line); + hologram.refreshAll(); - HologramDatabase.saveHologram(hologram); - HologramDatabase.trySaveToDisk(); - Bukkit.getPluginManager().callEvent(new NamedHologramEditedEvent(hologram)); - - sender.sendMessage(Colors.PRIMARY + "Line " + lineNumber + " changed!"); - EditCommand.sendQuickEditCommands(sender, label, hologram.getName()); - - } + HologramDatabase.saveHologram(hologram); + HologramDatabase.trySaveToDisk(); + Bukkit.getPluginManager().callEvent(new NamedHologramEditedEvent(hologram)); + + sender.sendMessage(Colors.PRIMARY + "Line " + lineNumber + " changed!"); + EditCommand.sendQuickEditCommands(sender, label, hologram.getName()); + + } - @Override - public List getTutorial() { - return Arrays.asList("Changes a line of a hologram."); - } - - @Override - public SubCommandType getType() { - return SubCommandType.EDIT_LINES; - } + @Override + public List getTutorial() { + return Arrays.asList("Changes a line of a hologram."); + } + + @Override + public SubCommandType getType() { + return SubCommandType.EDIT_LINES; + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/TeleportCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/TeleportCommand.java index 94dca5bb..26753371 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/TeleportCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/main/subs/TeleportCommand.java @@ -30,42 +30,42 @@ import java.util.List; public class TeleportCommand extends HologramSubCommand { - - public TeleportCommand() { - super("teleport", "tp"); - setPermission(Strings.BASE_PERM + "teleport"); - } + + public TeleportCommand() { + super("teleport", "tp"); + setPermission(Strings.BASE_PERM + "teleport"); + } - @Override - public String getPossibleArguments() { - return ""; - } + @Override + public String getPossibleArguments() { + return ""; + } - @Override - public int getMinimumArguments() { - return 1; - } + @Override + public int getMinimumArguments() { + return 1; + } - @Override - public void execute(CommandSender sender, String label, String[] args) throws CommandException { - Player player = CommandValidator.getPlayerSender(sender); - NamedHologram hologram = CommandValidator.getNamedHologram(args[0]); - - Location loc = hologram.getLocation(); - loc.setPitch(90); - player.teleport(loc, TeleportCause.PLUGIN); - player.sendMessage(Colors.PRIMARY + "You were teleported to the hologram named '" + hologram.getName() + "'."); + @Override + public void execute(CommandSender sender, String label, String[] args) throws CommandException { + Player player = CommandValidator.getPlayerSender(sender); + NamedHologram hologram = CommandValidator.getNamedHologram(args[0]); + + Location loc = hologram.getLocation(); + loc.setPitch(90); + player.teleport(loc, TeleportCause.PLUGIN); + player.sendMessage(Colors.PRIMARY + "You were teleported to the hologram named '" + hologram.getName() + "'."); - } + } - @Override - public List getTutorial() { - return Arrays.asList("Teleports you to the given hologram."); - } - - @Override - public SubCommandType getType() { - return SubCommandType.GENERIC; - } + @Override + public List getTutorial() { + return Arrays.asList("Teleports you to the given hologram."); + } + + @Override + public SubCommandType getType() { + return SubCommandType.GENERIC; + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/disk/HologramDatabase.java b/plugin/src/main/java/me/filoghost/holographicdisplays/disk/HologramDatabase.java index 25407257..5d824faa 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/disk/HologramDatabase.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/disk/HologramDatabase.java @@ -35,92 +35,92 @@ import java.util.Set; import java.util.logging.Level; public class HologramDatabase { - - private static File file; - private static FileConfiguration config; - - public static void loadYamlFile(Plugin plugin) { - file = new File(plugin.getDataFolder(), "database.yml"); - - if (!file.exists()) { - plugin.getDataFolder().mkdirs(); - plugin.saveResource("database.yml", true); - } - - config = YamlConfiguration.loadConfiguration(file); - } - - public static NamedHologram loadHologram(String name) throws HologramNotFoundException, InvalidFormatException, WorldNotFoundException, HologramLineParseException { - ConfigurationSection configSection = config.getConfigurationSection(name); - - if (configSection == null) { - throw new HologramNotFoundException(); - } - - List lines = configSection.getStringList("lines"); - String locationString = configSection.getString("location"); - - if (lines == null || locationString == null || lines.size() == 0) { - throw new HologramNotFoundException(); - } - - Location loc = LocationSerializer.locationFromString(locationString); - - NamedHologram hologram = new NamedHologram(loc, name); + + private static File file; + private static FileConfiguration config; + + public static void loadYamlFile(Plugin plugin) { + file = new File(plugin.getDataFolder(), "database.yml"); + + if (!file.exists()) { + plugin.getDataFolder().mkdirs(); + plugin.saveResource("database.yml", true); + } + + config = YamlConfiguration.loadConfiguration(file); + } + + public static NamedHologram loadHologram(String name) throws HologramNotFoundException, InvalidFormatException, WorldNotFoundException, HologramLineParseException { + ConfigurationSection configSection = config.getConfigurationSection(name); + + if (configSection == null) { + throw new HologramNotFoundException(); + } + + List lines = configSection.getStringList("lines"); + String locationString = configSection.getString("location"); + + if (lines == null || locationString == null || lines.size() == 0) { + throw new HologramNotFoundException(); + } + + Location loc = LocationSerializer.locationFromString(locationString); + + NamedHologram hologram = new NamedHologram(loc, name); - for (String line : lines) { - hologram.getLinesUnsafe().add(HologramLineParser.parseLine(hologram, line, false)); - } - - return hologram; - } - - public static String serializeHologramLine(CraftHologramLine line) { - return line.getSerializedConfigValue(); - } - - public static void deleteHologram(String name) { - config.set(name, null); - } - - public static void saveHologram(NamedHologram hologram) { - List serializedLines = new ArrayList<>(); - for (CraftHologramLine line : hologram.getLinesUnsafe()) { - serializedLines.add(serializeHologramLine(line)); - } - - ConfigurationSection hologramSection = getOrCreateSection(hologram.getName()); - hologramSection.set("location", LocationSerializer.locationToString(hologram.getLocation())); - hologramSection.set("lines", serializedLines); - } - - public static Set getHolograms() { - return config.getKeys(false); - } - - public static boolean isExistingHologram(String name) { - return config.isConfigurationSection(name); - } - - private static ConfigurationSection getOrCreateSection(String name) { - if (config.isConfigurationSection(name)) { - return config.getConfigurationSection(name); - } else { - return config.createSection(name); - } - } - - public static void saveToDisk() throws IOException { - if (config != null && file != null) { - config.save(file); - } - } - - public static void trySaveToDisk() { - try { - saveToDisk(); - } catch (IOException ex) { - ConsoleLogger.log(Level.SEVERE, "Unable to save database.yml to disk!", ex); - } - } + for (String line : lines) { + hologram.getLinesUnsafe().add(HologramLineParser.parseLine(hologram, line, false)); + } + + return hologram; + } + + public static String serializeHologramLine(CraftHologramLine line) { + return line.getSerializedConfigValue(); + } + + public static void deleteHologram(String name) { + config.set(name, null); + } + + public static void saveHologram(NamedHologram hologram) { + List serializedLines = new ArrayList<>(); + for (CraftHologramLine line : hologram.getLinesUnsafe()) { + serializedLines.add(serializeHologramLine(line)); + } + + ConfigurationSection hologramSection = getOrCreateSection(hologram.getName()); + hologramSection.set("location", LocationSerializer.locationToString(hologram.getLocation())); + hologramSection.set("lines", serializedLines); + } + + public static Set getHolograms() { + return config.getKeys(false); + } + + public static boolean isExistingHologram(String name) { + return config.isConfigurationSection(name); + } + + private static ConfigurationSection getOrCreateSection(String name) { + if (config.isConfigurationSection(name)) { + return config.getConfigurationSection(name); + } else { + return config.createSection(name); + } + } + + public static void saveToDisk() throws IOException { + if (config != null && file != null) { + config.save(file); + } + } + + public static void trySaveToDisk() { + try { + saveToDisk(); + } catch (IOException ex) { + ConsoleLogger.log(Level.SEVERE, "Unable to save database.yml to disk!", ex); + } + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/disk/HologramLineParser.java b/plugin/src/main/java/me/filoghost/holographicdisplays/disk/HologramLineParser.java index a1a67d19..17fcb2bd 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/disk/HologramLineParser.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/disk/HologramLineParser.java @@ -29,87 +29,87 @@ import org.bukkit.Material; import org.bukkit.inventory.ItemStack; public class HologramLineParser { - - - public static CraftHologramLine parseLine(NamedHologram hologram, String serializedLine, boolean checkMaterialValidity) throws HologramLineParseException { - CraftHologramLine hologramLine; - - if (serializedLine.toLowerCase().startsWith("icon:")) { - String serializedIcon = serializedLine.substring("icon:".length(), serializedLine.length()); - ItemStack icon = parseItemStack(serializedIcon, checkMaterialValidity); - hologramLine = new CraftItemLine(hologram, icon); - - } else { - if (serializedLine.trim().equalsIgnoreCase("{empty}")) { - hologramLine = new CraftTextLine(hologram, ""); - } else { - hologramLine = new CraftTextLine(hologram, StringConverter.toReadableFormat(serializedLine)); - } - } - - hologramLine.setSerializedConfigValue(serializedLine); - return hologramLine; - } - - - @SuppressWarnings("deprecation") - private static ItemStack parseItemStack(String serializedItem, boolean checkMaterialValidity) throws HologramLineParseException { - serializedItem = serializedItem.trim(); - - // Parse json - int nbtStart = serializedItem.indexOf('{'); - int nbtEnd = serializedItem.lastIndexOf('}'); - String nbtString = null; - - String basicItemData; - - if (nbtStart > 0 && nbtEnd > 0 && nbtEnd > nbtStart) { - nbtString = serializedItem.substring(nbtStart, nbtEnd + 1); - basicItemData = serializedItem.substring(0, nbtStart) + serializedItem.substring(nbtEnd + 1, serializedItem.length()); - } else { - basicItemData = serializedItem; - } - - basicItemData = ItemUtils.stripSpacingChars(basicItemData); + + + public static CraftHologramLine parseLine(NamedHologram hologram, String serializedLine, boolean checkMaterialValidity) throws HologramLineParseException { + CraftHologramLine hologramLine; + + if (serializedLine.toLowerCase().startsWith("icon:")) { + String serializedIcon = serializedLine.substring("icon:".length(), serializedLine.length()); + ItemStack icon = parseItemStack(serializedIcon, checkMaterialValidity); + hologramLine = new CraftItemLine(hologram, icon); + + } else { + if (serializedLine.trim().equalsIgnoreCase("{empty}")) { + hologramLine = new CraftTextLine(hologram, ""); + } else { + hologramLine = new CraftTextLine(hologram, StringConverter.toReadableFormat(serializedLine)); + } + } + + hologramLine.setSerializedConfigValue(serializedLine); + return hologramLine; + } + + + @SuppressWarnings("deprecation") + private static ItemStack parseItemStack(String serializedItem, boolean checkMaterialValidity) throws HologramLineParseException { + serializedItem = serializedItem.trim(); + + // Parse json + int nbtStart = serializedItem.indexOf('{'); + int nbtEnd = serializedItem.lastIndexOf('}'); + String nbtString = null; + + String basicItemData; + + if (nbtStart > 0 && nbtEnd > 0 && nbtEnd > nbtStart) { + nbtString = serializedItem.substring(nbtStart, nbtEnd + 1); + basicItemData = serializedItem.substring(0, nbtStart) + serializedItem.substring(nbtEnd + 1, serializedItem.length()); + } else { + basicItemData = serializedItem; + } + + basicItemData = ItemUtils.stripSpacingChars(basicItemData); - String materialName; - short dataValue = 0; - - if (basicItemData.contains(":")) { - String[] materialAndDataValue = basicItemData.split(":", -1); - try { - dataValue = (short) Integer.parseInt(materialAndDataValue[1]); - } catch (NumberFormatException e) { - throw new HologramLineParseException("Data value \"" + materialAndDataValue[1] + "\" is not a valid number."); - } - materialName = materialAndDataValue[0]; - } else { - materialName = basicItemData; - } - - Material material = ItemUtils.matchMaterial(materialName); - if (material == null) { - if (checkMaterialValidity) { - throw new HologramLineParseException("\"" + materialName + "\" is not a valid material."); - } - material = Material.BEDROCK; - } - - ItemStack itemStack = new ItemStack(material, 1, dataValue); - - if (nbtString != null) { - try { - // Check NBT syntax validity before applying it. - MojangsonParser.parse(nbtString); - Bukkit.getUnsafe().modifyItemStack(itemStack, nbtString); - } catch (MojangsonParseException e) { - throw new HologramLineParseException("Invalid NBT data, " + Utils.uncapitalize(ChatColor.stripColor(e.getMessage()))); - } catch (Throwable t) { - throw new HologramLineParseException("Unexpected exception while parsing NBT data.", t); - } - } - - return itemStack; - } + String materialName; + short dataValue = 0; + + if (basicItemData.contains(":")) { + String[] materialAndDataValue = basicItemData.split(":", -1); + try { + dataValue = (short) Integer.parseInt(materialAndDataValue[1]); + } catch (NumberFormatException e) { + throw new HologramLineParseException("Data value \"" + materialAndDataValue[1] + "\" is not a valid number."); + } + materialName = materialAndDataValue[0]; + } else { + materialName = basicItemData; + } + + Material material = ItemUtils.matchMaterial(materialName); + if (material == null) { + if (checkMaterialValidity) { + throw new HologramLineParseException("\"" + materialName + "\" is not a valid material."); + } + material = Material.BEDROCK; + } + + ItemStack itemStack = new ItemStack(material, 1, dataValue); + + if (nbtString != null) { + try { + // Check NBT syntax validity before applying it. + MojangsonParser.parse(nbtString); + Bukkit.getUnsafe().modifyItemStack(itemStack, nbtString); + } catch (MojangsonParseException e) { + throw new HologramLineParseException("Invalid NBT data, " + Utils.uncapitalize(ChatColor.stripColor(e.getMessage()))); + } catch (Throwable t) { + throw new HologramLineParseException("Unexpected exception while parsing NBT data.", t); + } + } + + return itemStack; + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/event/HolographicDisplaysReloadEvent.java b/plugin/src/main/java/me/filoghost/holographicdisplays/event/HolographicDisplaysReloadEvent.java index 4371312d..8e1b916e 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/event/HolographicDisplaysReloadEvent.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/event/HolographicDisplaysReloadEvent.java @@ -18,15 +18,15 @@ import org.bukkit.event.Event; import org.bukkit.event.HandlerList; public class HolographicDisplaysReloadEvent extends Event { - - private static final HandlerList handlers = new HandlerList(); + + private static final HandlerList handlers = new HandlerList(); @Override public HandlerList getHandlers() { return handlers; } - public static HandlerList getHandlerList() { - return handlers; - } + public static HandlerList getHandlerList() { + return handlers; + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/event/NamedHologramEditedEvent.java b/plugin/src/main/java/me/filoghost/holographicdisplays/event/NamedHologramEditedEvent.java index 2559d65a..fb3243b6 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/event/NamedHologramEditedEvent.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/event/NamedHologramEditedEvent.java @@ -19,25 +19,25 @@ import org.bukkit.event.Event; import org.bukkit.event.HandlerList; public class NamedHologramEditedEvent extends Event { - - private static final HandlerList handlers = new HandlerList(); - private NamedHologram namedHologram; - + private static final HandlerList handlers = new HandlerList(); + + private NamedHologram namedHologram; + public NamedHologramEditedEvent(NamedHologram namedHologram) { - this.namedHologram = namedHologram; - } + this.namedHologram = namedHologram; + } - public NamedHologram getNamedHologram() { - return namedHologram; - } + public NamedHologram getNamedHologram() { + return namedHologram; + } - @Override + @Override public HandlerList getHandlers() { return handlers; } - public static HandlerList getHandlerList() { - return handlers; - } + public static HandlerList getHandlerList() { + return handlers; + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/exception/CommandException.java b/plugin/src/main/java/me/filoghost/holographicdisplays/exception/CommandException.java index a8e9a2c7..ac252c38 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/exception/CommandException.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/exception/CommandException.java @@ -16,9 +16,9 @@ package me.filoghost.holographicdisplays.exception; public class CommandException extends Exception { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - public CommandException(String message) { - super(message); - } + public CommandException(String message) { + super(message); + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/exception/HologramLineParseException.java b/plugin/src/main/java/me/filoghost/holographicdisplays/exception/HologramLineParseException.java index 0c2919aa..a54e9bd1 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/exception/HologramLineParseException.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/exception/HologramLineParseException.java @@ -16,14 +16,14 @@ package me.filoghost.holographicdisplays.exception; public class HologramLineParseException extends Exception { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - public HologramLineParseException(String message) { - super(message); - } + public HologramLineParseException(String message) { + super(message); + } - public HologramLineParseException(String message, Throwable cause) { - super(message, cause); - } - + public HologramLineParseException(String message, Throwable cause) { + super(message, cause); + } + } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/exception/HologramNotFoundException.java b/plugin/src/main/java/me/filoghost/holographicdisplays/exception/HologramNotFoundException.java index b1c0fc62..0fa73d84 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/exception/HologramNotFoundException.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/exception/HologramNotFoundException.java @@ -16,6 +16,6 @@ package me.filoghost.holographicdisplays.exception; public class HologramNotFoundException extends Exception { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/exception/TooWideException.java b/plugin/src/main/java/me/filoghost/holographicdisplays/exception/TooWideException.java index b5c0d535..d1593a46 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/exception/TooWideException.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/exception/TooWideException.java @@ -16,16 +16,16 @@ package me.filoghost.holographicdisplays.exception; public class TooWideException extends Exception { - private static final long serialVersionUID = 1L; - - private int width; - - public TooWideException(int width) { - this.width = width; - } - - public int getWidth() { - return width; - } + private static final long serialVersionUID = 1L; + + private int width; + + public TooWideException(int width) { + this.width = width; + } + + public int getWidth() { + return width; + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/image/ImageMessage.java b/plugin/src/main/java/me/filoghost/holographicdisplays/image/ImageMessage.java index 7c63b639..076ae66c 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/image/ImageMessage.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/image/ImageMessage.java @@ -29,32 +29,32 @@ import java.util.Map.Entry; * Bukkit thread: https://forums.bukkit.org/threads/lib-imagemessage-v2-1-send-images-to-players-via-the-chat.204902 */ public class ImageMessage { - - public static final int MAX_WIDTH = 150; + + public static final int MAX_WIDTH = 150; - private static final Map colorsMap = new HashMap<>(); - private static final Map graysMap = new HashMap<>(); - - static { - colorsMap.put(ChatColor.DARK_BLUE, new Color(0, 0, 170)); - colorsMap.put(ChatColor.DARK_GREEN, new Color(0, 170, 0)); - colorsMap.put(ChatColor.DARK_AQUA, new Color(0, 170, 170)); - colorsMap.put(ChatColor.DARK_RED, new Color(170, 0, 0)); - colorsMap.put(ChatColor.DARK_PURPLE, new Color(170, 0, 170)); - colorsMap.put(ChatColor.GOLD, new Color(255, 170, 0)); - colorsMap.put(ChatColor.BLUE, new Color(85, 85, 255)); - colorsMap.put(ChatColor.GREEN, new Color(85, 255, 85)); - colorsMap.put(ChatColor.AQUA, new Color(85, 255, 255)); - colorsMap.put(ChatColor.RED, new Color(255, 85, 85)); - colorsMap.put(ChatColor.LIGHT_PURPLE, new Color(255, 85, 255)); - colorsMap.put(ChatColor.YELLOW, new Color(255, 255, 85)); - - graysMap.put(ChatColor.BLACK, new Color(0, 0, 0)); - graysMap.put(ChatColor.DARK_GRAY, new Color(85, 85, 85)); - graysMap.put(ChatColor.GRAY, new Color(170, 170, 170)); - graysMap.put(ChatColor.WHITE, new Color(255, 255, 255)); - } - + private static final Map colorsMap = new HashMap<>(); + private static final Map graysMap = new HashMap<>(); + + static { + colorsMap.put(ChatColor.DARK_BLUE, new Color(0, 0, 170)); + colorsMap.put(ChatColor.DARK_GREEN, new Color(0, 170, 0)); + colorsMap.put(ChatColor.DARK_AQUA, new Color(0, 170, 170)); + colorsMap.put(ChatColor.DARK_RED, new Color(170, 0, 0)); + colorsMap.put(ChatColor.DARK_PURPLE, new Color(170, 0, 170)); + colorsMap.put(ChatColor.GOLD, new Color(255, 170, 0)); + colorsMap.put(ChatColor.BLUE, new Color(85, 85, 255)); + colorsMap.put(ChatColor.GREEN, new Color(85, 255, 85)); + colorsMap.put(ChatColor.AQUA, new Color(85, 255, 255)); + colorsMap.put(ChatColor.RED, new Color(255, 85, 85)); + colorsMap.put(ChatColor.LIGHT_PURPLE, new Color(255, 85, 255)); + colorsMap.put(ChatColor.YELLOW, new Color(255, 255, 85)); + + graysMap.put(ChatColor.BLACK, new Color(0, 0, 0)); + graysMap.put(ChatColor.DARK_GRAY, new Color(85, 85, 85)); + graysMap.put(ChatColor.GRAY, new Color(170, 170, 170)); + graysMap.put(ChatColor.WHITE, new Color(255, 255, 255)); + } + private String[] lines; @@ -67,11 +67,11 @@ public class ImageMessage { double ratio = (double) image.getHeight() / image.getWidth(); int height = (int) ((width) * ratio); if (height == 0) { - height = 1; + height = 1; } if (width > MAX_WIDTH) { - throw new TooWideException(width); + throw new TooWideException(width); } BufferedImage resized = resizeImage(image, width, height); @@ -87,42 +87,42 @@ public class ImageMessage { } private String[] toImgMessage(ChatColor[][] colors) { - + String[] lines = new String[colors[0].length]; ChatColor transparencyColor = Configuration.transparencyColor; String transparencySymbol = Configuration.transparencySymbol; String imageSymbol = Configuration.imageSymbol; for (int y = 0; y < colors[0].length; y++) { - + StringBuffer line = new StringBuffer(); ChatColor previous = ChatColor.RESET; for (int x = 0; x < colors.length; x++) { - + ChatColor currentColor = colors[x][y]; if (currentColor == null) { - - // Use the trasparent char - if (previous != transparencyColor) { - - // Change the previous chat color and append the newer - line.append(transparencyColor); - previous = transparencyColor; - - } - line.append(transparencySymbol); - + + // Use the trasparent char + if (previous != transparencyColor) { + + // Change the previous chat color and append the newer + line.append(transparencyColor); + previous = transparencyColor; + + } + line.append(transparencySymbol); + } else { - - if (previous != currentColor) { - line.append(currentColor.toString()); - previous = currentColor; - } - - line.append(imageSymbol); + + if (previous != currentColor) { + line.append(currentColor.toString()); + previous = currentColor; + } + + line.append(imageSymbol); } } @@ -133,7 +133,7 @@ public class ImageMessage { } private BufferedImage resizeImage(BufferedImage originalImage, int width, int height) { - return toBufferedImage(originalImage.getScaledInstance(width, height, Image.SCALE_DEFAULT)); + return toBufferedImage(originalImage.getScaledInstance(width, height, Image.SCALE_DEFAULT)); } private BufferedImage toBufferedImage(Image img) { @@ -169,37 +169,37 @@ public class ImageMessage { } private ChatColor getClosestChatColor(Color color) { - if (color.getAlpha() < 80) return null; + if (color.getAlpha() < 80) return null; for (Entry entry : colorsMap.entrySet()) { - if (areIdentical(entry.getValue(), color)) { - return entry.getKey(); - } + if (areIdentical(entry.getValue(), color)) { + return entry.getKey(); + } } double bestGrayDistance = -1; ChatColor bestGrayMatch = null; for (Entry entry : graysMap.entrySet()) { - double distance = getDistance(color, entry.getValue()); - - if (distance < bestGrayDistance || bestGrayDistance == -1) { + double distance = getDistance(color, entry.getValue()); + + if (distance < bestGrayDistance || bestGrayDistance == -1) { bestGrayDistance = distance; bestGrayMatch = entry.getKey(); } } if (bestGrayDistance < 17500) { - return bestGrayMatch; + return bestGrayMatch; } double bestColorDistance = -1; ChatColor bestColorMatch = null; for (Entry entry : colorsMap.entrySet()) { - double distance = getDistance(color, entry.getValue()); - - if (distance < bestColorDistance || bestColorDistance == -1) { + double distance = getDistance(color, entry.getValue()); + + if (distance < bestColorDistance || bestColorDistance == -1) { bestColorDistance = distance; bestColorMatch = entry.getKey(); } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/listener/MainListener.java b/plugin/src/main/java/me/filoghost/holographicdisplays/listener/MainListener.java index 32054231..b13efcf1 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/listener/MainListener.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/listener/MainListener.java @@ -53,137 +53,137 @@ import java.util.Map; import java.util.logging.Level; public class MainListener implements Listener, ItemPickupManager { - - private NMSManager nmsManager; - - private Map anticlickSpam = new HashMap<>(); - - public MainListener(NMSManager nmsManager) { - this.nmsManager = nmsManager; - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onChunkUnload(ChunkUnloadEvent event) { - for (Entity entity : event.getChunk().getEntities()) { - if (!entity.isDead()) { - NMSEntityBase entityBase = nmsManager.getNMSEntityBase(entity); - - if (entityBase != null) { - ((CraftHologram) entityBase.getHologramLine().getParent()).despawnEntities(); - } - } - } - } - - @EventHandler (priority = EventPriority.MONITOR) - public void onChunkLoad(ChunkLoadEvent event) { - Chunk chunk = event.getChunk(); - - // Other plugins could call this event wrongly, check if the chunk is actually loaded. - if (chunk.isLoaded()) { - - // In case another plugin loads the chunk asynchronously always make sure to load the holograms on the main thread. - if (Bukkit.isPrimaryThread()) { - processChunkLoad(chunk); - } else { - Bukkit.getScheduler().runTask(HolographicDisplays.getInstance(), () -> processChunkLoad(chunk)); - } - } - } - - // This method should be always called synchronously. - public void processChunkLoad(Chunk chunk) { - NamedHologramManager.onChunkLoad(chunk); - PluginHologramManager.onChunkLoad(chunk); - } - - @EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = false) - public void onCreatureSpawn(CreatureSpawnEvent event) { - if (nmsManager.isNMSEntityBase(event.getEntity())) { - if (event.isCancelled()) { - event.setCancelled(false); - } - } - } - - @EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = false) - public void onProjectileLaunch(ProjectileLaunchEvent event) { - if (nmsManager.isNMSEntityBase(event.getEntity())) { - if (event.isCancelled()) { - event.setCancelled(false); - } - } - } - - @EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = false) - public void onItemSpawn(ItemSpawnEvent event) { - if (nmsManager.isNMSEntityBase(event.getEntity())) { - if (event.isCancelled()) { - event.setCancelled(false); - } - } - } - - @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; - } - - NMSEntityBase entityBase = nmsManager.getNMSEntityBase(event.getRightClicked()); - if (entityBase == null || !(entityBase.getHologramLine() instanceof CraftTouchSlimeLine)) { - return; - } - - CraftTouchSlimeLine touchSlime = (CraftTouchSlimeLine) entityBase.getHologramLine(); - if (touchSlime.getTouchablePiece().getTouchHandler() == null || !touchSlime.getParent().getVisibilityManager().isVisibleTo(clicker)) { - return; - } - - Long lastClick = anticlickSpam.get(clicker); - if (lastClick != null && System.currentTimeMillis() - lastClick.longValue() < 100) { - return; - } - - anticlickSpam.put(event.getPlayer(), System.currentTimeMillis()); - - try { - touchSlime.getTouchablePiece().getTouchHandler().onTouch(event.getPlayer()); - } catch (Throwable t) { - Plugin plugin = touchSlime.getParent() instanceof PluginHologram ? ((PluginHologram) touchSlime.getParent()).getOwner() : HolographicDisplays.getInstance(); - ConsoleLogger.log(Level.WARNING, "The plugin " + plugin.getName() + " generated an exception when the player " + event.getPlayer().getName() + " touched a hologram.", t); - } - } - - @Override - public void handleItemLinePickup(Player player, PickupHandler pickupHandler, Hologram hologram) { - try { - if (hologram.getVisibilityManager().isVisibleTo(player)) { - pickupHandler.onPickup(player); - } - } catch (Throwable t) { - Plugin plugin = hologram instanceof PluginHologram ? ((PluginHologram) hologram).getOwner() : HolographicDisplays.getInstance(); - ConsoleLogger.log(Level.WARNING, "The plugin " + plugin.getName() + " generated an exception when the player " + player.getName() + " picked up an item from a hologram.", t); - } - } - - @EventHandler - public void onJoin(PlayerJoinEvent event) { - if (Configuration.updateNotification && HolographicDisplays.getNewVersion() != null) { - if (event.getPlayer().hasPermission(Strings.BASE_PERM + "update")) { - event.getPlayer().sendMessage(Colors.PRIMARY_SHADOW + "[HolographicDisplays] " + Colors.PRIMARY + "Found an update: " + HolographicDisplays.getNewVersion() + ". Download:"); - event.getPlayer().sendMessage(Colors.PRIMARY_SHADOW + ">> " + Colors.PRIMARY + "http://dev.bukkit.org/bukkit-plugins/holographic-displays"); - } - } - } - - @EventHandler - public void onQuit(PlayerQuitEvent event) { - anticlickSpam.remove(event.getPlayer()); - } + + private NMSManager nmsManager; + + private Map anticlickSpam = new HashMap<>(); + + public MainListener(NMSManager nmsManager) { + this.nmsManager = nmsManager; + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onChunkUnload(ChunkUnloadEvent event) { + for (Entity entity : event.getChunk().getEntities()) { + if (!entity.isDead()) { + NMSEntityBase entityBase = nmsManager.getNMSEntityBase(entity); + + if (entityBase != null) { + ((CraftHologram) entityBase.getHologramLine().getParent()).despawnEntities(); + } + } + } + } + + @EventHandler (priority = EventPriority.MONITOR) + public void onChunkLoad(ChunkLoadEvent event) { + Chunk chunk = event.getChunk(); + + // Other plugins could call this event wrongly, check if the chunk is actually loaded. + if (chunk.isLoaded()) { + + // In case another plugin loads the chunk asynchronously always make sure to load the holograms on the main thread. + if (Bukkit.isPrimaryThread()) { + processChunkLoad(chunk); + } else { + Bukkit.getScheduler().runTask(HolographicDisplays.getInstance(), () -> processChunkLoad(chunk)); + } + } + } + + // This method should be always called synchronously. + public void processChunkLoad(Chunk chunk) { + NamedHologramManager.onChunkLoad(chunk); + PluginHologramManager.onChunkLoad(chunk); + } + + @EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = false) + public void onCreatureSpawn(CreatureSpawnEvent event) { + if (nmsManager.isNMSEntityBase(event.getEntity())) { + if (event.isCancelled()) { + event.setCancelled(false); + } + } + } + + @EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = false) + public void onProjectileLaunch(ProjectileLaunchEvent event) { + if (nmsManager.isNMSEntityBase(event.getEntity())) { + if (event.isCancelled()) { + event.setCancelled(false); + } + } + } + + @EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = false) + public void onItemSpawn(ItemSpawnEvent event) { + if (nmsManager.isNMSEntityBase(event.getEntity())) { + if (event.isCancelled()) { + event.setCancelled(false); + } + } + } + + @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; + } + + NMSEntityBase entityBase = nmsManager.getNMSEntityBase(event.getRightClicked()); + if (entityBase == null || !(entityBase.getHologramLine() instanceof CraftTouchSlimeLine)) { + return; + } + + CraftTouchSlimeLine touchSlime = (CraftTouchSlimeLine) entityBase.getHologramLine(); + if (touchSlime.getTouchablePiece().getTouchHandler() == null || !touchSlime.getParent().getVisibilityManager().isVisibleTo(clicker)) { + return; + } + + Long lastClick = anticlickSpam.get(clicker); + if (lastClick != null && System.currentTimeMillis() - lastClick.longValue() < 100) { + return; + } + + anticlickSpam.put(event.getPlayer(), System.currentTimeMillis()); + + try { + touchSlime.getTouchablePiece().getTouchHandler().onTouch(event.getPlayer()); + } catch (Throwable t) { + Plugin plugin = touchSlime.getParent() instanceof PluginHologram ? ((PluginHologram) touchSlime.getParent()).getOwner() : HolographicDisplays.getInstance(); + ConsoleLogger.log(Level.WARNING, "The plugin " + plugin.getName() + " generated an exception when the player " + event.getPlayer().getName() + " touched a hologram.", t); + } + } + + @Override + public void handleItemLinePickup(Player player, PickupHandler pickupHandler, Hologram hologram) { + try { + if (hologram.getVisibilityManager().isVisibleTo(player)) { + pickupHandler.onPickup(player); + } + } catch (Throwable t) { + Plugin plugin = hologram instanceof PluginHologram ? ((PluginHologram) hologram).getOwner() : HolographicDisplays.getInstance(); + ConsoleLogger.log(Level.WARNING, "The plugin " + plugin.getName() + " generated an exception when the player " + player.getName() + " picked up an item from a hologram.", t); + } + } + + @EventHandler + public void onJoin(PlayerJoinEvent event) { + if (Configuration.updateNotification && HolographicDisplays.getNewVersion() != null) { + if (event.getPlayer().hasPermission(Strings.BASE_PERM + "update")) { + event.getPlayer().sendMessage(Colors.PRIMARY_SHADOW + "[HolographicDisplays] " + Colors.PRIMARY + "Found an update: " + HolographicDisplays.getNewVersion() + ". Download:"); + event.getPlayer().sendMessage(Colors.PRIMARY_SHADOW + ">> " + Colors.PRIMARY + "http://dev.bukkit.org/bukkit-plugins/holographic-displays"); + } + } + } + + @EventHandler + public void onQuit(PlayerQuitEvent event) { + anticlickSpam.remove(event.getPlayer()); + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/object/CraftHologram.java b/plugin/src/main/java/me/filoghost/holographicdisplays/object/CraftHologram.java index 63db5061..855989f5 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/object/CraftHologram.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/object/CraftHologram.java @@ -34,327 +34,327 @@ import java.util.List; * This class is only used by the plugin itself. Do not attempt to use it. */ public class CraftHologram implements Hologram { - - // Position variables. - private World world; - private double x, y, z; - private int chunkX, chunkZ; - - // The entities that represent lines. - private final List lines; - - private CraftVisibilityManager visibilityManager; - private boolean allowPlaceholders; - private long creationTimestamp; - private boolean deleted; - - public CraftHologram(Location location) { - Validator.notNull(location, "location"); - updateLocation(location.getWorld(), location.getX(), location.getY(), location.getZ()); - - lines = new ArrayList<>(); - allowPlaceholders = false; - creationTimestamp = System.currentTimeMillis(); - visibilityManager = new CraftVisibilityManager(this); - } - - public boolean isInChunk(Chunk chunk) { - return chunk.getWorld() == world && chunk.getX() == chunkX && chunk.getZ() == chunkZ; - } - - @Override - public World getWorld() { - return world; - } - - @Override - public double getX() { - return x; - } - - @Override - public double getY() { - return y; - } - - @Override - public double getZ() { - return z; - } - - @Override - public Location getLocation() { - return new Location(world, x, y, z); - } - - private void updateLocation(World world, double x, double y, double z) { - Validator.notNull(world, "world"); - - this.world = world; - this.x = x; - this.y = y; - this.z = z; - chunkX = Utils.floor(x) >> 4; - chunkZ = Utils.floor(z) >> 4; - } - - @Override - public boolean isDeleted() { - return deleted; - } - - @Override - public void delete() { - if (!deleted) { - deleted = true; - clearLines(); - } - } - - public List getLinesUnsafe() { - return lines; - } - - @Override - public CraftHologramLine getLine(int index) { - return lines.get(index); - } - - @Override - public CraftTextLine appendTextLine(String text) { - Validator.isTrue(!deleted, "hologram already deleted"); - - CraftTextLine line = new CraftTextLine(this, text); - lines.add(line); - refreshSingleLines(); - return line; - } - - @Override - public CraftItemLine appendItemLine(ItemStack itemStack) { - Validator.isTrue(!deleted, "hologram already deleted"); - Validator.notNull(itemStack, "itemStack"); - - CraftItemLine line = new CraftItemLine(this, itemStack); - lines.add(line); - refreshSingleLines(); - return line; - } - - @Override - public CraftTextLine insertTextLine(int index, String text) { - Validator.isTrue(!deleted, "hologram already deleted"); - - CraftTextLine line = new CraftTextLine(this, text); - lines.add(index, line); - refreshSingleLines(); - return line; - } - - @Override - public CraftItemLine insertItemLine(int index, ItemStack itemStack) { - Validator.isTrue(!deleted, "hologram already deleted"); - Validator.notNull(itemStack, "itemStack"); - - CraftItemLine line = new CraftItemLine(this, itemStack); - lines.add(index, line); - refreshSingleLines(); - return line; - } - - @Override - public void removeLine(int index) { - Validator.isTrue(!deleted, "hologram already deleted"); - - lines.remove(index).despawn(); - refreshSingleLines(); - } - - public void removeLine(CraftHologramLine line) { - Validator.isTrue(!deleted, "hologram already deleted"); - - lines.remove(line); - line.despawn(); - refreshSingleLines(); - } - - @Override - public void clearLines() { - for (CraftHologramLine line : lines) { - line.despawn(); - } - - lines.clear(); - } - - @Override - public int size() { - return lines.size(); - } - - @Override - public double getHeight() { - if (lines.isEmpty()) { - return 0; - } - - double height = 0.0; - - for (CraftHologramLine line : lines) { - height += line.getHeight(); - } - - height += Configuration.spaceBetweenLines * (lines.size() - 1); - return height; - } - - @Override - public CraftVisibilityManager getVisibilityManager() { - return visibilityManager; - } - - - @Override - public long getCreationTimestamp() { - return creationTimestamp; - } + + // Position variables. + private World world; + private double x, y, z; + private int chunkX, chunkZ; + + // The entities that represent lines. + private final List lines; + + private CraftVisibilityManager visibilityManager; + private boolean allowPlaceholders; + private long creationTimestamp; + private boolean deleted; + + public CraftHologram(Location location) { + Validator.notNull(location, "location"); + updateLocation(location.getWorld(), location.getX(), location.getY(), location.getZ()); + + lines = new ArrayList<>(); + allowPlaceholders = false; + creationTimestamp = System.currentTimeMillis(); + visibilityManager = new CraftVisibilityManager(this); + } + + public boolean isInChunk(Chunk chunk) { + return chunk.getWorld() == world && chunk.getX() == chunkX && chunk.getZ() == chunkZ; + } + + @Override + public World getWorld() { + return world; + } + + @Override + public double getX() { + return x; + } + + @Override + public double getY() { + return y; + } + + @Override + public double getZ() { + return z; + } + + @Override + public Location getLocation() { + return new Location(world, x, y, z); + } + + private void updateLocation(World world, double x, double y, double z) { + Validator.notNull(world, "world"); + + this.world = world; + this.x = x; + this.y = y; + this.z = z; + chunkX = Utils.floor(x) >> 4; + chunkZ = Utils.floor(z) >> 4; + } + + @Override + public boolean isDeleted() { + return deleted; + } + + @Override + public void delete() { + if (!deleted) { + deleted = true; + clearLines(); + } + } + + public List getLinesUnsafe() { + return lines; + } + + @Override + public CraftHologramLine getLine(int index) { + return lines.get(index); + } + + @Override + public CraftTextLine appendTextLine(String text) { + Validator.isTrue(!deleted, "hologram already deleted"); + + CraftTextLine line = new CraftTextLine(this, text); + lines.add(line); + refreshSingleLines(); + return line; + } + + @Override + public CraftItemLine appendItemLine(ItemStack itemStack) { + Validator.isTrue(!deleted, "hologram already deleted"); + Validator.notNull(itemStack, "itemStack"); + + CraftItemLine line = new CraftItemLine(this, itemStack); + lines.add(line); + refreshSingleLines(); + return line; + } + + @Override + public CraftTextLine insertTextLine(int index, String text) { + Validator.isTrue(!deleted, "hologram already deleted"); + + CraftTextLine line = new CraftTextLine(this, text); + lines.add(index, line); + refreshSingleLines(); + return line; + } + + @Override + public CraftItemLine insertItemLine(int index, ItemStack itemStack) { + Validator.isTrue(!deleted, "hologram already deleted"); + Validator.notNull(itemStack, "itemStack"); + + CraftItemLine line = new CraftItemLine(this, itemStack); + lines.add(index, line); + refreshSingleLines(); + return line; + } + + @Override + public void removeLine(int index) { + Validator.isTrue(!deleted, "hologram already deleted"); + + lines.remove(index).despawn(); + refreshSingleLines(); + } + + public void removeLine(CraftHologramLine line) { + Validator.isTrue(!deleted, "hologram already deleted"); + + lines.remove(line); + line.despawn(); + refreshSingleLines(); + } + + @Override + public void clearLines() { + for (CraftHologramLine line : lines) { + line.despawn(); + } + + lines.clear(); + } + + @Override + public int size() { + return lines.size(); + } + + @Override + public double getHeight() { + if (lines.isEmpty()) { + return 0; + } + + double height = 0.0; + + for (CraftHologramLine line : lines) { + height += line.getHeight(); + } + + height += Configuration.spaceBetweenLines * (lines.size() - 1); + return height; + } + + @Override + public CraftVisibilityManager getVisibilityManager() { + return visibilityManager; + } + + + @Override + public long getCreationTimestamp() { + return creationTimestamp; + } - @Override - public boolean isAllowPlaceholders() { - return allowPlaceholders; - } + @Override + public boolean isAllowPlaceholders() { + return allowPlaceholders; + } - @Override - public void setAllowPlaceholders(boolean allowPlaceholders) { - if (this.allowPlaceholders == allowPlaceholders) { - return; - } - - this.allowPlaceholders = allowPlaceholders; - refreshAll(); - } - + @Override + public void setAllowPlaceholders(boolean allowPlaceholders) { + if (this.allowPlaceholders == allowPlaceholders) { + return; + } + + this.allowPlaceholders = allowPlaceholders; + refreshAll(); + } + - public void refreshAll() { - if (world.isChunkLoaded(chunkX, chunkZ)) { - spawnEntities(); - } - } - - public void refreshSingleLines() { - if (world.isChunkLoaded(chunkX, chunkZ)) { - - double currentY = this.y; - boolean first = true; - - for (CraftHologramLine line : lines) { - - currentY -= line.getHeight(); - - if (first) { - first = false; - } else { - currentY -= Configuration.spaceBetweenLines; - } - - if (line.isSpawned()) { - line.teleport(x, currentY, z); - } else { - line.spawn(world, x, currentY, z); - if (allowPlaceholders && line instanceof CraftTextLine) { - PlaceholdersManager.trackIfNecessary((CraftTextLine) line); - } - } - } - } - } - - /** - * Forces the entities to spawn, without checking if the chunk is loaded. - */ - public void spawnEntities() { - Validator.isTrue(!deleted, "hologram already deleted"); - - despawnEntities(); + public void refreshAll() { + if (world.isChunkLoaded(chunkX, chunkZ)) { + spawnEntities(); + } + } + + public void refreshSingleLines() { + if (world.isChunkLoaded(chunkX, chunkZ)) { + + double currentY = this.y; + boolean first = true; + + for (CraftHologramLine line : lines) { + + currentY -= line.getHeight(); + + if (first) { + first = false; + } else { + currentY -= Configuration.spaceBetweenLines; + } + + if (line.isSpawned()) { + line.teleport(x, currentY, z); + } else { + line.spawn(world, x, currentY, z); + if (allowPlaceholders && line instanceof CraftTextLine) { + PlaceholdersManager.trackIfNecessary((CraftTextLine) line); + } + } + } + } + } + + /** + * Forces the entities to spawn, without checking if the chunk is loaded. + */ + public void spawnEntities() { + Validator.isTrue(!deleted, "hologram already deleted"); + + despawnEntities(); - double currentY = this.y; - boolean first = true; - - for (CraftHologramLine line : lines) { - - currentY -= line.getHeight(); - - if (first) { - first = false; - } else { - currentY -= Configuration.spaceBetweenLines; - } - - line.spawn(world, x, currentY, z); - if (allowPlaceholders && line instanceof CraftTextLine) { - PlaceholdersManager.trackIfNecessary((CraftTextLine) line); - } - } - } - - /** - * Called by the PluginHologramManager when the chunk is unloaded. - */ - public void despawnEntities() { - for (CraftHologramLine piece : lines) { - piece.despawn(); - } - } - - @Override - public void teleport(Location location) { - Validator.notNull(location, "location"); - teleport(location.getWorld(), location.getX(), location.getY(), location.getZ()); - } - - @Override - public void teleport(World world, double x, double y, double z) { - Validator.isTrue(!deleted, "hologram already deleted"); - Validator.notNull(world, "world"); - - updateLocation(world, x, y, z); - - if (this.world != world) { - despawnEntities(); - refreshAll(); - return; - } - - double currentY = y; - boolean first = true; - - for (CraftHologramLine line : lines) { - - if (!line.isSpawned()) { - continue; - } - - currentY -= line.getHeight(); - - if (first) { - first = false; - } else { - currentY -= Configuration.spaceBetweenLines; - } - - line.teleport(x, currentY, z); - } - } + double currentY = this.y; + boolean first = true; + + for (CraftHologramLine line : lines) { + + currentY -= line.getHeight(); + + if (first) { + first = false; + } else { + currentY -= Configuration.spaceBetweenLines; + } + + line.spawn(world, x, currentY, z); + if (allowPlaceholders && line instanceof CraftTextLine) { + PlaceholdersManager.trackIfNecessary((CraftTextLine) line); + } + } + } + + /** + * Called by the PluginHologramManager when the chunk is unloaded. + */ + public void despawnEntities() { + for (CraftHologramLine piece : lines) { + piece.despawn(); + } + } + + @Override + public void teleport(Location location) { + Validator.notNull(location, "location"); + teleport(location.getWorld(), location.getX(), location.getY(), location.getZ()); + } + + @Override + public void teleport(World world, double x, double y, double z) { + Validator.isTrue(!deleted, "hologram already deleted"); + Validator.notNull(world, "world"); + + updateLocation(world, x, y, z); + + if (this.world != world) { + despawnEntities(); + refreshAll(); + return; + } + + double currentY = y; + boolean first = true; + + for (CraftHologramLine line : lines) { + + if (!line.isSpawned()) { + continue; + } + + currentY -= line.getHeight(); + + if (first) { + first = false; + } else { + currentY -= Configuration.spaceBetweenLines; + } + + line.teleport(x, currentY, z); + } + } - @Override - public String toString() { - return "CraftHologram [world=" + world + ", x=" + x + ", y=" + y + ", z=" + z + ", lines=" + lines + ", deleted=" + deleted + "]"; - } + @Override + public String toString() { + return "CraftHologram [world=" + world + ", x=" + x + ", y=" + y + ", z=" + z + ", lines=" + lines + ", deleted=" + deleted + "]"; + } - /** - * About: equals() and hashcode() - * Two holograms can never be equal. Even if they have the same position and the same elements, they are still two different objects. - * The equals and hashcode methods are not overriden, two holograms are equal only if they have the same memory address. - */ - + /** + * About: equals() and hashcode() + * Two holograms can never be equal. Even if they have the same position and the same elements, they are still two different objects. + * The equals and hashcode methods are not overriden, two holograms are equal only if they have the same memory address. + */ + } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/object/CraftVisibilityManager.java b/plugin/src/main/java/me/filoghost/holographicdisplays/object/CraftVisibilityManager.java index 4295099a..bae9365a 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/object/CraftVisibilityManager.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/object/CraftVisibilityManager.java @@ -27,158 +27,158 @@ import java.util.concurrent.ConcurrentHashMap; public class CraftVisibilityManager implements VisibilityManager { - private final CraftHologram hologram; - private Map playersVisibilityMap; - private boolean visibleByDefault; + private final CraftHologram hologram; + private Map playersVisibilityMap; + private boolean visibleByDefault; - private static final int VISIBILITY_DISTANCE_SQUARED = 64 * 64; - - public CraftVisibilityManager(CraftHologram hologram) { - Validator.notNull(hologram, "hologram"); - this.hologram = hologram; - this.visibleByDefault = true; - } - - @Override - public boolean isVisibleByDefault() { - return visibleByDefault; - } - - @Override - public void setVisibleByDefault(boolean visibleByDefault) { - if (this.visibleByDefault != visibleByDefault) { - - boolean oldVisibleByDefault = this.visibleByDefault; - this.visibleByDefault = visibleByDefault; - - for (Player player : Bukkit.getOnlinePlayers()) { - - if (playersVisibilityMap != null && playersVisibilityMap.containsKey(player.getName().toLowerCase())) { - // Has a specific value set - continue; - } - - if (oldVisibleByDefault) { - // If previously was visible, now is NOT visible by default, because the value has changed - sendDestroyPacketIfNear(player, hologram); - } else { - // Opposite case - sendCreatePacketIfNear(player, hologram); - } - } - } - } - - @Override - public void showTo(Player player) { - Validator.notNull(player, "player"); - - boolean wasVisible = isVisibleTo(player); - - if (playersVisibilityMap == null) { - // Lazy initialization - playersVisibilityMap = new ConcurrentHashMap<>(); - } - - playersVisibilityMap.put(player.getName().toLowerCase(), true); - - if (!wasVisible) { - sendCreatePacketIfNear(player, hologram); - } - } - - - @Override - public void hideTo(Player player) { - Validator.notNull(player, "player"); - - boolean wasVisible = isVisibleTo(player); - - if (playersVisibilityMap == null) { - // Lazy initialization - playersVisibilityMap = new ConcurrentHashMap<>(); - } - - playersVisibilityMap.put(player.getName().toLowerCase(), false); - - if (wasVisible) { - sendDestroyPacketIfNear(player, hologram); - } - } - - @Override - public boolean isVisibleTo(Player player) { - Validator.notNull(player, "player"); - - if (playersVisibilityMap != null) { + private static final int VISIBILITY_DISTANCE_SQUARED = 64 * 64; + + public CraftVisibilityManager(CraftHologram hologram) { + Validator.notNull(hologram, "hologram"); + this.hologram = hologram; + this.visibleByDefault = true; + } + + @Override + public boolean isVisibleByDefault() { + return visibleByDefault; + } + + @Override + public void setVisibleByDefault(boolean visibleByDefault) { + if (this.visibleByDefault != visibleByDefault) { + + boolean oldVisibleByDefault = this.visibleByDefault; + this.visibleByDefault = visibleByDefault; + + for (Player player : Bukkit.getOnlinePlayers()) { + + if (playersVisibilityMap != null && playersVisibilityMap.containsKey(player.getName().toLowerCase())) { + // Has a specific value set + continue; + } + + if (oldVisibleByDefault) { + // If previously was visible, now is NOT visible by default, because the value has changed + sendDestroyPacketIfNear(player, hologram); + } else { + // Opposite case + sendCreatePacketIfNear(player, hologram); + } + } + } + } + + @Override + public void showTo(Player player) { + Validator.notNull(player, "player"); + + boolean wasVisible = isVisibleTo(player); + + if (playersVisibilityMap == null) { + // Lazy initialization + playersVisibilityMap = new ConcurrentHashMap<>(); + } + + playersVisibilityMap.put(player.getName().toLowerCase(), true); + + if (!wasVisible) { + sendCreatePacketIfNear(player, hologram); + } + } + + + @Override + public void hideTo(Player player) { + Validator.notNull(player, "player"); + + boolean wasVisible = isVisibleTo(player); + + if (playersVisibilityMap == null) { + // Lazy initialization + playersVisibilityMap = new ConcurrentHashMap<>(); + } + + playersVisibilityMap.put(player.getName().toLowerCase(), false); + + if (wasVisible) { + sendDestroyPacketIfNear(player, hologram); + } + } + + @Override + public boolean isVisibleTo(Player player) { + Validator.notNull(player, "player"); + + if (playersVisibilityMap != null) { - Boolean value = playersVisibilityMap.get(player.getName().toLowerCase()); - if (value != null) { - return value; - } - } + Boolean value = playersVisibilityMap.get(player.getName().toLowerCase()); + if (value != null) { + return value; + } + } - return visibleByDefault; - } + return visibleByDefault; + } - @Override - public void resetVisibility(Player player) { - Validator.notNull(player, "player"); - - if (playersVisibilityMap == null) { - return; - } - - boolean wasVisible = isVisibleTo(player); - - playersVisibilityMap.remove(player.getName().toLowerCase()); - - if (visibleByDefault && !wasVisible) { - sendCreatePacketIfNear(player, hologram); - - } else if (!visibleByDefault && wasVisible) { - sendDestroyPacketIfNear(player, hologram); - } - } - - @Override - public void resetVisibilityAll() { - if (playersVisibilityMap != null) { - - // We need to refresh all the players - Set playerNames = new HashSet<>(playersVisibilityMap.keySet()); - - for (String playerName : playerNames) { - Player onlinePlayer = Bukkit.getPlayerExact(playerName); - if (onlinePlayer != null) { - resetVisibility(onlinePlayer); - } - } - - playersVisibilityMap.clear(); - playersVisibilityMap = null; - } - } - - private static void sendCreatePacketIfNear(Player player, CraftHologram hologram) { - if (HolographicDisplays.hasProtocolLibHook() && isNear(player, hologram)) { - HolographicDisplays.getProtocolLibHook().sendCreateEntitiesPacket(player, hologram); - } - } - - private static void sendDestroyPacketIfNear(Player player, CraftHologram hologram) { - if (HolographicDisplays.hasProtocolLibHook() && isNear(player, hologram)) { - HolographicDisplays.getProtocolLibHook().sendDestroyEntitiesPacket(player, hologram); - } - } - - private static boolean isNear(Player player, CraftHologram hologram) { - return player.isOnline() && player.getWorld().equals(hologram.getWorld()) && player.getLocation().distanceSquared(hologram.getLocation()) < VISIBILITY_DISTANCE_SQUARED; - } + @Override + public void resetVisibility(Player player) { + Validator.notNull(player, "player"); + + if (playersVisibilityMap == null) { + return; + } + + boolean wasVisible = isVisibleTo(player); + + playersVisibilityMap.remove(player.getName().toLowerCase()); + + if (visibleByDefault && !wasVisible) { + sendCreatePacketIfNear(player, hologram); + + } else if (!visibleByDefault && wasVisible) { + sendDestroyPacketIfNear(player, hologram); + } + } + + @Override + public void resetVisibilityAll() { + if (playersVisibilityMap != null) { + + // We need to refresh all the players + Set playerNames = new HashSet<>(playersVisibilityMap.keySet()); + + for (String playerName : playerNames) { + Player onlinePlayer = Bukkit.getPlayerExact(playerName); + if (onlinePlayer != null) { + resetVisibility(onlinePlayer); + } + } + + playersVisibilityMap.clear(); + playersVisibilityMap = null; + } + } + + private static void sendCreatePacketIfNear(Player player, CraftHologram hologram) { + if (HolographicDisplays.hasProtocolLibHook() && isNear(player, hologram)) { + HolographicDisplays.getProtocolLibHook().sendCreateEntitiesPacket(player, hologram); + } + } + + private static void sendDestroyPacketIfNear(Player player, CraftHologram hologram) { + if (HolographicDisplays.hasProtocolLibHook() && isNear(player, hologram)) { + HolographicDisplays.getProtocolLibHook().sendDestroyEntitiesPacket(player, hologram); + } + } + + private static boolean isNear(Player player, CraftHologram hologram) { + return player.isOnline() && player.getWorld().equals(hologram.getWorld()) && player.getLocation().distanceSquared(hologram.getLocation()) < VISIBILITY_DISTANCE_SQUARED; + } - @Override - public String toString() { - return "CraftVisibilityManager [playersMap=" + playersVisibilityMap + ", visibleByDefault=" + visibleByDefault + "]"; - } - + @Override + public String toString() { + return "CraftVisibilityManager [playersMap=" + playersVisibilityMap + ", visibleByDefault=" + visibleByDefault + "]"; + } + } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/object/DefaultBackendAPI.java b/plugin/src/main/java/me/filoghost/holographicdisplays/object/DefaultBackendAPI.java index 04d95630..dca90801 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/object/DefaultBackendAPI.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/object/DefaultBackendAPI.java @@ -29,53 +29,53 @@ import org.bukkit.plugin.Plugin; import java.util.Collection; public class DefaultBackendAPI extends BackendAPI { - - public Hologram createHologram(Plugin plugin, Location source) { - Validator.notNull(plugin, "plugin"); - Validator.notNull(source, "source"); - Validator.notNull(source.getWorld(), "source's world"); - Validator.isTrue(Bukkit.isPrimaryThread(), "Async hologram creation"); - - PluginHologram hologram = new PluginHologram(source, plugin); - PluginHologramManager.addHologram(hologram); - - return hologram; - } - - public boolean registerPlaceholder(Plugin plugin, String textPlaceholder, double refreshRate, PlaceholderReplacer replacer) { - Validator.notNull(textPlaceholder, "textPlaceholder"); - Validator.isTrue(refreshRate >= 0, "refreshRate should be positive"); - Validator.notNull(replacer, "replacer"); - - return PlaceholdersRegister.register(new Placeholder(plugin, textPlaceholder, refreshRate, replacer)); - } + + public Hologram createHologram(Plugin plugin, Location source) { + Validator.notNull(plugin, "plugin"); + Validator.notNull(source, "source"); + Validator.notNull(source.getWorld(), "source's world"); + Validator.isTrue(Bukkit.isPrimaryThread(), "Async hologram creation"); + + PluginHologram hologram = new PluginHologram(source, plugin); + PluginHologramManager.addHologram(hologram); + + return hologram; + } + + public boolean registerPlaceholder(Plugin plugin, String textPlaceholder, double refreshRate, PlaceholderReplacer replacer) { + Validator.notNull(textPlaceholder, "textPlaceholder"); + Validator.isTrue(refreshRate >= 0, "refreshRate should be positive"); + Validator.notNull(replacer, "replacer"); + + return PlaceholdersRegister.register(new Placeholder(plugin, textPlaceholder, refreshRate, replacer)); + } - public boolean isHologramEntity(Entity bukkitEntity) { - Validator.notNull(bukkitEntity, "bukkitEntity"); - return HolographicDisplays.getNMSManager().isNMSEntityBase(bukkitEntity); - } + public boolean isHologramEntity(Entity bukkitEntity) { + Validator.notNull(bukkitEntity, "bukkitEntity"); + return HolographicDisplays.getNMSManager().isNMSEntityBase(bukkitEntity); + } - public Collection getHolograms(Plugin plugin) { - Validator.notNull(plugin, "plugin"); - return PluginHologramManager.getHolograms(plugin); - } + public Collection getHolograms(Plugin plugin) { + Validator.notNull(plugin, "plugin"); + return PluginHologramManager.getHolograms(plugin); + } - public Collection getRegisteredPlaceholders(Plugin plugin) { - Validator.notNull(plugin, "plugin"); - return PlaceholdersRegister.getTextPlaceholdersByPlugin(plugin); - } + public Collection getRegisteredPlaceholders(Plugin plugin) { + Validator.notNull(plugin, "plugin"); + return PlaceholdersRegister.getTextPlaceholdersByPlugin(plugin); + } - public boolean unregisterPlaceholder(Plugin plugin, String textPlaceholder) { - Validator.notNull(plugin, "plugin"); - Validator.notNull(textPlaceholder, "textPlaceholder"); - return PlaceholdersRegister.unregister(plugin, textPlaceholder); - } + public boolean unregisterPlaceholder(Plugin plugin, String textPlaceholder) { + Validator.notNull(plugin, "plugin"); + Validator.notNull(textPlaceholder, "textPlaceholder"); + return PlaceholdersRegister.unregister(plugin, textPlaceholder); + } - public void unregisterPlaceholders(Plugin plugin) { - Validator.notNull(plugin, "plugin"); - for (String placeholder : getRegisteredPlaceholders(plugin)) { - unregisterPlaceholder(plugin, placeholder); - } - } + public void unregisterPlaceholders(Plugin plugin) { + Validator.notNull(plugin, "plugin"); + for (String placeholder : getRegisteredPlaceholders(plugin)) { + unregisterPlaceholder(plugin, placeholder); + } + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/object/NamedHologram.java b/plugin/src/main/java/me/filoghost/holographicdisplays/object/NamedHologram.java index 81a65a12..a37ddaa2 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/object/NamedHologram.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/object/NamedHologram.java @@ -18,27 +18,27 @@ import org.bukkit.Location; public class NamedHologram extends CraftHologram { - private final String name; - - public NamedHologram(Location source, String name) { - super(source); - this.name = name; - setAllowPlaceholders(true); - } + private final String name; + + public NamedHologram(Location source, String name) { + super(source); + this.name = name; + setAllowPlaceholders(true); + } - public String getName() { - return name; - } - - @Override - public void delete() { - super.delete(); - NamedHologramManager.removeHologram(this); - } + public String getName() { + return name; + } + + @Override + public void delete() { + super.delete(); + NamedHologramManager.removeHologram(this); + } - @Override - public String toString() { - return "NamedHologram [name=" + name + ", super=" + super.toString() + "]"; - } - + @Override + public String toString() { + return "NamedHologram [name=" + name + ", super=" + super.toString() + "]"; + } + } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/object/NamedHologramManager.java b/plugin/src/main/java/me/filoghost/holographicdisplays/object/NamedHologramManager.java index d1df800c..7d26fbb9 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/object/NamedHologramManager.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/object/NamedHologramManager.java @@ -24,68 +24,68 @@ import java.util.List; */ public class NamedHologramManager { - private static List pluginHolograms = new ArrayList<>(); - - public static void addHologram(NamedHologram hologram) { - pluginHolograms.add(hologram); - } - - public static void removeHologram(NamedHologram hologram) { - pluginHolograms.remove(hologram); - if (!hologram.isDeleted()) { - hologram.delete(); - } - } - - public static List getHolograms() { - return new ArrayList<>(pluginHolograms); - } - - public static NamedHologram getHologram(String name) { - for (NamedHologram hologram : pluginHolograms) { - if (hologram.getName().equalsIgnoreCase(name)) { - return hologram; - } - } - return null; - } - - public static boolean isExistingHologram(String name) { - return (getHologram(name) != null); - } + private static List pluginHolograms = new ArrayList<>(); + + public static void addHologram(NamedHologram hologram) { + pluginHolograms.add(hologram); + } + + public static void removeHologram(NamedHologram hologram) { + pluginHolograms.remove(hologram); + if (!hologram.isDeleted()) { + hologram.delete(); + } + } + + public static List getHolograms() { + return new ArrayList<>(pluginHolograms); + } + + public static NamedHologram getHologram(String name) { + for (NamedHologram hologram : pluginHolograms) { + if (hologram.getName().equalsIgnoreCase(name)) { + return hologram; + } + } + return null; + } + + public static boolean isExistingHologram(String name) { + return (getHologram(name) != null); + } - public static void onChunkLoad(Chunk chunk) { - // Load the holograms in that chunk. - for (NamedHologram hologram : pluginHolograms) { - if (hologram.isInChunk(chunk)) { - hologram.spawnEntities(); - } - } - } - - public static void onChunkUnload(Chunk chunk) { - // Hide the holograms in that chunk. - for (NamedHologram hologram : pluginHolograms) { - if (hologram.isInChunk(chunk)) { - hologram.despawnEntities(); - } - } - } - - public static void clearAll() { - List oldHolograms = new ArrayList<>(pluginHolograms); - pluginHolograms.clear(); - - for (NamedHologram hologram : oldHolograms) { - hologram.delete(); - } - } + public static void onChunkLoad(Chunk chunk) { + // Load the holograms in that chunk. + for (NamedHologram hologram : pluginHolograms) { + if (hologram.isInChunk(chunk)) { + hologram.spawnEntities(); + } + } + } + + public static void onChunkUnload(Chunk chunk) { + // Hide the holograms in that chunk. + for (NamedHologram hologram : pluginHolograms) { + if (hologram.isInChunk(chunk)) { + hologram.despawnEntities(); + } + } + } + + public static void clearAll() { + List oldHolograms = new ArrayList<>(pluginHolograms); + pluginHolograms.clear(); + + for (NamedHologram hologram : oldHolograms) { + hologram.delete(); + } + } - public static int size() { - return pluginHolograms.size(); - } + public static int size() { + return pluginHolograms.size(); + } - public static NamedHologram get(int i) { - return pluginHolograms.get(i); - } + public static NamedHologram get(int i) { + return pluginHolograms.get(i); + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/object/PluginHologram.java b/plugin/src/main/java/me/filoghost/holographicdisplays/object/PluginHologram.java index 8a74bdcc..d6a8a347 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/object/PluginHologram.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/object/PluginHologram.java @@ -22,23 +22,23 @@ import org.bukkit.plugin.Plugin; * This class is only used by the plugin itself. Do not attempt to use it. */ public class PluginHologram extends CraftHologram { - - private Plugin plugin; + + private Plugin plugin; - public PluginHologram(Location source, Plugin plugin) { - super(source); - Validator.notNull(plugin, "plugin"); - this.plugin = plugin; - } - - public Plugin getOwner() { - return plugin; - } - - @Override - public void delete() { - super.delete(); - PluginHologramManager.removeHologram(this); - } - + public PluginHologram(Location source, Plugin plugin) { + super(source); + Validator.notNull(plugin, "plugin"); + this.plugin = plugin; + } + + public Plugin getOwner() { + return plugin; + } + + @Override + public void delete() { + super.delete(); + PluginHologramManager.removeHologram(this); + } + } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/object/PluginHologramManager.java b/plugin/src/main/java/me/filoghost/holographicdisplays/object/PluginHologramManager.java index d9ed8220..6c8a4458 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/object/PluginHologramManager.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/object/PluginHologramManager.java @@ -29,59 +29,59 @@ import java.util.Set; */ public class PluginHologramManager { - private static List pluginHolograms = new ArrayList<>(); - - public static void addHologram(PluginHologram hologram) { - pluginHolograms.add(hologram); - } - - public static void removeHologram(PluginHologram hologram) { - pluginHolograms.remove(hologram); - if (!hologram.isDeleted()) { - hologram.delete(); - } - } - - public static List getHolograms() { - return new ArrayList<>(pluginHolograms); - } - - public static Set getHolograms(Plugin plugin) { - Set ownedHolograms = new HashSet<>(); - - for (PluginHologram hologram : pluginHolograms) { - if (hologram.getOwner().equals(plugin)) { - ownedHolograms.add(hologram); - } - } - - return Collections.unmodifiableSet(ownedHolograms); - } + private static List pluginHolograms = new ArrayList<>(); + + public static void addHologram(PluginHologram hologram) { + pluginHolograms.add(hologram); + } + + public static void removeHologram(PluginHologram hologram) { + pluginHolograms.remove(hologram); + if (!hologram.isDeleted()) { + hologram.delete(); + } + } + + public static List getHolograms() { + return new ArrayList<>(pluginHolograms); + } + + public static Set getHolograms(Plugin plugin) { + Set ownedHolograms = new HashSet<>(); + + for (PluginHologram hologram : pluginHolograms) { + if (hologram.getOwner().equals(plugin)) { + ownedHolograms.add(hologram); + } + } + + return Collections.unmodifiableSet(ownedHolograms); + } - public static void onChunkLoad(Chunk chunk) { - // Load the holograms in that chunk. - for (PluginHologram hologram : pluginHolograms) { - if (hologram.isInChunk(chunk)) { - hologram.spawnEntities(); - } - } - } - - public static void onChunkUnload(Chunk chunk) { - // Hide the holograms in that chunk. - for (PluginHologram hologram : pluginHolograms) { - if (hologram.isInChunk(chunk)) { - hologram.despawnEntities(); - } - } - } - - public static void clearAll() { - List oldHolograms = new ArrayList<>(pluginHolograms); - pluginHolograms.clear(); - - for (PluginHologram hologram : oldHolograms) { - hologram.delete(); - } - } + public static void onChunkLoad(Chunk chunk) { + // Load the holograms in that chunk. + for (PluginHologram hologram : pluginHolograms) { + if (hologram.isInChunk(chunk)) { + hologram.spawnEntities(); + } + } + } + + public static void onChunkUnload(Chunk chunk) { + // Hide the holograms in that chunk. + for (PluginHologram hologram : pluginHolograms) { + if (hologram.isInChunk(chunk)) { + hologram.despawnEntities(); + } + } + } + + public static void clearAll() { + List oldHolograms = new ArrayList<>(pluginHolograms); + pluginHolograms.clear(); + + for (PluginHologram hologram : oldHolograms) { + hologram.delete(); + } + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/object/line/CraftHologramLine.java b/plugin/src/main/java/me/filoghost/holographicdisplays/object/line/CraftHologramLine.java index 83be1866..ec3f6fa8 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/object/line/CraftHologramLine.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/object/line/CraftHologramLine.java @@ -23,71 +23,71 @@ import org.bukkit.World; import java.util.Collection; public abstract class CraftHologramLine implements HologramLine { - - private final double height; - private final CraftHologram parent; - - // This field is necessary for teleport. - private boolean isSpawned; - - // Useful for saving to disk. - private String serializedConfigValue; - - protected CraftHologramLine(double height, CraftHologram parent) { - Validator.notNull(parent, "parent hologram"); - this.height = height; - this.parent = parent; - } - - public final double getHeight() { - return height; - } + + private final double height; + private final CraftHologram parent; + + // This field is necessary for teleport. + private boolean isSpawned; + + // Useful for saving to disk. + private String serializedConfigValue; + + protected CraftHologramLine(double height, CraftHologram parent) { + Validator.notNull(parent, "parent hologram"); + this.height = height; + this.parent = parent; + } + + public final double getHeight() { + return height; + } - @Override - public final CraftHologram getParent() { - return parent; - } - - public void removeLine() { - parent.removeLine(this); - } + @Override + public final CraftHologram getParent() { + return parent; + } + + public void removeLine() { + parent.removeLine(this); + } - public void spawn(World world, double x, double y, double z) { - Validator.notNull(world, "world"); - - // Remove the old entities when spawning the new ones. - despawn(); - isSpawned = true; - - // Do nothing, there are no entities in this class. - } - - public void despawn() { - isSpawned = false; - } - - public final boolean isSpawned() { - return isSpawned; - } - - public String getSerializedConfigValue() { - return serializedConfigValue; - } + public void spawn(World world, double x, double y, double z) { + Validator.notNull(world, "world"); + + // Remove the old entities when spawning the new ones. + despawn(); + isSpawned = true; + + // Do nothing, there are no entities in this class. + } + + public void despawn() { + isSpawned = false; + } + + public final boolean isSpawned() { + return isSpawned; + } + + public String getSerializedConfigValue() { + return serializedConfigValue; + } - public void setSerializedConfigValue(String serializedConfigValue) { - this.serializedConfigValue = serializedConfigValue; - } + public void setSerializedConfigValue(String serializedConfigValue) { + this.serializedConfigValue = serializedConfigValue; + } - public Collection getRelativePlaceholders() { - return null; - } - - public boolean hasRelativePlaceholders() { - return getRelativePlaceholders() != null && !getRelativePlaceholders().isEmpty(); - } - - public abstract int[] getEntitiesIDs(); - - public abstract void teleport(double x, double y, double z); + public Collection getRelativePlaceholders() { + return null; + } + + public boolean hasRelativePlaceholders() { + return getRelativePlaceholders() != null && !getRelativePlaceholders().isEmpty(); + } + + public abstract int[] getEntitiesIDs(); + + public abstract void teleport(double x, double y, double z); } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/object/line/CraftItemLine.java b/plugin/src/main/java/me/filoghost/holographicdisplays/object/line/CraftItemLine.java index 4af5f018..755a7c96 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/object/line/CraftItemLine.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/object/line/CraftItemLine.java @@ -31,126 +31,126 @@ import org.bukkit.inventory.ItemStack; public class CraftItemLine extends CraftTouchableLine implements ItemLine { - private ItemStack itemStack; - private PickupHandler pickupHandler; - - private NMSItem nmsItem; - private NMSArmorStand nmsVehicle; - - public CraftItemLine(CraftHologram parent, ItemStack itemStack) { - super(0.7, parent); - setItemStack(itemStack); - } - - @Override - public ItemStack getItemStack() { - return itemStack; - } + private ItemStack itemStack; + private PickupHandler pickupHandler; + + private NMSItem nmsItem; + private NMSArmorStand nmsVehicle; + + public CraftItemLine(CraftHologram parent, ItemStack itemStack) { + super(0.7, parent); + setItemStack(itemStack); + } + + @Override + public ItemStack getItemStack() { + return itemStack; + } - @Override - public void setItemStack(ItemStack itemStack) { - Validator.notNull(itemStack, "itemStack"); - Validator.isTrue(0 < itemStack.getAmount() && itemStack.getAmount() <= 64, "Item must have amount between 1 and 64"); - this.itemStack = itemStack; - - if (nmsItem != null) { - nmsItem.setItemStackNMS(itemStack); - } - } + @Override + public void setItemStack(ItemStack itemStack) { + Validator.notNull(itemStack, "itemStack"); + Validator.isTrue(0 < itemStack.getAmount() && itemStack.getAmount() <= 64, "Item must have amount between 1 and 64"); + this.itemStack = itemStack; + + if (nmsItem != null) { + nmsItem.setItemStackNMS(itemStack); + } + } - @Override - public PickupHandler getPickupHandler() { - return pickupHandler; - } + @Override + public PickupHandler getPickupHandler() { + return pickupHandler; + } - @Override - public void setPickupHandler(PickupHandler pickupHandler) { - this.pickupHandler = pickupHandler; - } - - @Override - public void setTouchHandler(TouchHandler touchHandler) { - if (nmsVehicle != null) { - Location loc = nmsVehicle.getBukkitEntityNMS().getLocation(); - super.setTouchHandler(touchHandler, loc.getWorld(), loc.getX(), loc.getY() - getItemOffset(), loc.getZ()); - } else { - super.setTouchHandler(touchHandler, null, 0, 0, 0); - } - } + @Override + public void setPickupHandler(PickupHandler pickupHandler) { + this.pickupHandler = pickupHandler; + } + + @Override + public void setTouchHandler(TouchHandler touchHandler) { + if (nmsVehicle != null) { + Location loc = nmsVehicle.getBukkitEntityNMS().getLocation(); + super.setTouchHandler(touchHandler, loc.getWorld(), loc.getX(), loc.getY() - getItemOffset(), loc.getZ()); + } else { + super.setTouchHandler(touchHandler, null, 0, 0, 0); + } + } - @Override - public void spawn(World world, double x, double y, double z) { - super.spawn(world, x, y, z); - - if (itemStack != null) { - double offset = getItemOffset(); - - nmsItem = HolographicDisplays.getNMSManager().spawnNMSItem(world, x, y + offset, z, this, itemStack, HolographicDisplays.getMainListener()); - nmsVehicle = HolographicDisplays.getNMSManager().spawnNMSArmorStand(world, x, y + offset, z, this, HolographicDisplays.hasProtocolLibHook()); + @Override + public void spawn(World world, double x, double y, double z) { + super.spawn(world, x, y, z); + + if (itemStack != null) { + double offset = getItemOffset(); + + nmsItem = HolographicDisplays.getNMSManager().spawnNMSItem(world, x, y + offset, z, this, itemStack, HolographicDisplays.getMainListener()); + nmsVehicle = HolographicDisplays.getNMSManager().spawnNMSArmorStand(world, x, y + offset, z, this, HolographicDisplays.hasProtocolLibHook()); - nmsItem.setPassengerOfNMS(nmsVehicle); - } - } + nmsItem.setPassengerOfNMS(nmsVehicle); + } + } - - @Override - public void despawn() { - super.despawn(); - - if (nmsVehicle != null) { - nmsVehicle.killEntityNMS(); - nmsVehicle = null; - } - - if (nmsItem != null) { - nmsItem.killEntityNMS(); - nmsItem = null; - } - } + + @Override + public void despawn() { + super.despawn(); + + if (nmsVehicle != null) { + nmsVehicle.killEntityNMS(); + nmsVehicle = null; + } + + if (nmsItem != null) { + nmsItem.killEntityNMS(); + nmsItem = null; + } + } - @Override - public void teleport(double x, double y, double z) { - super.teleport(x, y, z); - - double offset = getItemOffset(); - - if (nmsVehicle != null) { - nmsVehicle.setLocationNMS(x, y + offset, z, HolographicDisplays.hasProtocolLibHook()); - } - - if (nmsItem != null) { - nmsItem.setLocationNMS(x, y + offset, z); - } - } + @Override + public void teleport(double x, double y, double z) { + super.teleport(x, y, z); + + double offset = getItemOffset(); + + if (nmsVehicle != null) { + nmsVehicle.setLocationNMS(x, y + offset, z, HolographicDisplays.hasProtocolLibHook()); + } + + if (nmsItem != null) { + nmsItem.setLocationNMS(x, y + offset, z); + } + } - @Override - public int[] getEntitiesIDs() { - if (isSpawned()) { - if (touchSlime != null) { - return ArrayUtils.addAll(new int[] {nmsVehicle.getIdNMS(), nmsItem.getIdNMS()}, touchSlime.getEntitiesIDs()); - } else { - return new int[] {nmsVehicle.getIdNMS(), nmsItem.getIdNMS()}; - } - } else { - return new int[0]; - } - } + @Override + public int[] getEntitiesIDs() { + if (isSpawned()) { + if (touchSlime != null) { + return ArrayUtils.addAll(new int[] {nmsVehicle.getIdNMS(), nmsItem.getIdNMS()}, touchSlime.getEntitiesIDs()); + } else { + return new int[] {nmsVehicle.getIdNMS(), nmsItem.getIdNMS()}; + } + } else { + return new int[0]; + } + } - public NMSItem getNmsItem() { - return nmsItem; - } + public NMSItem getNmsItem() { + return nmsItem; + } - public NMSEntityBase getNmsVehicle() { - return nmsVehicle; - } - - private double getItemOffset() { - return Offsets.ARMOR_STAND_WITH_ITEM; - } + public NMSEntityBase getNmsVehicle() { + return nmsVehicle; + } + + private double getItemOffset() { + return Offsets.ARMOR_STAND_WITH_ITEM; + } - @Override - public String toString() { - return "CraftItemLine [itemStack=" + itemStack + ", pickupHandler=" + pickupHandler + "]"; - } - + @Override + public String toString() { + return "CraftItemLine [itemStack=" + itemStack + ", pickupHandler=" + pickupHandler + "]"; + } + } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/object/line/CraftTextLine.java b/plugin/src/main/java/me/filoghost/holographicdisplays/object/line/CraftTextLine.java index a3f1872c..159165c9 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/object/line/CraftTextLine.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/object/line/CraftTextLine.java @@ -33,129 +33,129 @@ import java.util.List; public class CraftTextLine extends CraftTouchableLine implements TextLine { - private String text; - private List relativePlaceholders; - private NMSArmorStand nmsNameable; - - - public CraftTextLine(CraftHologram parent, String text) { - super(0.23, parent); - setText(text); - } - - - @Override - public String getText() { - return text; - } - - @Override - public void setText(String text) { - this.text = text; - - if (nmsNameable != null) { - if (text != null && !text.isEmpty()) { - nmsNameable.setCustomNameNMS(text); - if (getParent().isAllowPlaceholders()) { - PlaceholdersManager.trackIfNecessary(this); - } - } else { - nmsNameable.setCustomNameNMS(""); // It will not appear - if (getParent().isAllowPlaceholders()) { - PlaceholdersManager.untrack(this); - } - } - } - - if (text != null) { - for (RelativePlaceholder relativePlaceholder : RelativePlaceholder.getRegistry()) { - if (text.contains(relativePlaceholder.getTextPlaceholder())) { - if (relativePlaceholders == null) { - relativePlaceholders = new ArrayList<>(); - } - relativePlaceholders.add(relativePlaceholder); - } - } - } - - // Deallocate the list if unused - if (relativePlaceholders != null && relativePlaceholders.isEmpty()) { - relativePlaceholders = null; - } - } - - @Override - public void setTouchHandler(TouchHandler touchHandler) { - if (nmsNameable != null) { - Location loc = nmsNameable.getBukkitEntityNMS().getLocation(); - super.setTouchHandler(touchHandler, loc.getWorld(), loc.getX(), loc.getY() - getTextOffset(), loc.getZ()); - } else { - super.setTouchHandler(touchHandler, null, 0, 0, 0); - } - } + private String text; + private List relativePlaceholders; + private NMSArmorStand nmsNameable; + + + public CraftTextLine(CraftHologram parent, String text) { + super(0.23, parent); + setText(text); + } + + + @Override + public String getText() { + return text; + } + + @Override + public void setText(String text) { + this.text = text; + + if (nmsNameable != null) { + if (text != null && !text.isEmpty()) { + nmsNameable.setCustomNameNMS(text); + if (getParent().isAllowPlaceholders()) { + PlaceholdersManager.trackIfNecessary(this); + } + } else { + nmsNameable.setCustomNameNMS(""); // It will not appear + if (getParent().isAllowPlaceholders()) { + PlaceholdersManager.untrack(this); + } + } + } + + if (text != null) { + for (RelativePlaceholder relativePlaceholder : RelativePlaceholder.getRegistry()) { + if (text.contains(relativePlaceholder.getTextPlaceholder())) { + if (relativePlaceholders == null) { + relativePlaceholders = new ArrayList<>(); + } + relativePlaceholders.add(relativePlaceholder); + } + } + } + + // Deallocate the list if unused + if (relativePlaceholders != null && relativePlaceholders.isEmpty()) { + relativePlaceholders = null; + } + } + + @Override + public void setTouchHandler(TouchHandler touchHandler) { + if (nmsNameable != null) { + Location loc = nmsNameable.getBukkitEntityNMS().getLocation(); + super.setTouchHandler(touchHandler, loc.getWorld(), loc.getX(), loc.getY() - getTextOffset(), loc.getZ()); + } else { + super.setTouchHandler(touchHandler, null, 0, 0, 0); + } + } - @Override - public void spawn(World world, double x, double y, double z) { - super.spawn(world, x, y, z); - - nmsNameable = HolographicDisplays.getNMSManager().spawnNMSArmorStand(world, x, y + getTextOffset(), z, this, HolographicDisplays.hasProtocolLibHook()); + @Override + public void spawn(World world, double x, double y, double z) { + super.spawn(world, x, y, z); + + nmsNameable = HolographicDisplays.getNMSManager().spawnNMSArmorStand(world, x, y + getTextOffset(), z, this, HolographicDisplays.hasProtocolLibHook()); - if (text != null && !text.isEmpty()) { - nmsNameable.setCustomNameNMS(text); - } - } + if (text != null && !text.isEmpty()) { + nmsNameable.setCustomNameNMS(text); + } + } - - @Override - public void despawn() { - super.despawn(); - - if (nmsNameable != null) { - nmsNameable.killEntityNMS(); - nmsNameable = null; - } - } - - - @Override - public Collection getRelativePlaceholders() { - return relativePlaceholders; - } + + @Override + public void despawn() { + super.despawn(); + + if (nmsNameable != null) { + nmsNameable.killEntityNMS(); + nmsNameable = null; + } + } + + + @Override + public Collection getRelativePlaceholders() { + return relativePlaceholders; + } - - @Override - public void teleport(double x, double y, double z) { - super.teleport(x, y, z); - - if (nmsNameable != null) { - nmsNameable.setLocationNMS(x, y + getTextOffset(), z, HolographicDisplays.hasProtocolLibHook()); - } - } - - @Override - public int[] getEntitiesIDs() { - if (isSpawned()) { - if (touchSlime != null) { - return ArrayUtils.add(touchSlime.getEntitiesIDs(), nmsNameable.getIdNMS()); - } else { - return new int[] {nmsNameable.getIdNMS()}; - } - } else { - return new int[0]; - } - } + + @Override + public void teleport(double x, double y, double z) { + super.teleport(x, y, z); + + if (nmsNameable != null) { + nmsNameable.setLocationNMS(x, y + getTextOffset(), z, HolographicDisplays.hasProtocolLibHook()); + } + } + + @Override + public int[] getEntitiesIDs() { + if (isSpawned()) { + if (touchSlime != null) { + return ArrayUtils.add(touchSlime.getEntitiesIDs(), nmsNameable.getIdNMS()); + } else { + return new int[] {nmsNameable.getIdNMS()}; + } + } else { + return new int[0]; + } + } - public NMSNameable getNmsNameable() { - return nmsNameable; - } + public NMSNameable getNmsNameable() { + return nmsNameable; + } - private double getTextOffset() { - return Offsets.ARMOR_STAND_ALONE; - } + private double getTextOffset() { + return Offsets.ARMOR_STAND_ALONE; + } - @Override - public String toString() { - return "CraftTextLine [text=" + text + "]"; - } - + @Override + public String toString() { + return "CraftTextLine [text=" + text + "]"; + } + } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/object/line/CraftTouchSlimeLine.java b/plugin/src/main/java/me/filoghost/holographicdisplays/object/line/CraftTouchSlimeLine.java index 2ffc41fa..fb975d06 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/object/line/CraftTouchSlimeLine.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/object/line/CraftTouchSlimeLine.java @@ -26,91 +26,91 @@ import org.bukkit.World; * A touch slime that can be applied to a line. */ public class CraftTouchSlimeLine extends CraftHologramLine { - - // The touchable piece associated with this piece - private CraftTouchableLine touchablePiece; - - private NMSSlime nmsSlime; - private NMSArmorStand nmsVehicle; + + // The touchable piece associated with this piece + private CraftTouchableLine touchablePiece; + + private NMSSlime nmsSlime; + private NMSArmorStand nmsVehicle; - - protected CraftTouchSlimeLine(CraftHologram parent, CraftTouchableLine touchablePiece) { - super(0.5, parent); - this.touchablePiece = touchablePiece; - } + + protected CraftTouchSlimeLine(CraftHologram parent, CraftTouchableLine touchablePiece) { + super(0.5, parent); + this.touchablePiece = touchablePiece; + } - public CraftTouchableLine getTouchablePiece() { - return touchablePiece; - } + public CraftTouchableLine getTouchablePiece() { + return touchablePiece; + } - @Override - public void spawn(World world, double x, double y, double z) { - super.spawn(world, x, y, z); - - double offset = getSlimeOffset(); - - nmsSlime = HolographicDisplays.getNMSManager().spawnNMSSlime(world, x, y + offset, z, this); - nmsVehicle = HolographicDisplays.getNMSManager().spawnNMSArmorStand(world, x, y + offset, z, this, HolographicDisplays.hasProtocolLibHook()); - - nmsSlime.setPassengerOfNMS(nmsVehicle); - } + @Override + public void spawn(World world, double x, double y, double z) { + super.spawn(world, x, y, z); + + double offset = getSlimeOffset(); + + nmsSlime = HolographicDisplays.getNMSManager().spawnNMSSlime(world, x, y + offset, z, this); + nmsVehicle = HolographicDisplays.getNMSManager().spawnNMSArmorStand(world, x, y + offset, z, this, HolographicDisplays.hasProtocolLibHook()); + + nmsSlime.setPassengerOfNMS(nmsVehicle); + } - - @Override - public void despawn() { - super.despawn(); - - if (nmsSlime != null) { - nmsSlime.killEntityNMS(); - nmsSlime = null; - } - - if (nmsVehicle != null) { - nmsVehicle.killEntityNMS(); - nmsVehicle = null; - } - } + + @Override + public void despawn() { + super.despawn(); + + if (nmsSlime != null) { + nmsSlime.killEntityNMS(); + nmsSlime = null; + } + + if (nmsVehicle != null) { + nmsVehicle.killEntityNMS(); + nmsVehicle = null; + } + } - - @Override - public void teleport(double x, double y, double z) { - - double offset = getSlimeOffset(); - - if (nmsVehicle != null) { - nmsVehicle.setLocationNMS(x, y + offset, z, HolographicDisplays.hasProtocolLibHook()); - } - - if (nmsSlime != null) { - nmsSlime.setLocationNMS(x, y + offset, z); - } - } + + @Override + public void teleport(double x, double y, double z) { + + double offset = getSlimeOffset(); + + if (nmsVehicle != null) { + nmsVehicle.setLocationNMS(x, y + offset, z, HolographicDisplays.hasProtocolLibHook()); + } + + if (nmsSlime != null) { + nmsSlime.setLocationNMS(x, y + offset, z); + } + } - @Override - public int[] getEntitiesIDs() { - if (isSpawned()) { - return new int[] {nmsVehicle.getIdNMS(), nmsSlime.getIdNMS()}; - } else { - return new int[0]; - } - } + @Override + public int[] getEntitiesIDs() { + if (isSpawned()) { + return new int[] {nmsVehicle.getIdNMS(), nmsSlime.getIdNMS()}; + } else { + return new int[0]; + } + } - public NMSSlime getNmsSlime() { - return nmsSlime; - } + public NMSSlime getNmsSlime() { + return nmsSlime; + } - public NMSEntityBase getNmsVehicle() { - return nmsVehicle; - } - - private double getSlimeOffset() { - return Offsets.ARMOR_STAND_WITH_SLIME; - } + public NMSEntityBase getNmsVehicle() { + return nmsVehicle; + } + + private double getSlimeOffset() { + return Offsets.ARMOR_STAND_WITH_SLIME; + } - @Override - public String toString() { - return "CraftTouchSlimeLine [touchablePiece=" + touchablePiece + "]"; - } - + @Override + public String toString() { + return "CraftTouchSlimeLine [touchablePiece=" + touchablePiece + "]"; + } + } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/object/line/CraftTouchableLine.java b/plugin/src/main/java/me/filoghost/holographicdisplays/object/line/CraftTouchableLine.java index fb16ca1c..50a44aba 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/object/line/CraftTouchableLine.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/object/line/CraftTouchableLine.java @@ -24,68 +24,68 @@ import org.bukkit.World; */ public abstract class CraftTouchableLine extends CraftHologramLine { - protected CraftTouchSlimeLine touchSlime; - private TouchHandler touchHandler; + protected CraftTouchSlimeLine touchSlime; + private TouchHandler touchHandler; - - protected CraftTouchableLine(double height, CraftHologram parent) { - super(height, parent); - } - - - protected void setTouchHandler(TouchHandler touchHandler, World world, double x, double y, double z) { - this.touchHandler = touchHandler; - - if (touchHandler != null && touchSlime == null && world != null) { - // If the touch handler was null before and no entity has been spawned, spawn it now. - touchSlime = new CraftTouchSlimeLine(getParent(), this); - touchSlime.spawn(world, x, y + (getHeight() / 2.0 - touchSlime.getHeight() / 2.0), z); - - } else if (touchHandler == null && touchSlime != null) { - // Opposite case, the touch handler was not null and an entity was spawned, but now it's useless. - touchSlime.despawn(); - touchSlime = null; - } - } + + protected CraftTouchableLine(double height, CraftHologram parent) { + super(height, parent); + } + + + protected void setTouchHandler(TouchHandler touchHandler, World world, double x, double y, double z) { + this.touchHandler = touchHandler; + + if (touchHandler != null && touchSlime == null && world != null) { + // If the touch handler was null before and no entity has been spawned, spawn it now. + touchSlime = new CraftTouchSlimeLine(getParent(), this); + touchSlime.spawn(world, x, y + (getHeight() / 2.0 - touchSlime.getHeight() / 2.0), z); + + } else if (touchHandler == null && touchSlime != null) { + // Opposite case, the touch handler was not null and an entity was spawned, but now it's useless. + touchSlime.despawn(); + touchSlime = null; + } + } - - public TouchHandler getTouchHandler() { - return this.touchHandler; - } + + public TouchHandler getTouchHandler() { + return this.touchHandler; + } - @Override - public void spawn(World world, double x, double y, double z) { - super.spawn(world, x, y, z); - - if (touchHandler != null) { - touchSlime = new CraftTouchSlimeLine(getParent(), this); - touchSlime.spawn(world, x, y + (getHeight() / 2.0 - touchSlime.getHeight() / 2.0), z); - } - } + @Override + public void spawn(World world, double x, double y, double z) { + super.spawn(world, x, y, z); + + if (touchHandler != null) { + touchSlime = new CraftTouchSlimeLine(getParent(), this); + touchSlime.spawn(world, x, y + (getHeight() / 2.0 - touchSlime.getHeight() / 2.0), z); + } + } - @Override - public void despawn() { - super.despawn(); - - if (touchSlime != null) { - touchSlime.despawn(); - touchSlime = null; - } - } - - - @Override - public void teleport(double x, double y, double z) { - if (touchSlime != null) { - touchSlime.teleport(x, y + (getHeight() / 2.0 - touchSlime.getHeight() / 2.0), z); - } - } + @Override + public void despawn() { + super.despawn(); + + if (touchSlime != null) { + touchSlime.despawn(); + touchSlime = null; + } + } + + + @Override + public void teleport(double x, double y, double z) { + if (touchSlime != null) { + touchSlime.teleport(x, y + (getHeight() / 2.0 - touchSlime.getHeight() / 2.0), z); + } + } - public CraftTouchSlimeLine getTouchSlime() { - return touchSlime; - } - + public CraftTouchSlimeLine getTouchSlime() { + return touchSlime; + } + } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/AnimationsRegister.java b/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/AnimationsRegister.java index 0c24d492..80fbb8d2 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/AnimationsRegister.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/AnimationsRegister.java @@ -27,75 +27,75 @@ import java.util.Map; import java.util.logging.Level; public class AnimationsRegister { - - // - private final static Map animations = new HashMap<>(); - - public static void loadAnimations(Plugin plugin) { - animations.clear(); - - File animationFolder = new File(plugin.getDataFolder(), "animations"); - if (!animationFolder.isDirectory()) { - animationFolder.mkdirs(); - plugin.saveResource("animations/example.txt", false); - return; - } - - for (File file : animationFolder.listFiles()) { - - try { - List lines = FileUtils.readLines(file); - if (lines.size() == 0) { - continue; - } - - double speed = 0.5; - boolean validSpeedFound = false; - - String firstLine = lines.get(0).trim(); - if (firstLine.toLowerCase().startsWith("speed:")) { - - // Do not consider it. - lines.remove(0); - - firstLine = firstLine.substring("speed:".length()).trim(); - - try { - speed = Double.parseDouble(firstLine); - validSpeedFound = true; - } catch (NumberFormatException e) { } - } - - if (!validSpeedFound) { - ConsoleLogger.log(Level.WARNING, "Could not find a valid 'speed: ' in the first line of the file '" + file.getName() + "'. Default speed of 0.5 seconds will be used."); - } - - if (lines.isEmpty()) { - lines.add("[No lines: " + file.getName() + "]"); - ConsoleLogger.log(Level.WARNING, "Could not find any line in '" + file.getName() + "' (excluding the speed). You should add at least one more line."); - } - - // Replace placeholders. - for (int i = 0; i < lines.size(); i++) { - lines.set(i, StringConverter.toReadableFormat(lines.get(i))); - } - - animations.put(file.getName(), new Placeholder(HolographicDisplays.getInstance(), file.getName(), speed, new CyclicPlaceholderReplacer(lines.toArray(new String[lines.size()])))); - ConsoleLogger.logDebug(Level.INFO, "Successfully loaded animation '" + file.getName() + "', speed = " + speed + "."); - - } catch (Exception e) { - ConsoleLogger.log(Level.SEVERE, "Couldn't load the file '" + file.getName() + "'!", e); - } - } - } + + // + private final static Map animations = new HashMap<>(); + + public static void loadAnimations(Plugin plugin) { + animations.clear(); + + File animationFolder = new File(plugin.getDataFolder(), "animations"); + if (!animationFolder.isDirectory()) { + animationFolder.mkdirs(); + plugin.saveResource("animations/example.txt", false); + return; + } + + for (File file : animationFolder.listFiles()) { + + try { + List lines = FileUtils.readLines(file); + if (lines.size() == 0) { + continue; + } + + double speed = 0.5; + boolean validSpeedFound = false; + + String firstLine = lines.get(0).trim(); + if (firstLine.toLowerCase().startsWith("speed:")) { + + // Do not consider it. + lines.remove(0); + + firstLine = firstLine.substring("speed:".length()).trim(); + + try { + speed = Double.parseDouble(firstLine); + validSpeedFound = true; + } catch (NumberFormatException e) { } + } + + if (!validSpeedFound) { + ConsoleLogger.log(Level.WARNING, "Could not find a valid 'speed: ' in the first line of the file '" + file.getName() + "'. Default speed of 0.5 seconds will be used."); + } + + if (lines.isEmpty()) { + lines.add("[No lines: " + file.getName() + "]"); + ConsoleLogger.log(Level.WARNING, "Could not find any line in '" + file.getName() + "' (excluding the speed). You should add at least one more line."); + } + + // Replace placeholders. + for (int i = 0; i < lines.size(); i++) { + lines.set(i, StringConverter.toReadableFormat(lines.get(i))); + } + + animations.put(file.getName(), new Placeholder(HolographicDisplays.getInstance(), file.getName(), speed, new CyclicPlaceholderReplacer(lines.toArray(new String[lines.size()])))); + ConsoleLogger.logDebug(Level.INFO, "Successfully loaded animation '" + file.getName() + "', speed = " + speed + "."); + + } catch (Exception e) { + ConsoleLogger.log(Level.SEVERE, "Couldn't load the file '" + file.getName() + "'!", e); + } + } + } - - public static Map getAnimations() { - return animations; - } + + public static Map getAnimations() { + return animations; + } - public static Placeholder getAnimation(String name) { - return animations.get(name); - } - + public static Placeholder getAnimation(String name) { + return animations.get(name); + } + } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/CyclicPlaceholderReplacer.java b/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/CyclicPlaceholderReplacer.java index db09bcf7..d6134519 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/CyclicPlaceholderReplacer.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/CyclicPlaceholderReplacer.java @@ -18,24 +18,24 @@ import me.filoghost.holographicdisplays.api.placeholder.PlaceholderReplacer; public class CyclicPlaceholderReplacer implements PlaceholderReplacer { - String[] frames; - private int index; - - public CyclicPlaceholderReplacer(String[] frames) { - this.frames = frames; - index = 0; - } + String[] frames; + private int index; + + public CyclicPlaceholderReplacer(String[] frames) { + this.frames = frames; + index = 0; + } - @Override - public String update() { - String result = frames[index]; - - index++; - if (index >= frames.length) { - index = 0; - } - - return result; - } + @Override + public String update() { + String result = frames[index]; + + index++; + if (index >= frames.length) { + index = 0; + } + + return result; + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/DynamicLineData.java b/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/DynamicLineData.java index ea97b70d..5560d012 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/DynamicLineData.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/DynamicLineData.java @@ -24,65 +24,65 @@ import java.util.Map; import java.util.Set; public class DynamicLineData { - - private final NMSNameable entity; - private final String originalName; - - private Set placeholders; - private final Map animations; - private final Map replacers; - - public DynamicLineData(NMSNameable entity, String originalName) { - Validator.notNull(entity, "entity"); - - this.entity = entity; - this.originalName = originalName; - placeholders = new HashSet<>(); - animations = new HashMap<>(); - replacers = new HashMap<>(); - } + + private final NMSNameable entity; + private final String originalName; + + private Set placeholders; + private final Map animations; + private final Map replacers; + + public DynamicLineData(NMSNameable entity, String originalName) { + Validator.notNull(entity, "entity"); + + this.entity = entity; + this.originalName = originalName; + placeholders = new HashSet<>(); + animations = new HashMap<>(); + replacers = new HashMap<>(); + } - public NMSNameable getEntity() { - return entity; - } + public NMSNameable getEntity() { + return entity; + } - public String getOriginalName() { - return originalName; - } - - public void setPlaceholders(Set placeholders) { - this.placeholders = placeholders; - } + public String getOriginalName() { + return originalName; + } + + public void setPlaceholders(Set placeholders) { + this.placeholders = placeholders; + } - public Set getPlaceholders() { - return placeholders; - } + public Set getPlaceholders() { + return placeholders; + } - public Map getReplacers() { - return replacers; - } - - public Map getAnimations() { - return animations; - } + public Map getReplacers() { + return replacers; + } + + public Map getAnimations() { + return animations; + } - @Override - public int hashCode() { - return entity.hashCode(); - } + @Override + public int hashCode() { + return entity.hashCode(); + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - DynamicLineData other = (DynamicLineData) obj; - return this.entity == other.entity; - } - - - + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + DynamicLineData other = (DynamicLineData) obj; + return this.entity == other.entity; + } + + + } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/Placeholder.java b/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/Placeholder.java index 104cdceb..abb70420 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/Placeholder.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/Placeholder.java @@ -18,84 +18,84 @@ import me.filoghost.holographicdisplays.api.placeholder.PlaceholderReplacer; import org.bukkit.plugin.Plugin; public class Placeholder { - - // The plugin that owns this placeholder. - private final Plugin owner; - - // The placeholder itself, something like {onlinePlayers}. Case sensitive! - private final String textPlaceholder; - - // How many tenths of second between each refresh. - private int tenthsToRefresh; - - // This is the current replacement for this placeholder. - private String currentReplacement; - - private PlaceholderReplacer replacer; - - public Placeholder(Plugin owner, String textPlaceholder, double refreshRate, PlaceholderReplacer replacer) { - this.owner = owner; - this.textPlaceholder = textPlaceholder; - this.tenthsToRefresh = refreshRate <= 0.1 ? 1 : (int) (refreshRate * 10.0); - this.replacer = replacer; - this.currentReplacement = ""; - } - - public Plugin getOwner() { - return owner; - } - - public int getTenthsToRefresh() { - return tenthsToRefresh; - } - - public void setTenthsToRefresh(int tenthsToRefresh) { - this.tenthsToRefresh = tenthsToRefresh; - } + + // The plugin that owns this placeholder. + private final Plugin owner; + + // The placeholder itself, something like {onlinePlayers}. Case sensitive! + private final String textPlaceholder; + + // How many tenths of second between each refresh. + private int tenthsToRefresh; + + // This is the current replacement for this placeholder. + private String currentReplacement; + + private PlaceholderReplacer replacer; + + public Placeholder(Plugin owner, String textPlaceholder, double refreshRate, PlaceholderReplacer replacer) { + this.owner = owner; + this.textPlaceholder = textPlaceholder; + this.tenthsToRefresh = refreshRate <= 0.1 ? 1 : (int) (refreshRate * 10.0); + this.replacer = replacer; + this.currentReplacement = ""; + } + + public Plugin getOwner() { + return owner; + } + + public int getTenthsToRefresh() { + return tenthsToRefresh; + } + + public void setTenthsToRefresh(int tenthsToRefresh) { + this.tenthsToRefresh = tenthsToRefresh; + } - public String getTextPlaceholder() { - return textPlaceholder; - } - - public String getCurrentReplacement() { - return currentReplacement; - } - - public void setCurrentReplacement(String replacement) { - this.currentReplacement = replacement != null ? replacement : "null"; - } - - public PlaceholderReplacer getReplacer() { - return replacer; - } - - public void setReplacer(PlaceholderReplacer replacer) { - this.replacer = replacer; - } + public String getTextPlaceholder() { + return textPlaceholder; + } + + public String getCurrentReplacement() { + return currentReplacement; + } + + public void setCurrentReplacement(String replacement) { + this.currentReplacement = replacement != null ? replacement : "null"; + } + + public PlaceholderReplacer getReplacer() { + return replacer; + } + + public void setReplacer(PlaceholderReplacer replacer) { + this.replacer = replacer; + } - public void update() { - setCurrentReplacement(replacer.update()); - } - - - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - - if (obj instanceof Placeholder) { - return ((Placeholder) obj).textPlaceholder.equals(this.textPlaceholder); - } - - return false; - } - - - @Override - public int hashCode() { - return textPlaceholder.hashCode(); - } - - + public void update() { + setCurrentReplacement(replacer.update()); + } + + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + + if (obj instanceof Placeholder) { + return ((Placeholder) obj).textPlaceholder.equals(this.textPlaceholder); + } + + return false; + } + + + @Override + public int hashCode() { + return textPlaceholder.hashCode(); + } + + } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/PlaceholdersManager.java b/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/PlaceholdersManager.java index f6e8e3dd..3ab16dbf 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/PlaceholdersManager.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/PlaceholdersManager.java @@ -35,340 +35,340 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; public class PlaceholdersManager { - - private static long elapsedTenthsOfSecond; - protected static Set linesToUpdate = new HashSet<>(); - - private static final Pattern BUNGEE_ONLINE_PATTERN = makePlaceholderWithArgsPattern("online"); - private static final Pattern BUNGEE_MAX_PATTERN = makePlaceholderWithArgsPattern("max_players"); - private static final Pattern BUNGEE_MOTD_PATTERN = makePlaceholderWithArgsPattern("motd"); - private static final Pattern BUNGEE_MOTD_2_PATTERN = makePlaceholderWithArgsPattern("motd2"); - private static final Pattern BUNGEE_STATUS_PATTERN = makePlaceholderWithArgsPattern("status"); - private static final Pattern ANIMATION_PATTERN = makePlaceholderWithArgsPattern("animation"); - private static final Pattern WORLD_PATTERN = makePlaceholderWithArgsPattern("world"); - - private static Pattern makePlaceholderWithArgsPattern(String prefix) { - return Pattern.compile("(\\{" + Pattern.quote(prefix) + ":)(.+?)(\\})"); - } - - private static String extractArgumentFromPlaceholder(Matcher matcher) { - return matcher.group(2).trim(); - } - - - public static void load(Plugin plugin) { - Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> { - - for (Placeholder placeholder : PlaceholdersRegister.getPlaceholders()) { - if (elapsedTenthsOfSecond % placeholder.getTenthsToRefresh() == 0) { - try { - placeholder.update(); - } catch (Throwable t) { - ConsoleLogger.log(Level.WARNING, "The placeholder " + placeholder.getTextPlaceholder() + " registered by the plugin " + placeholder.getOwner().getName() + " generated an exception while updating. Please contact the author of " + placeholder.getOwner().getName(), t); - } - } - } - - for (Placeholder placeholder : AnimationsRegister.getAnimations().values()) { - if (elapsedTenthsOfSecond % placeholder.getTenthsToRefresh() == 0) { - placeholder.update(); - } - } - - Iterator iter = linesToUpdate.iterator(); - DynamicLineData currentLineData; - - while (iter.hasNext()) { - currentLineData = iter.next(); - - if (currentLineData.getEntity().isDeadNMS()) { - iter.remove(); - } else { - updatePlaceholders(currentLineData); - } - } - - elapsedTenthsOfSecond++; - - }, 2L, 2L); - } - - - public static void untrackAll() { - linesToUpdate.clear(); - } - - public static void untrack(CraftTextLine line) { - if (line == null || !line.isSpawned()) { - return; - } - - Iterator iter = linesToUpdate.iterator(); - while (iter.hasNext()) { - DynamicLineData data = iter.next(); - if (data.getEntity() == line.getNmsNameable()) { - iter.remove(); - data.getEntity().setCustomNameNMS(data.getOriginalName()); - } - } - } - - public static void trackIfNecessary(CraftTextLine line) { - NMSNameable nameableEntity = line.getNmsNameable(); - if (nameableEntity == null) { - return; - } - - String name = line.getText(); - if (name == null || name.isEmpty()) { - return; - } - - boolean updateName = false; + + private static long elapsedTenthsOfSecond; + protected static Set linesToUpdate = new HashSet<>(); + + private static final Pattern BUNGEE_ONLINE_PATTERN = makePlaceholderWithArgsPattern("online"); + private static final Pattern BUNGEE_MAX_PATTERN = makePlaceholderWithArgsPattern("max_players"); + private static final Pattern BUNGEE_MOTD_PATTERN = makePlaceholderWithArgsPattern("motd"); + private static final Pattern BUNGEE_MOTD_2_PATTERN = makePlaceholderWithArgsPattern("motd2"); + private static final Pattern BUNGEE_STATUS_PATTERN = makePlaceholderWithArgsPattern("status"); + private static final Pattern ANIMATION_PATTERN = makePlaceholderWithArgsPattern("animation"); + private static final Pattern WORLD_PATTERN = makePlaceholderWithArgsPattern("world"); + + private static Pattern makePlaceholderWithArgsPattern(String prefix) { + return Pattern.compile("(\\{" + Pattern.quote(prefix) + ":)(.+?)(\\})"); + } + + private static String extractArgumentFromPlaceholder(Matcher matcher) { + return matcher.group(2).trim(); + } + + + public static void load(Plugin plugin) { + Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> { + + for (Placeholder placeholder : PlaceholdersRegister.getPlaceholders()) { + if (elapsedTenthsOfSecond % placeholder.getTenthsToRefresh() == 0) { + try { + placeholder.update(); + } catch (Throwable t) { + ConsoleLogger.log(Level.WARNING, "The placeholder " + placeholder.getTextPlaceholder() + " registered by the plugin " + placeholder.getOwner().getName() + " generated an exception while updating. Please contact the author of " + placeholder.getOwner().getName(), t); + } + } + } + + for (Placeholder placeholder : AnimationsRegister.getAnimations().values()) { + if (elapsedTenthsOfSecond % placeholder.getTenthsToRefresh() == 0) { + placeholder.update(); + } + } + + Iterator iter = linesToUpdate.iterator(); + DynamicLineData currentLineData; + + while (iter.hasNext()) { + currentLineData = iter.next(); + + if (currentLineData.getEntity().isDeadNMS()) { + iter.remove(); + } else { + updatePlaceholders(currentLineData); + } + } + + elapsedTenthsOfSecond++; + + }, 2L, 2L); + } + + + public static void untrackAll() { + linesToUpdate.clear(); + } + + public static void untrack(CraftTextLine line) { + if (line == null || !line.isSpawned()) { + return; + } + + Iterator iter = linesToUpdate.iterator(); + while (iter.hasNext()) { + DynamicLineData data = iter.next(); + if (data.getEntity() == line.getNmsNameable()) { + iter.remove(); + data.getEntity().setCustomNameNMS(data.getOriginalName()); + } + } + } + + public static void trackIfNecessary(CraftTextLine line) { + NMSNameable nameableEntity = line.getNmsNameable(); + if (nameableEntity == null) { + return; + } + + String name = line.getText(); + if (name == null || name.isEmpty()) { + return; + } + + boolean updateName = false; - // Lazy initialization. - Set normalPlaceholders = null; - Map bungeeReplacers = null; - Map worldsOnlinePlayersReplacers = null; - Map animationsPlaceholders = null; - - Matcher matcher; - - for (Placeholder placeholder : PlaceholdersRegister.getPlaceholders()) { - - if (name.contains(placeholder.getTextPlaceholder())) { - - if (normalPlaceholders == null) { - normalPlaceholders = new HashSet<>(); - } - - normalPlaceholders.add(placeholder); - } - } - - - // Players in a world count pattern. - matcher = WORLD_PATTERN.matcher(name); - while (matcher.find()) { - - if (worldsOnlinePlayersReplacers == null) { - worldsOnlinePlayersReplacers = new HashMap<>(); - } - - final String worldsNames = extractArgumentFromPlaceholder(matcher); - - if (worldsNames.contains(",")) { - - String[] split = worldsNames.split(","); - for (int i = 0; i < split.length; i++) { - split[i] = split[i].trim(); - } - - final String[] worldsToTrack = split; - - // Add it to tracked worlds. - worldsOnlinePlayersReplacers.put(matcher.group(), () -> { - return WorldPlayerCounterTask.getCount(worldsToTrack); - }); - } else { - // Normal, single tracked world. - worldsOnlinePlayersReplacers.put(matcher.group(), () -> { - return WorldPlayerCounterTask.getCount(worldsNames); - }); - } - } - - // BungeeCord online pattern. - matcher = BUNGEE_ONLINE_PATTERN.matcher(name); - while (matcher.find()) { - - if (bungeeReplacers == null) { - bungeeReplacers = new HashMap<>(); - } - - final String serverName = extractArgumentFromPlaceholder(matcher); - BungeeServerTracker.track(serverName); // Track this server. - - if (serverName.contains(",")) { - - String[] split = serverName.split(","); - for (int i = 0; i < split.length; i++) { - split[i] = split[i].trim(); - } - - final String[] serversToTrack = split; - - // Add it to tracked servers. - bungeeReplacers.put(matcher.group(), () -> { - int count = 0; - for (String serverToTrack : serversToTrack) { - count += BungeeServerTracker.getPlayersOnline(serverToTrack); - } - return String.valueOf(count); - }); - } else { - // Normal, single tracked server. - bungeeReplacers.put(matcher.group(), () -> { - return String.valueOf(BungeeServerTracker.getPlayersOnline(serverName)); - }); - } - } - - // BungeeCord max players pattern. - matcher = BUNGEE_MAX_PATTERN.matcher(name); - while (matcher.find()) { - - if (bungeeReplacers == null) { - bungeeReplacers = new HashMap<>(); - } - - final String serverName = extractArgumentFromPlaceholder(matcher); - BungeeServerTracker.track(serverName); // Track this server. - - // Add it to tracked servers. - bungeeReplacers.put(matcher.group(), () -> { - return BungeeServerTracker.getMaxPlayers(serverName); - }); - } - - // BungeeCord motd pattern. - matcher = BUNGEE_MOTD_PATTERN.matcher(name); - while (matcher.find()) { - - if (bungeeReplacers == null) { - bungeeReplacers = new HashMap<>(); - } - - final String serverName = extractArgumentFromPlaceholder(matcher); - BungeeServerTracker.track(serverName); // Track this server. - - // Add it to tracked servers. - bungeeReplacers.put(matcher.group(), () -> { - return BungeeServerTracker.getMotd1(serverName); - }); - } - - // BungeeCord motd (line 2) pattern. - matcher = BUNGEE_MOTD_2_PATTERN.matcher(name); - while (matcher.find()) { - - if (bungeeReplacers == null) { - bungeeReplacers = new HashMap<>(); - } - - final String serverName = extractArgumentFromPlaceholder(matcher); - BungeeServerTracker.track(serverName); // Track this server. - - // Add it to tracked servers. - bungeeReplacers.put(matcher.group(), () -> { - return BungeeServerTracker.getMotd2(serverName); - }); - } - - // BungeeCord status pattern. - matcher = BUNGEE_STATUS_PATTERN.matcher(name); - while (matcher.find()) { - - if (bungeeReplacers == null) { - bungeeReplacers = new HashMap<>(); - } - - final String serverName = extractArgumentFromPlaceholder(matcher); - BungeeServerTracker.track(serverName); // Track this server. - - // Add it to tracked servers. - bungeeReplacers.put(matcher.group(), () -> { - return BungeeServerTracker.getOnlineStatus(serverName); - }); - } - - - // Animation pattern. - matcher = ANIMATION_PATTERN.matcher(name); - while (matcher.find()) { + // Lazy initialization. + Set normalPlaceholders = null; + Map bungeeReplacers = null; + Map worldsOnlinePlayersReplacers = null; + Map animationsPlaceholders = null; + + Matcher matcher; + + for (Placeholder placeholder : PlaceholdersRegister.getPlaceholders()) { + + if (name.contains(placeholder.getTextPlaceholder())) { + + if (normalPlaceholders == null) { + normalPlaceholders = new HashSet<>(); + } + + normalPlaceholders.add(placeholder); + } + } + + + // Players in a world count pattern. + matcher = WORLD_PATTERN.matcher(name); + while (matcher.find()) { + + if (worldsOnlinePlayersReplacers == null) { + worldsOnlinePlayersReplacers = new HashMap<>(); + } + + final String worldsNames = extractArgumentFromPlaceholder(matcher); + + if (worldsNames.contains(",")) { + + String[] split = worldsNames.split(","); + for (int i = 0; i < split.length; i++) { + split[i] = split[i].trim(); + } + + final String[] worldsToTrack = split; + + // Add it to tracked worlds. + worldsOnlinePlayersReplacers.put(matcher.group(), () -> { + return WorldPlayerCounterTask.getCount(worldsToTrack); + }); + } else { + // Normal, single tracked world. + worldsOnlinePlayersReplacers.put(matcher.group(), () -> { + return WorldPlayerCounterTask.getCount(worldsNames); + }); + } + } + + // BungeeCord online pattern. + matcher = BUNGEE_ONLINE_PATTERN.matcher(name); + while (matcher.find()) { + + if (bungeeReplacers == null) { + bungeeReplacers = new HashMap<>(); + } + + final String serverName = extractArgumentFromPlaceholder(matcher); + BungeeServerTracker.track(serverName); // Track this server. + + if (serverName.contains(",")) { + + String[] split = serverName.split(","); + for (int i = 0; i < split.length; i++) { + split[i] = split[i].trim(); + } + + final String[] serversToTrack = split; + + // Add it to tracked servers. + bungeeReplacers.put(matcher.group(), () -> { + int count = 0; + for (String serverToTrack : serversToTrack) { + count += BungeeServerTracker.getPlayersOnline(serverToTrack); + } + return String.valueOf(count); + }); + } else { + // Normal, single tracked server. + bungeeReplacers.put(matcher.group(), () -> { + return String.valueOf(BungeeServerTracker.getPlayersOnline(serverName)); + }); + } + } + + // BungeeCord max players pattern. + matcher = BUNGEE_MAX_PATTERN.matcher(name); + while (matcher.find()) { + + if (bungeeReplacers == null) { + bungeeReplacers = new HashMap<>(); + } + + final String serverName = extractArgumentFromPlaceholder(matcher); + BungeeServerTracker.track(serverName); // Track this server. + + // Add it to tracked servers. + bungeeReplacers.put(matcher.group(), () -> { + return BungeeServerTracker.getMaxPlayers(serverName); + }); + } + + // BungeeCord motd pattern. + matcher = BUNGEE_MOTD_PATTERN.matcher(name); + while (matcher.find()) { + + if (bungeeReplacers == null) { + bungeeReplacers = new HashMap<>(); + } + + final String serverName = extractArgumentFromPlaceholder(matcher); + BungeeServerTracker.track(serverName); // Track this server. + + // Add it to tracked servers. + bungeeReplacers.put(matcher.group(), () -> { + return BungeeServerTracker.getMotd1(serverName); + }); + } + + // BungeeCord motd (line 2) pattern. + matcher = BUNGEE_MOTD_2_PATTERN.matcher(name); + while (matcher.find()) { + + if (bungeeReplacers == null) { + bungeeReplacers = new HashMap<>(); + } + + final String serverName = extractArgumentFromPlaceholder(matcher); + BungeeServerTracker.track(serverName); // Track this server. + + // Add it to tracked servers. + bungeeReplacers.put(matcher.group(), () -> { + return BungeeServerTracker.getMotd2(serverName); + }); + } + + // BungeeCord status pattern. + matcher = BUNGEE_STATUS_PATTERN.matcher(name); + while (matcher.find()) { + + if (bungeeReplacers == null) { + bungeeReplacers = new HashMap<>(); + } + + final String serverName = extractArgumentFromPlaceholder(matcher); + BungeeServerTracker.track(serverName); // Track this server. + + // Add it to tracked servers. + bungeeReplacers.put(matcher.group(), () -> { + return BungeeServerTracker.getOnlineStatus(serverName); + }); + } + + + // Animation pattern. + matcher = ANIMATION_PATTERN.matcher(name); + while (matcher.find()) { - String fileName = extractArgumentFromPlaceholder(matcher); - Placeholder animation = AnimationsRegister.getAnimation(fileName); - - // If exists... - if (animation != null) { - - if (animationsPlaceholders == null) { - animationsPlaceholders = new HashMap<>(); - } - - animationsPlaceholders.put(matcher.group(), animation); - - } else { - name = name.replace(matcher.group(), "[Animation not found: " + fileName + "]"); - updateName = true; - } - } - - if (Utils.isThereNonNull(normalPlaceholders, bungeeReplacers, worldsOnlinePlayersReplacers, animationsPlaceholders)) { - - DynamicLineData lineData = new DynamicLineData(nameableEntity, name); - - if (normalPlaceholders != null) { - lineData.setPlaceholders(normalPlaceholders); - } - - if (bungeeReplacers != null) { - lineData.getReplacers().putAll(bungeeReplacers); - } - - if (worldsOnlinePlayersReplacers != null) { - lineData.getReplacers().putAll(worldsOnlinePlayersReplacers); - } - - if (animationsPlaceholders != null) { - lineData.getAnimations().putAll(animationsPlaceholders); - } - - // It could be already tracked! - if (!linesToUpdate.add(lineData)) { - linesToUpdate.remove(lineData); - linesToUpdate.add(lineData); - } - - updatePlaceholders(lineData); - - } else { - - // The name needs to be updated anyways. - if (updateName) { - nameableEntity.setCustomNameNMS(name); - } - } - } - - - private static void updatePlaceholders(DynamicLineData lineData) { - String oldCustomName = lineData.getEntity().getCustomNameStringNMS(); - String newCustomName = lineData.getOriginalName(); - - if (!lineData.getPlaceholders().isEmpty()) { - for (Placeholder placeholder : lineData.getPlaceholders()) { - newCustomName = newCustomName.replace(placeholder.getTextPlaceholder(), Utils.sanitize(placeholder.getCurrentReplacement())); - } - } - - if (!lineData.getReplacers().isEmpty()) { - for (Entry entry : lineData.getReplacers().entrySet()) { - newCustomName = newCustomName.replace(entry.getKey(), Utils.sanitize(entry.getValue().update())); - } - } - - if (!lineData.getAnimations().isEmpty()) { - for (Entry entry : lineData.getAnimations().entrySet()) { - newCustomName = newCustomName.replace(entry.getKey(), Utils.sanitize(entry.getValue().getCurrentReplacement())); - } - } - - // Update only if needed, don't send useless packets. - if (!oldCustomName.equals(newCustomName)) { - lineData.getEntity().setCustomNameNMS(newCustomName); - } - } + String fileName = extractArgumentFromPlaceholder(matcher); + Placeholder animation = AnimationsRegister.getAnimation(fileName); + + // If exists... + if (animation != null) { + + if (animationsPlaceholders == null) { + animationsPlaceholders = new HashMap<>(); + } + + animationsPlaceholders.put(matcher.group(), animation); + + } else { + name = name.replace(matcher.group(), "[Animation not found: " + fileName + "]"); + updateName = true; + } + } + + if (Utils.isThereNonNull(normalPlaceholders, bungeeReplacers, worldsOnlinePlayersReplacers, animationsPlaceholders)) { + + DynamicLineData lineData = new DynamicLineData(nameableEntity, name); + + if (normalPlaceholders != null) { + lineData.setPlaceholders(normalPlaceholders); + } + + if (bungeeReplacers != null) { + lineData.getReplacers().putAll(bungeeReplacers); + } + + if (worldsOnlinePlayersReplacers != null) { + lineData.getReplacers().putAll(worldsOnlinePlayersReplacers); + } + + if (animationsPlaceholders != null) { + lineData.getAnimations().putAll(animationsPlaceholders); + } + + // It could be already tracked! + if (!linesToUpdate.add(lineData)) { + linesToUpdate.remove(lineData); + linesToUpdate.add(lineData); + } + + updatePlaceholders(lineData); + + } else { + + // The name needs to be updated anyways. + if (updateName) { + nameableEntity.setCustomNameNMS(name); + } + } + } + + + private static void updatePlaceholders(DynamicLineData lineData) { + String oldCustomName = lineData.getEntity().getCustomNameStringNMS(); + String newCustomName = lineData.getOriginalName(); + + if (!lineData.getPlaceholders().isEmpty()) { + for (Placeholder placeholder : lineData.getPlaceholders()) { + newCustomName = newCustomName.replace(placeholder.getTextPlaceholder(), Utils.sanitize(placeholder.getCurrentReplacement())); + } + } + + if (!lineData.getReplacers().isEmpty()) { + for (Entry entry : lineData.getReplacers().entrySet()) { + newCustomName = newCustomName.replace(entry.getKey(), Utils.sanitize(entry.getValue().update())); + } + } + + if (!lineData.getAnimations().isEmpty()) { + for (Entry entry : lineData.getAnimations().entrySet()) { + newCustomName = newCustomName.replace(entry.getKey(), Utils.sanitize(entry.getValue().getCurrentReplacement())); + } + } + + // Update only if needed, don't send useless packets. + if (!oldCustomName.equals(newCustomName)) { + lineData.getEntity().setCustomNameNMS(newCustomName); + } + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/PlaceholdersRegister.java b/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/PlaceholdersRegister.java index 7072976e..649d352f 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/PlaceholdersRegister.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/PlaceholdersRegister.java @@ -27,85 +27,85 @@ import java.util.Iterator; import java.util.Set; public class PlaceholdersRegister { - - private static final Set placeholders = new HashSet<>(); - - // Register the default placeholders statically. - static { - - register(new Placeholder(HolographicDisplays.getInstance(), "{online}", 1.0, () -> { - return String.valueOf(Bukkit.getOnlinePlayers().size()); - })); - - register(new Placeholder(HolographicDisplays.getInstance(), "{max_players}", 10.0, () -> { - return String.valueOf(Bukkit.getMaxPlayers()); - })); - - register(new Placeholder(HolographicDisplays.getInstance(), "{motd}", 60.0, () -> { - return Bukkit.getMotd(); - })); - - register(new Placeholder(HolographicDisplays.getInstance(), "{time}", 0.9, () -> { - return Configuration.timeFormat.format(new Date()); - })); - - register(new Placeholder(HolographicDisplays.getInstance(), "&u", 0.2, new CyclicPlaceholderReplacer(Utils.arrayToStrings( - ChatColor.RED, - ChatColor.GOLD, - ChatColor.YELLOW, - ChatColor.GREEN, - ChatColor.AQUA, - ChatColor.LIGHT_PURPLE - )))); - } - - - public static boolean register(Placeholder placeholder) { - if (placeholders.contains(placeholder)) { - return false; - } - - placeholders.add(placeholder); - return true; - } - - public static Set getTextPlaceholdersByPlugin(Plugin plugin) { - Set found = new HashSet<>(); - - for (Placeholder placeholder : placeholders) { - if (placeholder.getOwner().equals(plugin)) { - found.add(placeholder.getTextPlaceholder()); - } - } - - return found; - } - - public static boolean unregister(Plugin plugin, String textPlaceholder) { - - Iterator iter = placeholders.iterator(); - - while (iter.hasNext()) { - Placeholder placeholder = iter.next(); - - if (placeholder.getOwner().equals(plugin) && placeholder.getTextPlaceholder().equals(textPlaceholder)) { - iter.remove(); - - for (DynamicLineData data : PlaceholdersManager.linesToUpdate) { - if (data.getPlaceholders().contains(placeholder)) { - data.getPlaceholders().remove(placeholder); - } - } - - return true; - } - } - - return false; - } - - protected static Set getPlaceholders() { - return placeholders; - } + + private static final Set placeholders = new HashSet<>(); + + // Register the default placeholders statically. + static { + + register(new Placeholder(HolographicDisplays.getInstance(), "{online}", 1.0, () -> { + return String.valueOf(Bukkit.getOnlinePlayers().size()); + })); + + register(new Placeholder(HolographicDisplays.getInstance(), "{max_players}", 10.0, () -> { + return String.valueOf(Bukkit.getMaxPlayers()); + })); + + register(new Placeholder(HolographicDisplays.getInstance(), "{motd}", 60.0, () -> { + return Bukkit.getMotd(); + })); + + register(new Placeholder(HolographicDisplays.getInstance(), "{time}", 0.9, () -> { + return Configuration.timeFormat.format(new Date()); + })); + + register(new Placeholder(HolographicDisplays.getInstance(), "&u", 0.2, new CyclicPlaceholderReplacer(Utils.arrayToStrings( + ChatColor.RED, + ChatColor.GOLD, + ChatColor.YELLOW, + ChatColor.GREEN, + ChatColor.AQUA, + ChatColor.LIGHT_PURPLE + )))); + } + + + public static boolean register(Placeholder placeholder) { + if (placeholders.contains(placeholder)) { + return false; + } + + placeholders.add(placeholder); + return true; + } + + public static Set getTextPlaceholdersByPlugin(Plugin plugin) { + Set found = new HashSet<>(); + + for (Placeholder placeholder : placeholders) { + if (placeholder.getOwner().equals(plugin)) { + found.add(placeholder.getTextPlaceholder()); + } + } + + return found; + } + + public static boolean unregister(Plugin plugin, String textPlaceholder) { + + Iterator iter = placeholders.iterator(); + + while (iter.hasNext()) { + Placeholder placeholder = iter.next(); + + if (placeholder.getOwner().equals(plugin) && placeholder.getTextPlaceholder().equals(textPlaceholder)) { + iter.remove(); + + for (DynamicLineData data : PlaceholdersManager.linesToUpdate) { + if (data.getPlaceholders().contains(placeholder)) { + data.getPlaceholders().remove(placeholder); + } + } + + return true; + } + } + + return false; + } + + protected static Set getPlaceholders() { + return placeholders; + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/RelativePlaceholder.java b/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/RelativePlaceholder.java index 7d710bf1..e3c1058b 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/RelativePlaceholder.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/RelativePlaceholder.java @@ -20,52 +20,52 @@ import java.util.Collection; import java.util.HashSet; public abstract class RelativePlaceholder { - - private static final Collection registry = new HashSet<>(); - - // The placeholder itself, something like {player}. - private final String textPlaceholder; - - public RelativePlaceholder(String textPlaceholder) { - this.textPlaceholder = textPlaceholder; - } - - public String getTextPlaceholder() { - return textPlaceholder; - } - - public abstract String getReplacement(Player player); - - public static void register(RelativePlaceholder relativePlaceholder) { - for (RelativePlaceholder existingPlaceholder : registry) { - if (existingPlaceholder.getTextPlaceholder().equals(relativePlaceholder.getTextPlaceholder())) { - throw new IllegalArgumentException("Relative placeholder already registered."); - } - } - - registry.add(relativePlaceholder); - } - - public static Collection getRegistry() { - return registry; - } - - static { - register(new RelativePlaceholder("{player}") { - - @Override - public String getReplacement(Player player) { - return player.getName(); - } - }); - - register(new RelativePlaceholder("{displayname}") { - - @Override - public String getReplacement(Player player) { - return player.getDisplayName(); - } - }); - } + + private static final Collection registry = new HashSet<>(); + + // The placeholder itself, something like {player}. + private final String textPlaceholder; + + public RelativePlaceholder(String textPlaceholder) { + this.textPlaceholder = textPlaceholder; + } + + public String getTextPlaceholder() { + return textPlaceholder; + } + + public abstract String getReplacement(Player player); + + public static void register(RelativePlaceholder relativePlaceholder) { + for (RelativePlaceholder existingPlaceholder : registry) { + if (existingPlaceholder.getTextPlaceholder().equals(relativePlaceholder.getTextPlaceholder())) { + throw new IllegalArgumentException("Relative placeholder already registered."); + } + } + + registry.add(relativePlaceholder); + } + + public static Collection getRegistry() { + return registry; + } + + static { + register(new RelativePlaceholder("{player}") { + + @Override + public String getReplacement(Player player) { + return player.getName(); + } + }); + + register(new RelativePlaceholder("{displayname}") { + + @Override + public String getReplacement(Player player) { + return player.getDisplayName(); + } + }); + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/task/BungeeCleanupTask.java b/plugin/src/main/java/me/filoghost/holographicdisplays/task/BungeeCleanupTask.java index d9b4e175..69b3b20f 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/task/BungeeCleanupTask.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/task/BungeeCleanupTask.java @@ -27,25 +27,25 @@ import java.util.logging.Level; * A task to remove unused server data in the server tracker. */ public class BungeeCleanupTask implements Runnable { - - private static final long MAX_INACTIVITY = TimeUnit.MINUTES.toMillis(10); + + private static final long MAX_INACTIVITY = TimeUnit.MINUTES.toMillis(10); - @Override - public void run() { - - long now = System.currentTimeMillis(); - Iterator> iter = BungeeServerTracker.getTrackedServers().entrySet().iterator(); - - while (iter.hasNext()) { - Entry next = iter.next(); - long lastRequest = next.getValue().getLastRequest(); - - if (lastRequest != 0 && now - lastRequest > MAX_INACTIVITY) { - // Don't track that server anymore. - iter.remove(); - ConsoleLogger.logDebug(Level.INFO, "Removed bungee server \"" + next.getKey() + "\" from tracking due to inactivity."); - } - } - } + @Override + public void run() { + + long now = System.currentTimeMillis(); + Iterator> iter = BungeeServerTracker.getTrackedServers().entrySet().iterator(); + + while (iter.hasNext()) { + Entry next = iter.next(); + long lastRequest = next.getValue().getLastRequest(); + + if (lastRequest != 0 && now - lastRequest > MAX_INACTIVITY) { + // Don't track that server anymore. + iter.remove(); + ConsoleLogger.logDebug(Level.INFO, "Removed bungee server \"" + next.getKey() + "\" from tracking due to inactivity."); + } + } + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/task/StartupLoadHologramsTask.java b/plugin/src/main/java/me/filoghost/holographicdisplays/task/StartupLoadHologramsTask.java index de4a6979..6b716b38 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/task/StartupLoadHologramsTask.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/task/StartupLoadHologramsTask.java @@ -28,28 +28,28 @@ import java.util.logging.Level; public class StartupLoadHologramsTask implements Runnable { - @Override - public void run() { - Set savedHologramsNames = HologramDatabase.getHolograms(); - if (savedHologramsNames != null) { - for (String hologramName : savedHologramsNames) { - try { - NamedHologram namedHologram = HologramDatabase.loadHologram(hologramName); - NamedHologramManager.addHologram(namedHologram); - namedHologram.refreshAll(); - } catch (HologramNotFoundException e) { - ConsoleLogger.log(Level.WARNING, "Hologram '" + hologramName + "' not found, skipping it."); - } catch (InvalidFormatException e) { - ConsoleLogger.log(Level.WARNING, "Hologram '" + hologramName + "' has an invalid location format."); - } catch (WorldNotFoundException e) { - ConsoleLogger.log(Level.WARNING, "Hologram '" + hologramName + "' was in the world '" + e.getMessage() + "' but it wasn't loaded."); - } catch (HologramLineParseException e) { - ConsoleLogger.log(Level.WARNING, "Hologram '" + hologramName + "' has an invalid line: " + e.getMessage()); - } catch (Exception e) { - ConsoleLogger.log(Level.WARNING, "Unhandled exception while loading the hologram '" + hologramName + "'. Please contact the developer.", e); - } - } - } - } + @Override + public void run() { + Set savedHologramsNames = HologramDatabase.getHolograms(); + if (savedHologramsNames != null) { + for (String hologramName : savedHologramsNames) { + try { + NamedHologram namedHologram = HologramDatabase.loadHologram(hologramName); + NamedHologramManager.addHologram(namedHologram); + namedHologram.refreshAll(); + } catch (HologramNotFoundException e) { + ConsoleLogger.log(Level.WARNING, "Hologram '" + hologramName + "' not found, skipping it."); + } catch (InvalidFormatException e) { + ConsoleLogger.log(Level.WARNING, "Hologram '" + hologramName + "' has an invalid location format."); + } catch (WorldNotFoundException e) { + ConsoleLogger.log(Level.WARNING, "Hologram '" + hologramName + "' was in the world '" + e.getMessage() + "' but it wasn't loaded."); + } catch (HologramLineParseException e) { + ConsoleLogger.log(Level.WARNING, "Hologram '" + hologramName + "' has an invalid line: " + e.getMessage()); + } catch (Exception e) { + ConsoleLogger.log(Level.WARNING, "Unhandled exception while loading the hologram '" + hologramName + "'. Please contact the developer.", e); + } + } + } + } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/task/WorldPlayerCounterTask.java b/plugin/src/main/java/me/filoghost/holographicdisplays/task/WorldPlayerCounterTask.java index f78f5e9a..613eb777 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/task/WorldPlayerCounterTask.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/task/WorldPlayerCounterTask.java @@ -24,41 +24,41 @@ import java.util.Map; public class WorldPlayerCounterTask implements Runnable { - private static Map worlds = new HashMap<>(); - - @Override - public void run() { - worlds.clear(); - - for (World world : Bukkit.getWorlds()) { - List players = world.getPlayers(); - int count = 0; - - for (Player player : players) { - if (!player.hasMetadata("NPC")) { - count++; - } - } - worlds.put(world.getName(), count); - } - } - - public static String getCount(String[] worldsNames) { - int total = 0; - for (String worldName : worldsNames) { - Integer count = worlds.get(worldName); - if (count == null) { - return "[World \"" + worldName + "\" not found]"; - } - - total += count; - } - - return String.valueOf(total); - } - - public static String getCount(String worldName) { - Integer count = worlds.get(worldName); - return count != null ? count.toString() : "[World \"" + worldName + "\" not found]"; - } + private static Map worlds = new HashMap<>(); + + @Override + public void run() { + worlds.clear(); + + for (World world : Bukkit.getWorlds()) { + List players = world.getPlayers(); + int count = 0; + + for (Player player : players) { + if (!player.hasMetadata("NPC")) { + count++; + } + } + worlds.put(world.getName(), count); + } + } + + public static String getCount(String[] worldsNames) { + int total = 0; + for (String worldName : worldsNames) { + Integer count = worlds.get(worldName); + if (count == null) { + return "[World \"" + worldName + "\" not found]"; + } + + total += count; + } + + return String.valueOf(total); + } + + public static String getCount(String worldName) { + Integer count = worlds.get(worldName); + return count != null ? count.toString() : "[World \"" + worldName + "\" not found]"; + } } diff --git a/pom.xml b/pom.xml index 18d2c882..21b48d42 100644 --- a/pom.xml +++ b/pom.xml @@ -1,296 +1,296 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - me.filoghost.holographicdisplays - holographicdisplays-parent - HolographicDisplays Parent - 3.0.0-SNAPSHOT - pom + me.filoghost.holographicdisplays + holographicdisplays-parent + HolographicDisplays Parent + 3.0.0-SNAPSHOT + pom - - UTF-8 - 1.8 - 1.8 - true - 1.8-R0.1-SNAPSHOT - + + UTF-8 + 1.8 + 1.8 + true + 1.8-R0.1-SNAPSHOT + - - - codemc-snapshots - https://repo.codemc.io/repository/maven-snapshots/ - - - codemc-releases - https://repo.codemc.io/repository/maven-releases/ - - + + + codemc-snapshots + https://repo.codemc.io/repository/maven-snapshots/ + + + codemc-releases + https://repo.codemc.io/repository/maven-releases/ + + - - api - utils - config - legacy-v1 - legacy-v2 - nms - plugin - example - - - - - - ${project.groupId} - holographicdisplays-api - ${project.version} - - - - ${project.groupId} - holographicdisplays-utils - ${project.version} - - - - ${project.groupId} - holographicdisplays-legacy-v1 - ${project.version} - + + api + utils + config + legacy-v1 + legacy-v2 + nms + plugin + example + + + + + + ${project.groupId} + holographicdisplays-api + ${project.version} + + + + ${project.groupId} + holographicdisplays-utils + ${project.version} + + + + ${project.groupId} + holographicdisplays-legacy-v1 + ${project.version} + - - ${project.groupId} - holographicdisplays-legacy-v2 - ${project.version} - - - - ${project.groupId} - holographicdisplays-config - ${project.version} - - - - ${project.groupId} - holographicdisplays-nms-interfaces - ${project.version} - - - - ${project.groupId} - holographicdisplays-nms-v1_8_r2 - ${project.version} - - - - ${project.groupId} - holographicdisplays-nms-v1_8_r3 - ${project.version} - - - - ${project.groupId} - holographicdisplays-nms-v1_9_r1 - ${project.version} - - - - ${project.groupId} - holographicdisplays-nms-v1_9_r2 - ${project.version} - - - - ${project.groupId} - holographicdisplays-nms-v1_10_r1 - ${project.version} - - - - ${project.groupId} - holographicdisplays-nms-v1_11_r1 - ${project.version} - - - - ${project.groupId} - holographicdisplays-nms-v1_12_r1 - ${project.version} - - - - ${project.groupId} - holographicdisplays-nms-v1_13_r1 - ${project.version} - - - - ${project.groupId} - holographicdisplays-nms-v1_13_r2 - ${project.version} - - - - ${project.groupId} - holographicdisplays-nms-v1_14_r1 - ${project.version} - - - - ${project.groupId} - holographicdisplays-nms-v1_15_r1 - ${project.version} - + + ${project.groupId} + holographicdisplays-legacy-v2 + ${project.version} + + + + ${project.groupId} + holographicdisplays-config + ${project.version} + + + + ${project.groupId} + holographicdisplays-nms-interfaces + ${project.version} + + + + ${project.groupId} + holographicdisplays-nms-v1_8_r2 + ${project.version} + + + + ${project.groupId} + holographicdisplays-nms-v1_8_r3 + ${project.version} + + + + ${project.groupId} + holographicdisplays-nms-v1_9_r1 + ${project.version} + + + + ${project.groupId} + holographicdisplays-nms-v1_9_r2 + ${project.version} + + + + ${project.groupId} + holographicdisplays-nms-v1_10_r1 + ${project.version} + + + + ${project.groupId} + holographicdisplays-nms-v1_11_r1 + ${project.version} + + + + ${project.groupId} + holographicdisplays-nms-v1_12_r1 + ${project.version} + + + + ${project.groupId} + holographicdisplays-nms-v1_13_r1 + ${project.version} + + + + ${project.groupId} + holographicdisplays-nms-v1_13_r2 + ${project.version} + + + + ${project.groupId} + holographicdisplays-nms-v1_14_r1 + ${project.version} + + + + ${project.groupId} + holographicdisplays-nms-v1_15_r1 + ${project.version} + - - ${project.groupId} - holographicdisplays-nms-v1_16_r1 - ${project.version} - + + ${project.groupId} + holographicdisplays-nms-v1_16_r1 + ${project.version} + - - ${project.groupId} - holographicdisplays-nms-v1_16_r2 - ${project.version} - + + ${project.groupId} + holographicdisplays-nms-v1_16_r2 + ${project.version} + - - ${project.groupId} - holographicdisplays-nms-v1_16_r3 - ${project.version} - - - - org.spigotmc - spigot-api - ${spigot-api.version} - provided - - - - com.comphenix.protocol - ProtocolLib - 4.2.1 - provided - - - - org.bstats - bstats-bukkit-lite - 1.7 - - - - me.filoghost.updatechecker - updatechecker - 1.0.0 - - - + + ${project.groupId} + holographicdisplays-nms-v1_16_r3 + ${project.version} + + + + org.spigotmc + spigot-api + ${spigot-api.version} + provided + + + + com.comphenix.protocol + ProtocolLib + 4.2.1 + provided + + + + org.bstats + bstats-bukkit-lite + 1.7 + + + + me.filoghost.updatechecker + updatechecker + 1.0.0 + + + - - clean package - - - - - org.apache.maven.plugins - maven-jar-plugin - 3.2.0 - - - false - - false - - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.2.0 - - - **/holographicdisplays/api/**/*.java - - - **/holographicdisplays/api/internal/**/*.java - - - - - - org.apache.maven.plugins - maven-antrun-plugin - 3.0.0 - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.3 - - - - org.apache.maven.plugins - maven-enforcer-plugin - 3.0.0-M3 - - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - org.apache.maven.plugins - maven-antrun-plugin - [0.0,) - - run - - - - - - - - - - - - - - - - org.apache.maven.plugins - maven-enforcer-plugin - - - - enforce - - - - - - [3.6.0,) - - - [1.8,) - - - - - - - - + + clean package + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.2.0 + + + false + + false + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.2.0 + + + **/holographicdisplays/api/**/*.java + + + **/holographicdisplays/api/internal/**/*.java + + + + + + org.apache.maven.plugins + maven-antrun-plugin + 3.0.0 + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.3 + + + + org.apache.maven.plugins + maven-enforcer-plugin + 3.0.0-M3 + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + org.apache.maven.plugins + maven-antrun-plugin + [0.0,) + + run + + + + + + + + + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + + + + enforce + + + + + + [3.6.0,) + + + [1.8,) + + + + + + + + diff --git a/utils/pom.xml b/utils/pom.xml index 3c3d5141..f2a5f19b 100644 --- a/utils/pom.xml +++ b/utils/pom.xml @@ -1,34 +1,34 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - - me.filoghost.holographicdisplays - holographicdisplays-parent - 3.0.0-SNAPSHOT - + + me.filoghost.holographicdisplays + holographicdisplays-parent + 3.0.0-SNAPSHOT + - holographicdisplays-utils - HolographicDisplays Utils + holographicdisplays-utils + HolographicDisplays Utils - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + - - - ${project.groupId} - holographicdisplays-api - - - - org.spigotmc - spigot-api - - + + + ${project.groupId} + holographicdisplays-api + + + + org.spigotmc + spigot-api + + diff --git a/utils/src/main/java/me/filoghost/holographicdisplays/exception/UnreadableImageException.java b/utils/src/main/java/me/filoghost/holographicdisplays/exception/UnreadableImageException.java index c3cc18b1..1975d1f4 100644 --- a/utils/src/main/java/me/filoghost/holographicdisplays/exception/UnreadableImageException.java +++ b/utils/src/main/java/me/filoghost/holographicdisplays/exception/UnreadableImageException.java @@ -16,6 +16,6 @@ package me.filoghost.holographicdisplays.exception; public class UnreadableImageException extends Exception { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; } diff --git a/utils/src/main/java/me/filoghost/holographicdisplays/util/ConsoleLogger.java b/utils/src/main/java/me/filoghost/holographicdisplays/util/ConsoleLogger.java index ba637251..f3818bde 100644 --- a/utils/src/main/java/me/filoghost/holographicdisplays/util/ConsoleLogger.java +++ b/utils/src/main/java/me/filoghost/holographicdisplays/util/ConsoleLogger.java @@ -20,40 +20,40 @@ import java.util.logging.Level; import java.util.logging.Logger; public class ConsoleLogger { - - private static boolean debug; - private static Logger logger; - - public static void setLogger(Logger logger) { - ConsoleLogger.logger = logger; - } - - public static void setDebugEnabled(boolean enabled) { - debug = enabled; - } - - public static void log(Level level, String msg, Throwable thrown) { - if (logger != null) { - logger.log(level, msg, thrown); - } - } - - public static void log(Level level, String msg) { - log(level, msg, null); - } + + private static boolean debug; + private static Logger logger; + + public static void setLogger(Logger logger) { + ConsoleLogger.logger = logger; + } + + public static void setDebugEnabled(boolean enabled) { + debug = enabled; + } + + public static void log(Level level, String msg, Throwable thrown) { + if (logger != null) { + logger.log(level, msg, thrown); + } + } + + public static void log(Level level, String msg) { + log(level, msg, null); + } - public static void logDebug(Level level, String msg, Throwable thrown) { - if (debug) { - log(level, "[Debug] " + msg, thrown); - } - } - - public static void logDebug(Level level, String msg) { - logDebug(level, msg, null); - } - - public static void handleSpawnFail(HologramLine parentPiece) { - logDebug(Level.WARNING, "Coulnd't spawn entity for this hologram: " + parentPiece.getParent().toString()); - } - + public static void logDebug(Level level, String msg, Throwable thrown) { + if (debug) { + log(level, "[Debug] " + msg, thrown); + } + } + + public static void logDebug(Level level, String msg) { + logDebug(level, msg, null); + } + + public static void handleSpawnFail(HologramLine parentPiece) { + logDebug(Level.WARNING, "Coulnd't spawn entity for this hologram: " + parentPiece.getParent().toString()); + } + } diff --git a/utils/src/main/java/me/filoghost/holographicdisplays/util/FileUtils.java b/utils/src/main/java/me/filoghost/holographicdisplays/util/FileUtils.java index 5e6423a8..c813fed6 100644 --- a/utils/src/main/java/me/filoghost/holographicdisplays/util/FileUtils.java +++ b/utils/src/main/java/me/filoghost/holographicdisplays/util/FileUtils.java @@ -29,78 +29,78 @@ import java.util.List; public class FileUtils { - - public static List readLines(File file) throws IOException, Exception { + + public static List readLines(File file) throws IOException, Exception { - if (!file.isFile()) { - throw new FileNotFoundException(file.getName()); - } - - BufferedReader br = null; + if (!file.isFile()) { + throw new FileNotFoundException(file.getName()); + } + + BufferedReader br = null; - try { + try { - List lines = new ArrayList<>(); + List lines = new ArrayList<>(); - if (!file.exists()) { - throw new FileNotFoundException(); - } + if (!file.exists()) { + throw new FileNotFoundException(); + } - br = new BufferedReader(new FileReader(file)); - String line = br.readLine(); + br = new BufferedReader(new FileReader(file)); + String line = br.readLine(); - while (line != null) { - lines.add(line); - line = br.readLine(); - } + while (line != null) { + lines.add(line); + line = br.readLine(); + } - return lines; + return lines; - } finally { - if (br != null) { - try { - br.close(); - } catch (IOException e) { } - } - } - } - - public static BufferedImage readImage(File file) throws UnreadableImageException, IOException, Exception { - - if (!file.isFile()) { - throw new FileNotFoundException(file.getName()); - } - - BufferedImage image = ImageIO.read(file); - - if (image == null) { - throw new UnreadableImageException(); - } - - return image; - } - - public static BufferedImage readImage(URL url) throws UnreadableImageException, IOException, Exception { - - BufferedImage image = ImageIO.read(url); - - if (image == null) { - throw new UnreadableImageException(); - } - - return image; - } - - public static boolean isParentFolder(File folder, File file) throws IOException { - File iteratorFile = file.getCanonicalFile(); - folder = folder.getCanonicalFile(); - while ((iteratorFile = iteratorFile.getParentFile()) != null) { - if (iteratorFile.equals(folder)) { - return true; - } - } - - return false; - } + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException e) { } + } + } + } + + public static BufferedImage readImage(File file) throws UnreadableImageException, IOException, Exception { + + if (!file.isFile()) { + throw new FileNotFoundException(file.getName()); + } + + BufferedImage image = ImageIO.read(file); + + if (image == null) { + throw new UnreadableImageException(); + } + + return image; + } + + public static BufferedImage readImage(URL url) throws UnreadableImageException, IOException, Exception { + + BufferedImage image = ImageIO.read(url); + + if (image == null) { + throw new UnreadableImageException(); + } + + return image; + } + + public static boolean isParentFolder(File folder, File file) throws IOException { + File iteratorFile = file.getCanonicalFile(); + folder = folder.getCanonicalFile(); + while ((iteratorFile = iteratorFile.getParentFile()) != null) { + if (iteratorFile.equals(folder)) { + return true; + } + } + + return false; + } } diff --git a/utils/src/main/java/me/filoghost/holographicdisplays/util/ItemUtils.java b/utils/src/main/java/me/filoghost/holographicdisplays/util/ItemUtils.java index 0e5e5cc6..9662bc95 100644 --- a/utils/src/main/java/me/filoghost/holographicdisplays/util/ItemUtils.java +++ b/utils/src/main/java/me/filoghost/holographicdisplays/util/ItemUtils.java @@ -22,99 +22,99 @@ import java.util.Map; import java.util.regex.Pattern; public class ItemUtils { - - // This is used on hologram icons, to prevent vanilla items from merging with them. - public static final String ANTISTACK_LORE = ChatColor.BLACK.toString() + Math.random(); - - // A map with formatted materials (lowercase and without symbols) for fast access. - private static final Map NAMES_TO_MATERIALS = new HashMap<>(); - - // The chars that will be ignored when matching materials. - private static final Pattern SPACING_CHARACTERS_PATTERN = Pattern.compile("[_ \\-]+"); - - static { - // Add default materials. - for (Material mat : Material.values()) { - NAMES_TO_MATERIALS.put(stripSpacingChars(mat.toString()).toLowerCase(), mat); - } - - // Only add aliases before 1.13. - if (!NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) { - // Default material names are not intuitive and sometimes confusing. - addAlias("iron bar", "IRON_FENCE"); - addAlias("iron bars", "IRON_FENCE"); - addAlias("glass pane", "THIN_GLASS"); - addAlias("nether wart", "NETHER_STALK"); - addAlias("nether warts", "NETHER_STALK"); - addAlias("slab", "STEP"); - addAlias("double slab", "DOUBLE_STEP"); - addAlias("stone brick", "SMOOTH_BRICK"); - addAlias("stone bricks", "SMOOTH_BRICK"); - addAlias("stone stair", "SMOOTH_STAIRS"); - addAlias("stone stairs", "SMOOTH_STAIRS"); - addAlias("potato", "POTATO_ITEM"); - addAlias("carrot", "CARROT_ITEM"); - addAlias("brewing stand", "BREWING_STAND_ITEM"); - addAlias("cauldron", "CAULDRON_ITEM"); - addAlias("carrot on stick", "CARROT_STICK"); - addAlias("carrot on a stick", "CARROT_STICK"); - addAlias("cobblestone wall", "COBBLE_WALL"); - addAlias("wood slab", "WOOD_STEP"); - addAlias("double wood slab", "WOOD_DOUBLE_STEP"); - addAlias("repeater", "DIODE"); - addAlias("piston", "PISTON_BASE"); - addAlias("sticky piston", "PISTON_STICKY_BASE"); - addAlias("flower pot", "FLOWER_POT_ITEM"); - addAlias("wood showel", "WOOD_SPADE"); - addAlias("stone showel", "STONE_SPADE"); - addAlias("gold showel", "GOLD_SPADE"); - addAlias("iron showel", "IRON_SPADE"); - addAlias("diamond showel", "DIAMOND_SPADE"); - addAlias("steak", "COOKED_BEEF"); - addAlias("cooked porkchop", "GRILLED_PORK"); - addAlias("raw porkchop", "PORK"); - addAlias("hardened clay", "HARD_CLAY"); - addAlias("huge brown mushroom", "HUGE_MUSHROOM_1"); - addAlias("huge red mushroom", "HUGE_MUSHROOM_2"); - addAlias("mycelium", "MYCEL"); - addAlias("poppy", "RED_ROSE"); - addAlias("comparator", "REDSTONE_COMPARATOR"); - addAlias("skull", "SKULL_ITEM"); - addAlias("head", "SKULL_ITEM"); - addAlias("redstone torch", "REDSTONE_TORCH_ON"); - addAlias("redstone lamp", "REDSTONE_LAMP_OFF"); - addAlias("glistering melon", "SPECKLED_MELON"); - addAlias("gunpowder", "SULPHUR"); - addAlias("lilypad", "WATER_LILY"); - addAlias("command block", "COMMAND"); - addAlias("dye", "INK_SACK"); - } - } - - private static void addAlias(String alias, String material) { - try { - NAMES_TO_MATERIALS.put(stripSpacingChars(alias).toLowerCase(), Material.valueOf(material)); - } catch (IllegalArgumentException e) { - // Not found, do nothing. - } - } - - public static String stripSpacingChars(String input) { - return SPACING_CHARACTERS_PATTERN.matcher(input).replaceAll(""); - } - - @SuppressWarnings("deprecation") - public static Material matchMaterial(String input) { - if (!NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) { - // Before 1.13, allow IDs as materials. - try { - return Material.getMaterial(Integer.parseInt(input)); - } catch (NumberFormatException e) { - // Not a number, ignore and go on. - } - } + + // This is used on hologram icons, to prevent vanilla items from merging with them. + public static final String ANTISTACK_LORE = ChatColor.BLACK.toString() + Math.random(); + + // A map with formatted materials (lowercase and without symbols) for fast access. + private static final Map NAMES_TO_MATERIALS = new HashMap<>(); + + // The chars that will be ignored when matching materials. + private static final Pattern SPACING_CHARACTERS_PATTERN = Pattern.compile("[_ \\-]+"); + + static { + // Add default materials. + for (Material mat : Material.values()) { + NAMES_TO_MATERIALS.put(stripSpacingChars(mat.toString()).toLowerCase(), mat); + } + + // Only add aliases before 1.13. + if (!NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) { + // Default material names are not intuitive and sometimes confusing. + addAlias("iron bar", "IRON_FENCE"); + addAlias("iron bars", "IRON_FENCE"); + addAlias("glass pane", "THIN_GLASS"); + addAlias("nether wart", "NETHER_STALK"); + addAlias("nether warts", "NETHER_STALK"); + addAlias("slab", "STEP"); + addAlias("double slab", "DOUBLE_STEP"); + addAlias("stone brick", "SMOOTH_BRICK"); + addAlias("stone bricks", "SMOOTH_BRICK"); + addAlias("stone stair", "SMOOTH_STAIRS"); + addAlias("stone stairs", "SMOOTH_STAIRS"); + addAlias("potato", "POTATO_ITEM"); + addAlias("carrot", "CARROT_ITEM"); + addAlias("brewing stand", "BREWING_STAND_ITEM"); + addAlias("cauldron", "CAULDRON_ITEM"); + addAlias("carrot on stick", "CARROT_STICK"); + addAlias("carrot on a stick", "CARROT_STICK"); + addAlias("cobblestone wall", "COBBLE_WALL"); + addAlias("wood slab", "WOOD_STEP"); + addAlias("double wood slab", "WOOD_DOUBLE_STEP"); + addAlias("repeater", "DIODE"); + addAlias("piston", "PISTON_BASE"); + addAlias("sticky piston", "PISTON_STICKY_BASE"); + addAlias("flower pot", "FLOWER_POT_ITEM"); + addAlias("wood showel", "WOOD_SPADE"); + addAlias("stone showel", "STONE_SPADE"); + addAlias("gold showel", "GOLD_SPADE"); + addAlias("iron showel", "IRON_SPADE"); + addAlias("diamond showel", "DIAMOND_SPADE"); + addAlias("steak", "COOKED_BEEF"); + addAlias("cooked porkchop", "GRILLED_PORK"); + addAlias("raw porkchop", "PORK"); + addAlias("hardened clay", "HARD_CLAY"); + addAlias("huge brown mushroom", "HUGE_MUSHROOM_1"); + addAlias("huge red mushroom", "HUGE_MUSHROOM_2"); + addAlias("mycelium", "MYCEL"); + addAlias("poppy", "RED_ROSE"); + addAlias("comparator", "REDSTONE_COMPARATOR"); + addAlias("skull", "SKULL_ITEM"); + addAlias("head", "SKULL_ITEM"); + addAlias("redstone torch", "REDSTONE_TORCH_ON"); + addAlias("redstone lamp", "REDSTONE_LAMP_OFF"); + addAlias("glistering melon", "SPECKLED_MELON"); + addAlias("gunpowder", "SULPHUR"); + addAlias("lilypad", "WATER_LILY"); + addAlias("command block", "COMMAND"); + addAlias("dye", "INK_SACK"); + } + } + + private static void addAlias(String alias, String material) { + try { + NAMES_TO_MATERIALS.put(stripSpacingChars(alias).toLowerCase(), Material.valueOf(material)); + } catch (IllegalArgumentException e) { + // Not found, do nothing. + } + } + + public static String stripSpacingChars(String input) { + return SPACING_CHARACTERS_PATTERN.matcher(input).replaceAll(""); + } + + @SuppressWarnings("deprecation") + public static Material matchMaterial(String input) { + if (!NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) { + // Before 1.13, allow IDs as materials. + try { + return Material.getMaterial(Integer.parseInt(input)); + } catch (NumberFormatException e) { + // Not a number, ignore and go on. + } + } - return NAMES_TO_MATERIALS.get(stripSpacingChars(input).toLowerCase()); - } + return NAMES_TO_MATERIALS.get(stripSpacingChars(input).toLowerCase()); + } } diff --git a/utils/src/main/java/me/filoghost/holographicdisplays/util/NMSVersion.java b/utils/src/main/java/me/filoghost/holographicdisplays/util/NMSVersion.java index b6423980..b86202f4 100644 --- a/utils/src/main/java/me/filoghost/holographicdisplays/util/NMSVersion.java +++ b/utils/src/main/java/me/filoghost/holographicdisplays/util/NMSVersion.java @@ -18,61 +18,61 @@ package me.filoghost.holographicdisplays.util; * The NMS version is the name of the main package under net.minecraft.server. */ public enum NMSVersion { - - v1_8_R2, - v1_8_R3, - v1_9_R1, - v1_9_R2, - v1_10_R1, - v1_11_R1, - v1_12_R1, - v1_13_R1, - v1_13_R2, - v1_14_R1, - v1_15_R1, - v1_16_R1, - v1_16_R2, - v1_16_R3; - - private static final NMSVersion CURRENT_VERSION = extractCurrentVersion(); - - - private static NMSVersion extractCurrentVersion() { - String nmsVersionName = VersionUtils.extractNMSVersion(); - - if (nmsVersionName != null) { - try { - return valueOf(nmsVersionName); - } catch (IllegalArgumentException e) { - return null; - } - } else { - return null; - } - } - - - public static boolean isValid() { - return CURRENT_VERSION != null; - } + + v1_8_R2, + v1_8_R3, + v1_9_R1, + v1_9_R2, + v1_10_R1, + v1_11_R1, + v1_12_R1, + v1_13_R1, + v1_13_R2, + v1_14_R1, + v1_15_R1, + v1_16_R1, + v1_16_R2, + v1_16_R3; + + private static final NMSVersion CURRENT_VERSION = extractCurrentVersion(); + + + private static NMSVersion extractCurrentVersion() { + String nmsVersionName = VersionUtils.extractNMSVersion(); + + if (nmsVersionName != null) { + try { + return valueOf(nmsVersionName); + } catch (IllegalArgumentException e) { + return null; + } + } else { + return null; + } + } + + + public static boolean isValid() { + return CURRENT_VERSION != null; + } - - public static NMSVersion getCurrent() { - if (CURRENT_VERSION == null) { - throw new IllegalStateException("Current version not set"); - } - return CURRENT_VERSION; - } - - - public static boolean isGreaterEqualThan(NMSVersion other) { - return getCurrent().ordinal() >= other.ordinal(); - } - - - public static boolean isBetween(NMSVersion from, NMSVersion to) { - return from.ordinal() <= getCurrent().ordinal() && getCurrent().ordinal() <= to.ordinal(); - } - - + + public static NMSVersion getCurrent() { + if (CURRENT_VERSION == null) { + throw new IllegalStateException("Current version not set"); + } + return CURRENT_VERSION; + } + + + public static boolean isGreaterEqualThan(NMSVersion other) { + return getCurrent().ordinal() >= other.ordinal(); + } + + + public static boolean isBetween(NMSVersion from, NMSVersion to) { + return from.ordinal() <= getCurrent().ordinal() && getCurrent().ordinal() <= to.ordinal(); + } + + } diff --git a/utils/src/main/java/me/filoghost/holographicdisplays/util/Offsets.java b/utils/src/main/java/me/filoghost/holographicdisplays/util/Offsets.java index 6682ddf4..81020b5d 100644 --- a/utils/src/main/java/me/filoghost/holographicdisplays/util/Offsets.java +++ b/utils/src/main/java/me/filoghost/holographicdisplays/util/Offsets.java @@ -19,16 +19,16 @@ package me.filoghost.holographicdisplays.util; * The second line is below the first, and so on. */ public class Offsets { - - public static final double - - // A single armor stand. - ARMOR_STAND_ALONE = -0.29, - - // An armor stand holding an item. - ARMOR_STAND_WITH_ITEM = 0, - - // An armor stand holding a slime. - ARMOR_STAND_WITH_SLIME = 0; + + public static final double + + // A single armor stand. + ARMOR_STAND_ALONE = -0.29, + + // An armor stand holding an item. + ARMOR_STAND_WITH_ITEM = 0, + + // An armor stand holding a slime. + ARMOR_STAND_WITH_SLIME = 0; } diff --git a/utils/src/main/java/me/filoghost/holographicdisplays/util/Utils.java b/utils/src/main/java/me/filoghost/holographicdisplays/util/Utils.java index 42555598..ab155000 100644 --- a/utils/src/main/java/me/filoghost/holographicdisplays/util/Utils.java +++ b/utils/src/main/java/me/filoghost/holographicdisplays/util/Utils.java @@ -16,99 +16,99 @@ package me.filoghost.holographicdisplays.util; public class Utils { - /** - * Converts a generic array to an array of Strings using the method toString(). - * @param array the array to convert - * @return the new generated array of Strings - */ - public static String[] arrayToStrings(Object... array) { - String[] result = new String[array.length]; - for (int i = 0; i < array.length; i++) { - result[i] = array[i] != null ? array[i].toString() : null; - } - - return result; - } - - - public static String limitLength(String s, int maxLength) { - if (s != null && s.length() > maxLength) { - s = s.substring(0, maxLength); - } - return s; - } - - - public static int floor(double num) { - int floor = (int) num; - return floor == num ? floor : floor - (int) (Double.doubleToRawLongBits(num) >>> 63); - } - - - public static double square(double num) { - return num * num; - } - - - public static String join(String[] elements, String separator, int startIndex, int endIndex) { - Validator.isTrue(startIndex >= 0 && startIndex < elements.length, "startIndex out of bounds"); - Validator.isTrue(endIndex >= 0 && endIndex <= elements.length, "endIndex out of bounds"); - Validator.isTrue(startIndex <= endIndex, "startIndex lower than endIndex"); - - StringBuilder result = new StringBuilder(); - - while (startIndex < endIndex) { - if (result.length() != 0) { - result.append(separator); - } - - if (elements[startIndex] != null) { - result.append(elements[startIndex]); - } - startIndex++; - } - - return result.toString(); - } - - public static String sanitize(String s) { - return s != null ? s : "null"; - } - - - public static boolean isThereNonNull(Object... objects) { - if (objects == null) { - return false; - } - - for (int i = 0; i < objects.length; i++) { - if (objects[i] != null) { - return true; - } - } - - return false; - } - - - public static boolean classExists(String className) { - try { - Class.forName(className); - return true; - } catch (Throwable t) { - return false; - } - } - - public static String uncapitalize(String str) { - if (str == null || str.isEmpty()) { - return str; - } - - return new StringBuilder(str.length()) - .append(Character.toLowerCase(str.charAt(0))) - .append(str.substring(1)) - .toString(); - } - + /** + * Converts a generic array to an array of Strings using the method toString(). + * @param array the array to convert + * @return the new generated array of Strings + */ + public static String[] arrayToStrings(Object... array) { + String[] result = new String[array.length]; + for (int i = 0; i < array.length; i++) { + result[i] = array[i] != null ? array[i].toString() : null; + } + + return result; + } + + + public static String limitLength(String s, int maxLength) { + if (s != null && s.length() > maxLength) { + s = s.substring(0, maxLength); + } + return s; + } + + + public static int floor(double num) { + int floor = (int) num; + return floor == num ? floor : floor - (int) (Double.doubleToRawLongBits(num) >>> 63); + } + + + public static double square(double num) { + return num * num; + } + + + public static String join(String[] elements, String separator, int startIndex, int endIndex) { + Validator.isTrue(startIndex >= 0 && startIndex < elements.length, "startIndex out of bounds"); + Validator.isTrue(endIndex >= 0 && endIndex <= elements.length, "endIndex out of bounds"); + Validator.isTrue(startIndex <= endIndex, "startIndex lower than endIndex"); + + StringBuilder result = new StringBuilder(); + + while (startIndex < endIndex) { + if (result.length() != 0) { + result.append(separator); + } + + if (elements[startIndex] != null) { + result.append(elements[startIndex]); + } + startIndex++; + } + + return result.toString(); + } + + public static String sanitize(String s) { + return s != null ? s : "null"; + } + + + public static boolean isThereNonNull(Object... objects) { + if (objects == null) { + return false; + } + + for (int i = 0; i < objects.length; i++) { + if (objects[i] != null) { + return true; + } + } + + return false; + } + + + public static boolean classExists(String className) { + try { + Class.forName(className); + return true; + } catch (Throwable t) { + return false; + } + } + + public static String uncapitalize(String str) { + if (str == null || str.isEmpty()) { + return str; + } + + return new StringBuilder(str.length()) + .append(Character.toLowerCase(str.charAt(0))) + .append(str.substring(1)) + .toString(); + } + } diff --git a/utils/src/main/java/me/filoghost/holographicdisplays/util/Validator.java b/utils/src/main/java/me/filoghost/holographicdisplays/util/Validator.java index 29e6a8f4..e709a762 100644 --- a/utils/src/main/java/me/filoghost/holographicdisplays/util/Validator.java +++ b/utils/src/main/java/me/filoghost/holographicdisplays/util/Validator.java @@ -16,16 +16,16 @@ package me.filoghost.holographicdisplays.util; public class Validator { - public static void notNull(Object o, String name) { - if (o == null) { - throw new NullPointerException(name + " cannot be null"); - } - } - - public static void isTrue(boolean statement, String message) { - if (!statement) { - throw new IllegalArgumentException(message); - } - } - + public static void notNull(Object o, String name) { + if (o == null) { + throw new NullPointerException(name + " cannot be null"); + } + } + + public static void isTrue(boolean statement, String message) { + if (!statement) { + throw new IllegalArgumentException(message); + } + } + } diff --git a/utils/src/main/java/me/filoghost/holographicdisplays/util/VersionUtils.java b/utils/src/main/java/me/filoghost/holographicdisplays/util/VersionUtils.java index 0fd26793..093bbb93 100644 --- a/utils/src/main/java/me/filoghost/holographicdisplays/util/VersionUtils.java +++ b/utils/src/main/java/me/filoghost/holographicdisplays/util/VersionUtils.java @@ -20,77 +20,77 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; public class VersionUtils { - - private static final boolean IS_PAPER_SERVER = Bukkit.getName().equals("Paper"); - - - /** - * Paper contains some code changes compared to Spigot. - */ - public static boolean isPaperServer() { - return IS_PAPER_SERVER; - } - - - /** - * This method uses a regex to get the NMS package part that changes with every update. - * Example: v1_13_R2 - * @return the NMS package part or null if not found. - */ - public static String extractNMSVersion() { - Matcher matcher = Pattern.compile("v\\d+_\\d+_R\\d+").matcher(Bukkit.getServer().getClass().getPackage().getName()); - if (matcher.find()) { - return matcher.group(); - } else { - return null; - } - } - - - /** - * @return 1 if reference > comparison, 0 if reference == comparison, -1 if reference < comparison - */ - private static int compare(String reference, String comparison) throws NumberFormatException { - String[] referenceSplit = reference.split("\\."); - String[] comparisonSplit = comparison.split("\\."); - - int longest = Math.max(referenceSplit.length, comparisonSplit.length); - - // Default value is 0 - int[] referenceNumbersArray = new int[longest]; - int[] comparisonNumbersArray = new int[longest]; - - for (int i = 0; i < referenceSplit.length; i++) { - referenceNumbersArray[i] = Integer.parseInt(referenceSplit[i]); - } - - for (int i = 0; i < comparisonSplit.length; i++) { - comparisonNumbersArray[i] = Integer.parseInt(comparisonSplit[i]); - } - - for (int i = 0; i < longest; i++) { - int diff = referenceNumbersArray[i] - comparisonNumbersArray[i]; - if (diff > 0) { - return 1; - } else if (diff < 0) { - return -1; - } - } - - return 0; - } - - - public static boolean isVersionGreaterEqual(String reference, String thanWhat) { - return compare(reference, thanWhat) >= 0; - } - - public static boolean isVersionLessEqual(String reference, String thanWhat) { - return compare(reference, thanWhat) <= 0; - } - - public static boolean isVersionBetweenEqual(String reference, String lowest, String highest) { - return isVersionGreaterEqual(reference, lowest) && isVersionLessEqual(reference, highest); - } - + + private static final boolean IS_PAPER_SERVER = Bukkit.getName().equals("Paper"); + + + /** + * Paper contains some code changes compared to Spigot. + */ + public static boolean isPaperServer() { + return IS_PAPER_SERVER; + } + + + /** + * This method uses a regex to get the NMS package part that changes with every update. + * Example: v1_13_R2 + * @return the NMS package part or null if not found. + */ + public static String extractNMSVersion() { + Matcher matcher = Pattern.compile("v\\d+_\\d+_R\\d+").matcher(Bukkit.getServer().getClass().getPackage().getName()); + if (matcher.find()) { + return matcher.group(); + } else { + return null; + } + } + + + /** + * @return 1 if reference > comparison, 0 if reference == comparison, -1 if reference < comparison + */ + private static int compare(String reference, String comparison) throws NumberFormatException { + String[] referenceSplit = reference.split("\\."); + String[] comparisonSplit = comparison.split("\\."); + + int longest = Math.max(referenceSplit.length, comparisonSplit.length); + + // Default value is 0 + int[] referenceNumbersArray = new int[longest]; + int[] comparisonNumbersArray = new int[longest]; + + for (int i = 0; i < referenceSplit.length; i++) { + referenceNumbersArray[i] = Integer.parseInt(referenceSplit[i]); + } + + for (int i = 0; i < comparisonSplit.length; i++) { + comparisonNumbersArray[i] = Integer.parseInt(comparisonSplit[i]); + } + + for (int i = 0; i < longest; i++) { + int diff = referenceNumbersArray[i] - comparisonNumbersArray[i]; + if (diff > 0) { + return 1; + } else if (diff < 0) { + return -1; + } + } + + return 0; + } + + + public static boolean isVersionGreaterEqual(String reference, String thanWhat) { + return compare(reference, thanWhat) >= 0; + } + + public static boolean isVersionLessEqual(String reference, String thanWhat) { + return compare(reference, thanWhat) <= 0; + } + + public static boolean isVersionBetweenEqual(String reference, String lowest, String highest) { + return isVersionGreaterEqual(reference, lowest) && isVersionLessEqual(reference, highest); + } + } diff --git a/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTByte.java b/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTByte.java index 1aa60342..88c767ee 100644 --- a/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTByte.java +++ b/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTByte.java @@ -5,54 +5,54 @@ package me.filoghost.holographicdisplays.util.nbt; */ public final class NBTByte extends NBTTag implements Cloneable { - private byte value; + private byte value; - public NBTByte(byte value) { - this.value = value; - } + public NBTByte(byte value) { + this.value = value; + } - @Override - public Byte getValue() { - return value; - } + @Override + public Byte getValue() { + return value; + } - public byte getByteValue() { - return value; - } + public byte getByteValue() { + return value; + } - public void setByteValue(byte value) { - this.value = value; - } + public void setByteValue(byte value) { + this.value = value; + } - @Override - public NBTType getType() { - return NBTType.BYTE; - } + @Override + public NBTType getType() { + return NBTType.BYTE; + } - // MISC + // MISC - @Override - public boolean equals(Object obj) { - return obj instanceof NBTByte && equals((NBTByte) obj); - } + @Override + public boolean equals(Object obj) { + return obj instanceof NBTByte && equals((NBTByte) obj); + } - public boolean equals(NBTByte tag) { - return this.value == tag.value; - } + public boolean equals(NBTByte tag) { + return this.value == tag.value; + } - @Override - public int hashCode() { - return Byte.hashCode(value); - } + @Override + public int hashCode() { + return Byte.hashCode(value); + } - @Override - public String toMSONString() { - return Byte.toUnsignedInt(value) + "b"; - } + @Override + public String toMSONString() { + return Byte.toUnsignedInt(value) + "b"; + } - @Override - public NBTByte clone() { - return new NBTByte(value); - } + @Override + public NBTByte clone() { + return new NBTByte(value); + } } diff --git a/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTByteArray.java b/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTByteArray.java index 320c2b36..e19e015f 100644 --- a/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTByteArray.java +++ b/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTByteArray.java @@ -7,58 +7,58 @@ import java.util.Arrays; */ public final class NBTByteArray extends NBTTag { - private final byte[] value; + private final byte[] value; - public NBTByteArray(byte[] value) { - this.value = value; - } + public NBTByteArray(byte[] value) { + this.value = value; + } - public NBTByteArray(Number[] numbers) { - this.value = new byte[numbers.length]; - for (int i = 0; i < numbers.length; i++) - value[i] = numbers[i].byteValue(); - } + public NBTByteArray(Number[] numbers) { + this.value = new byte[numbers.length]; + for (int i = 0; i < numbers.length; i++) + value[i] = numbers[i].byteValue(); + } - /** - * Returns the length of this array. - * - * @return the length of this array - */ - public int length() { - return value.length; - } + /** + * Returns the length of this array. + * + * @return the length of this array + */ + public int length() { + return value.length; + } - @Override - public byte[] getValue() { - return value; - } + @Override + public byte[] getValue() { + return value; + } - @Override - public NBTType getType() { - return NBTType.BYTE_ARRAY; - } + @Override + public NBTType getType() { + return NBTType.BYTE_ARRAY; + } - // MISC + // MISC - @Override - public boolean equals(Object obj) { - return obj instanceof NBTByteArray && equals((NBTByteArray) obj); - } + @Override + public boolean equals(Object obj) { + return obj instanceof NBTByteArray && equals((NBTByteArray) obj); + } - public boolean equals(NBTByteArray tag) { - return Arrays.equals(this.value, tag.value); - } + public boolean equals(NBTByteArray tag) { + return Arrays.equals(this.value, tag.value); + } - @Override - public String toMSONString() { - StringBuilder stringbuilder = new StringBuilder("[B;"); - for (int i = 0; i < this.value.length; i++) { - if (i != 0) { - stringbuilder.append(','); - } - stringbuilder.append(this.value[i]).append('B'); - } - return stringbuilder.append(']').toString(); - } + @Override + public String toMSONString() { + StringBuilder stringbuilder = new StringBuilder("[B;"); + for (int i = 0; i < this.value.length; i++) { + if (i != 0) { + stringbuilder.append(','); + } + stringbuilder.append(this.value[i]).append('B'); + } + return stringbuilder.append(']').toString(); + } } diff --git a/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTCompound.java b/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTCompound.java index 4afc4736..322ac130 100644 --- a/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTCompound.java +++ b/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTCompound.java @@ -15,422 +15,422 @@ import java.util.regex.Pattern; */ public final class NBTCompound extends NBTTag { - private static final Pattern SIMPLE_STRING = Pattern.compile("[A-Za-z0-9._+-]+"); + private static final Pattern SIMPLE_STRING = Pattern.compile("[A-Za-z0-9._+-]+"); - private final Map value; + private final Map value; - public NBTCompound(Map value) { - this.value = new LinkedHashMap(value); - } + public NBTCompound(Map value) { + this.value = new LinkedHashMap(value); + } - public NBTCompound() { - this.value = new LinkedHashMap(); - } + public NBTCompound() { + this.value = new LinkedHashMap(); + } - // GETTERS + // GETTERS - /** - * Returns the size of this compound. - * - * @return the size of this compound - */ - public int size() { - return value.size(); - } + /** + * Returns the size of this compound. + * + * @return the size of this compound + */ + public int size() { + return value.size(); + } - @Override - public Map getValue() { - return value; - } + @Override + public Map getValue() { + return value; + } - @Override - public NBTType getType() { - return NBTType.COMPOUND; - } + @Override + public NBTType getType() { + return NBTType.COMPOUND; + } - /** - * Returns a tag named with the given key. - * - * @param key the key - * @return a byte - * @throws NoSuchElementException if there is no tag with given name - */ - public NBTTag getTag(String key) { - if (!hasKey(key)) throw new NoSuchElementException(key); - return value.get(key); - } + /** + * Returns a tag named with the given key. + * + * @param key the key + * @return a byte + * @throws NoSuchElementException if there is no tag with given name + */ + public NBTTag getTag(String key) { + if (!hasKey(key)) throw new NoSuchElementException(key); + return value.get(key); + } - /** - * Returns a byte named with the given key. - * - * @param key the key - * @return a byte - * @throws NoSuchElementException if there is no byte with given name - */ - public byte getByte(String key) { - NBTTag tag = value.get(key); - if (!(tag instanceof NBTByte)) throw new NoSuchElementException(key); - return ((NBTByte) tag).getValue(); - } + /** + * Returns a byte named with the given key. + * + * @param key the key + * @return a byte + * @throws NoSuchElementException if there is no byte with given name + */ + public byte getByte(String key) { + NBTTag tag = value.get(key); + if (!(tag instanceof NBTByte)) throw new NoSuchElementException(key); + return ((NBTByte) tag).getValue(); + } - /** - * Returns an short named with the given key. - * - * @param key the key - * @return an short - * @throws NoSuchElementException if there is no short with given name - */ - public short getShort(String key) { - NBTTag tag = value.get(key); - if (!(tag instanceof NBTShort)) throw new NoSuchElementException(key); - return ((NBTShort) tag).getValue(); - } + /** + * Returns an short named with the given key. + * + * @param key the key + * @return an short + * @throws NoSuchElementException if there is no short with given name + */ + public short getShort(String key) { + NBTTag tag = value.get(key); + if (!(tag instanceof NBTShort)) throw new NoSuchElementException(key); + return ((NBTShort) tag).getValue(); + } - /** - * Returns an int named with the given key. - * - * @param key the key - * @return an int - * @throws NoSuchElementException if there is no int with given name - */ - public int getInt(String key) { - NBTTag tag = value.get(key); - if (!(tag instanceof NBTInt)) throw new NoSuchElementException(key); - return ((NBTInt) tag).getValue(); - } + /** + * Returns an int named with the given key. + * + * @param key the key + * @return an int + * @throws NoSuchElementException if there is no int with given name + */ + public int getInt(String key) { + NBTTag tag = value.get(key); + if (!(tag instanceof NBTInt)) throw new NoSuchElementException(key); + return ((NBTInt) tag).getValue(); + } - /** - * Returns an long named with the given key. - * - * @param key the key - * @return an long - * @throws NoSuchElementException if there is no long with given name - */ - public long getLong(String key) { - NBTTag tag = value.get(key); - if (!(tag instanceof NBTLong)) throw new NoSuchElementException(key); - return ((NBTLong) tag).getValue(); - } + /** + * Returns an long named with the given key. + * + * @param key the key + * @return an long + * @throws NoSuchElementException if there is no long with given name + */ + public long getLong(String key) { + NBTTag tag = value.get(key); + if (!(tag instanceof NBTLong)) throw new NoSuchElementException(key); + return ((NBTLong) tag).getValue(); + } - /** - * Returns float named with the given key. - * - * @param key the key - * @return a float - * @throws NoSuchElementException if there is no float with given name - */ - public float getFloat(String key) { - NBTTag tag = value.get(key); - if (!(tag instanceof NBTFloat)) throw new NoSuchElementException(key); - return ((NBTFloat) tag).getValue(); - } + /** + * Returns float named with the given key. + * + * @param key the key + * @return a float + * @throws NoSuchElementException if there is no float with given name + */ + public float getFloat(String key) { + NBTTag tag = value.get(key); + if (!(tag instanceof NBTFloat)) throw new NoSuchElementException(key); + return ((NBTFloat) tag).getValue(); + } - /** - * Returns a double named with the given key. - * - * @param key the key - * @return a double - * @throws NoSuchElementException if there is no int with given name - */ - public double getDouble(String key) { - NBTTag tag = value.get(key); - if (!(tag instanceof NBTDouble)) throw new NoSuchElementException(key); - return ((NBTDouble) tag).getValue(); - } + /** + * Returns a double named with the given key. + * + * @param key the key + * @return a double + * @throws NoSuchElementException if there is no int with given name + */ + public double getDouble(String key) { + NBTTag tag = value.get(key); + if (!(tag instanceof NBTDouble)) throw new NoSuchElementException(key); + return ((NBTDouble) tag).getValue(); + } - /** - * Returns a byte array named with the given key. - * - * @param key the key - * @return a byte array - * @throws NoSuchElementException if there is no int with given name - */ - public byte[] getByteArray(String key) { - NBTTag tag = value.get(key); - if (!(tag instanceof NBTByteArray)) throw new NoSuchElementException(key); - return ((NBTByteArray) tag).getValue(); - } + /** + * Returns a byte array named with the given key. + * + * @param key the key + * @return a byte array + * @throws NoSuchElementException if there is no int with given name + */ + public byte[] getByteArray(String key) { + NBTTag tag = value.get(key); + if (!(tag instanceof NBTByteArray)) throw new NoSuchElementException(key); + return ((NBTByteArray) tag).getValue(); + } - /** - * Returns a string named with the given key. - * - * @param key the key - * @return a string - * @throws NoSuchElementException if there is no int with given name - */ - public String getString(String key) { - NBTTag tag = value.get(key); - if (!(tag instanceof NBTString)) throw new NoSuchElementException(key); - return ((NBTString) tag).getValue(); - } + /** + * Returns a string named with the given key. + * + * @param key the key + * @return a string + * @throws NoSuchElementException if there is no int with given name + */ + public String getString(String key) { + NBTTag tag = value.get(key); + if (!(tag instanceof NBTString)) throw new NoSuchElementException(key); + return ((NBTString) tag).getValue(); + } - /** - * Returns a list named with the given key. - * - * @param key the key - * @return a list - * @throws NoSuchElementException if there is no int with given name - */ - public List getList(String key) { - return getTagList(key).getValue(); - } + /** + * Returns a list named with the given key. + * + * @param key the key + * @return a list + * @throws NoSuchElementException if there is no int with given name + */ + public List getList(String key) { + return getTagList(key).getValue(); + } - /** - * Returns a list named with the given key. - * - * @param key the key - * @return a list - * @throws NoSuchElementException if there is no list with given name - */ - public NBTList getTagList(String key) { - NBTTag tag = value.get(key); - if (!(tag instanceof NBTList)) throw new NoSuchElementException(key); - return (NBTList) tag; - } + /** + * Returns a list named with the given key. + * + * @param key the key + * @return a list + * @throws NoSuchElementException if there is no list with given name + */ + public NBTList getTagList(String key) { + NBTTag tag = value.get(key); + if (!(tag instanceof NBTList)) throw new NoSuchElementException(key); + return (NBTList) tag; + } - /** - * Returns a list named with the given key. - * - * @param key the key - * @return a list - * @throws NoSuchElementException if there is no compound with given name - */ - public Map getCompound(String key) { - return getCompoundTag(key).getValue(); - } + /** + * Returns a list named with the given key. + * + * @param key the key + * @return a list + * @throws NoSuchElementException if there is no compound with given name + */ + public Map getCompound(String key) { + return getCompoundTag(key).getValue(); + } - /** - * Returns a compound named with the given key. - * - * @param key the key - * @return a compound - * @throws NoSuchElementException if there is no compound with given name - */ - public NBTCompound getCompoundTag(String key) { - NBTTag tag = value.get(key); - if (!(tag instanceof NBTCompound)) throw new NoSuchElementException(key); - return (NBTCompound) tag; - } + /** + * Returns a compound named with the given key. + * + * @param key the key + * @return a compound + * @throws NoSuchElementException if there is no compound with given name + */ + public NBTCompound getCompoundTag(String key) { + NBTTag tag = value.get(key); + if (!(tag instanceof NBTCompound)) throw new NoSuchElementException(key); + return (NBTCompound) tag; + } - /** - * Returns an int array named with the given key. - * - * @param key the key - * @return a int array - * @throws NoSuchElementException if there is no int array with given name - */ - public int[] getIntArray(String key) { - NBTTag tag = value.get(key); - if (!(tag instanceof NBTIntArray)) throw new NoSuchElementException(key); - return ((NBTIntArray) tag).getValue(); - } + /** + * Returns an int array named with the given key. + * + * @param key the key + * @return a int array + * @throws NoSuchElementException if there is no int array with given name + */ + public int[] getIntArray(String key) { + NBTTag tag = value.get(key); + if (!(tag instanceof NBTIntArray)) throw new NoSuchElementException(key); + return ((NBTIntArray) tag).getValue(); + } - /** - * Returns a long array named with the given key. - * - * @param key the key - * @return a int array - * @throws NoSuchElementException if there is no int array with given name - */ - public long[] getLongArray(String key) { - NBTTag tag = value.get(key); - if (!(tag instanceof NBTLongArray)) throw new NoSuchElementException(key); - return ((NBTLongArray) tag).getValue(); - } + /** + * Returns a long array named with the given key. + * + * @param key the key + * @return a int array + * @throws NoSuchElementException if there is no int array with given name + */ + public long[] getLongArray(String key) { + NBTTag tag = value.get(key); + if (!(tag instanceof NBTLongArray)) throw new NoSuchElementException(key); + return ((NBTLongArray) tag).getValue(); + } - /** - * Returns an immutable set containing all the keys in this compound. - * - * @return an immutable set - */ - public Set getKeys() { - return Collections.unmodifiableSet(value.keySet()); - } + /** + * Returns an immutable set containing all the keys in this compound. + * + * @return an immutable set + */ + public Set getKeys() { + return Collections.unmodifiableSet(value.keySet()); + } - // PREDICATES + // PREDICATES - /** - * Returns whether this compound is empty. - * - * @return whether this compound is empty - */ - public boolean isEmpty() { - return value.isEmpty(); - } + /** + * Returns whether this compound is empty. + * + * @return whether this compound is empty + */ + public boolean isEmpty() { + return value.isEmpty(); + } - /** - * Returns whether this compound tag contains the given key. - * - * @param key the given key - * @return true if the tag contains the given key - */ - public boolean hasKey(String key) { - return value.containsKey(key); - } + /** + * Returns whether this compound tag contains the given key. + * + * @param key the given key + * @return true if the tag contains the given key + */ + public boolean hasKey(String key) { + return value.containsKey(key); + } - /** - * Returns whether this compound tag contains the given key and its value is of a given type. - * - * @param key the given key - * @param type the type of the value - * @return true if the tag contains an entry with given key and of given type - */ - public boolean hasKeyOfType(String key, NBTType type) { - Objects.requireNonNull(type); - return value.containsKey(key) && value.get(key).getType() == type; - } + /** + * Returns whether this compound tag contains the given key and its value is of a given type. + * + * @param key the given key + * @param type the type of the value + * @return true if the tag contains an entry with given key and of given type + */ + public boolean hasKeyOfType(String key, NBTType type) { + Objects.requireNonNull(type); + return value.containsKey(key) && value.get(key).getType() == type; + } - // MUTATORS + // MUTATORS - /** - * Put the given name and its corresponding tag into the compound tag. - * - * @param name the tag name - * @param tag the tag value - */ - public void put(String name, NBTTag tag) { - this.value.put(name, tag); - } + /** + * Put the given name and its corresponding tag into the compound tag. + * + * @param name the tag name + * @param tag the tag value + */ + public void put(String name, NBTTag tag) { + this.value.put(name, tag); + } - /** - * Put the given key and value into the compound tag. - * - * @param key they key - * @param value the value - */ - public void putByteArray(String key, byte[] value) { - put(key, new NBTByteArray(value)); - } + /** + * Put the given key and value into the compound tag. + * + * @param key they key + * @param value the value + */ + public void putByteArray(String key, byte[] value) { + put(key, new NBTByteArray(value)); + } - /** - * Put the given key and value into the compound tag. - * - * @param key they key - * @param value the value - */ - public void putByte(String key, byte value) { - put(key, new NBTByte(value)); - } + /** + * Put the given key and value into the compound tag. + * + * @param key they key + * @param value the value + */ + public void putByte(String key, byte value) { + put(key, new NBTByte(value)); + } - /** - * Put the given key and value into the compound tag. - * - * @param key they key - * @param value the value - */ - public void putDouble(String key, double value) { - put(key, new NBTDouble(value)); - } + /** + * Put the given key and value into the compound tag. + * + * @param key they key + * @param value the value + */ + public void putDouble(String key, double value) { + put(key, new NBTDouble(value)); + } - /** - * Put the given key and value into the compound tag. - * - * @param key they key - * @param value the value - */ - public void putFloat(String key, float value) { - put(key, new NBTFloat(value)); - } + /** + * Put the given key and value into the compound tag. + * + * @param key they key + * @param value the value + */ + public void putFloat(String key, float value) { + put(key, new NBTFloat(value)); + } - /** - * Put the given key and value into the compound tag. - * - * @param key they key - * @param value the value - */ - public void putIntArray(String key, int[] value) { - put(key, new NBTIntArray(value)); - } + /** + * Put the given key and value into the compound tag. + * + * @param key they key + * @param value the value + */ + public void putIntArray(String key, int[] value) { + put(key, new NBTIntArray(value)); + } - /** - * Put the given key and value into the compound tag. - * - * @param key they key - * @param value the value - */ - public void putLongArray(String key, long[] value) { - put(key, new NBTLongArray(value)); - } + /** + * Put the given key and value into the compound tag. + * + * @param key they key + * @param value the value + */ + public void putLongArray(String key, long[] value) { + put(key, new NBTLongArray(value)); + } - /** - * Put the given key and value into the compound tag. - * - * @param key they key - * @param value the valu - */ - public void putInt(String key, int value) { - put(key, new NBTInt(value)); - } + /** + * Put the given key and value into the compound tag. + * + * @param key they key + * @param value the valu + */ + public void putInt(String key, int value) { + put(key, new NBTInt(value)); + } - /** - * Put the given key and value into the compound tag. - * - * @param key they key - * @param value the value - */ - public void putLong(String key, long value) { - put(key, new NBTLong(value)); - } + /** + * Put the given key and value into the compound tag. + * + * @param key they key + * @param value the value + */ + public void putLong(String key, long value) { + put(key, new NBTLong(value)); + } - /** - * Put the given key and value into the compound tag. - * - * @param key they key - * @param value the value - */ - public void putShort(String key, short value) { - put(key, new NBTShort(value)); - } + /** + * Put the given key and value into the compound tag. + * + * @param key they key + * @param value the value + */ + public void putShort(String key, short value) { + put(key, new NBTShort(value)); + } - /** - * Put the given key and value into the compound tag. - * - * @param key they key - * @param value the value - */ - public void putString(String key, String value) { - put(key, new NBTString(value)); - } + /** + * Put the given key and value into the compound tag. + * + * @param key they key + * @param value the value + */ + public void putString(String key, String value) { + put(key, new NBTString(value)); + } - // ITERATION + // ITERATION - /** - * Performs an action for every pair of keys and tags. - * - * @param action the action - */ - public void forEach(BiConsumer action) { - this.value.forEach(action); - } + /** + * Performs an action for every pair of keys and tags. + * + * @param action the action + */ + public void forEach(BiConsumer action) { + this.value.forEach(action); + } - // MISC + // MISC - @Override - public boolean equals(Object obj) { - return obj instanceof NBTCompound && equals((NBTCompound) obj); - } + @Override + public boolean equals(Object obj) { + return obj instanceof NBTCompound && equals((NBTCompound) obj); + } - public boolean equals(NBTCompound tag) { - return this.isEmpty() && tag.isEmpty() - || this.value.equals(tag.value); - } + public boolean equals(NBTCompound tag) { + return this.isEmpty() && tag.isEmpty() + || this.value.equals(tag.value); + } - @Override - public String toMSONString() { - StringBuilder builder = new StringBuilder("{"); - Set keys = this.value.keySet(); + @Override + public String toMSONString() { + StringBuilder builder = new StringBuilder("{"); + Set keys = this.value.keySet(); - for (String key : keys) { - if (builder.length() > 1) { - builder.append(','); - } - builder - .append(SIMPLE_STRING.matcher(key).matches() ? key : NBTString.toMSONString(key)) - .append(':') - .append(this.value.get(key).toMSONString()); - } + for (String key : keys) { + if (builder.length() > 1) { + builder.append(','); + } + builder + .append(SIMPLE_STRING.matcher(key).matches() ? key : NBTString.toMSONString(key)) + .append(':') + .append(this.value.get(key).toMSONString()); + } - return builder.append("}").toString(); - } + return builder.append("}").toString(); + } } diff --git a/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTDouble.java b/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTDouble.java index cb9fe474..772eadc4 100644 --- a/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTDouble.java +++ b/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTDouble.java @@ -5,54 +5,54 @@ package me.filoghost.holographicdisplays.util.nbt; */ public final class NBTDouble extends NBTTag implements Cloneable { - private double value; + private double value; - public NBTDouble(double value) { - this.value = value; - } + public NBTDouble(double value) { + this.value = value; + } - @Override - public Double getValue() { - return value; - } + @Override + public Double getValue() { + return value; + } - public double getDoubleValue() { - return value; - } + public double getDoubleValue() { + return value; + } - public void setDoubleValue(double value) { - this.value = value; - } + public void setDoubleValue(double value) { + this.value = value; + } - @Override - public NBTType getType() { - return NBTType.DOUBLE; - } + @Override + public NBTType getType() { + return NBTType.DOUBLE; + } - // MISC + // MISC - @Override - public boolean equals(Object obj) { - return obj instanceof NBTDouble && equals((NBTDouble) obj); - } + @Override + public boolean equals(Object obj) { + return obj instanceof NBTDouble && equals((NBTDouble) obj); + } - public boolean equals(NBTDouble tag) { - return this.value == tag.value; - } + public boolean equals(NBTDouble tag) { + return this.value == tag.value; + } - @Override - public int hashCode() { - return Double.hashCode(value); - } + @Override + public int hashCode() { + return Double.hashCode(value); + } - @Override - public String toMSONString() { - return value + "d"; - } + @Override + public String toMSONString() { + return value + "d"; + } - @Override - public NBTDouble clone() { - return new NBTDouble(value); - } + @Override + public NBTDouble clone() { + return new NBTDouble(value); + } -} \ No newline at end of file +} diff --git a/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTFloat.java b/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTFloat.java index 95f83ef8..919ae1ac 100644 --- a/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTFloat.java +++ b/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTFloat.java @@ -5,54 +5,54 @@ package me.filoghost.holographicdisplays.util.nbt; */ public final class NBTFloat extends NBTTag implements Cloneable { - private float value; + private float value; - public NBTFloat(float value) { - this.value = value; - } + public NBTFloat(float value) { + this.value = value; + } - @Override - public Float getValue() { - return value; - } + @Override + public Float getValue() { + return value; + } - public float getFloatValue() { - return value; - } + public float getFloatValue() { + return value; + } - public void setFloatValue(float value) { - this.value = value; - } + public void setFloatValue(float value) { + this.value = value; + } - @Override - public NBTType getType() { - return NBTType.FLOAT; - } + @Override + public NBTType getType() { + return NBTType.FLOAT; + } - // MISC + // MISC - @Override - public boolean equals(Object obj) { - return obj instanceof NBTFloat && equals((NBTFloat) obj); - } + @Override + public boolean equals(Object obj) { + return obj instanceof NBTFloat && equals((NBTFloat) obj); + } - public boolean equals(NBTFloat tag) { - return this.value == tag.value; - } + public boolean equals(NBTFloat tag) { + return this.value == tag.value; + } - @Override - public int hashCode() { - return Float.hashCode(value); - } + @Override + public int hashCode() { + return Float.hashCode(value); + } - @Override - public String toMSONString() { - return value + "f"; - } + @Override + public String toMSONString() { + return value + "f"; + } - @Override - public NBTFloat clone() { - return new NBTFloat(value); - } + @Override + public NBTFloat clone() { + return new NBTFloat(value); + } } diff --git a/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTInt.java b/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTInt.java index 59d0a881..af133df3 100644 --- a/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTInt.java +++ b/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTInt.java @@ -5,54 +5,54 @@ package me.filoghost.holographicdisplays.util.nbt; */ public final class NBTInt extends NBTTag implements Cloneable { - private int value; + private int value; - public NBTInt(int value) { - this.value = value; - } + public NBTInt(int value) { + this.value = value; + } - @Override - public Integer getValue() { - return value; - } + @Override + public Integer getValue() { + return value; + } - public int getIntValue() { - return value; - } + public int getIntValue() { + return value; + } - public void setIntValue(int value) { - this.value = value; - } + public void setIntValue(int value) { + this.value = value; + } - @Override - public NBTType getType() { - return NBTType.INT; - } + @Override + public NBTType getType() { + return NBTType.INT; + } - // MISC + // MISC - @Override - public boolean equals(Object obj) { - return obj instanceof NBTInt && equals((NBTInt) obj); - } + @Override + public boolean equals(Object obj) { + return obj instanceof NBTInt && equals((NBTInt) obj); + } - public boolean equals(NBTInt tag) { - return this.value == tag.value; - } + public boolean equals(NBTInt tag) { + return this.value == tag.value; + } - @Override - public int hashCode() { - return Integer.hashCode(value); - } + @Override + public int hashCode() { + return Integer.hashCode(value); + } - @Override - public String toMSONString() { - return Integer.toString(value); - } + @Override + public String toMSONString() { + return Integer.toString(value); + } - @Override - public NBTInt clone() { - return new NBTInt(value); - } + @Override + public NBTInt clone() { + return new NBTInt(value); + } } diff --git a/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTIntArray.java b/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTIntArray.java index abb0fcf5..cf0fb6ad 100644 --- a/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTIntArray.java +++ b/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTIntArray.java @@ -8,68 +8,68 @@ import java.util.Objects; */ public final class NBTIntArray extends NBTTag implements Cloneable { - private final int[] value; + private final int[] value; - /** - * Creates the tag with an empty name. - * - * @param value the value of the tag - */ - public NBTIntArray(int[] value) { - this.value = Objects.requireNonNull(value); - } + /** + * Creates the tag with an empty name. + * + * @param value the value of the tag + */ + public NBTIntArray(int[] value) { + this.value = Objects.requireNonNull(value); + } - public NBTIntArray(Number[] numbers) { - this.value = new int[numbers.length]; - for (int i = 0; i < numbers.length; i++) - value[i] = numbers[i].intValue(); - } + public NBTIntArray(Number[] numbers) { + this.value = new int[numbers.length]; + for (int i = 0; i < numbers.length; i++) + value[i] = numbers[i].intValue(); + } - /** - * Returns the length of this array. - * - * @return the length of this array - */ - public int length() { - return value.length; - } + /** + * Returns the length of this array. + * + * @return the length of this array + */ + public int length() { + return value.length; + } - @Override - public int[] getValue() { - return value; - } + @Override + public int[] getValue() { + return value; + } - @Override - public NBTType getType() { - return NBTType.INT_ARRAY; - } + @Override + public NBTType getType() { + return NBTType.INT_ARRAY; + } - // MISC + // MISC - @Override - public boolean equals(Object obj) { - return obj instanceof NBTIntArray && equals((NBTIntArray) obj); - } + @Override + public boolean equals(Object obj) { + return obj instanceof NBTIntArray && equals((NBTIntArray) obj); + } - public boolean equals(NBTIntArray tag) { - return Arrays.equals(this.value, tag.value); - } + public boolean equals(NBTIntArray tag) { + return Arrays.equals(this.value, tag.value); + } - @Override - public String toMSONString() { - StringBuilder stringbuilder = new StringBuilder("[I;"); - for (int i = 0; i < this.value.length; i++) { - if (i != 0) { - stringbuilder.append(','); - } - stringbuilder.append(this.value[i]); - } - return stringbuilder.append(']').toString(); - } + @Override + public String toMSONString() { + StringBuilder stringbuilder = new StringBuilder("[I;"); + for (int i = 0; i < this.value.length; i++) { + if (i != 0) { + stringbuilder.append(','); + } + stringbuilder.append(this.value[i]); + } + return stringbuilder.append(']').toString(); + } - @Override - public NBTIntArray clone() { - return new NBTIntArray(value); - } + @Override + public NBTIntArray clone() { + return new NBTIntArray(value); + } } diff --git a/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTList.java b/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTList.java index 8c445b19..ab5cea73 100644 --- a/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTList.java +++ b/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTList.java @@ -12,177 +12,177 @@ import java.util.NoSuchElementException; */ public final class NBTList extends NBTTag implements Iterable, Cloneable { - private NBTType type; + private NBTType type; - private final List list = new ArrayList(); + private final List list = new ArrayList(); - /** - * Creates the list with a type and a series of elements. - * - * @param type the type of tag - * @param value the value of the tag - */ - public NBTList(NBTType type, List value) { - this.type = type; - for (NBTTag entry : value) { - this.add(entry); - } - } + /** + * Creates the list with a type and a series of elements. + * + * @param type the type of tag + * @param value the value of the tag + */ + public NBTList(NBTType type, List value) { + this.type = type; + for (NBTTag entry : value) { + this.add(entry); + } + } - /** - * Creates the list with a type and a series of elements. - * - * @param type the type of tag - * @param value the value of the tag - */ - public NBTList(NBTType type, NBTTag... value) { - this(type, Arrays.asList(value)); - } + /** + * Creates the list with a type and a series of elements. + * + * @param type the type of tag + * @param value the value of the tag + */ + public NBTList(NBTType type, NBTTag... value) { + this(type, Arrays.asList(value)); + } - /** - * Creates an empty list with a type. - * - * @param type the type of tag or null if the list has no type yet - */ - public NBTList(NBTType type) { - this.type = type; - } + /** + * Creates an empty list with a type. + * + * @param type the type of tag or null if the list has no type yet + */ + public NBTList(NBTType type) { + this.type = type; + } - /** - * Creates an empty list without a type. - */ - public NBTList() { - this(null); - } + /** + * Creates an empty list without a type. + */ + public NBTList() { + this(null); + } - // GETTERS + // GETTERS - /** - * Returns the size of this list. - * - * @return the size of this list - */ - public int size() { - return list.size(); - } + /** + * Returns the size of this list. + * + * @return the size of this list + */ + public int size() { + return list.size(); + } - @Override - public List getValue() { - return list; - } + @Override + public List getValue() { + return list; + } - @Override - public NBTType getType() { - return NBTType.LIST; - } + @Override + public NBTType getType() { + return NBTType.LIST; + } - /** - * Gets the type of elements in this list. - * - * @return The type of elements in this list. - */ - public NBTType getElementType() { - return type; - } + /** + * Gets the type of elements in this list. + * + * @return The type of elements in this list. + */ + public NBTType getElementType() { + return type; + } - /** - * Returns a tag named with the given index. - * - * @param index the index - * @return a byte - * @throws NoSuchElementException if there is no tag with given index - */ - public NBTTag get(int index) { - return list.get(index); - } + /** + * Returns a tag named with the given index. + * + * @param index the index + * @return a byte + * @throws NoSuchElementException if there is no tag with given index + */ + public NBTTag get(int index) { + return list.get(index); + } - // PREDICATES + // PREDICATES - /** - * Returns whether this list is empty. - * - * @return whether this list is empty - */ - public boolean isEmpty() { - return list.isEmpty(); - } + /** + * Returns whether this list is empty. + * + * @return whether this list is empty + */ + public boolean isEmpty() { + return list.isEmpty(); + } - // MUTATORS + // MUTATORS - /** - * Add the given tag. - * - * @param value the tag - */ - public void add(NBTTag value) { - if (this.type == null) - this.type = value.getType(); - else if (this.type != value.getType()) - throw new IllegalArgumentException(value.getType() + " is not of expected type " + type); - list.add(value); - } + /** + * Add the given tag. + * + * @param value the tag + */ + public void add(NBTTag value) { + if (this.type == null) + this.type = value.getType(); + else if (this.type != value.getType()) + throw new IllegalArgumentException(value.getType() + " is not of expected type " + type); + list.add(value); + } - /** - * Add the given tag at the given index in the list. - * - * @param value the tag - */ - public void add(int index, NBTTag value) { - if (index < 0 || index >= list.size()) - throw new IndexOutOfBoundsException(Integer.toString(index)); - if (this.type == null) - this.type = value.getType(); - else if (this.type != value.getType()) - throw new IllegalArgumentException(value.getType() + " is not of expected type " + type); - list.add(index, value); - } + /** + * Add the given tag at the given index in the list. + * + * @param value the tag + */ + public void add(int index, NBTTag value) { + if (index < 0 || index >= list.size()) + throw new IndexOutOfBoundsException(Integer.toString(index)); + if (this.type == null) + this.type = value.getType(); + else if (this.type != value.getType()) + throw new IllegalArgumentException(value.getType() + " is not of expected type " + type); + list.add(index, value); + } - /** - * Add all the tags in the given list. - * - * @param values a list of tags - */ - public void addAll(Collection values) { - for (NBTTag entry : values) { - this.add(entry); - } - } + /** + * Add all the tags in the given list. + * + * @param values a list of tags + */ + public void addAll(Collection values) { + for (NBTTag entry : values) { + this.add(entry); + } + } - // MISC + // MISC - @Override - public boolean equals(Object obj) { - return obj instanceof NBTList && equals((NBTList) obj); - } + @Override + public boolean equals(Object obj) { + return obj instanceof NBTList && equals((NBTList) obj); + } - public boolean equals(NBTList tag) { - return this.isEmpty() && tag.isEmpty() - || this.type == tag.type && this.list.equals(tag.list); - } + public boolean equals(NBTList tag) { + return this.isEmpty() && tag.isEmpty() + || this.type == tag.type && this.list.equals(tag.list); + } - @Override - public Iterator iterator() { - return list.iterator(); - } + @Override + public Iterator iterator() { + return list.iterator(); + } - @Override - public String toMSONString() { - StringBuilder builder = new StringBuilder("["); - Iterator iter = iterator(); + @Override + public String toMSONString() { + StringBuilder builder = new StringBuilder("["); + Iterator iter = iterator(); - boolean first = true; - while (iter.hasNext()) { - if (first) first = false; - else builder.append(','); - builder.append(iter.next().toMSONString()); - } + boolean first = true; + while (iter.hasNext()) { + if (first) first = false; + else builder.append(','); + builder.append(iter.next().toMSONString()); + } - return builder.append("]").toString(); - } + return builder.append("]").toString(); + } - @Override - public NBTList clone() { - return new NBTList(type, list); - } + @Override + public NBTList clone() { + return new NBTList(type, list); + } } diff --git a/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTLong.java b/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTLong.java index 35bc6d9b..054de4b9 100644 --- a/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTLong.java +++ b/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTLong.java @@ -5,54 +5,54 @@ package me.filoghost.holographicdisplays.util.nbt; */ public final class NBTLong extends NBTTag implements Cloneable { - private long value; + private long value; - public NBTLong(long value) { - this.value = value; - } + public NBTLong(long value) { + this.value = value; + } - @Override - public Long getValue() { - return value; - } + @Override + public Long getValue() { + return value; + } - public long getLongValue() { - return value; - } + public long getLongValue() { + return value; + } - public void setLongValue(long value) { - this.value = value; - } + public void setLongValue(long value) { + this.value = value; + } - @Override - public NBTType getType() { - return NBTType.LONG; - } + @Override + public NBTType getType() { + return NBTType.LONG; + } - // MISC + // MISC - @Override - public boolean equals(Object obj) { - return obj instanceof NBTLong && equals((NBTLong) obj); - } + @Override + public boolean equals(Object obj) { + return obj instanceof NBTLong && equals((NBTLong) obj); + } - public boolean equals(NBTLong tag) { - return this.value == tag.value; - } + public boolean equals(NBTLong tag) { + return this.value == tag.value; + } - @Override - public int hashCode() { - return Long.hashCode(value); - } + @Override + public int hashCode() { + return Long.hashCode(value); + } - @Override - public String toMSONString() { - return value + "L"; - } + @Override + public String toMSONString() { + return value + "L"; + } - @Override - public NBTLong clone() { - return new NBTLong(value); - } + @Override + public NBTLong clone() { + return new NBTLong(value); + } } diff --git a/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTLongArray.java b/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTLongArray.java index 153481f0..48bffa75 100644 --- a/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTLongArray.java +++ b/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTLongArray.java @@ -7,63 +7,63 @@ import java.util.Arrays; */ public final class NBTLongArray extends NBTTag { - private final long[] value; + private final long[] value; - /** - * Creates the tag with an empty name. - * - * @param value the value of the tag - */ - public NBTLongArray(long... value) { - this.value = value; - } + /** + * Creates the tag with an empty name. + * + * @param value the value of the tag + */ + public NBTLongArray(long... value) { + this.value = value; + } - public NBTLongArray(Number[] numbers) { - this.value = new long[numbers.length]; - for (int i = 0; i < numbers.length; i++) - value[i] = numbers[i].longValue(); - } + public NBTLongArray(Number[] numbers) { + this.value = new long[numbers.length]; + for (int i = 0; i < numbers.length; i++) + value[i] = numbers[i].longValue(); + } - /** - * Returns the length of this array. - * - * @return the length of this array - */ - public int length() { - return value.length; - } + /** + * Returns the length of this array. + * + * @return the length of this array + */ + public int length() { + return value.length; + } - @Override - public long[] getValue() { - return value; - } + @Override + public long[] getValue() { + return value; + } - @Override - public NBTType getType() { - return NBTType.LONG_ARRAY; - } + @Override + public NBTType getType() { + return NBTType.LONG_ARRAY; + } - // MISC + // MISC - @Override - public boolean equals(Object obj) { - return obj instanceof NBTLongArray && equals((NBTLongArray) obj); - } + @Override + public boolean equals(Object obj) { + return obj instanceof NBTLongArray && equals((NBTLongArray) obj); + } - public boolean equals(NBTLongArray tag) { - return Arrays.equals(this.value, tag.value); - } + public boolean equals(NBTLongArray tag) { + return Arrays.equals(this.value, tag.value); + } - @Override - public String toMSONString() { - StringBuilder stringbuilder = new StringBuilder("[I;"); - for (int i = 0; i < this.value.length; i++) { - if (i != 0) { - stringbuilder.append(','); - } - stringbuilder.append(this.value[i]); - } - return stringbuilder.append(']').toString(); - } + @Override + public String toMSONString() { + StringBuilder stringbuilder = new StringBuilder("[I;"); + for (int i = 0; i < this.value.length; i++) { + if (i != 0) { + stringbuilder.append(','); + } + stringbuilder.append(this.value[i]); + } + return stringbuilder.append(']').toString(); + } } diff --git a/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTShort.java b/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTShort.java index 607c3a70..8bff3620 100644 --- a/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTShort.java +++ b/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTShort.java @@ -5,54 +5,54 @@ package me.filoghost.holographicdisplays.util.nbt; */ public final class NBTShort extends NBTTag implements Cloneable { - private short value; + private short value; - public NBTShort(short value) { - this.value = value; - } + public NBTShort(short value) { + this.value = value; + } - @Override - public Short getValue() { - return value; - } + @Override + public Short getValue() { + return value; + } - public short getShortValue() { - return value; - } + public short getShortValue() { + return value; + } - public void setShortValue(short value) { - this.value = value; - } + public void setShortValue(short value) { + this.value = value; + } - @Override - public NBTType getType() { - return NBTType.SHORT; - } + @Override + public NBTType getType() { + return NBTType.SHORT; + } - // MISC + // MISC - @Override - public boolean equals(Object obj) { - return obj instanceof NBTShort && equals((NBTShort) obj); - } + @Override + public boolean equals(Object obj) { + return obj instanceof NBTShort && equals((NBTShort) obj); + } - public boolean equals(NBTShort tag) { - return this.value == tag.value; - } + public boolean equals(NBTShort tag) { + return this.value == tag.value; + } - @Override - public int hashCode() { - return Short.hashCode(value); - } + @Override + public int hashCode() { + return Short.hashCode(value); + } - @Override - public String toMSONString() { - return value + "s"; - } + @Override + public String toMSONString() { + return value + "s"; + } - @Override - public NBTShort clone() { - return new NBTShort(value); - } + @Override + public NBTShort clone() { + return new NBTShort(value); + } } diff --git a/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTString.java b/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTString.java index bf16666e..d73c2313 100644 --- a/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTString.java +++ b/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTString.java @@ -5,62 +5,62 @@ package me.filoghost.holographicdisplays.util.nbt; */ public final class NBTString extends NBTTag implements Cloneable { - private String value; + private String value; - public NBTString(String value) { - setValue(value); - } + public NBTString(String value) { + setValue(value); + } - @Override - public String getValue() { - return value; - } + @Override + public String getValue() { + return value; + } - public void setValue(String value) { - this.value = value; - } + public void setValue(String value) { + this.value = value; + } - @Override - public NBTType getType() { - return NBTType.STRING; - } + @Override + public NBTType getType() { + return NBTType.STRING; + } - // MISC + // MISC - @Override - public int hashCode() { - return value.hashCode(); - } + @Override + public int hashCode() { + return value.hashCode(); + } - @Override - public String toMSONString() { - return toMSONString(value); - } + @Override + public String toMSONString() { + return toMSONString(value); + } - @Override - public NBTString clone() { - return new NBTString(value); - } + @Override + public NBTString clone() { + return new NBTString(value); + } - // UTIL + // UTIL - /** - * Converts a regular string into a Mojangson string by surrounding it with quotes and escaping backslashes and - * quotes inside it. - * - * @param str the string - * @return the Mojangson string - */ - public static String toMSONString(String str) { - StringBuilder builder = new StringBuilder("\""); - char[] chars = str.toCharArray(); - for (char c : chars) { - if ((c == '\\') || (c == '"')) { - builder.append('\\'); - } - builder.append(c); - } - return builder.append('\"').toString(); - } + /** + * Converts a regular string into a Mojangson string by surrounding it with quotes and escaping backslashes and + * quotes inside it. + * + * @param str the string + * @return the Mojangson string + */ + public static String toMSONString(String str) { + StringBuilder builder = new StringBuilder("\""); + char[] chars = str.toCharArray(); + for (char c : chars) { + if ((c == '\\') || (c == '"')) { + builder.append('\\'); + } + builder.append(c); + } + return builder.append('\"').toString(); + } } diff --git a/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTTag.java b/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTTag.java index 4978399e..1d5bef12 100644 --- a/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTTag.java +++ b/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTTag.java @@ -5,56 +5,56 @@ package me.filoghost.holographicdisplays.util.nbt; */ public abstract class NBTTag { - /** - * Gets the value of this tag. - * - * @return the value of this tag - */ - public abstract Object getValue(); + /** + * Gets the value of this tag. + * + * @return the value of this tag + */ + public abstract Object getValue(); - /** - * Returns the type of this tag. - * - * @return the type of this tag - */ - public abstract NBTType getType(); + /** + * Returns the type of this tag. + * + * @return the type of this tag + */ + public abstract NBTType getType(); - /** - * Convenience method for getting the id of this tag's type. - * - * @return the type id - */ - public byte getTypeId() { - return getType().getId(); - } + /** + * Convenience method for getting the id of this tag's type. + * + * @return the type id + */ + public byte getTypeId() { + return getType().getId(); + } - /** - * Returns a Mojangson string depicting this NBT tag. - * - * @return a Mojangson string depicting this NBT tag - */ - public abstract String toMSONString(); + /** + * Returns a Mojangson string depicting this NBT tag. + * + * @return a Mojangson string depicting this NBT tag + */ + public abstract String toMSONString(); - // MISC + // MISC - @Override - public boolean equals(Object obj) { - if (obj instanceof NBTTag) { - NBTTag tag = (NBTTag) obj; - return this.getType() == tag.getType() - && this.getValue().equals(tag.getValue()); - } - return false; - } + @Override + public boolean equals(Object obj) { + if (obj instanceof NBTTag) { + NBTTag tag = (NBTTag) obj; + return this.getType() == tag.getType() + && this.getValue().equals(tag.getValue()); + } + return false; + } - @Override - public int hashCode() { - return getValue().hashCode(); - } + @Override + public int hashCode() { + return getValue().hashCode(); + } - @Override - public String toString() { - return toMSONString(); - } + @Override + public String toString() { + return toMSONString(); + } } diff --git a/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTType.java b/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTType.java index 43961f20..6618d2f8 100644 --- a/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTType.java +++ b/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/NBTType.java @@ -14,179 +14,179 @@ package me.filoghost.holographicdisplays.util.nbt; *

*/ public enum NBTType { - /** - * Used to mark the end of compounds tags. May also be the type of empty list tags. - * - * @since NBT Version 19132 - */ - END("TAG_End", false, false, false), + /** + * Used to mark the end of compounds tags. May also be the type of empty list tags. + * + * @since NBT Version 19132 + */ + END("TAG_End", false, false, false), - /** - * A signed integer (8 bits). Sometimes used for booleans. (-128 to 127) - * - * @since NBT Version 19132 - */ - BYTE("TAG_Byte", true, true, false), + /** + * A signed integer (8 bits). Sometimes used for booleans. (-128 to 127) + * + * @since NBT Version 19132 + */ + BYTE("TAG_Byte", true, true, false), - /** - * A signed integer (16 bits). (-215 to 215-1) - * - * @since NBT Version 19132 - */ - SHORT("TAG_Short", true, true, false), + /** + * A signed integer (16 bits). (-215 to 215-1) + * + * @since NBT Version 19132 + */ + SHORT("TAG_Short", true, true, false), - /** - * A signed integer (32 bits). (-231 to 231-1) - * - * @since NBT Version 19132 - */ - INT("TAG_Int", true, true, false), + /** + * A signed integer (32 bits). (-231 to 231-1) + * + * @since NBT Version 19132 + */ + INT("TAG_Int", true, true, false), - /** - * A signed integer (64 bits). (-263 to 263-1) - * - * @since NBT Version 19132 - */ - LONG("TAG_Long", true, true, false), + /** + * A signed integer (64 bits). (-263 to 263-1) + * + * @since NBT Version 19132 + */ + LONG("TAG_Long", true, true, false), - /** - * A signed (IEEE 754-2008) floating point number (32 bits). - * - * @since NBT Version 19132 - */ - FLOAT("TAG_Float", true, true, false), + /** + * A signed (IEEE 754-2008) floating point number (32 bits). + * + * @since NBT Version 19132 + */ + FLOAT("TAG_Float", true, true, false), - /** - * A signed (IEEE 754-2008) floating point number (64 bits). - * - * @since NBT Version 19132 - */ - DOUBLE("TAG_Double", true, true, false), + /** + * A signed (IEEE 754-2008) floating point number (64 bits). + * + * @since NBT Version 19132 + */ + DOUBLE("TAG_Double", true, true, false), - /** - * An array of {@link #BYTE} with maximum length of {@link Integer#MAX_VALUE}. - * - * @since NBT Version 19132 - */ - BYTE_ARRAY("TAG_Byte_Array", false, false, true), + /** + * An array of {@link #BYTE} with maximum length of {@link Integer#MAX_VALUE}. + * + * @since NBT Version 19132 + */ + BYTE_ARRAY("TAG_Byte_Array", false, false, true), - /** - * UTF-8 encoded string. - * - * @since NBT Version 19132 - */ - STRING("TAG_String", true, false, false), + /** + * UTF-8 encoded string. + * + * @since NBT Version 19132 + */ + STRING("TAG_String", true, false, false), - /** - * A list of unnamed tags of equal type. - * - * @since NBT Version 19132 - */ - LIST("TAG_List", false, false, false), + /** + * A list of unnamed tags of equal type. + * + * @since NBT Version 19132 + */ + LIST("TAG_List", false, false, false), - /** - * Compound of named tags followed by {@link #END}. - * - * @since NBT Version 19132 - */ - COMPOUND("TAG_Compound", false, false, false), + /** + * Compound of named tags followed by {@link #END}. + * + * @since NBT Version 19132 + */ + COMPOUND("TAG_Compound", false, false, false), - /** - * An array of {@link #BYTE} with maximum length of {@link Integer#MAX_VALUE}. - * - * @since NBT Version 19132 - */ - INT_ARRAY("TAG_Int_Array", false, false, true), + /** + * An array of {@link #BYTE} with maximum length of {@link Integer#MAX_VALUE}. + * + * @since NBT Version 19132 + */ + INT_ARRAY("TAG_Int_Array", false, false, true), - /** - * An array of {@link #LONG} with maximum length of {@link Integer#MAX_VALUE}. - * - * @since NBT Version 19133 - */ - LONG_ARRAY("TAG_Long_Array", false, false, true); + /** + * An array of {@link #LONG} with maximum length of {@link Integer#MAX_VALUE}. + * + * @since NBT Version 19133 + */ + LONG_ARRAY("TAG_Long_Array", false, false, true); - private final String name; - private final boolean numeric, primitive, array; - private final byte id; + private final String name; + private final boolean numeric, primitive, array; + private final byte id; - NBTType(String name, boolean primitive, boolean numeric, boolean array) { - this.name = name; - this.id = (byte) ordinal(); - this.numeric = numeric; - this.primitive = primitive; - this.array = array; - } + NBTType(String name, boolean primitive, boolean numeric, boolean array) { + this.name = name; + this.id = (byte) ordinal(); + this.numeric = numeric; + this.primitive = primitive; + this.array = array; + } - /** - * Returns the type with the given id. - * - * @param id the id - * @return the type - */ - public static NBTType getById(byte id) { - return values()[id]; - } + /** + * Returns the type with the given id. + * + * @param id the id + * @return the type + */ + public static NBTType getById(byte id) { + return values()[id]; + } - /** - *

- * Returns the id of this tag type. - *

- *

- * Although this method is currently equivalent to {@link #ordinal()}, it should always be used in its stead, - * since it is not guaranteed that this behavior will remain consistent. - *

- * - * @return the id - */ - public byte getId() { - return id; - } + /** + *

+ * Returns the id of this tag type. + *

+ *

+ * Although this method is currently equivalent to {@link #ordinal()}, it should always be used in its stead, + * since it is not guaranteed that this behavior will remain consistent. + *

+ * + * @return the id + */ + public byte getId() { + return id; + } - /** - * Returns the name of this type. - * - * @return the name - */ - public String getName() { - return name; - } + /** + * Returns the name of this type. + * + * @return the name + */ + public String getName() { + return name; + } - /** - *

- * Returns whether this tag type is numeric. - *

- *

- * All tag types with payloads that are representable as a {@link Number} are compliant with this definition. - *

- * - * @return whether this type is numeric - */ - public boolean isNumeric() { - return numeric; - } + /** + *

+ * Returns whether this tag type is numeric. + *

+ *

+ * All tag types with payloads that are representable as a {@link Number} are compliant with this definition. + *

+ * + * @return whether this type is numeric + */ + public boolean isNumeric() { + return numeric; + } - /** - * Returns whether this tag type is primitive, meaning that it is not a {@link NBTByteArray}, {@link NBTIntArray}, - * {@link NBTList}, {@link NBTCompound} or {@link NBTEnd}. - * - * @return whether this type is numeric - */ - public boolean isPrimitive() { - return primitive; - } + /** + * Returns whether this tag type is primitive, meaning that it is not a {@link NBTByteArray}, {@link NBTIntArray}, + * {@link NBTList}, {@link NBTCompound} or {@link NBTEnd}. + * + * @return whether this type is numeric + */ + public boolean isPrimitive() { + return primitive; + } - /** - * Returns whether this tag type is is an array type such as {@link NBTByteArray} or {@link NBTIntArray}. - * - * @return whether this type is an array type - */ - public boolean isArray() { - return array; - } + /** + * Returns whether this tag type is is an array type such as {@link NBTByteArray} or {@link NBTIntArray}. + * + * @return whether this type is an array type + */ + public boolean isArray() { + return array; + } - @Override - public String toString() { - return getName(); - } + @Override + public String toString() { + return getName(); + } } diff --git a/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/parser/MojangsonParseException.java b/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/parser/MojangsonParseException.java index 2da9bc7e..51af4faf 100644 --- a/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/parser/MojangsonParseException.java +++ b/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/parser/MojangsonParseException.java @@ -6,22 +6,22 @@ import java.io.IOException; public class MojangsonParseException extends IOException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - public MojangsonParseException(String msg, String content, int index) { - super(msg + " at character " + index + ": " + printErrorLoc(content, index)); - } + public MojangsonParseException(String msg, String content, int index) { + super(msg + " at character " + index + ": " + printErrorLoc(content, index)); + } - private static String printErrorLoc(String content, int index) { - StringBuilder builder = new StringBuilder(); - int i = Math.min(content.length(), index); - if (i > 35) { - builder.append("..."); - } - builder.append(content.substring(Math.max(0, i - 35), i)); - builder.append(ChatColor.GOLD + "<--[HERE]"); + private static String printErrorLoc(String content, int index) { + StringBuilder builder = new StringBuilder(); + int i = Math.min(content.length(), index); + if (i > 35) { + builder.append("..."); + } + builder.append(content.substring(Math.max(0, i - 35), i)); + builder.append(ChatColor.GOLD + "<--[HERE]"); - return builder.toString(); - } + return builder.toString(); + } } diff --git a/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/parser/MojangsonParser.java b/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/parser/MojangsonParser.java index 17f1cf25..81653720 100644 --- a/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/parser/MojangsonParser.java +++ b/utils/src/main/java/me/filoghost/holographicdisplays/util/nbt/parser/MojangsonParser.java @@ -21,355 +21,355 @@ import java.util.regex.Pattern; public final class MojangsonParser { - private static final Pattern - DOUBLE_NS = Pattern.compile("[-+]?(?:[0-9]+[.]|[0-9]*[.][0-9]+)(?:e[-+]?[0-9]+)?", Pattern.CASE_INSENSITIVE), - DOUBLE_S = Pattern.compile("[-+]?(?:[0-9]+[.]?|[0-9]*[.][0-9]+)(?:e[-+]?[0-9]+)?d", Pattern.CASE_INSENSITIVE), - FLOAT = Pattern.compile("[-+]?(?:[0-9]+[.]?|[0-9]*[.][0-9]+)(?:e[-+]?[0-9]+)?f", Pattern.CASE_INSENSITIVE), - BYTE = Pattern.compile("[-+]?(?:0|[1-9][0-9]*)b", Pattern.CASE_INSENSITIVE), - LONG = Pattern.compile("[-+]?(?:0|[1-9][0-9]*)l", Pattern.CASE_INSENSITIVE), - SHORT = Pattern.compile("[-+]?(?:0|[1-9][0-9]*)s", Pattern.CASE_INSENSITIVE), - INT = Pattern.compile("[-+]?(?:0|[1-9][0-9]*)"); + private static final Pattern + DOUBLE_NS = Pattern.compile("[-+]?(?:[0-9]+[.]|[0-9]*[.][0-9]+)(?:e[-+]?[0-9]+)?", Pattern.CASE_INSENSITIVE), + DOUBLE_S = Pattern.compile("[-+]?(?:[0-9]+[.]?|[0-9]*[.][0-9]+)(?:e[-+]?[0-9]+)?d", Pattern.CASE_INSENSITIVE), + FLOAT = Pattern.compile("[-+]?(?:[0-9]+[.]?|[0-9]*[.][0-9]+)(?:e[-+]?[0-9]+)?f", Pattern.CASE_INSENSITIVE), + BYTE = Pattern.compile("[-+]?(?:0|[1-9][0-9]*)b", Pattern.CASE_INSENSITIVE), + LONG = Pattern.compile("[-+]?(?:0|[1-9][0-9]*)l", Pattern.CASE_INSENSITIVE), + SHORT = Pattern.compile("[-+]?(?:0|[1-9][0-9]*)s", Pattern.CASE_INSENSITIVE), + INT = Pattern.compile("[-+]?(?:0|[1-9][0-9]*)"); - private final String str; - private int index; + private final String str; + private int index; - public static NBTCompound parse(String mson) throws MojangsonParseException { - return new MojangsonParser(mson).parseRootCompound(); - } + public static NBTCompound parse(String mson) throws MojangsonParseException { + return new MojangsonParser(mson).parseRootCompound(); + } - private MojangsonParser(String str) { - this.str = str; - } + private MojangsonParser(String str) { + this.str = str; + } - // PARSE + // PARSE - private NBTCompound parseRootCompound() throws MojangsonParseException { - skipWhitespace(); - NBTCompound result = parseCompound(); - expectNoTrail(); - return result; - } + private NBTCompound parseRootCompound() throws MojangsonParseException { + skipWhitespace(); + NBTCompound result = parseCompound(); + expectNoTrail(); + return result; + } - private String parseCompoundKey() throws MojangsonParseException { - skipWhitespace(); - if (!hasNext()) { - throw parseException("Expected key"); - } - return currentChar() == '"' ? parseQuotedString() : parseSimpleString(); - } + private String parseCompoundKey() throws MojangsonParseException { + skipWhitespace(); + if (!hasNext()) { + throw parseException("Expected key"); + } + return currentChar() == '"' ? parseQuotedString() : parseSimpleString(); + } - private NBTTag parseStringOrLiteral() throws MojangsonParseException { - skipWhitespace(); - if (currentChar() == '"') - return new NBTString(parseQuotedString()); - String str = parseSimpleString(); - if (str.isEmpty()) - throw parseException("Expected value"); - return parseLiteral(str); - } + private NBTTag parseStringOrLiteral() throws MojangsonParseException { + skipWhitespace(); + if (currentChar() == '"') + return new NBTString(parseQuotedString()); + String str = parseSimpleString(); + if (str.isEmpty()) + throw parseException("Expected value"); + return parseLiteral(str); + } - private NBTTag parseLiteral(String str) { - try { - if (FLOAT.matcher(str).matches()) { - return new NBTFloat(Float.parseFloat(str.substring(0, str.length() - 1))); - } - if (BYTE.matcher(str).matches()) { - return new NBTByte(Byte.parseByte(str.substring(0, str.length() - 1))); - } - if (LONG.matcher(str).matches()) { - return new NBTLong(Long.parseLong(str.substring(0, str.length() - 1))); - } - if (SHORT.matcher(str).matches()) { - return new NBTShort(Short.parseShort(str.substring(0, str.length() - 1))); - } - if (INT.matcher(str).matches()) { - return new NBTInt(Integer.parseInt(str)); - } - if (DOUBLE_S.matcher(str).matches()) { - return new NBTDouble(Double.parseDouble(str.substring(0, str.length() - 1))); - } - if (DOUBLE_NS.matcher(str).matches()) { - return new NBTDouble(Double.parseDouble(str)); - } - if ("true".equalsIgnoreCase(str)) { - return new NBTByte((byte) 1); - } - if ("false".equalsIgnoreCase(str)) { - return new NBTByte((byte) 0); - } - } catch (NumberFormatException ex) { - return new NBTString(str); - } - return new NBTString(str); - } + private NBTTag parseLiteral(String str) { + try { + if (FLOAT.matcher(str).matches()) { + return new NBTFloat(Float.parseFloat(str.substring(0, str.length() - 1))); + } + if (BYTE.matcher(str).matches()) { + return new NBTByte(Byte.parseByte(str.substring(0, str.length() - 1))); + } + if (LONG.matcher(str).matches()) { + return new NBTLong(Long.parseLong(str.substring(0, str.length() - 1))); + } + if (SHORT.matcher(str).matches()) { + return new NBTShort(Short.parseShort(str.substring(0, str.length() - 1))); + } + if (INT.matcher(str).matches()) { + return new NBTInt(Integer.parseInt(str)); + } + if (DOUBLE_S.matcher(str).matches()) { + return new NBTDouble(Double.parseDouble(str.substring(0, str.length() - 1))); + } + if (DOUBLE_NS.matcher(str).matches()) { + return new NBTDouble(Double.parseDouble(str)); + } + if ("true".equalsIgnoreCase(str)) { + return new NBTByte((byte) 1); + } + if ("false".equalsIgnoreCase(str)) { + return new NBTByte((byte) 0); + } + } catch (NumberFormatException ex) { + return new NBTString(str); + } + return new NBTString(str); + } - private String parseQuotedString() throws MojangsonParseException { - int j = ++this.index; - StringBuilder builder = null; - boolean escape = false; + private String parseQuotedString() throws MojangsonParseException { + int j = ++this.index; + StringBuilder builder = null; + boolean escape = false; - while (hasNext()) { - char c = nextChar(); - if (escape) { - if ((c != '\\') && (c != '"')) { - throw parseException("Invalid escape of '" + c + "'"); - } - escape = false; - } else { - if (c == '\\') { - escape = true; - if (builder != null) { - continue; - } - builder = new StringBuilder(this.str.substring(j, this.index - 1)); - continue; - } - if (c == '"') { - return builder == null ? this.str.substring(j, this.index - 1) : builder.toString(); - } - } - if (builder != null) { - builder.append(c); - } - } - throw parseException("Missing termination quote"); - } + while (hasNext()) { + char c = nextChar(); + if (escape) { + if ((c != '\\') && (c != '"')) { + throw parseException("Invalid escape of '" + c + "'"); + } + escape = false; + } else { + if (c == '\\') { + escape = true; + if (builder != null) { + continue; + } + builder = new StringBuilder(this.str.substring(j, this.index - 1)); + continue; + } + if (c == '"') { + return builder == null ? this.str.substring(j, this.index - 1) : builder.toString(); + } + } + if (builder != null) { + builder.append(c); + } + } + throw parseException("Missing termination quote"); + } - private String parseSimpleString() { - int j = this.index; - while (hasNext() && isSimpleChar(currentChar())) { - this.index += 1; - } - return this.str.substring(j, this.index); - } + private String parseSimpleString() { + int j = this.index; + while (hasNext() && isSimpleChar(currentChar())) { + this.index += 1; + } + return this.str.substring(j, this.index); + } - private NBTTag parseAnything() throws MojangsonParseException { - skipWhitespace(); - if (!hasNext()) - throw parseException("Expected value"); + private NBTTag parseAnything() throws MojangsonParseException { + skipWhitespace(); + if (!hasNext()) + throw parseException("Expected value"); - int c = currentChar(); - if (c == '{') - return parseCompound(); - else if (c == '[') - return parseDetectedArray(); - else - return parseStringOrLiteral(); - } + int c = currentChar(); + if (c == '{') + return parseCompound(); + else if (c == '[') + return parseDetectedArray(); + else + return parseStringOrLiteral(); + } - private NBTTag parseDetectedArray() throws MojangsonParseException { - if (hasCharsLeft(2) && getChar(1) != '"' && getChar(2) == ';') { - return parseNumArray(); - } - return parseList(); - } + private NBTTag parseDetectedArray() throws MojangsonParseException { + if (hasCharsLeft(2) && getChar(1) != '"' && getChar(2) == ';') { + return parseNumArray(); + } + return parseList(); + } - private NBTCompound parseCompound() throws MojangsonParseException { - expectChar('{'); + private NBTCompound parseCompound() throws MojangsonParseException { + expectChar('{'); - NBTCompound compound = new NBTCompound(); + NBTCompound compound = new NBTCompound(); - skipWhitespace(); - while ((hasNext()) && (currentChar() != '}')) { - String str = parseCompoundKey(); - if (str.isEmpty()) { - throw parseException("Expected non-empty key"); - } - expectChar(':'); + skipWhitespace(); + while ((hasNext()) && (currentChar() != '}')) { + String str = parseCompoundKey(); + if (str.isEmpty()) { + throw parseException("Expected non-empty key"); + } + expectChar(':'); - compound.put(str, parseAnything()); - if (!advanceToNextArrayElement()) { - break; - } - if (!hasNext()) { - throw parseException("Expected key"); - } - } - expectChar('}'); + compound.put(str, parseAnything()); + if (!advanceToNextArrayElement()) { + break; + } + if (!hasNext()) { + throw parseException("Expected key"); + } + } + expectChar('}'); - return compound; - } + return compound; + } - private NBTList parseList() throws MojangsonParseException { - expectChar('['); + private NBTList parseList() throws MojangsonParseException { + expectChar('['); - skipWhitespace(); - if (!hasNext()) { - throw parseException("Expected value"); - } - NBTList list = new NBTList(); - NBTType listType = null; + skipWhitespace(); + if (!hasNext()) { + throw parseException("Expected value"); + } + NBTList list = new NBTList(); + NBTType listType = null; - while (currentChar() != ']') { - NBTTag element = parseAnything(); - NBTType elementType = element.getType(); + while (currentChar() != ']') { + NBTTag element = parseAnything(); + NBTType elementType = element.getType(); - if (listType == null) { - listType = elementType; - } else if (elementType != listType) { - throw parseException("Unable to insert " + elementType + " into ListTag of type " + listType); - } - list.add(element); - if (!advanceToNextArrayElement()) { - break; - } - if (!hasNext()) { - throw parseException("Expected value"); - } - } - expectChar(']'); + if (listType == null) { + listType = elementType; + } else if (elementType != listType) { + throw parseException("Unable to insert " + elementType + " into ListTag of type " + listType); + } + list.add(element); + if (!advanceToNextArrayElement()) { + break; + } + if (!hasNext()) { + throw parseException("Expected value"); + } + } + expectChar(']'); - return list; - } + return list; + } - private NBTTag parseNumArray() throws MojangsonParseException { - expectChar('['); - char arrayType = nextChar(); - expectChar(';'); - //nextChar(); semicolon ignored by Mojang + private NBTTag parseNumArray() throws MojangsonParseException { + expectChar('['); + char arrayType = nextChar(); + expectChar(';'); + //nextChar(); semicolon ignored by Mojang - skipWhitespace(); - if (!hasNext()) { - throw parseException("Expected value"); - } - if (arrayType == 'B') - return new NBTByteArray(parseNumArray(NBTType.BYTE_ARRAY, NBTType.BYTE)); - else if (arrayType == 'L') - return new NBTLongArray(parseNumArray(NBTType.LONG_ARRAY, NBTType.LONG)); - else if (arrayType == 'I') - return new NBTIntArray(parseNumArray(NBTType.INT_ARRAY, NBTType.INT)); - throw parseException("Invalid array type '" + arrayType + "' found"); - } + skipWhitespace(); + if (!hasNext()) { + throw parseException("Expected value"); + } + if (arrayType == 'B') + return new NBTByteArray(parseNumArray(NBTType.BYTE_ARRAY, NBTType.BYTE)); + else if (arrayType == 'L') + return new NBTLongArray(parseNumArray(NBTType.LONG_ARRAY, NBTType.LONG)); + else if (arrayType == 'I') + return new NBTIntArray(parseNumArray(NBTType.INT_ARRAY, NBTType.INT)); + throw parseException("Invalid array type '" + arrayType + "' found"); + } - private Number[] parseNumArray(NBTType arrayType, NBTType primType) throws MojangsonParseException { - List result = new ArrayList(); - while (currentChar() != ']') { - NBTTag element = parseAnything(); - NBTType elementType = element.getType(); + private Number[] parseNumArray(NBTType arrayType, NBTType primType) throws MojangsonParseException { + List result = new ArrayList(); + while (currentChar() != ']') { + NBTTag element = parseAnything(); + NBTType elementType = element.getType(); - if (elementType != primType) { - throw parseException("Unable to insert " + elementType + " into " + arrayType); - } - if (primType == NBTType.BYTE) { - result.add(((NBTByte) element).getValue()); - } else if (primType == NBTType.LONG) { - result.add(((NBTLong) element).getValue()); - } else { - result.add(((NBTInt) element).getValue()); - } - if (!advanceToNextArrayElement()) { - break; - } - if (!hasNext()) { - throw parseException("Expected value"); - } - } - expectChar(']'); + if (elementType != primType) { + throw parseException("Unable to insert " + elementType + " into " + arrayType); + } + if (primType == NBTType.BYTE) { + result.add(((NBTByte) element).getValue()); + } else if (primType == NBTType.LONG) { + result.add(((NBTLong) element).getValue()); + } else { + result.add(((NBTInt) element).getValue()); + } + if (!advanceToNextArrayElement()) { + break; + } + if (!hasNext()) { + throw parseException("Expected value"); + } + } + expectChar(']'); - return result.toArray(new Number[result.size()]); - } + return result.toArray(new Number[result.size()]); + } - // CHARACTER NAVIGATION + // CHARACTER NAVIGATION - private boolean advanceToNextArrayElement() { - skipWhitespace(); - if (hasNext() && currentChar() == ',') { - this.index += 1; - skipWhitespace(); - return true; - } - return false; - } + private boolean advanceToNextArrayElement() { + skipWhitespace(); + if (hasNext() && currentChar() == ',') { + this.index += 1; + skipWhitespace(); + return true; + } + return false; + } - private void skipWhitespace() { - while (hasNext() && Character.isWhitespace(currentChar())) { - this.index += 1; - } - } + private void skipWhitespace() { + while (hasNext() && Character.isWhitespace(currentChar())) { + this.index += 1; + } + } - private boolean hasCharsLeft(int paramInt) { - return this.index + paramInt < this.str.length(); - } + private boolean hasCharsLeft(int paramInt) { + return this.index + paramInt < this.str.length(); + } - private boolean hasNext() { - return hasCharsLeft(0); - } + private boolean hasNext() { + return hasCharsLeft(0); + } - /** - * Returns the character in the string at the current index plus a given offset. - * - * @param offset the offset - * @return the character at the offset - */ - private char getChar(int offset) { - return this.str.charAt(this.index + offset); - } + /** + * Returns the character in the string at the current index plus a given offset. + * + * @param offset the offset + * @return the character at the offset + */ + private char getChar(int offset) { + return this.str.charAt(this.index + offset); + } - /** - * Returns the current character. - * - * @return the current character - */ - private char currentChar() { - return getChar(0); - } + /** + * Returns the current character. + * + * @return the current character + */ + private char currentChar() { + return getChar(0); + } - /** - * Returns the current character and increments the index. - * - * @return the current character - */ - private char nextChar() { - return this.str.charAt(this.index++); - } + /** + * Returns the current character and increments the index. + * + * @return the current character + */ + private char nextChar() { + return this.str.charAt(this.index++); + } - // UTIL + // UTIL - /** - * Verifies whether the current character is of given value and whether the parser can advance. If these conditions - * are met, the parser advances by one. If these conditions are not met, an exception is thrown. - * - * @param c the expected character - * @throws MojangsonParseException if {@link #currentChar()} does not equal {@code c} or if {@link #hasNext()} - * returns false - */ - private void expectChar(char c) throws MojangsonParseException { - skipWhitespace(); + /** + * Verifies whether the current character is of given value and whether the parser can advance. If these conditions + * are met, the parser advances by one. If these conditions are not met, an exception is thrown. + * + * @param c the expected character + * @throws MojangsonParseException if {@link #currentChar()} does not equal {@code c} or if {@link #hasNext()} + * returns false + */ + private void expectChar(char c) throws MojangsonParseException { + skipWhitespace(); - boolean hasNext = hasNext(); - if (hasNext && currentChar() == c) { - this.index += 1; - return; - } - throw new MojangsonParseException("Expected '" + c + "' but got '" + (hasNext ? Character.valueOf(currentChar()) : "") + "'", this.str, this.index + 1); - } + boolean hasNext = hasNext(); + if (hasNext && currentChar() == c) { + this.index += 1; + return; + } + throw new MojangsonParseException("Expected '" + c + "' but got '" + (hasNext ? Character.valueOf(currentChar()) : "") + "'", this.str, this.index + 1); + } - /** - * Verifies that the string has ended or that all characters from the next character on only consists of whitespace. - * - * @throws MojangsonParseException if the following characters contain a non-whitespace character - */ - private void expectNoTrail() throws MojangsonParseException { - skipWhitespace(); - if (hasNext()) { - this.index++; - throw parseException("Trailing data found"); - } - } + /** + * Verifies that the string has ended or that all characters from the next character on only consists of whitespace. + * + * @throws MojangsonParseException if the following characters contain a non-whitespace character + */ + private void expectNoTrail() throws MojangsonParseException { + skipWhitespace(); + if (hasNext()) { + this.index++; + throw parseException("Trailing data found"); + } + } - private MojangsonParseException parseException(String paramString) { - return new MojangsonParseException(paramString, this.str, this.index); - } + private MojangsonParseException parseException(String paramString) { + return new MojangsonParseException(paramString, this.str, this.index); + } - private static boolean isSimpleChar(char paramChar) { - return (paramChar >= '0' && paramChar <= '9') - || (paramChar >= 'A' && paramChar <= 'Z') - || (paramChar >= 'a' && paramChar <= 'z') - || paramChar == '_' - || paramChar == '-' - || paramChar == '.' - || paramChar == '+'; - } + private static boolean isSimpleChar(char paramChar) { + return (paramChar >= '0' && paramChar <= '9') + || (paramChar >= 'A' && paramChar <= 'Z') + || (paramChar >= 'a' && paramChar <= 'z') + || paramChar == '_' + || paramChar == '-' + || paramChar == '.' + || paramChar == '+'; + } } diff --git a/utils/src/main/java/me/filoghost/holographicdisplays/util/reflection/ReflectField.java b/utils/src/main/java/me/filoghost/holographicdisplays/util/reflection/ReflectField.java index a716c11c..306cc34b 100644 --- a/utils/src/main/java/me/filoghost/holographicdisplays/util/reflection/ReflectField.java +++ b/utils/src/main/java/me/filoghost/holographicdisplays/util/reflection/ReflectField.java @@ -18,42 +18,42 @@ import java.lang.reflect.Field; @SuppressWarnings("unchecked") public class ReflectField { - - private final Class clazz; - private final String name; - - private Field field; - - public ReflectField(Class clazz, String name) { - this.clazz = clazz; - this.name = name; - } - - private void init() throws Exception { - if (field == null) { - field = clazz.getDeclaredField(name); - field.setAccessible(true); - } - } - - public T get(Object instance) throws Exception { - init(); - return (T) field.get(instance); - } - - public T getStatic() throws Exception { - init(); - return (T) field.get(null); - } - - public void set(Object instance, T value) throws Exception { - init(); - field.set(instance, value); - } - - public void setStatic(T value) throws Exception { - init(); - field.set(null, value); - } + + private final Class clazz; + private final String name; + + private Field field; + + public ReflectField(Class clazz, String name) { + this.clazz = clazz; + this.name = name; + } + + private void init() throws Exception { + if (field == null) { + field = clazz.getDeclaredField(name); + field.setAccessible(true); + } + } + + public T get(Object instance) throws Exception { + init(); + return (T) field.get(instance); + } + + public T getStatic() throws Exception { + init(); + return (T) field.get(null); + } + + public void set(Object instance, T value) throws Exception { + init(); + field.set(instance, value); + } + + public void setStatic(T value) throws Exception { + init(); + field.set(null, value); + } } diff --git a/utils/src/main/java/me/filoghost/holographicdisplays/util/reflection/ReflectMethod.java b/utils/src/main/java/me/filoghost/holographicdisplays/util/reflection/ReflectMethod.java index e22df1bd..2f3635b0 100644 --- a/utils/src/main/java/me/filoghost/holographicdisplays/util/reflection/ReflectMethod.java +++ b/utils/src/main/java/me/filoghost/holographicdisplays/util/reflection/ReflectMethod.java @@ -18,34 +18,34 @@ import java.lang.reflect.Method; @SuppressWarnings("unchecked") public class ReflectMethod { - - private final Class clazz; - private final String name; - private final Class[] parameterTypes; - - private Method method; - - public ReflectMethod(Class clazz, String name, Class... parameterTypes) { - this.clazz = clazz; - this.name = name; - this.parameterTypes = parameterTypes; - } - - private void init() throws Exception { - if (method == null) { - method = clazz.getDeclaredMethod(name, parameterTypes); - method.setAccessible(true); - } - } - - public T invoke(Object instance, Object... args) throws Exception { - init(); - return (T) method.invoke(instance, args); - } - - public T invokeStatic(Object... args) throws Exception { - init(); - return (T) method.invoke(null, args); - } + + private final Class clazz; + private final String name; + private final Class[] parameterTypes; + + private Method method; + + public ReflectMethod(Class clazz, String name, Class... parameterTypes) { + this.clazz = clazz; + this.name = name; + this.parameterTypes = parameterTypes; + } + + private void init() throws Exception { + if (method == null) { + method = clazz.getDeclaredMethod(name, parameterTypes); + method.setAccessible(true); + } + } + + public T invoke(Object instance, Object... args) throws Exception { + init(); + return (T) method.invoke(instance, args); + } + + public T invokeStatic(Object... args) throws Exception { + init(); + return (T) method.invoke(null, args); + } }