Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
0bbcf6cdb2 | ||
|
f11d60f78c | ||
|
8a6b98614f |
@@ -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);
|
||||
|
||||
}
|
||||
|
137
plugin/src/main/java/com/lishid/openinv/ConfigUpdater.java
Normal file
137
plugin/src/main/java/com/lishid/openinv/ConfigUpdater.java
Normal file
@@ -0,0 +1,137 @@
|
||||
package com.lishid.openinv;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
public class ConfigUpdater {
|
||||
|
||||
private static final int CONFIG_VERSION = 3;
|
||||
|
||||
private final OpenInv plugin;
|
||||
|
||||
public ConfigUpdater(OpenInv plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
private int getConfigVersion() {
|
||||
return plugin.getConfig().getInt("config-version", 1);
|
||||
}
|
||||
|
||||
private boolean isConfigOutdated() {
|
||||
return getConfigVersion() < CONFIG_VERSION;
|
||||
}
|
||||
|
||||
public void checkForUpdates() {
|
||||
if (isConfigOutdated()) {
|
||||
plugin.getLogger().info("Configuration update found! Performing update...");
|
||||
performUpdate();
|
||||
plugin.getLogger().info("Configuration update complete!");
|
||||
}
|
||||
}
|
||||
|
||||
private void performUpdate() {
|
||||
// Update according to the right version
|
||||
switch (getConfigVersion()) {
|
||||
case 1:
|
||||
updateConfig1To2();
|
||||
case 2:
|
||||
updateConfig2To3();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateConfig2To3() {
|
||||
plugin.getConfig().set("config-version", 3);
|
||||
plugin.getConfig().set("items.open-inv", null);
|
||||
plugin.getConfig().set("toggles.items.open-inv", null);
|
||||
plugin.getConfig().set("settings.disable-saving", plugin.getConfig().getBoolean("DisableSaving", false));
|
||||
plugin.getConfig().set("DisableSaving", null);
|
||||
// Save the new config
|
||||
plugin.saveConfig();
|
||||
}
|
||||
|
||||
private void updateConfig1To2() {
|
||||
// Backup the old config file
|
||||
try {
|
||||
plugin.getConfig().save(new File(plugin.getDataFolder(), "config_old.yml"));
|
||||
plugin.getLogger().info("Backed up config.yml to config_old.yml before updating.");
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().warning("Could not back up config.yml before updating!");
|
||||
}
|
||||
|
||||
// Get the old config settings
|
||||
int itemOpenInvItemId = plugin.getConfig().getInt("ItemOpenInvItemID", 280);
|
||||
plugin.getConfig().set("ItemOpenInvItemID", null);
|
||||
boolean notifySilentChest = plugin.getConfig().getBoolean("NotifySilentChest", true);
|
||||
plugin.getConfig().set("NotifySilentChest", null);
|
||||
boolean notifyAnyChest = plugin.getConfig().getBoolean("NotifyAnyChest", true);
|
||||
plugin.getConfig().set("NotifyAnyChest", null);
|
||||
|
||||
updateToggles("AnyChest", ".toggle", "toggles.any-chest");
|
||||
updateToggles("ItemOpenInv", ".toggle", "toggles.items.open-inv");
|
||||
updateToggles("SilentChest", ".toggle", "toggles.silent-chest");
|
||||
|
||||
plugin.getConfig().set("config-version", 2);
|
||||
plugin.getConfig().set("items.open-inv", getMaterialById(itemOpenInvItemId).toString());
|
||||
plugin.getConfig().set("notify.any-chest", notifyAnyChest);
|
||||
plugin.getConfig().set("notify.silent-chest", notifySilentChest);
|
||||
|
||||
// Save the new config
|
||||
plugin.saveConfig();
|
||||
}
|
||||
|
||||
private void updateToggles(String sectionName, String suffix, String newSectionName) {
|
||||
// Ensure section exists
|
||||
if (!plugin.getConfig().isConfigurationSection(sectionName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ConfigurationSection section = plugin.getConfig().getConfigurationSection(sectionName);
|
||||
Set<String> keys = section.getKeys(false);
|
||||
|
||||
// Ensure section has content
|
||||
if (keys == null || keys.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, Boolean> toggles = new HashMap<String, Boolean>();
|
||||
|
||||
for (String playerName : keys) {
|
||||
OfflinePlayer player = plugin.matchPlayer(playerName);
|
||||
String dataID = plugin.getPlayerID(player);
|
||||
toggles.put(dataID, section.getBoolean(playerName + suffix, false));
|
||||
}
|
||||
|
||||
// Wipe old ConfigurationSection
|
||||
plugin.getConfig().set(sectionName, null);
|
||||
// Prepare new ConfigurationSection
|
||||
if (plugin.getConfig().isConfigurationSection(newSectionName)) {
|
||||
section = plugin.getConfig().getConfigurationSection(newSectionName);
|
||||
} else {
|
||||
section = plugin.getConfig().createSection(newSectionName);
|
||||
}
|
||||
|
||||
// Set new values
|
||||
for (Map.Entry<String, Boolean> entry : toggles.entrySet()) {
|
||||
section.set(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private Material getMaterialById(int id) {
|
||||
Material material = Material.getMaterial(id);
|
||||
|
||||
if (material == null) {
|
||||
material = Material.STICK;
|
||||
}
|
||||
|
||||
return material;
|
||||
}
|
||||
}
|
@@ -41,7 +41,6 @@ import com.lishid.openinv.util.Function;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
@@ -118,27 +117,7 @@ public class OpenInv extends JavaPlugin {
|
||||
inventoryAccess = accessor.newInventoryAccess();
|
||||
anySilentContainer = accessor.newAnySilentContainer();
|
||||
|
||||
FileConfiguration config = getConfig();
|
||||
boolean dirtyConfig = false;
|
||||
if (!config.isBoolean("NotifySilentChest")) {
|
||||
config.set("NotifySilentChest", true);
|
||||
dirtyConfig = true;
|
||||
}
|
||||
if (!config.isBoolean("NotifyAnyChest")) {
|
||||
config.set("NotifyAnyChest", true);
|
||||
dirtyConfig = true;
|
||||
}
|
||||
if (!config.isBoolean("DisableSaving")) {
|
||||
config.set("DisableSaving", false);
|
||||
dirtyConfig = true;
|
||||
}
|
||||
config.addDefault("NotifySilentChest", true);
|
||||
config.addDefault("NotifyAnyChest", true);
|
||||
config.addDefault("DisableSaving", false);
|
||||
config.options().copyDefaults(true);
|
||||
if (dirtyConfig) {
|
||||
saveConfig();
|
||||
}
|
||||
new ConfigUpdater(this).checkForUpdates();
|
||||
|
||||
pm.registerEvents(new OpenInvPlayerListener(this), this);
|
||||
pm.registerEvents(new OpenInvInventoryListener(this), this);
|
||||
@@ -169,7 +148,7 @@ public class OpenInv extends JavaPlugin {
|
||||
* @return true if the server version is supported
|
||||
*/
|
||||
public boolean isSupportedVersion() {
|
||||
return accessor.isSupported();
|
||||
return this.accessor.isSupported();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -246,7 +225,7 @@ public class OpenInv extends JavaPlugin {
|
||||
* @return false unless configured otherwise
|
||||
*/
|
||||
public boolean disableSaving() {
|
||||
return getConfig().getBoolean("DisableSaving", false);
|
||||
return getConfig().getBoolean("settings.disable-saving", false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,7 +235,7 @@ public class OpenInv extends JavaPlugin {
|
||||
* @return true unless configured otherwise
|
||||
*/
|
||||
public boolean notifySilentChest() {
|
||||
return getConfig().getBoolean("NotifySilentChest", true);
|
||||
return getConfig().getBoolean("notify.silent-chest", true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -266,7 +245,7 @@ public class OpenInv extends JavaPlugin {
|
||||
* @return true unless configured otherwise
|
||||
*/
|
||||
public boolean notifyAnyChest() {
|
||||
return getConfig().getBoolean("NotifyAnyChest", true);
|
||||
return getConfig().getBoolean("notify.any-chest", true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -276,7 +255,7 @@ public class OpenInv extends JavaPlugin {
|
||||
* @return true if SilentChest is enabled
|
||||
*/
|
||||
public boolean getPlayerSilentChestStatus(OfflinePlayer player) {
|
||||
return getConfig().getBoolean("SilentChest." + playerLoader.getPlayerDataID(player) + ".toggle", false);
|
||||
return getConfig().getBoolean("toggles.silent-chest." + playerLoader.getPlayerDataID(player), false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -286,7 +265,7 @@ public class OpenInv extends JavaPlugin {
|
||||
* @param status the status
|
||||
*/
|
||||
public void setPlayerSilentChestStatus(OfflinePlayer player, boolean status) {
|
||||
getConfig().set("SilentChest." + playerLoader.getPlayerDataID(player) + ".toggle", status);
|
||||
getConfig().set("toggles.silent-chest." + playerLoader.getPlayerDataID(player), status);
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
@@ -297,7 +276,7 @@ public class OpenInv extends JavaPlugin {
|
||||
* @return true if AnyChest is enabled
|
||||
*/
|
||||
public boolean getPlayerAnyChestStatus(OfflinePlayer player) {
|
||||
return getConfig().getBoolean("AnyChest." + playerLoader.getPlayerDataID(player) + ".toggle", true);
|
||||
return getConfig().getBoolean("toggles.any-chest." + playerLoader.getPlayerDataID(player), false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -307,10 +286,21 @@ public class OpenInv extends JavaPlugin {
|
||||
* @param status the status
|
||||
*/
|
||||
public void setPlayerAnyChestStatus(OfflinePlayer player, boolean status) {
|
||||
getConfig().set("AnyChest." + playerLoader.getPlayerDataID(player) + ".toggle", status);
|
||||
getConfig().set("toggles.silent-chest." + playerLoader.getPlayerDataID(player), status);
|
||||
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 +323,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;
|
||||
|
2
pom.xml
2
pom.xml
@@ -10,7 +10,7 @@
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<openinv.version>3.0.0-SNAPSHOT</openinv.version>
|
||||
<openinv.version>3.0.1</openinv.version>
|
||||
</properties>
|
||||
|
||||
<profiles>
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user