diff --git a/src/main/java/com/useful/ucars/CartOrientationUtil.java b/src/main/java/com/useful/ucars/CartOrientationUtil.java index fe20766..251b4d6 100644 --- a/src/main/java/com/useful/ucars/CartOrientationUtil.java +++ b/src/main/java/com/useful/ucars/CartOrientationUtil.java @@ -40,18 +40,20 @@ public static void setPitch(Entity cart, float pitch){ Method getHandle = cmr.getMethod("getHandle"); Object nmsCart = getHandle.invoke(cmr.cast(cart)); Field p = null; - if(ucars.MCVersion < 17) { - Class ema = Reflect.getNMSClass("world.entity.vehicle.","EntityMinecartAbstract"); - p = ema.getField("pitch"); - p.setAccessible(true); - p.set(ema.cast(nmsCart), -pitch); - p.setAccessible(false); - } else { - Class e = Reflect.getNMSClass("world.entity.","Entity"); - p = e.getDeclaredField("az"); //Pitch field is now az and in the Entity-Class - p.setAccessible(true); - p.set(e.cast(nmsCart), -pitch); - p.setAccessible(false); + if(ucars.MCVersion.get(0) == 1) { + if(ucars.MCVersion.get(1) < 17) { + Class ema = Reflect.getNMSClass("world.entity.vehicle.","EntityMinecartAbstract"); + p = ema.getField("pitch"); + p.setAccessible(true); + p.set(ema.cast(nmsCart), -pitch); + p.setAccessible(false); + } else { + Class e = Reflect.getNMSClass("world.entity.","Entity"); + p = e.getDeclaredField("az"); //Pitch field is now az and in the Entity-Class + p.setAccessible(true); + p.set(e.cast(nmsCart), -pitch); + p.setAccessible(false); + } } } catch (Exception e) { e.printStackTrace(); @@ -71,18 +73,20 @@ public static void setYaw(Entity cart, float yaw){ Method getHandle = cmr.getMethod("getHandle"); Object nmsCart = getHandle.invoke(cmr.cast(cart)); Field p = null; - if(ucars.MCVersion < 17) { - Class ema = Reflect.getNMSClass("world.entity.vehicle.","EntityMinecartAbstract"); - p = ema.getField("yaw"); - p.setAccessible(true); - p.set(ema.cast(nmsCart), yaw); - p.setAccessible(false); - } else { - Class e = Reflect.getNMSClass("world.entity.","Entity"); - p = e.getDeclaredField("ay"); //Yaw field is now ay and in the Entity-Class - p.setAccessible(true); - p.set(e.cast(nmsCart), yaw); - p.setAccessible(false); + if(ucars.MCVersion.get(0) == 1) { + if(ucars.MCVersion.get(1) < 17) { + Class ema = Reflect.getNMSClass("world.entity.vehicle.","EntityMinecartAbstract"); + p = ema.getField("yaw"); + p.setAccessible(true); + p.set(ema.cast(nmsCart), yaw); + p.setAccessible(false); + } else { + Class e = Reflect.getNMSClass("world.entity.","Entity"); + p = e.getDeclaredField("ay"); //Yaw field is now ay and in the Entity-Class + p.setAccessible(true); + p.set(e.cast(nmsCart), yaw); + p.setAccessible(false); + } } } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/com/useful/ucars/Reflect.java b/src/main/java/com/useful/ucars/Reflect.java index c0c4d5c..a735baa 100644 --- a/src/main/java/com/useful/ucars/Reflect.java +++ b/src/main/java/com/useful/ucars/Reflect.java @@ -49,10 +49,12 @@ public static void sendPacket(Player p, Object packet) { public static Class getNMSClass(String newPackage, String ClassName) { String className = "net.minecraft."; - if(ucars.MCVersion < 17) { - className += "server."+ version + ClassName; - } else { - className += newPackage+ClassName; + if(ucars.MCVersion.get(0) == 1) { + if(ucars.MCVersion.get(1) < 17) { + className += "server."+ version + ClassName; + } else { + className += newPackage+ClassName; + } } Class c = null; diff --git a/src/main/java/com/useful/ucars/ucars.java b/src/main/java/com/useful/ucars/ucars.java index b0be5d6..671e5d0 100644 --- a/src/main/java/com/useful/ucars/ucars.java +++ b/src/main/java/com/useful/ucars/ucars.java @@ -14,6 +14,8 @@ import java.util.Map; import java.util.Set; import java.util.logging.Level; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -63,7 +65,7 @@ public class ucars extends JavaPlugin { public static boolean playersIgnoreTrafficLights = false; public static boolean turningCircles = true; public static boolean fireUpdateEvent = false; - public static Float MCVersion = null; + public static ArrayList MCVersion = new ArrayList(); public static String colorise(String prefix) { return ChatColor.translateAlternateColorCodes('&', prefix); @@ -171,8 +173,15 @@ public void run() { @Override public void onEnable() { plugin = this; - - MCVersion = Float.valueOf(Bukkit.getVersion().replace(")","").split("MC: 1.")[1]); + + Pattern pattern = Pattern.compile(".v(.*?)_R"); //Get MC-Version + Matcher matcher = pattern.matcher(Bukkit.getServer().getClass().getPackage().getName()); + if(matcher.find()) { + String[] MCVersionStr = matcher.group(1).split("_"); + for(String s:MCVersionStr) { + MCVersion.add(Integer.parseInt(s)); + } + } File langFile = new File(getDataFolder().getAbsolutePath() + File.separator + "lang.yml");