diff --git a/src/main/java/com/lishid/openinv/commands/OpenEnderPluginCommand.java b/src/main/java/com/lishid/openinv/commands/OpenEnderPluginCommand.java index 5a05087..bb383c5 100644 --- a/src/main/java/com/lishid/openinv/commands/OpenEnderPluginCommand.java +++ b/src/main/java/com/lishid/openinv/commands/OpenEnderPluginCommand.java @@ -34,7 +34,7 @@ import com.lishid.openinv.utils.UUIDUtil; public class OpenEnderPluginCommand implements CommandExecutor { private final OpenInv plugin; - public static final Map openEnderHistory = new ConcurrentHashMap(); + private final Map openEnderHistory = new ConcurrentHashMap(); public OpenEnderPluginCommand(OpenInv plugin) { this.plugin = plugin; @@ -49,7 +49,7 @@ public class OpenEnderPluginCommand implements CommandExecutor { } if (!OpenInv.hasPermission(sender, Permissions.PERM_ENDERCHEST)) { - sender.sendMessage(ChatColor.RED + "You do not have permission to access player enderchest"); + sender.sendMessage(ChatColor.RED + "You do not have permission to access player enderchests."); return true; } @@ -58,7 +58,7 @@ public class OpenEnderPluginCommand implements CommandExecutor { return true; } - Player player = (Player) sender; + final Player player = (Player) sender; // History management UUID history = openEnderHistory.get(player.getUniqueId()); @@ -85,21 +85,25 @@ public class OpenEnderPluginCommand implements CommandExecutor { } final UUID playerUUID = player.getUniqueId(); + Player target = Bukkit.getPlayer(uuid); - // Targeted player was not found online, start asynchron lookup in files if (target == null) { - sender.sendMessage(ChatColor.GREEN + "Starting inventory lookup."); - plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() { + // Targeted player was not found online, start asynchronous lookup in files + Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { @Override public void run() { - // Try loading the player's data asynchronly + // Try loading the player's data asynchronously final Player target = OpenInv.playerLoader.loadPlayer(uuid); - // Back to synchron to send messages and display inventory + if (target == null) { + player.sendMessage(ChatColor.RED + "Player not found!"); + return; + } + // Open target's inventory synchronously Bukkit.getScheduler().runTask(plugin, new Runnable() { @Override public void run() { Player player = Bukkit.getPlayer(playerUUID); - // If sender is no longer online after loading the target. Abort! + // If sender is no longer online after loading the target, abort! if (player == null) { return; } diff --git a/src/main/java/com/lishid/openinv/commands/OpenInvPluginCommand.java b/src/main/java/com/lishid/openinv/commands/OpenInvPluginCommand.java index 4ae1f19..7d01e73 100644 --- a/src/main/java/com/lishid/openinv/commands/OpenInvPluginCommand.java +++ b/src/main/java/com/lishid/openinv/commands/OpenInvPluginCommand.java @@ -34,7 +34,7 @@ import com.lishid.openinv.utils.UUIDUtil; public class OpenInvPluginCommand implements CommandExecutor { private final OpenInv plugin; - public static final Map openInvHistory = new ConcurrentHashMap(); + private final Map openInvHistory = new ConcurrentHashMap(); public OpenInvPluginCommand(OpenInv plugin) { this.plugin = plugin; @@ -48,7 +48,7 @@ public class OpenInvPluginCommand implements CommandExecutor { return true; } if (!OpenInv.hasPermission(sender, Permissions.PERM_OPENINV)) { - sender.sendMessage(ChatColor.RED + "You do not have permission to access player inventories"); + sender.sendMessage(ChatColor.RED + "You do not have permission to access player inventories."); return true; } @@ -57,7 +57,7 @@ public class OpenInvPluginCommand implements CommandExecutor { return true; } - Player player = (Player) sender; + final Player player = (Player) sender; // History management UUID history = openInvHistory.get(player.getUniqueId()); @@ -78,21 +78,25 @@ public class OpenInvPluginCommand implements CommandExecutor { } final UUID playerUUID = player.getUniqueId(); + Player target = Bukkit.getPlayer(uuid); - // Targeted player was not found online, start asynchron lookup in files if (target == null) { - sender.sendMessage(ChatColor.GREEN + "Starting inventory lookup."); - plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() { + // Targeted player was not found online, start asynchronous lookup in files + Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { @Override public void run() { - // Try loading the player's data asynchronly + // Try loading the player's data asynchronously final Player target = OpenInv.playerLoader.loadPlayer(uuid); - // Back to synchron to send messages and display inventory + if (target == null) { + player.sendMessage(ChatColor.RED + "Player not found!"); + return; + } + // Open target's inventory synchronously Bukkit.getScheduler().runTask(plugin, new Runnable() { @Override public void run() { Player player = Bukkit.getPlayer(playerUUID); - // If sender is no longer online after loading the target. Abort! + // If sender is no longer online after loading the target, abort! if (player == null) { return; } diff --git a/src/main/java/com/lishid/openinv/internal/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/PlayerDataManager.java index d0ee87e..2bbc264 100644 --- a/src/main/java/com/lishid/openinv/internal/PlayerDataManager.java +++ b/src/main/java/com/lishid/openinv/internal/PlayerDataManager.java @@ -34,7 +34,7 @@ public class PlayerDataManager { public Player loadPlayer(UUID uuid) { try { OfflinePlayer player = Bukkit.getOfflinePlayer(uuid); - if (player == null) { + if (player == null || !player.hasPlayedBefore()) { return null; } GameProfile profile = new GameProfile(uuid, player.getName()); diff --git a/src/main/java/com/lishid/openinv/internal/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/SpecialPlayerInventory.java index 48cdcdd..c34f3be 100644 --- a/src/main/java/com/lishid/openinv/internal/SpecialPlayerInventory.java +++ b/src/main/java/com/lishid/openinv/internal/SpecialPlayerInventory.java @@ -32,7 +32,7 @@ public class SpecialPlayerInventory extends PlayerInventory { private CraftPlayer owner; private boolean playerOnline = false; - public SpecialPlayerInventory(Player p, Boolean online) { + public SpecialPlayerInventory(Player p, boolean online) { super(((CraftPlayer) p).getHandle()); this.owner = (CraftPlayer) p; this.items = player.inventory.items;