Added item cube syncing back in, with improved usability. Uses a shared

inventory instead of a hack'ish click-based system.
This commit is contained in:
sigonasr2 2016-07-02 23:16:44 -05:00
parent a42ab99a9d
commit 43237b7a04
5 changed files with 292 additions and 318 deletions

Binary file not shown.

View File

@ -1,6 +1,6 @@
name: TwosideKeeper name: TwosideKeeper
main: sig.plugin.TwosideKeeper.TwosideKeeper main: sig.plugin.TwosideKeeper.TwosideKeeper
version: 3.4.4r1 version: 3.4.4r2
commands: commands:
money: money:
description: Tells the player the amount of money they are holding. description: Tells the player the amount of money they are holding.
@ -67,3 +67,8 @@ commands:
usage: /fix usage: /fix
permission: TwosideKeeper.fix permission: TwosideKeeper.fix
permission-message: No permissions! permission-message: No permissions!
tp_world:
description: Teleports to a location in a specified world.
usage: /tp_world <world> <x> <y> <z>
permission: TwosideKeeper.tp_world
permission-message: No permissions!

View File

@ -16,6 +16,7 @@ import org.bukkit.entity.Monster;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Skeleton; import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Skeleton.SkeletonType; import org.bukkit.entity.Skeleton.SkeletonType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.inventory.meta.PotionMeta;
@ -1383,4 +1384,71 @@ public class GenericFunctions {
return true; 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;i<target.getSize();i++) {
ItemStack targetitem = target.getItem(i);
if (targetitem!=null &&
targetitem.getType()!=Material.AIR &&
item.isSimilar(targetitem) &&
targetitem.getAmount()<targetitem.getMaxStackSize()) {
//We have some room!
int space = targetitem.getMaxStackSize()-targetitem.getAmount();
if (item.getAmount()<space) {
targetitem.setAmount(targetitem.getAmount()+item.getAmount());
//That means we are done!
return new ItemStack(Material.AIR);
} else {
//Insert what we can. Handle the rest elsewhere.
targetitem.setAmount(targetitem.getMaxStackSize());
item.setAmount(item.getAmount()-space);
}
} else
if (targetitem==null) {
//This is an empty spot. Insert the item here.
int space = item.getMaxStackSize();
if (item.getAmount()<space) {
ItemStack newslot = item.clone();
target.setItem(i, newslot);
return new ItemStack(Material.AIR);
} else {
//Insert what we can. Handle the rest elsewhere.
ItemStack newslot = item.clone();
newslot.setAmount(item.getMaxStackSize());
target.setItem(i, newslot);
item.setAmount(item.getAmount()-space);
}
} else if (targetitem.getType()==Material.AIR)
{
//This is an empty spot. Insert the item here.
int space = item.getMaxStackSize();
if (item.getAmount()<space) {
ItemStack newslot = item.clone();
target.setItem(i, newslot);
return new ItemStack(Material.AIR);
} else {
//Insert what we can. Handle the rest elsewhere.
ItemStack newslot = item.clone();
newslot.setAmount(item.getMaxStackSize());
target.setItem(i, newslot);
item.setAmount(item.getAmount()-space);
}
}
}
return item;
} else {
return new ItemStack(Material.AIR);
}
}
} }

View File

@ -3,6 +3,9 @@ package sig.plugin.TwosideKeeper.HelperStructures;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
@ -22,8 +25,27 @@ public class ItemCube {
} }
return false; //Didn't find anyone, oh well.. return false; //Didn't find anyone, oh well..
} }
public static Inventory getViewingItemCubeInventory(int id, Player checker) {
for (int i=0;i<Bukkit.getOnlinePlayers().size();i++) {
Player p = Iterables.get(Bukkit.getOnlinePlayers(), i);
if (!p.equals(checker)) {
if (p.getOpenInventory()!=null && p.getOpenInventory().getTitle().contains("Item Cube #"+id)) {
//This is an item cube. Check if it's the same number.
return p.getOpenInventory().getTopInventory();
}
}
}
return null; //Didn't find anything.
}
public static void displayErrorMessage(Player p) { public static void displayErrorMessage(Player p) {
p.playSound(p.getLocation(), Sound.BLOCK_NOTE_PLING, 0.6f, 4.0f); p.playSound(p.getLocation(), Sound.BLOCK_NOTE_PLING, 0.6f, 4.0f);
p.sendMessage("Someone is currently using this Item Cube! Please wait for them to finish."); p.sendMessage("Someone is currently using this Item Cube! Please wait for them to finish.");
} }
public static void addToViewersOfItemCube(int idnumb, ItemStack cursor, Player check) {
Inventory inv = getViewingItemCubeInventory(idnumb, check);
if (inv!=null) {
inv.addItem(cursor);
}
}
} }

