Cross world disabled

This commit is contained in:
lishd 2011-07-11 16:53:59 -04:00
parent 8908cc918a
commit 70c75996c0
4 changed files with 59 additions and 18 deletions

View file

@ -6,6 +6,7 @@ import lishid.openinv.utils.PlayerInventoryChest;
import net.minecraft.server.ContainerPlayer; import net.minecraft.server.ContainerPlayer;
import net.minecraft.server.EntityPlayer; import net.minecraft.server.EntityPlayer;
import net.minecraft.server.ICrafting;
import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.event.Event; import org.bukkit.event.Event;
@ -24,6 +25,7 @@ import org.bukkit.plugin.Plugin;
public class OpenInv extends JavaPlugin { public class OpenInv extends JavaPlugin {
private final OpenInvPlayerListener playerListener = new OpenInvPlayerListener(this); private final OpenInvPlayerListener playerListener = new OpenInvPlayerListener(this);
private final OpenInvEntityListener entityListener = new OpenInvEntityListener(this); private final OpenInvEntityListener entityListener = new OpenInvEntityListener(this);
//private final OpenInvInventoryListener inventoryListener = new OpenInvInventoryListener(this);
public static PermissionHandler permissionHandler; public static PermissionHandler permissionHandler;
public void onDisable() { public void onDisable() {
} }
@ -47,10 +49,11 @@ public class OpenInv extends JavaPlugin {
//pm.registerEvent(Event.Type.PLAYER_RESPAWN, playerListener, Event.Priority.Normal, this); //pm.registerEvent(Event.Type.PLAYER_RESPAWN, playerListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_INTERACT, playerListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.PLAYER_INTERACT, playerListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener, Event.Priority.Normal, this);
//pm.registerEvent(Event.Type.INVENTORY_CLOSE, inventoryListener, Event.Priority.Normal, this);
setupPermissions(); setupPermissions();
// EXAMPLE: Custom code, here we just output some info so we can check all is well
PluginDescriptionFile pdfFile = this.getDescription(); PluginDescriptionFile pdfFile = this.getDescription();
System.out.println("[" + pdfFile.getName() + "] version " + pdfFile.getVersion() + " is enabled!" ); System.out.println("[" + pdfFile.getName() + "] version " + pdfFile.getVersion() + " enabled!" );
getCommand("openinv").setExecutor(new OpenInvPluginCommand(this)); getCommand("openinv").setExecutor(new OpenInvPluginCommand(this));
getCommand("searchinv").setExecutor(new SearchInvPluginCommand(this)); getCommand("searchinv").setExecutor(new SearchInvPluginCommand(this));
@ -59,12 +62,20 @@ public class OpenInv extends JavaPlugin {
public static void ReplaceInv(CraftPlayer player) public static void ReplaceInv(CraftPlayer player)
{ {
try{
EntityPlayer entityplayer = player.getHandle(); EntityPlayer entityplayer = player.getHandle();
entityplayer.inventory = new PlayerInventoryChest(entityplayer.inventory); entityplayer.inventory = new PlayerInventoryChest(entityplayer.inventory);
entityplayer.defaultContainer = new ContainerPlayer(entityplayer.inventory, !entityplayer.world.isStatic); entityplayer.defaultContainer = new ContainerPlayer(entityplayer.inventory, !entityplayer.world.isStatic);
entityplayer.activeContainer = entityplayer.defaultContainer; entityplayer.activeContainer = entityplayer.defaultContainer;
//sync
((ICrafting)entityplayer).a(entityplayer.activeContainer, entityplayer.activeContainer.b());
entityplayer.activeContainer.a();
player.setHandle(entityplayer); player.setHandle(entityplayer);
} }
catch(Exception e)
{}
}
} }

View file

@ -19,6 +19,7 @@ import org.bukkit.entity.Player;
public class OpenInvPluginCommand implements CommandExecutor { public class OpenInvPluginCommand implements CommandExecutor {
private final OpenInv plugin; private final OpenInv plugin;
public static HashMap<Player, PlayerInventoryChest> offlineInv = new HashMap<Player, PlayerInventoryChest>();
public static HashMap<Player, OpenInvHistory> theOpenInvHistory = new HashMap<Player, OpenInvHistory>(); public static HashMap<Player, OpenInvHistory> theOpenInvHistory = new HashMap<Player, OpenInvHistory>();
public OpenInvPluginCommand(OpenInv plugin) { public OpenInvPluginCommand(OpenInv plugin) {
this.plugin = plugin; this.plugin = plugin;
@ -30,6 +31,7 @@ public class OpenInvPluginCommand implements CommandExecutor {
return true; return true;
} }
//boolean Offline = false;
Player player = (Player)sender; Player player = (Player)sender;
OpenInvHistory history = theOpenInvHistory.get(player); OpenInvHistory history = theOpenInvHistory.get(player);
@ -60,13 +62,11 @@ public class OpenInvPluginCommand implements CommandExecutor {
if(history.lastPlayer != null) if(history.lastPlayer != null)
{ {
target = this.plugin.getServer().getPlayer(history.lastPlayer); target = this.plugin.getServer().getPlayer(history.lastPlayer);
//EntityPlayer entply = new EntityPlayer(((CraftServer)this.plugin.getServer()).getServer(), ((CraftPlayer)player).getHandle().world, "", null);
//CraftPlayer ply = new CraftPlayer((CraftServer) this.plugin.getServer(), null);
} }
else else
{ {
sender.sendMessage("OpenInv history is empty!"); sender.sendMessage(ChatColor.RED + "OpenInv history is empty!");
return false; return true;
} }
} }
else else
@ -77,13 +77,32 @@ public class OpenInvPluginCommand implements CommandExecutor {
if(target == null) if(target == null)
{ {
sender.sendMessage("Player not found!"); //Offline inv here...
/*try{
MinecraftServer server = ((CraftServer)this.plugin.getServer()).getServer();
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), args[0], new ItemInWorldManager(server.getWorldServer(0)));
target = (entity == null) ? null : (Player) entity.getBukkitEntity();
if(target != null)
{
Offline = true;
target.loadData();
}
else
{
sender.sendMessage(ChatColor.RED + "Player not found!");
return false; return false;
} }
} catch(Exception e)
{*/
//sender.sendMessage("Error while retrieving offline player data!");
sender.sendMessage(ChatColor.RED + "Player '" + args[0] + "' not found!");
return true;
/*}*/
}
if(target == player) if(target == player)
{ {
sender.sendMessage("Cannot target yourself!"); sender.sendMessage(ChatColor.RED + "Cannot OpenInv yourself!");
return false; return true;
} }
if (!PermissionRelay.hasPermission(player, "OpenInv.override") && PermissionRelay.hasPermission(target, "OpenInv.exempt")) { if (!PermissionRelay.hasPermission(player, "OpenInv.override") && PermissionRelay.hasPermission(target, "OpenInv.exempt")) {
@ -91,6 +110,12 @@ public class OpenInvPluginCommand implements CommandExecutor {
return true; return true;
} }
if((!PermissionRelay.hasPermission(player, "OpenInv.crossworld") && !PermissionRelay.hasPermission(player, "OpenInv.override")) &&
target.getWorld() != player.getWorld()){
sender.sendMessage(ChatColor.RED + target.getDisplayName() + " is not in your world!");
return true;
}
history.lastPlayer = target.getName(); history.lastPlayer = target.getName();
// Get the EntityPlayer handle from the sender // Get the EntityPlayer handle from the sender
@ -103,7 +128,12 @@ public class OpenInvPluginCommand implements CommandExecutor {
{ {
OpenInv.ReplaceInv((CraftPlayer) target); OpenInv.ReplaceInv((CraftPlayer) target);
} }
/*
if(Offline && entitytarget.inventory instanceof PlayerInventoryChest)
{
offlineInv.put(target, (PlayerInventoryChest) entitytarget.inventory);
}
*/
entityplayer.a(entitytarget.inventory); entityplayer.a(entitytarget.inventory);
return true; return true;

View file

@ -20,7 +20,7 @@ public class PlayerInventoryChest extends InventoryPlayer
@Override @Override
public String getName() { public String getName() {
return ((EntityPlayer)this.d).displayName; return ((EntityPlayer)this.d).displayName + " (" + this.itemInHandIndex + ")";
} }
@Override @Override

View file

@ -1,6 +1,6 @@
name: OpenInv name: OpenInv
main: lishid.openinv.OpenInv main: lishid.openinv.OpenInv
version: 1.3.1 version: 1.3.3
author: lishid author: lishid
description: > description: >
This plugin allows you to open another player's inventory as a chest This plugin allows you to open another player's inventory as a chest