mirror of
https://github.com/TotalFreedomMC/OpenInv.git
synced 2025-01-03 13:38:21 +00:00
Update to 1.10
This commit is contained in:
parent
c3a8bc9486
commit
de0d28b12d
1 changed files with 32 additions and 68 deletions
|
@ -45,9 +45,12 @@ public class OpenInvCommand implements CommandExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if (command.getName().equalsIgnoreCase("openinv")) {
|
if (command.getName().equalsIgnoreCase("openinv")) {
|
||||||
final boolean isConsole = sender instanceof ConsoleCommandSender;
|
if (!(sender instanceof Player)) {
|
||||||
|
sender.sendMessage(ChatColor.RED + "You can't use this command from the console.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (!OpenInv.hasPermission(sender, Permissions.PERM_OPENINV)) {
|
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.");
|
||||||
|
@ -55,38 +58,34 @@ public class OpenInvCommand implements CommandExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length > 0 && args[0].equalsIgnoreCase("?")) {
|
if (args.length > 0 && args[0].equalsIgnoreCase("?")) {
|
||||||
OpenInv.showHelp(sender);
|
OpenInv.showHelp((Player) sender);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = isConsole ? null : (Player) sender;
|
final Player player = (Player) sender;
|
||||||
|
|
||||||
|
// History management
|
||||||
|
UUID history = openInvHistory.get(player.getUniqueId());
|
||||||
|
if (history == null) {
|
||||||
|
history = player.getUniqueId();
|
||||||
|
openInvHistory.put(player.getUniqueId(), history);
|
||||||
|
}
|
||||||
|
|
||||||
final UUID uuid;
|
final UUID uuid;
|
||||||
|
|
||||||
// Read from history if target is not named
|
// Read from history if target is not named
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
if (isConsole) {
|
|
||||||
// TODO: Should this output the command's usage instead?
|
|
||||||
sender.sendMessage(ChatColor.RED + "Player not found!");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// History management
|
|
||||||
UUID history = openInvHistory.get(player.getUniqueId());
|
|
||||||
if (history == null) {
|
|
||||||
history = player.getUniqueId();
|
|
||||||
openInvHistory.put(player.getUniqueId(), history);
|
|
||||||
}
|
|
||||||
|
|
||||||
uuid = history;
|
uuid = history;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
uuid = UUIDUtils.getPlayerUUID(args[0]);
|
uuid = UUIDUtils.getPlayerUUID(args[0]);
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
sender.sendMessage(ChatColor.RED + "Player not found!");
|
player.sendMessage(ChatColor.RED + "Player not found!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final UUID playerUUID = isConsole ? null : player.getUniqueId();
|
final UUID playerUUID = player.getUniqueId();
|
||||||
|
|
||||||
Player target = Bukkit.getPlayer(uuid);
|
Player target = Bukkit.getPlayer(uuid);
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
|
@ -97,40 +96,27 @@ public class OpenInvCommand implements CommandExecutor {
|
||||||
// Try loading the player's data asynchronously
|
// Try loading the player's data asynchronously
|
||||||
final Player target = plugin.getPlayerLoader().loadPlayer(uuid);
|
final Player target = plugin.getPlayerLoader().loadPlayer(uuid);
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
sender.sendMessage(ChatColor.RED + "Player not found!");
|
player.sendMessage(ChatColor.RED + "Player not found!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open/output target's inventory synchronously
|
// Open target's inventory synchronously
|
||||||
if (isConsole) {
|
Bukkit.getScheduler().runTask(plugin, new Runnable() {
|
||||||
Bukkit.getScheduler().runTask(plugin, new Runnable() {
|
@Override
|
||||||
@Override
|
public void run() {
|
||||||
public void run() {
|
Player player = Bukkit.getPlayer(playerUUID);
|
||||||
outputInventory(sender, target);
|
// If sender is no longer online after loading the target, abort!
|
||||||
|
if (player == null) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
} else {
|
|
||||||
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 (player == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
openInventory(player, target);
|
openInventory(player, target);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if (isConsole) {
|
openInventory(player, target);
|
||||||
outputInventory(sender, target);
|
|
||||||
} else {
|
|
||||||
openInventory(player, target);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -139,28 +125,6 @@ public class OpenInvCommand implements CommandExecutor {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
private void outputInventory(CommandSender sender, Player target) {
|
|
||||||
// Get the inventory and open it
|
|
||||||
SpecialPlayerInventory specialInv = plugin.getPlayerInventory(target, true);
|
|
||||||
Inventory inventory = specialInv.getBukkitInventory();
|
|
||||||
|
|
||||||
for (int slot = 0; slot < inventory.getSize(); slot++) {
|
|
||||||
ItemStack itemStack = inventory.getItem(slot);
|
|
||||||
|
|
||||||
if (itemStack != null) {
|
|
||||||
String itemID = (itemStack.getDurability() != -1)
|
|
||||||
? (itemStack.getTypeId() + ":" + itemStack.getDurability())
|
|
||||||
: String.valueOf(itemStack.getTypeId());
|
|
||||||
|
|
||||||
sender.sendMessage(ChatColor.GREEN + "Slot " + slot + ": " + ChatColor.WHITE
|
|
||||||
+ itemStack.getType().toString() + "(" + itemID + ") x" + itemStack.getAmount());
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(ChatColor.GREEN + "Slot " + slot + ": " + ChatColor.WHITE + "Empty");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void openInventory(Player player, Player target) {
|
private void openInventory(Player player, Player target) {
|
||||||
// Null target check
|
// Null target check
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
|
|
Loading…
Reference in a new issue