Don't use reflection to increment container counter

Fixes #53 (pretty please with a cherry on top)
This commit is contained in:
Jikoo 2016-11-27 06:13:17 -05:00
parent 0bbcf6cdb2
commit 6aa25dd2dc
13 changed files with 13 additions and 133 deletions

View file

@ -16,8 +16,6 @@
package com.lishid.openinv.internal.v1_4_5;
import java.lang.reflect.Field;
import com.lishid.openinv.internal.IAnySilentContainer;
import org.bukkit.ChatColor;
@ -142,15 +140,7 @@ public class AnySilentContainer implements IAnySilentContainer {
returnValue = true;
} else {
try {
int windowId = 0;
try {
Field windowID = player.getClass().getDeclaredField("containerCounter");
windowID.setAccessible(true);
windowId = windowID.getInt(player);
windowId = windowId % 100 + 1;
windowID.setInt(player, windowId);
} catch (NoSuchFieldException e) {}
int windowId = player.nextContainerCounter();
player.netServerHandler.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) tile).getName(), ((IInventory) tile).getSize()));
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
player.activeContainer.windowId = windowId;

View file

@ -16,8 +16,6 @@
package com.lishid.openinv.internal.v1_4_6;
import java.lang.reflect.Field;
import com.lishid.openinv.internal.IAnySilentContainer;
import org.bukkit.ChatColor;
@ -142,15 +140,7 @@ public class AnySilentContainer implements IAnySilentContainer {
returnValue = true;
} else {
try {
int windowId = 0;
try {
Field windowID = player.getClass().getDeclaredField("containerCounter");
windowID.setAccessible(true);
windowId = windowID.getInt(player);
windowId = windowId % 100 + 1;
windowID.setInt(player, windowId);
} catch (NoSuchFieldException e) {}
int windowId = player.nextContainerCounter();
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) tile).getName(), ((IInventory) tile).getSize()));
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
player.activeContainer.windowId = windowId;

View file

@ -10,7 +10,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<openinv.version>3.0.1</openinv.version>
<openinv.version>3.0.1-SNAPSHOT</openinv.version>
</properties>
<profiles>

View file

@ -16,8 +16,6 @@
package com.lishid.openinv.internal.v1_4_R1;
import java.lang.reflect.Field;
import com.lishid.openinv.internal.IAnySilentContainer;
import org.bukkit.ChatColor;
@ -142,15 +140,7 @@ public class AnySilentContainer implements IAnySilentContainer {
returnValue = true;
} else {
try {
int windowId = 0;
try {
Field windowID = player.getClass().getDeclaredField("containerCounter");
windowID.setAccessible(true);
windowId = windowID.getInt(player);
windowId = windowId % 100 + 1;
windowID.setInt(player, windowId);
} catch (NoSuchFieldException e) {}
int windowId = player.nextContainerCounter();
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) tile).getName(), ((IInventory) tile).getSize()));
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
player.activeContainer.windowId = windowId;

View file

@ -16,8 +16,6 @@
package com.lishid.openinv.internal.v1_5_R2;
import java.lang.reflect.Field;
import com.lishid.openinv.internal.IAnySilentContainer;
import org.bukkit.ChatColor;
@ -142,15 +140,7 @@ public class AnySilentContainer implements IAnySilentContainer {
returnValue = true;
} else {
try {
int windowId = 0;
try {
Field windowID = player.getClass().getDeclaredField("containerCounter");
windowID.setAccessible(true);
windowId = windowID.getInt(player);
windowId = windowId % 100 + 1;
windowID.setInt(player, windowId);
} catch (NoSuchFieldException e) {}
int windowId = player.nextContainerCounter();
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) tile).getName(), ((IInventory) tile).getSize(), true));
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
player.activeContainer.windowId = windowId;

View file

@ -16,8 +16,6 @@
package com.lishid.openinv.internal.v1_5_R3;
import java.lang.reflect.Field;
import com.lishid.openinv.internal.IAnySilentContainer;
import org.bukkit.ChatColor;
@ -142,15 +140,7 @@ public class AnySilentContainer implements IAnySilentContainer {
returnValue = true;
} else {
try {
int windowId = 0;
try {
Field windowID = player.getClass().getDeclaredField("containerCounter");
windowID.setAccessible(true);
windowId = windowID.getInt(player);
windowId = windowId % 100 + 1;
windowID.setInt(player, windowId);
} catch (NoSuchFieldException e) {}
int windowId = player.nextContainerCounter();
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) tile).getName(), ((IInventory) tile).getSize(), true));
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
player.activeContainer.windowId = windowId;

View file

@ -16,8 +16,6 @@
package com.lishid.openinv.internal.v1_6_R1;
import java.lang.reflect.Field;
import com.lishid.openinv.internal.IAnySilentContainer;
import org.bukkit.ChatColor;
@ -142,15 +140,7 @@ public class AnySilentContainer implements IAnySilentContainer {
returnValue = true;
} else {
try {
int windowId = 0;
try {
Field windowID = player.getClass().getDeclaredField("containerCounter");
windowID.setAccessible(true);
windowId = windowID.getInt(player);
windowId = windowId % 100 + 1;
windowID.setInt(player, windowId);
} catch (NoSuchFieldException e) {}
int windowId = player.nextContainerCounter();
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) tile).getName(), ((IInventory) tile).getSize(), true));
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
player.activeContainer.windowId = windowId;

