Changed reflection to grab the version by type rather than name

This commit is contained in:
Sekwah 2018-08-29 05:54:50 +01:00
parent 81e339172d
commit accfda8d90
3 changed files with 13 additions and 6 deletions

View File

@ -4,7 +4,7 @@ apply plugin: 'idea'
apply plugin: 'eclipse'
group = 'com.sekwah.advancedportals'
version = '0.0.46-snapshot'
version = '0.0.47-snapshot'
description = ""

View File

@ -38,6 +38,7 @@ public class CraftBukkit {
private Constructor<?> blockPositionConstructor;
private Method getWorldHandleMethod;
private Method getTileEntityMethod;
private Field getEntityTimeoutField;
public CraftBukkit(AdvancedPortalsPlugin plugin, String bukkitImpl) throws ClassNotFoundException, NoSuchFieldException, NoSuchMethodException {
@ -79,7 +80,15 @@ public class CraftBukkit {
getTileEntityMethod = Class.forName(minecraftPackage + "WorldServer").getMethod("getTileEntity", blockPos);
Field[] endGatewayFields = Class.forName(minecraftPackage + "TileEntityEndGateway").getDeclaredFields();
for(Field field : endGatewayFields) {
if(field.getType() == int.class && !field.isAccessible()) {
field.setAccessible(true);
getEntityTimeoutField = field;
return;
}
}
} catch (Exception e) {
e.printStackTrace();
@ -139,11 +148,9 @@ public class CraftBukkit {
Object tileEntity = this.getTileEntityMethod.invoke(this.getWorldHandleMethod.invoke(block.getWorld()),
this.blockPositionConstructor.newInstance(block.getX(), block.getY(), block.getZ()));
if(tileEntity.getClass().isAssignableFrom(this.tileEntityEndGatewayClass)) {
Field f = tileEntity.getClass().getDeclaredField("f");
f.setAccessible(true);
f.set(tileEntity, Integer.MAX_VALUE);
getEntityTimeoutField.set(tileEntity, Integer.MAX_VALUE);
}
} catch (IllegalAccessException| InvocationTargetException | InstantiationException | NoSuchFieldException e) {
} catch (IllegalAccessException| InvocationTargetException | InstantiationException e) {
this.plugin.getLogger().warning("Error setting gateway time");
e.printStackTrace();
}

View File

@ -1,6 +1,6 @@
main: com.sekwah.advancedportals.AdvancedPortalsPlugin
name: AdvancedPortals
version: 0.0.46
version: 0.0.47
author: sekwah41
description: An advanced portals plugin for bukkit.
api-version: 1.13