Merge branch 'development'

This commit is contained in:
Christian Koop 2021-12-07 17:20:45 +01:00
commit 42cf648d6f
No known key found for this signature in database
GPG Key ID: 89A8181384E010A3
26 changed files with 125 additions and 40 deletions

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.1</version>
<version>2.6.2</version>
<relativePath>../pom.xml</relativePath>
</parent>

View File

@ -0,0 +1,71 @@
package com.songoda.core.compatibility;
import org.bukkit.inventory.ItemStack;
import java.lang.reflect.Method;
public enum MethodMapping {
MC_ITEM_STACK__GET_TAG("getTag", "s"),
MC_ITEM_STACK__SET_TAG("setTag", "c", ClassMapping.NBT_TAG_COMPOUND.getClazz()),
MC_NBT_TAG_COMPOUND__SET("set", "a", String.class, ClassMapping.NBT_BASE.getClazz()),
MC_NBT_TAG_COMPOUND__SET_SHORT("setShort", "a", String.class),
MC_NBT_TAG_COMPOUND__SET_STRING("setString", "a", String.class, String.class),
MC_NBT_TAG_COMPOUND__REMOVE("remove", "r", String.class, short.class),
CB_ITEM_STACK__AS_NMS_COPY("asNMSCopy", ItemStack.class),
CB_ITEM_STACK__AS_CRAFT_MIRROR("asCraftMirror", ClassMapping.ITEM_STACK.getClazz()),
MC_NBT_TAG_LIST__ADD("a", "add", "add", ClassMapping.NBT_BASE.getClazz());
private final String _1_14;
private final String _1_17;
private final String _1_18;
private final Class<?>[] paramaters;
MethodMapping(String _1_14, String _1_17, String _1_18, Class<?>... paramaters) {
this._1_14 = _1_14;
this._1_17 = _1_17;
this._1_18 = _1_18;
this.paramaters = paramaters;
}
MethodMapping(String _1_17, String _1_18, Class<?>... paramaters) {
this._1_14 = null;
this._1_17 = _1_17;
this._1_18 = _1_18;
this.paramaters = paramaters;
}
MethodMapping(String _1_18, Class<?>... paramaters) {
this._1_14 = null;
this._1_17 = null;
this._1_18 = _1_18;
this.paramaters = paramaters;
}
public Method getMethod(Class<?> clazz) {
try {
String methodName = _1_18;
switch (ServerVersion.getServerVersion()) {
case V1_14:
if (_1_14 != null)
methodName = _1_14;
break;
case V1_17:
if (_1_17 != null)
methodName = _1_17;
break;
}
Method method = clazz.getDeclaredMethod(methodName, paramaters);
method.setAccessible(true);
return method;
} catch (Exception e) {
return null;
}
}
}

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.1</version>
<version>2.6.2</version>
<relativePath>../pom.xml</relativePath>
</parent>

View File

