Pass craftworld to the constructor to do less reflection

This commit is contained in:
Shevchik 2014-03-07 09:28:47 +04:00
parent 364c687e16
commit 6a19624e4b
4 changed files with 10 additions and 15 deletions

View File

@ -77,7 +77,7 @@ public class PlayerSitData {
e.printStackTrace(); e.printStackTrace();
} }
} }
private Entity sitPlayerOnArrow(Player player, Location arrowloc) throws NoSuchMethodException, SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, InstantiationException, InvocationTargetException { private Entity sitPlayerOnArrow(Player player, Location arrowloc) throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Entity arrow = plugin.getNMSAccess().spawnArrow(arrowloc); Entity arrow = plugin.getNMSAccess().spawnArrow(arrowloc);
arrow.setPassenger(player); arrow.setPassenger(player);
return arrow; return arrow;

View File

@ -2,7 +2,6 @@ package com.cnaude.chairs.vehiclearrow;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
@ -30,14 +29,10 @@ public class NMSAccess {
throw new Exception("ChairsReloaded is not compatible with your server version"); throw new Exception("ChairsReloaded is not compatible with your server version");
} }
public Arrow spawnArrow(Location location) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException { public Arrow spawnArrow(Location location) throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
World world = location.getWorld(); World world = location.getWorld();
Method getHandle = world.getClass().getDeclaredMethod("getHandle"); Constructor<?> ct = nmsArrowClass.getConstructor(world.getClass());
getHandle.setAccessible(true); NMSChairsArrowInterface vehiclearrow = (NMSChairsArrowInterface) ct.newInstance(world);
Object nmsworld = getHandle.invoke(world);
Constructor<?> ct = nmsArrowClass.getConstructor(nmsworld.getClass().getSuperclass());
ct.setAccessible(true);
NMSChairsArrowInterface vehiclearrow = (NMSChairsArrowInterface) ct.newInstance(nmsworld);
vehiclearrow.setArrowLocation(location); vehiclearrow.setArrowLocation(location);
vehiclearrow.addToWorld(); vehiclearrow.addToWorld();
vehiclearrow.setBukkitEntity(Bukkit.getServer()); vehiclearrow.setBukkitEntity(Bukkit.getServer());

View File

@ -1,19 +1,19 @@
package com.cnaude.chairs.vehiclearrow.nms164; package com.cnaude.chairs.vehiclearrow.nms164;
import net.minecraft.server.v1_6_R3.EntityArrow; import net.minecraft.server.v1_6_R3.EntityArrow;
import net.minecraft.server.v1_6_R3.World;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.craftbukkit.v1_6_R3.CraftServer; import org.bukkit.craftbukkit.v1_6_R3.CraftServer;
import org.bukkit.craftbukkit.v1_6_R3.CraftWorld;
import org.bukkit.entity.Arrow; import org.bukkit.entity.Arrow;
import com.cnaude.chairs.vehiclearrow.NMSChairsArrowInterface; import com.cnaude.chairs.vehiclearrow.NMSChairsArrowInterface;
public class NMSChairsArrow extends EntityArrow implements NMSChairsArrowInterface { public class NMSChairsArrow extends EntityArrow implements NMSChairsArrowInterface {
public NMSChairsArrow(World world) { public NMSChairsArrow(CraftWorld cworld) {
super(world); super(cworld.getHandle());
} }
@Override @Override

View File

@ -1,10 +1,10 @@
package com.cnaude.chairs.vehiclearrow.nms172; package com.cnaude.chairs.vehiclearrow.nms172;
import net.minecraft.server.v1_7_R1.EntityArrow; import net.minecraft.server.v1_7_R1.EntityArrow;
import net.minecraft.server.v1_7_R1.World;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.craftbukkit.v1_7_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_7_R1.CraftServer; import org.bukkit.craftbukkit.v1_7_R1.CraftServer;
import org.bukkit.entity.Arrow; import org.bukkit.entity.Arrow;
@ -12,8 +12,8 @@ import com.cnaude.chairs.vehiclearrow.NMSChairsArrowInterface;
public class NMSChairsArrow extends EntityArrow implements NMSChairsArrowInterface { public class NMSChairsArrow extends EntityArrow implements NMSChairsArrowInterface {
public NMSChairsArrow(World world) { public NMSChairsArrow(CraftWorld cworld) {
super(world); super(cworld.getHandle());
} }
@Override @Override