diff --git a/1_4_5/src/main/java/com/lishid/openinv/internal/v1_4_5/PlayerDataManager.java b/1_4_5/src/main/java/com/lishid/openinv/internal/v1_4_5/PlayerDataManager.java index 08500e7..e3a8ea5 100644 --- a/1_4_5/src/main/java/com/lishid/openinv/internal/v1_4_5/PlayerDataManager.java +++ b/1_4_5/src/main/java/com/lishid/openinv/internal/v1_4_5/PlayerDataManager.java @@ -59,4 +59,14 @@ public class PlayerDataManager implements IPlayerDataManager { return player.getName(); } + @Override + public OfflinePlayer getPlayerByID(String identifier) { + OfflinePlayer player = Bukkit.getOfflinePlayer(identifier); + // Ensure player is a real player, otherwise return null + if (player == null || !player.hasPlayedBefore() && !player.isOnline()) { + return null; + } + return player; + } + } diff --git a/1_4_6/src/main/java/com/lishid/openinv/internal/v1_4_6/PlayerDataManager.java b/1_4_6/src/main/java/com/lishid/openinv/internal/v1_4_6/PlayerDataManager.java index b768876..0c09f7b 100644 --- a/1_4_6/src/main/java/com/lishid/openinv/internal/v1_4_6/PlayerDataManager.java +++ b/1_4_6/src/main/java/com/lishid/openinv/internal/v1_4_6/PlayerDataManager.java @@ -59,4 +59,14 @@ public class PlayerDataManager implements IPlayerDataManager { return player.getName(); } + @Override + public OfflinePlayer getPlayerByID(String identifier) { + OfflinePlayer player = Bukkit.getOfflinePlayer(identifier); + // Ensure player is a real player, otherwise return null + if (player == null || !player.hasPlayedBefore() && !player.isOnline()) { + return null; + } + return player; + } + } diff --git a/internal/src/main/java/com/lishid/openinv/internal/IPlayerDataManager.java b/internal/src/main/java/com/lishid/openinv/internal/IPlayerDataManager.java index bbcd68d..cddf6a5 100644 --- a/internal/src/main/java/com/lishid/openinv/internal/IPlayerDataManager.java +++ b/internal/src/main/java/com/lishid/openinv/internal/IPlayerDataManager.java @@ -39,4 +39,12 @@ public interface IPlayerDataManager { */ public String getPlayerDataID(OfflinePlayer player); + /** + * Gets an OfflinePlayer by the given unique identifier. + * + * @param identifier the unique identifier + * @return the OfflinePlayer, or null if no exact match was found + */ + public OfflinePlayer getPlayerByID(String identifier); + } diff --git a/plugin/src/main/java/com/lishid/openinv/OpenInv.java b/plugin/src/main/java/com/lishid/openinv/OpenInv.java index 48b7637..2cb85c9 100644 --- a/plugin/src/main/java/com/lishid/openinv/OpenInv.java +++ b/plugin/src/main/java/com/lishid/openinv/OpenInv.java @@ -169,7 +169,7 @@ public class OpenInv extends JavaPlugin { * @return true if the server version is supported */ public boolean isSupportedVersion() { - return accessor.isSupported(); + return this.accessor.isSupported(); } /** @@ -311,6 +311,17 @@ public class OpenInv extends JavaPlugin { saveConfig(); } + /** + * Gets a unique identifier by which the OfflinePlayer can be referenced. Using the value + * returned to look up a Player will generally be much faster for later implementations. + * + * @param offline the OfflinePlayer + * @return the identifier + */ + public String getPlayerID(OfflinePlayer offline) { + return this.playerLoader.getPlayerDataID(offline); + } + /** * Get an OfflinePlayer by name. *
@@ -333,12 +344,15 @@ public class OpenInv extends JavaPlugin { } } + // Attempt exact offline match first - adds UUID support for later versions + OfflinePlayer player = this.playerLoader.getPlayerByID(name); + // Ensure name is valid if server is in online mode to avoid unnecessary searching if (getServer().getOnlineMode() && !name.matches("[a-zA-Z0-9_]{3,16}")) { return null; } - OfflinePlayer player = getServer().getPlayerExact(name); + player = getServer().getPlayerExact(name); if (player != null) { return player; diff --git a/v1_10_R1/src/main/java/com/lishid/openinv/internal/v1_10_R1/PlayerDataManager.java b/v1_10_R1/src/main/java/com/lishid/openinv/internal/v1_10_R1/PlayerDataManager.java index cecd3c7..3909151 100644 --- a/v1_10_R1/src/main/java/com/lishid/openinv/internal/v1_10_R1/PlayerDataManager.java +++ b/v1_10_R1/src/main/java/com/lishid/openinv/internal/v1_10_R1/PlayerDataManager.java @@ -16,6 +16,8 @@ package com.lishid.openinv.internal.v1_10_R1; +import java.util.UUID; + import com.lishid.openinv.internal.IPlayerDataManager; import com.mojang.authlib.GameProfile; @@ -61,4 +63,20 @@ public class PlayerDataManager implements IPlayerDataManager { return player.getUniqueId().toString(); } + @Override + public OfflinePlayer getPlayerByID(String identifier) { + try { + UUID uuid = UUID.fromString(identifier); + OfflinePlayer player = Bukkit.getOfflinePlayer(uuid); + // Ensure player is a real player, otherwise return null + if (player == null || !player.hasPlayedBefore() && !player.isOnline()) { + return null; + } + return player; + } catch (IllegalArgumentException e) { + // Not a UUID + return null; + } + } + } diff --git a/v1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/PlayerDataManager.java b/v1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/PlayerDataManager.java index 760fe58..30bb00e 100644 --- a/v1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/PlayerDataManager.java +++ b/v1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/PlayerDataManager.java @@ -16,6 +16,8 @@ package com.lishid.openinv.internal.v1_11_R1; +import java.util.UUID; + import com.lishid.openinv.internal.IPlayerDataManager; import com.mojang.authlib.GameProfile; @@ -61,4 +63,20 @@ public class PlayerDataManager implements IPlayerDataManager { return player.getUniqueId().toString(); } + @Override + public OfflinePlayer getPlayerByID(String identifier) { + try { + UUID uuid = UUID.fromString(identifier); + OfflinePlayer player = Bukkit.getOfflinePlayer(uuid); + // Ensure player is a real player, otherwise return null + if (player == null || !player.hasPlayedBefore() && !player.isOnline()) { + return null; + } + return player; + } catch (IllegalArgumentException e) { + // Not a UUID + return null; + } + } + } diff --git a/v1_4_R1/src/main/java/com/lishid/openinv/internal/v1_4_R1/PlayerDataManager.java b/v1_4_R1/src/main/java/com/lishid/openinv/internal/v1_4_R1/PlayerDataManager.java index e92f7a2..f88713c 100644 --- a/v1_4_R1/src/main/java/com/lishid/openinv/internal/v1_4_R1/PlayerDataManager.java +++ b/v1_4_R1/src/main/java/com/lishid/openinv/internal/v1_4_R1/PlayerDataManager.java @@ -60,4 +60,14 @@ public class PlayerDataManager implements IPlayerDataManager { return player.getName(); } + @Override + public OfflinePlayer getPlayerByID(String identifier) { + OfflinePlayer player = Bukkit.getOfflinePlayer(identifier); + // Ensure player is a real player, otherwise return null + if (player == null || !player.hasPlayedBefore() && !player.isOnline()) { + return null; + } + return player; + } + } diff --git a/v1_5_R2/src/main/java/com/lishid/openinv/internal/v1_5_R2/PlayerDataManager.java b/v1_5_R2/src/main/java/com/lishid/openinv/internal/v1_5_R2/PlayerDataManager.java index a6e8e7d..1bea276 100644 --- a/v1_5_R2/src/main/java/com/lishid/openinv/internal/v1_5_R2/PlayerDataManager.java +++ b/v1_5_R2/src/main/java/com/lishid/openinv/internal/v1_5_R2/PlayerDataManager.java @@ -59,4 +59,14 @@ public class PlayerDataManager implements IPlayerDataManager { return player.getName(); } + @Override + public OfflinePlayer getPlayerByID(String identifier) { + OfflinePlayer player = Bukkit.getOfflinePlayer(identifier); + // Ensure player is a real player, otherwise return null + if (player == null || !player.hasPlayedBefore() && !player.isOnline()) { + return null; + } + return player; + } + } diff --git a/v1_5_R3/src/main/java/com/lishid/openinv/internal/v1_5_R3/PlayerDataManager.java b/v1_5_R3/src/main/java/com/lishid/openinv/internal/v1_5_R3/PlayerDataManager.java index f77b8fd..fbe6646 100644 --- a/v1_5_R3/src/main/java/com/lishid/openinv/internal/v1_5_R3/PlayerDataManager.java +++ b/v1_5_R3/src/main/java/com/lishid/openinv/internal/v1_5_R3/PlayerDataManager.java @@ -59,4 +59,14 @@ public class PlayerDataManager implements IPlayerDataManager { return player.getName(); } + @Override + public OfflinePlayer getPlayerByID(String identifier) { + OfflinePlayer player = Bukkit.getOfflinePlayer(identifier); + // Ensure player is a real player, otherwise return null + if (player == null || !player.hasPlayedBefore() && !player.isOnline()) { + return null; + } + return player; + } + } diff --git a/v1_6_R1/src/main/java/com/lishid/openinv/internal/v1_6_R1/PlayerDataManager.java b/v1_6_R1/src/main/java/com/lishid/openinv/internal/v1_6_R1/PlayerDataManager.java index a7359c2..3429d10 100644 --- a/v1_6_R1/src/main/java/com/lishid/openinv/internal/v1_6_R1/PlayerDataManager.java +++ b/v1_6_R1/src/main/java/com/lishid/openinv/internal/v1_6_R1/PlayerDataManager.java @@ -59,4 +59,14 @@ public class PlayerDataManager implements IPlayerDataManager { return player.getName(); } + @Override + public OfflinePlayer getPlayerByID(String identifier) { + OfflinePlayer player = Bukkit.getOfflinePlayer(identifier); + // Ensure player is a real player, otherwise return null + if (player == null || !player.hasPlayedBefore() && !player.isOnline()) { + return null; + } + return player; + } + } diff --git a/v1_6_R2/src/main/java/com/lishid/openinv/internal/v1_6_R2/PlayerDataManager.java b/v1_6_R2/src/main/java/com/lishid/openinv/internal/v1_6_R2/PlayerDataManager.java index 8401f1f..03f50fa 100644 --- a/v1_6_R2/src/main/java/com/lishid/openinv/internal/v1_6_R2/PlayerDataManager.java +++ b/v1_6_R2/src/main/java/com/lishid/openinv/internal/v1_6_R2/PlayerDataManager.java @@ -59,4 +59,14 @@ public class PlayerDataManager implements IPlayerDataManager { return player.getName(); } + @Override + public OfflinePlayer getPlayerByID(String identifier) { + OfflinePlayer player = Bukkit.getOfflinePlayer(identifier); + // Ensure player is a real player, otherwise return null + if (player == null || !player.hasPlayedBefore() && !player.isOnline()) { + return null; + } + return player; + } + } diff --git a/v1_6_R3/src/main/java/com/lishid/openinv/internal/v1_6_R3/PlayerDataManager.java b/v1_6_R3/src/main/java/com/lishid/openinv/internal/v1_6_R3/PlayerDataManager.java index 4e38815..b0abe80 100644 --- a/v1_6_R3/src/main/java/com/lishid/openinv/internal/v1_6_R3/PlayerDataManager.java +++ b/v1_6_R3/src/main/java/com/lishid/openinv/internal/v1_6_R3/PlayerDataManager.java @@ -59,4 +59,14 @@ public class PlayerDataManager implements IPlayerDataManager { return player.getName(); } + @Override + public OfflinePlayer getPlayerByID(String identifier) { + OfflinePlayer player = Bukkit.getOfflinePlayer(identifier); + // Ensure player is a real player, otherwise return null + if (player == null || !player.hasPlayedBefore() && !player.isOnline()) { + return null; + } + return player; + } + } diff --git a/v1_7_R1/src/main/java/com/lishid/openinv/internal/v1_7_R1/PlayerDataManager.java b/v1_7_R1/src/main/java/com/lishid/openinv/internal/v1_7_R1/PlayerDataManager.java index 499bc18..aa3795a 100644 --- a/v1_7_R1/src/main/java/com/lishid/openinv/internal/v1_7_R1/PlayerDataManager.java +++ b/v1_7_R1/src/main/java/com/lishid/openinv/internal/v1_7_R1/PlayerDataManager.java @@ -60,4 +60,14 @@ public class PlayerDataManager implements IPlayerDataManager { return player.getName(); } + @Override + public OfflinePlayer getPlayerByID(String identifier) { + OfflinePlayer player = Bukkit.getOfflinePlayer(identifier); + // Ensure player is a real player, otherwise return null + if (player == null || !player.hasPlayedBefore() && !player.isOnline()) { + return null; + } + return player; + } + } diff --git a/v1_7_R2/src/main/java/com/lishid/openinv/internal/v1_7_R2/PlayerDataManager.java b/v1_7_R2/src/main/java/com/lishid/openinv/internal/v1_7_R2/PlayerDataManager.java index eda1ce4..d30a20c 100644 --- a/v1_7_R2/src/main/java/com/lishid/openinv/internal/v1_7_R2/PlayerDataManager.java +++ b/v1_7_R2/src/main/java/com/lishid/openinv/internal/v1_7_R2/PlayerDataManager.java @@ -61,4 +61,14 @@ public class PlayerDataManager implements IPlayerDataManager { return player.getName(); } + @Override + public OfflinePlayer getPlayerByID(String identifier) { + OfflinePlayer player = Bukkit.getOfflinePlayer(identifier); + // Ensure player is a real player, otherwise return null + if (player == null || !player.hasPlayedBefore() && !player.isOnline()) { + return null; + } + return player; + } + } diff --git a/v1_7_R3/src/main/java/com/lishid/openinv/internal/v1_7_R3/PlayerDataManager.java b/v1_7_R3/src/main/java/com/lishid/openinv/internal/v1_7_R3/PlayerDataManager.java index 7f17bc0..8569033 100644 --- a/v1_7_R3/src/main/java/com/lishid/openinv/internal/v1_7_R3/PlayerDataManager.java +++ b/v1_7_R3/src/main/java/com/lishid/openinv/internal/v1_7_R3/PlayerDataManager.java @@ -16,6 +16,8 @@ package com.lishid.openinv.internal.v1_7_R3; +import java.util.UUID; + import com.lishid.openinv.internal.IPlayerDataManager; import org.bukkit.Bukkit; @@ -60,4 +62,20 @@ public class PlayerDataManager implements IPlayerDataManager { return player.getUniqueId().toString(); } + @Override + public OfflinePlayer getPlayerByID(String identifier) { + try { + UUID uuid = UUID.fromString(identifier); + OfflinePlayer player = Bukkit.getOfflinePlayer(uuid); + // Ensure player is a real player, otherwise return null + if (player == null || !player.hasPlayedBefore() && !player.isOnline()) { + return null; + } + return player; + } catch (IllegalArgumentException e) { + // Not a UUID + return null; + } + } + } diff --git a/v1_7_R4/src/main/java/com/lishid/openinv/internal/v1_7_R4/PlayerDataManager.java b/v1_7_R4/src/main/java/com/lishid/openinv/internal/v1_7_R4/PlayerDataManager.java index b26947d..5209859 100644 --- a/v1_7_R4/src/main/java/com/lishid/openinv/internal/v1_7_R4/PlayerDataManager.java +++ b/v1_7_R4/src/main/java/com/lishid/openinv/internal/v1_7_R4/PlayerDataManager.java @@ -16,6 +16,8 @@ package com.lishid.openinv.internal.v1_7_R4; +import java.util.UUID; + import com.lishid.openinv.internal.IPlayerDataManager; import org.bukkit.Bukkit; @@ -60,4 +62,20 @@ public class PlayerDataManager implements IPlayerDataManager { return player.getUniqueId().toString(); } + @Override + public OfflinePlayer getPlayerByID(String identifier) { + try { + UUID uuid = UUID.fromString(identifier); + OfflinePlayer player = Bukkit.getOfflinePlayer(uuid); + // Ensure player is a real player, otherwise return null + if (player == null || !player.hasPlayedBefore() && !player.isOnline()) { + return null; + } + return player; + } catch (IllegalArgumentException e) { + // Not a UUID + return null; + } + } + } diff --git a/v1_8_R1/src/main/java/com/lishid/openinv/internal/v1_8_R1/PlayerDataManager.java b/v1_8_R1/src/main/java/com/lishid/openinv/internal/v1_8_R1/PlayerDataManager.java index 1b45d27..bbd9e26 100644 --- a/v1_8_R1/src/main/java/com/lishid/openinv/internal/v1_8_R1/PlayerDataManager.java +++ b/v1_8_R1/src/main/java/com/lishid/openinv/internal/v1_8_R1/PlayerDataManager.java @@ -16,6 +16,8 @@ package com.lishid.openinv.internal.v1_8_R1; +import java.util.UUID; + import com.lishid.openinv.internal.IPlayerDataManager; import com.mojang.authlib.GameProfile; @@ -61,4 +63,20 @@ public class PlayerDataManager implements IPlayerDataManager { return player.getUniqueId().toString(); } + @Override + public OfflinePlayer getPlayerByID(String identifier) { + try { + UUID uuid = UUID.fromString(identifier); + OfflinePlayer player = Bukkit.getOfflinePlayer(uuid); + // Ensure player is a real player, otherwise return null + if (player == null || !player.hasPlayedBefore() && !player.isOnline()) { + return null; + } + return player; + } catch (IllegalArgumentException e) { + // Not a UUID + return null; + } + } + } diff --git a/v1_8_R2/src/main/java/com/lishid/openinv/internal/v1_8_R2/PlayerDataManager.java b/v1_8_R2/src/main/java/com/lishid/openinv/internal/v1_8_R2/PlayerDataManager.java index d79bb09..6e9d1de 100644 --- a/v1_8_R2/src/main/java/com/lishid/openinv/internal/v1_8_R2/PlayerDataManager.java +++ b/v1_8_R2/src/main/java/com/lishid/openinv/internal/v1_8_R2/PlayerDataManager.java @@ -16,6 +16,8 @@ package com.lishid.openinv.internal.v1_8_R2; +import java.util.UUID; + import com.lishid.openinv.internal.IPlayerDataManager; import com.mojang.authlib.GameProfile; @@ -61,4 +63,20 @@ public class PlayerDataManager implements IPlayerDataManager { return player.getUniqueId().toString(); } + @Override + public OfflinePlayer getPlayerByID(String identifier) { + try { + UUID uuid = UUID.fromString(identifier); + OfflinePlayer player = Bukkit.getOfflinePlayer(uuid); + // Ensure player is a real player, otherwise return null + if (player == null || !player.hasPlayedBefore() && !player.isOnline()) { + return null; + } + return player; + } catch (IllegalArgumentException e) { + // Not a UUID + return null; + } + } + } diff --git a/v1_8_R3/src/main/java/com/lishid/openinv/internal/v1_8_R3/PlayerDataManager.java b/v1_8_R3/src/main/java/com/lishid/openinv/internal/v1_8_R3/PlayerDataManager.java index 818e703..e7e6a4e 100644 --- a/v1_8_R3/src/main/java/com/lishid/openinv/internal/v1_8_R3/PlayerDataManager.java +++ b/v1_8_R3/src/main/java/com/lishid/openinv/internal/v1_8_R3/PlayerDataManager.java @@ -16,6 +16,8 @@ package com.lishid.openinv.internal.v1_8_R3; +import java.util.UUID; + import com.lishid.openinv.internal.IPlayerDataManager; import com.mojang.authlib.GameProfile; @@ -61,4 +63,20 @@ public class PlayerDataManager implements IPlayerDataManager { return player.getUniqueId().toString(); } + @Override + public OfflinePlayer getPlayerByID(String identifier) { + try { + UUID uuid = UUID.fromString(identifier); + OfflinePlayer player = Bukkit.getOfflinePlayer(uuid); + // Ensure player is a real player, otherwise return null + if (player == null || !player.hasPlayedBefore() && !player.isOnline()) { + return null; + } + return player; + } catch (IllegalArgumentException e) { + // Not a UUID + return null; + } + } + } diff --git a/v1_9_R1/src/main/java/com/lishid/openinv/internal/v1_9_R1/PlayerDataManager.java b/v1_9_R1/src/main/java/com/lishid/openinv/internal/v1_9_R1/PlayerDataManager.java index 0166f62..7e2cd46 100644 --- a/v1_9_R1/src/main/java/com/lishid/openinv/internal/v1_9_R1/PlayerDataManager.java +++ b/v1_9_R1/src/main/java/com/lishid/openinv/internal/v1_9_R1/PlayerDataManager.java @@ -16,6 +16,8 @@ package com.lishid.openinv.internal.v1_9_R1; +import java.util.UUID; + import com.lishid.openinv.internal.IPlayerDataManager; import com.mojang.authlib.GameProfile; @@ -61,4 +63,20 @@ public class PlayerDataManager implements IPlayerDataManager { return player.getUniqueId().toString(); } + @Override + public OfflinePlayer getPlayerByID(String identifier) { + try { + UUID uuid = UUID.fromString(identifier); + OfflinePlayer player = Bukkit.getOfflinePlayer(uuid); + // Ensure player is a real player, otherwise return null + if (player == null || !player.hasPlayedBefore() && !player.isOnline()) { + return null; + } + return player; + } catch (IllegalArgumentException e) { + // Not a UUID + return null; + } + } + } diff --git a/v1_9_R2/src/main/java/com/lishid/openinv/internal/v1_9_R2/PlayerDataManager.java b/v1_9_R2/src/main/java/com/lishid/openinv/internal/v1_9_R2/PlayerDataManager.java index 3678093..fa8d3d8 100644 --- a/v1_9_R2/src/main/java/com/lishid/openinv/internal/v1_9_R2/PlayerDataManager.java +++ b/v1_9_R2/src/main/java/com/lishid/openinv/internal/v1_9_R2/PlayerDataManager.java @@ -16,6 +16,8 @@ package com.lishid.openinv.internal.v1_9_R2; +import java.util.UUID; + import com.lishid.openinv.internal.IPlayerDataManager; import com.mojang.authlib.GameProfile; @@ -61,4 +63,20 @@ public class PlayerDataManager implements IPlayerDataManager { return player.getUniqueId().toString(); } + @Override + public OfflinePlayer getPlayerByID(String identifier) { + try { + UUID uuid = UUID.fromString(identifier); + OfflinePlayer player = Bukkit.getOfflinePlayer(uuid); + // Ensure player is a real player, otherwise return null + if (player == null || !player.hasPlayedBefore() && !player.isOnline()) { + return null; + } + return player; + } catch (IllegalArgumentException e) { + // Not a UUID + return null; + } + } + }