Compare commits

...

1 Commits
2.2.5 ... 2.2.6

Author SHA1 Message Date
Jikoo
21cd1926ae Don't find username on the main thread. Not friendly with partial names. 2014-12-01 16:11:52 -05:00
6 changed files with 127 additions and 52 deletions

View File

@@ -17,12 +17,16 @@
package com.lishid.openinv.commands; package com.lishid.openinv.commands;
import java.util.HashMap; import java.util.HashMap;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import com.lishid.openinv.OpenInv; import com.lishid.openinv.OpenInv;
import com.lishid.openinv.Permissions; import com.lishid.openinv.Permissions;
@@ -53,8 +57,7 @@ public class OpenEnderPluginCommand implements CommandExecutor {
return true; return true;
} }
Player player = (Player) sender; final Player player = (Player) sender;
boolean offline = false;
// History management // History management
String history = openEnderHistory.get(player); String history = openEnderHistory.get(player);
@@ -64,55 +67,74 @@ public class OpenEnderPluginCommand implements CommandExecutor {
openEnderHistory.put(player, history); openEnderHistory.put(player, history);
} }
// Target selecting final String name;
Player target;
String name = "";
// 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 (history != null && history != "") {
name = history; name = history;
} }
else {
sender.sendMessage(ChatColor.RED + "OpenEnder history is empty!");
return true;
}
}
else { else {
name = args[0]; name = args[0];
} }
target = this.plugin.getServer().getPlayer(name); sender.sendMessage(ChatColor.GREEN + "Starting inventory lookup.");
final UUID senderID = player.getUniqueId();
new BukkitRunnable() {
@Override
public void run() {
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(name);
if (Bukkit.getPlayer(senderID) == null) {
return;
}
if (offlinePlayer == null || !offlinePlayer.hasPlayedBefore()) {
player.sendMessage(ChatColor.RED + "Player not found!");
return;
}
new BukkitRunnable() {
@Override
public void run() {
if (Bukkit.getPlayer(senderID) == null) {
return;
}
openInventory(player, offlinePlayer.getUniqueId());
}
}.runTask(plugin);
}
}.runTaskAsynchronously(plugin);
return true;
}
private void openInventory(Player player, UUID uuid) {
Player target = this.plugin.getServer().getPlayer(uuid);
if (target == null) { if (target == null) {
// Try loading the player's data // Try loading the player's data
target = OpenInv.playerLoader.loadPlayer(name); target = OpenInv.playerLoader.loadPlayer(uuid);
if (target == null) { if (target == null) {
sender.sendMessage(ChatColor.RED + "Player " + name + " not found!"); player.sendMessage(ChatColor.RED + "Player not found!");
return true; return;
} }
} }
if (target != sender && !OpenInv.hasPermission(sender, Permissions.PERM_ENDERCHEST_ALL)) {
sender.sendMessage(ChatColor.RED + "You do not have permission to access other player's enderchest"); if (target != player && !OpenInv.hasPermission(player, Permissions.PERM_ENDERCHEST_ALL)) {
return true; player.sendMessage(ChatColor.RED + "You do not have permission to access other player's enderchest");
return;
} }
// Record the target // Record the target
history = target.getName(); openEnderHistory.put(player, target.getName());
openEnderHistory.put(player, history);
// Create the inventory // Create the inventory
ISpecialEnderChest chest = OpenInv.enderChests.get(target.getName().toLowerCase()); ISpecialEnderChest chest = OpenInv.enderChests.get(target.getName().toLowerCase());
if (chest == null) { if (chest == null) {
chest = InternalAccessor.Instance.newSpecialEnderChest(target, !offline); chest = InternalAccessor.Instance.newSpecialEnderChest(target, !target.isOnline());
} }
// Open the inventory // Open the inventory
player.openInventory(chest.getBukkitInventory()); player.openInventory(chest.getBukkitInventory());
return true;
} }
} }

View File

