Skip to content

Commit

Permalink
MMOItems Support - Item in hand is specific MMOItem
Browse files Browse the repository at this point in the history
  • Loading branch information
Axolottl committed Jan 31, 2022
1 parent 3c7d99e commit 05197f6
Show file tree
Hide file tree
Showing 13 changed files with 344 additions and 265 deletions.
48 changes: 31 additions & 17 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:+")
Expand All @@ -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 {
Expand All @@ -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!")}}
}

}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#Tue Feb 16 14:18:06 CET 2021
group=com.gmail.berndivader
artver=1.739-SNAPSHOT
artver=1.741-SNAPSHOT
49 changes: 24 additions & 25 deletions src/main/java/com/gmail/berndivader/mythicmobsext/NMS/NMSUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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);

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -452,7 +451,7 @@ public static Drop getDrop(String item_name) {
*/
@SuppressWarnings("unchecked")
public static Map<String, Map<Plugin, MetadataValue>> getEntityMetadataMap(Server server) {
Map<String, Map<Plugin, MetadataValue>> metadata_map = new HashMap<String, Map<Plugin, MetadataValue>>();
Map<String, Map<Plugin, MetadataValue>> metadata_map = new HashMap<>();
try {
Object craft_server = server;
Object entity_metadata_store = class_CraftServer_getEntityMetadataStoreMethod.invoke(craft_server);
Expand All @@ -472,7 +471,7 @@ public static Map<String, Map<Plugin, MetadataValue>> getEntityMetadataMap(Serve
*/
@SuppressWarnings("unchecked")
public static Map<String, Map<Plugin, MetadataValue>> getPlayerMetadataMap(Entity entity) {
Map<String, Map<Plugin, MetadataValue>> metadata_map = new HashMap<String, Map<Plugin, MetadataValue>>();
Map<String, Map<Plugin, MetadataValue>> metadata_map = new HashMap<>();
try {
Object craft_server = entity.getServer();
Object entity_metadata_store = class_CraftServer_getPlayerMetadataStoreMethod.invoke(craft_server);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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<UUID, Entity> entityMap = (Map<UUID, Entity>)class_WorldServer_entitiesByUUIDField.get(worldHandle);
Object nmsEntity = class_WorldServer_getEntityMethod.invoke(worldHandle, uuid);
if (nmsEntity != null) {
return getBukkitEntity(nmsEntity);
}
/*final Map<UUID, Entity> entityMap = (Map<UUID, Entity>) class_WorldServer_getEntitiesMethod.invoke(worldHandle);
if (entityMap != null) {
Object nmsEntity = entityMap.get(uuid);
if (nmsEntity != null) {
return getBukkitEntity(nmsEntity);
}
}
*/
} catch (Exception ex) {
ex.printStackTrace();
}
Expand Down
Loading

0 comments on commit 05197f6

Please sign in to comment.