mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2024-12-20 07:47:38 +01:00
Better version control
This commit is contained in:
parent
c22c025fb9
commit
90ac307519
@ -28,6 +28,7 @@ import com.gmail.filoghost.holographicdisplays.placeholder.PlaceholdersManager;
|
||||
import com.gmail.filoghost.holographicdisplays.task.BungeeCleanupTask;
|
||||
import com.gmail.filoghost.holographicdisplays.task.StartupLoadHologramsTask;
|
||||
import com.gmail.filoghost.holographicdisplays.task.WorldPlayerCounterTask;
|
||||
import com.gmail.filoghost.holographicdisplays.util.MinecraftVersion;
|
||||
import com.gmail.filoghost.holographicdisplays.util.VersionUtils;
|
||||
|
||||
public class HolographicDisplays extends JavaPlugin {
|
||||
@ -41,15 +42,6 @@ public class HolographicDisplays extends JavaPlugin {
|
||||
// The command handler, just in case a plugin wants to register more commands.
|
||||
private HologramsCommandHandler commandHandler;
|
||||
|
||||
// Since 1.8 we use armor stands instead of wither skulls.
|
||||
private static boolean is18orGreater;
|
||||
|
||||
// Since 1.9 there is a different offset for the nametag.
|
||||
private static boolean is19orGreater;
|
||||
|
||||
// Since 1.10 there is a difference in the entity metadata packet index for items.
|
||||
private static boolean is110orGreater;
|
||||
|
||||
// The new version found by the updater, null if there is no new version.
|
||||
private static String newVersion;
|
||||
|
||||
@ -114,34 +106,44 @@ public class HolographicDisplays extends JavaPlugin {
|
||||
// It's simple, we don't need reflection.
|
||||
if ("v1_7_R1".equals(version)) {
|
||||
nmsManager = new com.gmail.filoghost.holographicdisplays.nms.v1_7_R1.NmsManagerImpl();
|
||||
MinecraftVersion.set(MinecraftVersion.v1_7);
|
||||
|
||||
} else if ("v1_7_R2".equals(version)) {
|
||||
nmsManager = new com.gmail.filoghost.holographicdisplays.nms.v1_7_R2.NmsManagerImpl();
|
||||
MinecraftVersion.set(MinecraftVersion.v1_7);
|
||||
|
||||
} else if ("v1_7_R3".equals(version)) {
|
||||
nmsManager = new com.gmail.filoghost.holographicdisplays.nms.v1_7_R3.NmsManagerImpl();
|
||||
MinecraftVersion.set(MinecraftVersion.v1_7);
|
||||
|
||||
} else if ("v1_7_R4".equals(version)) {
|
||||
nmsManager = new com.gmail.filoghost.holographicdisplays.nms.v1_7_R4.NmsManagerImpl();
|
||||
MinecraftVersion.set(MinecraftVersion.v1_7);
|
||||
|
||||
} else if ("v1_8_R1".equals(version)) {
|
||||
is18orGreater = true;
|
||||
nmsManager = new com.gmail.filoghost.holographicdisplays.nms.v1_8_R1.NmsManagerImpl();
|
||||
MinecraftVersion.set(MinecraftVersion.v1_8);
|
||||
|
||||
} else if ("v1_8_R2".equals(version)) {
|
||||
is18orGreater = true;
|
||||
nmsManager = new com.gmail.filoghost.holographicdisplays.nms.v1_8_R2.NmsManagerImpl();
|
||||
MinecraftVersion.set(MinecraftVersion.v1_8);
|
||||
|
||||
} else if ("v1_8_R3".equals(version)) {
|
||||
is18orGreater = true;
|
||||
nmsManager = new com.gmail.filoghost.holographicdisplays.nms.v1_8_R3.NmsManagerImpl();
|
||||
MinecraftVersion.set(MinecraftVersion.v1_8);
|
||||
|
||||
} else if ("v1_9_R1".equals(version)) {
|
||||
is18orGreater = true;
|
||||
is19orGreater = true;
|
||||
nmsManager = new com.gmail.filoghost.holographicdisplays.nms.v1_9_R1.NmsManagerImpl();
|
||||
MinecraftVersion.set(MinecraftVersion.v1_9);
|
||||
|
||||
} else if ("v1_9_R2".equals(version)) {
|
||||
is18orGreater = true;
|
||||
is19orGreater = true;
|
||||
nmsManager = new com.gmail.filoghost.holographicdisplays.nms.v1_9_R2.NmsManagerImpl();
|
||||
MinecraftVersion.set(MinecraftVersion.v1_9);
|
||||
|
||||
} else if ("v1_10_R1".equals(version)) {
|
||||
is18orGreater = true;
|
||||
is19orGreater = true;
|
||||
is110orGreater = true;
|
||||
nmsManager = new com.gmail.filoghost.holographicdisplays.nms.v1_10_R1.NmsManagerImpl();
|
||||
MinecraftVersion.set(MinecraftVersion.v1_10);
|
||||
|
||||
} else {
|
||||
printWarnAndDisable(
|
||||
"******************************************************",
|
||||
@ -184,10 +186,10 @@ public class HolographicDisplays extends JavaPlugin {
|
||||
if (VersionUtils.classExists("com.comphenix.protocol.wrappers.WrappedDataWatcher$WrappedDataWatcherObject")) {
|
||||
// Only the new version contains this class
|
||||
getLogger().info("Found ProtocolLib, using new version.");
|
||||
protocolLibHook = new com.gmail.filoghost.holographicdisplays.bridge.protocollib.current.ProtocolLibHookImpl(is19orGreater, is110orGreater);
|
||||
protocolLibHook = new com.gmail.filoghost.holographicdisplays.bridge.protocollib.current.ProtocolLibHookImpl();
|
||||
} else {
|
||||
getLogger().info("Found ProtocolLib, using old version.");
|
||||
protocolLibHook = new com.gmail.filoghost.holographicdisplays.bridge.protocollib.old.ProtocolLibHookImpl(is18orGreater);
|
||||
protocolLibHook = new com.gmail.filoghost.holographicdisplays.bridge.protocollib.old.ProtocolLibHookImpl();
|
||||
}
|
||||
|
||||
if (protocolLibHook.hook(this, nmsManager)) {
|
||||
@ -278,18 +280,6 @@ public class HolographicDisplays extends JavaPlugin {
|
||||
public HologramsCommandHandler getCommandHandler() {
|
||||
return commandHandler;
|
||||
}
|
||||
|
||||
public static boolean is18orGreater() {
|
||||
return is18orGreater;
|
||||
}
|
||||
|
||||
public static boolean is19orGreater() {
|
||||
return is19orGreater;
|
||||
}
|
||||
|
||||
public static boolean is110orGreater() {
|
||||
return is19orGreater;
|
||||
}
|
||||
|
||||
private static void printWarnAndDisable(String... messages) {
|
||||
StringBuffer buffer = new StringBuffer("\n ");
|
||||
|
@ -32,6 +32,7 @@ import com.gmail.filoghost.holographicdisplays.object.line.CraftItemLine;
|
||||
import com.gmail.filoghost.holographicdisplays.object.line.CraftTextLine;
|
||||
import com.gmail.filoghost.holographicdisplays.object.line.CraftTouchSlimeLine;
|
||||
import com.gmail.filoghost.holographicdisplays.object.line.CraftTouchableLine;
|
||||
import com.gmail.filoghost.holographicdisplays.util.MinecraftVersion;
|
||||
import com.gmail.filoghost.holographicdisplays.util.Utils;
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
@ -42,26 +43,15 @@ import com.google.common.base.Optional;
|
||||
*/
|
||||
public class ProtocolLibHookImpl implements ProtocolLibHook {
|
||||
|
||||
private boolean is1_9orGreater;
|
||||
private boolean is110orGreater;
|
||||
|
||||
private NMSManager nmsManager;
|
||||
|
||||
private boolean initSerializers;
|
||||
private Serializer
|
||||
itemSerializer,
|
||||
intSerializer,
|
||||
byteSerializer;
|
||||
private Serializer itemSerializer, intSerializer, byteSerializer;
|
||||
|
||||
public ProtocolLibHookImpl(boolean is19orGreater, boolean is110orGreater) {
|
||||
this.is1_9orGreater = is19orGreater;
|
||||
this.is110orGreater = is110orGreater;
|
||||
}
|
||||
private int itemstackMetadataWatcherIndex;
|
||||
|
||||
@Override
|
||||
public boolean hook(Plugin plugin, NMSManager nmsManager) {
|
||||
this.nmsManager = nmsManager;
|
||||
|
||||
|
||||
String version = Bukkit.getPluginManager().getPlugin("ProtocolLib").getDescription().getVersion();
|
||||
if (version.matches(Pattern.quote("3.7-SNAPSHOT") + ".+")) {
|
||||
Bukkit.getConsoleSender().sendMessage(
|
||||
@ -71,6 +61,24 @@ public class ProtocolLibHookImpl implements ProtocolLibHook {
|
||||
"Please update ProtocolLib.");
|
||||
return false;
|
||||
}
|
||||
|
||||
this.nmsManager = nmsManager;
|
||||
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_9)) {
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_10)) {
|
||||
itemstackMetadataWatcherIndex = 6;
|
||||
} else {
|
||||
itemstackMetadataWatcherIndex = 5;
|
||||
}
|
||||
} else {
|
||||
itemstackMetadataWatcherIndex = 10;
|
||||
}
|
||||
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_9)) {
|
||||
itemSerializer = Registry.get(MinecraftReflection.getItemStackClass());
|
||||
intSerializer = Registry.get(Integer.class);
|
||||
byteSerializer = Registry.get(Byte.class);
|
||||
}
|
||||
|
||||
AdapterParameteters params = PacketAdapter
|
||||
.params()
|
||||
@ -183,7 +191,7 @@ public class ProtocolLibHookImpl implements ProtocolLibHook {
|
||||
String replacement = customName.replace("{player}", player.getName()).replace("{displayname}", player.getDisplayName());
|
||||
|
||||
WrappedWatchableObject newWatchableObject;
|
||||
if (is1_9orGreater) {
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_9)) {
|
||||
// The other constructor does not work in 1.9+.
|
||||
newWatchableObject = new WrappedWatchableObject(watchableObject.getWatcherObject(), replacement);
|
||||
} else {
|
||||
@ -255,19 +263,12 @@ public class ProtocolLibHookImpl implements ProtocolLibHook {
|
||||
WrapperPlayServerEntityMetadata itemDataPacket = new WrapperPlayServerEntityMetadata();
|
||||
WrappedDataWatcher dataWatcher = new WrappedDataWatcher();
|
||||
|
||||
if (is1_9orGreater) {
|
||||
if (!initSerializers) {
|
||||
itemSerializer = Registry.get(MinecraftReflection.getItemStackClass());
|
||||
intSerializer = Registry.get(Integer.class);
|
||||
byteSerializer = Registry.get(Byte.class);
|
||||
initSerializers = true;
|
||||
}
|
||||
|
||||
dataWatcher.setObject(new WrappedDataWatcherObject(is110orGreater ? 6 : 5, itemSerializer), Optional.of(itemLine.getNmsItem().getRawItemStack()));
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_9)) {
|
||||
dataWatcher.setObject(new WrappedDataWatcherObject(itemstackMetadataWatcherIndex, itemSerializer), Optional.of(itemLine.getNmsItem().getRawItemStack()));
|
||||
dataWatcher.setObject(new WrappedDataWatcherObject(1, intSerializer), 300);
|
||||
dataWatcher.setObject(new WrappedDataWatcherObject(0, byteSerializer), (byte) 0);
|
||||
} else {
|
||||
dataWatcher.setObject(10, itemLine.getNmsItem().getRawItemStack());
|
||||
dataWatcher.setObject(itemstackMetadataWatcherIndex, itemLine.getNmsItem().getRawItemStack());
|
||||
dataWatcher.setObject(1, 300);
|
||||
dataWatcher.setObject(0, (byte) 0);
|
||||
}
|
||||
@ -302,7 +303,7 @@ public class ProtocolLibHookImpl implements ProtocolLibHook {
|
||||
|
||||
|
||||
private AbstractPacket getAttachPacket(int vehicleId, int passengerId) {
|
||||
if (is1_9orGreater) {
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_9)) {
|
||||
WrapperPlayServerMount attachPacket = new WrapperPlayServerMount();
|
||||
attachPacket.setVehicleId(vehicleId);
|
||||
attachPacket.setPassengers(new int[] {passengerId});
|
||||
|
@ -16,7 +16,6 @@ import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
||||
import com.gmail.filoghost.holographicdisplays.HolographicDisplays;
|
||||
import com.gmail.filoghost.holographicdisplays.bridge.protocollib.ProtocolLibHook;
|
||||
import com.gmail.filoghost.holographicdisplays.bridge.protocollib.old.WrapperPlayServerSpawnEntity.ObjectTypes;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
@ -27,6 +26,7 @@ import com.gmail.filoghost.holographicdisplays.object.line.CraftItemLine;
|
||||
import com.gmail.filoghost.holographicdisplays.object.line.CraftTextLine;
|
||||
import com.gmail.filoghost.holographicdisplays.object.line.CraftTouchSlimeLine;
|
||||
import com.gmail.filoghost.holographicdisplays.object.line.CraftTouchableLine;
|
||||
import com.gmail.filoghost.holographicdisplays.util.MinecraftVersion;
|
||||
import com.gmail.filoghost.holographicdisplays.util.Utils;
|
||||
import com.gmail.filoghost.holographicdisplays.util.VersionUtils;
|
||||
|
||||
@ -37,21 +37,15 @@ import com.gmail.filoghost.holographicdisplays.util.VersionUtils;
|
||||
*/
|
||||
public class ProtocolLibHookImpl implements ProtocolLibHook {
|
||||
|
||||
private boolean is18orGreater;
|
||||
|
||||
private NMSManager nmsManager;
|
||||
|
||||
private int customNameWatcherIndex;
|
||||
|
||||
public ProtocolLibHookImpl(boolean is18orGreater) {
|
||||
this.is18orGreater = is18orGreater;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hook(Plugin plugin, NMSManager nmsManager) {
|
||||
this.nmsManager = nmsManager;
|
||||
|
||||
if (is18orGreater) {
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_8)) {
|
||||
customNameWatcherIndex = 2;
|
||||
} else {
|
||||
customNameWatcherIndex = 10;
|
||||
@ -232,7 +226,7 @@ public class ProtocolLibHookImpl implements ProtocolLibHook {
|
||||
itemPacket.sendPacket(player);
|
||||
|
||||
AbstractPacket vehiclePacket;
|
||||
if (HolographicDisplays.is18orGreater()) {
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_8)) {
|
||||
// In 1.8 we have armor stands, that are living entities.
|
||||
vehiclePacket = new WrapperPlayServerSpawnEntityLiving(itemLine.getNmsVehicle().getBukkitEntityNMS());
|
||||
} else {
|
||||
@ -268,7 +262,7 @@ public class ProtocolLibHookImpl implements ProtocolLibHook {
|
||||
if (touchSlime.isSpawned()) {
|
||||
AbstractPacket vehiclePacket;
|
||||
|
||||
if (HolographicDisplays.is18orGreater()) {
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_8)) {
|
||||
// Armor stand vehicle
|
||||
vehiclePacket = new WrapperPlayServerSpawnEntityLiving(touchSlime.getNmsVehicle().getBukkitEntityNMS());
|
||||
} else {
|
||||
|
@ -7,7 +7,6 @@ import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.HolographicDisplays;
|
||||
import com.gmail.filoghost.holographicdisplays.commands.Colors;
|
||||
import com.gmail.filoghost.holographicdisplays.commands.CommandValidator;
|
||||
import com.gmail.filoghost.holographicdisplays.commands.Strings;
|
||||
@ -15,6 +14,7 @@ import com.gmail.filoghost.holographicdisplays.commands.main.HologramSubCommand;
|
||||
import com.gmail.filoghost.holographicdisplays.exception.CommandException;
|
||||
import com.gmail.filoghost.holographicdisplays.object.NamedHologram;
|
||||
import com.gmail.filoghost.holographicdisplays.object.NamedHologramManager;
|
||||
import com.gmail.filoghost.holographicdisplays.util.MinecraftVersion;
|
||||
|
||||
public class FixCommand extends HologramSubCommand {
|
||||
|
||||
@ -37,7 +37,7 @@ public class FixCommand extends HologramSubCommand {
|
||||
@Override
|
||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
||||
|
||||
CommandValidator.isTrue(!HolographicDisplays.is18orGreater(), "This command is no longer necessary in 1.8+. The holograms already use the correct ambient light.");
|
||||
CommandValidator.isTrue(!MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_8), "This command is no longer necessary in 1.8+. The holograms already use the correct ambient light.");
|
||||
|
||||
NamedHologram hologram = NamedHologramManager.getHologram(args[0].toLowerCase());
|
||||
CommandValidator.notNull(hologram, Strings.noSuchHologram(args[0].toLowerCase()));
|
||||
@ -70,7 +70,7 @@ public class FixCommand extends HologramSubCommand {
|
||||
|
||||
@Override
|
||||
public SubCommandType getType() {
|
||||
if (HolographicDisplays.is18orGreater()) {
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_8)) {
|
||||
return SubCommandType.HIDDEN;
|
||||
} else {
|
||||
return SubCommandType.GENERIC;
|
||||
|
@ -13,6 +13,7 @@ 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.MinecraftVersion;
|
||||
import com.gmail.filoghost.holographicdisplays.util.Offsets;
|
||||
import com.gmail.filoghost.holographicdisplays.util.Validator;
|
||||
|
||||
@ -61,9 +62,9 @@ public class CraftItemLine extends CraftTouchableLine implements ItemLine {
|
||||
|
||||
Location loc = nmsItem.getBukkitEntityNMS().getLocation();
|
||||
|
||||
if (HolographicDisplays.is19orGreater()) {
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_9)) {
|
||||
super.setTouchHandler(touchHandler, loc.getWorld(), loc.getX(), loc.getY() - getItemOffset(), loc.getZ());
|
||||
} else if (HolographicDisplays.is18orGreater()) {
|
||||
} else if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_8)) {
|
||||
super.setTouchHandler(touchHandler, loc.getWorld(), loc.getX(), loc.getY() - getItemOffset(), loc.getZ());
|
||||
} else {
|
||||
super.setTouchHandler(touchHandler, loc.getWorld(), loc.getX(), loc.getY() - getItemOffset(), loc.getZ());
|
||||
@ -84,7 +85,7 @@ public class CraftItemLine extends CraftTouchableLine implements ItemLine {
|
||||
|
||||
nmsItem = HolographicDisplays.getNMSManager().spawnNMSItem(world, x, y + offset, z, this, itemStack);
|
||||
|
||||
if (HolographicDisplays.is18orGreater()) {
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_8)) {
|
||||
nmsVehicle = HolographicDisplays.getNMSManager().spawnNMSArmorStand(world, x, y + offset, z, this);
|
||||
} else {
|
||||
nmsVehicle = HolographicDisplays.getNMSManager().spawnNMSWitherSkull(world, x, y + offset, z, this);
|
||||
@ -150,9 +151,9 @@ public class CraftItemLine extends CraftTouchableLine implements ItemLine {
|
||||
}
|
||||
|
||||
private double getItemOffset() {
|
||||
if (HolographicDisplays.is19orGreater()) {
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_9)) {
|
||||
return Offsets.ARMOR_STAND_WITH_ITEM_1_9;
|
||||
} else if (HolographicDisplays.is18orGreater()) {
|
||||
} else if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_8)) {
|
||||
return Offsets.ARMOR_STAND_WITH_ITEM;
|
||||
} else {
|
||||
return Offsets.WITHER_SKULL_WITH_ITEM;
|
||||
|
@ -12,6 +12,7 @@ import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBa
|
||||
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.MinecraftVersion;
|
||||
import com.gmail.filoghost.holographicdisplays.util.Offsets;
|
||||
|
||||
public class CraftTextLine extends CraftTouchableLine implements TextLine {
|
||||
@ -70,7 +71,7 @@ public class CraftTextLine extends CraftTouchableLine implements TextLine {
|
||||
public void spawn(World world, double x, double y, double z) {
|
||||
super.spawn(world, x, y, z);
|
||||
|
||||
if (HolographicDisplays.is18orGreater()) {
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_8)) {
|
||||
nmsNameble = HolographicDisplays.getNMSManager().spawnNMSArmorStand(world, x, y + getTextOffset(), z, this);
|
||||
} else {
|
||||
nmsNameble = HolographicDisplays.getNMSManager().spawnNMSHorse(world, x, y + Offsets.WITHER_SKULL_WITH_HORSE, z, this);
|
||||
@ -148,9 +149,9 @@ public class CraftTextLine extends CraftTouchableLine implements TextLine {
|
||||
}
|
||||
|
||||
private double getTextOffset() {
|
||||
if (HolographicDisplays.is19orGreater()) {
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_9)) {
|
||||
return Offsets.ARMOR_STAND_ALONE_1_9;
|
||||
} else if (HolographicDisplays.is18orGreater()) {
|
||||
} else if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_8)) {
|
||||
return Offsets.ARMOR_STAND_ALONE;
|
||||
} else {
|
||||
return Offsets.WITHER_SKULL_WITH_HORSE;
|
||||
|
@ -6,6 +6,7 @@ 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.MinecraftVersion;
|
||||
import com.gmail.filoghost.holographicdisplays.util.Offsets;
|
||||
|
||||
/**
|
||||
@ -38,7 +39,7 @@ public class CraftTouchSlimeLine extends CraftHologramLine {
|
||||
|
||||
nmsSlime = HolographicDisplays.getNMSManager().spawnNMSSlime(world, x, y + offset, z, this);
|
||||
|
||||
if (HolographicDisplays.is18orGreater()) {
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_8)) {
|
||||
nmsVehicle = HolographicDisplays.getNMSManager().spawnNMSArmorStand(world, x, y + offset, z, this);
|
||||
} else {
|
||||
nmsVehicle = HolographicDisplays.getNMSManager().spawnNMSWitherSkull(world, x, y + offset, z, this);
|
||||
@ -99,9 +100,9 @@ public class CraftTouchSlimeLine extends CraftHologramLine {
|
||||
}
|
||||
|
||||
private double getSlimeOffset() {
|
||||
if (HolographicDisplays.is19orGreater()) {
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_9)) {
|
||||
return Offsets.ARMOR_STAND_WITH_SLIME_1_9;
|
||||
} else if (HolographicDisplays.is18orGreater()) {
|
||||
} else if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_8)) {
|
||||
return Offsets.ARMOR_STAND_WITH_SLIME;
|
||||
} else {
|
||||
return Offsets.WITHER_SKULL_WITH_SLIME;
|
||||
|
@ -0,0 +1,45 @@
|
||||
package com.gmail.filoghost.holographicdisplays.util;
|
||||
|
||||
/*
|
||||
* Since 1.8 we use armor stands instead of wither skulls.
|
||||
* Since 1.9 there is a different offset for the nametag.
|
||||
* Since 1.10 there is a difference in the entity metadata packet index for items.
|
||||
*/
|
||||
public class MinecraftVersion {
|
||||
|
||||
private static MinecraftVersion version;
|
||||
|
||||
public static final MinecraftVersion
|
||||
|
||||
v1_7 = new MinecraftVersion(1),
|
||||
|
||||
// Since 1.8 we use armor stands instead of wither skulls.
|
||||
v1_8 = new MinecraftVersion(2),
|
||||
|
||||
// Since 1.9 there is a different offset for the nametag.
|
||||
v1_9 = new MinecraftVersion(3),
|
||||
|
||||
// Since 1.10 there is a difference in the entity metadata packet index for items.
|
||||
v1_10 = new MinecraftVersion(4);
|
||||
|
||||
private int value;
|
||||
|
||||
private MinecraftVersion(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static void set(MinecraftVersion version) {
|
||||
if (version == null) {
|
||||
throw new NullPointerException("version");
|
||||
}
|
||||
if (MinecraftVersion.version != null) {
|
||||
throw new IllegalArgumentException("version already set");
|
||||
}
|
||||
MinecraftVersion.version = version;
|
||||
}
|
||||
|
||||
public static boolean isGreaterEqualThan(MinecraftVersion other) {
|
||||
return MinecraftVersion.version.value >= other.value;
|
||||
}
|
||||
|
||||
}
|
@ -10,7 +10,6 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.HolographicDisplays;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
public class VersionUtils {
|
||||
@ -55,7 +54,7 @@ public class VersionUtils {
|
||||
}
|
||||
|
||||
public static boolean isArmorstand(EntityType type) {
|
||||
if (!HolographicDisplays.is18orGreater()) {
|
||||
if (!MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_8)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user