From 6a19624e4b20e829dd55af997cc9360c3052a6b6 Mon Sep 17 00:00:00 2001 From: Shevchik Date: Fri, 7 Mar 2014 09:28:47 +0400 Subject: [PATCH] Pass craftworld to the constructor to do less reflection --- src/com/cnaude/chairs/core/PlayerSitData.java | 2 +- src/com/cnaude/chairs/vehiclearrow/NMSAccess.java | 11 +++-------- .../chairs/vehiclearrow/nms164/NMSChairsArrow.java | 6 +++--- .../chairs/vehiclearrow/nms172/NMSChairsArrow.java | 6 +++--- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/com/cnaude/chairs/core/PlayerSitData.java b/src/com/cnaude/chairs/core/PlayerSitData.java index edaef58..cd08520 100644 --- a/src/com/cnaude/chairs/core/PlayerSitData.java +++ b/src/com/cnaude/chairs/core/PlayerSitData.java @@ -77,7 +77,7 @@ public class PlayerSitData { 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); arrow.setPassenger(player); return arrow; diff --git a/src/com/cnaude/chairs/vehiclearrow/NMSAccess.java b/src/com/cnaude/chairs/vehiclearrow/NMSAccess.java index b3ee385..217f441 100644 --- a/src/com/cnaude/chairs/vehiclearrow/NMSAccess.java +++ b/src/com/cnaude/chairs/vehiclearrow/NMSAccess.java @@ -2,7 +2,6 @@ package com.cnaude.chairs.vehiclearrow; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -30,14 +29,10 @@ public class NMSAccess { 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(); - Method getHandle = world.getClass().getDeclaredMethod("getHandle"); - getHandle.setAccessible(true); - Object nmsworld = getHandle.invoke(world); - Constructor ct = nmsArrowClass.getConstructor(nmsworld.getClass().getSuperclass()); - ct.setAccessible(true); - NMSChairsArrowInterface vehiclearrow = (NMSChairsArrowInterface) ct.newInstance(nmsworld); + Constructor ct = nmsArrowClass.getConstructor(world.getClass()); + NMSChairsArrowInterface vehiclearrow = (NMSChairsArrowInterface) ct.newInstance(world); vehiclearrow.setArrowLocation(location); vehiclearrow.addToWorld(); vehiclearrow.setBukkitEntity(Bukkit.getServer()); diff --git a/src/com/cnaude/chairs/vehiclearrow/nms164/NMSChairsArrow.java b/src/com/cnaude/chairs/vehiclearrow/nms164/NMSChairsArrow.java index 7dfd595..62fccfb 100644 --- a/src/com/cnaude/chairs/vehiclearrow/nms164/NMSChairsArrow.java +++ b/src/com/cnaude/chairs/vehiclearrow/nms164/NMSChairsArrow.java @@ -1,19 +1,19 @@ package com.cnaude.chairs.vehiclearrow.nms164; import net.minecraft.server.v1_6_R3.EntityArrow; -import net.minecraft.server.v1_6_R3.World; import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.craftbukkit.v1_6_R3.CraftServer; +import org.bukkit.craftbukkit.v1_6_R3.CraftWorld; import org.bukkit.entity.Arrow; import com.cnaude.chairs.vehiclearrow.NMSChairsArrowInterface; public class NMSChairsArrow extends EntityArrow implements NMSChairsArrowInterface { - public NMSChairsArrow(World world) { - super(world); + public NMSChairsArrow(CraftWorld cworld) { + super(cworld.getHandle()); } @Override diff --git a/src/com/cnaude/chairs/vehiclearrow/nms172/NMSChairsArrow.java b/src/com/cnaude/chairs/vehiclearrow/nms172/NMSChairsArrow.java index 3409c69..c99f6b6 100644 --- a/src/com/cnaude/chairs/vehiclearrow/nms172/NMSChairsArrow.java +++ b/src/com/cnaude/chairs/vehiclearrow/nms172/NMSChairsArrow.java @@ -1,10 +1,10 @@ package com.cnaude.chairs.vehiclearrow.nms172; import net.minecraft.server.v1_7_R1.EntityArrow; -import net.minecraft.server.v1_7_R1.World; import org.bukkit.Location; import org.bukkit.Server; +import org.bukkit.craftbukkit.v1_7_R1.CraftWorld; import org.bukkit.craftbukkit.v1_7_R1.CraftServer; import org.bukkit.entity.Arrow; @@ -12,8 +12,8 @@ import com.cnaude.chairs.vehiclearrow.NMSChairsArrowInterface; public class NMSChairsArrow extends EntityArrow implements NMSChairsArrowInterface { - public NMSChairsArrow(World world) { - super(world); + public NMSChairsArrow(CraftWorld cworld) { + super(cworld.getHandle()); } @Override