mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-28 13:36:33 +01:00
Fix keepInventory NPE; resolves #481
This commit is contained in:
parent
95f19123ed
commit
4ed3b945e2
4
pom.xml
4
pom.xml
@ -2,7 +2,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>de.erethon</groupId>
|
||||
<artifactId>dungeonsxl</artifactId>
|
||||
<version>0.17.2</version>
|
||||
<version>0.17.3</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>DungeonsXL</name>
|
||||
<url>https://dre2n.github.io</url>
|
||||
@ -83,7 +83,7 @@
|
||||
<dependency>
|
||||
<groupId>de.erethon</groupId>
|
||||
<artifactId>commons</artifactId>
|
||||
<version>5.1.2</version>
|
||||
<version>5.1.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -16,8 +16,6 @@
|
||||
*/
|
||||
package de.erethon.dungeonsxl.util;
|
||||
|
||||
import de.erethon.commons.misc.ReflectionUtil;
|
||||
import java.lang.reflect.Method;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
/**
|
||||
@ -26,17 +24,8 @@ import org.bukkit.block.Block;
|
||||
@Deprecated
|
||||
public class MagicValueUtil {
|
||||
|
||||
private static Method CRAFT_BLOCK_SET_DATA;
|
||||
|
||||
static {
|
||||
try {
|
||||
CRAFT_BLOCK_SET_DATA = Class.forName(ReflectionUtil.ORG_BUKKIT_CRAFTBUKKIT + ".block.CraftBlock").getDeclaredMethod("setData", byte.class);
|
||||
} catch (NoSuchMethodException | SecurityException | ClassNotFoundException exception) {
|
||||
}
|
||||
}
|
||||
|
||||
public static void setBlockData(Block block, byte data) {
|
||||
ReflectionUtil.invoke(CRAFT_BLOCK_SET_DATA, block, data);
|
||||
ReflectionUtil.invoke(ReflectionUtil.CRAFT_BLOCK_SET_DATA, block, data);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package de.erethon.dungeonsxl.util;
|
||||
|
||||
import static de.erethon.commons.misc.ReflectionUtil.*;
|
||||
import static de.erethon.dungeonsxl.util.ReflectionUtil.*;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
|
80
src/main/java/de/erethon/dungeonsxl/util/ReflectionUtil.java
Normal file
80
src/main/java/de/erethon/dungeonsxl/util/ReflectionUtil.java
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2018 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.erethon.dungeonsxl.util;
|
||||
|
||||
import de.erethon.commons.compatibility.CompatibilityHandler;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class ReflectionUtil {
|
||||
|
||||
static String INTERNALS_VERSION = CompatibilityHandler.getInstance().getInternals().toString();
|
||||
static String ORG_BUKKIT_CRAFTBUKKIT = "org.bukkit.craftbukkit." + INTERNALS_VERSION;
|
||||
static String NET_MINECRAFT_SERVER = "net.minecraft.server." + INTERNALS_VERSION;
|
||||
static Class NBT_TAG_COMPOUND;
|
||||
static Method NBT_TAG_COMPOUND_HAS_KEY;
|
||||
static Method NBT_TAG_COMPOUND_REMOVE;
|
||||
static Method NBT_TAG_COMPOUND_SET_BOOLEAN;
|
||||
static Class ITEM_STACK;
|
||||
static Method ITEM_STACK_GET_TAG;
|
||||
static Method ITEM_STACK_SET_TAG;
|
||||
static Class CRAFT_ITEM_STACK;
|
||||
static Method CRAFT_ITEM_STACK_AS_BUKKIT_COPY;
|
||||
static Method CRAFT_ITEM_STACK_AS_NMS_COPY;
|
||||
static Method CRAFT_BLOCK_SET_DATA;
|
||||
|
||||
static {
|
||||
try {
|
||||
NBT_TAG_COMPOUND = Class.forName(NET_MINECRAFT_SERVER + ".NBTTagCompound");
|
||||
NBT_TAG_COMPOUND_HAS_KEY = NBT_TAG_COMPOUND.getDeclaredMethod("hasKey", String.class);
|
||||
NBT_TAG_COMPOUND_REMOVE = NBT_TAG_COMPOUND.getDeclaredMethod("remove", String.class);
|
||||
NBT_TAG_COMPOUND_SET_BOOLEAN = NBT_TAG_COMPOUND.getDeclaredMethod("setBoolean", String.class, boolean.class);
|
||||
ITEM_STACK = Class.forName(NET_MINECRAFT_SERVER + ".ItemStack");
|
||||
ITEM_STACK_GET_TAG = ITEM_STACK.getDeclaredMethod("getTag");
|
||||
ITEM_STACK_SET_TAG = ITEM_STACK.getDeclaredMethod("setTag", NBT_TAG_COMPOUND);
|
||||
CRAFT_ITEM_STACK = Class.forName(ORG_BUKKIT_CRAFTBUKKIT + ".inventory.CraftItemStack");
|
||||
CRAFT_ITEM_STACK_AS_BUKKIT_COPY = CRAFT_ITEM_STACK.getDeclaredMethod("asBukkitCopy", ITEM_STACK);
|
||||
CRAFT_ITEM_STACK_AS_NMS_COPY = CRAFT_ITEM_STACK.getDeclaredMethod("asNMSCopy", ItemStack.class);
|
||||
CRAFT_BLOCK_SET_DATA = Class.forName(ReflectionUtil.ORG_BUKKIT_CRAFTBUKKIT + ".block.CraftBlock").getDeclaredMethod("setData", byte.class);
|
||||
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalArgumentException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
static Object newInstance(Class clazz) {
|
||||
try {
|
||||
return clazz.newInstance();
|
||||
} catch (IllegalAccessException | InstantiationException exception) {
|
||||
exception.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static Object invoke(Method method, Object instance, Object... args) {
|
||||
try {
|
||||
return method.invoke(instance, args);
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException exception) {
|
||||
exception.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user