Merge pull request #1 from ViaVersion/master

Update
This commit is contained in:
ForceUpdate1 2021-02-27 11:58:05 +01:00 committed by GitHub
commit caaef40060
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 6 deletions

View File

@ -6,7 +6,7 @@
<groupId>de.gerrygames</groupId>
<artifactId>viarewind-legacy-support</artifactId>
<version>1.3.2</version>
<version>1.3.3</version>
<packaging>jar</packaging>
<properties>
@ -34,7 +34,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.18</version>
<version>1.18.10</version>
<scope>provided</scope>
</dependency>
@ -42,7 +42,7 @@
<dependency>
<groupId>us.myles</groupId>
<artifactId>viaversion</artifactId>
<version>2.1.3</version>
<version>2.2.2</version>
<scope>provided</scope>
</dependency>
@ -50,7 +50,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
<version>1.15.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>

View File

@ -13,13 +13,16 @@ import us.myles.ViaVersion.api.Via;
public class EnchantingListener implements Listener {
private final boolean newMaterialNames = Material.getMaterial("LAPIS_LAZULI") != null;
private final Material lapisMaterial = newMaterialNames ? Material.LAPIS_LAZULI : Material.getMaterial("INK_SACK");
@EventHandler
public void onInventoryOpen(InventoryOpenEvent e) {
if (!(e.getInventory() instanceof EnchantingInventory)) return;
Player player = (Player) e.getPlayer();
if (Via.getAPI().getPlayerVersion(player)>5) return;
PlayerInventory playerInventory = player.getInventory();
ItemStack lapis = new ItemStack(Material.INK_SACK, 1, (short) 4);
ItemStack lapis = newMaterialNames ? new ItemStack(lapisMaterial) : new ItemStack(lapisMaterial, 1, (short) 4);
int amount = 0;
for (int i = 0; i<playerInventory.getSize(); i++) {
ItemStack item = playerInventory.getItem(i);

View File

@ -13,6 +13,15 @@ import java.util.Map;
public class ReflectionAPI {
private static Map<String, Field> fields = new HashMap<>();
private static Map<String, Method> methods = new HashMap<>();
private static boolean staticFinalModificationBlocked;
static {
try {
Field.class.getDeclaredField("modifiers");
} catch (NoSuchFieldException ex) {
staticFinalModificationBlocked = true;
}
}
public static Field getField(Class clazz, String fieldname) {
String key = clazz.getName() + ":" + fieldname;
@ -41,7 +50,25 @@ public class ReflectionAPI {
public static void setFieldNotFinal(Field field) {
int modifiers = field.getModifiers();
if (!Modifier.isFinal(modifiers)) return;
setValuePrintException(Field.class, field, "modifiers", modifiers & ~Modifier.FINAL);
if (staticFinalModificationBlocked) {
try {
Method getDeclaredFields0 = Class.class.getDeclaredMethod("getDeclaredFields0", boolean.class);
getDeclaredFields0.setAccessible(true);
Field[] fields = (Field[]) getDeclaredFields0.invoke(Field.class, false);
for (Field classField : fields) {
if ("modifiers".equals(classField.getName())) {
classField.setAccessible(true);
classField.set(field, modifiers & ~Modifier.FINAL);
break;
}
}
} catch (ReflectiveOperationException ex) {
ex.printStackTrace();
}
} else {
setValuePrintException(Field.class, field, "modifiers", modifiers & ~Modifier.FINAL);
}
}
public static <E> Constructor<E> getEmptyConstructor(Class<E> clazz) {

View File

@ -1,6 +1,7 @@
name: ViaRewind-Legacy-Support
version: ${project.version}
main: de.gerrygames.viarewind.legacysupport.BukkitPlugin
api-version: 1.13
authors: [Gerrygames]
website: https://github.com/Gerrygames