mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-18 14:11:40 +01:00
[trunk] Replace all CraftInventory with Inventory
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1154 e251c2fe-e539-e718-e476-b85c1f46cddb
This commit is contained in:
parent
9a17f38448
commit
395530bfd4
@ -3,7 +3,6 @@ package com.earth2me.essentials;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.craftbukkit.block.CraftSign;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockListener;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
@ -142,8 +141,8 @@ public class EssentialsEcoBlockListener extends BlockListener
|
||||
else
|
||||
{
|
||||
ItemStack i2 = ItemDb.get(l2[1], r2);
|
||||
if (!InventoryWorkaround.containsItem((CraftInventory)user.getInventory(), true, i2)) throw new Exception("You do not have " + r2 + "x " + l2[1] + ".");
|
||||
InventoryWorkaround.removeItem((CraftInventory)user.getInventory(), true, i2);
|
||||
if (!InventoryWorkaround.containsItem(user.getInventory(), true, i2)) throw new Exception("You do not have " + r2 + "x " + l2[1] + ".");
|
||||
InventoryWorkaround.removeItem(user.getInventory(), true, i2);
|
||||
user.updateInventory();
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,6 @@ import java.util.Map;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.craftbukkit.block.CraftSign;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerListener;
|
||||
@ -54,9 +53,9 @@ public class EssentialsEcoPlayerListener extends PlayerListener
|
||||
int amount = Integer.parseInt(sign.getLine(1));
|
||||
ItemStack item = ItemDb.get(sign.getLine(2), amount);
|
||||
int cost = Integer.parseInt(sign.getLine(3).substring(1));
|
||||
if (!InventoryWorkaround.containsItem((CraftInventory)user.getInventory(), true, item)) throw new Exception("You do not have enough items to sell.");
|
||||
if (!InventoryWorkaround.containsItem(user.getInventory(), true, item)) throw new Exception("You do not have enough items to sell.");
|
||||
user.giveMoney(cost);
|
||||
InventoryWorkaround.removeItem((CraftInventory)user.getInventory(), true, item);
|
||||
InventoryWorkaround.removeItem(user.getInventory(), true, item);
|
||||
user.updateInventory();
|
||||
}
|
||||
catch (Throwable ex)
|
||||
@ -109,7 +108,7 @@ public class EssentialsEcoPlayerListener extends PlayerListener
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!InventoryWorkaround.containsItem((CraftInventory)user.getInventory(), true, qi1))
|
||||
if (!InventoryWorkaround.containsItem(user.getInventory(), true, qi1))
|
||||
throw new Exception("You do not have " + q1 + "x " + l1[1] + ".");
|
||||
}
|
||||
|
||||
@ -118,7 +117,7 @@ public class EssentialsEcoPlayerListener extends PlayerListener
|
||||
if (m1)
|
||||
user.takeMoney(q1);
|
||||
else
|
||||
InventoryWorkaround.removeItem((CraftInventory)user.getInventory(), true, qi1);
|
||||
InventoryWorkaround.removeItem(user.getInventory(), true, qi1);
|
||||
|
||||
if (m2)
|
||||
user.giveMoney(q2);
|
||||
|
@ -1,14 +1,12 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import net.minecraft.server.InventoryPlayer;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.craftbukkit.block.CraftSign;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventoryPlayer;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.*;
|
||||
@ -315,10 +313,10 @@ public class EssentialsPlayerListener extends PlayerListener
|
||||
else
|
||||
{
|
||||
ItemStack i = ItemDb.get(l1[1], q1);
|
||||
if (!InventoryWorkaround.containsItem((CraftInventory)user.getInventory(), true, i)) {
|
||||
if (!InventoryWorkaround.containsItem(user.getInventory(), true, i)) {
|
||||
throw new Exception("You do not have " + q1 + "x " + l1[1] + ".");
|
||||
}
|
||||
InventoryWorkaround.removeItem((CraftInventory)user.getInventory(), true, i);
|
||||
InventoryWorkaround.removeItem(user.getInventory(), true, i);
|
||||
user.updateInventory();
|
||||
}
|
||||
}
|
||||
@ -363,10 +361,10 @@ public class EssentialsPlayerListener extends PlayerListener
|
||||
else
|
||||
{
|
||||
ItemStack i = ItemDb.get(l1[1], q1);
|
||||
if (!InventoryWorkaround.containsItem((CraftInventory)user.getInventory(), true, i)) {
|
||||
if (!InventoryWorkaround.containsItem(user.getInventory(), true, i)) {
|
||||
throw new Exception("You do not have " + q1 + "x " + l1[1] + ".");
|
||||
}
|
||||
InventoryWorkaround.removeItem((CraftInventory)user.getInventory(), true, i);
|
||||
InventoryWorkaround.removeItem(user.getInventory(), true, i);
|
||||
user.updateInventory();
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import java.util.HashMap;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/*
|
||||
@ -12,11 +11,11 @@ import org.bukkit.inventory.ItemStack;
|
||||
*/
|
||||
public class InventoryWorkaround {
|
||||
|
||||
public static int first(CraftInventory ci, ItemStack item, boolean forceDurability, boolean forceAmount) {
|
||||
public static int first(Inventory ci, ItemStack item, boolean forceDurability, boolean forceAmount) {
|
||||
return next(ci, item, 0, forceDurability, forceAmount);
|
||||
}
|
||||
|
||||
public static int next(CraftInventory ci, ItemStack item, int start, boolean forceDurability, boolean forceAmount) {
|
||||
public static int next(Inventory ci, ItemStack item, int start, boolean forceDurability, boolean forceAmount) {
|
||||
ItemStack[] inventory = ci.getContents();
|
||||
for (int i = start; i < inventory.length; i++) {
|
||||
ItemStack cItem = inventory[i];
|
||||
@ -27,7 +26,7 @@ public class InventoryWorkaround {
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static HashMap<Integer, ItemStack> removeItem(CraftInventory ci, boolean forceDurability, ItemStack... items) {
|
||||
public static HashMap<Integer, ItemStack> removeItem(Inventory ci, boolean forceDurability, ItemStack... items) {
|
||||
HashMap<Integer, ItemStack> leftover = new HashMap<Integer, ItemStack>();
|
||||
|
||||
// TODO: optimization
|
||||
@ -74,7 +73,7 @@ public class InventoryWorkaround {
|
||||
return leftover;
|
||||
}
|
||||
|
||||
public static boolean containsItem(CraftInventory ci, boolean forceDurability, ItemStack... items) {
|
||||
public static boolean containsItem(Inventory ci, boolean forceDurability, ItemStack... items) {
|
||||
HashMap<Integer, ItemStack> leftover = new HashMap<Integer, ItemStack>();
|
||||
|
||||
// TODO: optimization
|
||||
|
@ -3,7 +3,6 @@ package com.earth2me.essentials.commands;
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
|
||||
public class Commandinvsee extends EssentialsCommand {
|
||||
|
||||
@ -22,7 +21,7 @@ public class Commandinvsee extends EssentialsCommand {
|
||||
invUser = getPlayer(server, args, 0);
|
||||
}
|
||||
if (invUser == user && user.savedInventory != null) {
|
||||
((CraftInventory)invUser.getInventory()).setContents(user.savedInventory);
|
||||
invUser.getInventory().setContents(user.savedInventory);
|
||||
user.savedInventory = null;
|
||||
user.sendMessage("Your inventory has been restored.");
|
||||
return;
|
||||
@ -32,7 +31,7 @@ public class Commandinvsee extends EssentialsCommand {
|
||||
if (user.savedInventory == null) {
|
||||
user.savedInventory = user.getInventory().getContents();
|
||||
}
|
||||
((CraftInventory)user.getInventory()).setContents(((CraftInventory)invUser.getInventory()).getContents());
|
||||
user.getInventory().setContents(invUser.getInventory().getContents());
|
||||
user.sendMessage("You see the inventory of "+invUser.getDisplayName()+".");
|
||||
user.sendMessage("Use /invsee to restore your inventory.");
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import java.util.List;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class Commandunlimited extends EssentialsCommand
|
||||
@ -79,7 +78,7 @@ public class Commandunlimited extends EssentialsCommand
|
||||
user.sendMessage("§7Giving unlimited amount of " + itemname + " to " + target.getDisplayName() + ".");
|
||||
}
|
||||
target.sendMessage("§7Giving unlimited amount of " + itemname + " to " + target.getDisplayName() + ".");
|
||||
if (!InventoryWorkaround.containsItem((CraftInventory)target.getInventory(), true, stack)) {
|
||||
if (!InventoryWorkaround.containsItem(target.getInventory(), true, stack)) {
|
||||
target.getInventory().addItem(stack);
|
||||
}
|
||||
target.setUnlimited(stack, true);
|
||||
|
Loading…
Reference in New Issue
Block a user