mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2024-11-19 17:05:17 +01:00
Refactor MinecraftVersion into NMSVersion
This commit is contained in:
parent
a67866ff42
commit
bfbe3400ce
@ -32,7 +32,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.NMSVersion;
|
||||
import com.gmail.filoghost.holographicdisplays.util.VersionUtils;
|
||||
|
||||
public class HolographicDisplays extends JavaPlugin {
|
||||
@ -86,71 +86,7 @@ public class HolographicDisplays extends JavaPlugin {
|
||||
});
|
||||
}
|
||||
|
||||
String version = VersionUtils.getBukkitVersion();
|
||||
|
||||
if (version == null) {
|
||||
// Caused by MCPC+ / Cauldron renaming packages, extract the version from Bukkit.getVersion().
|
||||
version = VersionUtils.getMinecraftVersion();
|
||||
|
||||
if ("1.7.2".equals(version)) {
|
||||
version = "v1_7_R1";
|
||||
} else if ("1.7.5".equals(version)) {
|
||||
version = "v1_7_R2";
|
||||
} else if ("1.7.8".equals(version)) {
|
||||
version = "v1_7_R3";
|
||||
} else if ("1.7.10".equals(version)) {
|
||||
version = "v1_7_R4";
|
||||
} else if ("1.8".equals(version)) {
|
||||
version = "v1_8_R1";
|
||||
} else if ("1.8.3".equals(version)) {
|
||||
version = "v1_8_R2";
|
||||
} else {
|
||||
// Cannot definitely get the version. This will cause the plugin to disable itself.
|
||||
version = null;
|
||||
}
|
||||
}
|
||||
|
||||
// It's simple, we don't need reflection.
|
||||
if ("v1_7_R1".equals(version)) {
|
||||
MinecraftVersion.set(MinecraftVersion.v1_7);
|
||||
|
||||
} else if ("v1_7_R2".equals(version)) {
|
||||
MinecraftVersion.set(MinecraftVersion.v1_7);
|
||||
|
||||
} else if ("v1_7_R3".equals(version)) {
|
||||
MinecraftVersion.set(MinecraftVersion.v1_7);
|
||||
|
||||
} else if ("v1_7_R4".equals(version)) {
|
||||
MinecraftVersion.set(MinecraftVersion.v1_7);
|
||||
|
||||
} else if ("v1_8_R1".equals(version)) {
|
||||
MinecraftVersion.set(MinecraftVersion.v1_8);
|
||||
|
||||
} else if ("v1_8_R2".equals(version)) {
|
||||
MinecraftVersion.set(MinecraftVersion.v1_8);
|
||||
|
||||
} else if ("v1_8_R3".equals(version)) {
|
||||
MinecraftVersion.set(MinecraftVersion.v1_8);
|
||||
|
||||
} else if ("v1_9_R1".equals(version)) {
|
||||
MinecraftVersion.set(MinecraftVersion.v1_9);
|
||||
|
||||
} else if ("v1_9_R2".equals(version)) {
|
||||
MinecraftVersion.set(MinecraftVersion.v1_9);
|
||||
|
||||
} else if ("v1_10_R1".equals(version)) {
|
||||
MinecraftVersion.set(MinecraftVersion.v1_10);
|
||||
|
||||
} else if ("v1_11_R1".equals(version)) {
|
||||
MinecraftVersion.set(MinecraftVersion.v1_11);
|
||||
|
||||
} else if ("v1_12_R1".equals(version)) {
|
||||
MinecraftVersion.set(MinecraftVersion.v1_12);
|
||||
|
||||
} else if ("v1_13_R1".equals(version)) {
|
||||
MinecraftVersion.set(MinecraftVersion.v1_13);
|
||||
|
||||
} else {
|
||||
if (!NMSVersion.isValid()) {
|
||||
printWarnAndDisable(
|
||||
"******************************************************",
|
||||
" This version of HolographicDisplays only",
|
||||
@ -162,7 +98,7 @@ public class HolographicDisplays extends JavaPlugin {
|
||||
}
|
||||
|
||||
try {
|
||||
nmsManager = (NMSManager) Class.forName("com.gmail.filoghost.holographicdisplays.nms." + version + ".NmsManagerImpl").getConstructor().newInstance();
|
||||
nmsManager = (NMSManager) Class.forName("com.gmail.filoghost.holographicdisplays.nms." + NMSVersion.getCurrent() + ".NmsManagerImpl").getConstructor().newInstance();
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
printWarnAndDisable(
|
||||
@ -210,11 +146,11 @@ public class HolographicDisplays extends JavaPlugin {
|
||||
if (versionNumbersMatcher.find()) {
|
||||
String versionNumbers = versionNumbersMatcher.group();
|
||||
|
||||
if (MinecraftVersion.get() == MinecraftVersion.v1_7) {
|
||||
if (NMSVersion.isBetween(NMSVersion.v1_7_R1, NMSVersion.v1_7_R4)) {
|
||||
if (!VersionUtils.isVersionBetweenEqual(versionNumbers, "3.6.4", "3.7.0")) {
|
||||
requiredVersionError = "between 3.6.4 and 3.7.0";
|
||||
}
|
||||
} else if (MinecraftVersion.get() == MinecraftVersion.v1_8) {
|
||||
} else if (NMSVersion.isBetween(NMSVersion.v1_8_R1, NMSVersion.v1_8_R3)) {
|
||||
if (!VersionUtils.isVersionBetweenEqual(versionNumbers, "3.6.4", "3.6.5") && !VersionUtils.isVersionGreaterEqual(versionNumbers, "4.1")) {
|
||||
requiredVersionError = "between 3.6.4 and 3.6.5 or higher than 4.1";
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ 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.MinecraftVersion;
|
||||
import com.gmail.filoghost.holographicdisplays.util.NMSVersion;
|
||||
import com.gmail.filoghost.holographicdisplays.util.VersionUtils;
|
||||
|
||||
public class BungeeChannel implements PluginMessageListener {
|
||||
@ -33,7 +33,7 @@ public class BungeeChannel implements PluginMessageListener {
|
||||
Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "BungeeCord");
|
||||
Bukkit.getMessenger().registerIncomingPluginChannel(plugin, "BungeeCord", this);
|
||||
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_13)) {
|
||||
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) {
|
||||
// TODO implement when RedisBungee will be updated
|
||||
} else {
|
||||
Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "RedisBungee");
|
||||
|
@ -36,7 +36,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.NMSVersion;
|
||||
import com.gmail.filoghost.holographicdisplays.util.Utils;
|
||||
|
||||
/**
|
||||
@ -74,8 +74,8 @@ public class ProtocolLibHookImpl implements ProtocolLibHook {
|
||||
|
||||
this.nmsManager = nmsManager;
|
||||
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_9)) {
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_10)) {
|
||||
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_9_R1)) {
|
||||
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_10_R1)) {
|
||||
itemstackMetadataWatcherIndex = 6;
|
||||
} else {
|
||||
itemstackMetadataWatcherIndex = 5;
|
||||
@ -86,7 +86,7 @@ public class ProtocolLibHookImpl implements ProtocolLibHook {
|
||||
|
||||
customNameWatcherIndex = 2;
|
||||
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_9)) {
|
||||
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_9_R1)) {
|
||||
itemSerializer = Registry.get(MinecraftReflection.getItemStackClass());
|
||||
intSerializer = Registry.get(Integer.class);
|
||||
byteSerializer = Registry.get(Byte.class);
|
||||
@ -94,7 +94,7 @@ public class ProtocolLibHookImpl implements ProtocolLibHook {
|
||||
booleanSerializer = Registry.get(Boolean.class);
|
||||
}
|
||||
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_13)) {
|
||||
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) {
|
||||
chatComponentSerializer = Registry.get(MinecraftReflection.getIChatBaseComponentClass(), true);
|
||||
}
|
||||
|
||||
@ -218,7 +218,7 @@ public class ProtocolLibHookImpl implements ProtocolLibHook {
|
||||
Object customNameWatchableObjectValue = customNameWatchableObject.getValue();
|
||||
String customName;
|
||||
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_13)) {
|
||||
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) {
|
||||
if (!(customNameWatchableObjectValue instanceof Optional)) {
|
||||
return false;
|
||||
}
|
||||
@ -245,7 +245,7 @@ public class ProtocolLibHookImpl implements ProtocolLibHook {
|
||||
|
||||
customName = customName.replace("{player}", player.getName()).replace("{displayname}", player.getDisplayName());
|
||||
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_13)) {
|
||||
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) {
|
||||
customNameWatchableObject.setValue(Optional.of(WrappedChatComponent.fromJson(customName).getHandle()));
|
||||
} else {
|
||||
customNameWatchableObject.setValue(customName);
|
||||
@ -300,8 +300,8 @@ public class ProtocolLibHookImpl implements ProtocolLibHook {
|
||||
WrapperPlayServerEntityMetadata itemDataPacket = new WrapperPlayServerEntityMetadata();
|
||||
WrappedDataWatcher dataWatcher = new WrappedDataWatcher();
|
||||
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_9)) {
|
||||
Object itemStackObject = MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_11) ? itemLine.getNmsItem().getRawItemStack() : Optional.of(itemLine.getNmsItem().getRawItemStack());
|
||||
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_9_R1)) {
|
||||
Object itemStackObject = NMSVersion.isGreaterEqualThan(NMSVersion.v1_11_R1) ? itemLine.getNmsItem().getRawItemStack() : Optional.of(itemLine.getNmsItem().getRawItemStack());
|
||||
dataWatcher.setObject(new WrappedDataWatcherObject(itemstackMetadataWatcherIndex, itemSerializer), itemStackObject);
|
||||
dataWatcher.setObject(new WrappedDataWatcherObject(1, intSerializer), 300);
|
||||
dataWatcher.setObject(new WrappedDataWatcherObject(0, byteSerializer), (byte) 0);
|
||||
@ -339,7 +339,7 @@ public class ProtocolLibHookImpl implements ProtocolLibHook {
|
||||
|
||||
|
||||
private void sendSpawnArmorStandPacket(Player receiver, NMSArmorStand armorStand) {
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_11)) {
|
||||
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_11_R1)) {
|
||||
WrapperPlayServerSpawnEntity spawnPacket = new WrapperPlayServerSpawnEntity(armorStand.getBukkitEntityNMS(), WrapperPlayServerSpawnEntity.ObjectTypes.ARMOR_STAND, 1);
|
||||
spawnPacket.sendPacket(receiver);
|
||||
|
||||
@ -350,7 +350,7 @@ public class ProtocolLibHookImpl implements ProtocolLibHook {
|
||||
|
||||
String customName = armorStand.getCustomNameNMS();
|
||||
if (customName != null && !customName.isEmpty()) {
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_13)) {
|
||||
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) {
|
||||
dataWatcher.setObject(new WrappedDataWatcherObject(customNameWatcherIndex, chatComponentSerializer), Optional.of(WrappedChatComponent.fromText(customName).getHandle()));
|
||||
} else {
|
||||
dataWatcher.setObject(new WrappedDataWatcherObject(customNameWatcherIndex, stringSerializer), customName);
|
||||
@ -373,7 +373,7 @@ public class ProtocolLibHookImpl implements ProtocolLibHook {
|
||||
|
||||
|
||||
private void sendVehicleAttachPacket(Player receiver, int vehicleId, int passengerId) {
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_9)) {
|
||||
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_9_R1)) {
|
||||
WrapperPlayServerMount attachPacket = new WrapperPlayServerMount();
|
||||
attachPacket.setVehicleId(vehicleId);
|
||||
attachPacket.setPassengers(new int[] {passengerId});
|
||||
|
@ -27,7 +27,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.NMSVersion;
|
||||
import com.gmail.filoghost.holographicdisplays.util.Utils;
|
||||
import com.gmail.filoghost.holographicdisplays.util.VersionUtils;
|
||||
|
||||
@ -46,7 +46,7 @@ public class ProtocolLibHookImpl implements ProtocolLibHook {
|
||||
public boolean hook(Plugin plugin, NMSManager nmsManager) {
|
||||
this.nmsManager = nmsManager;
|
||||
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_8)) {
|
||||
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_8_R1)) {
|
||||
customNameWatcherIndex = 2;
|
||||
} else {
|
||||
customNameWatcherIndex = 10;
|
||||
@ -227,7 +227,7 @@ public class ProtocolLibHookImpl implements ProtocolLibHook {
|
||||
itemPacket.sendPacket(player);
|
||||
|
||||
AbstractPacket vehiclePacket;
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_8)) {
|
||||
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_8_R1)) {
|
||||
// In 1.8 we have armor stands, that are living entities.
|
||||
vehiclePacket = new WrapperPlayServerSpawnEntityLiving(itemLine.getNmsVehicle().getBukkitEntityNMS());
|
||||
} else {
|
||||
@ -263,7 +263,7 @@ public class ProtocolLibHookImpl implements ProtocolLibHook {
|
||||
if (touchSlime.isSpawned()) {
|
||||
AbstractPacket vehiclePacket;
|
||||
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_8)) {
|
||||
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_8_R1)) {
|
||||
// Armor stand vehicle
|
||||
vehiclePacket = new WrapperPlayServerSpawnEntityLiving(touchSlime.getNmsVehicle().getBukkitEntityNMS());
|
||||
} else {
|
||||
|
@ -14,7 +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;
|
||||
import com.gmail.filoghost.holographicdisplays.util.NMSVersion;
|
||||
|
||||
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(!MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_8), "This command is no longer necessary in 1.8+. The holograms already use the correct ambient light.");
|
||||
CommandValidator.isTrue(!NMSVersion.isGreaterEqualThan(NMSVersion.v1_8_R1), "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 (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_8)) {
|
||||
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_8_R1)) {
|
||||
return SubCommandType.HIDDEN;
|
||||
} else {
|
||||
return SubCommandType.GENERIC;
|
||||
|
@ -13,7 +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.NMSVersion;
|
||||
import com.gmail.filoghost.holographicdisplays.util.Offsets;
|
||||
import com.gmail.filoghost.holographicdisplays.util.Validator;
|
||||
|
||||
@ -62,9 +62,9 @@ public class CraftItemLine extends CraftTouchableLine implements ItemLine {
|
||||
|
||||
Location loc = nmsItem.getBukkitEntityNMS().getLocation();
|
||||
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_9)) {
|
||||
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_9_R1)) {
|
||||
super.setTouchHandler(touchHandler, loc.getWorld(), loc.getX(), loc.getY() - getItemOffset(), loc.getZ());
|
||||
} else if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_8)) {
|
||||
} else if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_8_R1)) {
|
||||
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());
|
||||
@ -85,7 +85,7 @@ public class CraftItemLine extends CraftTouchableLine implements ItemLine {
|
||||
|
||||
nmsItem = HolographicDisplays.getNMSManager().spawnNMSItem(world, x, y + offset, z, this, itemStack, HolographicDisplays.getMainListener());
|
||||
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_8)) {
|
||||
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_8_R1)) {
|
||||
nmsVehicle = HolographicDisplays.getNMSManager().spawnNMSArmorStand(world, x, y + offset, z, this);
|
||||
} else {
|
||||
nmsVehicle = HolographicDisplays.getNMSManager().spawnNMSWitherSkull(world, x, y + offset, z, this);
|
||||
@ -151,9 +151,9 @@ public class CraftItemLine extends CraftTouchableLine implements ItemLine {
|
||||
}
|
||||
|
||||
private double getItemOffset() {
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_9)) {
|
||||
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_9_R1)) {
|
||||
return Offsets.ARMOR_STAND_WITH_ITEM_1_9;
|
||||
} else if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_8)) {
|
||||
} else if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_8_R1)) {
|
||||
return Offsets.ARMOR_STAND_WITH_ITEM;
|
||||
} else {
|
||||
return Offsets.WITHER_SKULL_WITH_ITEM;
|
||||
|
@ -12,7 +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.NMSVersion;
|
||||
import com.gmail.filoghost.holographicdisplays.util.Offsets;
|
||||
|
||||
public class CraftTextLine extends CraftTouchableLine implements TextLine {
|
||||
@ -71,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 (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_8)) {
|
||||
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_8_R1)) {
|
||||
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);
|
||||
@ -149,9 +149,9 @@ public class CraftTextLine extends CraftTouchableLine implements TextLine {
|
||||
}
|
||||
|
||||
private double getTextOffset() {
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_9)) {
|
||||
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_9_R1)) {
|
||||
return Offsets.ARMOR_STAND_ALONE_1_9;
|
||||
} else if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_8)) {
|
||||
} else if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_8_R1)) {
|
||||
return Offsets.ARMOR_STAND_ALONE;
|
||||
} else {
|
||||
return Offsets.WITHER_SKULL_WITH_HORSE;
|
||||
|
@ -6,7 +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.NMSVersion;
|
||||
import com.gmail.filoghost.holographicdisplays.util.Offsets;
|
||||
|
||||
/**
|
||||
@ -39,7 +39,7 @@ public class CraftTouchSlimeLine extends CraftHologramLine {
|
||||
|
||||
nmsSlime = HolographicDisplays.getNMSManager().spawnNMSSlime(world, x, y + offset, z, this);
|
||||
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_8)) {
|
||||
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_8_R1)) {
|
||||
nmsVehicle = HolographicDisplays.getNMSManager().spawnNMSArmorStand(world, x, y + offset, z, this);
|
||||
} else {
|
||||
nmsVehicle = HolographicDisplays.getNMSManager().spawnNMSWitherSkull(world, x, y + offset, z, this);
|
||||
@ -100,9 +100,9 @@ public class CraftTouchSlimeLine extends CraftHologramLine {
|
||||
}
|
||||
|
||||
private double getSlimeOffset() {
|
||||
if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_9)) {
|
||||
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_9_R1)) {
|
||||
return Offsets.ARMOR_STAND_WITH_SLIME_1_9;
|
||||
} else if (MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_8)) {
|
||||
} else if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_8_R1)) {
|
||||
return Offsets.ARMOR_STAND_WITH_SLIME;
|
||||
} else {
|
||||
return Offsets.WITHER_SKULL_WITH_SLIME;
|
||||
|
@ -1,55 +0,0 @@
|
||||
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),
|
||||
|
||||
v1_11 = new MinecraftVersion(5),
|
||||
|
||||
v1_12 = new MinecraftVersion(6),
|
||||
|
||||
v1_13 = new MinecraftVersion(7);
|
||||
|
||||
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 MinecraftVersion get() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public static boolean isGreaterEqualThan(MinecraftVersion other) {
|
||||
return MinecraftVersion.version.value >= other.value;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package com.gmail.filoghost.holographicdisplays.util;
|
||||
|
||||
/**
|
||||
* The NMS version is the name of the main package under net.minecraft.server.
|
||||
*/
|
||||
public enum NMSVersion {
|
||||
|
||||
v1_7_R1,
|
||||
v1_7_R2,
|
||||
v1_7_R3,
|
||||
v1_7_R4,
|
||||
v1_8_R1,
|
||||
v1_8_R2,
|
||||
v1_8_R3,
|
||||
v1_9_R1,
|
||||
v1_9_R2,
|
||||
v1_10_R1,
|
||||
v1_11_R1,
|
||||
v1_12_R1,
|
||||
v1_13_R1;
|
||||
|
||||
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 {
|
||||
// Caused by MCPC+ / Cauldron renaming packages, get the NMS version from the Minecraft version.
|
||||
nmsVersionName = VersionUtils.extractMinecraftVersion();
|
||||
|
||||
if ("1.7.2".equals(nmsVersionName)) {
|
||||
return v1_7_R1;
|
||||
} else if ("1.7.5".equals(nmsVersionName)) {
|
||||
return v1_7_R2;
|
||||
} else if ("1.7.8".equals(nmsVersionName)) {
|
||||
return v1_7_R3;
|
||||
} else if ("1.7.10".equals(nmsVersionName)) {
|
||||
return v1_7_R4;
|
||||
} else if ("1.8".equals(nmsVersionName)) {
|
||||
return v1_8_R1;
|
||||
} else if ("1.8.3".equals(nmsVersionName)) {
|
||||
return v1_8_R2;
|
||||
} else {
|
||||
// Cannot definitely get the version. This will cause the plugin to disable itself.
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -22,7 +22,7 @@ public class VersionUtils {
|
||||
* Example: v1_8_R1
|
||||
* @return the NMS package part or null if not found.
|
||||
*/
|
||||
public static String getBukkitVersion() {
|
||||
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();
|
||||
@ -36,7 +36,7 @@ public class VersionUtils {
|
||||
* Example: 1.8.1
|
||||
* @return the version of this release or null if not found.
|
||||
*/
|
||||
public static String getMinecraftVersion() {
|
||||
public static String extractMinecraftVersion() {
|
||||
Matcher matcher = Pattern.compile("(\\(MC: )([\\d\\.]+)(\\))").matcher(Bukkit.getVersion());
|
||||
if (matcher.find()) {
|
||||
return matcher.group(2);
|
||||
@ -58,7 +58,7 @@ public class VersionUtils {
|
||||
}
|
||||
|
||||
public static boolean isArmorstand(EntityType type) {
|
||||
if (!MinecraftVersion.isGreaterEqualThan(MinecraftVersion.v1_8)) {
|
||||
if (!NMSVersion.isGreaterEqualThan(NMSVersion.v1_8_R1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user