mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-30 21:17:38 +01:00
Don't extend ItemStack
This commit is contained in:
parent
7fdb2ad7d3
commit
298ab846c1
@ -116,24 +116,24 @@ public class Kit
|
||||
|
||||
final String[] parts = d.split(" ");
|
||||
final ItemStack parseStack = ess.getItemDb().get(parts[0], parts.length > 1 ? Integer.parseInt(parts[1]) : 1);
|
||||
final MetaItemStack stack = new MetaItemStack(parseStack);
|
||||
final MetaItemStack metaStack = new MetaItemStack(parseStack);
|
||||
|
||||
if (parts.length > 2)
|
||||
{
|
||||
for (int i = 2; i < parts.length; i++)
|
||||
{
|
||||
stack.addStringEnchantment(null, allowUnsafe, parts[i]);
|
||||
metaStack.addStringEnchantment(null, allowUnsafe, parts[i]);
|
||||
}
|
||||
}
|
||||
|
||||
final Map<Integer, ItemStack> overfilled;
|
||||
if (user.isAuthorized("essentials.oversizedstacks"))
|
||||
{
|
||||
overfilled = InventoryWorkaround.addOversizedItems(user.getInventory(), ess.getSettings().getOversizedStackSize(), stack.getBase());
|
||||
overfilled = InventoryWorkaround.addOversizedItems(user.getInventory(), ess.getSettings().getOversizedStackSize(), metaStack.getItemStack());
|
||||
}
|
||||
else
|
||||
{
|
||||
overfilled = InventoryWorkaround.addItems(user.getInventory(), stack.getBase());
|
||||
overfilled = InventoryWorkaround.addItems(user.getInventory(), metaStack.getItemStack());
|
||||
}
|
||||
for (ItemStack itemStack : overfilled.values())
|
||||
{
|
||||
|
@ -9,17 +9,17 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
|
||||
|
||||
public class MetaItemStack extends ItemStack
|
||||
public class MetaItemStack
|
||||
{
|
||||
private final transient Pattern splitPattern = Pattern.compile("[:+',;.]");
|
||||
private final ItemStack stack;
|
||||
|
||||
public MetaItemStack(final ItemStack stack)
|
||||
{
|
||||
this.stack = stack;
|
||||
this.stack = stack.clone();
|
||||
}
|
||||
|
||||
public ItemStack getBase()
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
return stack;
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
public class Commandenchant extends EssentialsCommand
|
||||
@ -24,7 +25,7 @@ public class Commandenchant extends EssentialsCommand
|
||||
@Override
|
||||
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
final MetaItemStack stack = new MetaItemStack(user.getItemInHand());
|
||||
final ItemStack stack = user.getItemInHand();
|
||||
if (stack == null)
|
||||
{
|
||||
throw new Exception(_("nothingInHand"));
|
||||
@ -58,11 +59,13 @@ public class Commandenchant extends EssentialsCommand
|
||||
}
|
||||
|
||||
final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments() && user.isAuthorized("essentials.enchant.allowunsafe");
|
||||
final Enchantment enchantment = stack.getEnchantment(user, args[0]);
|
||||
stack.addEnchantment(user, allowUnsafe, enchantment, level);
|
||||
|
||||
final MetaItemStack metaStack = new MetaItemStack(stack);
|
||||
final Enchantment enchantment = metaStack.getEnchantment(user, args[0]);
|
||||
metaStack.addEnchantment(user, allowUnsafe, enchantment, level);
|
||||
|
||||
|
||||
user.getInventory().setItemInHand(stack.getBase());
|
||||
user.getInventory().setItemInHand(metaStack.getItemStack());
|
||||
user.updateInventory();
|
||||
final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH);
|
||||
if (level == 0)
|
||||
|
@ -10,6 +10,7 @@ import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
public class Commandgive extends EssentialsCommand
|
||||
@ -27,7 +28,7 @@ public class Commandgive extends EssentialsCommand
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
final MetaItemStack stack = new MetaItemStack(ess.getItemDb().get(args[1]));
|
||||
ItemStack stack = ess.getItemDb().get(args[1]);
|
||||
|
||||
final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
|
||||
if (sender instanceof Player
|
||||
@ -70,7 +71,8 @@ public class Commandgive extends EssentialsCommand
|
||||
|
||||
if (args.length > 3)
|
||||
{
|
||||
boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments();
|
||||
MetaItemStack metaStack = new MetaItemStack(stack);
|
||||
boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments();
|
||||
if (allowUnsafe && sender instanceof Player && !ess.getUser(sender).isAuthorized("essentials.enchant.allowunsafe"))
|
||||
{
|
||||
allowUnsafe = false;
|
||||
@ -78,8 +80,9 @@ public class Commandgive extends EssentialsCommand
|
||||
|
||||
for (int i = Util.isInt(args[3]) ? 4 : 3; i < args.length; i++)
|
||||
{
|
||||
stack.addStringEnchantment(null, allowUnsafe, args[i]);
|
||||
metaStack.addStringEnchantment(null, allowUnsafe, args[i]);
|
||||
}
|
||||
stack = metaStack.getItemStack();
|
||||
}
|
||||
|
||||
if (stack.getType() == Material.AIR)
|
||||
@ -91,11 +94,11 @@ public class Commandgive extends EssentialsCommand
|
||||
sender.sendMessage(_("giveSpawn", stack.getAmount(), itemName, giveTo.getDisplayName()));
|
||||
if (giveTo.isAuthorized("essentials.oversizedstacks"))
|
||||
{
|
||||
InventoryWorkaround.addOversizedItems(giveTo.getInventory(), ess.getSettings().getOversizedStackSize(), stack.getBase());
|
||||
InventoryWorkaround.addOversizedItems(giveTo.getInventory(), ess.getSettings().getOversizedStackSize(), stack);
|
||||
}
|
||||
else
|
||||
{
|
||||
InventoryWorkaround.addItems(giveTo.getInventory(), stack.getBase());
|
||||
InventoryWorkaround.addItems(giveTo.getInventory(), stack);
|
||||
}
|
||||
giveTo.updateInventory();
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
|
||||
import java.util.Locale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
public class Commanditem extends EssentialsCommand
|
||||
@ -23,7 +24,7 @@ public class Commanditem extends EssentialsCommand
|
||||
{
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
final MetaItemStack stack = new MetaItemStack(ess.getItemDb().get(args[0]));
|
||||
ItemStack stack = ess.getItemDb().get(args[0]);
|
||||
|
||||
final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
|
||||
if (ess.getSettings().permissionBasedItemSpawn()
|
||||
@ -56,12 +57,14 @@ public class Commanditem extends EssentialsCommand
|
||||
}
|
||||
if (args.length > 2)
|
||||
{
|
||||
MetaItemStack metaStack = new MetaItemStack(stack);
|
||||
final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments() && user.isAuthorized("essentials.enchant.allowunsafe");
|
||||
|
||||
for (int i = 2; i < args.length; i++)
|
||||
{
|
||||
stack.addStringEnchantment(null, allowUnsafe, args[i]);
|
||||
metaStack.addStringEnchantment(null, allowUnsafe, args[i]);
|
||||
}
|
||||
stack = metaStack.getItemStack();
|
||||
}
|
||||
|
||||
|
||||
@ -74,11 +77,11 @@ public class Commanditem extends EssentialsCommand
|
||||
user.sendMessage(_("itemSpawn", stack.getAmount(), displayName));
|
||||
if (user.isAuthorized("essentials.oversizedstacks"))
|
||||
{
|
||||
InventoryWorkaround.addOversizedItems(user.getInventory(), ess.getSettings().getOversizedStackSize(), stack.getBase());
|
||||
InventoryWorkaround.addOversizedItems(user.getInventory(), ess.getSettings().getOversizedStackSize(), stack);
|
||||
}
|
||||
else
|
||||
{
|
||||
InventoryWorkaround.addItems(user.getInventory(), stack.getBase());
|
||||
InventoryWorkaround.addItems(user.getInventory(), stack);
|
||||
}
|
||||
user.updateInventory();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user