View File

@ -18,6 +18,7 @@ import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.WorldCreator;
import org.bukkit.attribute.Attribute; import org.bukkit.attribute.Attribute;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.Chest; import org.bukkit.block.Chest;
@ -237,6 +238,8 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
sig.plugin.TwosideKeeper.Recipes.Initialize_SlabReconstruction_Recipes(); sig.plugin.TwosideKeeper.Recipes.Initialize_SlabReconstruction_Recipes();
sig.plugin.TwosideKeeper.Recipes.Initialize_Artifact_Recipes(); sig.plugin.TwosideKeeper.Recipes.Initialize_Artifact_Recipes();
Bukkit.createWorld(new WorldCreator("ItemCube"));
filesave=getDataFolder(); //Store the location of where our data folder is. filesave=getDataFolder(); //Store the location of where our data folder is.
log("Data folder at "+filesave+".",3); log("Data folder at "+filesave+".",3);
@ -724,8 +727,15 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
p.sendMessage(EssenceLogger.GenerateReport()); p.sendMessage(EssenceLogger.GenerateReport());
return true; return true;
} else } else
if (cmd.getName().equalsIgnoreCase("")) { if (cmd.getName().equalsIgnoreCase("tp_world")) {
if (args.length==4) {
Player p = (Player)sender;
p.teleport(new Location(Bukkit.getWorld(args[0]),Double.parseDouble(args[1]),Double.parseDouble(args[2]),Double.parseDouble(args[3])));
return true;
} else {
sender.sendMessage("Wrong arguments!");
}
return true;
} }
} else { } else {
//Implement console/admin version later (Let's you check any name's money.) //Implement console/admin version later (Let's you check any name's money.)
@ -1453,9 +1463,11 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
Location oldBedPos = ev.getPlayer().getBedSpawnLocation(); Location oldBedPos = ev.getPlayer().getBedSpawnLocation();
log(ev.getPlayer()+" Right-clicked bed. Set bed spawn to "+BedPos.toString(),3); log(ev.getPlayer()+" Right-clicked bed. Set bed spawn to "+BedPos.toString(),3);
ev.getPlayer().setBedSpawnLocation(BedPos); ev.getPlayer().setBedSpawnLocation(BedPos);
if (!oldBedPos.equals(BedPos)) { log(oldBedPos.toString()+"::"+ev.getPlayer().getBedSpawnLocation().toString(),5);
ev.getPlayer().sendMessage(ChatColor.BLUE+""+ChatColor.ITALIC+"New bed respawn location set."); if (oldBedPos.getBlockX()!=ev.getPlayer().getBedSpawnLocation().getBlockX() ||
} oldBedPos.getBlockY()!=ev.getPlayer().getBedSpawnLocation().getBlockY() ||
oldBedPos.getBlockZ()!=ev.getPlayer().getBedSpawnLocation().getBlockZ())
ev.getPlayer().sendMessage(ChatColor.BLUE+""+ChatColor.ITALIC+"New bed respawn location set.");
} }
if (ev.getAction()==Action.RIGHT_CLICK_BLOCK && if (ev.getAction()==Action.RIGHT_CLICK_BLOCK &&
ev.getClickedBlock().getType().toString().contains("RAIL") && ev.getClickedBlock().getType().toString().contains("RAIL") &&
@ -1466,7 +1478,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
ev.setCancelled(true); //Do not place minecarts on rails -.- ev.setCancelled(true); //Do not place minecarts on rails -.-
ev.getPlayer().updateInventory(); ev.getPlayer().updateInventory();
} }
if (ev.getAction()==Action.RIGHT_CLICK_AIR || (ev.getPlayer().isSneaking() && ev.getAction()==Action.RIGHT_CLICK_AIR) || (ev.getPlayer().isSneaking() && ev.getAction()==Action.RIGHT_CLICK_BLOCK)) { if (ev.getAction()==Action.RIGHT_CLICK_AIR || (ev.getPlayer().isSneaking() && ev.getAction()==Action.RIGHT_CLICK_AIR) || (ev.getPlayer().isSneaking() && ev.getAction()==Action.RIGHT_CLICK_BLOCK && !GenericFunctions.isDumpableContainer(ev.getClickedBlock().getType()))) {
if (ev.getPlayer().getInventory().getItemInMainHand().hasItemMeta() && if (ev.getPlayer().getInventory().getItemInMainHand().hasItemMeta() &&
ev.getPlayer().getInventory().getItemInMainHand().getItemMeta().hasLore() && ev.getPlayer().getInventory().getItemInMainHand().getItemMeta().hasLore() &&
ev.getPlayer().getInventory().getItemInMainHand().getItemMeta().getLore().size()==4 && ev.getPlayer().getInventory().getItemInMainHand().getItemMeta().getLore().size()==4 &&
@ -1487,9 +1499,33 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
openItemCubeInventory(newinv.getTopInventory(),newinv); openItemCubeInventory(newinv.getTopInventory(),newinv);
ev.getPlayer().playSound(ev.getPlayer().getLocation(), Sound.BLOCK_CHEST_OPEN, 1.0f, 1.0f); ev.getPlayer().playSound(ev.getPlayer().getLocation(), Sound.BLOCK_CHEST_OPEN, 1.0f, 1.0f);
} else { } else {
ItemCube.displayErrorMessage(ev.getPlayer()); //ItemCube.displayErrorMessage(ev.getPlayer());
ev.getPlayer().openInventory(ItemCube.getViewingItemCubeInventory(itemcube_id, ev.getPlayer()));
PlayerStructure pd = (PlayerStructure) playerdata.get(ev.getPlayer().getUniqueId());
pd.isViewingItemCube=true;
ev.getPlayer().playSound(ev.getPlayer().getLocation(), Sound.BLOCK_CHEST_OPEN, 1.0f, 1.0f);
} }
} }
} else
if (ev.getPlayer().isSneaking() && ev.getAction()==Action.RIGHT_CLICK_BLOCK && !GenericFunctions.isDumpableContainer(ev.getClickedBlock().getType())) {
//This is an attempt to insert an item cube into a container. See what item cube we're holding.
ev.setCancelled(true);
if (ev.getPlayer().getInventory().getItemInMainHand().hasItemMeta() &&
ev.getPlayer().getInventory().getItemInMainHand().getItemMeta().hasLore() &&
ev.getPlayer().getInventory().getItemInMainHand().getItemMeta().getLore().size()==4 &&
ev.getPlayer().getInventory().getItemInMainHand().getItemMeta().getLore().get(3).contains(ChatColor.DARK_PURPLE+"ID#")) {
int itemcube_id=Integer.parseInt(ev.getPlayer().getInventory().getItemInMainHand().getItemMeta().getLore().get(3).split("#")[1]);
int size=0;
if (ev.getPlayer().getInventory().getItemInMainHand().getType()==Material.CHEST) {
size=9;
} else {
size=27;
}
//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.
//Chest c = (Chest)ev.getClickedBlock().getState();
}
} }
if (b!=null && (b.getType() == Material.SIGN || if (b!=null && (b.getType() == Material.SIGN ||
b.getType() == Material.SIGN_POST || b.getType() == Material.SIGN_POST ||
@ -1501,89 +1537,95 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
if (b.getType()==Material.WALL_SIGN && if (b.getType()==Material.WALL_SIGN &&
!TwosideShops.IsPlayerUsingTerminal(player)) { //Shop signs can only be wall signs. !TwosideShops.IsPlayerUsingTerminal(player)) { //Shop signs can only be wall signs.
log("This is a wall sign.",5); log("This is a wall sign.",5);
if (s.getLine(0).equalsIgnoreCase("shop")) { //Make sure it is on a chest. Or trapped chest.
log("This is a shop sign.",5); org.bukkit.material.Sign s1 = (org.bukkit.material.Sign)(b.getState().getData());
//Create a new shop. Block chest = b.getRelative(s1.getAttachedFace());
ItemStack item = player.getEquipment().getItemInMainHand(); if (chest.getType()==Material.CHEST ||
if (item.getType()!=Material.AIR) { chest.getType()==Material.TRAPPED_CHEST) {
WorldShopSession ss = TwosideShops.AddSession(SessionState.CREATE, player, s); if (s.getLine(0).equalsIgnoreCase("shop")) {
player.sendMessage("Creating a shop to sell "+ChatColor.GREEN+GenericFunctions.GetItemName(item)+ChatColor.WHITE+"."); log("This is a shop sign.",5);
int totalcount = 0; //Create a new shop.
totalcount = GenericFunctions.CountItems(player, item); ItemStack item = player.getEquipment().getItemInMainHand();
log("We have "+totalcount+" items in our inventory.",4); if (item.getType()!=Material.AIR) {
ss.SetItem(item); WorldShopSession ss = TwosideShops.AddSession(SessionState.CREATE, player, s);
player.sendMessage("How many of this item do you want to sell? "+ChatColor.GREEN+"(MAX: "+ChatColor.YELLOW+totalcount+ChatColor.GREEN+")"); player.sendMessage("Creating a shop to sell "+ChatColor.GREEN+GenericFunctions.GetItemName(item)+ChatColor.WHITE+".");
} else { int totalcount = 0;
player.sendMessage(ChatColor.RED+"Cannot create a shop with nothing! "+ChatColor.WHITE+"Right-click the sign" totalcount = GenericFunctions.CountItems(player, item);
+ " with the item you want to sell in your hand."); log("We have "+totalcount+" items in our inventory.",4);
} ss.SetItem(item);
} else player.sendMessage("How many of this item do you want to sell? "+ChatColor.GREEN+"(MAX: "+ChatColor.YELLOW+totalcount+ChatColor.GREEN+")");
if (s.getLine(0).equalsIgnoreCase(ChatColor.BLUE+"-- SHOP --")) { } else {
log("This is a buy shop sign.",5); player.sendMessage(ChatColor.RED+"Cannot create a shop with nothing! "+ChatColor.WHITE+"Right-click the sign"
int shopID = TwosideShops.GetShopID(s); + " with the item you want to sell in your hand.");
WorldShop shop = TwosideShops.LoadWorldShopData(shopID); }
} 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); 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); WorldShop.spawnShopItem(ev,newloc,shop);
if (shop.GetOwner().equalsIgnoreCase(ev.getPlayer().getName())) { if (shop.GetOwner().equalsIgnoreCase(ev.getPlayer().getName())) {
player.sendMessage(ChatColor.DARK_PURPLE+"Editing shop..."); 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+"."); 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); TwosideShops.AddSession(SessionState.EDIT, player, s);
} else {
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 { } 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
} else if (s.getLine(0).equalsIgnoreCase("buyshop")) {
if (s.getLine(0).equalsIgnoreCase("buyshop")) { //Create a new buy shop.
//Create a new buy shop. ItemStack item = player.getEquipment().getItemInMainHand();
ItemStack item = player.getEquipment().getItemInMainHand(); if (item.getType()!=Material.AIR) {
if (item.getType()!=Material.AIR) { WorldShopSession ss = TwosideShops.AddSession(SessionState.BUY_CREATE, player, s);
WorldShopSession ss = TwosideShops.AddSession(SessionState.BUY_CREATE, player, s); player.sendMessage("Creating a shop to buy "+ChatColor.GREEN+GenericFunctions.GetItemName(item)+ChatColor.WHITE+".");
player.sendMessage("Creating a shop to buy "+ChatColor.GREEN+GenericFunctions.GetItemName(item)+ChatColor.WHITE+"."); int totalcount = 0;
int totalcount = 0; totalcount = GenericFunctions.CountItems(player, item);
totalcount = GenericFunctions.CountItems(player, item); ss.SetItem(item);
ss.SetItem(item); player.sendMessage("How many of this item do you want to buy?");
player.sendMessage("How many of this item do you want to buy?"); } else {
} else { player.sendMessage(ChatColor.RED+"Cannot create a shop with nothing! "+ChatColor.WHITE+"Right-click the sign"
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.");
+ " with the item you want to buy in your hand."); }
} } 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-")) { //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); Location newloc = ev.getClickedBlock().getLocation().add(-ev.getBlockFace().getModX()+0.5, -ev.getBlockFace().getModY()+1.5, -ev.getBlockFace().getModZ()+0.5);
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);
WorldShop.spawnShopItem(ev,newloc,shop);
if (shop.GetOwner().equalsIgnoreCase(ev.getPlayer().getName())) { if (shop.GetOwner().equalsIgnoreCase(ev.getPlayer().getName())) {
player.sendMessage(ChatColor.DARK_PURPLE+"Editing shop..."); 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+"."); 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); 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 { } 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. //Determine if this is a bank sign.
@ -1834,6 +1876,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
public void onInventoryClose(InventoryCloseEvent ev) { public void onInventoryClose(InventoryCloseEvent ev) {
if (ev.getPlayer() instanceof Player) { if (ev.getPlayer() instanceof Player) {
Player p = (Player)ev.getPlayer(); Player p = (Player)ev.getPlayer();
//log("Location of inventory: "+ev.getInventory().getLocation().toString(),2);
if (DeathManager.deathStructureExists(p) && ev.getInventory().getTitle().contains("Death Loot")) { if (DeathManager.deathStructureExists(p) && ev.getInventory().getTitle().contains("Death Loot")) {
Location deathloc = DeathManager.getDeathStructure(p).deathloc; Location deathloc = DeathManager.getDeathStructure(p).deathloc;
//Whatever is left drops at the death location. //Whatever is left drops at the death location.
@ -2199,7 +2242,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
CubeType cubetype = CubeType.NORMAL; CubeType cubetype = CubeType.NORMAL;
//This is an Item Cube. //This is an Item Cube.
ev.setCancelled(true); ev.setCancelled(true);
ev.setResult(Result.DENY); //ev.setResult(Result.DENY);
int size; int size;
if (ev.getCurrentItem().getType()==Material.CHEST) { 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. //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")) { if (((PlayerStructure)playerdata.get(ev.getWhoClicked().getUniqueId())).isViewingItemCube && ev.getInventory().getTitle().contains("Item Cube")) {
//Check to see what the Item Cube ID is. //Check to see what the Item Cube ID is.
@ -2253,234 +2310,54 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} }
else else
//Make sure we are not already inside the cube we're placing into. //Make sure we are not already inside the cube we're placing into.
if (!ItemCube.isSomeoneViewingItemCube(idnumb,(Player)ev.getWhoClicked())) { if (idnumb!=itemcubeid) {
if (idnumb!=itemcubeid) { //See if someone has this inventory opened already.
log(idnumb+" does not match "+itemcubeid,5); Inventory virtualinventory = null;
//Try to insert item inside this item cube. virtualinventory = ItemCube.getViewingItemCubeInventory(idnumb, (Player)ev.getWhoClicked());
List<ItemStack> virtual_inventory = itemCube_loadConfig(idnumb); if (virtualinventory==null) {
boolean stack_available=false; virtualinventory = Bukkit.createInventory((Player)ev.getWhoClicked(), clicked_size);
//Now we will see if there are any places to stack blocks on. log("Inventory size is "+clicked_size,5);
int quantity=ev.getCursor().getAmount(); List<ItemStack> items = itemCube_loadConfig(idnumb);
log("Amount held: "+quantity,5); for (int i=0;i<virtualinventory.getSize();i++) {
for (int i=0;i<size;i++) { if (items.get(i)!=null) {
if (virtual_inventory.get(i).isSimilar(ev.getCursor()) && virtualinventory.setItem(i, items.get(i));
virtual_inventory.get(i).getMaxStackSize()>virtual_inventory.get(i).getAmount()) { log("Load up with "+items.get(i).toString(),5);
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. ItemCube.addToViewersOfItemCube(idnumb,ev.getCursor(),(Player)ev.getWhoClicked());
log("There is space for "+space+" blocks.",5); }
if (space>=quantity) { HashMap result = virtualinventory.addItem(ev.getCursor());
//We are done, because we can store everything. log("Clicked ID number "+idnumb,5);
virtual_inventory.get(i).setAmount(virtual_inventory.get(i).getAmount()+quantity); //Set whatever's left back to the cursor.
quantity=0; if (result.size()>0) {
final int ider = idnumb; ev.setCursor((ItemStack)result.get(0));
final List<ItemStack> 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<Bukkit.getServer().getOnlinePlayers().toArray().length;j++) {
//Make sure the player we are checking is not ourself.
final Player p = (Player)Bukkit.getServer().getOnlinePlayers().toArray()[j];
if (p.getOpenInventory()!=null &&
!p.getName().equalsIgnoreCase(ev.getWhoClicked().getName()) &&
p.getOpenInventory().getTitle().contentEquals("Item Cube #"+idnumb)) {
p.closeInventory();
}
}
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
@Override
public void run() {
itemCube_saveConfig(ider,items,type);
}
},2);
} else {*/
itemCube_saveConfig(ider,items,type);
//}
ev.setCursor(new ItemStack(Material.AIR));
break;
} else {
//We still have more. Store what we can.
quantity-=space;
log("Still have "+quantity+" blocks left.",5);
virtual_inventory.get(i).setAmount(virtual_inventory.get(i).getMaxStackSize());
itemCube_saveConfig(idnumb,virtual_inventory,cubetype);
}
}
}
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));
itemCube_saveConfig(idnumb,virtual_inventory,cubetype);
} else {
//Look for an empty space.
for (int i=0;i<size;i++) {
if (virtual_inventory.get(i).getType()==Material.AIR) {
//WE have found an empty space. Throw it in there.
virtual_inventory.set(i, ev.getCursor());
log("Set item slot "+i+" to "+ev.getCursor().toString(),5);
ev.setCursor(new ItemStack(Material.AIR));
final int ider = idnumb;
final List<ItemStack> 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<Bukkit.getServer().getOnlinePlayers().toArray().length;j++) {
//Make sure the player we are checking is not ourself.
final Player p = (Player)Bukkit.getServer().getOnlinePlayers().toArray()[j];
if (p.getOpenInventory()!=null &&
!p.getName().equalsIgnoreCase(ev.getWhoClicked().getName()) &&
p.getOpenInventory().getTitle().contentEquals("Item Cube #"+idnumb)) {
p.closeInventory();
}
}
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
@Override
public void run() {
itemCube_saveConfig(ider,items,type);
}
},2);
break;
} else {*/
itemCube_saveConfig(ider,items,type);
//}
}
}
}
} else { } else {
//Well, we're already in here, I don't know why they didn't just use the ev.setCursor(new ItemStack(Material.AIR));
//minecraft inventory management system. Now I have to do math... log("Cursor should be air.",5);
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;i<size;i++) {
if (ev.getView().getTopInventory().getItem(i)!=null &&
ev.getView().getTopInventory().getItem(i).isSimilar(ev.getCursor()) &&
ev.getView().getTopInventory().getItem(i).getMaxStackSize()>ev.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<ItemStack> itemlist = new ArrayList<ItemStack>();
for (int j=0;j<ev.getView().getTopInventory().getSize();j++) {
itemlist.add(ev.getView().getTopInventory().getItem(j));
}
final int ider = idnumb;
final List<ItemStack> 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<Bukkit.getServer().getOnlinePlayers().toArray().length;j++) {
//Make sure the player we are checking is not ourself.
final Player p = (Player)Bukkit.getServer().getOnlinePlayers().toArray()[j];
if (p.getOpenInventory()!=null &&
!p.getName().equalsIgnoreCase(ev.getWhoClicked().getName()) &&
p.getOpenInventory().getTitle().contentEquals("Item Cube #"+idnumb)) {
p.closeInventory();
}
}
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
@Override
public void run() {
itemCube_saveConfig(ider,items,type);
}
},2);
} else {
itemCube_saveConfig(ider,items,type);
}*/
ev.setCursor(new ItemStack(Material.AIR));
break;
} else {
//We still have more. Store what we can.
quantity-=space;
log("Still have "+quantity+" blocks left.",5);
ev.getView().getTopInventory().getItem(i).setAmount(ev.getView().getTopInventory().getItem(i).getMaxStackSize());
List<ItemStack> itemlist = new ArrayList<ItemStack>();
for (int j=0;j<ev.getView().getTopInventory().getSize();j++) {
itemlist.add(ev.getView().getTopInventory().getItem(j));
}
/* 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<Bukkit.getServer().getOnlinePlayers().toArray().length;j++) {
//Make sure the player we are checking is not ourself.
final Player p = (Player)Bukkit.getServer().getOnlinePlayers().toArray()[j];
if (p.getOpenInventory()!=null &&
!p.getName().equalsIgnoreCase(ev.getWhoClicked().getName()) &&
p.getOpenInventory().getTitle().contentEquals("Item Cube #"+idnumb)) {
p.closeInventory();
}
}
final int ider = idnumb;
final List<ItemStack> items = itemlist;
final CubeType type = cubetype;
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
@Override
public void run() {
itemCube_saveConfig(ider,items,type);
}
},2);
}*/
}
}
} }
if (quantity>0) { List<ItemStack> itemslist = new ArrayList<ItemStack>();
//We can't fit this anywhere else. So we put the rest back to the cursor. for (int i=0;i<virtualinventory.getSize();i++) {
ev.getCursor().setAmount(quantity); itemslist.add(virtualinventory.getItem(i));
} else { }
stack_available=true; itemCube_saveConfig(idnumb,itemslist);
} } 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...
//Add it to the inventory being viewed.
HashMap result = ev.getWhoClicked().getOpenInventory().getTopInventory().addItem(ev.getCursor());
//Add it to everyone viewing the cube.
//ItemCube.addToViewersOfItemCube(idnumb, ev.getCursor(), (Player)ev.getWhoClicked());
if (stack_available) { if (result.size()>0) {
ev.setCursor(new ItemStack(Material.AIR)); ev.setCursor((ItemStack)result.get(0));
} else { } else {
for (int i=0;i<size;i++) { ev.setCursor(new ItemStack(Material.AIR));
if (ev.getView().getTopInventory().getItem(i)==null || ev.getView().getTopInventory().getItem(i).getType()==Material.AIR) { }
//WE have found an empty space. Throw it in there. List<ItemStack> itemslist = new ArrayList<ItemStack>();
ev.getView().getTopInventory().setItem(i, ev.getCursor()); for (int i=0;i<ev.getWhoClicked().getOpenInventory().getTopInventory().getSize();i++) {
ev.setCursor(new ItemStack(Material.AIR)); itemslist.add(ev.getWhoClicked().getOpenInventory().getTopInventory().getItem(i));
break; }
} itemCube_saveConfig(idnumb,itemslist);
}
}
}
} else {
ev.setCancelled(true);
ev.setCursor(ev.getCursor());
ItemCube.displayErrorMessage((Player)ev.getWhoClicked());
} }
} }
} }
@ -2523,13 +2400,16 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
ev.setCancelled(true); ev.setCancelled(true);
ev.setResult(Result.DENY); ev.setResult(Result.DENY);
InventoryView newinv = p.openInventory(Bukkit.getServer().createInventory(p, inventory_size, "Item Cube #"+idnumb)); InventoryView newinv = p.openInventory(Bukkit.getServer().createInventory(p, inventory_size, "Item Cube #"+idnumb));
openItemCubeInventory(newinv.getTopInventory(),newinv); openItemCubeInventory(p.getOpenInventory().getTopInventory(),newinv);
pd.isViewingItemCube=true; pd.isViewingItemCube=true;
p.playSound(p.getLocation(),Sound.BLOCK_CHEST_OPEN,1.0f,1.0f); p.playSound(p.getLocation(),Sound.BLOCK_CHEST_OPEN,1.0f,1.0f);
} else { } else {
ev.setCancelled(true); ev.setCancelled(true);
ev.setResult(Result.DENY); ev.setResult(Result.DENY);
ItemCube.displayErrorMessage(p); //ItemCube.displayErrorMessage(p);
p.openInventory(ItemCube.getViewingItemCubeInventory(idnumb, p));
pd.isViewingItemCube=true;
p.playSound(p.getLocation(), Sound.BLOCK_CHEST_OPEN, 1.0f, 1.0f);
} }
//} //}
} }
@ -4293,7 +4173,6 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} else { } else {
double money = workable.getDouble("money"); double money = workable.getDouble("money");
money+=amt; money+=amt;
workable.set("money", money); workable.set("money", money);