@@ -17,12 +17,16 @@
package com.lishid.openinv.commands; package com.lishid.openinv.commands;
import java.util.HashMap; import java.util.HashMap;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import com.lishid.openinv.OpenInv; import com.lishid.openinv.OpenInv;
import com.lishid.openinv.Permissions; import com.lishid.openinv.Permissions;
@@ -52,8 +56,7 @@ public class OpenInvPluginCommand implements CommandExecutor {
return true; return true;
} }
Player player = (Player) sender; final Player player = (Player) sender;
boolean offline = false;
// History management // History management
String history = openInvHistory.get(player); String history = openInvHistory.get(player);
@@ -63,10 +66,7 @@ public class OpenInvPluginCommand implements CommandExecutor {
openInvHistory.put(player, history); openInvHistory.put(player, history);
} }
// Target selecting final String name;
Player target;
String name = "";
// Read from history if target is not named // Read from history if target is not named
if (args.length < 1) { if (args.length < 1) {
@@ -76,51 +76,76 @@ public class OpenInvPluginCommand implements CommandExecutor {
name = args[0]; name = args[0];
} }
target = this.plugin.getServer().getPlayer(name); sender.sendMessage(ChatColor.GREEN + "Starting inventory lookup.");
final UUID senderID = player.getUniqueId();
new BukkitRunnable() {
@Override
public void run() {
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(name);
if (Bukkit.getPlayer(senderID) == null) {
return;
}
if (offlinePlayer == null || !offlinePlayer.hasPlayedBefore()) {
player.sendMessage(ChatColor.RED + "Player not found!");
return;
}
new BukkitRunnable() {
@Override
public void run() {
if (Bukkit.getPlayer(senderID) == null) {
return;
}
openInventory(player, offlinePlayer.getUniqueId());
}
}.runTask(plugin);
}
}.runTaskAsynchronously(plugin);
if (target == null) {
if (target == null) {
// Try loading the player's data
target = OpenInv.playerLoader.loadPlayer(name);
if (target == null) {
sender.sendMessage(ChatColor.RED + "Player " + name + " not found!");
return true; return true;
} }
private void openInventory(Player player, UUID uuid) {
Player target = this.plugin.getServer().getPlayer(uuid);
if (target == null) {
// Try loading the player's data
target = OpenInv.playerLoader.loadPlayer(uuid);
if (target == null) {
player.sendMessage(ChatColor.RED + "Player not found!");
return;
} }
} }
// Permissions checks // Permissions checks
if (!OpenInv.hasPermission(player, Permissions.PERM_OVERRIDE) && OpenInv.hasPermission(target, Permissions.PERM_EXEMPT)) { if (!OpenInv.hasPermission(player, Permissions.PERM_OVERRIDE) && OpenInv.hasPermission(target, Permissions.PERM_EXEMPT)) {
sender.sendMessage(ChatColor.RED + target.getDisplayName() + "'s inventory is protected!"); player.sendMessage(ChatColor.RED + target.getDisplayName() + "'s inventory is protected!");
return true; return;
} }
// Crosswork check // Crosswork check
if ((!OpenInv.hasPermission(player, Permissions.PERM_CROSSWORLD) && !OpenInv.hasPermission(player, Permissions.PERM_OVERRIDE)) && target.getWorld() != player.getWorld()) { if ((!OpenInv.hasPermission(player, Permissions.PERM_CROSSWORLD) && !OpenInv.hasPermission(player, Permissions.PERM_OVERRIDE)) && target.getWorld() != player.getWorld()) {
sender.sendMessage(ChatColor.RED + target.getDisplayName() + " is not in your world!"); player.sendMessage(ChatColor.RED + target.getDisplayName() + " is not in your world!");
return true; return;
} }
// Self-open check // Self-open check
if (!OpenInv.hasPermission(player, Permissions.PERM_OPENSELF) && target.equals(player)) { if (!OpenInv.hasPermission(player, Permissions.PERM_OPENSELF) && target.equals(player)) {
sender.sendMessage(ChatColor.RED + "You're not allowed to openinv yourself."); player.sendMessage(ChatColor.RED + "You're not allowed to openinv yourself.");
return true; return;
} }
// Record the target // Record the target
history = target.getName(); openInvHistory.put(player, target.getName());
openInvHistory.put(player, history);
// Create the inventory // Create the inventory
ISpecialPlayerInventory inv = OpenInv.inventories.get(target.getName().toLowerCase()); ISpecialPlayerInventory inv = OpenInv.inventories.get(target.getName().toLowerCase());
if (inv == null) { if (inv == null) {
inv = InternalAccessor.Instance.newSpecialPlayerInventory(target, !offline); inv = InternalAccessor.Instance.newSpecialPlayerInventory(target, !target.isOnline());
} }
// Open the inventory // Open the inventory
player.openInventory(inv.getBukkitInventory()); player.openInventory(inv.getBukkitInventory());
return true;
} }
} }

View File

@@ -16,8 +16,11 @@
package com.lishid.openinv.internal; package com.lishid.openinv.internal;
import java.util.UUID;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public interface IPlayerDataManager { public interface IPlayerDataManager {
public Player loadPlayer(String name); public Player loadPlayer(String name);
public Player loadPlayer(UUID uuid);
} }

View File

@@ -101,4 +101,29 @@ public class PlayerDataManager implements IPlayerDataManager {
return found; return found;
} }
/* (non-Javadoc)
* @see com.lishid.openinv.internal.IPlayerDataManager#loadPlayer(java.util.UUID)
*/
@Override
public Player loadPlayer(UUID uuid) {
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
if (player == null || !player.hasPlayedBefore()) {
return null;
}
GameProfile profile = new GameProfile(uuid, player.getName());
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
// Create an entity to load the player data
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0)));
// Get the bukkit entity
Player target = (entity == null) ? null : entity.getBukkitEntity();
if (target != null) {
// Load data
target.loadData();
// Return the entity
return target;
}
return null;
}
} }

View File

@@ -82,7 +82,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
public ItemStack[] getContents() { public ItemStack[] getContents() {
ItemStack[] C = new ItemStack[getSize()]; ItemStack[] C = new ItemStack[getSize()];
System.arraycopy(items, 0, C, 0, items.length); System.arraycopy(items, 0, C, 0, items.length);
System.arraycopy(items, 0, C, items.length, armor.length); System.arraycopy(armor, 0, C, items.length, armor.length);
return C; return C;
} }

View File

@@ -1,6 +1,6 @@
name: OpenInv name: OpenInv
main: com.lishid.openinv.OpenInv main: com.lishid.openinv.OpenInv
version: 2.2.5 version: 2.2.6
author: lishid author: lishid
description: > description: >
This plugin allows you to open a player's inventory as a chest and interact with it in real time. This plugin allows you to open a player's inventory as a chest and interact with it in real time.