diff --git a/TwosideKeeper.jar b/TwosideKeeper.jar index ccac4c8..eb6bfe7 100644 Binary files a/TwosideKeeper.jar and b/TwosideKeeper.jar differ diff --git a/src/plugin.yml b/src/plugin.yml index 8de0202..54ce092 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: TwosideKeeper main: sig.plugin.TwosideKeeper.TwosideKeeper -version: 3.3.4 +version: 3.3.5 commands: money: description: Tells the player the amount of money they are holding. @@ -32,6 +32,11 @@ commands: usage: /recyclingcenter permission: TwosideKeeper.recyclingcenter permission-message: No permissions! + glowingitem: + description: Creates a new glowing item. + usage: /glowingitem + permission: TwosideKeeper.glowingitem + permission-message: No permissions! sound: description: Toggle sound message notifications. usage: /sound diff --git a/src/sig/plugin/TwosideKeeper/Artifact.java b/src/sig/plugin/TwosideKeeper/Artifact.java index c6eeb87..6aa82a7 100644 --- a/src/sig/plugin/TwosideKeeper/Artifact.java +++ b/src/sig/plugin/TwosideKeeper/Artifact.java @@ -173,4 +173,13 @@ public class Artifact { return false; } } + public static boolean isMysteriousEssence(ItemStack item) { + //Check for type of item, and if it's an artifact. + if (isArtifact(item) && + item.getType()==Material.PUMPKIN_SEEDS) { + return true; + } else { + return false; + } + } } diff --git a/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java b/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java index de9e2ab..e05f088 100644 --- a/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java +++ b/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java @@ -6,6 +6,8 @@ import java.util.List; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.Sign; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -13,6 +15,7 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.PotionMeta; import sig.plugin.TwosideKeeper.TwosideKeeper; +import sig.plugin.TwosideKeeper.HelperStructures.WorldShop; public class GenericFunctions { @@ -1037,8 +1040,11 @@ public class GenericFunctions { public static boolean isHardenedItem(ItemStack item) { if (item.hasItemMeta() && item.getItemMeta().hasLore()) { + //TwosideKeeper.log("This item has lore...", 2); for (int i=0;i entities = ev.getPlayer().getLocation().getWorld().getNearbyEntities(loc, 1, 1, 1); + for (int i=0;i partyplayers; + public List lastorder; int color; Location region; Party(int color, Location rawPos) { partyplayers = new ArrayList(); + lastorder = new ArrayList(); rawPos.setX((int)(rawPos.getX()/(16*TwosideKeeper.PARTY_CHUNK_SIZE))*(16*TwosideKeeper.PARTY_CHUNK_SIZE)); rawPos.setZ((int)(rawPos.getZ()/(16*TwosideKeeper.PARTY_CHUNK_SIZE))*(16*TwosideKeeper.PARTY_CHUNK_SIZE)); region=rawPos; @@ -126,8 +128,12 @@ public class Party { sortedorder.add(lasti,partyplayers.get(i)); } } - for (int i=0;i0) { + current_session.SetAmt(amt); + ev.getPlayer().sendMessage("Input how much you will pay for each "+ChatColor.GREEN+GenericFunctions.GetItemName(current_session.getItem())+ChatColor.WHITE+":"); + current_session.SetSession(SessionState.BUY_PRICE); + } else { + ev.getPlayer().sendMessage("You cannot purchase 0 of an item."); + TwosideShops.RemoveSession(ev.getPlayer()); + } + } else { + ev.getPlayer().sendMessage("That is not a valid number! Please try again."); + } + break; case PRICE: if (isNumeric(ev.getMessage())) { final DecimalFormat df = new DecimalFormat("0.00"); @@ -821,6 +854,33 @@ public class TwosideKeeper extends JavaPlugin implements Listener { ev.getPlayer().sendMessage("That is not a valid number! Please try again."); } break; + case BUY_PRICE: + if (isNumeric(ev.getMessage())) { + final DecimalFormat df = new DecimalFormat("0.00"); + final double amt = Double.parseDouble(ev.getMessage()); + if (amt>0 && amt<=999999999999.99) { + ev.getPlayer().sendMessage(ChatColor.DARK_BLUE+"Purchase Shop has been successfully created!"); + Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() { + @Override + public void run() { + TwosideShops.SaveWorldShopData( + TwosideShops.CreateWorldShop(current_session.GetSign(), current_session.getItem(), current_session.getAmt(), Double.parseDouble(df.format(amt)), ev.getPlayer().getName(),true) + ); + TwosideShops.RemoveSession(ev.getPlayer()); + } + },1); + + } else { + if (amt>999999999999.99) { + ev.getPlayer().sendMessage("You cannot buy an item for that ridiculous amount. Please try again."); + } else { + ev.getPlayer().sendMessage("You cannot buy an item for free. Please try again."); + } + } + } else { + ev.getPlayer().sendMessage("That is not a valid number! Please try again."); + } + break; case EDIT: if (isNumeric(ev.getMessage())) { int amt = Integer.parseInt(ev.getMessage()); @@ -831,7 +891,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { shop.UpdateAmount(shop.GetAmount()+amt); RemoveItemAmount(ev.getPlayer(), shop.GetItem(), amt); TwosideShops.SaveWorldShopData(shop); - TwosideShops.UpdateSign(shop, TwosideShops.GetShopID(current_session.GetSign()), current_session.GetSign()); + TwosideShops.UpdateSign(shop, TwosideShops.GetShopID(current_session.GetSign()), current_session.GetSign(),false); ev.getPlayer().sendMessage("Added "+ChatColor.AQUA+amt+ChatColor.WHITE+" more "+ChatColor.GREEN+shop.GetItemName()+ChatColor.WHITE+" to your shop!"); ev.getPlayer().sendMessage("Input how much each "+ChatColor.GREEN+shop.GetItemName()+ChatColor.WHITE+" will cost (Old value - "+ChatColor.YELLOW+"$"+df.format(shop.GetUnitPrice())+ChatColor.WHITE+":"); @@ -878,7 +938,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { log("Dropped shop item.",5); //ev.getPlayer().getWorld().dropItemNaturally(ev.getPlayer().getLocation(), drop).setPickupDelay(0); TwosideShops.SaveWorldShopData(shop); - TwosideShops.UpdateSign(shop, TwosideShops.GetShopID(current_session.GetSign()), current_session.GetSign()); + TwosideShops.UpdateSign(shop, TwosideShops.GetShopID(current_session.GetSign()), current_session.GetSign(),false); if (shop.GetAmount()>0) { current_session.SetSession(SessionState.UPDATE); @@ -895,6 +955,65 @@ public class TwosideKeeper extends JavaPlugin implements Listener { ev.getPlayer().sendMessage("That is not a valid number! Please try again."); } break; + case BUY_EDIT: + if (isNumeric(ev.getMessage())) { + int amt = Integer.parseInt(ev.getMessage()); + DecimalFormat df = new DecimalFormat("0.00"); + WorldShop shop = TwosideShops.LoadWorldShopData(TwosideShops.GetShopID(current_session.GetSign())); + if (amt>=0) { //This means we want to add more to the amount. + shop.UpdateAmount(shop.GetAmount()+amt); + TwosideShops.SaveWorldShopData(shop); + TwosideShops.UpdateSign(shop, TwosideShops.GetShopID(current_session.GetSign()), current_session.GetSign(),true); + ev.getPlayer().sendMessage("Requested "+ChatColor.AQUA+amt+ChatColor.WHITE+" more "+ChatColor.GREEN+shop.GetItemName()+ChatColor.WHITE+" to your shop!"); + ev.getPlayer().sendMessage("Input how much you will pay for each "+ChatColor.GREEN+shop.GetItemName()+ChatColor.WHITE+" (Old value - "+ChatColor.YELLOW+"$"+df.format(shop.GetUnitPrice())+ChatColor.WHITE+":"); + + current_session.SetSession(SessionState.BUY_UPDATE); + } else { + if (-amt<=shop.GetStoredAmount()) { + //Take out these items from the shop. + amt*=-1; + shop.UpdateStoredAmount(shop.GetStoredAmount()-amt); + ItemStack drop = shop.GetItem(); + int dropAmt = amt; + //ev.getPlayer().getWorld().dropItemNaturally(ev.getPlayer().getLocation(), drop).setPickupDelay(0); + final Player p = ev.getPlayer(); + while (dropAmt>0) { + if (dropAmt>shop.GetItem().getMaxStackSize()) { + drop.setAmount(shop.GetItem().getMaxStackSize()); + final ItemStack dropitem = drop; + Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() { + @Override + public void run() { + p.getWorld().dropItemNaturally(p.getLocation(), dropitem).setPickupDelay(0); + } + },1); + dropAmt-=shop.GetItem().getMaxStackSize(); + } else { + drop.setAmount(dropAmt); + final ItemStack dropitem = drop; + Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() { + @Override + public void run() { + p.getWorld().dropItemNaturally(p.getLocation(), dropitem).setPickupDelay(0); + } + },1); + dropAmt=0; + } + } + log("Dropped shop item.",5); + //ev.getPlayer().getWorld().dropItemNaturally(ev.getPlayer().getLocation(), drop).setPickupDelay(0); + TwosideShops.SaveWorldShopData(shop); + TwosideShops.UpdateSign(shop, TwosideShops.GetShopID(current_session.GetSign()), current_session.GetSign(),true); + + TwosideShops.RemoveSession(p); + } else { + ev.getPlayer().sendMessage("You only have "+shop.GetStoredAmount()+" of "+ChatColor.GREEN+shop.GetItemName()+ChatColor.WHITE+" stored in the shop. Please try again."); + } + } + } else { + ev.getPlayer().sendMessage("That is not a valid number! Please try again."); + } + break; case UPDATE: if (isNumeric(ev.getMessage())) { double amt = Double.parseDouble(ev.getMessage()); @@ -902,7 +1021,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { if (amt>0 && amt<=999999999999.99) { shop.UpdateUnitPrice(amt); TwosideShops.SaveWorldShopData(shop); - TwosideShops.UpdateSign(shop, TwosideShops.GetShopID(current_session.GetSign()), current_session.GetSign()); + TwosideShops.UpdateSign(shop, TwosideShops.GetShopID(current_session.GetSign()), current_session.GetSign(),false); ev.getPlayer().sendMessage(ChatColor.DARK_BLUE+"Shop successfully updated!"); TwosideShops.RemoveSession(ev.getPlayer()); } else { @@ -916,6 +1035,27 @@ public class TwosideKeeper extends JavaPlugin implements Listener { ev.getPlayer().sendMessage("That is not a valid number! Please try again."); } break; + case BUY_UPDATE: + if (isNumeric(ev.getMessage())) { + double amt = Double.parseDouble(ev.getMessage()); + WorldShop shop = TwosideShops.LoadWorldShopData(TwosideShops.GetShopID(current_session.GetSign())); + if (amt>0 && amt<=999999999999.99) { + shop.UpdateUnitPrice(amt); + TwosideShops.SaveWorldShopData(shop); + TwosideShops.UpdateSign(shop, TwosideShops.GetShopID(current_session.GetSign()), current_session.GetSign(),true); + ev.getPlayer().sendMessage(ChatColor.DARK_BLUE+"Shop successfully updated!"); + TwosideShops.RemoveSession(ev.getPlayer()); + } else { + if (amt>999999999999.99) { + ev.getPlayer().sendMessage("You cannot buy an item for that ridiculous amount. Please try again."); + } else { + ev.getPlayer().sendMessage("You cannot buy an item for free. Please try again."); + } + } + } else { + ev.getPlayer().sendMessage("That is not a valid number! Please try again."); + } + break; case PURCHASE: if (isNumeric(ev.getMessage())) { DecimalFormat df = new DecimalFormat("0.00"); @@ -952,7 +1092,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { dropAmt=0; } } - TwosideShops.UpdateSign(shop, shopID, current_session.GetSign()); + TwosideShops.UpdateSign(shop, shopID, current_session.GetSign(),false); TwosideShops.SaveWorldShopData(shop); TwosideShops.RemoveSession(ev.getPlayer()); givePlayerMoney(ev.getPlayer(), -amt*shop.GetUnitPrice()); @@ -976,38 +1116,79 @@ public class TwosideKeeper extends JavaPlugin implements Listener { ev.getPlayer().sendMessage("That is not a valid number! Please try again."); } break; + case SELL: + if (isNumeric(ev.getMessage())) { + DecimalFormat df = new DecimalFormat("0.00"); + int amt = Integer.parseInt(ev.getMessage()); + if (amt>0) { + int shopID = TwosideShops.GetShopID(current_session.GetSign()); + WorldShop shop = TwosideShops.LoadWorldShopData(shopID); + if (amt<=GenericFunctions.CountItems(ev.getPlayer(), shop.GetItem())) { //Make sure we are holding enough of this item. + //Make sure we are only requesting as many items as the shop owner wants. + if (amt<=shop.GetAmount()) { + if (getPlayerBankMoney(shop.GetOwner())>=amt*shop.GetUnitPrice()) { + ev.getPlayer().sendMessage(ChatColor.DARK_BLUE+"Successfully sold "+amt+" "+ChatColor.GREEN+shop.GetItemName()+ChatColor.WHITE+" and earned "+ChatColor.YELLOW+"$"+df.format(amt*shop.GetUnitPrice())+ChatColor.WHITE+"!"); + shop.UpdateAmount(shop.GetAmount()-amt); + shop.UpdateStoredAmount(shop.GetStoredAmount()+amt); + ItemStack shopItem = shop.GetItem(); + RemoveItemAmount(ev.getPlayer(),shop.GetItem(),amt); + TwosideShops.UpdateSign(shop, shopID, current_session.GetSign(),true); + TwosideShops.SaveWorldShopData(shop); + TwosideShops.RemoveSession(ev.getPlayer()); + givePlayerMoney(ev.getPlayer(), amt*shop.GetUnitPrice()); + givePlayerBankMoney(shop.GetOwner(), -amt*shop.GetUnitPrice()); + TwosideShops.AddNewPurchase(shop.GetOwner(), ev.getPlayer(), shop.GetItem(), amt*shop.GetUnitPrice(), amt, false); + } else { + ev.getPlayer().sendMessage(ChatColor.LIGHT_PURPLE+shop.GetOwner()+ChatColor.WHITE+" only has enough money in their bank to buy "+ChatColor.GREEN+(int)(getPlayerBankMoney(shop.GetOwner())/shop.GetUnitPrice())+ChatColor.WHITE+" of "+ChatColor.GREEN+shop.GetItemName()+ChatColor.WHITE+"! Please try again."); + } + } else { + ev.getPlayer().sendMessage("The shop owner is only requesting "+ChatColor.GREEN+shop.GetAmount()+ChatColor.WHITE+" of "+ChatColor.GREEN+shop.GetItemName()+ChatColor.WHITE+"! Please try again."); + } + } else { + ev.getPlayer().sendMessage("You are not holding that many "+ChatColor.GREEN+shop.GetItemName()+ChatColor.WHITE+"! Please try again."); + } + } else { + ev.getPlayer().sendMessage(ChatColor.RED+"Decided not to sell."); + TwosideShops.RemoveSession(ev.getPlayer()); + } + } else { + ev.getPlayer().sendMessage("That is not a valid number! Please try again."); + } + break; default: break; } ev.setMessage(""); ev.setCancelled(true); } else - for (int i=0;i-1) { + pos = ev.getMessage().indexOf("[]"); + ev.setMessage(ev.getMessage().replace("[]", "")); + log("pos is "+pos+" message is: {"+ev.getMessage()+"}",5); + DiscordMessageSender.sendRawMessageDiscord(("**"+ev.getPlayer().getName()+"** "+ev.getMessage().substring(0, pos)+"**["+ChatColor.stripColor(GenericFunctions.GetItemName(ev.getPlayer().getEquipment().getItemInMainHand()))+"]**"+"\n```"+WorldShop.GetItemInfo(ev.getPlayer().getEquipment().getItemInMainHand())+" ```\n"+ev.getMessage().substring(pos))); + Bukkit.dispatchCommand(Bukkit.getConsoleSender(),"tellraw @a [\"\",{\"text\":\"<"+ev.getPlayer().getName()+"> \"},{\"text\":\""+ev.getMessage().substring(0, pos)+"\"},{\"text\":\""+ChatColor.GREEN+"["+ChatColor.stripColor(GenericFunctions.GetItemName(ev.getPlayer().getEquipment().getItemInMainHand()))+ChatColor.GREEN+"]"+ChatColor.WHITE+"\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\""+GenericFunctions.GetItemName(ev.getPlayer().getEquipment().getItemInMainHand())+"\n"+WorldShop.GetItemInfo(ev.getPlayer().getEquipment().getItemInMainHand()).replace("\"", "\\\"")+"\"}},{\"text\":\""+ev.getMessage().substring(pos)+"\"}]"); + ev.setCancelled(true); } - } - int pos = -1; - log(ev.getMessage()+" "+ev.getMessage().indexOf("[]"),5); - if (ev.getMessage().indexOf("[]")>-1) { - pos = ev.getMessage().indexOf("[]"); - ev.setMessage(ev.getMessage().replace("[]", "")); - log("pos is "+pos+" message is: {"+ev.getMessage()+"}",5); - DiscordMessageSender.sendRawMessageDiscord("**"+ev.getPlayer().getName()+"** "+ev.getMessage().substring(0, pos)+"**["+ChatColor.stripColor(GenericFunctions.GetItemName(ev.getPlayer().getEquipment().getItemInMainHand()))+"]**"+"\n```"+WorldShop.GetItemInfo(ev.getPlayer().getEquipment().getItemInMainHand())+"```\n"+ev.getMessage().substring(pos)); - Bukkit.dispatchCommand(Bukkit.getConsoleSender(),"tellraw @a [\"\",{\"text\":\"<"+ev.getPlayer().getName()+"> \"},{\"text\":\""+ev.getMessage().substring(0, pos)+"\"},{\"text\":\""+ChatColor.GREEN+"["+ChatColor.stripColor(GenericFunctions.GetItemName(ev.getPlayer().getEquipment().getItemInMainHand()))+ChatColor.GREEN+"]"+ChatColor.WHITE+"\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\""+GenericFunctions.GetItemName(ev.getPlayer().getEquipment().getItemInMainHand())+"\n"+WorldShop.GetItemInfo(ev.getPlayer().getEquipment().getItemInMainHand()).replace("\"", "\\\"")+"\"}},{\"text\":\""+ev.getMessage().substring(pos)+"\"}]"); - ev.setCancelled(true); + //Bukkit.dispatchCommand(Bukkit.getConsoleSender(),"tellraw @a [\"\",{\"text\":\""+ChatColor.GREEN+"[Item]"+ChatColor.WHITE+"\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\""+(ev.getPlayer().getEquipment().getItemInMainHand().getType())+"\"}},{\"text\":\" "+ev.getMessage().substring(0, pos)+" \"}]"); } - //Bukkit.dispatchCommand(Bukkit.getConsoleSender(),"tellraw @a [\"\",{\"text\":\""+ChatColor.GREEN+"[Item]"+ChatColor.WHITE+"\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\""+(ev.getPlayer().getEquipment().getItemInMainHand().getType())+"\"}},{\"text\":\" "+ev.getMessage().substring(0, pos)+" \"}]"); - } } @@ -1186,40 +1367,9 @@ public class TwosideKeeper extends JavaPlugin implements Listener { 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); - //See if a drop entity is already here. - boolean item_here=false; - Collection entities = ev.getPlayer().getWorld().getNearbyEntities(newloc, 1, 1, 1); - for (int i=0;i0) { + 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. @@ -1620,39 +1811,6 @@ public class TwosideKeeper extends JavaPlugin implements Listener { } } } - //((Player)ev.getEntity()).setSaturation(((Player)ev.getEntity()).getSaturation()+1.0f); - //We will never use saturation to heal. - } - } - - @EventHandler(priority=EventPriority.LOW) - public void onFoodLevelChange(FoodLevelChangeEvent ev) { - if (ev.getEntityType()==EntityType.PLAYER) { - Player p = (Player)ev.getEntity(); - if (p.getFoodLevel()p.getMaxHealth()) { - p.setHealth(p.getMaxHealth()); - } else { - p.setHealth(p.getHealth()+FOOD_HEAL_AMT); - } - } - p.setSaturation(p.getSaturation()*2); - } - if (p.getFoodLevel()>ev.getFoodLevel()) { - //Find the player that is losing food level. - for (int i=0;i0) { - pd.saturation--; - ev.setFoodLevel(ev.getFoodLevel()+1); - log("Saturation level is now "+(pd.saturation)+". Food level is now "+p.getFoodLevel(),4); - } - } - } - } } } @@ -2202,6 +2360,18 @@ public class TwosideKeeper extends JavaPlugin implements Listener { } } } + + @EventHandler(priority=EventPriority.LOW) + public void onItemSpawn(ItemSpawnEvent ev) { + //If the item is of a rare type, we will highlight it for emphasis. + Item it = ev.getEntity(); + if ((Artifact.isArtifact(it.getItemStack()) && + !Artifact.isMysteriousEssence(it.getItemStack()) || + GenericFunctions.isRareItem(it.getItemStack()))) { + it.setCustomName((it.getItemStack().getItemMeta().hasDisplayName())?it.getItemStack().getItemMeta().getDisplayName():GenericFunctions.UserFriendlyMaterialName(it.getItemStack())); + it.setCustomNameVisible(true); + } + } /** * RECYCLING CENTER CODE! @@ -2211,8 +2381,8 @@ public class TwosideKeeper extends JavaPlugin implements Listener { Item i = ev.getEntity(); //If the item is a display item, respawn it. - if (i.getCustomName()!=null) { - if (hasShopSignAttached(i.getLocation().add(0,-0.5,-0.5).getBlock())) { + if (i!=null && i.getCustomName()!=null) { + if (WorldShop.hasShopSignAttached(i.getLocation().add(0,-0.5,-0.5).getBlock())) { Item e = (Item)(i.getWorld().dropItemNaturally(i.getLocation(), i.getItemStack())); e.setCustomName(i.getCustomName()); e.setGlowing(i.isGlowing()); @@ -2613,6 +2783,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { if (m.getType()==EntityType.ZOMBIE && MonsterController.isZombieLeader(m)) { ev.setDroppedExp(ev.getDroppedExp()*2); + dropmult+=0.4; } if (m.getType()==EntityType.GUARDIAN || m.getType()==EntityType.SKELETON) { @@ -2717,16 +2888,20 @@ public class TwosideKeeper extends JavaPlugin implements Listener { ItemStack raresword = new ItemStack(Material.STONE_SWORD); ItemMeta sword_meta = raresword.getItemMeta(); sword_meta.setDisplayName(ChatColor.AQUA+""+ChatColor.BOLD+"Mega Stone Sword"); + raresword.setItemMeta(sword_meta); + raresword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, ((int)(Math.random()*6)+5)); + raresword.addUnsafeEnchantment(Enchantment.DAMAGE_ARTHROPODS, ((int)(Math.random()*6)+5)); + raresword.addUnsafeEnchantment(Enchantment.DAMAGE_UNDEAD, ((int)(Math.random()*6)+5)); if (Math.random()<0.1) { sword_meta.setDisplayName(ChatColor.AQUA+""+ChatColor.BOLD+"Hardened Mega Stone Sword"); List lore = new ArrayList(); lore.add(ChatColor.GRAY+"Breaks Remaining: "+ChatColor.YELLOW+"2"); sword_meta.setLore(lore); + raresword.setItemMeta(sword_meta); + raresword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 10); + raresword.addUnsafeEnchantment(Enchantment.DAMAGE_ARTHROPODS, 10); + raresword.addUnsafeEnchantment(Enchantment.DAMAGE_UNDEAD, 10); } - raresword.setItemMeta(sword_meta); - raresword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 10); - raresword.addUnsafeEnchantment(Enchantment.DAMAGE_ARTHROPODS, 10); - raresword.addUnsafeEnchantment(Enchantment.DAMAGE_UNDEAD, 10); ev.getDrops().add(raresword); } if (Math.random()<0.00390625*dropmult) { @@ -2760,39 +2935,36 @@ public class TwosideKeeper extends JavaPlugin implements Listener { ItemStack raresword = new ItemStack(Material.IRON_SWORD); ItemMeta sword_meta = raresword.getItemMeta(); sword_meta.setDisplayName(ChatColor.AQUA+""+ChatColor.BOLD+"Mega Iron Sword"); + raresword.setItemMeta(sword_meta); + raresword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, ((int)(Math.random()*4)+7)); + raresword.addUnsafeEnchantment(Enchantment.DAMAGE_ARTHROPODS, ((int)(Math.random()*4)+7)); + raresword.addUnsafeEnchantment(Enchantment.DAMAGE_UNDEAD, ((int)(Math.random()*4)+7)); if (Math.random()<0.1) { sword_meta.setDisplayName(ChatColor.AQUA+""+ChatColor.BOLD+"Hardened Mega Iron Sword"); List lore = new ArrayList(); lore.add(ChatColor.GRAY+"Breaks Remaining: "+ChatColor.YELLOW+((int)(Math.random()*6)+2)); sword_meta.setLore(lore); + raresword.setItemMeta(sword_meta); + raresword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 10); + raresword.addUnsafeEnchantment(Enchantment.DAMAGE_ARTHROPODS, 10); + raresword.addUnsafeEnchantment(Enchantment.DAMAGE_UNDEAD, 10); } - raresword.setItemMeta(sword_meta); - raresword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 10); - raresword.addUnsafeEnchantment(Enchantment.DAMAGE_ARTHROPODS, 10); - raresword.addUnsafeEnchantment(Enchantment.DAMAGE_UNDEAD, 10); ev.getDrops().add(raresword); - } - if (Math.random() lore = new ArrayList(); - lore.add(ChatColor.GRAY+"Breaks Remaining: "+ChatColor.YELLOW+((int)(Math.random()*6)+2)); - sword_meta.setLore(lore); + ev.getDrops().add(raresword); } - raresword.setItemMeta(sword_meta); - raresword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 10); - raresword.addUnsafeEnchantment(Enchantment.DAMAGE_ARTHROPODS, 10); - raresword.addUnsafeEnchantment(Enchantment.DAMAGE_UNDEAD, 10); - raresword.addUnsafeEnchantment(Enchantment.DURABILITY, 10); - ev.getDrops().add(raresword); } if (Math.random() lore = new ArrayList(); @@ -2800,20 +2972,27 @@ public class TwosideKeeper extends JavaPlugin implements Listener { lore.add(ChatColor.GRAY+"Twice as strong"); lore.add(ChatColor.GRAY+"Breaks Remaining: "+ChatColor.YELLOW+((int)(Math.random()*6)+2)); sword_meta.setLore(lore); + raresword.setItemMeta(sword_meta); + raresword.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 10); + raresword.addUnsafeEnchantment(Enchantment.PROTECTION_EXPLOSIONS, 10); + raresword.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, 10); + raresword.addUnsafeEnchantment(Enchantment.PROTECTION_FIRE, 10); + raresword.addUnsafeEnchantment(Enchantment.PROTECTION_PROJECTILE, 10); + raresword.addUnsafeEnchantment(Enchantment.DURABILITY, 10); } - raresword.setItemMeta(sword_meta); - raresword.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 10); - raresword.addUnsafeEnchantment(Enchantment.PROTECTION_EXPLOSIONS, 10); - raresword.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, 10); - raresword.addUnsafeEnchantment(Enchantment.PROTECTION_FIRE, 10); - raresword.addUnsafeEnchantment(Enchantment.PROTECTION_PROJECTILE, 10); - raresword.addUnsafeEnchantment(Enchantment.DURABILITY, 10); ev.getDrops().add(raresword); } if (Math.random() lore = new ArrayList(); @@ -2821,20 +3000,27 @@ public class TwosideKeeper extends JavaPlugin implements Listener { lore.add(ChatColor.GRAY+"Twice as strong"); lore.add(ChatColor.GRAY+"Breaks Remaining: "+ChatColor.YELLOW+((int)(Math.random()*6)+2)); sword_meta.setLore(lore); + raresword.setItemMeta(sword_meta); + raresword.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 10); + raresword.addUnsafeEnchantment(Enchantment.PROTECTION_EXPLOSIONS, 10); + raresword.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, 10); + raresword.addUnsafeEnchantment(Enchantment.PROTECTION_FIRE, 10); + raresword.addUnsafeEnchantment(Enchantment.PROTECTION_PROJECTILE, 10); + raresword.addUnsafeEnchantment(Enchantment.DURABILITY, 10); } - raresword.setItemMeta(sword_meta); - raresword.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 10); - raresword.addUnsafeEnchantment(Enchantment.PROTECTION_EXPLOSIONS, 10); - raresword.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, 10); - raresword.addUnsafeEnchantment(Enchantment.PROTECTION_FIRE, 10); - raresword.addUnsafeEnchantment(Enchantment.PROTECTION_PROJECTILE, 10); - raresword.addUnsafeEnchantment(Enchantment.DURABILITY, 10); ev.getDrops().add(raresword); } if (Math.random() lore = new ArrayList(); @@ -2842,20 +3028,27 @@ public class TwosideKeeper extends JavaPlugin implements Listener { lore.add(ChatColor.GRAY+"Twice as strong"); lore.add(ChatColor.GRAY+"Breaks Remaining: "+ChatColor.YELLOW+((int)(Math.random()*6)+2)); sword_meta.setLore(lore); + raresword.setItemMeta(sword_meta); + raresword.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 10); + raresword.addUnsafeEnchantment(Enchantment.PROTECTION_EXPLOSIONS, 10); + raresword.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, 10); + raresword.addUnsafeEnchantment(Enchantment.PROTECTION_FIRE, 10); + raresword.addUnsafeEnchantment(Enchantment.PROTECTION_PROJECTILE, 10); + raresword.addUnsafeEnchantment(Enchantment.DURABILITY, 10); } - raresword.setItemMeta(sword_meta); - raresword.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 10); - raresword.addUnsafeEnchantment(Enchantment.PROTECTION_EXPLOSIONS, 10); - raresword.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, 10); - raresword.addUnsafeEnchantment(Enchantment.PROTECTION_FIRE, 10); - raresword.addUnsafeEnchantment(Enchantment.PROTECTION_PROJECTILE, 10); - raresword.addUnsafeEnchantment(Enchantment.DURABILITY, 10); ev.getDrops().add(raresword); } if (Math.random() lore = new ArrayList(); @@ -2863,88 +3056,122 @@ public class TwosideKeeper extends JavaPlugin implements Listener { lore.add(ChatColor.GRAY+"Twice as strong"); lore.add(ChatColor.GRAY+"Breaks Remaining: "+ChatColor.YELLOW+((int)(Math.random()*6)+2)); sword_meta.setLore(lore); + raresword.setItemMeta(sword_meta); + raresword.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 10); + raresword.addUnsafeEnchantment(Enchantment.PROTECTION_EXPLOSIONS, 10); + raresword.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, 10); + raresword.addUnsafeEnchantment(Enchantment.PROTECTION_FIRE, 10); + raresword.addUnsafeEnchantment(Enchantment.PROTECTION_PROJECTILE, 10); + raresword.addUnsafeEnchantment(Enchantment.DURABILITY, 10); } - raresword.setItemMeta(sword_meta); - raresword.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 10); - raresword.addUnsafeEnchantment(Enchantment.PROTECTION_EXPLOSIONS, 10); - raresword.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, 10); - raresword.addUnsafeEnchantment(Enchantment.PROTECTION_FIRE, 10); - raresword.addUnsafeEnchantment(Enchantment.PROTECTION_PROJECTILE, 10); - raresword.addUnsafeEnchantment(Enchantment.DURABILITY, 10); ev.getDrops().add(raresword); } if (Math.random() lore = new ArrayList(); lore.add(ChatColor.GRAY+"Breaks Remaining: "+ChatColor.YELLOW+((int)(Math.random()*6)+2)); sword_meta.setLore(lore); + raresword.setItemMeta(sword_meta); + raresword.addUnsafeEnchantment(Enchantment.DIG_SPEED, 10); + raresword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 10); + raresword.addUnsafeEnchantment(Enchantment.LOOT_BONUS_BLOCKS, 10); + raresword.addUnsafeEnchantment(Enchantment.KNOCKBACK, 1); + raresword.addUnsafeEnchantment(Enchantment.DURABILITY, 10); } - raresword.setItemMeta(sword_meta); - raresword.addUnsafeEnchantment(Enchantment.DIG_SPEED, 10); - raresword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 10); - raresword.addUnsafeEnchantment(Enchantment.LOOT_BONUS_BLOCKS, 10); - raresword.addUnsafeEnchantment(Enchantment.KNOCKBACK, 1); - raresword.addUnsafeEnchantment(Enchantment.DURABILITY, 10); ev.getDrops().add(raresword); } if (Math.random() lore = new ArrayList(); lore.add(ChatColor.GRAY+"Breaks Remaining: "+ChatColor.YELLOW+((int)(Math.random()*6)+2)); sword_meta.setLore(lore); + raresword.setItemMeta(sword_meta); + raresword.addUnsafeEnchantment(Enchantment.DIG_SPEED, 10); + raresword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 10); + raresword.addUnsafeEnchantment(Enchantment.LOOT_BONUS_MOBS, 10); + raresword.addUnsafeEnchantment(Enchantment.KNOCKBACK, 1); + raresword.addUnsafeEnchantment(Enchantment.DURABILITY, 10); } - raresword.setItemMeta(sword_meta); - raresword.addUnsafeEnchantment(Enchantment.DIG_SPEED, 10); - raresword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 10); - raresword.addUnsafeEnchantment(Enchantment.LOOT_BONUS_MOBS, 10); - raresword.addUnsafeEnchantment(Enchantment.KNOCKBACK, 1); - raresword.addUnsafeEnchantment(Enchantment.DURABILITY, 10); ev.getDrops().add(raresword); } if (Math.random() lore = new ArrayList(); lore.add(ChatColor.GRAY+"Breaks Remaining: "+ChatColor.YELLOW+((int)(Math.random()*6)+2)); sword_meta.setLore(lore); + raresword.setItemMeta(sword_meta); + raresword.addUnsafeEnchantment(Enchantment.DIG_SPEED, 10); + raresword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 10); + raresword.addUnsafeEnchantment(Enchantment.LOOT_BONUS_BLOCKS, 10); + raresword.addUnsafeEnchantment(Enchantment.KNOCKBACK, 1); + raresword.addUnsafeEnchantment(Enchantment.DURABILITY, 10); } raresword.setItemMeta(sword_meta); - raresword.addUnsafeEnchantment(Enchantment.DIG_SPEED, 10); - raresword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 10); - raresword.addUnsafeEnchantment(Enchantment.LOOT_BONUS_BLOCKS, 10); - raresword.addUnsafeEnchantment(Enchantment.KNOCKBACK, 1); - raresword.addUnsafeEnchantment(Enchantment.DURABILITY, 10); ev.getDrops().add(raresword); } if (Math.random() lore = new ArrayList(); lore.add(ChatColor.GRAY+"Breaks Remaining: "+ChatColor.YELLOW+((int)(Math.random()*6)+2)); sword_meta.setLore(lore); + raresword.setItemMeta(sword_meta); + raresword.addUnsafeEnchantment(Enchantment.DIG_SPEED, 10); + raresword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 10); + raresword.addUnsafeEnchantment(Enchantment.LOOT_BONUS_MOBS, 10); + raresword.addUnsafeEnchantment(Enchantment.KNOCKBACK, 10); + raresword.addUnsafeEnchantment(Enchantment.DURABILITY, 10); } + ev.getDrops().add(raresword); + } + if (Math.random()0) { + //It did, we are going to release those items. + ItemStack drop = shop.GetItem(); + int dropAmt = shop.GetStoredAmount(); + while (dropAmt>0) { + if (dropAmt>shop.GetItem().getMaxStackSize()) { + drop.setAmount(shop.GetItem().getMaxStackSize()); + ev.getPlayer().getWorld().dropItemNaturally(ev.getPlayer().getLocation(), drop).setPickupDelay(0); + dropAmt-=shop.GetItem().getMaxStackSize(); + } else { + drop.setAmount(dropAmt); + ev.getPlayer().getWorld().dropItemNaturally(ev.getPlayer().getLocation(), drop).setPickupDelay(0); + dropAmt=0; + } + } + //ev.getPlayer().getLocation().getWorld().dropItemNaturally(ev.getPlayer().getLocation(), drop).setPickupDelay(0); + } + //Remove the itemstack that represented this item. + Collection nearby = ev.getPlayer().getWorld().getNearbyEntities(ev.getBlock().getLocation(), 3, 3, 3); + for (int i=0;i player_effects = p.getActivePotionEffects(); + for (int i=0;i0) { + partylevel = playerdata.get(j).partybonus; + log("Party level is "+partylevel,5); + if (partylevel>9) {partylevel=9;} + } + } + + int sharpnesslevel=0; + //Apply player enchantments next. + //Each sharpness level increases damage by 0.5. + //Both Smite and Bane of Arthropods increases damage by 1.0 per level. + if (p.getEquipment().getItemInMainHand()!=null) { + if (p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.DAMAGE_ALL)>0) { + sharpnesslevel+=p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.DAMAGE_ALL); + log("Player "+p.getName()+" has Sharpness "+p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.DAMAGE_ALL)+".",5); + } else + if (target!=null) { + if ((target.getType()==EntityType.ZOMBIE || target.getType()==EntityType.PIG_ZOMBIE || + target.getType()==EntityType.WITHER || target.getType()==EntityType.SKELETON) && + p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.DAMAGE_UNDEAD)>0) { + sharpnesslevel+=p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.DAMAGE_UNDEAD)*2; + log("Player "+p.getName()+" has Smite "+p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.DAMAGE_UNDEAD)+".",5); + } else + if ((target.getType()==EntityType.SPIDER || target.getType()==EntityType.CAVE_SPIDER || + target.getType()==EntityType.SILVERFISH || target.getType()==EntityType.ENDERMITE) && + p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.DAMAGE_ARTHROPODS)>0) { + sharpnesslevel+=p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.DAMAGE_ARTHROPODS)*2; + log("Player "+p.getName()+" has Bane of Arthropods "+p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.DAMAGE_ARTHROPODS)+".",5); + } + } + } + + return (basedmg+(sharpnesslevel*0.5)) + /((10-partylevel)*0.1) + /((10-strengthlevel)*0.1) + *((10-weaknesslevel)*0.1); + } + + public void DealCalculatedDamage(ItemStack weapon, LivingEntity p, LivingEntity target) { + //Deals custom calculated damage to a given target. + //Because we do not want to use Minecraft's built-in combat system, we will + //create our own. + double basedmg = CalculateWeaponDamage(p, target); + //Enchantments! //Check for Protection enchantment. @@ -4469,9 +4810,6 @@ public class TwosideKeeper extends JavaPlugin implements Listener { //Now apply resistances if any. //Resistance effect reduces damage by 10% per level of resistance. int resistlevel = 0; - int strengthlevel = 0; - int weaknesslevel = 0; - int partylevel = 0; Collection target_effects = target.getActivePotionEffects(); for (int i=0;i player_effects = p.getActivePotionEffects(); - for (int i=0;i0) { - partylevel = playerdata.get(j).partybonus; - log("Party level is "+partylevel,5); - if (partylevel>9) {partylevel=9;} - } - } - - int sharpnesslevel=0; - //Apply player enchantments next. - //Each sharpness level increases damage by 0.5. - //Both Smite and Bane of Arthropods increases damage by 1.0 per level. - if (p.getEquipment().getItemInMainHand()!=null) { - if (p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.DAMAGE_ALL)>0) { - sharpnesslevel+=p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.DAMAGE_ALL); - log("Player "+p.getName()+" has Sharpness "+p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.DAMAGE_ALL)+".",5); - } else - if ((target.getType()==EntityType.ZOMBIE || target.getType()==EntityType.PIG_ZOMBIE || - target.getType()==EntityType.WITHER || target.getType()==EntityType.SKELETON) && - p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.DAMAGE_UNDEAD)>0) { - sharpnesslevel+=p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.DAMAGE_ALL)*2; - log("Player "+p.getName()+" has Smite "+p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.DAMAGE_ALL)+".",5); - } else - if ((target.getType()==EntityType.SPIDER || target.getType()==EntityType.CAVE_SPIDER || - target.getType()==EntityType.SILVERFISH || target.getType()==EntityType.ENDERMITE) && - p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.DAMAGE_UNDEAD)>0) { - sharpnesslevel+=p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.DAMAGE_ALL)*2; - log("Player "+p.getName()+" has Bane of Arthropods "+p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.DAMAGE_ALL)+".",5); - } - } - boolean hasShield=false; //Check if our enemy has a shield. @@ -4538,14 +4828,9 @@ public class TwosideKeeper extends JavaPlugin implements Listener { } final double dmgamt = ( - basedmg - +sharpnesslevel*0.5 - -(basedmg*(dmgreduction/100.0d)) + basedmg-(basedmg*(dmgreduction/100.0d)) ) *((10-resistlevel)*0.1) - /((10-strengthlevel)*0.1) - *((10-weaknesslevel)*0.1) - /((10-partylevel)*0.1) *((100-protectionlevel)*0.01) *((hasShield)?0.95:1.00); //Calculated damage amount. @@ -4647,27 +4932,6 @@ public class TwosideKeeper extends JavaPlugin implements Listener { return finaldmg; } - public boolean hasShopSignAttached(Block b) { - //Returns true if there is a shop sign attached to this block. - //Look on all four sides relative to this block. - log("Reference block is "+b.getLocation().toString()+" of type "+b.getType(),5); - for (int x=-1;x<=1;x++) { - for (int z=-1;z<=1;z++) { - if ((x!=0 || z!=0) && Math.abs(x)!=Math.abs(z)) { - log("This is a "+b.getLocation().add(x,0.5,z).getBlock().getType(),5); - if (b.getLocation().add(x,0,z).getBlock().getType()==Material.WALL_SIGN) { - Sign s = (Sign)(b.getLocation().add(x,0,z).getBlock().getState()); - //See if this sign is a world shop. - if (WorldShop.IsWorldSign(s)) { - return true; - } - } - } - } - } - return false; - } - /** * Removes amt amount of items from a player's inventory, given * an item. @@ -4692,7 +4956,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { } public ChatColor GetHeartColor(int colorval) { - switch (colorval) { + switch (colorval % 10) { case 0:{ return ChatColor.DARK_GRAY; } diff --git a/src/sig/plugin/TwosideKeeper/WorldShopManager.java b/src/sig/plugin/TwosideKeeper/WorldShopManager.java index 7715864..df70fd7 100644 --- a/src/sig/plugin/TwosideKeeper/WorldShopManager.java +++ b/src/sig/plugin/TwosideKeeper/WorldShopManager.java @@ -36,23 +36,36 @@ public class WorldShopManager { * @param owner Owner of the shop. */ public WorldShop CreateWorldShop(Sign s, ItemStack item, int amt, double price, String owner) { + //Convert the sign. + return CreateWorldShop(s,item,amt,price,owner,false); + } + + public WorldShop CreateWorldShop(Sign s, ItemStack item, int amt, double price, String owner, boolean purchaseshop) { //Convert the sign. String[] lines = s.getLines(); List sign_lines = new ArrayList(); - WorldShop newshop = new WorldShop(item, amt, price, owner, TwosideKeeper.WORLD_SHOP_ID); - if (lines[0].equalsIgnoreCase("shop")) { - UpdateSign(newshop, TwosideKeeper.WORLD_SHOP_ID, s); + WorldShop newshop = new WorldShop(item, amt, 0, price, owner, TwosideKeeper.WORLD_SHOP_ID); + if (lines[0].equalsIgnoreCase("shop") || lines[0].equalsIgnoreCase("buyshop")) { + UpdateSign(newshop, TwosideKeeper.WORLD_SHOP_ID, s,purchaseshop); } TwosideKeeper.WORLD_SHOP_ID++; return newshop; } - public void UpdateSign(WorldShop shop, int id, Sign s) { + public void UpdateSign(WorldShop shop, int id, Sign s, boolean purchaseshop) { //Convert the sign. String[] lines = s.getLines(); List sign_lines = new ArrayList(); //Create a shop out of this. - sign_lines.add(ChatColor.BLUE+"-- SHOP --"); + if (purchaseshop) { + if (shop.GetStoredAmount()>0) { + sign_lines.add(ChatColor.YELLOW+""+ChatColor.BOLD+"-BUYING SHOP-"); + } else { + sign_lines.add(ChatColor.BLUE+"- BUYING SHOP -"); + } + } else { + sign_lines.add(ChatColor.BLUE+"-- SHOP --"); + } if (shop.GetItem().hasItemMeta() && shop.GetItem().getItemMeta().hasDisplayName()) { sign_lines.add(shop.GetItem().getItemMeta().getDisplayName()); @@ -78,7 +91,7 @@ public class WorldShopManager { config = new File(TwosideKeeper.filesave,"worldshop.data"); FileConfiguration workable = YamlConfiguration.loadConfiguration(config); - return new WorldShop(workable.getItemStack("item"+id),workable.getInt("amt"+id),workable.getDouble("item_price"+id),workable.getString("owner"+id),id); + return new WorldShop(workable.getItemStack("item"+id),workable.getInt("amt"+id),workable.getInt("storedamt"+id),workable.getDouble("item_price"+id),workable.getString("owner"+id),id); } public void SaveWorldShopData(WorldShop shop) { @@ -92,6 +105,7 @@ public class WorldShopManager { workable.set("item_price"+id,shop.GetUnitPrice()); workable.set("amt"+id,shop.GetAmount()); workable.set("owner"+id,shop.GetOwner()); + workable.set("storedamt"+id,shop.GetStoredAmount()); try { workable.save(config); @@ -151,10 +165,13 @@ public class WorldShopManager { public void RemoveSession(WorldShopSession ss) { sessions.remove(ss); } - + public void AddNewPurchase(String owner, Player purchaser, ItemStack item, double price, int amt) { purchases.add(new ShopPurchase(owner, purchaser, item, price, amt)); } + public void AddNewPurchase(String owner, Player purchaser, ItemStack item, double price, int amt, boolean sell) { + purchases.add(new ShopPurchase(owner, purchaser, item, price, amt, sell)); + } public boolean PlayerHasPurchases(Player p) { for (int i=0;i