@ -53,7 +53,7 @@ public class SongodaCore {
/**
* @since coreRevision 6
*/
private final static String coreVersion = "2.6.1";
private final static String coreVersion = "2.6.2";
/**
* This is specific to the website api

View File

@ -5,6 +5,7 @@ import com.mojang.authlib.properties.Property;
import com.songoda.core.compatibility.ClassMapping;
import com.songoda.core.compatibility.CompatibleHand;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.compatibility.MethodMapping;
import com.songoda.core.compatibility.ServerVersion;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
@ -193,11 +194,10 @@ public class ItemUtils {
return tool.getDurability() + requiredAmount <= tool.getType().getMaxDurability();
}
static Class cb_ItemStack = NMSUtils.getCraftClass("inventory.CraftItemStack");
static Class mc_ItemStack = ClassMapping.ITEM_STACK.getClazz();
static Class mc_NBTTagCompound = ClassMapping.NBT_TAG_COMPOUND.getClazz();
static Class mc_NBTTagList = ClassMapping.NBT_TAG_LIST.getClazz();
static Class mc_NBTBase = ClassMapping.NBT_BASE.getClazz();
static Class<?> cb_ItemStack = ClassMapping.CRAFT_ITEM_STACK.getClazz();
static Class<?> mc_ItemStack = ClassMapping.ITEM_STACK.getClazz();
static Class<?> mc_NBTTagCompound = ClassMapping.NBT_TAG_COMPOUND.getClazz();
static Class<?> mc_NBTTagList = ClassMapping.NBT_TAG_LIST.getClazz();
static Method mc_ItemStack_getTag;
static Method mc_ItemStack_setTag;
static Method mc_NBTTagCompound_set;
@ -211,17 +211,15 @@ public class ItemUtils {
static {
if (cb_ItemStack != null) {
try {
mc_ItemStack_getTag = mc_ItemStack.getDeclaredMethod("getTag");
mc_ItemStack_setTag = mc_ItemStack.getDeclaredMethod("setTag", mc_NBTTagCompound);
mc_NBTTagCompound_set = mc_NBTTagCompound.getDeclaredMethod("set", String.class, mc_NBTBase);
mc_NBTTagCompound_remove = mc_NBTTagCompound.getDeclaredMethod("remove", String.class);
mc_NBTTagCompound_setShort = mc_NBTTagCompound.getDeclaredMethod("setShort", String.class, short.class);
mc_NBTTagCompound_setString = mc_NBTTagCompound.getDeclaredMethod("setString", String.class, String.class);
cb_CraftItemStack_asNMSCopy = cb_ItemStack.getDeclaredMethod("asNMSCopy", ItemStack.class);
cb_CraftItemStack_asCraftMirror = cb_ItemStack.getDeclaredMethod("asCraftMirror", mc_ItemStack);
mc_NBTTagList_add = ServerVersion.isServerVersionAtLeast(ServerVersion.V1_14)
? NMSUtils.getPrivateMethod(mc_NBTTagList, "a", mc_NBTBase)
: mc_NBTTagList.getDeclaredMethod("add", mc_NBTBase);
mc_ItemStack_getTag = MethodMapping.MC_ITEM_STACK__GET_TAG.getMethod(mc_ItemStack);
mc_ItemStack_setTag = MethodMapping.MC_ITEM_STACK__SET_TAG.getMethod(mc_ItemStack);
mc_NBTTagCompound_set = MethodMapping.MC_NBT_TAG_COMPOUND__SET.getMethod(mc_NBTTagCompound);
mc_NBTTagCompound_remove = MethodMapping.MC_NBT_TAG_COMPOUND__REMOVE.getMethod(mc_NBTTagCompound);
mc_NBTTagCompound_setShort = MethodMapping.MC_NBT_TAG_COMPOUND__SET_SHORT.getMethod(mc_NBTTagCompound);
mc_NBTTagCompound_setString = MethodMapping.MC_NBT_TAG_COMPOUND__SET_STRING.getMethod(mc_NBTTagCompound);
cb_CraftItemStack_asNMSCopy = MethodMapping.CB_ITEM_STACK__AS_NMS_COPY.getMethod(mc_ItemStack);
cb_CraftItemStack_asCraftMirror = MethodMapping.CB_ITEM_STACK__AS_CRAFT_MIRROR.getMethod(mc_ItemStack);
mc_NBTTagList_add = MethodMapping.MC_NBT_TAG_LIST__ADD.getMethod(mc_NBTTagList);
} catch (Exception ex) {
Logger.getLogger(ItemUtils.class.getName()).log(Level.SEVERE, null, ex);
}
@ -229,7 +227,7 @@ public class ItemUtils {
}
/**
* Make an item glow as if it contained an enchantment. <br>
* Make an item glow as if it contained an enchantment. <br>
* Tested working 1.8-1.14
*
* @param item itemstack to create a glowing copy of

View File

@ -8,6 +8,10 @@ import java.lang.reflect.Field;
import java.lang.reflect.Method;
public class NMSUtils {
/**
* @deprecated Use {@link ClassMapping} instead
*/
@Deprecated
public static Class<?> getCraftClass(String className) {
try {
String fullName = "org.bukkit.craftbukkit." + ServerVersion.getServerVersionString() + "." + className;

View File

@ -22,7 +22,7 @@ public class SWorldBorder {
static {
try {
worldBorderClass = ClassMapping.WORLD_BORDER.getClazz();
craftWorldClass = NMSUtils.getCraftClass("CraftWorld");
craftWorldClass = ClassMapping.CRAFT_WORLD.getClazz();
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_17)) {
Class<?> clientboundInitializeBorderPacketClass = ClassMapping.CLIENTBOUND_INITIALIZE_BORDER_PACKET.getClazz();

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.1</version>
<version>2.6.2</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.1</version>
<version>2.6.2</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.1</version>
<version>2.6.2</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.1</version>
<version>2.6.2</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.1</version>
<version>2.6.2</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.1</version>
<version>2.6.2</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.1</version>
<version>2.6.2</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.1</version>
<version>2.6.2</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.1</version>
<version>2.6.2</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.1</version>
<version>2.6.2</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.1</version>
<version>2.6.2</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.1</version>
<version>2.6.2</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -3,11 +3,23 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
</plugins>
</build>
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.1</version>
<version>2.6.2</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.1</version>
<version>2.6.2</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.1</version>
<version>2.6.2</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.1</version>
<version>2.6.2</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.1</version>
<version>2.6.2</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.1</version>
<version>2.6.2</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -6,7 +6,7 @@
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.1</version>
<version>2.6.2</version>
<packaging>pom</packaging>
<!-- Run 'mvn versions:set -DgenerateBackupPoms=false -DnewVersion=X.Y.Z' to update version recursively -->