From 0faa6df7efa74ac6183dbae56d21b71c3f97e43b Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Thu, 16 Jul 2015 20:33:17 +0200 Subject: [PATCH] NMS handler Works with v1_7_R3 - v1_8_R3. --- src/com/dre/dungeonsxl/P.java | 63 ++------------- .../MultiVersionHandler.java | 68 +++++++++++++++++ .../multiversionhandler/v1_7_R3.java | 75 ++++++++++++++++++ .../multiversionhandler/v1_7_R4.java | 75 ++++++++++++++++++ .../multiversionhandler/v1_8_R1.java | 76 +++++++++++++++++++ .../multiversionhandler/v1_8_R2.java | 76 +++++++++++++++++++ .../multiversionhandler/v1_8_R3.java | 76 +++++++++++++++++++ src/plugin.yml | 2 +- 8 files changed, 453 insertions(+), 58 deletions(-) create mode 100644 src/com/dre/dungeonsxl/multiversionhandler/MultiVersionHandler.java create mode 100644 src/com/dre/dungeonsxl/multiversionhandler/v1_7_R3.java create mode 100644 src/com/dre/dungeonsxl/multiversionhandler/v1_7_R4.java create mode 100644 src/com/dre/dungeonsxl/multiversionhandler/v1_8_R1.java create mode 100644 src/com/dre/dungeonsxl/multiversionhandler/v1_8_R2.java create mode 100644 src/com/dre/dungeonsxl/multiversionhandler/v1_8_R3.java diff --git a/src/com/dre/dungeonsxl/P.java b/src/com/dre/dungeonsxl/P.java index daf3ae12..1dbebbd4 100644 --- a/src/com/dre/dungeonsxl/P.java +++ b/src/com/dre/dungeonsxl/P.java @@ -12,11 +12,6 @@ import java.util.UUID; import java.util.concurrent.CopyOnWriteArrayList; import net.milkbowl.vault.permission.Permission; -import net.minecraft.server.v1_8_R3.EntityPlayer; -import net.minecraft.server.v1_8_R3.MinecraftServer; -import net.minecraft.server.v1_8_R3.PlayerInteractManager; - -import com.mojang.authlib.GameProfile; import org.apache.commons.lang.math.NumberUtils; import org.bukkit.Bukkit; @@ -25,8 +20,6 @@ import org.bukkit.Location; import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.craftbukkit.v1_8_R3.CraftServer; -import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; @@ -43,6 +36,7 @@ import com.dre.dungeonsxl.listener.EntityListener; import com.dre.dungeonsxl.listener.HangingListener; import com.dre.dungeonsxl.listener.PlayerListener; import com.dre.dungeonsxl.listener.WorldListener; +import com.dre.dungeonsxl.multiversionhandler.MultiVersionHandler; public class P extends JavaPlugin { public static P p; @@ -118,6 +112,9 @@ public class P extends JavaPlugin { // MSG this.log(this.getDescription().getName() + " enabled!"); + if (!(MultiVersionHandler.supported.contains(MultiVersionHandler.getInternals()))) { + this.log("Warning: Your CraftBukkit version is deprecated. DungeonsXL does not support it."); + } } @Override @@ -434,59 +431,11 @@ public class P extends JavaPlugin { } public Player getOfflinePlayer(String player, UUID uuid) { - Player pplayer = null; - try { - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - - for (File playerfile : playerfolder.listFiles()) { - String filename = playerfile.getName(); - String playername = filename.substring(0, filename.length() - 4); - - GameProfile profile = new GameProfile(uuid, playername); - - if (playername.trim().equalsIgnoreCase(player)) { - MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); - EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); - Player target = (entity == null) ? null : (Player) entity.getBukkitEntity(); - if (target != null) { - target.loadData(); - return target; - } - } - } - } catch (Exception e) { - return null; - } - return pplayer; + return MultiVersionHandler.getOfflinePlayer(player, uuid); } public Player getOfflinePlayer(String player, UUID uuid, Location location) { - Player pplayer = null; - try { - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - - for (File playerfile : playerfolder.listFiles()) { - String filename = playerfile.getName(); - String playername = filename.substring(0, filename.length() - 4); - - GameProfile profile = new GameProfile(uuid, playername); - - if (playername.trim().equalsIgnoreCase(player)) { - MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); - EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); - entity.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); - entity.world = ((CraftWorld) location.getWorld()).getHandle(); - Player target = (entity == null) ? null : (Player) entity.getBukkitEntity(); - if (target != null) { - // target.loadData(); - return target; - } - } - } - } catch (Exception e) { - return null; - } - return pplayer; + return MultiVersionHandler.getOfflinePlayer(player, uuid, location); } // -------------------------------------------- // diff --git a/src/com/dre/dungeonsxl/multiversionhandler/MultiVersionHandler.java b/src/com/dre/dungeonsxl/multiversionhandler/MultiVersionHandler.java new file mode 100644 index 00000000..3f8f17c0 --- /dev/null +++ b/src/com/dre/dungeonsxl/multiversionhandler/MultiVersionHandler.java @@ -0,0 +1,68 @@ +package com.dre.dungeonsxl.multiversionhandler; + +import java.util.UUID; + +import org.bukkit.Location; +import org.bukkit.entity.Player; + +import com.dre.dungeonsxl.P; + +public class MultiVersionHandler { + + private static String version = P.p.getServer().getVersion(); + + public static String supported = "v1_8_R1,v1_8_R2,v1_8_R3"; + + public static String getInternals() { + String internals = "v1_8_R3"; + if (version.contains("1.8.4") || version.contains("1.8.5") || version.contains("1.8.6") || version.contains("1.8.7")) { + internals = "v1_8_R3"; + } else if (version.contains("1.8.3")) { + internals = "v1_8_R2"; + } else if (version.contains("1.8") && !version.contains("1.8.")) { + internals = "v1_8_R1"; + } else if (version.contains("1.7.10")) { + internals = "v1_7_R4"; + } else if (version.contains("1.7.8") || version.contains("1.7.9")) { + internals = "v1_7_R3"; + } + return internals; + } + + public static Player getOfflinePlayer(String player, UUID uuid) { + Player pplayer = null; + if (getInternals().equals("v1_8_R3")) { + pplayer = v1_8_R3.getOfflinePlayer(player, uuid); + } else if (getInternals().equals("v1_8_R2")) { + pplayer = v1_8_R2.getOfflinePlayer(player, uuid); + } else if (getInternals().equals("v1_8_R1")) { + pplayer = v1_8_R1.getOfflinePlayer(player, uuid); + } else if (getInternals().equals("v1_8_R2")) { + pplayer = v1_8_R1.getOfflinePlayer(player, uuid); + } else if (getInternals().equals("v1_7_R4")) { + pplayer = v1_7_R4.getOfflinePlayer(player, uuid); + } else if (getInternals().equals("v1_7_R3")) { + pplayer = v1_7_R3.getOfflinePlayer(player, uuid); + } + return pplayer; + } + + public static Player getOfflinePlayer(String player, UUID uuid, Location location) { + Player pplayer = null; + if (getInternals().equals("v1_8_R3")) { + pplayer = v1_8_R3.getOfflinePlayer(player, uuid, location); + } else if (getInternals().equals("v1_8_R2")) { + pplayer = v1_8_R2.getOfflinePlayer(player, uuid, location); + } else if (getInternals().equals("v1_8_R1")) { + pplayer = v1_8_R1.getOfflinePlayer(player, uuid, location); + } else if (getInternals().equals("v1_8_R2")) { + pplayer = v1_8_R1.getOfflinePlayer(player, uuid, location); + } else if (getInternals().equals("v1_7_R4")) { + pplayer = v1_7_R4.getOfflinePlayer(player, uuid, location); + } else if (getInternals().equals("v1_7_R3")) { + pplayer = v1_7_R3.getOfflinePlayer(player, uuid, location); + } + return pplayer; + } + +} diff --git a/src/com/dre/dungeonsxl/multiversionhandler/v1_7_R3.java b/src/com/dre/dungeonsxl/multiversionhandler/v1_7_R3.java new file mode 100644 index 00000000..1cb78995 --- /dev/null +++ b/src/com/dre/dungeonsxl/multiversionhandler/v1_7_R3.java @@ -0,0 +1,75 @@ +package com.dre.dungeonsxl.multiversionhandler; + +import java.io.File; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_7_R3.CraftServer; +import org.bukkit.craftbukkit.v1_7_R3.CraftWorld; +import org.bukkit.entity.Player; + +import net.minecraft.server.v1_7_R3.EntityPlayer; +import net.minecraft.server.v1_7_R3.MinecraftServer; +import net.minecraft.server.v1_7_R3.PlayerInteractManager; +import net.minecraft.util.com.mojang.authlib.GameProfile; + +public class v1_7_R3 { + + public static Player getOfflinePlayer(String player, UUID uuid) { + Player pplayer = null; + try { + File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + + for (File playerfile : playerfolder.listFiles()) { + String filename = playerfile.getName(); + String playername = filename.substring(0, filename.length() - 4); + + GameProfile profile = new GameProfile(uuid, playername); + + if (playername.trim().equalsIgnoreCase(player)) { + MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); + Player target = (entity == null) ? null : (Player) entity.getBukkitEntity(); + if (target != null) { + target.loadData(); + return target; + } + } + } + } catch (Exception e) { + return null; + } + return pplayer; + } + + public static Player getOfflinePlayer(String player, UUID uuid, Location location) { + Player pplayer = null; + try { + File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + + for (File playerfile : playerfolder.listFiles()) { + String filename = playerfile.getName(); + String playername = filename.substring(0, filename.length() - 4); + + GameProfile profile = new GameProfile(uuid, playername); + + if (playername.trim().equalsIgnoreCase(player)) { + MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); + entity.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + entity.world = ((CraftWorld) location.getWorld()).getHandle(); + Player target = (entity == null) ? null : (Player) entity.getBukkitEntity(); + if (target != null) { + // target.loadData(); + return target; + } + } + } + } catch (Exception e) { + return null; + } + return pplayer; + } + +} diff --git a/src/com/dre/dungeonsxl/multiversionhandler/v1_7_R4.java b/src/com/dre/dungeonsxl/multiversionhandler/v1_7_R4.java new file mode 100644 index 00000000..f7808c62 --- /dev/null +++ b/src/com/dre/dungeonsxl/multiversionhandler/v1_7_R4.java @@ -0,0 +1,75 @@ +package com.dre.dungeonsxl.multiversionhandler; + +import java.io.File; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_7_R4.CraftServer; +import org.bukkit.craftbukkit.v1_7_R4.CraftWorld; +import org.bukkit.entity.Player; + +import net.minecraft.server.v1_7_R4.EntityPlayer; +import net.minecraft.server.v1_7_R4.MinecraftServer; +import net.minecraft.server.v1_7_R4.PlayerInteractManager; +import net.minecraft.util.com.mojang.authlib.GameProfile; + +public class v1_7_R4 { + + public static Player getOfflinePlayer(String player, UUID uuid) { + Player pplayer = null; + try { + File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + + for (File playerfile : playerfolder.listFiles()) { + String filename = playerfile.getName(); + String playername = filename.substring(0, filename.length() - 4); + + GameProfile profile = new GameProfile(uuid, playername); + + if (playername.trim().equalsIgnoreCase(player)) { + MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); + Player target = (entity == null) ? null : (Player) entity.getBukkitEntity(); + if (target != null) { + target.loadData(); + return target; + } + } + } + } catch (Exception e) { + return null; + } + return pplayer; + } + + public static Player getOfflinePlayer(String player, UUID uuid, Location location) { + Player pplayer = null; + try { + File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + + for (File playerfile : playerfolder.listFiles()) { + String filename = playerfile.getName(); + String playername = filename.substring(0, filename.length() - 4); + + GameProfile profile = new GameProfile(uuid, playername); + + if (playername.trim().equalsIgnoreCase(player)) { + MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); + entity.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + entity.world = ((CraftWorld) location.getWorld()).getHandle(); + Player target = (entity == null) ? null : (Player) entity.getBukkitEntity(); + if (target != null) { + // target.loadData(); + return target; + } + } + } + } catch (Exception e) { + return null; + } + return pplayer; + } + +} diff --git a/src/com/dre/dungeonsxl/multiversionhandler/v1_8_R1.java b/src/com/dre/dungeonsxl/multiversionhandler/v1_8_R1.java new file mode 100644 index 00000000..aaacae46 --- /dev/null +++ b/src/com/dre/dungeonsxl/multiversionhandler/v1_8_R1.java @@ -0,0 +1,76 @@ +package com.dre.dungeonsxl.multiversionhandler; + +import java.io.File; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_8_R1.CraftServer; +import org.bukkit.craftbukkit.v1_8_R1.CraftWorld; +import org.bukkit.entity.Player; + +import com.mojang.authlib.GameProfile; + +import net.minecraft.server.v1_8_R1.EntityPlayer; +import net.minecraft.server.v1_8_R1.MinecraftServer; +import net.minecraft.server.v1_8_R1.PlayerInteractManager; + +public class v1_8_R1 { + + public static Player getOfflinePlayer(String player, UUID uuid) { + Player pplayer = null; + try { + File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + + for (File playerfile : playerfolder.listFiles()) { + String filename = playerfile.getName(); + String playername = filename.substring(0, filename.length() - 4); + + GameProfile profile = new GameProfile(uuid, playername); + + if (playername.trim().equalsIgnoreCase(player)) { + MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); + Player target = (entity == null) ? null : (Player) entity.getBukkitEntity(); + if (target != null) { + target.loadData(); + return target; + } + } + } + } catch (Exception e) { + return null; + } + return pplayer; + } + + public static Player getOfflinePlayer(String player, UUID uuid, Location location) { + Player pplayer = null; + try { + File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + + for (File playerfile : playerfolder.listFiles()) { + String filename = playerfile.getName(); + String playername = filename.substring(0, filename.length() - 4); + + GameProfile profile = new GameProfile(uuid, playername); + + if (playername.trim().equalsIgnoreCase(player)) { + MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); + entity.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + entity.world = ((CraftWorld) location.getWorld()).getHandle(); + Player target = (entity == null) ? null : (Player) entity.getBukkitEntity(); + if (target != null) { + // target.loadData(); + return target; + } + } + } + } catch (Exception e) { + return null; + } + return pplayer; + } + +} diff --git a/src/com/dre/dungeonsxl/multiversionhandler/v1_8_R2.java b/src/com/dre/dungeonsxl/multiversionhandler/v1_8_R2.java new file mode 100644 index 00000000..021cc1a4 --- /dev/null +++ b/src/com/dre/dungeonsxl/multiversionhandler/v1_8_R2.java @@ -0,0 +1,76 @@ +package com.dre.dungeonsxl.multiversionhandler; + +import java.io.File; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_8_R2.CraftServer; +import org.bukkit.craftbukkit.v1_8_R2.CraftWorld; +import org.bukkit.entity.Player; + +import com.mojang.authlib.GameProfile; + +import net.minecraft.server.v1_8_R2.EntityPlayer; +import net.minecraft.server.v1_8_R2.MinecraftServer; +import net.minecraft.server.v1_8_R2.PlayerInteractManager; + +public class v1_8_R2 { + + public static Player getOfflinePlayer(String player, UUID uuid) { + Player pplayer = null; + try { + File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + + for (File playerfile : playerfolder.listFiles()) { + String filename = playerfile.getName(); + String playername = filename.substring(0, filename.length() - 4); + + GameProfile profile = new GameProfile(uuid, playername); + + if (playername.trim().equalsIgnoreCase(player)) { + MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); + Player target = (entity == null) ? null : (Player) entity.getBukkitEntity(); + if (target != null) { + target.loadData(); + return target; + } + } + } + } catch (Exception e) { + return null; + } + return pplayer; + } + + public static Player getOfflinePlayer(String player, UUID uuid, Location location) { + Player pplayer = null; + try { + File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + + for (File playerfile : playerfolder.listFiles()) { + String filename = playerfile.getName(); + String playername = filename.substring(0, filename.length() - 4); + + GameProfile profile = new GameProfile(uuid, playername); + + if (playername.trim().equalsIgnoreCase(player)) { + MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); + entity.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + entity.world = ((CraftWorld) location.getWorld()).getHandle(); + Player target = (entity == null) ? null : (Player) entity.getBukkitEntity(); + if (target != null) { + // target.loadData(); + return target; + } + } + } + } catch (Exception e) { + return null; + } + return pplayer; + } + +} diff --git a/src/com/dre/dungeonsxl/multiversionhandler/v1_8_R3.java b/src/com/dre/dungeonsxl/multiversionhandler/v1_8_R3.java new file mode 100644 index 00000000..472382a7 --- /dev/null +++ b/src/com/dre/dungeonsxl/multiversionhandler/v1_8_R3.java @@ -0,0 +1,76 @@ +package com.dre.dungeonsxl.multiversionhandler; + +import java.io.File; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; +import org.bukkit.entity.Player; + +import com.mojang.authlib.GameProfile; + +import net.minecraft.server.v1_8_R3.EntityPlayer; +import net.minecraft.server.v1_8_R3.MinecraftServer; +import net.minecraft.server.v1_8_R3.PlayerInteractManager; + +public class v1_8_R3 { + + public static Player getOfflinePlayer(String player, UUID uuid) { + Player pplayer = null; + try { + File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + + for (File playerfile : playerfolder.listFiles()) { + String filename = playerfile.getName(); + String playername = filename.substring(0, filename.length() - 4); + + GameProfile profile = new GameProfile(uuid, playername); + + if (playername.trim().equalsIgnoreCase(player)) { + MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); + Player target = (entity == null) ? null : (Player) entity.getBukkitEntity(); + if (target != null) { + target.loadData(); + return target; + } + } + } + } catch (Exception e) { + return null; + } + return pplayer; + } + + public static Player getOfflinePlayer(String player, UUID uuid, Location location) { + Player pplayer = null; + try { + File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + + for (File playerfile : playerfolder.listFiles()) { + String filename = playerfile.getName(); + String playername = filename.substring(0, filename.length() - 4); + + GameProfile profile = new GameProfile(uuid, playername); + + if (playername.trim().equalsIgnoreCase(player)) { + MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); + entity.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + entity.world = ((CraftWorld) location.getWorld()).getHandle(); + Player target = (entity == null) ? null : (Player) entity.getBukkitEntity(); + if (target != null) { + // target.loadData(); + return target; + } + } + } + } catch (Exception e) { + return null; + } + return pplayer; + } + +} diff --git a/src/plugin.yml b/src/plugin.yml index 2a138712..e20bb901 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: DungeonsXL main: com.dre.dungeonsxl.P -version: 0.9.2-SNAPSHOT +version: 0.9.3 author: Frank Baumann authors: [Frank Baumann, Milan Albrecht, Tobias Schmitz, Daniel Saukel] website: http://www.dre2n.ml