Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit accfda8

Browse files
author
Sekwah
committedAug 29, 2018
Changed reflection to grab the version by type rather than name
1 parent 81e3391 commit accfda8

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed
 

‎build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ apply plugin: 'idea'
44
apply plugin: 'eclipse'
55

66
group = 'com.sekwah.advancedportals'
7-
version = '0.0.46-snapshot'
7+
version = '0.0.47-snapshot'
88

99
description = ""
1010

‎src/main/java/com/sekwah/advancedportals/compat/CraftBukkit.java

+11-4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class CraftBukkit {
3838
private Constructor<?> blockPositionConstructor;
3939
private Method getWorldHandleMethod;
4040
private Method getTileEntityMethod;
41+
private Field getEntityTimeoutField;
4142

4243

4344
public CraftBukkit(AdvancedPortalsPlugin plugin, String bukkitImpl) throws ClassNotFoundException, NoSuchFieldException, NoSuchMethodException {
@@ -79,7 +80,15 @@ public CraftBukkit(AdvancedPortalsPlugin plugin, String bukkitImpl) throws Class
7980

8081
getTileEntityMethod = Class.forName(minecraftPackage + "WorldServer").getMethod("getTileEntity", blockPos);
8182

83+
Field[] endGatewayFields = Class.forName(minecraftPackage + "TileEntityEndGateway").getDeclaredFields();
8284

85+
for(Field field : endGatewayFields) {
86+
if(field.getType() == int.class && !field.isAccessible()) {
87+
field.setAccessible(true);
88+
getEntityTimeoutField = field;
89+
return;
90+
}
91+
}
8392

8493
} catch (Exception e) {
8594
e.printStackTrace();
@@ -139,11 +148,9 @@ public void setGatewayAgeHigh(Block block) {
139148
Object tileEntity = this.getTileEntityMethod.invoke(this.getWorldHandleMethod.invoke(block.getWorld()),
140149
this.blockPositionConstructor.newInstance(block.getX(), block.getY(), block.getZ()));
141150
if(tileEntity.getClass().isAssignableFrom(this.tileEntityEndGatewayClass)) {
142-
Field f = tileEntity.getClass().getDeclaredField("f");
143-
f.setAccessible(true);
144-
f.set(tileEntity, Integer.MAX_VALUE);
151+
getEntityTimeoutField.set(tileEntity, Integer.MAX_VALUE);
145152
}
146-
} catch (IllegalAccessException| InvocationTargetException | InstantiationException | NoSuchFieldException e) {
153+
} catch (IllegalAccessException| InvocationTargetException | InstantiationException e) {
147154
this.plugin.getLogger().warning("Error setting gateway time");
148155
e.printStackTrace();
149156
}

‎src/main/resources/plugin.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
main: com.sekwah.advancedportals.AdvancedPortalsPlugin
22
name: AdvancedPortals
3-
version: 0.0.46
3+
version: 0.0.47
44
author: sekwah41
55
description: An advanced portals plugin for bukkit.
66
api-version: 1.13

0 commit comments

Comments
 (0)
Please sign in to comment.