diff --git a/TwosideKeeper.jar b/TwosideKeeper.jar index 381b000..2f1fd99 100644 Binary files a/TwosideKeeper.jar and b/TwosideKeeper.jar differ diff --git a/src/plugin.yml b/src/plugin.yml index 0ca1fad..d53122d 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: TwosideKeeper main: sig.plugin.TwosideKeeper.TwosideKeeper -version: 3.4.4r1 +version: 3.4.4r2 commands: money: description: Tells the player the amount of money they are holding. @@ -66,4 +66,9 @@ commands: description: Does many things depending on what item is being held. Typically if it's broken, typing this will help. usage: /fix permission: TwosideKeeper.fix + permission-message: No permissions! + tp_world: + description: Teleports to a location in a specified world. + usage: /tp_world + permission: TwosideKeeper.tp_world permission-message: No permissions! \ No newline at end of file diff --git a/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java b/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java index e914c29..fe0ae92 100644 --- a/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java +++ b/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java @@ -16,6 +16,7 @@ import org.bukkit.entity.Monster; import org.bukkit.entity.Player; import org.bukkit.entity.Skeleton; import org.bukkit.entity.Skeleton.SkeletonType; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.PotionMeta; @@ -1383,4 +1384,71 @@ public class GenericFunctions { return true; } } + + public static boolean isDumpableContainer(Material mat) { + if (mat==Material.CHEST || + mat==Material.TRAPPED_CHEST) { + return true; + } + return false; + } + + public static ItemStack moveItemStack(ItemStack item, Inventory target) { + //First see if there are any incomplete stacks in the target inventory. + if (item!=null && + item.getType()!=Material.AIR) { + for (int i=0;i0) { - player.sendMessage("How many "+ChatColor.GREEN+shop.GetItemName()+ChatColor.WHITE+" would you like to buy? "+ChatColor.GREEN+"(MAX: "+((getPlayerMoney(player)<(shop.GetAmount()*shop.GetUnitPrice()))?(int)(getPlayerMoney(player)/shop.GetUnitPrice()):shop.GetAmount())+")"); - - //Initiate buying session. - TwosideShops.AddSession(SessionState.PURCHASE, player, s); - log("Added a shop session for "+player.getName()+".",4); - shop.sendItemInfo(player); + //Make sure it is on a chest. Or trapped chest. + org.bukkit.material.Sign s1 = (org.bukkit.material.Sign)(b.getState().getData()); + Block chest = b.getRelative(s1.getAttachedFace()); + if (chest.getType()==Material.CHEST || + chest.getType()==Material.TRAPPED_CHEST) { + if (s.getLine(0).equalsIgnoreCase("shop")) { + log("This is a shop sign.",5); + //Create a new shop. + ItemStack item = player.getEquipment().getItemInMainHand(); + if (item.getType()!=Material.AIR) { + WorldShopSession ss = TwosideShops.AddSession(SessionState.CREATE, player, s); + player.sendMessage("Creating a shop to sell "+ChatColor.GREEN+GenericFunctions.GetItemName(item)+ChatColor.WHITE+"."); + int totalcount = 0; + totalcount = GenericFunctions.CountItems(player, item); + log("We have "+totalcount+" items in our inventory.",4); + ss.SetItem(item); + player.sendMessage("How many of this item do you want to sell? "+ChatColor.GREEN+"(MAX: "+ChatColor.YELLOW+totalcount+ChatColor.GREEN+")"); + } else { + player.sendMessage(ChatColor.RED+"Cannot create a shop with nothing! "+ChatColor.WHITE+"Right-click the sign" + + " with the item you want to sell in your hand."); + } + } else + if (s.getLine(0).equalsIgnoreCase(ChatColor.BLUE+"-- SHOP --")) { + log("This is a buy shop sign.",5); + int shopID = TwosideShops.GetShopID(s); + WorldShop shop = TwosideShops.LoadWorldShopData(shopID); + + Location newloc = ev.getClickedBlock().getLocation().add(-ev.getBlockFace().getModX()+0.5, -ev.getBlockFace().getModY()+1.5, -ev.getBlockFace().getModZ()+0.5); + + WorldShop.spawnShopItem(ev,newloc,shop); + + if (shop.GetOwner().equalsIgnoreCase(ev.getPlayer().getName())) { + player.sendMessage(ChatColor.DARK_PURPLE+"Editing shop..."); + player.sendMessage("Insert more "+ChatColor.GREEN+shop.GetItemName()+ChatColor.WHITE+" by typing a positive amount "+ChatColor.GREEN+"(MAX:"+GenericFunctions.CountItems(player,shop.GetItem())+")"+ChatColor.WHITE+". Or withdraw "+ChatColor.GREEN+shop.GetItemName()+ChatColor.WHITE+" by typing a negative amount "+ChatColor.GREEN+"(MAX:"+shop.GetAmount()+")"+ChatColor.WHITE+"."); + TwosideShops.AddSession(SessionState.EDIT, player, s); } else { - player.sendMessage(ChatColor.GOLD+"Sorry! "+ChatColor.WHITE+"This shop is sold out! Let "+ChatColor.LIGHT_PURPLE+shop.GetOwner()+ChatColor.WHITE+" know to restock the shop!"); + if (shop.GetAmount()>0) { + player.sendMessage("How many "+ChatColor.GREEN+shop.GetItemName()+ChatColor.WHITE+" would you like to buy? "+ChatColor.GREEN+"(MAX: "+((getPlayerMoney(player)<(shop.GetAmount()*shop.GetUnitPrice()))?(int)(getPlayerMoney(player)/shop.GetUnitPrice()):shop.GetAmount())+")"); + + //Initiate buying session. + TwosideShops.AddSession(SessionState.PURCHASE, player, s); + log("Added a shop session for "+player.getName()+".",4); + shop.sendItemInfo(player); + } else { + player.sendMessage(ChatColor.GOLD+"Sorry! "+ChatColor.WHITE+"This shop is sold out! Let "+ChatColor.LIGHT_PURPLE+shop.GetOwner()+ChatColor.WHITE+" know to restock the shop!"); + } } - } - } else - if (s.getLine(0).equalsIgnoreCase("buyshop")) { - //Create a new buy shop. - ItemStack item = player.getEquipment().getItemInMainHand(); - if (item.getType()!=Material.AIR) { - WorldShopSession ss = TwosideShops.AddSession(SessionState.BUY_CREATE, player, s); - player.sendMessage("Creating a shop to buy "+ChatColor.GREEN+GenericFunctions.GetItemName(item)+ChatColor.WHITE+"."); - int totalcount = 0; - totalcount = GenericFunctions.CountItems(player, item); - ss.SetItem(item); - player.sendMessage("How many of this item do you want to buy?"); - } else { - player.sendMessage(ChatColor.RED+"Cannot create a shop with nothing! "+ChatColor.WHITE+"Right-click the sign" - + " with the item you want to buy in your hand."); - } - } else - if (s.getLine(0).equalsIgnoreCase(ChatColor.BLUE+"- BUYING SHOP -") || - s.getLine(0).equalsIgnoreCase(ChatColor.YELLOW+""+ChatColor.BOLD+"-BUYING SHOP-")) { - //This is a buy shop. - int shopID = TwosideShops.GetShopID(s); - WorldShop shop = TwosideShops.LoadWorldShopData(shopID); - Location newloc = ev.getClickedBlock().getLocation().add(-ev.getBlockFace().getModX()+0.5, -ev.getBlockFace().getModY()+1.5, -ev.getBlockFace().getModZ()+0.5); - WorldShop.spawnShopItem(ev,newloc,shop); - - - if (shop.GetOwner().equalsIgnoreCase(ev.getPlayer().getName())) { - player.sendMessage(ChatColor.DARK_PURPLE+"Editing shop..."); - player.sendMessage("Request more "+ChatColor.GREEN+shop.GetItemName()+ChatColor.WHITE+" by typing a positive amount "+ChatColor.WHITE+". Or withdraw stored "+ChatColor.GREEN+shop.GetItemName()+ChatColor.WHITE+" by typing a negative amount "+ChatColor.GREEN+"(MAX:"+shop.GetStoredAmount()+")"+ChatColor.WHITE+"."); - TwosideShops.AddSession(SessionState.BUY_EDIT, player, s); - } else { - if (shop.GetAmount()>0) { - player.sendMessage("How many "+ChatColor.GREEN+shop.GetItemName()+ChatColor.WHITE+" would you like to sell? "+ChatColor.GREEN+"(MAX: "+(shop.GetUnitPrice()*GenericFunctions.CountItems(player, shop.GetItem())<=getPlayerBankMoney(shop.GetOwner())?((GenericFunctions.CountItems(player, shop.GetItem())<=shop.GetAmount())?(GenericFunctions.CountItems(player, shop.GetItem())):shop.GetAmount()):(int)(getPlayerBankMoney(shop.GetOwner())/shop.GetUnitPrice()))+")"); - - //Initiate buying session. - TwosideShops.AddSession(SessionState.SELL, player, s); - log("Added a shop session for "+player.getName()+".",4); - shop.sendItemInfo(player); + } else + if (s.getLine(0).equalsIgnoreCase("buyshop")) { + //Create a new buy shop. + ItemStack item = player.getEquipment().getItemInMainHand(); + if (item.getType()!=Material.AIR) { + WorldShopSession ss = TwosideShops.AddSession(SessionState.BUY_CREATE, player, s); + player.sendMessage("Creating a shop to buy "+ChatColor.GREEN+GenericFunctions.GetItemName(item)+ChatColor.WHITE+"."); + int totalcount = 0; + totalcount = GenericFunctions.CountItems(player, item); + ss.SetItem(item); + player.sendMessage("How many of this item do you want to buy?"); + } else { + player.sendMessage(ChatColor.RED+"Cannot create a shop with nothing! "+ChatColor.WHITE+"Right-click the sign" + + " with the item you want to buy in your hand."); + } + } else + if (s.getLine(0).equalsIgnoreCase(ChatColor.BLUE+"- BUYING SHOP -") || + s.getLine(0).equalsIgnoreCase(ChatColor.YELLOW+""+ChatColor.BOLD+"-BUYING SHOP-")) { + //This is a buy shop. + int shopID = TwosideShops.GetShopID(s); + WorldShop shop = TwosideShops.LoadWorldShopData(shopID); + Location newloc = ev.getClickedBlock().getLocation().add(-ev.getBlockFace().getModX()+0.5, -ev.getBlockFace().getModY()+1.5, -ev.getBlockFace().getModZ()+0.5); + WorldShop.spawnShopItem(ev,newloc,shop); + + + if (shop.GetOwner().equalsIgnoreCase(ev.getPlayer().getName())) { + player.sendMessage(ChatColor.DARK_PURPLE+"Editing shop..."); + player.sendMessage("Request more "+ChatColor.GREEN+shop.GetItemName()+ChatColor.WHITE+" by typing a positive amount "+ChatColor.WHITE+". Or withdraw stored "+ChatColor.GREEN+shop.GetItemName()+ChatColor.WHITE+" by typing a negative amount "+ChatColor.GREEN+"(MAX:"+shop.GetStoredAmount()+")"+ChatColor.WHITE+"."); + TwosideShops.AddSession(SessionState.BUY_EDIT, player, s); } else { - player.sendMessage(ChatColor.GOLD+"Sorry! "+ChatColor.WHITE+"This shop is not buying anymore items! "+ChatColor.LIGHT_PURPLE+shop.GetOwner()+ChatColor.WHITE+" needs to edit the shop!"); + if (shop.GetAmount()>0) { + player.sendMessage("How many "+ChatColor.GREEN+shop.GetItemName()+ChatColor.WHITE+" would you like to sell? "+ChatColor.GREEN+"(MAX: "+(shop.GetUnitPrice()*GenericFunctions.CountItems(player, shop.GetItem())<=getPlayerBankMoney(shop.GetOwner())?((GenericFunctions.CountItems(player, shop.GetItem())<=shop.GetAmount())?(GenericFunctions.CountItems(player, shop.GetItem())):shop.GetAmount()):(int)(getPlayerBankMoney(shop.GetOwner())/shop.GetUnitPrice()))+")"); + + //Initiate buying session. + TwosideShops.AddSession(SessionState.SELL, player, s); + log("Added a shop session for "+player.getName()+".",4); + shop.sendItemInfo(player); + } else { + player.sendMessage(ChatColor.GOLD+"Sorry! "+ChatColor.WHITE+"This shop is not buying anymore items! "+ChatColor.LIGHT_PURPLE+shop.GetOwner()+ChatColor.WHITE+" needs to edit the shop!"); + } } - } + } } } //Determine if this is a bank sign. @@ -1828,12 +1870,13 @@ public class TwosideKeeper extends JavaPlugin implements Listener { } } } - } + } @EventHandler(priority=EventPriority.LOW) public void onInventoryClose(InventoryCloseEvent ev) { if (ev.getPlayer() instanceof Player) { Player p = (Player)ev.getPlayer(); + //log("Location of inventory: "+ev.getInventory().getLocation().toString(),2); if (DeathManager.deathStructureExists(p) && ev.getInventory().getTitle().contains("Death Loot")) { Location deathloc = DeathManager.getDeathStructure(p).deathloc; //Whatever is left drops at the death location. @@ -2199,7 +2242,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { CubeType cubetype = CubeType.NORMAL; //This is an Item Cube. ev.setCancelled(true); - ev.setResult(Result.DENY); + //ev.setResult(Result.DENY); int size; if (ev.getCurrentItem().getType()==Material.CHEST) { @@ -2214,6 +2257,20 @@ public class TwosideKeeper extends JavaPlugin implements Listener { } } + + int clicked_size; + if (ev.getCurrentItem().getType()==Material.CHEST) { + clicked_size=9; + cubetype=CubeType.NORMAL; + } else { + clicked_size=27; + if (ev.getCurrentItem().getType()==Material.STORAGE_MINECART) { + cubetype=CubeType.LARGE; + } else { + cubetype=CubeType.ENDER; + } + } + //See if we're looking at an Item Cube inventory already. if (((PlayerStructure)playerdata.get(ev.getWhoClicked().getUniqueId())).isViewingItemCube && ev.getInventory().getTitle().contains("Item Cube")) { //Check to see what the Item Cube ID is. @@ -2253,234 +2310,54 @@ public class TwosideKeeper extends JavaPlugin implements Listener { } else //Make sure we are not already inside the cube we're placing into. - if (!ItemCube.isSomeoneViewingItemCube(idnumb,(Player)ev.getWhoClicked())) { - if (idnumb!=itemcubeid) { - log(idnumb+" does not match "+itemcubeid,5); - //Try to insert item inside this item cube. - List virtual_inventory = itemCube_loadConfig(idnumb); - boolean stack_available=false; - //Now we will see if there are any places to stack blocks on. - int quantity=ev.getCursor().getAmount(); - log("Amount held: "+quantity,5); - for (int i=0;ivirtual_inventory.get(i).getAmount()) { - log("Entered Loop",5); - //This is the same, and we have room to throw some in. - int space=virtual_inventory.get(i).getMaxStackSize()-virtual_inventory.get(i).getAmount(); //How much space is here. - log("There is space for "+space+" blocks.",5); - if (space>=quantity) { - //We are done, because we can store everything. - virtual_inventory.get(i).setAmount(virtual_inventory.get(i).getAmount()+quantity); - quantity=0; - final int ider = idnumb; - final List items = virtual_inventory; - final CubeType type = cubetype; - /*//OLD ENDER ITEM CUBE CODE. - if (itemCube_getCubeType(idnumb)==CubeType.ENDER) { - log("This is an Ender Item Cube transfer click.",5); - //We are going to look at all players and see if they have this inventory open. - final int id = idnumb; - for (int j=0;j0) { - //We can't fit this anywhere else. So we put the rest back to the cursor. - ev.getCursor().setAmount(quantity); - } else { - stack_available=true; - } - - if (stack_available) { - ev.setCursor(new ItemStack(Material.AIR)); - itemCube_saveConfig(idnumb,virtual_inventory,cubetype); - } else { - //Look for an empty space. - for (int i=0;i items = virtual_inventory; - final CubeType type = cubetype; - - /*//OLD ENDER ITEM CUBE CODE - * if (itemCube_getCubeType(idnumb)==CubeType.ENDER) { - log("This is an Ender Item Cube transfer click.",5); - //We are going to look at all players and see if they have this inventory open. - final int id = idnumb; - for (int j=0;j items = itemCube_loadConfig(idnumb); + for (int i=0;i0) { + ev.setCursor((ItemStack)result.get(0)); } else { - //Well, we're already in here, I don't know why they didn't just use the - //minecraft inventory management system. Now I have to do math... - - boolean stack_available=false; - - //Now we will see if there are any places to stack blocks on. - int quantity=ev.getCursor().getAmount(); - log("Amount held: "+quantity,5); - for (int i=0;iev.getView().getTopInventory().getItem(i).getAmount()) { - log("Entered Loop",5); - //This is the same, and we have room to throw some in. - int space=ev.getView().getTopInventory().getItem(i).getMaxStackSize()-ev.getView().getTopInventory().getItem(i).getAmount(); //How much space is here. - log("There is space for "+space+" blocks.",5); - if (space>=quantity) { - //We are done, because we can store everything. - ev.getView().getTopInventory().getItem(i).setAmount(ev.getView().getTopInventory().getItem(i).getAmount()+quantity); - quantity=0; - List itemlist = new ArrayList(); - for (int j=0;j items = itemlist; - final CubeType type = cubetype; - /* OLD ENDER ITEM CUBE CODE. - if (itemCube_getCubeType(idnumb)==CubeType.ENDER) { - log("This is an Ender Item Cube transfer click.",5); - //We are going to look at all players and see if they have this inventory open. - final int id = idnumb; - for (int j=0;j itemlist = new ArrayList(); - for (int j=0;j items = itemlist; - final CubeType type = cubetype; - Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() { - @Override - public void run() { - itemCube_saveConfig(ider,items,type); - } - },2); - }*/ - } - } + ev.setCursor(new ItemStack(Material.AIR)); + log("Cursor should be air.",5); } - if (quantity>0) { - //We can't fit this anywhere else. So we put the rest back to the cursor. - ev.getCursor().setAmount(quantity); - } else { - stack_available=true; - } - - if (stack_available) { - ev.setCursor(new ItemStack(Material.AIR)); - } else { - for (int i=0;i itemslist = new ArrayList(); + for (int i=0;i0) { + ev.setCursor((ItemStack)result.get(0)); + } else { + ev.setCursor(new ItemStack(Material.AIR)); + } + List itemslist = new ArrayList(); + for (int i=0;i