Skip to content

Commit

Permalink
Merge pull request #62 from retrooper/dev
Browse files Browse the repository at this point in the history
1.7.5 release
  • Loading branch information
retrooper committed Nov 9, 2020
2 parents a1c591a + 7c583bf commit a88e95e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.retrooper</groupId>
<artifactId>packetevents</artifactId>
<version>1.7.4</version>
<version>1.7.5</version>

<!-- You can build the project with this: "mvn clean compile assembly:single" -->
<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public final class PacketEvents implements Listener {
private static final PacketEvents instance = new PacketEvents();
private static final ArrayList<Plugin> plugins = new ArrayList<>(1);
private static boolean loaded, initialized;
private static final PEVersion version = new PEVersion(1, 7, 4);
private static final PEVersion version = new PEVersion(1, 7, 5);

private static PacketEventsSettings settings = new PacketEventsSettings();
/** General executor service, basically for anything that the packet executor service doesn't do.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,8 @@ public Object readAnyObject(int index) {
public Object readObject(int index, Class<?> type) {
Map<Class<?>, Field[]> cached = fieldCache.get(packetClass);
if (cached != null) {
if (!cached.containsKey(type)) {
Field[] cachedFields = cached.get(type);
if (cachedFields == null) {
List<Field> typeFields = new ArrayList<>();
for (Field f : packetClass.getDeclaredFields()) {
f.setAccessible(true);
Expand All @@ -501,10 +502,14 @@ public Object readObject(int index, Class<?> type) {
}
if (!typeFields.isEmpty()) {
cached.put(type, typeFields.toArray(new Field[0]));
cachedFields = cached.get(type);
}
else {
throw new WrapperFieldNotFoundException("The class you are trying to read fields from does not contain any fields!");
}
}
try {
return cached.get(type)[index].get(packet);
return cachedFields[index].get(packet);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -601,12 +606,9 @@ private Field getField(Class<?> type, int index) {
}

private List<Field> getFields(Class<?> type, Field[] fields) {
List<Field> ret = null;
List<Field> ret = new ArrayList<>();
for (Field field : fields) {
if (field.getType() == type) {
if (ret == null) {
ret = new ArrayList<>();
}
ret.add(field);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import io.github.retrooper.packetevents.enums.Direction;
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
import io.github.retrooper.packetevents.utils.server.ServerVersion;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;


public final class WrappedPacketInBlockPlace extends WrappedPacket {
Expand All @@ -41,21 +39,17 @@ public WrappedPacketInBlockPlace(final Object packet) {
public static void load() {
isHigherThan_v_1_8_8 = version.isHigherThan(ServerVersion.v_1_8_8);
isHigherThan_v_1_7_10 = version.isHigherThan(ServerVersion.v_1_7_10);
if (isHigherThan_v_1_8_8) {
WrappedPacketInBlockPlace_1_9.load();
}
WrappedPacketInBlockPlace_1_9.load();
}

public Direction getDirection() {
if(isHigherThan_v_1_8_8) {
if (isHigherThan_v_1_8_8) {
WrappedPacketInBlockPlace_1_9 blockPlace_1_9 = new WrappedPacketInBlockPlace_1_9(packet);
return Direction.valueOf(((Enum)blockPlace_1_9.getEnumDirectionObject()).name());
}
else if(isHigherThan_v_1_7_10) {
return Direction.valueOf(((Enum) blockPlace_1_9.getEnumDirectionObject()).name());
} else if (isHigherThan_v_1_7_10) {
WrappedPacketInBlockPlace_1_8 blockPlace_1_8 = new WrappedPacketInBlockPlace_1_8(packet);
return Direction.values()[blockPlace_1_8.getFace()];
}
else {
} else {
WrappedPacketInBlockPlace_1_7_10 blockPlace_1_7_10 = new WrappedPacketInBlockPlace_1_7_10(packet);
return Direction.values()[blockPlace_1_7_10.face];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ final class WrappedPacketInBlockPlace_1_8 extends WrappedPacket {

public int getX() {
if(blockPosObj == null) {
blockPosObj = readObject(0, NMSUtils.blockPosClass);
blockPosObj = readObject(1, NMSUtils.blockPosClass);
}
try {
return (int) Reflection.getMethod(blockPosObj.getClass().getSuperclass(), "getX", 0).invoke(blockPosObj);
Expand All @@ -49,10 +49,11 @@ public int getX() {
}
return -1;
}


public int getY() {
if(blockPosObj == null) {
blockPosObj = readObject(0, NMSUtils.blockPosClass);
blockPosObj = readObject(1, NMSUtils.blockPosClass);
}
try {
return (int) Reflection.getMethod(blockPosObj.getClass().getSuperclass(), "getY", 0).invoke(blockPosObj);
Expand All @@ -64,7 +65,7 @@ public int getY() {

public int getZ() {
if(blockPosObj == null) {
blockPosObj = readObject(0, NMSUtils.blockPosClass);
blockPosObj = readObject(1, NMSUtils.blockPosClass);
}
try {
return (int) Reflection.getMethod(blockPosObj.getClass().getSuperclass(), "getZ", 0).invoke(blockPosObj);
Expand Down

0 comments on commit a88e95e

Please sign in to comment.