diff --git a/build.gradle b/build.gradle index 9f9e742f..b09d2ae6 100644 --- a/build.gradle +++ b/build.gradle @@ -1,8 +1,16 @@ apply plugin: 'java' apply plugin: 'maven-publish' +if(JavaVersion.current() != JavaVersion.VERSION_1_8){ + throw new GradleException("This build must be run with java 8") +} + repositories { mavenCentral() + maven { + url = "https://repo.codemc.io/repository/maven-public/" + allowInsecureProtocol = true + } maven { url "http://mc.hackerzlair.org:8888/repository/public" allowInsecureProtocol = true @@ -11,19 +19,24 @@ repositories { url = "http://repo.extendedclip.com/content/repositories/placeholderapi/" allowInsecureProtocol = true } - } - + maven { + url "https://mvn.lumine.io/repository/maven-public/" + allowInsecureProtocol = true + } + mavenLocal() +} + dependencies { compileOnly ("org.spigotmc:spigot-1.16.5:+") compileOnly ("org.spigotmc:spigot-1.16.3R:+") compileOnly ("org.spigotmc:spigot-1.16.1R:+") - compileOnly ("org.spigotmc:spigot-1.15.2:+") - compileOnly ("org.spigotmc:spigot-1.14.4:+") - compileOnly ("org.spigotmc:spigot-1.13.2:+") - compileOnly ("org.spigotmc:spigot-1.12.2:+") + compileOnly ("org.spigotmc:spigot-1.15.2:+") + compileOnly ("org.spigotmc:spigot-1.14.4:+") + compileOnly ("org.spigotmc:spigot-1.13.2:+") + compileOnly ("org.spigotmc:spigot-1.12.2:+") compileOnly ("com.massivecraft:massivecore:+") compileOnly ("com.massivecraft:factions:+") - compileOnly ("com.gmail.filoghost:holographicdisplays:+") + compileOnly ("me.filoghost.holographicdisplays:holographicdisplays-api:+") compileOnly ("com.comphenix:protocol:+") compileOnly ("com.garbagemule:mobarena:+") compileOnly ("com.sk89q:worldedit:+") @@ -36,6 +49,7 @@ dependencies { compileOnly ("com.palmergames.bukkit.towny:Towny:+") compileOnly ("io.lumine.xikage:mythicmobs:4.12.0") compileOnly ("me.clip:placeholderapi:+") + compileOnly ("io.lumine:MythicLib:1.0.17") } processResources { @@ -54,29 +68,29 @@ processResources { { println("Warning! gradle.properties file is missing!") } - + print("Process resources....") inputs.property "version", project.version from (sourceSets.main.resources.srcDirs) { - include "plugin.yml" - expand "version": project.version + include "plugin.yml" + expand "version": project.version } from (sourceSets.main.resources.srcDirs) { - exclude "plugin.yml" + exclude "plugin.yml" } println("Done!") } compileJava { dependsOn clean - + doLast { print("Create POM file....") - subprojects { - group = 'com.mythicmobsextension' - task generatePom << { pom { }.writeTo("./build/libs/"+project.name+"-"+project.version+".xml") - println("Done!")}} + subprojects { + group = 'com.mythicmobsextension' + task generatePom << { pom { }.writeTo("./build/libs/"+project.name+"-"+project.version+".xml") + println("Done!")}} } - + } diff --git a/gradle.properties b/gradle.properties index 7ad92b86..18651784 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ #Tue Feb 16 14:18:06 CET 2021 group=com.gmail.berndivader -artver=1.739-SNAPSHOT +artver=1.741-SNAPSHOT diff --git a/src/main/java/com/gmail/berndivader/mythicmobsext/NMS/NMSUtils.java b/src/main/java/com/gmail/berndivader/mythicmobsext/NMS/NMSUtils.java index 7f118b61..ec6df6a1 100644 --- a/src/main/java/com/gmail/berndivader/mythicmobsext/NMS/NMSUtils.java +++ b/src/main/java/com/gmail/berndivader/mythicmobsext/NMS/NMSUtils.java @@ -4,9 +4,9 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Server; import org.bukkit.entity.Creature; @@ -69,26 +69,25 @@ public class NMSUtils extends CompatibilityUtils { public static boolean initialize() { boolean bool = com.gmail.berndivader.mythicmobsext.compatibilitylib.NMSUtils.initialize(Main.getPlugin().getLogger()); try { - class_IChatBaseComponent_ChatSerializer = fixBukkitClass( - "net.minecraft.server.IChatBaseComponent$ChatSerializer"); - class_EntitySnowman = fixBukkitClass("net.minecraft.server.EntitySnowman"); + class_IChatBaseComponent_ChatSerializer = fixBukkitClass("IChatBaseComponent$ChatSerializer", true, "network.chat"); + class_EntitySnowman = fixBukkitClass("EntitySnowman", true, "world.entity.animal"); class_Drop = fixBukkitClass("io.lumine.xikage.mythicmobs.drops.Drop"); - class_PathfinderGoalSelector_PathfinderGoalSelectorItem = fixBukkitClass( - Utils.serverV < 14 ? "net.minecraft.server.PathfinderGoalSelector$PathfinderGoalSelectorItem" - : "net.minecraft.server.PathfinderGoalWrapped"); - class_IInventory = fixBukkitClass("net.minecraft.server.IInventory"); - class_CraftInventory = fixBukkitClass("org.bukkit.craftbukkit.inventory.CraftInventory"); + class_PathfinderGoalSelector_PathfinderGoalSelectorItem = fixBukkitClass(Utils.serverV < 14 ? + "PathfinderGoalSelector$PathfinderGoalSelectorItem" : "PathfinderGoalWrapped", + true, "world.entity.ai.goal"); + class_IInventory = fixBukkitClass("IInventory", true, "world"); + class_CraftInventory = fixBukkitClass("inventory.CraftInventory", false); class_MetadataStoreBase = fixBukkitClass("org.bukkit.metadata.MetadataStoreBase"); - class_Entity_lastXField = class_Entity.getDeclaredField("lastX"); + class_Entity_lastXField = class_Entity.getDeclaredField(version < 17 ? "lastX" : "u"); // 1.17 : xo class_Entity_lastXField.setAccessible(true); - class_Entity_lastYField = class_Entity.getDeclaredField("lastY"); + class_Entity_lastYField = class_Entity.getDeclaredField(version < 17 ? "lastY" : "v"); // 1.17 : yo class_Entity_lastYField.setAccessible(true); - class_Entity_lastZField = class_Entity.getDeclaredField("lastZ"); + class_Entity_lastZField = class_Entity.getDeclaredField(version < 17 ? "lastZ" : "w"); // 1.17 : zo class_Entity_lastZField.setAccessible(true); - class_Entity_lastPitchField = class_Entity.getDeclaredField("lastPitch"); + class_Entity_lastPitchField = class_Entity.getDeclaredField(version < 17 ? "lastPitch" : "x"); // 1.17 : yRotO class_Entity_lastPitchField.setAccessible(true); - class_Entity_lastYawField = class_Entity.getDeclaredField("lastYaw"); + class_Entity_lastYawField = class_Entity.getDeclaredField(version < 17 ? "lastYaw" : "y"); // 1.17 : xRotO class_Entity_lastYawField.setAccessible(true); if (Utils.serverV < 14) { @@ -108,16 +107,16 @@ public static boolean initialize() { class_MinecraftServer_currentTickField = class_MinecraftServer.getDeclaredField("currentTick"); class_MinecraftServer_currentTickField.setAccessible(true); - class_Entity_getFlagMethod = class_Entity.getMethod("getFlag", Integer.TYPE); + class_Entity_getFlagMethod = class_Entity.getMethod(version < 18 ? "getFlag" : "h", Integer.TYPE); class_IChatBaseComponent_ChatSerializer_aMethod = class_IChatBaseComponent_ChatSerializer.getMethod("a", String.class); - class_EntityCreature_setGoalTargetMethod = class_EntityCreature.getMethod("setGoalTarget", + class_EntityCreature_setGoalTargetMethod = class_EntityCreature.getMethod(version < 18 ? "setGoalTarget" : "setTarget", class_EntityLiving, TargetReason.class, Boolean.TYPE); - class_EntityPlayer_clearActiveItemMethod = class_EntityPlayer.getMethod("clearActiveItem"); - class_EntityLiving_getArmorStrengthMethod = class_EntityLiving.getMethod("getArmorStrength"); - class_EntitySnowman_setHasPumpkinMethod = class_EntitySnowman.getMethod("setHasPumpkin", Boolean.TYPE); - class_EntityLiving_getArrowCountMethod = class_EntityLiving.getMethod("getArrowCount"); - class_EntityLiving_setArrowCountMethod = class_EntityLiving.getMethod("setArrowCount", Integer.TYPE); + class_EntityPlayer_clearActiveItemMethod = class_EntityPlayer.getMethod(version < 18 ? "clearActiveItem" : "eR"); + class_EntityLiving_getArmorStrengthMethod = class_EntityLiving.getMethod(version < 18 ? "getArmorStrength" : "ei"); + class_EntitySnowman_setHasPumpkinMethod = class_EntitySnowman.getMethod(version < 18 ? "setHasPumpkin" : "v", Boolean.TYPE); + class_EntityLiving_getArrowCountMethod = class_EntityLiving.getMethod(version < 18 ? "getArrowCount" : "em"); + class_EntityLiving_setArrowCountMethod = class_EntityLiving.getMethod("setArrowCount", Integer.TYPE, Boolean.TYPE); class_PathfinderGoalSelector_PathfinderGoalSelectorItem_equalsMethod = class_PathfinderGoalSelector_PathfinderGoalSelectorItem .getMethod("equals", Object.class); @@ -199,11 +198,11 @@ public static float getLastYawFloat(Entity entity) { * @param server {@link Server} * @return int - ticks */ - public static int getCurrentTick(Server s1) { + public static int getCurrentTick(Server server) { int i1 = 0; Object o1; try { - if ((o1 = getHandle(s1)) != null) { + if ((o1 = getHandle(server)) != null) { i1 = class_MinecraftServer_currentTickField.getInt(o1); } } catch (Exception ex) { @@ -452,7 +451,7 @@ public static Drop getDrop(String item_name) { */ @SuppressWarnings("unchecked") public static Map> getEntityMetadataMap(Server server) { - Map> metadata_map = new HashMap>(); + Map> metadata_map = new HashMap<>(); try { Object craft_server = server; Object entity_metadata_store = class_CraftServer_getEntityMetadataStoreMethod.invoke(craft_server); @@ -472,7 +471,7 @@ public static Map> getEntityMetadataMap(Serve */ @SuppressWarnings("unchecked") public static Map> getPlayerMetadataMap(Entity entity) { - Map> metadata_map = new HashMap>(); + Map> metadata_map = new HashMap<>(); try { Object craft_server = entity.getServer(); Object entity_metadata_store = class_CraftServer_getPlayerMetadataStoreMethod.invoke(craft_server); diff --git a/src/main/java/com/gmail/berndivader/mythicmobsext/compatibilitylib/CompatibilityUtils.java b/src/main/java/com/gmail/berndivader/mythicmobsext/compatibilitylib/CompatibilityUtils.java index c8ecab7f..1088adf0 100644 --- a/src/main/java/com/gmail/berndivader/mythicmobsext/compatibilitylib/CompatibilityUtils.java +++ b/src/main/java/com/gmail/berndivader/mythicmobsext/compatibilitylib/CompatibilityUtils.java @@ -71,16 +71,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.Set; -import java.util.UUID; -import java.util.WeakHashMap; +import java.util.*; import java.util.function.Consumer; import java.util.logging.Level; @@ -238,17 +229,17 @@ public static void setInvulnerable(Entity entity) { public static void setInvulnerable(Entity entity, boolean flag) { try { Object handle = getHandle(entity); - class_Entity_invulnerableField.set(handle, flag); + class_Entity_setInvulnerable.invoke(handle, flag); } catch (Exception ex) { ex.printStackTrace(); } } public static boolean isInvulnerable(Entity entity) { - if (class_Entity_invulnerableField == null) return false; + if (class_Entity_isInvulnerable == null) return false; try { Object handle = getHandle(entity); - return (boolean)class_Entity_invulnerableField.get(handle); + return (boolean) class_Entity_isInvulnerable.invoke(handle); } catch (Exception ex) { ex.printStackTrace(); } @@ -518,7 +509,7 @@ public static Runnable getTaskRunnable(BukkitTask task) { public static void ageItem(Item item, int ticksToAge) { try { - Class itemClass = fixBukkitClass("net.minecraft.server.EntityItem"); + Class itemClass = fixBukkitClass("EntityItem", true, "world.entity.item"); Object handle = getHandle(item); Field ageField = itemClass.getDeclaredField("age"); ageField.setAccessible(true); @@ -1126,6 +1117,7 @@ public static boolean setResourcePack(Player player, String rp, byte[] hash) { // TODO: Player.setResourcePack in 1.11+ try { String hashString = BaseEncoding.base16().lowerCase().encode(hash); + // 1.17 : remove initialization of class_EntityPlayer_setResourcePackMethod class_EntityPlayer_setResourcePackMethod.invoke(getHandle(player), rp, hashString); } catch (Exception ex) { ex.printStackTrace(); @@ -1532,13 +1524,18 @@ public static Block getHitBlock(ProjectileHitEvent event) { public static Entity getEntity(World world, UUID uuid) { try { Object worldHandle = getHandle(world); - final Map entityMap = (Map)class_WorldServer_entitiesByUUIDField.get(worldHandle); + Object nmsEntity = class_WorldServer_getEntityMethod.invoke(worldHandle, uuid); + if (nmsEntity != null) { + return getBukkitEntity(nmsEntity); + } + /*final Map entityMap = (Map) class_WorldServer_getEntitiesMethod.invoke(worldHandle); if (entityMap != null) { Object nmsEntity = entityMap.get(uuid); if (nmsEntity != null) { return getBukkitEntity(nmsEntity); } } + */ } catch (Exception ex) { ex.printStackTrace(); } diff --git a/src/main/java/com/gmail/berndivader/mythicmobsext/compatibilitylib/NMSUtils.java b/src/main/java/com/gmail/berndivader/mythicmobsext/compatibilitylib/NMSUtils.java index 3707b435..be40f7c0 100644 --- a/src/main/java/com/gmail/berndivader/mythicmobsext/compatibilitylib/NMSUtils.java +++ b/src/main/java/com/gmail/berndivader/mythicmobsext/compatibilitylib/NMSUtils.java @@ -46,12 +46,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; +import java.util.*; import java.util.function.Consumer; import java.util.logging.Level; import java.util.logging.Logger; @@ -78,6 +73,10 @@ public class NMSUtils { protected static boolean hasTimeSkipEvent = false; protected static String versionPrefix = ""; + protected static int version = -1; + protected static int versionMinor = -1; + protected static String npack = ""; + protected static String cpack = ""; protected final static int NBT_TYPE_COMPOUND = 10; protected final static int NBT_TYPE_INT_ARRAY= 11; @@ -375,14 +374,18 @@ public class NMSUtils { protected static Constructor class_RecipeChoice_ExactChoice_List_constructor; protected static Constructor class_BlockActionContext_constructor; - protected static Field class_Entity_invulnerableField; + protected static Method class_Entity_setInvulnerable; + protected static Method class_Entity_isInvulnerable; + protected static Method class_ItemStack_getTag; + protected static Method class_ItemStack_setTag; + + protected static Method class_WorldServer_getEntityMethod; + protected static Field class_Entity_persistField; protected static Field class_Entity_motXField; protected static Field class_Entity_motYField; protected static Field class_Entity_motZField; protected static Field class_Entity_motField; - protected static Field class_WorldServer_entitiesByUUIDField; - protected static Field class_ItemStack_tagField; protected static Field class_Firework_ticksFlownField; protected static Field class_Firework_expectedLifespanField; protected static Field class_CraftSkull_profile; @@ -445,77 +448,83 @@ public static boolean initialize(Logger logger) { versionPrefix = packages[3] + "."; } - try { - class_Block = fixBukkitClass("net.minecraft.server.Block"); - class_Entity = fixBukkitClass("net.minecraft.server.Entity"); - class_EntityLiving = fixBukkitClass("net.minecraft.server.EntityLiving"); - class_EntityHuman = fixBukkitClass("net.minecraft.server.EntityHuman"); - class_ItemStack = fixBukkitClass("net.minecraft.server.ItemStack"); - class_DataWatcher = fixBukkitClass("net.minecraft.server.DataWatcher"); - class_DataWatcherObject = fixBukkitClass("net.minecraft.server.DataWatcherObject"); - class_NBTBase = fixBukkitClass("net.minecraft.server.NBTBase"); - class_NBTTagCompound = fixBukkitClass("net.minecraft.server.NBTTagCompound"); - class_NBTTagList = fixBukkitClass("net.minecraft.server.NBTTagList"); - class_NBTTagString = fixBukkitClass("net.minecraft.server.NBTTagString"); - class_NBTTagByte = fixBukkitClass("net.minecraft.server.NBTTagByte"); - class_NBTTagDouble = fixBukkitClass("net.minecraft.server.NBTTagDouble"); - class_NBTTagFloat = fixBukkitClass("net.minecraft.server.NBTTagFloat"); - class_NBTTagInt = fixBukkitClass("net.minecraft.server.NBTTagInt"); - class_NBTTagLong = fixBukkitClass("net.minecraft.server.NBTTagLong"); - class_NBTTagShort = fixBukkitClass("net.minecraft.server.NBTTagShort"); - class_CraftWorld = fixBukkitClass("org.bukkit.craftbukkit.CraftWorld"); - class_CraftInventoryCustom = fixBukkitClass("org.bukkit.craftbukkit.inventory.CraftInventoryCustom"); - class_CraftItemStack = fixBukkitClass("org.bukkit.craftbukkit.inventory.CraftItemStack"); - class_CraftBlockState = fixBukkitClass("org.bukkit.craftbukkit.block.CraftBlockState"); - class_CraftTask = fixBukkitClass("org.bukkit.craftbukkit.scheduler.CraftTask"); - class_CraftLivingEntity = fixBukkitClass("org.bukkit.craftbukkit.entity.CraftLivingEntity"); - class_Packet = fixBukkitClass("net.minecraft.server.Packet"); - class_World = fixBukkitClass("net.minecraft.server.World"); - class_WorldServer = fixBukkitClass("net.minecraft.server.WorldServer"); - class_EnumSkyBlock = (Class)fixBukkitClass("net.minecraft.server.EnumSkyBlock"); - class_EnumSoundCategory = (Class)fixBukkitClass("net.minecraft.server.SoundCategory"); + String[] versions = className.replace(".", ",").split(",")[3].substring(1).split("_"); + version = Integer.parseInt(versions[1]); // 1.X + versionMinor = Integer.parseInt(versions[2].substring(1)); // 1.X.Y + npack = "net.minecraft.server." + Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3]; + cpack = Bukkit.getServer().getClass().getPackage().getName() + "."; + + try { + class_Block = fixBukkitClass("Block", true, "world.level.block"); + class_Entity = fixBukkitClass("Entity", true, "world.entity"); + class_EntityLiving = fixBukkitClass("EntityLiving", true, "world.entity"); + class_EntityHuman = fixBukkitClass("EntityHuman", true, "world.entity.player"); + class_ItemStack = fixBukkitClass("ItemStack", true, "world.item"); + class_DataWatcher = fixBukkitClass("DataWatcher", true, "network.syncher"); + class_DataWatcherObject = fixBukkitClass("DataWatcherObject", true, "network.syncher"); + class_NBTBase = fixBukkitClass("NBTBase", true, "nbt"); + class_NBTTagCompound = fixBukkitClass("NBTTagCompound", true, "nbt"); + class_NBTTagList = fixBukkitClass("NBTTagList", true, "nbt"); + class_NBTTagString = fixBukkitClass("NBTTagString", true, "nbt"); + class_NBTTagByte = fixBukkitClass("NBTTagByte", true, "nbt"); + class_NBTTagDouble = fixBukkitClass("NBTTagDouble", true, "nbt"); + class_NBTTagFloat = fixBukkitClass("NBTTagFloat", true, "nbt"); + class_NBTTagInt = fixBukkitClass("NBTTagInt", true, "nbt"); + class_NBTTagLong = fixBukkitClass("NBTTagLong", true, "nbt"); + class_NBTTagShort = fixBukkitClass("NBTTagShort", true, "nbt"); + class_CraftWorld = fixBukkitClass("CraftWorld", false); + class_CraftInventoryCustom = fixBukkitClass("inventory.CraftInventoryCustom", false); + class_CraftItemStack = fixBukkitClass("inventory.CraftItemStack", false); + class_CraftBlockState = fixBukkitClass("block.CraftBlockState", false); + class_CraftTask = fixBukkitClass("scheduler.CraftTask", false); + class_CraftLivingEntity = fixBukkitClass("entity.CraftLivingEntity", false); + class_Packet = fixBukkitClass("Packet", true, "network.protocol"); + class_World = fixBukkitClass("World", true, "world.level"); + class_WorldServer = fixBukkitClass("WorldServer", true, "server.level"); + class_EnumSkyBlock = (Class)fixBukkitClass("EnumSkyBlock", true, "world.level"); + class_EnumSoundCategory = (Class)fixBukkitClass("SoundCategory", true, "sounds"); enum_SoundCategory_PLAYERS = Enum.valueOf(class_EnumSoundCategory, "PLAYERS"); - class_EntityPainting = fixBukkitClass("net.minecraft.server.EntityPainting"); - class_EntityCreature = fixBukkitClass("net.minecraft.server.EntityCreature"); - class_EntityItemFrame = fixBukkitClass("net.minecraft.server.EntityItemFrame"); - class_EntityMinecartRideable = fixBukkitClass("net.minecraft.server.EntityMinecartRideable"); - class_EntityTNTPrimed = fixBukkitClass("net.minecraft.server.EntityTNTPrimed"); - class_AxisAlignedBB = fixBukkitClass("net.minecraft.server.AxisAlignedBB"); - class_DamageSource = fixBukkitClass("net.minecraft.server.DamageSource"); - class_EntityDamageSource = fixBukkitClass("net.minecraft.server.EntityDamageSource"); - class_EntityFirework = fixBukkitClass("net.minecraft.server.EntityFireworks"); - class_CraftSkull = fixBukkitClass("org.bukkit.craftbukkit.block.CraftSkull"); - class_CraftMetaSkull = fixBukkitClass("org.bukkit.craftbukkit.inventory.CraftMetaSkull"); - class_NBTCompressedStreamTools = fixBukkitClass("net.minecraft.server.NBTCompressedStreamTools"); - class_TileEntity = fixBukkitClass("net.minecraft.server.TileEntity"); - class_EntityHorse = fixBukkitClass("net.minecraft.server.EntityHorse"); - class_EntityWitherSkull = fixBukkitClass("net.minecraft.server.EntityWitherSkull"); - class_PacketPlayOutAttachEntity = fixBukkitClass("net.minecraft.server.PacketPlayOutAttachEntity"); - class_PacketPlayOutEntityDestroy = fixBukkitClass("net.minecraft.server.PacketPlayOutEntityDestroy"); - class_PacketPlayOutSpawnEntity = fixBukkitClass("net.minecraft.server.PacketPlayOutSpawnEntity"); - class_PacketPlayOutSpawnEntityLiving = fixBukkitClass("net.minecraft.server.PacketPlayOutSpawnEntityLiving"); - class_PacketPlayOutEntityMetadata = fixBukkitClass("net.minecraft.server.PacketPlayOutEntityMetadata"); - class_PacketPlayOutEntityStatus = fixBukkitClass("net.minecraft.server.PacketPlayOutEntityStatus"); - class_PacketPlayOutExperience = fixBukkitClass("net.minecraft.server.PacketPlayOutExperience"); - class_PacketPlayOutAnimation = fixBukkitClass("net.minecraft.server.PacketPlayOutAnimation"); - class_PacketPlayOutBlockBreakAnimation = fixBukkitClass("net.minecraft.server.PacketPlayOutBlockBreakAnimation"); - class_EntityFallingBlock = fixBukkitClass("net.minecraft.server.EntityFallingBlock"); - class_EntityArmorStand = fixBukkitClass("net.minecraft.server.EntityArmorStand"); - class_EntityPlayer = fixBukkitClass("net.minecraft.server.EntityPlayer"); - class_PlayerConnection = fixBukkitClass("net.minecraft.server.PlayerConnection"); - class_Chunk = fixBukkitClass("net.minecraft.server.Chunk"); - class_CraftPlayer = fixBukkitClass("org.bukkit.craftbukkit.entity.CraftPlayer"); - class_CraftChunk = fixBukkitClass("org.bukkit.craftbukkit.CraftChunk"); - class_CraftEntity = fixBukkitClass("org.bukkit.craftbukkit.entity.CraftEntity"); - class_TileEntitySign = fixBukkitClass("net.minecraft.server.TileEntitySign"); - class_CraftServer = fixBukkitClass("org.bukkit.craftbukkit.CraftServer"); - class_MinecraftServer = fixBukkitClass("net.minecraft.server.MinecraftServer"); - class_BlockPosition = fixBukkitClass("net.minecraft.server.BlockPosition"); - - class_EntityProjectile = NMSUtils.getBukkitClass("net.minecraft.server.EntityProjectile"); - class_EntityFireball = NMSUtils.getBukkitClass("net.minecraft.server.EntityFireball"); - class_EntityArrow = NMSUtils.getBukkitClass("net.minecraft.server.EntityArrow"); - class_CraftArrow = NMSUtils.getBukkitClass("org.bukkit.craftbukkit.entity.CraftArrow"); + class_EntityPainting = fixBukkitClass("EntityPainting", true, "world.entity.decoration"); + class_EntityCreature = fixBukkitClass("EntityCreature", true, "world.entity"); + class_EntityItemFrame = fixBukkitClass("EntityItemFrame", true, "world.entity.decoration"); + class_EntityMinecartRideable = fixBukkitClass("EntityMinecartRideable", true, "world.entity.vehicle"); + class_EntityTNTPrimed = fixBukkitClass("EntityTNTPrimed", true, "world.entity.item"); + class_AxisAlignedBB = fixBukkitClass("AxisAlignedBB", true, "world.phys"); + class_DamageSource = fixBukkitClass("DamageSource", true, "world.damagesource"); + class_EntityDamageSource = fixBukkitClass("EntityDamageSource", true, "world.damagesource"); + class_EntityFirework = fixBukkitClass("EntityFireworks", true, "world.entity.projectile"); + class_CraftSkull = fixBukkitClass("block.CraftSkull", false); + class_CraftMetaSkull = fixBukkitClass("inventory.CraftMetaSkull", false); + class_NBTCompressedStreamTools = fixBukkitClass("NBTCompressedStreamTools", true, "nbt"); + class_TileEntity = fixBukkitClass("TileEntity", true, "world.level.block.entity"); + class_EntityHorse = fixBukkitClass("EntityHorse", true, "world.entity.animal.horse"); + class_EntityWitherSkull = fixBukkitClass("EntityWitherSkull", true, "world.entity.projectile"); + class_PacketPlayOutAttachEntity = fixBukkitClass("PacketPlayOutAttachEntity", true, "network.protocol.game"); + class_PacketPlayOutEntityDestroy = fixBukkitClass("PacketPlayOutEntityDestroy", true, "network.protocol.game"); + class_PacketPlayOutSpawnEntity = fixBukkitClass("PacketPlayOutSpawnEntity", true, "network.protocol.game"); + class_PacketPlayOutSpawnEntityLiving = fixBukkitClass("PacketPlayOutSpawnEntityLiving", true, "network.protocol.game"); + class_PacketPlayOutEntityMetadata = fixBukkitClass("PacketPlayOutEntityMetadata", true, "network.protocol.game"); + class_PacketPlayOutEntityStatus = fixBukkitClass("PacketPlayOutEntityStatus", true, "network.protocol.game"); + class_PacketPlayOutExperience = fixBukkitClass("PacketPlayOutExperience", true, "network.protocol.game"); + class_PacketPlayOutAnimation = fixBukkitClass("PacketPlayOutAnimation", true, "network.protocol.game"); + class_PacketPlayOutBlockBreakAnimation = fixBukkitClass("PacketPlayOutBlockBreakAnimation", true, "network.protocol.game"); + class_EntityFallingBlock = fixBukkitClass("EntityFallingBlock", true,"world.entity.item"); + class_EntityArmorStand = fixBukkitClass("EntityArmorStand", true, "world.entity.decoration"); + class_EntityPlayer = fixBukkitClass("EntityPlayer", true, "server.level"); + class_PlayerConnection = fixBukkitClass("PlayerConnection", true, "server.network"); + class_Chunk = fixBukkitClass("Chunk", true, "world.level.chunk"); + class_CraftPlayer = fixBukkitClass("entity.CraftPlayer", false); + class_CraftChunk = fixBukkitClass("CraftChunk", false); + class_CraftEntity = fixBukkitClass("entity.CraftEntity", false); + class_TileEntitySign = fixBukkitClass("TileEntitySign", true, "world.level.block.entity"); + class_CraftServer = fixBukkitClass("CraftServer", false); + class_MinecraftServer = fixBukkitClass("MinecraftServer", true, "server"); + class_BlockPosition = fixBukkitClass("BlockPosition", true, "core"); + + class_EntityProjectile = fixBukkitClass("EntityProjectile", true, "world.entity.projectile"); + class_EntityFireball = fixBukkitClass("EntityFireball", true, "world.entity.projectile"); + class_EntityArrow = fixBukkitClass("EntityArrow", true, "world.entity.projectile"); + class_CraftArrow = fixBukkitClass("entity.CraftArrow", false); class_Entity_getBukkitEntityMethod = class_Entity.getMethod("getBukkitEntity"); class_Entity_setYawPitchMethod = class_Entity.getDeclaredMethod("setYawPitch", Float.TYPE, Float.TYPE); @@ -548,7 +557,8 @@ public static boolean initialize(Logger logger) { class_CraftLivingEntity_getHandleMethod = class_CraftLivingEntity.getMethod("getHandle"); class_CraftWorld_getHandleMethod = class_CraftWorld.getMethod("getHandle"); class_EntityPlayer_openSignMethod = class_EntityPlayer.getMethod("openSign", class_TileEntitySign); - class_EntityPlayer_setResourcePackMethod = class_EntityPlayer.getMethod("setResourcePack", String.class, String.class); + // 1.17 : remove because it's setResourcePack(String, String, boolean, IChatBaseComponent) +// class_EntityPlayer_setResourcePackMethod = class_EntityPlayer.getMethod("setResourcePack", String.class, String.class); class_CraftServer_getServerMethod = class_CraftServer.getMethod("getServer"); class_MinecraftServer_getResourcePackMethod = class_MinecraftServer.getMethod("getResourcePack"); @@ -565,17 +575,18 @@ public static boolean initialize(Logger logger) { class_CraftWorld_environmentField = class_CraftWorld.getDeclaredField("environment"); class_CraftWorld_environmentField.setAccessible(true); - class_Entity_invulnerableField = class_Entity.getDeclaredField("invulnerable"); - class_Entity_invulnerableField.setAccessible(true); - class_ItemStack_tagField = class_ItemStack.getDeclaredField("tag"); - class_ItemStack_tagField.setAccessible(true); - class_EntityTNTPrimed_source = class_EntityTNTPrimed.getDeclaredField("source"); - class_EntityTNTPrimed_source.setAccessible(true); - class_EntityPlayer_playerConnectionField = class_EntityPlayer.getDeclaredField("playerConnection"); - - class_Firework_ticksFlownField = class_EntityFirework.getDeclaredField("ticksFlown"); + class_Entity_setInvulnerable = class_Entity.getDeclaredMethod("setInvulnerable", boolean.class); + class_Entity_isInvulnerable = class_Entity.getDeclaredMethod("isInvulnerable"); + + class_ItemStack_getTag = class_ItemStack.getDeclaredMethod("getTag"); + class_ItemStack_setTag = class_ItemStack.getDeclaredMethod("setTag", class_NBTTagCompound); + + class_EntityTNTPrimed_source = class_EntityTNTPrimed.getDeclaredField(version < 17 ? "source" : "d"); // 1.17 : owner + class_EntityPlayer_playerConnectionField = class_EntityPlayer.getDeclaredField(version < 17 ? "playerConnection" : "b"); // 1.17 : connection + + class_Firework_ticksFlownField = class_EntityFirework.getDeclaredField(version < 17 ? "ticksFlown" : "e"); // 1.17 : life class_Firework_ticksFlownField.setAccessible(true); - class_Firework_expectedLifespanField = class_EntityFirework.getDeclaredField("expectedLifespan"); + class_Firework_expectedLifespanField = class_EntityFirework.getDeclaredField(version < 17 ? "expectedLifespan" : "f"); // 1.17 : lifetime class_Firework_expectedLifespanField.setAccessible(true); class_NBTTagCompound_constructor = class_NBTTagCompound.getConstructor(); @@ -587,33 +598,33 @@ public static boolean initialize(Logger logger) { class_NBTTagFloat_constructor = new NBTConstructor(class_NBTTagFloat, Float.TYPE); class_NBTTagLong_constructor = new NBTConstructor(class_NBTTagLong, Long.TYPE); - Class class_NBTTagIntArray = fixBukkitClass("net.minecraft.server.NBTTagIntArray"); - Class class_NBTTagByteArray = fixBukkitClass("net.minecraft.server.NBTTagByteArray"); + Class class_NBTTagIntArray = fixBukkitClass("NBTTagIntArray", true, "nbt"); + Class class_NBTTagByteArray = fixBukkitClass("NBTTagByteArray", true, "nbt"); class_NBTTagIntArray_constructor = class_NBTTagIntArray.getConstructor(int[].class); class_NBTTagByteArray_constructor = class_NBTTagByteArray.getConstructor(byte[].class); try { - Class class_NBTTagLongArray = fixBukkitClass("net.minecraft.server.NBTTagLongArray"); + Class class_NBTTagLongArray = fixBukkitClass("NBTTagLongArray", true, "nbt"); class_NBTTagLongArray_constructor = class_NBTTagLongArray.getConstructor(long[].class); } catch (Throwable ignore) { class_NBTTagLongArray_constructor = null; } - class_NBTTagList_list = class_NBTTagList.getDeclaredField("list"); + class_NBTTagList_list = class_NBTTagList.getDeclaredField(version < 17 ? "list" : "w"); class_NBTTagList_list.setAccessible(true); - class_NBTTagByte_dataField = class_NBTTagByte.getDeclaredField("data"); + class_NBTTagByte_dataField = class_NBTTagByte.getDeclaredField(version < 17 ? "data" : "x"); class_NBTTagByte_dataField.setAccessible(true); - class_NBTTagDouble_dataField = class_NBTTagDouble.getDeclaredField("data"); + class_NBTTagDouble_dataField = class_NBTTagDouble.getDeclaredField(version < 17 ? "data" : "w"); class_NBTTagDouble_dataField.setAccessible(true); - class_NBTTagFloat_dataField = class_NBTTagFloat.getDeclaredField("data"); + class_NBTTagFloat_dataField = class_NBTTagFloat.getDeclaredField(version < 17 ? "data" : "w"); class_NBTTagFloat_dataField.setAccessible(true); - class_NBTTagInt_dataField = class_NBTTagInt.getDeclaredField("data"); + class_NBTTagInt_dataField = class_NBTTagInt.getDeclaredField(version < 17 ? "data" : "c"); class_NBTTagInt_dataField.setAccessible(true); - class_NBTTagLong_dataField = class_NBTTagLong.getDeclaredField("data"); + class_NBTTagLong_dataField = class_NBTTagLong.getDeclaredField(version < 17 ? "data" : "c"); class_NBTTagLong_dataField.setAccessible(true); - class_NBTTagShort_dataField = class_NBTTagShort.getDeclaredField("data"); + class_NBTTagShort_dataField = class_NBTTagShort.getDeclaredField(version < 17 ? "data" : "c"); class_NBTTagShort_dataField.setAccessible(true); - class_NBTTagString_dataField = class_NBTTagString.getDeclaredField("data"); + class_NBTTagString_dataField = class_NBTTagString.getDeclaredField(version < 17 ? "data" : "A"); class_NBTTagString_dataField.setAccessible(true); class_NBTTagList_getMethod = class_NBTTagList.getMethod("get", Integer.TYPE); class_NBTTagList_sizeMethod = class_NBTTagList.getMethod("size"); @@ -623,21 +634,21 @@ public static boolean initialize(Logger logger) { class_NBTTagCompound_getMethod = class_NBTTagCompound.getMethod("get", String.class); class_NBTTagCompound_getCompoundMethod = class_NBTTagCompound.getMethod("getCompound", String.class); - class_EntityFallingBlock_hurtEntitiesField = class_EntityFallingBlock.getDeclaredField("hurtEntities"); + class_EntityFallingBlock_hurtEntitiesField = class_EntityFallingBlock.getDeclaredField(version < 17 ? "hurtEntities" : "ap"); class_EntityFallingBlock_hurtEntitiesField.setAccessible(true); - class_EntityFallingBlock_fallHurtAmountField = class_EntityFallingBlock.getDeclaredField("fallHurtAmount"); + class_EntityFallingBlock_fallHurtAmountField = class_EntityFallingBlock.getDeclaredField(version < 17 ? "fallHurtAmount" : "ar"); // 1.17 : fallDamagePerDistance class_EntityFallingBlock_fallHurtAmountField.setAccessible(true); - class_EntityFallingBlock_fallHurtMaxField = class_EntityFallingBlock.getDeclaredField("fallHurtMax"); + class_EntityFallingBlock_fallHurtMaxField = class_EntityFallingBlock.getDeclaredField(version < 17 ? "fallHurtMax" : "aq"); // 1.17 : fallDamageMax class_EntityFallingBlock_fallHurtMaxField.setAccessible(true); class_CraftItemStack_getHandleField = class_CraftItemStack.getDeclaredField("handle"); class_CraftItemStack_getHandleField.setAccessible(true); - + class_MemorySection_mapField = MemorySection.class.getDeclaredField("map"); class_MemorySection_mapField.setAccessible(true); - - class_TileEntityContainer = fixBukkitClass("net.minecraft.server.TileEntityContainer"); - class_ChestLock = fixBukkitClass("net.minecraft.server.ChestLock"); + + class_TileEntityContainer = fixBukkitClass("TileEntityContainer", true, "world.level.block.entity"); + class_ChestLock = fixBukkitClass("ChestLock", true, "world"); class_Entity_getBoundingBox = class_Entity.getMethod("getBoundingBox"); class_GameProfile = getClass("com.mojang.authlib.GameProfile"); class_GameProfile_constructor = class_GameProfile.getConstructor(UUID.class, String.class); @@ -657,14 +668,13 @@ public static boolean initialize(Logger logger) { class_GameProfileProperty_constructor = class_GameProfileProperty.getConstructor(String.class, String.class, String.class); class_GameProfileProperty_noSignatureConstructor = class_GameProfileProperty.getConstructor(String.class, String.class); - class_EnumDirection = (Class)fixBukkitClass("net.minecraft.server.EnumDirection"); + class_EnumDirection = (Class)fixBukkitClass("EnumDirection", true, "core"); class_BlockPosition_Constructor = class_BlockPosition.getConstructor(Double.TYPE, Double.TYPE, Double.TYPE); class_EntityPaintingConstructor = class_EntityPainting.getConstructor(class_World, class_BlockPosition, class_EnumDirection); class_EntityItemFrameConstructor = class_EntityItemFrame.getConstructor(class_World, class_BlockPosition, class_EnumDirection); // TODO: Server.getEntity(UUID) in 1.11+ - class_WorldServer_entitiesByUUIDField = class_WorldServer.getDeclaredField("entitiesByUUID"); - class_WorldServer_entitiesByUUIDField.setAccessible(true); + class_WorldServer_getEntityMethod = class_WorldServer.getDeclaredMethod("getEntity", UUID.class); // TODO: World.getNearbyEntities in 1.11+ class_AxisAlignedBB_Constructor = class_AxisAlignedBB.getConstructor(Double.TYPE, Double.TYPE, Double.TYPE, Double.TYPE, Double.TYPE, Double.TYPE); @@ -718,12 +728,12 @@ public static boolean initialize(Logger logger) { } try { - Class class_CraftArt = fixBukkitClass("org.bukkit.craftbukkit.CraftArt"); + Class class_CraftArt = fixBukkitClass("CraftArt", false); class_CraftArt_NotchToBukkitMethod = class_CraftArt.getMethod("BukkitToNotch", Art.class); - Class class_EntityPainting = fixBukkitClass("net.minecraft.server.EntityPainting"); + Class class_EntityPainting = fixBukkitClass("EntityPainting", true, "world.entity.decoration"); class_EntityPainting_art = class_EntityPainting.getDeclaredField("art"); class_EntityPainting_art.setAccessible(true); - Class class_EntityHanging = fixBukkitClass("net.minecraft.server.EntityHanging"); + Class class_EntityHanging = fixBukkitClass("EntityHanging", true, "world.entity.decoration"); class_EntityHanging_blockPosition = class_EntityHanging.getField("blockPosition"); class_EntityHanging_blockPosition.setAccessible(true); class_BlockPosition_getXMethod = class_BlockPosition.getMethod("getX"); @@ -801,9 +811,9 @@ public static boolean initialize(Logger logger) { class_Material_isLegacyMethod = Material.class.getMethod("isLegacy"); class_Material_getLegacyMethod = Material.class.getMethod("getMaterial", String.class, Boolean.TYPE); - class_MinecraftKey = fixBukkitClass("net.minecraft.server.MinecraftKey"); + class_MinecraftKey = fixBukkitClass("MinecraftKey", true, "resources"); class_MinecraftKey_constructor = class_MinecraftKey.getConstructor(String.class); - class_Vec3D = fixBukkitClass("net.minecraft.server.Vec3D"); + class_Vec3D = fixBukkitClass("Vec3D", true, "world.phys"); class_Vec3D_constructor = class_Vec3D.getConstructor(Double.TYPE, Double.TYPE, Double.TYPE); Class class_BlockData = Class.forName("org.bukkit.block.data.BlockData"); @@ -866,7 +876,7 @@ public static boolean initialize(Logger logger) { // 1.14 Support try { - class_EnumExplosionEffect = (Class)fixBukkitClass("net.minecraft.server.Explosion$Effect"); + class_EnumExplosionEffect = (Class)fixBukkitClass("Explosion$Effect", true, "world.level"); enum_ExplosionEffect_BREAK = Enum.valueOf(class_EnumExplosionEffect, "BREAK"); enum_ExplosionEffect_NONE = Enum.valueOf(class_EnumExplosionEffect, "NONE"); class_World_explodeMethod = class_World.getMethod("createExplosion", class_Entity, Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Boolean.TYPE, class_EnumExplosionEffect); @@ -884,7 +894,7 @@ public static boolean initialize(Logger logger) { if (isCurrentVersion) { try { entityTypes = new HashMap<>(); - class_entityTypes = fixBukkitClass("net.minecraft.server.EntityTypes"); + class_entityTypes = fixBukkitClass("EntityTypes", true, "world.entity"); for (Field field : class_entityTypes.getFields()) { if (field.getType().equals(class_entityTypes)) { Object entityType = field.get(null); @@ -957,7 +967,7 @@ public static boolean initialize(Logger logger) { } try { - class_PacketPlayOutCustomSoundEffect = fixBukkitClass("net.minecraft.server.PacketPlayOutCustomSoundEffect"); + class_PacketPlayOutCustomSoundEffect = fixBukkitClass("PacketPlayOutCustomSoundEffect", true, "network.protocol.game"); if (class_MinecraftKey_constructor != null) { class_PacketPlayOutCustomSoundEffect_Constructor = class_PacketPlayOutCustomSoundEffect.getConstructor(class_MinecraftKey, class_EnumSoundCategory, class_Vec3D, Float.TYPE, Float.TYPE); @@ -969,11 +979,11 @@ public static boolean initialize(Logger logger) { } try { - Class class_ItemBoneMeal = fixBukkitClass("net.minecraft.server.ItemBoneMeal"); + Class class_ItemBoneMeal = fixBukkitClass("ItemBoneMeal", true, "world.item"); class_ItemDye_bonemealMethod = class_ItemBoneMeal.getMethod("a", class_ItemStack, class_World, class_BlockPosition); } catch (Throwable not13) { try { - Class class_ItemDye = fixBukkitClass("net.minecraft.server.ItemDye"); + Class class_ItemDye = fixBukkitClass("ItemDye", true, "world.item"); class_ItemDye_bonemealMethod = class_ItemDye.getMethod("a", class_ItemStack, class_World, class_BlockPosition); } catch (Throwable ex) { class_ItemDye_bonemealMethod = null; @@ -1022,7 +1032,7 @@ public static boolean initialize(Logger logger) { class_NBTTagList_getDoubleMethod = null; } try { - Class class_IBlockData = fixBukkitClass("net.minecraft.server.IBlockData"); + Class class_IBlockData = fixBukkitClass("IBlockData", true, "world.level.block.state"); class_World_getTypeMethod = class_World.getMethod("getType", class_BlockPosition); class_World_setTypeAndDataMethod = class_World.getMethod("setTypeAndData", class_BlockPosition, class_IBlockData, Integer.TYPE); } catch (Throwable ex) { @@ -1040,7 +1050,8 @@ public static boolean initialize(Logger logger) { Field damageSource_MagicField = class_DamageSource.getField("MAGIC"); object_magicSource = damageSource_MagicField.get(null); } catch (Throwable ex) { - getLogger().log(Level.WARNING, "An error occurred, magic damage will not work, using normal damage instead", ex); + getLogger().log(Level.WARNING, "An error occurred, magic damage will not work, using normal damage instead"); + //getLogger().log(Level.WARNING, "An error occurred, magic damage will not work, using normal damage instead", ex); class_EntityLiving_damageEntityMethod = null; class_DamageSource_getMagicSourceMethod = null; object_magicSource = null; @@ -1051,7 +1062,7 @@ public static boolean initialize(Logger logger) { class_EntityHuman_getBedMethod = class_EntityPlayer.getMethod("getSpawn"); class_EntityPlayer_getSpawnDimensionMethod = class_EntityPlayer.getMethod("getSpawnDimension"); class_EntityPlayer_serverField = class_EntityPlayer.getField("server"); - Class class_resourceKey = fixBukkitClass("net.minecraft.server.ResourceKey"); + Class class_resourceKey = fixBukkitClass("ResourceKey", true, "resources"); class_MinecraftServer_getWorldServerMethod = class_MinecraftServer.getMethod("getWorldServer", class_resourceKey); class_WorldServer_worldMethod = class_WorldServer.getMethod("getWorld"); } catch (Exception notCurrent) { @@ -1060,7 +1071,8 @@ public static boolean initialize(Logger logger) { } } catch (Throwable ex) { class_EntityHuman_getBedMethod = null; - getLogger().log(Level.WARNING, "An error occurred, could not get bed location directly, will use API", ex); + getLogger().log(Level.WARNING, "An error occurred, could not get bed location directly, will use API"); + //getLogger().log(Level.WARNING, "An error occurred, could not get bed location directly, will use API", ex); } try { @@ -1085,7 +1097,7 @@ public static boolean initialize(Logger logger) { } } try { - Class class_IBlockData = fixBukkitClass("net.minecraft.server.IBlockData"); + Class class_IBlockData = fixBukkitClass("IBlockData", true, "world.level.block.state"); class_Block_fromLegacyData = class_Block.getMethod("fromLegacyData", Integer.TYPE); class_Chunk_setBlockMethod = class_Chunk.getMethod("a", class_BlockPosition, class_IBlockData); } catch (Throwable ex) { @@ -1280,31 +1292,33 @@ public static boolean initialize(Logger logger) { } } } catch (Throwable ex) { - getLogger().log(Level.WARNING, "An error occurred while registering entity movement accessors, vehicle control will not work", ex); + getLogger().log(Level.WARNING, "An error occurred while registering entity movement accessors, vehicle control will not work"); + //getLogger().log(Level.WARNING, "An error occurred while registering entity movement accessors, vehicle control will not work", ex); class_Entity_jumpingField = null; class_Entity_moveStrafingField = null; class_Entity_moveForwardField = null; } try { - class_BlockBase = fixBukkitClass("net.minecraft.server.BlockBase"); + class_BlockBase = fixBukkitClass("BlockBase", true, "world.level.block.state"); class_Block_durabilityField = class_BlockBase.getDeclaredField("durability"); class_Block_durabilityField.setAccessible(true); } catch (Exception not16) { try { class_Block_durabilityField = class_Block.getDeclaredField("durability"); class_Block_durabilityField.setAccessible(true); - Class craftMagicNumbers = fixBukkitClass("org.bukkit.craftbukkit.util.CraftMagicNumbers"); + Class craftMagicNumbers = fixBukkitClass("util.CraftMagicNumbers", false); class_CraftMagicNumbers_getBlockMethod = craftMagicNumbers.getMethod("getBlock", Material.class); } catch (Throwable ex) { - getLogger().log(Level.WARNING, "An error occurred while registering block durability accessor, durability-based block checks will not work", ex); + getLogger().log(Level.WARNING, "An error occurred while registering block durability accessor, durability-based block checks will not work"); + //getLogger().log(Level.WARNING, "An error occurred while registering block durability accessor, durability-based block checks will not work", ex); class_Block_durabilityField = null; class_CraftMagicNumbers_getBlockMethod = null; } } try { - Class craftMagicNumbers = fixBukkitClass("org.bukkit.craftbukkit.util.CraftMagicNumbers"); + Class craftMagicNumbers = fixBukkitClass("util.CraftMagicNumbers", false); class_CraftMagicNumbers_getBlockMethod = craftMagicNumbers.getMethod("getBlock", Material.class); } catch (Throwable ex) { getLogger().log(Level.WARNING, "An error occurred while registering block accessor, durability-based block checks will not work", ex); @@ -1315,13 +1329,13 @@ public static boolean initialize(Logger logger) { // 1.12 try { // Common to 1.12 and below - class_PacketPlayOutChat = fixBukkitClass("net.minecraft.server.PacketPlayOutChat"); - class_ChatComponentText = fixBukkitClass("net.minecraft.server.ChatComponentText"); - class_IChatBaseComponent = fixBukkitClass("net.minecraft.server.IChatBaseComponent"); + class_PacketPlayOutChat = fixBukkitClass("PacketPlayOutChat", true, "network.protocol.game"); + class_ChatComponentText = fixBukkitClass("ChatComponentText", true, "network.chat"); + class_IChatBaseComponent = fixBukkitClass("IChatBaseComponent", true, "network.chat"); class_ChatComponentText_constructor = class_ChatComponentText.getConstructor(String.class); // Common to 1.16 and below - class_ChatMessageType = (Class)fixBukkitClass("net.minecraft.server.ChatMessageType"); + class_ChatMessageType = (Class)fixBukkitClass("ChatMessageType", true, "network.chat"); enum_ChatMessageType_GAME_INFO = Enum.valueOf(class_ChatMessageType, "GAME_INFO"); // 1.16 specific @@ -1363,7 +1377,7 @@ public static boolean initialize(Logger logger) { try { try { - class_IBlockData = fixBukkitClass("net.minecraft.server.IBlockData"); + class_IBlockData = fixBukkitClass("IBlockData", true, "world.level.block.state"); class_TileEntity_loadMethod = class_TileEntity.getMethod("load", class_IBlockData, class_NBTTagCompound); } catch (Throwable not16) { class_IBlockData = null; @@ -1501,7 +1515,8 @@ public static boolean initialize(Logger logger) { } } } catch (Throwable ex) { - getLogger().log(Level.WARNING, "An error occurred, chest locking and unlocking will not work", ex); + getLogger().log(Level.WARNING, "An error occurred, chest locking and unlocking will not work"); + //getLogger().log(Level.WARNING, "An error occurred, chest locking and unlocking will not work", ex); class_TileEntityContainer_setLock = null; class_TileEntityContainer_getLock = null; } @@ -1519,13 +1534,14 @@ public static boolean initialize(Logger logger) { class_PlayerConnection_floatCountField.setAccessible(true); } } catch (Throwable ex) { - getLogger().log(Level.WARNING, "An error occurred, player flight exemption will not work", ex); + getLogger().log(Level.WARNING, "An error occurred, player flight exemption will not work"); + //getLogger().log(Level.WARNING, "An error occurred, player flight exemption will not work", ex); class_PlayerConnection_floatCountField = null; } try { try { // Purpur fork - Class class_IProjectile = fixBukkitClass("net.minecraft.server.IProjectile"); + Class class_IProjectile = fixBukkitClass("IProjectile", true, "world.entity.projectile"); class_EntityArrow_lifeField = class_IProjectile.getDeclaredField("despawnCounter"); } catch (Throwable ignore) { try { @@ -1571,7 +1587,8 @@ public static boolean initialize(Logger logger) { } } } catch (Throwable ex) { - getLogger().log(Level.WARNING, "An error occurred, thorn damage override to hurt ender dragon will not work", ex); + getLogger().log(Level.WARNING, "An error occurred, thorn damage override to hurt ender dragon will not work"); + //getLogger().log(Level.WARNING, "An error occurred, thorn damage override to hurt ender dragon will not work", ex); class_EntityDamageSource_setThornsMethod = null; } @@ -1592,7 +1609,8 @@ public static boolean initialize(Logger logger) { class_Entity_saveMethod = class_Entity.getMethod("e", class_NBTTagCompound); } } catch (Throwable ex) { - getLogger().log(Level.WARNING, "An error occurred, saving entities to spawn eggs will not work", ex); + getLogger().log(Level.WARNING, "An error occurred, saving entities to spawn eggs will not work"); + //getLogger().log(Level.WARNING, "An error occurred, saving entities to spawn eggs will not work", ex); class_Entity_getTypeMethod = null; class_Entity_saveMethod = null; } @@ -1611,7 +1629,8 @@ public static boolean initialize(Logger logger) { class_ItemStack_createStackMethod = class_ItemStack.getMethod("createStack", class_NBTTagCompound); } } catch (Throwable ex) { - getLogger().log(Level.WARNING, "An error occurred, restoring inventories from schematics will not work", ex); + getLogger().log(Level.WARNING, "An error occurred, restoring inventories from schematics will not work"); + //getLogger().log(Level.WARNING, "An error occurred, restoring inventories from schematics will not work", ex); class_ItemStack_createStackMethod = null; } @@ -1619,7 +1638,8 @@ public static boolean initialize(Logger logger) { class_EntityArrow_damageField = class_EntityArrow.getDeclaredField("damage"); class_EntityArrow_damageField.setAccessible(true); } catch (Throwable ex) { - getLogger().log(Level.WARNING, "An error occurred, setting arrow damage will not work", ex); + getLogger().log(Level.WARNING, "An error occurred, setting arrow damage will not work"); + //getLogger().log(Level.WARNING, "An error occurred, setting arrow damage will not work", ex); class_EntityArrow_damageField = null; } @@ -1636,7 +1656,8 @@ public static boolean initialize(Logger logger) { class_Entity_isSilentMethod = class_Entity.getDeclaredMethod("ad"); } } catch (Throwable ex) { - getLogger().log(Level.WARNING, "An error occurred, silent entities will not work", ex); + getLogger().log(Level.WARNING, "An error occurred, silent entities will not work"); + //getLogger().log(Level.WARNING, "An error occurred, silent entities will not work", ex); class_Entity_setSilentMethod = null; class_Entity_isSilentMethod = null; } @@ -1669,14 +1690,14 @@ public static boolean initialize(Logger logger) { // Auto block state creation try { - class_CraftBlock = fixBukkitClass("org.bukkit.craftbukkit.block.CraftBlock"); + class_CraftBlock = fixBukkitClass("block.CraftBlock"); class_CraftBlock_getNMSBlockMethod = class_CraftBlock.getDeclaredMethod("getNMSBlock"); class_CraftBlock_getNMSBlockMethod.setAccessible(true); - class_BlockActionContext = fixBukkitClass("net.minecraft.server.BlockActionContext"); + class_BlockActionContext = fixBukkitClass("BlockActionContext", true, "world.item.context"); class_Block_getPlacedStateMethod = class_Block.getMethod("getPlacedState", class_BlockActionContext); - class_EnumHand = (Class)fixBukkitClass("net.minecraft.server.EnumHand"); + class_EnumHand = (Class)fixBukkitClass("EnumHand", true, "world"); enum_EnumHand_MAIN_HAND = Enum.valueOf(class_EnumHand, "MAIN_HAND"); - class_MovingObjectPositionBlock = fixBukkitClass("net.minecraft.server.MovingObjectPositionBlock"); + class_MovingObjectPositionBlock = fixBukkitClass("MovingObjectPositionBlock", true, "world.phys"); class_BlockActionContext_constructor = class_BlockActionContext.getDeclaredConstructor(class_World, class_EntityHuman, class_EnumHand, class_ItemStack, class_MovingObjectPositionBlock); class_BlockActionContext_constructor.setAccessible(true); class_MovingObjectPositionBlock_createMethod = class_MovingObjectPositionBlock.getMethod("a", class_Vec3D, class_EnumDirection, class_BlockPosition); @@ -1692,7 +1713,8 @@ public static boolean initialize(Logger logger) { } catch (Throwable ex) { failed = true; - getLogger().log(Level.SEVERE, "An unexpected error occurred initializing Magic", ex); + getLogger().log(Level.SEVERE, "An unexpected error occurred initializing Magic"); + //getLogger().log(Level.SEVERE, "An unexpected error occurred initializing Magic", ex); } return !failed; @@ -1726,23 +1748,21 @@ public static Class getClass(String className) { return result; } - public static Class getBukkitClass(String className) { - Class result = null; - try { - result = fixBukkitClass(className); - } catch (Exception ex) { - result = null; + public static Class fixBukkitClass(String className, boolean nms, String package17) throws ClassNotFoundException { + if (nms) { + className = (version < 17 ? npack : "net.minecraft." + package17) + "." + className; + } else { + className = cpack + className; } - return result; + return NMSUtils.class.getClassLoader().loadClass(className); } - public static Class fixBukkitClass(String className) throws ClassNotFoundException { - if (!versionPrefix.isEmpty()) { - className = className.replace("org.bukkit.craftbukkit.", "org.bukkit.craftbukkit." + versionPrefix); - className = className.replace("net.minecraft.server.", "net.minecraft.server." + versionPrefix); - } + public static Class fixBukkitClass(String className, boolean nms) throws ClassNotFoundException { + return fixBukkitClass(className, nms, null); + } + public static Class fixBukkitClass(String className) throws ClassNotFoundException { return NMSUtils.class.getClassLoader().loadClass(className); } @@ -1901,7 +1921,7 @@ public static org.bukkit.entity.Entity getBukkitEntity(Object entity) public static Object getTag(Object mcItemStack) { Object tag = null; try { - tag = class_ItemStack_tagField.get(mcItemStack); + tag = class_ItemStack_getTag.invoke(mcItemStack); } catch (Throwable ex) { ex.printStackTrace(); } @@ -1943,9 +1963,9 @@ public static ItemStack makeReal(ItemStack stack) { return null; } try { - Object tag = class_ItemStack_tagField.get(nmsStack); + Object tag = class_ItemStack_getTag.invoke(nmsStack); if (tag == null) { - class_ItemStack_tagField.set(nmsStack, class_NBTTagCompound_constructor.newInstance()); + class_ItemStack_setTag.invoke(nmsStack, class_NBTTagCompound_constructor.newInstance()); } } catch (Throwable ex) { ex.printStackTrace(); @@ -1970,7 +1990,7 @@ public static Object getTag(ItemStack itemStack) { try { Object mcItemStack = getHandle(itemStack); if (mcItemStack == null) return null; - tag = class_ItemStack_tagField.get(mcItemStack); + tag = class_ItemStack_getTag.invoke(mcItemStack); } catch (Throwable ex) { ex.printStackTrace(); } @@ -2036,7 +2056,7 @@ public static Object createNode(ItemStack stack, String tag) { Object tagObject = getTag(craft); if (tagObject == null) { tagObject = class_NBTTagCompound_constructor.newInstance(); - class_ItemStack_tagField.set(craft, tagObject); + class_ItemStack_setTag.invoke(craft, tagObject); } outputObject = class_NBTTagCompound_constructor.newInstance(); class_NBTTagCompound_setMethod.invoke(tagObject, tag, outputObject); diff --git a/src/main/java/com/gmail/berndivader/mythicmobsext/conditions/OwnsMMOItem.java b/src/main/java/com/gmail/berndivader/mythicmobsext/conditions/OwnsMMOItem.java new file mode 100644 index 00000000..7bc0f649 --- /dev/null +++ b/src/main/java/com/gmail/berndivader/mythicmobsext/conditions/OwnsMMOItem.java @@ -0,0 +1,39 @@ +package com.gmail.berndivader.mythicmobsext.conditions; + +import org.bukkit.entity.Player; + +import com.gmail.berndivader.mythicmobsext.externals.ExternalAnnotation; + +import io.lumine.mythic.lib.api.item.NBTItem; +import io.lumine.xikage.mythicmobs.adapters.AbstractEntity; +import io.lumine.xikage.mythicmobs.io.MythicLineConfig; +import io.lumine.xikage.mythicmobs.skills.conditions.IEntityCondition; + +@ExternalAnnotation(name = "ownsmmoitem,ownsmi", author = "Ulti") +public class OwnsMMOItem extends AbstractCustomCondition implements IEntityCondition { + private String Type; + private String ID; + + public OwnsMMOItem(String line, MythicLineConfig mlc) { + super(line, mlc); + Type = mlc.getString("type", "ANY"); + ID = mlc.getString("id", "ANY"); + } + + @Override + public boolean check(AbstractEntity target) { + Player player = ((Player) target.getBukkitEntity()); + NBTItem nbtItem = NBTItem.get(player.getEquipment().getItemInMainHand()); + System.out.println("pre-test"); + if(nbtItem.hasType() && nbtItem.getType() == Type) { + System.out.println("has a type and is of the specific type"); + if(nbtItem.getString("MMOITEMS_ITEM_ID") == ID) { + System.out.println("the right ID"); + return true; + } + System.out.println("Not the right ID"); + } + System.out.println("not the type or doesn't have a type"); + return false; + } +} diff --git a/src/main/java/com/gmail/berndivader/mythicmobsext/healthbar/Healthbar.java b/src/main/java/com/gmail/berndivader/mythicmobsext/healthbar/Healthbar.java index 55309eee..169d6cb3 100644 --- a/src/main/java/com/gmail/berndivader/mythicmobsext/healthbar/Healthbar.java +++ b/src/main/java/com/gmail/berndivader/mythicmobsext/healthbar/Healthbar.java @@ -2,6 +2,11 @@ import java.util.UUID; +import com.gmail.berndivader.mythicmobsext.Main; +import me.filoghost.holographicdisplays.api.beta.HolographicDisplaysAPI; +import me.filoghost.holographicdisplays.api.beta.hologram.Hologram; +import me.filoghost.holographicdisplays.api.beta.hologram.VisibilitySettings; +import me.filoghost.holographicdisplays.api.beta.hologram.line.TextHologramLine; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.World; @@ -9,15 +14,15 @@ import org.bukkit.util.Vector; import com.gmail.berndivader.mythicmobsext.utils.math.MathUtils; -import com.gmail.filoghost.holographicdisplays.api.line.TextLine; -import com.gmail.filoghost.holographicdisplays.object.CraftHologram; -public class Healthbar extends CraftHologram { +public class Healthbar { + + protected Hologram hologram; protected LivingEntity entity; protected UUID uuid; protected double offset, sOffset, fOffset; protected String template; - protected TextLine textline; + protected TextHologramLine textline; protected int showCounter, showCounterDefault; protected boolean useOffset, iYaw; @@ -31,7 +36,8 @@ public Healthbar(LivingEntity entity, double offset) { public Healthbar(LivingEntity entity, double offset, int showCounter, String l, double sOffset, double fOffset, boolean ignoreYaw) { - super(entity.getLocation().add(0, offset, 0)); + hologram = HolographicDisplaysAPI.get(Main.getPlugin()).createHologram(entity.getLocation().add(0, offset, 0)); + this.fOffset = fOffset; this.sOffset = sOffset; this.iYaw = ignoreYaw; @@ -39,17 +45,17 @@ public Healthbar(LivingEntity entity, double offset, int showCounter, String l, if (this.useOffset) { Vector soV = MathUtils.getSideOffsetVectorFixed(entity.getLocation().getYaw(), this.sOffset, this.iYaw); Vector foV = MathUtils.getFrontBackOffsetVector(entity.getLocation().getDirection(), this.fOffset); - this.getLocation().add(soV); - this.getLocation().add(foV); + hologram.getPosition().add(soV.getX(), soV.getY(), soV.getZ()); + hologram.getPosition().add(foV.getX(), foV.getY(), foV.getZ()); } this.uuid = entity.getUniqueId(); HealthbarHandler.healthbars.put(this.uuid, this); if (showCounter == -1) { this.showCounterDefault = -1; - this.getVisibilityManager().setVisibleByDefault(true); + hologram.getVisibilitySettings().setGlobalVisibility(VisibilitySettings.Visibility.VISIBLE); } else { this.showCounterDefault = showCounter; - this.getVisibilityManager().setVisibleByDefault(false); + hologram.getVisibilitySettings().setGlobalVisibility(VisibilitySettings.Visibility.HIDDEN); } if (!l.contains("$h")) l = "$h"; @@ -57,19 +63,19 @@ public Healthbar(LivingEntity entity, double offset, int showCounter, String l, this.entity = entity; this.offset = offset; this.showCounter = 0; - this.textline = this.appendTextLine(this.composeHealthLine()); + this.textline = hologram.getLines().appendText(this.composeHealthLine()); } public void updateHealth() { this.textline.setText(this.composeHealthLine()); if (this.showCounterDefault > -1) { this.showCounter = this.showCounterDefault; - this.getVisibilityManager().setVisibleByDefault(true); + hologram.getVisibilitySettings().setGlobalVisibility(VisibilitySettings.Visibility.VISIBLE); } } public boolean update() { - if (this.isDeleted()) + if (hologram.isDeleted()) return false; Location l = this.entity.getLocation(); World w = l.getWorld(); @@ -78,7 +84,7 @@ public boolean update() { double z = l.getZ(); if (this.showCounterDefault > -1) { if (this.showCounter == 0) { - this.getVisibilityManager().setVisibleByDefault(false); + hologram.getVisibilitySettings().setGlobalVisibility(VisibilitySettings.Visibility.HIDDEN); this.showCounter = -1; } else { this.showCounter--; @@ -90,7 +96,7 @@ public boolean update() { x += soV.getX() + foV.getX(); z += soV.getZ() + foV.getZ(); } - this.teleport(w, x, y + this.offset, z); + hologram.setPosition(w, x, y + this.offset, z); return true; } @@ -102,7 +108,7 @@ public double getHealth() { public void remove() { HealthbarHandler.healthbars.remove(this.uuid); - this.delete(); + hologram.delete(); } public void changeDisplay(String display) { diff --git a/src/main/java/com/gmail/berndivader/mythicmobsext/healthbar/HealthbarHandler.java b/src/main/java/com/gmail/berndivader/mythicmobsext/healthbar/HealthbarHandler.java index 81f312ff..2e066901 100644 --- a/src/main/java/com/gmail/berndivader/mythicmobsext/healthbar/HealthbarHandler.java +++ b/src/main/java/com/gmail/berndivader/mythicmobsext/healthbar/HealthbarHandler.java @@ -20,8 +20,8 @@ public class HealthbarHandler implements Listener { - static Plugin plugin = Main.getPlugin(); - static Logger logger = Main.logger; + static Plugin plugin; + static Logger logger; static String str_pluginName; public static ConcurrentHashMap healthbars; public static ConcurrentHashMap speechbubbles; diff --git a/src/main/java/com/gmail/berndivader/mythicmobsext/healthbar/SpeechBubble.java b/src/main/java/com/gmail/berndivader/mythicmobsext/healthbar/SpeechBubble.java index b65b7a8c..94a84e9d 100644 --- a/src/main/java/com/gmail/berndivader/mythicmobsext/healthbar/SpeechBubble.java +++ b/src/main/java/com/gmail/berndivader/mythicmobsext/healthbar/SpeechBubble.java @@ -2,6 +2,11 @@ import java.util.UUID; +import com.gmail.berndivader.mythicmobsext.Main; +import me.filoghost.holographicdisplays.api.beta.HolographicDisplaysAPI; +import me.filoghost.holographicdisplays.api.beta.hologram.Hologram; +import me.filoghost.holographicdisplays.api.beta.hologram.HologramLines; +import me.filoghost.holographicdisplays.api.beta.hologram.VisibilitySettings; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; @@ -10,17 +15,15 @@ import org.bukkit.util.Vector; import com.gmail.berndivader.mythicmobsext.utils.math.MathUtils; -import com.gmail.filoghost.holographicdisplays.api.line.TextLine; -import com.gmail.filoghost.holographicdisplays.object.CraftHologram; -public class SpeechBubble extends CraftHologram { +public class SpeechBubble { + protected Hologram hologram; protected LivingEntity entity; protected UUID uuid; protected double offset; protected double sOffset; protected double fOffset; protected String[] template; - protected TextLine textline; protected int counter; protected int maxlines; protected int il1 = 0; @@ -39,7 +42,7 @@ public SpeechBubble(LivingEntity entity, String[] text, int ll) { public SpeechBubble(LivingEntity entity, String s1, Location l1, double offset, int showCounter, String[] text, double sOffset, double fOffset, boolean b1, int ll, boolean b2) { - super(l1); + hologram = HolographicDisplaysAPI.get(Main.getPlugin()).createHologram(l1); this.id = s1; this.ll = ll; this.fOffset = fOffset; @@ -49,14 +52,14 @@ public SpeechBubble(LivingEntity entity, String s1, Location l1, double offset, if (this.useOffset && b1) { Vector soV = MathUtils.getSideOffsetVectorFixed(entity.getLocation().getYaw(), this.sOffset, false); Vector foV = MathUtils.getFrontBackOffsetVector(entity.getLocation().getDirection(), this.fOffset); - this.getLocation().add(soV); - this.getLocation().add(foV); + hologram.getPosition().add(soV.getX(), soV.getY(), soV.getZ()); + hologram.getPosition().add(foV.getX(), foV.getY(), foV.getZ()); } this.uc1 = b2; this.uuid = entity.getUniqueId(); HealthbarHandler.speechbubbles.put(this.uuid.toString() + this.id, this); this.counter = showCounter < 1 ? 60 : showCounter * 20; - this.getVisibilityManager().setVisibleByDefault(true); + hologram.getVisibilitySettings().setGlobalVisibility(VisibilitySettings.Visibility.VISIBLE); this.counter = showCounter; this.entity = entity; this.offset = offset; @@ -65,21 +68,21 @@ public SpeechBubble(LivingEntity entity, String s1, Location l1, double offset, } public boolean update() { - if (this.isDeleted()) + if (hologram.isDeleted()) return false; Location l = this.entity.getLocation(); World w = l.getWorld(); double dx = l.getX(); double dy = l.getY(); double dz = l.getZ(); - double do1 = (this.size() * 0.25) + (il1 * 0.5) + this.offset; + double do1 = (hologram.getLines().size() * 0.25) + (il1 * 0.5) + this.offset; if (this.useOffset) { Vector soV = MathUtils.getSideOffsetVectorFixed(entity.getLocation().getYaw(), this.sOffset, false); Vector foV = MathUtils.getFrontBackOffsetVector(entity.getLocation().getDirection(), this.fOffset); dx += soV.getX() + foV.getX(); dz += soV.getZ() + foV.getZ(); } - this.teleport(w, dx, dy + do1, dz); + hologram.setPosition(w, dx, dy + do1, dz); if (uc1) { this.counter--; if (this.counter < 0) @@ -90,11 +93,12 @@ public boolean update() { public void remove() { HealthbarHandler.speechbubbles.remove(this.uuid.toString() + this.id); - this.delete(); + hologram.delete(); } public void lines() { - this.clearLines(); + HologramLines lines = hologram.getLines(); + lines.clear(); this.il1 = 0; for (String l : this.template) { if (l.contains("")[0]) + ">"; String[] a2 = (l.replace(a1, "")).split(""); if (a2.length > 0) - this.appendTextLine(a2[0]); + lines.appendText(a2[0]); Material m1; if ((m1 = Material.getMaterial(a3.toUpperCase())) != null) { - this.appendItemLine(new ItemStack(m1)); + lines.appendItem(new ItemStack(m1)); il1++; } if (a2.length > 1) - this.appendTextLine(a2[1]); + lines.appendText(a2[1]); } else { - this.appendTextLine(l); + lines.appendText(l); } } } diff --git a/src/main/java/com/gmail/berndivader/mythicmobsext/jboolexpr/BooleanExpressionLR.java b/src/main/java/com/gmail/berndivader/mythicmobsext/jboolexpr/BooleanExpressionLR.java index 30bab06e..19d8adf2 100644 --- a/src/main/java/com/gmail/berndivader/mythicmobsext/jboolexpr/BooleanExpressionLR.java +++ b/src/main/java/com/gmail/berndivader/mythicmobsext/jboolexpr/BooleanExpressionLR.java @@ -18,7 +18,7 @@ public boolean booleanValue() { private IBoolean toIBoolean(final String formatedBooleanExpression, final int index) throws MalformedBooleanException { char lastChar = getLastChar(formatedBooleanExpression); - if (new Character(lastChar).toString().matches("\\s")) { + if (String.valueOf(lastChar).matches("\\s")) { lastChar = ' '; } String substring = getSubstringWithoutLastChar(formatedBooleanExpression); @@ -46,7 +46,7 @@ private IBoolean toIBoolean(final String formatedBooleanExpression, final int in private IBoolean toIBoolean(final IBoolean lastIBoolean, final String formatedBooleanExpression, final int index) throws MalformedBooleanException { char lastChar = getLastChar(formatedBooleanExpression); - if (new Character(lastChar).toString().matches("\\s")) { + if (String.valueOf(lastChar).matches("\\s")) { lastChar = ' '; } String substring = getSubstringWithoutLastChar(formatedBooleanExpression); diff --git a/src/main/java/com/gmail/berndivader/mythicmobsext/jboolexpr/BooleanUtil.java b/src/main/java/com/gmail/berndivader/mythicmobsext/jboolexpr/BooleanUtil.java index 9a797953..39fda2b2 100644 --- a/src/main/java/com/gmail/berndivader/mythicmobsext/jboolexpr/BooleanUtil.java +++ b/src/main/java/com/gmail/berndivader/mythicmobsext/jboolexpr/BooleanUtil.java @@ -32,15 +32,15 @@ private static void validRegexp(final String booleanExpression) throws Malformed while (matcher.find()) { int start = matcher.start(); if (start != 0) { - errorIndexes.add(new Integer(start)); + errorIndexes.add(start); } int end = matcher.end(); if (end != booleanExpression.length()) { - errorIndexes.add(new Integer(end)); + errorIndexes.add(end); } } if (errorIndexes.isEmpty()) { - errorIndexes.add(new Integer(0)); + errorIndexes.add(0); } throw new MalformedBooleanException("Expected [ ' ' ( ) || && ! true false ]", errorIndexes, booleanExpression); diff --git a/src/main/java/com/gmail/berndivader/mythicmobsext/jboolexpr/MalformedBooleanException.java b/src/main/java/com/gmail/berndivader/mythicmobsext/jboolexpr/MalformedBooleanException.java index 1f541ac9..7e8023ea 100644 --- a/src/main/java/com/gmail/berndivader/mythicmobsext/jboolexpr/MalformedBooleanException.java +++ b/src/main/java/com/gmail/berndivader/mythicmobsext/jboolexpr/MalformedBooleanException.java @@ -36,7 +36,7 @@ public String getBooleanExpressionErrorMessage() { private static List toList(final int errorIndex) { List errorIndexes = new ArrayList(); - errorIndexes.add(new Integer(errorIndex)); + errorIndexes.add(errorIndex); return errorIndexes; } diff --git a/src/main/java/com/gmail/berndivader/mythicmobsext/utils/Vector2D.java b/src/main/java/com/gmail/berndivader/mythicmobsext/utils/Vector2D.java index 66fccd71..8bb4e275 100644 --- a/src/main/java/com/gmail/berndivader/mythicmobsext/utils/Vector2D.java +++ b/src/main/java/com/gmail/berndivader/mythicmobsext/utils/Vector2D.java @@ -624,7 +624,7 @@ public boolean equals(Object obj) { @Override public int hashCode() { - return ((new Double(x)).hashCode() >> 13) ^ (new Double(z)).hashCode(); + return (Double.valueOf(x).hashCode() >> 13) ^ Double.valueOf(z).hashCode(); } @Override