summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2012-01-04 17:51:14 +0000
committerKHobbits <rob@khobbits.co.uk>2012-01-04 17:51:14 +0000
commitde0a4194763173ef7e624f3910fa424ffeefadfc (patch)
tree75c8288e6cf23ebe95baa8e2ce9b65750548b5c3
parent6dd73f524773e20636eef1a1fc8b964ab4fa4e04 (diff)
downloadEssentials-de0a4194763173ef7e624f3910fa424ffeefadfc.tar
Essentials-de0a4194763173ef7e624f3910fa424ffeefadfc.tar.gz
Essentials-de0a4194763173ef7e624f3910fa424ffeefadfc.tar.lz
Essentials-de0a4194763173ef7e624f3910fa424ffeefadfc.tar.xz
Essentials-de0a4194763173ef7e624f3910fa424ffeefadfc.zip
Cleaning up item spawning and kits.
-rw-r--r--Essentials/src/com/earth2me/essentials/ItemDb.java27
-rw-r--r--Essentials/src/com/earth2me/essentials/Kits.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/api/IItemDb.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/api/IUser.java4
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandgive.java43
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commanditem.java38
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandrealname.java3
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java1
-rw-r--r--Essentials/src/com/earth2me/essentials/user/User.java27
-rw-r--r--EssentialsSigns/src/com/earth2me/essentials/signs/SignKit.java10
10 files changed, 71 insertions, 86 deletions
diff --git a/Essentials/src/com/earth2me/essentials/ItemDb.java b/Essentials/src/com/earth2me/essentials/ItemDb.java
index 2abdb83c7..3ac4326f7 100644
--- a/Essentials/src/com/earth2me/essentials/ItemDb.java
+++ b/Essentials/src/com/earth2me/essentials/ItemDb.java
@@ -3,10 +3,12 @@ package com.earth2me.essentials;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.IItemDb;
+import com.earth2me.essentials.api.IUser;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import lombok.Cleanup;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
@@ -58,6 +60,31 @@ public class ItemDb implements IItemDb
}
}
+ public ItemStack get(final String id, final IUser user) throws Exception
+ {
+ final ItemStack stack = get(id.toLowerCase(Locale.ENGLISH));
+
+ int defaultStackSize = 0;
+ int oversizedStackSize = 0;
+ @Cleanup
+ com.earth2me.essentials.api.ISettings settings = ess.getSettings();
+ settings.acquireReadLock();
+
+ defaultStackSize = settings.getData().getGeneral().getDefaultStacksize();
+ oversizedStackSize = settings.getData().getGeneral().getOversizedStacksize();
+
+ if (defaultStackSize > 0)
+ {
+ stack.setAmount(defaultStackSize);
+ }
+ else if (oversizedStackSize > 0 && user.isAuthorized("essentials.oversizedstacks"))
+ {
+ stack.setAmount(oversizedStackSize);
+ }
+
+ return stack;
+ }
+
public ItemStack get(final String id, final int quantity) throws Exception
{
final ItemStack retval = get(id.toLowerCase(Locale.ENGLISH));
diff --git a/Essentials/src/com/earth2me/essentials/Kits.java b/Essentials/src/com/earth2me/essentials/Kits.java
index da08a7540..880f3f511 100644
--- a/Essentials/src/com/earth2me/essentials/Kits.java
+++ b/Essentials/src/com/earth2me/essentials/Kits.java
@@ -65,7 +65,7 @@ public class Kits extends AsyncStorageObjectHolder<com.earth2me.essentials.setti
public void sendKit(IUser user, Kit kit) throws Exception
{
final List<ItemStack> itemList = kit.getItems();
- user.giveItems(itemList);
+ user.giveItems(itemList, true);
}
@Override
diff --git a/Essentials/src/com/earth2me/essentials/api/IItemDb.java b/Essentials/src/com/earth2me/essentials/api/IItemDb.java
index b37d9e1a2..5aa79f002 100644
--- a/Essentials/src/com/earth2me/essentials/api/IItemDb.java
+++ b/Essentials/src/com/earth2me/essentials/api/IItemDb.java
@@ -5,6 +5,8 @@ import org.bukkit.inventory.ItemStack;
public interface IItemDb extends IReload
{
+ ItemStack get(final String name, final IUser user) throws Exception;
+
ItemStack get(final String name, final int quantity) throws Exception;
ItemStack get(final String name) throws Exception;
diff --git a/Essentials/src/com/earth2me/essentials/api/IUser.java b/Essentials/src/com/earth2me/essentials/api/IUser.java
index dbb459ac3..7217c3989 100644
--- a/Essentials/src/com/earth2me/essentials/api/IUser.java
+++ b/Essentials/src/com/earth2me/essentials/api/IUser.java
@@ -30,9 +30,9 @@ public interface IUser extends Player, IStorageObjectHolder<UserData>, IReload,
void giveMoney(double value, CommandSender initiator);
- void giveItems(ItemStack itemStack);
+ void giveItems(ItemStack itemStack, Boolean canSpew);
- void giveItems(List<ItemStack> itemStacks);
+ void giveItems(List<ItemStack> itemStacks, Boolean canSpew);
void setMoney(double value);
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java
index 717ff0bff..45fc2f77b 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java
@@ -22,8 +22,10 @@ public class Commandgive extends EssentialsCommand
{
throw new NotEnoughArgumentsException();
}
+
+ final IUser giveTo = getPlayer(args, 0);
- final ItemStack stack = ess.getItemDb().get(args[1]);
+ final ItemStack stack = ess.getItemDb().get(args[1], giveTo);
final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
if (sender instanceof Player
@@ -31,35 +33,12 @@ public class Commandgive extends EssentialsCommand
&& !ess.getUser((Player)sender).isAuthorized("essentials.give.item-" + stack.getTypeId())))
{
throw new Exception(ChatColor.RED + "You are not allowed to spawn the item " + itemname);
- }
+ }
- final IUser giveTo = getPlayer(args, 0);
-
- int defaultStackSize = 0;
- int oversizedStackSize = 0;
- ISettings settings = ess.getSettings();
- settings.acquireReadLock();
- try
- {
- defaultStackSize = settings.getData().getGeneral().getDefaultStacksize();
- oversizedStackSize = settings.getData().getGeneral().getOversizedStacksize();
- }
- finally
- {
- settings.unlock();
- }
if (args.length > 2 && Integer.parseInt(args[2]) > 0)
{
stack.setAmount(Integer.parseInt(args[2]));
- }
- else if (defaultStackSize > 0)
- {
- stack.setAmount(defaultStackSize);
- }
- else if (oversizedStackSize > 0 && giveTo.isAuthorized("essentials.oversizedstacks"))
- {
- stack.setAmount(oversizedStackSize);
- }
+ }
if (args.length > 3)
{
@@ -88,17 +67,11 @@ public class Commandgive extends EssentialsCommand
{
throw new Exception(ChatColor.RED + "You can't give air.");
}
+
+ giveTo.giveItems(stack, false);
final String itemName = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace('_', ' ');
sender.sendMessage(ChatColor.BLUE + "Giving " + stack.getAmount() + " of " + itemName + " to " + giveTo.getDisplayName() + ".");
- if (giveTo.isAuthorized("essentials.oversizedstacks"))
- {
- InventoryWorkaround.addItem(giveTo.getInventory(), true, oversizedStackSize, stack);
- }
- else
- {
- InventoryWorkaround.addItem(giveTo.getInventory(), true, stack);
- }
- giveTo.updateInventory();
+
}
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanditem.java b/Essentials/src/com/earth2me/essentials/commands/Commanditem.java
index 66756fe1f..985535dec 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commanditem.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commanditem.java
@@ -19,7 +19,7 @@ public class Commanditem extends EssentialsCommand
{
throw new NotEnoughArgumentsException();
}
- final ItemStack stack = ess.getItemDb().get(args[0]);
+ final ItemStack stack = ess.getItemDb().get(args[0], user);
final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
if (!user.isAuthorized("essentials.itemspawn.item-" + itemname)
@@ -28,32 +28,11 @@ public class Commanditem extends EssentialsCommand
throw new Exception(_("cantSpawnItem", itemname));
}
- int defaultStackSize = 0;
- int oversizedStackSize = 0;
- ISettings settings = ess.getSettings();
- settings.acquireReadLock();
- try
- {
- defaultStackSize = settings.getData().getGeneral().getDefaultStacksize();
- oversizedStackSize = settings.getData().getGeneral().getOversizedStacksize();
- }
- finally
- {
- settings.unlock();
- }
if (args.length > 1 && Integer.parseInt(args[1]) > 0)
{
stack.setAmount(Integer.parseInt(args[1]));
}
- else if (defaultStackSize > 0)
- {
- stack.setAmount(defaultStackSize);
- }
- else if (oversizedStackSize > 0 && user.isAuthorized("essentials.oversizedstacks"))
- {
- stack.setAmount(oversizedStackSize);
- }
-
+
if (args.length > 2)
{
for (int i = 2; i < args.length; i++)
@@ -82,16 +61,9 @@ public class Commanditem extends EssentialsCommand
throw new Exception(_("cantSpawnItem", "Air"));
}
+ user.giveItems(stack, false);
+
final String displayName = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace('_', ' ');
- user.sendMessage(_("itemSpawn", stack.getAmount(), displayName));
- if (user.isAuthorized("essentials.oversizedstacks"))
- {
- InventoryWorkaround.addItem(user.getInventory(), true, oversizedStackSize, stack);
- }
- else
- {
- InventoryWorkaround.addItem(user.getInventory(), true, stack);
- }
- user.updateInventory();
+ user.sendMessage(_("itemSpawn", stack.getAmount(), displayName));
}
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java b/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java
index 6b4381d7b..db4dbd31e 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java
@@ -19,7 +19,8 @@ public class Commandrealname extends EssentialsCommand
{
throw new NotEnoughArgumentsException();
}
- @Cleanup final ISettings settings = ess.getSettings();
+ @Cleanup
+ final ISettings settings = ess.getSettings();
final String whois = args[0].toLowerCase(Locale.ENGLISH);
for (Player onlinePlayer : server.getOnlinePlayers())
{
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java b/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java
index cea64131a..0c6ac8b12 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java
@@ -104,6 +104,7 @@ public class Commandunlimited extends EssentialsCommand
user.sendMessage(_(message, itemname, target.getDisplayName()));
}
target.sendMessage(_(message, itemname, target.getDisplayName()));
+ target.acquireWriteLock();
target.getData().setUnlimited(stack.getType(), enableUnlimited);
return true;
diff --git a/Essentials/src/com/earth2me/essentials/user/User.java b/Essentials/src/com/earth2me/essentials/user/User.java
index e42e5396a..54092d6ef 100644
--- a/Essentials/src/com/earth2me/essentials/user/User.java
+++ b/Essentials/src/com/earth2me/essentials/user/User.java
@@ -654,21 +654,21 @@ public class User extends UserBase implements IUser
}
@Override
- public void giveItems(ItemStack itemStack)
+ public void giveItems(ItemStack itemStack, Boolean canSpew)
{
- if (giveItemStack(itemStack))
+ if (giveItemStack(itemStack, canSpew))
{
sendMessage(_("InvFull"));
}
}
@Override
- public void giveItems(List<ItemStack> itemStacks)
+ public void giveItems(List<ItemStack> itemStacks, Boolean canSpew)
{
boolean spew = false;
for (ItemStack itemStack : itemStacks)
{
- if (giveItemStack(itemStack))
+ if (giveItemStack(itemStack, canSpew))
{
spew = true;
}
@@ -679,9 +679,15 @@ public class User extends UserBase implements IUser
}
}
- private boolean giveItemStack(ItemStack itemStack)
+ private boolean giveItemStack(ItemStack itemStack, Boolean canSpew)
{
boolean spew = false;
+
+ if (itemStack == null || itemStack.getType() == Material.AIR)
+ {
+ return spew;
+ }
+
final Map<Integer, ItemStack> overfilled;
if (isAuthorized("essentials.oversizedstacks"))
{
@@ -696,11 +702,14 @@ public class User extends UserBase implements IUser
{
overfilled = InventoryWorkaround.addItem(getInventory(), true, itemStack);
}
- for (ItemStack overflowStack : overfilled.values())
+ if (canSpew)
{
- getWorld().dropItemNaturally(getLocation(), overflowStack);
- spew = true;
+ for (ItemStack overflowStack : overfilled.values())
+ {
+ getWorld().dropItemNaturally(getLocation(), overflowStack);
+ spew = true;
+ }
}
return spew;
- }
+ }
}
diff --git a/EssentialsSigns/src/com/earth2me/essentials/signs/SignKit.java b/EssentialsSigns/src/com/earth2me/essentials/signs/SignKit.java
index 16f314d5f..4e7aaf793 100644
--- a/EssentialsSigns/src/com/earth2me/essentials/signs/SignKit.java
+++ b/EssentialsSigns/src/com/earth2me/essentials/signs/SignKit.java
@@ -3,6 +3,7 @@ package com.earth2me.essentials.signs;
import com.earth2me.essentials.*;
import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.IUser;
+import com.earth2me.essentials.settings.Kit;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -31,7 +32,7 @@ public class SignKit extends EssentialsSign
{
try
{
- ess.getSettings().getKit(kitName);
+ ess.getKits().getKit(kitName);
}
catch (Exception ex)
{
@@ -58,10 +59,9 @@ public class SignKit extends EssentialsSign
charge.isAffordableFor(player);
try
{
- final Object kit = ess.getSettings().getKit(kitName);
- final Map<String, Object> els = (Map<String, Object>)kit;
- final List<String> items = Kit.getItems(player, els);
- Kit.expandItems(ess, player, items);
+ final Kit kit = ess.getKits().getKit(kitName);
+ ess.getKits().sendKit(player, kit);
+
charge.charge(player);
}
catch (Exception ex)