mirror of
https://github.com/TotalFreedomMC/OpenInv.git
synced 2024-12-23 00:15:08 +00:00
Added support for UUID-based player lookups in 1.7.5+
You could argue that ShadowRanger's conversion of everything to UUID is better, but that would result in us having to contact Mojang's servers simply to fetch a player by UUID for versions < 1.7.5. It seems excessive (not to mention that uncached contact can result in rate limiting) when the server itself will not remember who they are across name changes. If they can re-obtain everything in their inventory, they can re-run /ac.
This commit is contained in:
parent
d7eec528e4
commit
8a6b98614f
21 changed files with 286 additions and 2 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
* <p>
|
||||
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue