summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2012-03-25 02:33:52 +0100
committerKHobbits <rob@khobbits.co.uk>2012-03-25 02:33:52 +0100
commitb7221516dce1e10664a3b54104fd012c30c0fbef (patch)
treed915566af361e1e7ac4b4a25519f5497f662bd92
parent160c3f428ce7ae3b80d6d08ca796f6881b1c8eca (diff)
downloadEssentials-b7221516dce1e10664a3b54104fd012c30c0fbef.tar
Essentials-b7221516dce1e10664a3b54104fd012c30c0fbef.tar.gz
Essentials-b7221516dce1e10664a3b54104fd012c30c0fbef.tar.lz
Essentials-b7221516dce1e10664a3b54104fd012c30c0fbef.tar.xz
Essentials-b7221516dce1e10664a3b54104fd012c30c0fbef.zip
Invsee now shows a live player inventory in a window, rather than cloning players inventory.
New Permission: essentials.invsee.modify - Player with this permission will be able to add/remove items from the other players inventory.
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java30
-rw-r--r--Essentials/src/com/earth2me/essentials/UserData.java52
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandinvsee.java37
-rw-r--r--Essentials/src/plugin.yml6
4 files changed, 41 insertions, 84 deletions
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
index 43adf0a6f..486235993 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
@@ -20,6 +20,9 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
+import org.bukkit.event.inventory.InventoryClickEvent;
+import org.bukkit.event.inventory.InventoryCloseEvent;
+import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerLoginEvent.Result;
import org.bukkit.event.player.*;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
@@ -107,11 +110,6 @@ public class EssentialsPlayerListener implements Listener
{
user.toggleGodModeEnabled();
}
- if (user.getSavedInventory() != null)
- {
- user.getInventory().setContents(user.getSavedInventory());
- user.setSavedInventory(null);
- }
user.updateActivity(false);
user.dispose();
}
@@ -388,4 +386,26 @@ public class EssentialsPlayerListener implements Listener
event.setCancelled(true);
}
}
+
+ @EventHandler(priority = EventPriority.LOW)
+ public void onInventoryClickEvent(final InventoryClickEvent event)
+ {
+ if (event.getView().getTopInventory().getType() == InventoryType.PLAYER)
+ {
+ final User user = ess.getUser(event.getWhoClicked());
+ if (user.isInvSee() && !user.isAuthorized("essentials.invsee.modify"))
+ {
+ event.setCancelled(true);
+ }
+ }
+ }
+ @EventHandler(priority = EventPriority.MONITOR)
+ public void onInventoryCloseEvent(final InventoryCloseEvent event)
+ {
+ if (event.getView().getTopInventory().getType() == InventoryType.PLAYER)
+ {
+ final User user = ess.getUser(event.getPlayer());
+ user.setInvSee(false);
+ }
+ }
}
diff --git a/Essentials/src/com/earth2me/essentials/UserData.java b/Essentials/src/com/earth2me/essentials/UserData.java
index 3b6516277..11c701c34 100644
--- a/Essentials/src/com/earth2me/essentials/UserData.java
+++ b/Essentials/src/com/earth2me/essentials/UserData.java
@@ -42,7 +42,6 @@ public abstract class UserData extends PlayerExtension implements IConf
lastHealTimestamp = _getLastHealTimestamp();
jail = _getJail();
mails = _getMails();
- savedInventory = _getSavedInventory();
teleportEnabled = getTeleportEnabled();
ignoredPlayers = getIgnoredPlayers();
godmode = _getGodModeEnabled();
@@ -407,50 +406,17 @@ public abstract class UserData extends PlayerExtension implements IConf
mails.add(mail);
setMails(mails);
}
- private ItemStack[] savedInventory;
-
- public ItemStack[] getSavedInventory()
- {
- return savedInventory;
- }
-
- private ItemStack[] _getSavedInventory()
- {
- int size = config.getInt("inventory.size", 0);
- if (size < 1 || (getInventory() != null && size > getInventory().getSize()))
- {
- return null;
- }
- ItemStack[] is = new ItemStack[size];
- for (int i = 0; i < size; i++)
- {
- is[i] = config.getItemStack("inventory." + i);
- }
- return is;
+
+ private boolean invSee;
+
+ public boolean isInvSee() {
+ return invSee;
}
-
- public void setSavedInventory(ItemStack[] is)
- {
- if (is == null || is.length == 0)
- {
- savedInventory = null;
- config.removeProperty("inventory");
- }
- else
- {
- savedInventory = is;
- config.setProperty("inventory.size", is.length);
- for (int i = 0; i < is.length; i++)
- {
- if (is[i] == null || is[i].getType() == Material.AIR)
- {
- continue;
- }
- config.setProperty("inventory." + i, is[i]);
- }
- }
- config.save();
+
+ public void setInvSee(boolean set) {
+ invSee = set;
}
+
private boolean teleportEnabled;
private boolean getTeleportEnabled()
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandinvsee.java b/Essentials/src/com/earth2me/essentials/commands/Commandinvsee.java
index 1f5c32faa..a4a659e97 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandinvsee.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandinvsee.java
@@ -17,41 +17,12 @@ public class Commandinvsee extends EssentialsCommand
@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
{
-
- if (args.length < 1 && user.getSavedInventory() == null)
+ if (args.length < 1)
{
throw new NotEnoughArgumentsException();
}
- User invUser = user;
- if (args.length == 1)
- {
- invUser = getPlayer(server, args, 0);
- }
- if (invUser == user && user.getSavedInventory() != null)
- {
- invUser.getInventory().setContents(user.getSavedInventory());
- user.setSavedInventory(null);
- user.sendMessage(_("invRestored"));
- throw new NoChargeException();
- }
-
- if (user.getSavedInventory() == null)
- {
- user.setSavedInventory(user.getInventory().getContents());
- }
- ItemStack[] invUserStack = invUser.getInventory().getContents();
- final int userStackLength = user.getInventory().getContents().length;
- if (invUserStack.length < userStackLength)
- {
- invUserStack = Arrays.copyOf(invUserStack, userStackLength);
- }
- if (invUserStack.length > userStackLength)
- {
- throw new Exception(_("invBigger"));
- }
- user.getInventory().setContents(invUserStack);
- user.sendMessage(_("invSee", invUser.getDisplayName()));
- user.sendMessage(_("invSeeHelp"));
- throw new NoChargeException();
+ final User invUser = getPlayer(server, args, 0);
+ user.setInvSee(true);
+ user.openInventory(invUser.getInventory());
}
}
diff --git a/Essentials/src/plugin.yml b/Essentials/src/plugin.yml
index 7eaca70f4..2230cf71c 100644
--- a/Essentials/src/plugin.yml
+++ b/Essentials/src/plugin.yml
@@ -189,7 +189,7 @@ commands:
killall:
description: Kill all mobs in a world.
usage: /<command> [mobType] [radius]
- aliases: [ekillall,butcher,ebutcher]
+ aliases: [ekillall,butcher,ebutcher,mobkill,emobkill]
kittycannon:
description: Throw an exploding kitten at your opponent
usage: /<command>
@@ -308,11 +308,11 @@ commands:
spawner:
description: Change the mob type of a spawner
usage: /<command> <mob>
- aliases: [espawner]
+ aliases: [espawner,changems,echangems]
spawnmob:
description: Spawns a mob.
usage: /<command> <mob>[:data][,<mount>[:data]] [amount] [player]
- aliases: [espawnmob]
+ aliases: [espawnmob,mob,emob]
sudo:
description: Make another user perform a command.
usage: /<command> <player> <command [args]>