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' apply plugin: 'eclipse'
group = 'com.sekwah.advancedportals' group = 'com.sekwah.advancedportals'
version = '0.0.46-snapshot' version = '0.0.47-snapshot'
description = "" description = ""

View File

@ -38,6 +38,7 @@ public class CraftBukkit {
private Constructor<?> blockPositionConstructor; private Constructor<?> blockPositionConstructor;
private Method getWorldHandleMethod; private Method getWorldHandleMethod;
private Method getTileEntityMethod; private Method getTileEntityMethod;
private Field getEntityTimeoutField;
public CraftBukkit(AdvancedPortalsPlugin plugin, String bukkitImpl) throws ClassNotFoundException, NoSuchFieldException, NoSuchMethodException { 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); 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) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -139,11 +148,9 @@ public class CraftBukkit {
Object tileEntity = this.getTileEntityMethod.invoke(this.getWorldHandleMethod.invoke(block.getWorld()), Object tileEntity = this.getTileEntityMethod.invoke(this.getWorldHandleMethod.invoke(block.getWorld()),
this.blockPositionConstructor.newInstance(block.getX(), block.getY(), block.getZ())); this.blockPositionConstructor.newInstance(block.getX(), block.getY(), block.getZ()));
if(tileEntity.getClass().isAssignableFrom(this.tileEntityEndGatewayClass)) { if(tileEntity.getClass().isAssignableFrom(this.tileEntityEndGatewayClass)) {
Field f = tileEntity.getClass().getDeclaredField("f"); getEntityTimeoutField.set(tileEntity, Integer.MAX_VALUE);
f.setAccessible(true);
f.set(tileEntity, Integer.MAX_VALUE);
} }
} catch (IllegalAccessException| InvocationTargetException | InstantiationException | NoSuchFieldException e) { } catch (IllegalAccessException| InvocationTargetException | InstantiationException e) {
this.plugin.getLogger().warning("Error setting gateway time"); this.plugin.getLogger().warning("Error setting gateway time");
e.printStackTrace(); e.printStackTrace();
} }

View File

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