From 4214b251cf1f0d881fb3b4f7abc161301ded2600 Mon Sep 17 00:00:00 2001 From: filoghost Date: Tue, 21 Aug 2018 00:05:32 +0200 Subject: [PATCH] Fix offsets --- .../nms/v1_8_R1/EntityNMSArmorStand.java | 7 +-- .../bridge/bungeecord/BungeeChannel.java | 3 +- .../object/CraftVisibilityManager.java | 3 +- .../object/line/CraftItemLine.java | 8 +--- .../object/line/CraftTextLine.java | 8 +--- .../object/line/CraftTouchSlimeLine.java | 7 +-- .../placeholder/PlaceholdersRegister.java | 3 +- .../holographicdisplays/util/Offsets.java | 47 ++++++++++++++----- .../util/VersionUtils.java | 33 ------------- 9 files changed, 43 insertions(+), 76 deletions(-) diff --git a/NMS/v1_8_R1/src/main/java/com/gmail/filoghost/holographicdisplays/nms/v1_8_R1/EntityNMSArmorStand.java b/NMS/v1_8_R1/src/main/java/com/gmail/filoghost/holographicdisplays/nms/v1_8_R1/EntityNMSArmorStand.java index 2a6a8248..6f0fd37a 100644 --- a/NMS/v1_8_R1/src/main/java/com/gmail/filoghost/holographicdisplays/nms/v1_8_R1/EntityNMSArmorStand.java +++ b/NMS/v1_8_R1/src/main/java/com/gmail/filoghost/holographicdisplays/nms/v1_8_R1/EntityNMSArmorStand.java @@ -31,12 +31,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta setArms(false); setGravity(true); setBasePlate(true); - try { - ReflectionUtils.callPrivateMethod(EntityArmorStand.class, this, "n", new Class[]{ boolean.class }, new Object[]{ true }); // n() = setMarker() - } catch (Exception e) { - e.printStackTrace(); - // It will still work. - } + // There is no "Marker" tag in v1_8_R1 this.parentPiece = parentPiece; try { ReflectionUtils.setPrivateField(EntityArmorStand.class, this, "bg", Integer.MAX_VALUE); diff --git a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/bridge/bungeecord/BungeeChannel.java b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/bridge/bungeecord/BungeeChannel.java index ffaea90c..493b01f8 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/bridge/bungeecord/BungeeChannel.java +++ b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/bridge/bungeecord/BungeeChannel.java @@ -16,7 +16,6 @@ import org.bukkit.plugin.messaging.PluginMessageListener; import com.gmail.filoghost.holographicdisplays.HolographicDisplays; import com.gmail.filoghost.holographicdisplays.disk.Configuration; import com.gmail.filoghost.holographicdisplays.util.NMSVersion; -import com.gmail.filoghost.holographicdisplays.util.VersionUtils; public class BungeeChannel implements PluginMessageListener { @@ -103,7 +102,7 @@ public class BungeeChannel implements PluginMessageListener { } // OR, if you don't need to send it to a specific player - Collection players = VersionUtils.getOnlinePlayers(); + Collection players = Bukkit.getOnlinePlayers(); if (players.size() > 0) { players.iterator().next().sendPluginMessage(HolographicDisplays.getInstance(), Configuration.useRedisBungee ? "RedisBungee" : "BungeeCord", b.toByteArray()); } diff --git a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/object/CraftVisibilityManager.java b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/object/CraftVisibilityManager.java index 6d5c4537..32099a89 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/object/CraftVisibilityManager.java +++ b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/object/CraftVisibilityManager.java @@ -11,7 +11,6 @@ import org.bukkit.entity.Player; import com.gmail.filoghost.holographicdisplays.HolographicDisplays; import com.gmail.filoghost.holographicdisplays.api.VisibilityManager; import com.gmail.filoghost.holographicdisplays.util.Validator; -import com.gmail.filoghost.holographicdisplays.util.VersionUtils; public class CraftVisibilityManager implements VisibilityManager { @@ -39,7 +38,7 @@ public class CraftVisibilityManager implements VisibilityManager { boolean oldVisibleByDefault = this.visibleByDefault; this.visibleByDefault = visibleByDefault; - for (Player player : VersionUtils.getOnlinePlayers()) { + for (Player player : Bukkit.getOnlinePlayers()) { if (playersVisibilityMap != null && playersVisibilityMap.containsKey(player.getName().toLowerCase())) { // Has a specific value set diff --git a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/object/line/CraftItemLine.java b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/object/line/CraftItemLine.java index 88c2f34a..81c1e699 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/object/line/CraftItemLine.java +++ b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/object/line/CraftItemLine.java @@ -13,7 +13,6 @@ import com.gmail.filoghost.holographicdisplays.api.line.ItemLine; import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase; import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSItem; import com.gmail.filoghost.holographicdisplays.object.CraftHologram; -import com.gmail.filoghost.holographicdisplays.util.NMSVersion; import com.gmail.filoghost.holographicdisplays.util.Offsets; import com.gmail.filoghost.holographicdisplays.util.Validator; @@ -56,6 +55,7 @@ public class CraftItemLine extends CraftTouchableLine implements ItemLine { this.pickupHandler = pickupHandler; } + @Override public void setTouchHandler(TouchHandler touchHandler) { if (nmsItem != null) { Location loc = nmsItem.getBukkitEntityNMS().getLocation(); @@ -136,11 +136,7 @@ public class CraftItemLine extends CraftTouchableLine implements ItemLine { } private double getItemOffset() { - if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_9_R1)) { - return Offsets.ARMOR_STAND_WITH_ITEM_1_9; - } else { - return Offsets.ARMOR_STAND_WITH_ITEM; - } + return Offsets.ARMOR_STAND_WITH_ITEM; } @Override diff --git a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/object/line/CraftTextLine.java b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/object/line/CraftTextLine.java index 86389826..54ff894f 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/object/line/CraftTextLine.java +++ b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/object/line/CraftTextLine.java @@ -10,7 +10,6 @@ import com.gmail.filoghost.holographicdisplays.api.line.TextLine; import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSNameable; import com.gmail.filoghost.holographicdisplays.object.CraftHologram; import com.gmail.filoghost.holographicdisplays.placeholder.PlaceholdersManager; -import com.gmail.filoghost.holographicdisplays.util.NMSVersion; import com.gmail.filoghost.holographicdisplays.util.Offsets; public class CraftTextLine extends CraftTouchableLine implements TextLine { @@ -49,6 +48,7 @@ public class CraftTextLine extends CraftTouchableLine implements TextLine { } } + @Override public void setTouchHandler(TouchHandler touchHandler) { if (nmsNameble != null) { @@ -113,11 +113,7 @@ public class CraftTextLine extends CraftTouchableLine implements TextLine { } private double getTextOffset() { - if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_9_R1)) { - return Offsets.ARMOR_STAND_ALONE_1_9; - } else { - return Offsets.ARMOR_STAND_ALONE; - } + return Offsets.ARMOR_STAND_ALONE; } @Override diff --git a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/object/line/CraftTouchSlimeLine.java b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/object/line/CraftTouchSlimeLine.java index 852fcae4..e0a3fd23 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/object/line/CraftTouchSlimeLine.java +++ b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/object/line/CraftTouchSlimeLine.java @@ -6,7 +6,6 @@ import com.gmail.filoghost.holographicdisplays.HolographicDisplays; import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase; import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSSlime; import com.gmail.filoghost.holographicdisplays.object.CraftHologram; -import com.gmail.filoghost.holographicdisplays.util.NMSVersion; import com.gmail.filoghost.holographicdisplays.util.Offsets; /** @@ -95,11 +94,7 @@ public class CraftTouchSlimeLine extends CraftHologramLine { } private double getSlimeOffset() { - if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_9_R1)) { - return Offsets.ARMOR_STAND_WITH_SLIME_1_9; - } else { - return Offsets.ARMOR_STAND_WITH_SLIME; - } + return Offsets.ARMOR_STAND_WITH_SLIME; } @Override diff --git a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/placeholder/PlaceholdersRegister.java b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/placeholder/PlaceholdersRegister.java index a8a0134f..f953549b 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/placeholder/PlaceholdersRegister.java +++ b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/placeholder/PlaceholdersRegister.java @@ -12,7 +12,6 @@ import com.gmail.filoghost.holographicdisplays.HolographicDisplays; import com.gmail.filoghost.holographicdisplays.api.placeholder.PlaceholderReplacer; import com.gmail.filoghost.holographicdisplays.disk.Configuration; import com.gmail.filoghost.holographicdisplays.util.Utils; -import com.gmail.filoghost.holographicdisplays.util.VersionUtils; public class PlaceholdersRegister { @@ -25,7 +24,7 @@ public class PlaceholdersRegister { @Override public String update() { - return String.valueOf(VersionUtils.getOnlinePlayers().size()); + return String.valueOf(Bukkit.getOnlinePlayers().size()); } })); diff --git a/Utils/src/main/java/com/gmail/filoghost/holographicdisplays/util/Offsets.java b/Utils/src/main/java/com/gmail/filoghost/holographicdisplays/util/Offsets.java index b2b81b7d..f3b979b6 100644 --- a/Utils/src/main/java/com/gmail/filoghost/holographicdisplays/util/Offsets.java +++ b/Utils/src/main/java/com/gmail/filoghost/holographicdisplays/util/Offsets.java @@ -8,23 +8,44 @@ public class Offsets { public static final double - // For 1.8+, a single armor stand. - ARMOR_STAND_ALONE = -0.26, + // A single armor stand. + ARMOR_STAND_ALONE = getArmorStandAloneOffset(), - // For 1.8+, an armor stand holding an item. - ARMOR_STAND_WITH_ITEM = -1.48, + // An armor stand holding an item. + ARMOR_STAND_WITH_ITEM = getArmorStandWithItemOffset(), - // For 1.8+, an armor stand holding a slime. - ARMOR_STAND_WITH_SLIME = -1.49, + // An armor stand holding a slime. + ARMOR_STAND_WITH_SLIME = getArmorStandWithSlimeOffset(); - // For 1.9+, a single armor stand. - ARMOR_STAND_ALONE_1_9 = -0.29, - - // For 1.9+, an armor stand holding an item. - ARMOR_STAND_WITH_ITEM_1_9 = -0.0, + private static double getArmorStandAloneOffset() { + if (NMSVersion.getCurrent() == NMSVersion.v1_8_R1) { + // When the NBT tag "Marker" was not implemented + return -1.25; + } else { + return -0.29; + } + } + + + private static double getArmorStandWithItemOffset() { + if (NMSVersion.getCurrent() == NMSVersion.v1_8_R1) { + // When the NBT tag "Marker" was not implemented + return -1.48; + } else { + return 0; + } + } + + + private static double getArmorStandWithSlimeOffset() { + if (NMSVersion.getCurrent() == NMSVersion.v1_8_R1) { + // When the NBT tag "Marker" was not implemented + return -1.48; + } else { + return 0; + } + } - // For 1.9+, an armor stand holding a slime. - ARMOR_STAND_WITH_SLIME_1_9 = -0.01; } diff --git a/Utils/src/main/java/com/gmail/filoghost/holographicdisplays/util/VersionUtils.java b/Utils/src/main/java/com/gmail/filoghost/holographicdisplays/util/VersionUtils.java index 7ae03fff..2ddb6e76 100644 --- a/Utils/src/main/java/com/gmail/filoghost/holographicdisplays/util/VersionUtils.java +++ b/Utils/src/main/java/com/gmail/filoghost/holographicdisplays/util/VersionUtils.java @@ -1,21 +1,12 @@ package com.gmail.filoghost.holographicdisplays.util; -import java.lang.reflect.Method; -import java.util.Collection; -import java.util.Collections; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import com.google.common.collect.ImmutableList; public class VersionUtils { - private static Method getOnlinePlayersMethod; - private static boolean getOnlinePlayersUseReflection; - /** * This method uses a regex to get the NMS package part that changes with every update. * Example: v1_8_R1 @@ -56,30 +47,6 @@ public class VersionUtils { } } - public static Collection getOnlinePlayers() { - try { - - if (getOnlinePlayersMethod == null) { - getOnlinePlayersMethod = Bukkit.class.getDeclaredMethod("getOnlinePlayers"); - if (getOnlinePlayersMethod.getReturnType() == Player[].class) { - getOnlinePlayersUseReflection = true; - } - } - - if (!getOnlinePlayersUseReflection) { - return Bukkit.getOnlinePlayers(); - } else { - Player[] playersArray = (Player[]) getOnlinePlayersMethod.invoke(null); - return ImmutableList.copyOf(playersArray); - } - - } catch (Exception e) { - e.printStackTrace(); - return Collections.emptyList(); - } - } - - /** * @return 1 if reference > comparison, 0 if reference == comparison, -1 if reference < comparison */