Merge branch 'development'

This commit is contained in:
Christian Koop 2021-12-14 21:01:32 +01:00
commit e8aa3f2b78
No known key found for this signature in database
GPG Key ID: 89A8181384E010A3
26 changed files with 91 additions and 88 deletions

View File

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

View File

@ -44,7 +44,9 @@ public enum ClassMapping {
CRAFT_ITEM_STACK("inventory", "CraftItemStack"),
CRAFT_MAGIC_NUMBERS("util", "CraftMagicNumbers"),
CRAFT_PLAYER("entity", "CraftPlayer"),
CRAFT_WORLD("CraftWorld");
CRAFT_WORLD("CraftWorld"),
MOJANGSON_PARSER("nbt", "MojangsonParser");
private final String packageName;
private final String className;

View File

@ -1,11 +1,11 @@
package com.songoda.core.compatibility;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import java.lang.reflect.Method;
public enum MethodMapping {
MC_ITEM_STACK__GET_TAG("getTag", "getTag", "s"),
MC_ITEM_STACK__SET_TAG("setTag", "setTag", "c", ClassMapping.NBT_TAG_COMPOUND.getClazz()),
@ -14,17 +14,40 @@ public enum MethodMapping {
MC_NBT_TAG_COMPOUND__SET_STRING("setString", "setString", "a", String.class, String.class),
MC_NBT_TAG_COMPOUND__REMOVE("remove", "remove", "r", String.class),
CB_ITEM_STACK__AS_NMS_COPY("asNMSCopy", "asNMSCopy", ItemStack.class),
CB_ITEM_STACK__AS_CRAFT_MIRROR("asCraftMirror", "asCraftMirror", ClassMapping.ITEM_STACK.getClazz()),
CB_GENERIC__GET_HANDLE("getHandle"),
MC_NBT_TAG_LIST__ADD("add", "a", "add", "add", ClassMapping.NBT_BASE.getClazz()),
CB_BLOCK__GET_NMS("getNMS"),
CB_BLOCK__GET_POSITION("getPosition"),
CB_ITEM_STACK__AS_NMS_COPY("asNMSCopy", ItemStack.class),
CB_ITEM_STACK__AS_CRAFT_MIRROR("asCraftMirror", ClassMapping.ITEM_STACK.getClazz()),
CRAFT_MAGIC_NUMBERS__GET_BLOCK__MATERIAL("getBlock", Material.class),
MC_CHUNK__GET_WORLD("getWorld", "D"),
MC_NBT_TAG_LIST__ADD("add", "a", "add", "c", ClassMapping.NBT_BASE.getClazz()),
I_BLOCK_DATA__GET_BLOCK("getBlock", "b"),
BLOCK__GET_BLOCK_DATA("getBlockData", "n"),
CHUNK__SET_BLOCK_STATE("setType", "setBlockState", ClassMapping.BLOCK_POSITION.getClazz(), ClassMapping.I_BLOCK_DATA.getClazz(), boolean.class, boolean.class),
ITEM_STACK__SAVE("save", "b", ClassMapping.NBT_TAG_COMPOUND.getClazz()),
ITEM_STACK__GET_ITEM("getItem", "c"),
ITEM_STACK__GET_MAX_STACK_SIZE("getMaxStackSize", "l"),
WORLD__UPDATE_ADJACENT_COMPARATORS("updateAdjacentComparators", "c", ClassMapping.BLOCK_POSITION.getClazz(), ClassMapping.BLOCK.getClazz()),
WORLD__GET_CHUNK_AT("getChunkAt", "d", int.class, int.class),
WORLD_BOARDER__SET_CENTER("setCenter", "setCenter", "setCenter", "c", double.class, double.class),
WORLD_BOARDER__SET_SIZE("setSize", "setSize", "setSize", "a", double.class),
WORLD_BOARDER__SET_WARNING_TIME("setWarningTime", "setWarningTime", "setWarningTime", "b", int.class),
WORLD_BOARDER__SET_WARNING_DISTANCE("setWarningDistance", "setWarningDistance", "setWarningDistance", "c", int.class),
WORLD_BOARDER__TRANSITION_SIZE_BETWEEN("transitionSizeBetween", "transitionSizeBetween", "transitionSizeBetween", "a", double.class, double.class, long.class);
WORLD_BOARDER__TRANSITION_SIZE_BETWEEN("transitionSizeBetween", "transitionSizeBetween", "transitionSizeBetween", "a", double.class, double.class, long.class),
MOJANGSON_PARSER__PARSE("parse", "a", String.class);
private final String saneFallback;
private final String _1_14;
@ -59,29 +82,42 @@ public enum MethodMapping {
this.paramaters = paramaters;
}
MethodMapping(String saneFallback, Class<?>... paramaters) {
this.saneFallback = saneFallback;
this._1_14 = null;
this._1_17 = null;
this._1_18 = null;
this.paramaters = paramaters;
}
public Method getMethod(Class<?> clazz) {
try {
String methodName = _1_18;
switch (ServerVersion.getServerVersion()) {
case V1_14:
if (_1_14 != null)
if (_1_14 != null) {
methodName = _1_14;
}
break;
case V1_17:
if (_1_17 != null)
if (_1_17 != null) {
methodName = _1_17;
}
break;
}
try {
Method method = clazz.getDeclaredMethod(methodName, paramaters);
Method method = clazz.getMethod(methodName, paramaters);
method.setAccessible(true);
return method;
} catch (NoSuchMethodException ex) {
if (saneFallback != null) {
} catch (NullPointerException | NoSuchMethodException ex) {
if (saneFallback != null && !saneFallback.equals(methodName)) {
try {
Method method = clazz.getDeclaredMethod(saneFallback, paramaters);
Method method = clazz.getMethod(saneFallback, paramaters);
method.setAccessible(true);
return method;
@ -89,6 +125,8 @@ public enum MethodMapping {
ex.printStackTrace();
innerEx.printStackTrace();
}
} else {
ex.printStackTrace();
}
}
} catch (Exception ex) {

View File

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

View File

@ -2,6 +2,7 @@ package com.songoda.core.utils;
import com.songoda.core.compatibility.ClassMapping;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.compatibility.MethodMapping;
import com.songoda.core.compatibility.ServerVersion;
import org.bukkit.Effect;
import org.bukkit.Location;
@ -346,28 +347,20 @@ public class BlockUtils {
try {
if (chunkToNmsChunk == null) {
chunkToNmsChunk = loc.getChunk().getClass().getMethod("getHandle");
nmsChunkGetWorld = chunkToNmsChunk.getReturnType().getMethod("getWorld");
chunkToNmsChunk = MethodMapping.CB_GENERIC__GET_HANDLE.getMethod(ClassMapping.CRAFT_CHUNK.getClazz());
nmsChunkGetWorld = MethodMapping.MC_CHUNK__GET_WORLD.getMethod(chunkToNmsChunk.getReturnType());
Class<?> blockPositionClass;
try {
craftBlockGetPosition = craftBlock.getClass().getMethod("getPosition");
blockPositionClass = craftBlockGetPosition.getReturnType();
} catch (NoSuchMethodException ignore) {
blockPositionClass = ClassMapping.BLOCK_POSITION.getClazz();
blockPositionConstructor = blockPositionClass.getConstructor(double.class, double.class, double.class);
craftBlockGetPosition = MethodMapping.CB_BLOCK__GET_POSITION.getMethod(ClassMapping.CRAFT_BLOCK.getClazz());
if (craftBlockGetPosition == null) {
blockPositionConstructor = ClassMapping.BLOCK_POSITION.getClazz().getConstructor(double.class, double.class, double.class);
}
nmsWorldUpdateAdjacentComparators = nmsChunkGetWorld.getReturnType().getMethod("updateAdjacentComparators", blockPositionClass, ClassMapping.BLOCK.getClazz());
nmsWorldUpdateAdjacentComparators = MethodMapping.WORLD__UPDATE_ADJACENT_COMPARATORS.getMethod(ClassMapping.WORLD.getClazz());
try {
craftBlockBlockDataGetter = craftBlock.getClass().getMethod("getNMS");
blockDataGetBlock = craftBlockBlockDataGetter.getReturnType().getMethod("getBlock");
} catch (NoSuchMethodException ignore) {
craftMagicNumbersGetBlockByMaterial = ClassMapping.CRAFT_MAGIC_NUMBERS.getClazz()
.getMethod("getBlock", craftBlock.getType().getClass());
craftBlockBlockDataGetter = MethodMapping.CB_BLOCK__GET_NMS.getMethod(ClassMapping.CRAFT_BLOCK.getClazz());
blockDataGetBlock = MethodMapping.I_BLOCK_DATA__GET_BLOCK.getMethod(ClassMapping.I_BLOCK_DATA.getClazz());
if (craftBlockBlockDataGetter == null || blockDataGetBlock == null) {
craftMagicNumbersGetBlockByMaterial = MethodMapping.CRAFT_MAGIC_NUMBERS__GET_BLOCK__MATERIAL.getMethod(ClassMapping.CRAFT_MAGIC_NUMBERS.getClazz());
}
}
@ -389,7 +382,7 @@ public class BlockUtils {
}
nmsWorldUpdateAdjacentComparators.invoke(nmsWorld, blockPosition, nmsBlock);
} catch (ReflectiveOperationException ex) {
} catch (NullPointerException | ReflectiveOperationException ex) {
ex.printStackTrace();
}
}
@ -419,11 +412,11 @@ public class BlockUtils {
Class<?> clazzChunk = ClassMapping.CHUNK.getClazz();
getHandle = clazzCraftWorld.getMethod("getHandle");
getChunkAt = clazzWorld.getMethod("getChunkAt", int.class, int.class);
getChunkAt = MethodMapping.WORLD__GET_CHUNK_AT.getMethod(clazzWorld);
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
getBlockData = clazzBlock.getMethod("getBlockData");
setType = clazzChunk.getMethod("setType", clazzBlockPosition, clazzIBlockData, boolean.class);
getBlockData = MethodMapping.BLOCK__GET_BLOCK_DATA.getMethod(ClassMapping.BLOCK.getClazz());
setType = MethodMapping.CHUNK__SET_BLOCK_STATE.getMethod(ClassMapping.CHUNK.getClazz());
} else {
getByCombinedId = clazzBlock.getMethod("getByCombinedId", int.class);
setType = clazzChunk.getMethod("a", clazzBlockPosition, clazzIBlockData);

View File

@ -318,34 +318,6 @@ public class ItemUtils {
return item;
}
private static Class<?> mc_Item = ClassMapping.ITEM.getClazz();
private static Method mc_Item_getItem;
private static Field mc_Item_maxStackSize;
static {
if (mc_ItemStack != null) {
try {
mc_Item_getItem = mc_ItemStack.getDeclaredMethod("getItem");
mc_Item_maxStackSize = mc_Item.getDeclaredField("maxStackSize");
mc_Item_maxStackSize.setAccessible(true);
} catch (Exception ignore) {
}
}
}
public static ItemStack setMaxStack(ItemStack item, int max) {
if (item != null && mc_Item_maxStackSize != null) {
try {
Object objItemStack = mc_Item_getItem.invoke(cb_CraftItemStack_asNMSCopy.invoke(null, item));
mc_Item_maxStackSize.set(objItemStack, max);
} catch (ReflectiveOperationException ex) {
Bukkit.getLogger().log(Level.SEVERE, "Failed to set max stack size on item " + item, ex);
}
}
return item;
}
public static ItemStack getPlayerSkull(OfflinePlayer player) {
ItemStack head = CompatibleMaterial.PLAYER_HEAD.getItem();
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_8)) {

View File

@ -55,10 +55,8 @@ public class SWorldBorder {
Object worldBorder = worldBorderClass.getConstructor().newInstance();
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9)) {
Object craftWorld = craftWorldClass.cast(centerLocation.getWorld());
Method getHandleMethod = craftWorld.getClass().getMethod("getHandle");
Object worldServer = getHandleMethod.invoke(craftWorld);
NMSUtils.setField(worldBorder, "world", worldServer, false);
Object nmsWorld = MethodMapping.CB_GENERIC__GET_HANDLE.getMethod(ClassMapping.CRAFT_WORLD.getClazz()).invoke(centerLocation.getWorld());
NMSUtils.setField(worldBorder, "world", nmsWorld, false);
}
Method setCenter = MethodMapping.WORLD_BOARDER__SET_CENTER.getMethod(ClassMapping.WORLD_BORDER.getClazz());
@ -87,7 +85,7 @@ public class SWorldBorder {
} else {
@SuppressWarnings({"unchecked", "rawtypes"})
Object packet = packetPlayOutWorldBorderConstructor.newInstance(worldBorder,
Enum.valueOf((Class<Enum>) packetPlayOutWorldBorderEnumClass, "INITIALIZE"));
Enum.valueOf((Class<? extends Enum>) packetPlayOutWorldBorderEnumClass, "INITIALIZE"));
NmsManager.getPlayer().sendPacket(player, packet);
}
} catch (InstantiationException | InvocationTargetException | NoSuchMethodException | IllegalAccessException ex) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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