Players cannot unload Item Cubes into others' shops.

This commit is contained in:
sigonasr2 2016-07-08 17:59:54 -05:00
parent 7cecc25c05
commit 6cc89d3426
4 changed files with 78 additions and 58 deletions

Binary file not shown.

View File

@ -523,7 +523,8 @@ public class WorldShop {
public static boolean isPurchaseShopSign(Sign s) { public static boolean isPurchaseShopSign(Sign s) {
if (isWorldShopSign(s) && if (isWorldShopSign(s) &&
s.getLine(0).equalsIgnoreCase(ChatColor.BLUE+"- BUYING SHOP -") || s.getLine(0).equalsIgnoreCase(ChatColor.BLUE+"- BUYING SHOP -") ||
s.getLine(0).equalsIgnoreCase(ChatColor.YELLOW+""+ChatColor.BOLD+"-BUYING SHOP-")) { s.getLine(0).equalsIgnoreCase(ChatColor.YELLOW+""+ChatColor.BOLD+"-BUYING SHOP-") ||
s.getLine(0).equalsIgnoreCase(ChatColor.GREEN+""+ChatColor.BOLD+"-BUYING SHOP-")) {
return true; return true;
} else { } else {
return false; return false;
@ -533,7 +534,8 @@ public class WorldShop {
public static boolean isWorldShopSign(Sign s) { public static boolean isWorldShopSign(Sign s) {
if (s.getLine(0).equalsIgnoreCase(ChatColor.BLUE+"-- SHOP --") || if (s.getLine(0).equalsIgnoreCase(ChatColor.BLUE+"-- SHOP --") ||
s.getLine(0).equalsIgnoreCase(ChatColor.BLUE+"- BUYING SHOP -") || s.getLine(0).equalsIgnoreCase(ChatColor.BLUE+"- BUYING SHOP -") ||
s.getLine(0).equalsIgnoreCase(ChatColor.YELLOW+""+ChatColor.BOLD+"-BUYING SHOP-")) { s.getLine(0).equalsIgnoreCase(ChatColor.YELLOW+""+ChatColor.BOLD+"-BUYING SHOP-") ||
s.getLine(0).equalsIgnoreCase(ChatColor.GREEN+""+ChatColor.BOLD+"-BUYING SHOP-")) {
return true; return true;
} else { } else {
return false; return false;

View File

@ -1662,67 +1662,83 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} }
//Now that we have the item cube. Dump whatever contents we can into the container. //Now that we have the item cube. Dump whatever contents we can into the container.
//Get the inventory of the chest we are inserting into. //We need to make sure the chest is not a world shop. If it is, we can see if we're the owner of it.
Chest c = (Chest)ev.getClickedBlock().getState(); boolean allowed=true;
Inventory chest_inventory = c.getBlockInventory(); String owner="";
if (c.getInventory().getHolder() instanceof DoubleChest) { if (WorldShop.hasShopSignAttached(ev.getClickedBlock())) {
chest_inventory = ((DoubleChest)c.getInventory().getHolder()).getInventory(); WorldShop s = TwosideShops.LoadWorldShopData(WorldShop.grabShopSign(ev.getClickedBlock().getLocation()));
if (!s.GetOwner().equalsIgnoreCase(ev.getPlayer().getName())) {
log("This is a double chest",5); allowed=false;
owner=s.GetOwner();
}
} }
//Get the inventory we are dumping out. if (allowed) {
Inventory virtualinventory = ItemCube.getViewingItemCubeInventory(itemcube_id, ev.getPlayer()); //Get the inventory of the chest we are inserting into.
if (virtualinventory==null) { Chest c = (Chest)ev.getClickedBlock().getState();
//Then we will make one. Inventory chest_inventory = c.getBlockInventory();
virtualinventory = Bukkit.createInventory(ev.getPlayer(), size); if (c.getInventory().getHolder() instanceof DoubleChest) {
//Load up this inventory. chest_inventory = ((DoubleChest)c.getInventory().getHolder()).getInventory();
List<ItemStack> items = itemCube_loadConfig(itemcube_id);
log("This is a double chest",5);
}
//Get the inventory we are dumping out.
Inventory virtualinventory = ItemCube.getViewingItemCubeInventory(itemcube_id, ev.getPlayer());
if (virtualinventory==null) {
//Then we will make one.
virtualinventory = Bukkit.createInventory(ev.getPlayer(), size);
//Load up this inventory.
List<ItemStack> items = itemCube_loadConfig(itemcube_id);
for (int i=0;i<virtualinventory.getSize();i++) {
if (items.get(i)!=null) {
virtualinventory.setItem(i, items.get(i));
log("Load up with "+items.get(i).toString(),5);
}
}
}
List<ItemStack> save_items = new ArrayList<ItemStack>();
for (int i=0;i<size;i++) {
save_items.add(new ItemStack(Material.AIR));
}
boolean fit=true;
int count=0;
//Now that we have our items. Dump what we can into the chest inventory.
for (int i=0;i<virtualinventory.getSize();i++) { for (int i=0;i<virtualinventory.getSize();i++) {
if (items.get(i)!=null) { if (virtualinventory.getItem(i)!=null &&
virtualinventory.setItem(i, items.get(i)); virtualinventory.getItem(i).getType()!=Material.AIR) {
log("Load up with "+items.get(i).toString(),5); HashMap result = chest_inventory.addItem(virtualinventory.getItem(i));
if (result.size()>0) {
save_items.set(i,(ItemStack)result.get(0));
fit=false;
log("This item "+(ItemStack)result.get(0)+" (slot "+i+") could not fit!",4);
} else {
count++;
}
} }
} }
}
List<ItemStack> save_items = new ArrayList<ItemStack>(); //The rest of the hashmap goes back in the original inventory.
if (!fit) {
for (int i=0;i<size;i++) { ev.getPlayer().sendMessage(ChatColor.RED+"Attempted to store your items, not all of them could fit!"+ChatColor.WHITE+" Stored "+ChatColor.AQUA+count+ChatColor.WHITE+" items.");
save_items.add(new ItemStack(Material.AIR)); } else {
} if (count>0) {
ev.getPlayer().sendMessage("Stored "+ChatColor.AQUA+count+ChatColor.WHITE+" items inside the chest.");
boolean fit=true;
int count=0;
//Now that we have our items. Dump what we can into the chest inventory.
for (int i=0;i<virtualinventory.getSize();i++) {
if (virtualinventory.getItem(i)!=null &&
virtualinventory.getItem(i).getType()!=Material.AIR) {
HashMap result = chest_inventory.addItem(virtualinventory.getItem(i));
if (result.size()>0) {
save_items.set(i,(ItemStack)result.get(0));
fit=false;
log("This item "+(ItemStack)result.get(0)+" (slot "+i+") could not fit!",4);
} else {
count++;
} }
} }
} virtualinventory.clear();
//The rest of the hashmap goes back in the original inventory.
if (!fit) { //Save the Item Cube.
ev.getPlayer().sendMessage(ChatColor.RED+"Attempted to store your items, not all of them could fit!"+ChatColor.WHITE+" Stored "+ChatColor.AQUA+count+ChatColor.WHITE+" items."); itemCube_saveConfig(itemcube_id,save_items);
//This may have been a shop. Update the shop too.
WorldShop.updateShopSign(ev.getClickedBlock().getLocation());
} else { } else {
if (count>0) { ev.getPlayer().sendMessage("This shop is owned by "+ChatColor.LIGHT_PURPLE+owner+ChatColor.WHITE+". You cannot dump item cubes into others' shops!");
ev.getPlayer().sendMessage("Stored "+ChatColor.AQUA+count+ChatColor.WHITE+" items inside the chest."); //ev.setCancelled(true);
}
} }
virtualinventory.clear();
//Save the Item Cube.
itemCube_saveConfig(itemcube_id,save_items);
//This may have been a shop. Update the shop too.
WorldShop.updateShopSign(ev.getClickedBlock().getLocation());
} }
} }
if (b!=null && (b.getType() == Material.SIGN || if (b!=null && (b.getType() == Material.SIGN ||
@ -1860,7 +1876,8 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} }
} else } else
if (s.getLine(0).equalsIgnoreCase(ChatColor.BLUE+"- BUYING SHOP -") || if (s.getLine(0).equalsIgnoreCase(ChatColor.BLUE+"- BUYING SHOP -") ||
s.getLine(0).equalsIgnoreCase(ChatColor.YELLOW+""+ChatColor.BOLD+"-BUYING SHOP-")) { s.getLine(0).equalsIgnoreCase(ChatColor.YELLOW+""+ChatColor.BOLD+"-BUYING SHOP-") ||
s.getLine(0).equalsIgnoreCase(ChatColor.GREEN+""+ChatColor.BOLD+"-BUYING SHOP-")) {
//This is a buy shop. //This is a buy shop.
int shopID = TwosideShops.GetShopID(s); int shopID = TwosideShops.GetShopID(s);
WorldShop shop = TwosideShops.LoadWorldShopData(shopID); WorldShop shop = TwosideShops.LoadWorldShopData(shopID);
@ -3654,7 +3671,8 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} }
} else } else
if (s.getLine(0).equalsIgnoreCase(ChatColor.BLUE+"- BUYING SHOP -") || if (s.getLine(0).equalsIgnoreCase(ChatColor.BLUE+"- BUYING SHOP -") ||
s.getLine(0).equalsIgnoreCase(ChatColor.YELLOW+""+ChatColor.BOLD+"-BUYING SHOP-")) { s.getLine(0).equalsIgnoreCase(ChatColor.YELLOW+""+ChatColor.BOLD+"-BUYING SHOP-") ||
s.getLine(0).equalsIgnoreCase(ChatColor.GREEN+""+ChatColor.BOLD+"-BUYING SHOP-")) {
//This is a shop. Let's find out who the owner is. //This is a shop. Let's find out who the owner is.
int shopID = TwosideShops.GetShopID(s); int shopID = TwosideShops.GetShopID(s);
WorldShop shop = TwosideShops.LoadWorldShopData(shopID); WorldShop shop = TwosideShops.LoadWorldShopData(shopID);

View File

@ -66,7 +66,7 @@ public class WorldShopManager {
//Create a shop out of this. //Create a shop out of this.
if (purchaseshop) { if (purchaseshop) {
if (shop.GetStoredAmount()>0) { if (shop.GetStoredAmount()>0) {
sign_lines.add(ChatColor.YELLOW+""+ChatColor.BOLD+"-BUYING SHOP-"); sign_lines.add(ChatColor.GREEN+""+ChatColor.BOLD+"-BUYING SHOP-");
} else { } else {
sign_lines.add(ChatColor.BLUE+"- BUYING SHOP -"); sign_lines.add(ChatColor.BLUE+"- BUYING SHOP -");
} }
@ -96,7 +96,7 @@ public class WorldShopManager {
//Create a shop out of this. //Create a shop out of this.
if (purchaseshop) { if (purchaseshop) {
if (shop.GetStoredAmount()>0) { if (shop.GetStoredAmount()>0) {
sign_lines.add(ChatColor.YELLOW+""+ChatColor.BOLD+"-BUYING SHOP-"); sign_lines.add(ChatColor.GREEN+""+ChatColor.BOLD+"-BUYING SHOP-");
} else { } else {
sign_lines.add(ChatColor.BLUE+"- BUYING SHOP -"); sign_lines.add(ChatColor.BLUE+"- BUYING SHOP -");
} }