This commit is contained in:
MattBDev 2016-05-28 22:37:56 -04:00
parent 6c40ed7718
commit 4af846967c
5 changed files with 46 additions and 30 deletions

View File

@ -43,6 +43,7 @@ public class SendChunk {
* Constructor * Constructor
*/ */
public SendChunk() throws ClassNotFoundException, NoSuchMethodException, NoSuchFieldException { public SendChunk() throws ClassNotFoundException, NoSuchMethodException, NoSuchFieldException {
RefConstructor tempMapChunk;
RefClass classCraftPlayer = getRefClass("{cb}.entity.CraftPlayer"); RefClass classCraftPlayer = getRefClass("{cb}.entity.CraftPlayer");
this.methodGetHandlePlayer = classCraftPlayer.getMethod("getHandle"); this.methodGetHandlePlayer = classCraftPlayer.getMethod("getHandle");
RefClass classCraftChunk = getRefClass("{cb}.CraftChunk"); RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
@ -50,12 +51,16 @@ public class SendChunk {
RefClass classChunk = getRefClass("{nms}.Chunk"); RefClass classChunk = getRefClass("{nms}.Chunk");
this.methodInitLighting = classChunk.getMethod("initLighting"); this.methodInitLighting = classChunk.getMethod("initLighting");
RefClass classMapChunk = getRefClass("{nms}.PacketPlayOutMapChunk"); RefClass classMapChunk = getRefClass("{nms}.PacketPlayOutMapChunk");
//TODO in 1.7.10 this is PacketPlayOutMapChunk(Chunk chunk, boolean flag, int i, int version)
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), 1, 9, 4)) { if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), 1, 9, 4)) {
this.mapChunk = classMapChunk.getConstructor(classChunk.getRealClass(),int.class); tempMapChunk = classMapChunk.getConstructor(classChunk.getRealClass(),int.class);
} else { } else {
this.mapChunk = classMapChunk.getConstructor(classChunk.getRealClass(), boolean.class, int.class); try {
tempMapChunk = classMapChunk.getConstructor(classChunk.getRealClass(), boolean.class, int.class);
} catch (NoSuchMethodException ignored) {
tempMapChunk = classMapChunk.getConstructor(classChunk.getRealClass(),boolean.class, int.class, int.class);
} }
}
this.mapChunk = tempMapChunk;
RefClass classEntityPlayer = getRefClass("{nms}.EntityPlayer"); RefClass classEntityPlayer = getRefClass("{nms}.EntityPlayer");
this.connection = classEntityPlayer.getField("playerConnection"); this.connection = classEntityPlayer.getField("playerConnection");
RefClass classPacket = getRefClass("{nms}.Packet"); RefClass classPacket = getRefClass("{nms}.Packet");
@ -110,11 +115,24 @@ public class SendChunk {
Object c = this.methodGetHandleChunk.of(chunk).call(); Object c = this.methodGetHandleChunk.of(chunk).call();
chunks.remove(chunk); chunks.remove(chunk);
Object con = this.connection.of(entity).get(); Object con = this.connection.of(entity).get();
Object packet; Object packet = null;
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), 1, 9, 4)) { if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), 1, 9, 4)) {
try {
packet = this.mapChunk.create(c,65535); packet = this.mapChunk.create(c,65535);
} catch (Exception ignored) {}
} else { } else {
try {
packet = this.mapChunk.create(c, true, 65535); packet = this.mapChunk.create(c, true, 65535);
} catch (ReflectiveOperationException | IllegalArgumentException e) {
try {
packet = this.mapChunk.create(c, true, 65535, 5);
} catch (ReflectiveOperationException | IllegalArgumentException e1) {
e1.printStackTrace();
}
}
}
if (packet == null) {
PS.debug("Error with PacketPlayOutMapChunk reflection.");
} }
this.send.of(con).call(packet); this.send.of(con).call(packet);
} }

View File

@ -319,7 +319,12 @@ public class FastQueue_1_8 extends SlowQueue {
// End blockstate workaround // // End blockstate workaround //
// check sign // check sign
Object pos = this.constructorBlockPosition.create(x, y, z); Object pos = null;
try {
pos = this.constructorBlockPosition.create(x, y, z);
} catch (ReflectiveOperationException e) {
e.printStackTrace();
}
Object combined = this.methodGetByCombinedId.call(newBlock.id + (newBlock.data << 12)); Object combined = this.methodGetByCombinedId.call(newBlock.id + (newBlock.data << 12));
this.methodA.of(chunk).call(pos, combined); this.methodA.of(chunk).call(pos, combined);
} }

View File

@ -23,7 +23,6 @@ import org.bukkit.World.Environment;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@ -220,8 +219,7 @@ public class FastQueue_1_8_3 extends SlowQueue {
} }
} }
// Clear // Clear
} catch (IllegalAccessException | IllegalArgumentException | NoSuchMethodException | SecurityException | InvocationTargetException } catch (IllegalArgumentException | SecurityException | ReflectiveOperationException e) {
| NoSuchFieldException e) {
e.printStackTrace(); e.printStackTrace();
} }
int[][] biomes = fs.biomes; int[][] biomes = fs.biomes;
@ -243,7 +241,7 @@ public class FastQueue_1_8_3 extends SlowQueue {
} }
} }
public Object newChunkSection(int i, boolean flag, char[] ids) { public Object newChunkSection(int i, boolean flag, char[] ids) throws ReflectiveOperationException {
return this.classChunkSectionConstructor.create(i, flag, ids); return this.classChunkSectionConstructor.create(i, flag, ids);
} }

View File

@ -1,5 +1,7 @@
package com.plotsquared.bukkit.util.block; package com.plotsquared.bukkit.util.block;
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.PseudoRandom; import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
@ -12,22 +14,19 @@ import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod;
import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod.RefExecutor; import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod.RefExecutor;
import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper; import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper;
import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.bukkit.util.BukkitUtil;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.World.Environment; import org.bukkit.World.Environment;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import java.lang.reflect.Field;
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass; import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;
public class FastQueue_1_9 extends SlowQueue { public class FastQueue_1_9 extends SlowQueue {
@ -197,8 +196,7 @@ public class FastQueue_1_9 extends SlowQueue {
} }
} }
// Clear // Clear
} catch (IllegalAccessException | IllegalArgumentException | NoSuchMethodException | SecurityException | InvocationTargetException | } catch (IllegalArgumentException | SecurityException | ReflectiveOperationException e) {
NoSuchFieldException e) {
e.printStackTrace(); e.printStackTrace();
} }
int[][] biomes = fs.biomes; int[][] biomes = fs.biomes;
@ -221,7 +219,7 @@ public class FastQueue_1_9 extends SlowQueue {
world.refreshChunk(fs.getX(), fs.getZ()); world.refreshChunk(fs.getX(), fs.getZ());
} }
public Object newChunkSection(int i, boolean flag, char[] ids) { public Object newChunkSection(int i, boolean flag, char[] ids) throws ReflectiveOperationException {
return this.classChunkSectionConstructor.create(i, flag, ids); return this.classChunkSectionConstructor.create(i, flag, ids);
} }

View File

@ -609,14 +609,11 @@ public class ReflectionUtils {
* *
* @return new object * @return new object
* *
* @throws RuntimeException if something went wrong * @throws ReflectiveOperationException
* @throws IllegalArgumentException
*/ */
public Object create(Object... params) { public Object create(Object... params) throws ReflectiveOperationException, IllegalArgumentException {
try {
return this.constructor.newInstance(params); return this.constructor.newInstance(params);
} catch (Exception e) {
throw new RuntimeException(e);
}
} }
} }