Removed EnchantmentFix, because it's fixed in CB#1526

This commit is contained in:
snowleo 2011-11-30 19:31:21 +01:00
parent a8a9fc3dd6
commit 15d8ec6026
5 changed files with 7 additions and 91 deletions

View File

@ -1,6 +1,5 @@
package com.earth2me.essentials; package com.earth2me.essentials;
import com.earth2me.essentials.craftbukkit.EnchantmentFix;
import com.earth2me.essentials.craftbukkit.SetBed; import com.earth2me.essentials.craftbukkit.SetBed;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.textreader.IText; import com.earth2me.essentials.textreader.IText;
@ -117,7 +116,7 @@ public class EssentialsPlayerListener extends PlayerListener
} }
if (user.getSavedInventory() != null) if (user.getSavedInventory() != null)
{ {
EnchantmentFix.setContents(user.getInventory(), user.getSavedInventory()); user.getInventory().setContents(user.getSavedInventory());
user.setSavedInventory(null); user.setSavedInventory(null);
} }
user.updateActivity(false); user.updateActivity(false);

View File

@ -1,6 +1,5 @@
package com.earth2me.essentials; package com.earth2me.essentials;
import com.earth2me.essentials.craftbukkit.EnchantmentFix;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.bukkit.Location; import org.bukkit.Location;
@ -152,27 +151,13 @@ public final class InventoryWorkaround
{ {
final ItemStack stack = item.clone(); final ItemStack stack = item.clone();
stack.setAmount(maxAmount); stack.setAmount(maxAmount);
if (cinventory instanceof FakeInventory) cinventory.setItem(firstFree, stack);
{
cinventory.setItem(firstFree, stack);
}
else
{
EnchantmentFix.setItem(cinventory, firstFree, stack);
}
item.setAmount(item.getAmount() - maxAmount); item.setAmount(item.getAmount() - maxAmount);
} }
else else
{ {
// Just store it // Just store it
if (cinventory instanceof FakeInventory) cinventory.setItem(firstFree, item);
{
cinventory.setItem(firstFree, item);
}
else
{
EnchantmentFix.setItem(cinventory, firstFree, item);
}
break; break;
} }
} }
@ -251,7 +236,7 @@ public final class InventoryWorkaround
{ {
// split the stack and store // split the stack and store
itemStack.setAmount(amount - toDelete); itemStack.setAmount(amount - toDelete);
EnchantmentFix.setItem(cinventory, first, itemStack); cinventory.setItem(first, itemStack);
toDelete = 0; toDelete = 0;
} }
} }

View File

@ -2,7 +2,6 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.User; import com.earth2me.essentials.User;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import com.earth2me.essentials.craftbukkit.EnchantmentFix;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
@ -113,7 +112,7 @@ public class Commandenchant extends EssentialsCommand
} else { } else {
stack.addEnchantment(enchantment, level); stack.addEnchantment(enchantment, level);
} }
EnchantmentFix.setItemInHand(user.getInventory(), stack); user.getInventory().setItemInHand(stack);
user.updateInventory(); user.updateInventory();
final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH); final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH);
if (level == 0) { if (level == 0) {

View File

@ -2,7 +2,6 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User; import com.earth2me.essentials.User;
import com.earth2me.essentials.craftbukkit.EnchantmentFix;
import java.util.Arrays; import java.util.Arrays;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -30,7 +29,7 @@ public class Commandinvsee extends EssentialsCommand
} }
if (invUser == user && user.getSavedInventory() != null) if (invUser == user && user.getSavedInventory() != null)
{ {
EnchantmentFix.setContents(invUser.getInventory(), user.getSavedInventory()); invUser.getInventory().setContents(user.getSavedInventory());
user.setSavedInventory(null); user.setSavedInventory(null);
user.sendMessage(_("invRestored")); user.sendMessage(_("invRestored"));
throw new NoChargeException(); throw new NoChargeException();
@ -50,7 +49,7 @@ public class Commandinvsee extends EssentialsCommand
{ {
throw new Exception(_("invBigger")); throw new Exception(_("invBigger"));
} }
EnchantmentFix.setContents(user.getInventory(), invUserStack); user.getInventory().setContents(invUserStack);
user.sendMessage(_("invSee", invUser.getDisplayName())); user.sendMessage(_("invSee", invUser.getDisplayName()));
user.sendMessage(_("invSeeHelp")); user.sendMessage(_("invSeeHelp"));
throw new NoChargeException(); throw new NoChargeException();

View File

@ -1,66 +0,0 @@
package com.earth2me.essentials.craftbukkit;
import org.bukkit.craftbukkit.inventory.CraftInventory;
import org.bukkit.craftbukkit.inventory.CraftInventoryPlayer;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
public class EnchantmentFix
{
public static void setContents(Inventory inventory, ItemStack[] items)
{
CraftInventory cInventory = (CraftInventory)inventory;
if (cInventory.getContents().length != items.length)
{
throw new IllegalArgumentException("Invalid inventory size; expected " + cInventory.getContents().length);
}
net.minecraft.server.ItemStack[] mcItems = cInventory.getInventory().getContents();
for (int i = 0; i < items.length; i++)
{
ItemStack item = items[i];
if (item == null || item.getTypeId() <= 0)
{
mcItems[i] = null;
}
else
{
mcItems[i] = new net.minecraft.server.ItemStack(item.getTypeId(), item.getAmount(), item.getDurability());
new CraftItemStack(mcItems[i]).addUnsafeEnchantments(item.getEnchantments());
}
}
}
public static void setItem(Inventory inventory, int index, ItemStack item)
{
CraftInventory cInventory = (CraftInventory)inventory;
if (item == null)
{
cInventory.getInventory().setItem(index, null);
}
else
{
net.minecraft.server.ItemStack stack = new net.minecraft.server.ItemStack(item.getTypeId(), item.getAmount(), item.getDurability());
new CraftItemStack(stack).addUnsafeEnchantments(item.getEnchantments());
cInventory.getInventory().setItem(index, stack);
}
}
public static void setItemInHand(Inventory inventory, ItemStack item)
{
CraftInventoryPlayer cInventory = (CraftInventoryPlayer)inventory;
if (item == null)
{
cInventory.getInventory().setItem(cInventory.getInventory().itemInHandIndex, null);
}
else
{
net.minecraft.server.ItemStack stack = new net.minecraft.server.ItemStack(item.getTypeId(), item.getAmount(), item.getDurability());
new CraftItemStack(stack).addUnsafeEnchantments(item.getEnchantments());
cInventory.getInventory().setItem(cInventory.getInventory().itemInHandIndex, stack);
}
}
}