View file

@ -16,8 +16,6 @@
package com.lishid.openinv.internal.v1_6_R2;
import java.lang.reflect.Field;
import com.lishid.openinv.internal.IAnySilentContainer;
import org.bukkit.ChatColor;
@ -142,15 +140,7 @@ public class AnySilentContainer implements IAnySilentContainer {
returnValue = true;
} else {
try {
int windowId = 0;
try {
Field windowID = player.getClass().getDeclaredField("containerCounter");
windowID.setAccessible(true);
windowId = windowID.getInt(player);
windowId = windowId % 100 + 1;
windowID.setInt(player, windowId);
} catch (NoSuchFieldException e) {}
int windowId = player.nextContainerCounter();
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) tile).getName(), ((IInventory) tile).getSize(), true));
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
player.activeContainer.windowId = windowId;

View file

@ -16,8 +16,6 @@
package com.lishid.openinv.internal.v1_6_R3;
import java.lang.reflect.Field;
import com.lishid.openinv.internal.IAnySilentContainer;
import org.bukkit.ChatColor;
@ -142,15 +140,7 @@ public class AnySilentContainer implements IAnySilentContainer {
returnValue = true;
} else {
try {
int windowId = 0;
try {
Field windowID = player.getClass().getDeclaredField("containerCounter");
windowID.setAccessible(true);
windowId = windowID.getInt(player);
windowId = windowId % 100 + 1;
windowID.setInt(player, windowId);
} catch (NoSuchFieldException e) {}
int windowId = player.nextContainerCounter();
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) tile).getName(), ((IInventory) tile).getSize(), true));
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
player.activeContainer.windowId = windowId;

View file

@ -16,8 +16,6 @@
package com.lishid.openinv.internal.v1_7_R1;
import java.lang.reflect.Field;
import com.lishid.openinv.internal.IAnySilentContainer;
import org.bukkit.ChatColor;
@ -143,15 +141,7 @@ public class AnySilentContainer implements IAnySilentContainer {
returnValue = true;
} else {
try {
int windowId = 0;
try {
Field windowID = player.getClass().getDeclaredField("containerCounter");
windowID.setAccessible(true);
windowId = windowID.getInt(player);
windowId = windowId % 100 + 1;
windowID.setInt(player, windowId);
} catch (NoSuchFieldException e) {}
int windowId = player.nextContainerCounter();
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) tile).getInventoryName(), ((IInventory) tile).getSize(), true));
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
player.activeContainer.windowId = windowId;

View file

@ -16,8 +16,6 @@
package com.lishid.openinv.internal.v1_7_R2;
import java.lang.reflect.Field;
import com.lishid.openinv.internal.IAnySilentContainer;
import org.bukkit.ChatColor;
@ -143,15 +141,7 @@ public class AnySilentContainer implements IAnySilentContainer {
returnValue = true;
} else {
try {
int windowId = 0;
try {
Field windowID = player.getClass().getDeclaredField("containerCounter");
windowID.setAccessible(true);
windowId = windowID.getInt(player);
windowId = windowId % 100 + 1;
windowID.setInt(player, windowId);
} catch (NoSuchFieldException e) {}
int windowId = player.nextContainerCounter();
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) tile).getInventoryName(), ((IInventory) tile).getSize(), true));
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
player.activeContainer.windowId = windowId;

View file

@ -16,8 +16,6 @@
package com.lishid.openinv.internal.v1_7_R3;
import java.lang.reflect.Field;
import com.lishid.openinv.internal.IAnySilentContainer;
import org.bukkit.ChatColor;
@ -143,15 +141,7 @@ public class AnySilentContainer implements IAnySilentContainer {
returnValue = true;
} else {
try {
int windowId = 0;
try {
Field windowID = player.getClass().getDeclaredField("containerCounter");
windowID.setAccessible(true);
windowId = windowID.getInt(player);
windowId = windowId % 100 + 1;
windowID.setInt(player, windowId);
} catch (NoSuchFieldException e) {}
int windowId = player.nextContainerCounter();
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) tile).getInventoryName(), ((IInventory) tile).getSize(), true));
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
player.activeContainer.windowId = windowId;

View file

@ -16,8 +16,6 @@
package com.lishid.openinv.internal.v1_7_R4;
import java.lang.reflect.Field;
import com.lishid.openinv.internal.IAnySilentContainer;
import org.bukkit.ChatColor;
@ -143,15 +141,7 @@ public class AnySilentContainer implements IAnySilentContainer {
returnValue = true;
} else {
try {
int windowId = 0;
try {
Field windowID = player.getClass().getDeclaredField("containerCounter");
windowID.setAccessible(true);
windowId = windowID.getInt(player);
windowId = windowId % 100 + 1;
windowID.setInt(player, windowId);
} catch (NoSuchFieldException e) {}
int windowId = player.nextContainerCounter();
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) tile).getInventoryName(), ((IInventory) tile).getSize(), true));
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
player.activeContainer.windowId = windowId;