WorldShops are now only able to be created on Chests and Trapped Chests.

World shops now use the inventory of the chest the sign is on, no longer
do the items exist virtually. Added some new ways to get Mysterious
Essence. Fixed Zombie Reinforcement algorithm. Disabled Artifact
crafting recipes (except for upgrade/downgrade crafting recipes) in
preparation for a future Artifact patch. Loot has been tinkered with to
make getting tools a lot more rare. Armor is a lot more common.
This commit is contained in:
sigonasr2 2016-07-03 21:48:53 -05:00
parent e670b07554
commit ce0dc8c206
12 changed files with 602 additions and 176 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.4r2 version: 3.4.6
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.

View File

@ -33,7 +33,7 @@ public class ChargeZombie {
for (int z=-radius;z<radius+1;z++) { for (int z=-radius;z<radius+1;z++) {
if (!BlockUtils.isExplosionProof(m.getLocation().add(x,y,z).getBlock().getType()) || if (!BlockUtils.isExplosionProof(m.getLocation().add(x,y,z).getBlock().getType()) ||
m.getLocation().add(x,y,z).getBlock().getType()==Material.OBSIDIAN) { m.getLocation().add(x,y,z).getBlock().getType()==Material.OBSIDIAN) {
if (!(y==0 && m.getTarget().getLocation().getY()>m.getLocation().getY())) { //Player is higher than zombie. Don't break blocks in front of it. Climb up them. if (!(y==0 && m.getTarget().getLocation().getY()>m.getLocation().getY()) || !m.getLocation().add(x,y,z).getBlock().getType().isSolid()) { //Player is higher than zombie. Don't break blocks in front of it. Climb up them. Unless it's lava.
if (!(y<0 && (m.getTarget().getLocation().getY()>m.getLocation().getY()-1))) { //Player is lower than zombie. Break blocks below it to get to the player. if (!(y<0 && (m.getTarget().getLocation().getY()>m.getLocation().getY()-1))) { //Player is lower than zombie. Break blocks below it to get to the player.
boolean brokeliquid = false; boolean brokeliquid = false;
//Break it. //Break it.
@ -43,11 +43,12 @@ public class ChargeZombie {
m.getLocation().add(x,y,z).getBlock().getType()==Material.LAVA || m.getLocation().add(x,y,z).getBlock().getType()==Material.LAVA ||
m.getLocation().add(x,y,z).getBlock().getType()==Material.STATIONARY_LAVA) { m.getLocation().add(x,y,z).getBlock().getType()==Material.STATIONARY_LAVA) {
brokeliquid=true; brokeliquid=true;
if (m.getLocation().add(x,y,z).getBlock().getType()==Material.STATIONARY_LAVA) {
m.getLocation().add(x,y,z).getBlock().setType(Material.OBSIDIAN);
m.getLocation().getWorld().playSound(m.getLocation().add(x,y,z),Sound.BLOCK_FIRE_EXTINGUISH, 1f, 1f);
} }
if (brokeliquid) { }
m.getLocation().getWorld().playSound(m.getLocation().add(x,y,z),Sound.BLOCK_WATER_AMBIENT, 0.03f, 0.5f); if (!brokeliquid) {
//m.getLocation().getWorld().playSound(m.getLocation().add(x,y,z),Sound.BLOCK_FIRE_EXTINGUISH, 0.03f, 0.5f);
} else {
m.getLocation().getWorld().playSound(m.getLocation().add(x,y,z),Sound.BLOCK_STONE_BREAK, 1.0f, 1.0f); m.getLocation().getWorld().playSound(m.getLocation().add(x,y,z),Sound.BLOCK_STONE_BREAK, 1.0f, 1.0f);
} }
m.getLocation().add(x,y,z).getBlock().breakNaturally(); m.getLocation().add(x,y,z).getBlock().breakNaturally();

View File

@ -496,6 +496,9 @@ public class GenericFunctions {
case SIGN_POST:{ case SIGN_POST:{
return "Sign"; return "Sign";
} }
case WALL_SIGN:{
return "Sign";
}
case SKULL_ITEM:{ case SKULL_ITEM:{
return "Skull"; return "Skull";
} }
@ -1167,6 +1170,51 @@ public class GenericFunctions {
} }
} }
/**
* This function will return the number of items of this type
* that exist in an inventory.
* @param it
* @param item
* @return
*/
public static int CountItems(Inventory it, ItemStack item) {
int totalcount=0;
for (int i=0;i<it.getSize();i++) {
if (it.getItem(i)!=null &&
it.getItem(i).isSimilar(item)) {
totalcount+=it.getItem(i).getAmount();
}
}
return totalcount;
}
/**
* This function will return the amount of empty space that can
* be filled with the specified item for the inventory.
* Useful for buy shops.
* @param it
* @param item
* @return
*/
public static int CountEmptySpace(Inventory it, ItemStack item) {
int totalcount=0;
for (int i=0;i<it.getSize();i++) {
if (it.getItem(i)!=null &&
(it.getItem(i).getType()==Material.AIR ||
it.getItem(i).isSimilar(item))) {
if (it.getItem(i).getAmount()!=item.getMaxStackSize()) {
totalcount+=item.getMaxStackSize()-it.getItem(i).getAmount();
} else {
//TwosideKeeper.log("This is equivalent to max stack size of "+item.getMaxStackSize(), 2);
//totalcount+=item.getMaxStackSize();
}
} else if (it.getItem(i)==null) {
totalcount+=item.getMaxStackSize();
}
}
return totalcount;
}
/** /**
* This function will return the number of items of this type * This function will return the number of items of this type
* that exist in your inventory. It will not include your * that exist in your inventory. It will not include your
@ -1176,14 +1224,7 @@ public class GenericFunctions {
* @return * @return
*/ */
public static int CountItems(Player p, ItemStack item) { public static int CountItems(Player p, ItemStack item) {
int totalcount=0; return CountItems(p.getInventory(),item);
for (int i=0;i<p.getInventory().getSize();i++) {
if (p.getInventory().getItem(i)!=null &&
p.getInventory().getItem(i).isSimilar(item)) {
totalcount+=p.getInventory().getItem(i).getAmount();
}
}
return totalcount;
} }
public static ItemStack convertToHardenedPiece(ItemStack item, int breaks) { public static ItemStack convertToHardenedPiece(ItemStack item, int breaks) {
@ -1248,6 +1289,7 @@ public class GenericFunctions {
item.getType().toString().contains("AXE") || item.getType().toString().contains("AXE") ||
item.getType().toString().contains("SWORD") || item.getType().toString().contains("SWORD") ||
item.getType().toString().contains("HOE") || item.getType().toString().contains("HOE") ||
item.getType().toString().contains("FISHING_ROD") ||
item.getType().toString().contains("BOW")) { item.getType().toString().contains("BOW")) {
return true; return true;
} else { } else {

View File

@ -130,7 +130,7 @@ public class Loot {
item.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, GetEnchantmentLevels(item.getType(),hardened)); item.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, GetEnchantmentLevels(item.getType(),hardened));
item.addUnsafeEnchantment(Enchantment.DURABILITY, GetEnchantmentLevels(item.getType(),hardened)); item.addUnsafeEnchantment(Enchantment.DURABILITY, GetEnchantmentLevels(item.getType(),hardened));
item.addUnsafeEnchantment(Enchantment.LUCK, GetEnchantmentLevels(item.getType(),hardened)); item.addUnsafeEnchantment(Enchantment.LUCK, GetEnchantmentLevels(item.getType(),hardened));
item.addUnsafeEnchantment(Enchantment.LURE, GetEnchantmentLevels(item.getType(),hardened)); item.addUnsafeEnchantment(Enchantment.LURE, (int)(((Math.random()*3)+2)*((hardened)?HARDENED_ENCHANT_MULT:1)));
} else { } else {
//Generic Random Enchantments. //Generic Random Enchantments.
for (int i=0;i<Enchantment.values().length;i++) { for (int i=0;i<Enchantment.values().length;i++) {

View File

@ -239,7 +239,15 @@ public enum MonsterDifficulty {
LootStructure ls = lootlist[(int)((Math.random())*lootlist.length)]; LootStructure ls = lootlist[(int)((Math.random())*lootlist.length)];
if (GenericFunctions.isEquip(new ItemStack(ls.GetMaterial()))) { if (GenericFunctions.isEquip(new ItemStack(ls.GetMaterial()))) {
//Turn it into a Mega Piece. //Turn it into a Mega Piece.
if (GenericFunctions.isTool(new ItemStack(ls.GetMaterial()))) {
if (Math.random()<=0.1) {
return Loot.GenerateMegaPiece(ls.GetMaterial(), ls.GetHardened()); return Loot.GenerateMegaPiece(ls.GetMaterial(), ls.GetHardened());
} else {
return new ItemStack(ls.GetMaterial(),1,(short)(Math.random()*ls.GetMaterial().getMaxDurability()));
}
} else {
return Loot.GenerateMegaPiece(ls.GetMaterial(), ls.GetHardened());
}
} else { } else {
//Turn it into a normal item. //Turn it into a normal item.
return new ItemStack(ls.GetMaterial(),ls.GetAmount()); return new ItemStack(ls.GetMaterial(),ls.GetAmount());

View File

@ -12,6 +12,8 @@ import org.bukkit.DyeColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.Chest;
import org.bukkit.block.DoubleChest;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.block.banner.Pattern; import org.bukkit.block.banner.Pattern;
import org.bukkit.block.banner.PatternType; import org.bukkit.block.banner.PatternType;
@ -21,6 +23,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BannerMeta; import org.bukkit.inventory.meta.BannerMeta;
import org.bukkit.inventory.meta.BookMeta; import org.bukkit.inventory.meta.BookMeta;
@ -497,9 +500,20 @@ public class WorldShop {
return sb.toString(); return sb.toString();
} }
public static boolean isPurchaseShopSign(Sign s) {
if (isWorldShopSign(s) &&
s.getLine(0).equalsIgnoreCase(ChatColor.BLUE+"- BUYING SHOP -") ||
s.getLine(0).equalsIgnoreCase(ChatColor.YELLOW+""+ChatColor.BOLD+"-BUYING SHOP-")) {
return true;
} else {
return false;
}
}
public static boolean isWorldShopSign(Sign s) { public static boolean isWorldShopSign(Sign s) {
if (s.getLine(0).equalsIgnoreCase(ChatColor.BLUE+"-- SHOP --") || if (s.getLine(0).equalsIgnoreCase(ChatColor.BLUE+"-- SHOP --") ||
s.getLine(0).equalsIgnoreCase(ChatColor.BLUE+"- BUYING SHOP -")) { s.getLine(0).equalsIgnoreCase(ChatColor.BLUE+"- BUYING SHOP -") ||
s.getLine(0).equalsIgnoreCase(ChatColor.YELLOW+""+ChatColor.BOLD+"-BUYING SHOP-")) {
return true; return true;
} else { } else {
return false; return false;
@ -533,6 +547,151 @@ public class WorldShop {
return false; return false;
} }
public static boolean shopSignExists(Location block) {
return !(grabShopSign(block)==null);
}
public static Sign grabShopSign(Location block) {
//Look for a sign in all directions.
boolean found=false;
Block signblock = null;
Block signblock2 = null;
for (int i=-1;i<2;i++) {
for (int j=-1;j<2;j++) {
if (i!=0^j!=0) {
Block testblock = block.getBlock().getRelative(i,0,j);
if (testblock.getType().equals(block.getBlock().getType())) {
//We found a double chest.
signblock2=testblock;
TwosideKeeper.log("Found a double chest @ "+i+","+j,5);
}
if (testblock.getType()==Material.WALL_SIGN) {
TwosideKeeper.log("This might be a shop sign "+i+","+j,5);
//This might be a world shop sign. Check.
Sign s = (Sign)(testblock.getState());
//See if the attached block is this block.
org.bukkit.material.Sign s1 = (org.bukkit.material.Sign)(testblock.getState().getData());
if (testblock.getLocation().getBlock().getRelative(s1.getAttachedFace()).getLocation().equals(block) //We want to make sure the sign is attached to this block.
&& WorldShop.isWorldShopSign(s)) {
//This is a shop sign. We found it.
signblock = testblock;
}
}
}
}
}
if (signblock!=null) {
//We will now return it.
TwosideKeeper.log("------------",5);
return (Sign)signblock.getState();
} else if (signblock2!=null) {
//Check in all directions of the connected double chest for a shop sign.
for (int i=-1;i<2;i++) {
for (int j=-1;j<2;j++) {
if (i!=0^j!=0) {
Block testblock = signblock2.getRelative(i,0,j);
if (testblock.getType()==Material.WALL_SIGN) {
TwosideKeeper.log("(2) This might be a shop sign "+i+","+j,5);
//This might be a world shop sign. Check.
Sign s = (Sign)(testblock.getState());
org.bukkit.material.Sign s1 = (org.bukkit.material.Sign)(testblock.getState().getData());
if (testblock.getLocation().getBlock().getRelative(s1.getAttachedFace()).getLocation().equals(signblock2.getLocation()) //We want to make sure the sign is attached to this block.
&& WorldShop.isWorldShopSign(s)) {
//This is a shop sign. We found it.
TwosideKeeper.log("------------",5);
return (Sign)testblock.getState();
}
}
}
}
}
}
TwosideKeeper.log("------------",5);
return null;
}
public static Block getBlockShopSignAttachedTo(Sign s) {
org.bukkit.material.Sign s1 = (org.bukkit.material.Sign)(s.getBlock().getState().getData());
return s.getBlock().getRelative(s1.getAttachedFace());
}
public static void updateShopSign(Location shopblock) {
//This will first attempt to grab the shop sign.
//Upon finding it, we will load up the shop and update it to the correct value inside the chest inventory.
Sign s = grabShopSign(shopblock);
if (s!=null) {
TwosideKeeper.log("There is a shop sign here",5);
//Load up the shop.
WorldShop shop = TwosideKeeper.TwosideShops.LoadWorldShopData(s);
//Now detect the amount inside the double chest.
Chest c = (Chest)shopblock.getBlock().getState();
Inventory chest_inventory = c.getInventory();
int amt = 0;
if (isPurchaseShopSign(s)) {
amt = GenericFunctions.CountEmptySpace(chest_inventory, shop.GetItem());
shop.amt = amt;
shop.storedamt = 0;
} else {
amt = GenericFunctions.CountItems(chest_inventory, shop.GetItem());
shop.amt = amt;
}
TwosideKeeper.TwosideShops.SaveWorldShopData(shop);
TwosideKeeper.log("There are "+amt+" of "+shop.GetItem().toString(),5);
TwosideKeeper.TwosideShops.UpdateSign(shop, s);
}
}
public static void spawnShopItem(Location signloc, WorldShop shop) {
org.bukkit.material.Sign s = (org.bukkit.material.Sign)signloc.getBlock().getState().getData();
Block shopblock = signloc.getBlock().getRelative(s.getAttachedFace());
//See if there's already a shop item here.
boolean item_here=false;
Collection<Entity> entities = signloc.getWorld().getNearbyEntities(signloc, 0.2, 0.2, 0.2);
for (int i=0;i<entities.size();i++) {
Entity e = Iterables.get(entities, i);
if (e.getType()==EntityType.DROPPED_ITEM) {
Item it = (Item)e;
ItemStack checkdrop = shop.GetItem().clone();
checkdrop = Artifact.convert(checkdrop);
checkdrop.removeEnchantment(Enchantment.LUCK);
ItemMeta m = checkdrop.getItemMeta();
List<String> lore = new ArrayList<String>();
if (m.hasLore()) {
lore = m.getLore();
}
lore.add("WorldShop Display Item");
m.setLore(lore);
checkdrop.setItemMeta(m);
if (
it.getItemStack().isSimilar(shop.GetItem())
) {
item_here=true;
}
}
}
if (!item_here) {
TwosideKeeper.log("Spawning item!",5);
ItemStack i = shop.GetItem().clone();
ItemStack drop = Artifact.convert(i);
drop.removeEnchantment(Enchantment.LUCK);
ItemMeta m = drop.getItemMeta();
List<String> lore = m.getLore();
lore.add("WorldShop Display Item");
m.setLore(lore);
drop.setItemMeta(m);
Item it = signloc.getWorld().dropItem(shopblock.getLocation().add(0.5, 1.5, 0.5), drop);
it.setPickupDelay(999999999);
it.setVelocity(new Vector(0,0,0));
it.setCustomName(""+shop.getID());
it.setCustomNameVisible(false);
it.setInvulnerable(true);
//it.setGlowing(true);
//it.teleport(ev.getClickedBlock().getLocation().add(-ev.getBlockFace().getModX()+0.5, -ev.getBlockFace().getModY()+1.5, -ev.getBlockFace().getModZ()+0.5));
}
}
public static void spawnShopItem(PlayerInteractEvent ev, Location loc, WorldShop shop) { public static void spawnShopItem(PlayerInteractEvent ev, Location loc, WorldShop shop) {
//See if a drop entity is already here. //See if a drop entity is already here.
boolean item_here=false; boolean item_here=false;
@ -566,7 +725,7 @@ public class WorldShop {
lore.add("WorldShop Display Item"); lore.add("WorldShop Display Item");
m.setLore(lore); m.setLore(lore);
drop.setItemMeta(m); drop.setItemMeta(m);
Item it = ev.getPlayer().getWorld().dropItemNaturally(ev.getClickedBlock().getLocation().add(-ev.getBlockFace().getModX()+0.5, -ev.getBlockFace().getModY()+1.5, -ev.getBlockFace().getModZ()+0.5), drop); Item it = ev.getPlayer().getWorld().dropItem(ev.getClickedBlock().getLocation().add(-ev.getBlockFace().getModX()+0.5, -ev.getBlockFace().getModY()+1.5, -ev.getBlockFace().getModZ()+0.5), drop);
it.setPickupDelay(999999999); it.setPickupDelay(999999999);
it.setVelocity(new Vector(0,0,0)); it.setVelocity(new Vector(0,0,0));
it.setCustomName(""+shop.getID()); it.setCustomName(""+shop.getID());

View File

@ -65,6 +65,9 @@ public class WorldShopSession {
public void SetSession(SessionState type) { public void SetSession(SessionState type) {
status = type; status = type;
} }
public void SetSign(Sign s) {
this.s=s;
}
public void UpdateTime() { public void UpdateTime() {
time = TwosideKeeper.getServerTickTime(); time = TwosideKeeper.getServerTickTime();
} }

View File

@ -34,9 +34,16 @@ public class MonsterController {
/** /**
* @return Returns false if this spawn is not allowed. * @return Returns false if this spawn is not allowed.
*/ */
public static boolean MobHeightControl(LivingEntity ent) { public static boolean MobHeightControl(LivingEntity ent, boolean minion) {
//Modify spawning algorithm. //Modify spawning algorithm.
int ylv = ent.getLocation().getBlockY(); int ylv = ent.getLocation().getBlockY();
if (minion) {
ylv+=16;
ent.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,999999,1));
ent.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE,999999,1));
ent.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE,999999,4));
ent.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION,999999,4));
}
if (isZombieLeader(ent)) { if (isZombieLeader(ent)) {
//Zombie leaders have faster movement. //Zombie leaders have faster movement.
ent.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,999999,1)); ent.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,999999,1));

View File

@ -509,6 +509,8 @@ public class Recipes {
newrecipe.addIngredient(Material.CLAY_BALL); newrecipe.addIngredient(Material.CLAY_BALL);
Bukkit.addRecipe(newrecipe); Bukkit.addRecipe(newrecipe);
} }
}
public static void Initialize_ArtifactHelper_Recipes() {
ShapelessRecipe upgraderecipe = new ShapelessRecipe(Artifact.createArtifactItem(ArtifactItem.DIVINE_ESSENCE)); ShapelessRecipe upgraderecipe = new ShapelessRecipe(Artifact.createArtifactItem(ArtifactItem.DIVINE_ESSENCE));
upgraderecipe.addIngredient(Material.NETHER_STAR); upgraderecipe.addIngredient(Material.NETHER_STAR);
upgraderecipe.addIngredient(Material.SUGAR); upgraderecipe.addIngredient(Material.SUGAR);

View File

@ -30,6 +30,7 @@ import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Arrow; import org.bukkit.entity.Arrow;
import org.bukkit.entity.Bat;
import org.bukkit.entity.ComplexLivingEntity; import org.bukkit.entity.ComplexLivingEntity;
import org.bukkit.entity.Creeper; import org.bukkit.entity.Creeper;
import org.bukkit.entity.EnderDragon; import org.bukkit.entity.EnderDragon;
@ -41,6 +42,7 @@ import org.bukkit.entity.Horse;
import org.bukkit.entity.Horse.Variant; import org.bukkit.entity.Horse.Variant;
import org.bukkit.entity.HumanEntity; import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.entity.LightningStrike;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Monster; import org.bukkit.entity.Monster;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -103,7 +105,9 @@ import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.event.server.ServerCommandEvent; import org.bukkit.event.server.ServerCommandEvent;
import org.bukkit.event.server.ServerListPingEvent; import org.bukkit.event.server.ServerListPingEvent;
import org.bukkit.event.vehicle.VehicleCreateEvent; import org.bukkit.event.vehicle.VehicleCreateEvent;
import org.bukkit.event.vehicle.VehicleDestroyEvent;
import org.bukkit.event.vehicle.VehicleExitEvent; import org.bukkit.event.vehicle.VehicleExitEvent;
import org.bukkit.event.weather.LightningStrikeEvent;
import org.bukkit.event.world.WorldSaveEvent; import org.bukkit.event.world.WorldSaveEvent;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.InventoryView;
@ -174,7 +178,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
public static double HEADSHOT_ACC=1.0f; //How accurate headshots have to be. Lower values means more leniency on headshots. Higher values means more strict. public static double HEADSHOT_ACC=1.0f; //How accurate headshots have to be. Lower values means more leniency on headshots. Higher values means more strict.
public static double COMMON_DROP_RATE=0.1; // 1/10 chance public static double COMMON_DROP_RATE=0.1; // 1/10 chance
public static double RARE_DROP_RATE=0.0078125; // 1/128 chance public static double RARE_DROP_RATE=0.0078125; // 1/128 chance
public static double LEGENDARY_DROP_RATE=0.00390625; // 1/256 chance public static double LEGENDARY_DROP_RATE=0.001953125; // 1/512 chance
public static int PARTY_CHUNK_SIZE=16; //The number of chunks each party spans. public static int PARTY_CHUNK_SIZE=16; //The number of chunks each party spans.
public double XP_CONVERSION_RATE=0.01; //How much money per exp point? public double XP_CONVERSION_RATE=0.01; //How much money per exp point?
public static int WORLD_SHOP_ID=0; //The shop ID number we are on. public static int WORLD_SHOP_ID=0; //The shop ID number we are on.
@ -184,7 +188,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
public static File filesave; public static File filesave;
public static HashMap playerdata; public static HashMap playerdata;
public static SpleefManager TwosideSpleefGames; public static SpleefManager TwosideSpleefGames;
public WorldShopManager TwosideShops; public static WorldShopManager TwosideShops;
public static MysteriousEssenceLogger EssenceLogger; //The logger for Essences. public static MysteriousEssenceLogger EssenceLogger; //The logger for Essences.
public int TeamCounter = 0; public int TeamCounter = 0;
@ -237,7 +241,8 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
sig.plugin.TwosideKeeper.Recipes.Initialize_ItemDeconstruction_Recipes(); sig.plugin.TwosideKeeper.Recipes.Initialize_ItemDeconstruction_Recipes();
sig.plugin.TwosideKeeper.Recipes.Initialize_WoolRecolor_Recipes(); sig.plugin.TwosideKeeper.Recipes.Initialize_WoolRecolor_Recipes();
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();
sig.plugin.TwosideKeeper.Recipes.Initialize_ArtifactHelper_Recipes();
Bukkit.createWorld(new WorldCreator("ItemCube")); Bukkit.createWorld(new WorldCreator("ItemCube"));
@ -946,7 +951,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
final WorldShopSession current_session = TwosideShops.GetSession(ev.getPlayer()); final WorldShopSession current_session = TwosideShops.GetSession(ev.getPlayer());
current_session.UpdateTime(); //Make sure our session does not expire. current_session.UpdateTime(); //Make sure our session does not expire.
switch (current_session.GetSessionType()) { switch (current_session.GetSessionType()) {
case CREATE: /*case CREATE: //OBSOLETE.
if (ev.getMessage().length()<=9 && isNumeric(ev.getMessage()) && isInteger(ev.getMessage())) { if (ev.getMessage().length()<=9 && isNumeric(ev.getMessage()) && isInteger(ev.getMessage())) {
int amt = Integer.parseInt(ev.getMessage()); int amt = Integer.parseInt(ev.getMessage());
if (amt<=GenericFunctions.CountItems(ev.getPlayer(), current_session.getItem()) && amt>0) { if (amt<=GenericFunctions.CountItems(ev.getPlayer(), current_session.getItem()) && amt>0) {
@ -965,8 +970,8 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
ev.getPlayer().sendMessage("That is not a valid number!"); ev.getPlayer().sendMessage("That is not a valid number!");
TwosideShops.RemoveSession(ev.getPlayer()); TwosideShops.RemoveSession(ev.getPlayer());
} }
break; break;*/
case BUY_CREATE: /*case BUY_CREATE: //OBSOLETE.
if (ev.getMessage().length()<=9 && isNumeric(ev.getMessage()) && isInteger(ev.getMessage())) { if (ev.getMessage().length()<=9 && isNumeric(ev.getMessage()) && isInteger(ev.getMessage())) {
int amt = Integer.parseInt(ev.getMessage()); int amt = Integer.parseInt(ev.getMessage());
if (amt>0) { if (amt>0) {
@ -981,7 +986,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
ev.getPlayer().sendMessage("That is not a valid number!"); ev.getPlayer().sendMessage("That is not a valid number!");
TwosideShops.RemoveSession(ev.getPlayer()); TwosideShops.RemoveSession(ev.getPlayer());
} }
break; break;*/
case PRICE: case PRICE:
if (isNumeric(ev.getMessage())) { if (isNumeric(ev.getMessage())) {
final DecimalFormat df = new DecimalFormat("0.00"); final DecimalFormat df = new DecimalFormat("0.00");
@ -991,14 +996,13 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() { Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
@Override @Override
public void run() { public void run() {
TwosideShops.SaveWorldShopData( WorldShop newshop = TwosideShops.CreateWorldShop(current_session.GetSign(), current_session.getItem(), current_session.getAmt(), Double.parseDouble(df.format(amt)), ev.getPlayer().getName());
TwosideShops.CreateWorldShop(current_session.GetSign(), current_session.getItem(), current_session.getAmt(), Double.parseDouble(df.format(amt)), ev.getPlayer().getName()) WorldShop.spawnShopItem(current_session.GetSign().getLocation(), newshop);
); TwosideShops.SaveWorldShopData(newshop);
RemoveItemAmount(ev.getPlayer(), current_session.getItem(), current_session.getAmt()); //RemoveItemAmount(ev.getPlayer(), current_session.getItem(), current_session.getAmt()); //We now handle items via chest.
TwosideShops.RemoveSession(ev.getPlayer()); TwosideShops.RemoveSession(ev.getPlayer());
} }
},1); },1);
} else { } else {
if (amt>999999999999.99) { if (amt>999999999999.99) {
ev.getPlayer().sendMessage("You cannot sell an item for that ridiculous amount."); ev.getPlayer().sendMessage("You cannot sell an item for that ridiculous amount.");
@ -1021,9 +1025,9 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() { Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
@Override @Override
public void run() { public void run() {
TwosideShops.SaveWorldShopData( WorldShop newshop = TwosideShops.CreateWorldShop(current_session.GetSign(), current_session.getItem(), current_session.getAmt(), Double.parseDouble(df.format(amt)), ev.getPlayer().getName(),true);
TwosideShops.CreateWorldShop(current_session.GetSign(), current_session.getItem(), current_session.getAmt(), Double.parseDouble(df.format(amt)), ev.getPlayer().getName(),true) TwosideShops.SaveWorldShopData(newshop);
); WorldShop.spawnShopItem(current_session.GetSign().getLocation(), newshop);
TwosideShops.RemoveSession(ev.getPlayer()); TwosideShops.RemoveSession(ev.getPlayer());
} }
},1); },1);
@ -1053,7 +1057,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
TwosideShops.SaveWorldShopData(shop); TwosideShops.SaveWorldShopData(shop);
TwosideShops.UpdateSign(shop, TwosideShops.GetShopID(current_session.GetSign()), current_session.GetSign(),false); 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("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+":"); 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+"):");
current_session.SetSession(SessionState.UPDATE); current_session.SetSession(SessionState.UPDATE);
} else { } else {
@ -1103,7 +1107,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
if (shop.GetAmount()>0) { if (shop.GetAmount()>0) {
current_session.SetSession(SessionState.UPDATE); current_session.SetSession(SessionState.UPDATE);
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+":"); 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+"):");
} else { } else {
ev.getPlayer().sendMessage(ChatColor.DARK_BLUE+"Shop successfully updated!"); ev.getPlayer().sendMessage(ChatColor.DARK_BLUE+"Shop successfully updated!");
TwosideShops.RemoveSession(ev.getPlayer()); TwosideShops.RemoveSession(ev.getPlayer());
@ -1117,7 +1121,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
TwosideShops.RemoveSession(ev.getPlayer()); TwosideShops.RemoveSession(ev.getPlayer());
} }
break; break;
case BUY_EDIT: /*case BUY_EDIT: //LEGACY CODE.
if (ev.getMessage().length()<=9 && isNumeric(ev.getMessage()) && isInteger(ev.getMessage())) { if (ev.getMessage().length()<=9 && isNumeric(ev.getMessage()) && isInteger(ev.getMessage())) {
int amt = Integer.parseInt(ev.getMessage()); int amt = Integer.parseInt(ev.getMessage());
DecimalFormat df = new DecimalFormat("0.00"); DecimalFormat df = new DecimalFormat("0.00");
@ -1176,7 +1180,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
ev.getPlayer().sendMessage("That is not a valid number!"); ev.getPlayer().sendMessage("That is not a valid number!");
TwosideShops.RemoveSession(ev.getPlayer()); TwosideShops.RemoveSession(ev.getPlayer());
} }
break; break;*/
case UPDATE: case UPDATE:
if (isNumeric(ev.getMessage())) { if (isNumeric(ev.getMessage())) {
double amt = Double.parseDouble(ev.getMessage()); double amt = Double.parseDouble(ev.getMessage());
@ -1234,6 +1238,8 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
if (getPlayerMoney(ev.getPlayer())>=amt*shop.GetUnitPrice()) { if (getPlayerMoney(ev.getPlayer())>=amt*shop.GetUnitPrice()) {
ev.getPlayer().sendMessage(ChatColor.DARK_BLUE+"Successfully bought "+amt+" "+ChatColor.GREEN+shop.GetItemName()+ChatColor.WHITE+"!"); ev.getPlayer().sendMessage(ChatColor.DARK_BLUE+"Successfully bought "+amt+" "+ChatColor.GREEN+shop.GetItemName()+ChatColor.WHITE+"!");
shop.UpdateAmount(shop.GetAmount()-amt); shop.UpdateAmount(shop.GetAmount()-amt);
//We have to remove that amount from the chest shop.
final Chest c = (Chest)WorldShop.getBlockShopSignAttachedTo(current_session.GetSign()).getState();
ItemStack shopItem = shop.GetItem(); ItemStack shopItem = shop.GetItem();
int dropAmt = amt; int dropAmt = amt;
while (dropAmt>0) { while (dropAmt>0) {
@ -1244,6 +1250,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
@Override @Override
public void run() { public void run() {
ev.getPlayer().getWorld().dropItemNaturally(ev.getPlayer().getLocation(), dropitem).setPickupDelay(0); ev.getPlayer().getWorld().dropItemNaturally(ev.getPlayer().getLocation(), dropitem).setPickupDelay(0);
c.getInventory().removeItem(dropitem);
} }
},1); },1);
dropAmt-=shop.GetItem().getMaxStackSize(); dropAmt-=shop.GetItem().getMaxStackSize();
@ -1254,6 +1261,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
@Override @Override
public void run() { public void run() {
ev.getPlayer().getWorld().dropItemNaturally(ev.getPlayer().getLocation(), dropitem).setPickupDelay(0); ev.getPlayer().getWorld().dropItemNaturally(ev.getPlayer().getLocation(), dropitem).setPickupDelay(0);
c.getInventory().removeItem(dropitem);
} }
},1); },1);
dropAmt=0; dropAmt=0;
@ -1298,8 +1306,24 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
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+"!"); 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.UpdateAmount(shop.GetAmount()-amt);
shop.UpdateStoredAmount(shop.GetStoredAmount()+amt); shop.UpdateStoredAmount(shop.GetStoredAmount()+amt);
final Chest c = (Chest)WorldShop.getBlockShopSignAttachedTo(current_session.GetSign()).getState();
ItemStack shopItem = shop.GetItem(); ItemStack shopItem = shop.GetItem();
RemoveItemAmount(ev.getPlayer(),shop.GetItem(),amt); RemoveItemAmount(ev.getPlayer(),shop.GetItem(),amt);
//Add it to the chest.
int amt_to_add = amt;
while (amt_to_add>0) {
if (amt_to_add<shop.GetItem().getMaxStackSize()) {
ItemStack drop = shop.GetItem().clone();
drop.setAmount(amt_to_add);
c.getInventory().addItem(drop);
amt_to_add=0;
} else {
ItemStack drop = shop.GetItem().clone();
drop.setAmount(shop.GetItem().getMaxStackSize());
c.getInventory().addItem(drop);
amt_to_add-=shop.GetItem().getMaxStackSize();
}
}
TwosideShops.UpdateSign(shop, shopID, current_session.GetSign(),true); TwosideShops.UpdateSign(shop, shopID, current_session.GetSign(),true);
TwosideShops.SaveWorldShopData(shop); TwosideShops.SaveWorldShopData(shop);
TwosideShops.RemoveSession(ev.getPlayer()); TwosideShops.RemoveSession(ev.getPlayer());
@ -1413,6 +1437,22 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
},8); },8);
} }
//Check if we're allowed to open a shop chest.
if (ev.getAction()==Action.RIGHT_CLICK_BLOCK &&
(ev.getClickedBlock().getType()==Material.CHEST ||
ev.getClickedBlock().getType()==Material.TRAPPED_CHEST)) {
//Now check if it's a shop chest.
Sign shopsign = WorldShop.grabShopSign(ev.getClickedBlock().getLocation());
if (shopsign!=null) {
//Now grab the owner of the shop.
WorldShop shop = TwosideShops.LoadWorldShopData(shopsign);
if (!shop.GetOwner().equalsIgnoreCase(ev.getPlayer().getName())) {
ev.getPlayer().sendMessage("This shop belongs to "+ChatColor.LIGHT_PURPLE+shop.GetOwner()+ChatColor.WHITE+"! You cannot look at other's shops!");
ev.setCancelled(true);
}
}
}
//Check for a Malleable Base right-click. //Check for a Malleable Base right-click.
if ((ev.getAction()==Action.RIGHT_CLICK_AIR || if ((ev.getAction()==Action.RIGHT_CLICK_AIR ||
ev.getAction()==Action.RIGHT_CLICK_BLOCK) && ev.getAction()==Action.RIGHT_CLICK_BLOCK) &&
@ -1576,13 +1616,17 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
if (!fit) { if (!fit) {
ev.getPlayer().sendMessage(ChatColor.RED+"Attempted to store your items, not all of them could fit!"+ChatColor.WHITE+" Stored "+ChatColor.AQUA+count+ChatColor.WHITE+" items."); ev.getPlayer().sendMessage(ChatColor.RED+"Attempted to store your items, not all of them could fit!"+ChatColor.WHITE+" Stored "+ChatColor.AQUA+count+ChatColor.WHITE+" items.");
} else { } else {
if (count>0) {
ev.getPlayer().sendMessage("Stored "+ChatColor.AQUA+count+ChatColor.WHITE+" items inside the chest."); ev.getPlayer().sendMessage("Stored "+ChatColor.AQUA+count+ChatColor.WHITE+" items inside the chest.");
} }
}
virtualinventory.clear(); virtualinventory.clear();
//Save the Item Cube. //Save the Item Cube.
itemCube_saveConfig(itemcube_id,save_items); itemCube_saveConfig(itemcube_id,save_items);
//This may have been a shop. Update the shop too.
WorldShop.updateShopSign(ev.getClickedBlock().getLocation());
} }
} }
if (b!=null && (b.getType() == Material.SIGN || if (b!=null && (b.getType() == Material.SIGN ||
@ -1592,8 +1636,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
Sign s = (Sign)(b.getState()); Sign s = (Sign)(b.getState());
//Determine if this is a shop sign. //Determine if this is a shop sign.
if (b.getType()==Material.WALL_SIGN && if (b.getType()==Material.WALL_SIGN) { //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);
//Make sure it is on a chest. Or trapped chest. //Make sure it is on a chest. Or trapped chest.
org.bukkit.material.Sign s1 = (org.bukkit.material.Sign)(b.getState().getData()); org.bukkit.material.Sign s1 = (org.bukkit.material.Sign)(b.getState().getData());
@ -1601,21 +1644,28 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
if (chest.getType()==Material.CHEST || if (chest.getType()==Material.CHEST ||
chest.getType()==Material.TRAPPED_CHEST) { chest.getType()==Material.TRAPPED_CHEST) {
if (s.getLine(0).equalsIgnoreCase("shop")) { if (s.getLine(0).equalsIgnoreCase("shop")) {
if (!WorldShop.shopSignExists(chest.getLocation())) {
log("This is a shop sign.",5); log("This is a shop sign.",5);
//Create a new shop. //Create a new 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.CREATE, player, s); WorldShopSession ss = TwosideShops.AddSession(SessionState.PRICE, player, s);
player.sendMessage("Creating a shop to sell "+ChatColor.GREEN+GenericFunctions.GetItemName(item)+ChatColor.WHITE+"."); player.sendMessage("Creating a shop to sell "+ChatColor.GREEN+GenericFunctions.GetItemName(item)+ChatColor.WHITE+".");
int totalcount = 0; int totalcount = 0;
totalcount = GenericFunctions.CountItems(player, item); totalcount = GenericFunctions.CountItems(player, item);
log("We have "+totalcount+" items in our inventory.",4); log("We have "+totalcount+" items in our inventory.",4);
ss.SetItem(item); ss.SetItem(item);
player.sendMessage("How many of this item do you want to sell? "+ChatColor.GREEN+"(MAX: "+ChatColor.YELLOW+totalcount+ChatColor.GREEN+")"); //player.sendMessage("Specify how much "+ChatColor.GREEN+"(MAX: "+ChatColor.YELLOW+totalcount+ChatColor.GREEN+")");
Chest c = (Chest)chest.getState();
ss.SetAmt(GenericFunctions.CountItems(c.getInventory(), item));
player.sendMessage("Input how much each "+ChatColor.GREEN+GenericFunctions.GetItemName(ss.getItem())+ChatColor.WHITE+" will cost:");
} 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 sell in your hand."); + " with the item you want to sell in your hand.");
} }
} else {
player.sendMessage(ChatColor.RED+"Sorry! "+ChatColor.WHITE+" A shop has already been setup here!");
}
} else } else
if (s.getLine(0).equalsIgnoreCase(ChatColor.BLUE+"-- SHOP --")) { if (s.getLine(0).equalsIgnoreCase(ChatColor.BLUE+"-- SHOP --")) {
log("This is a buy shop sign.",5); log("This is a buy shop sign.",5);
@ -1628,8 +1678,10 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
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+"."); //OBSOLETE!
TwosideShops.AddSession(SessionState.EDIT, player, s); DecimalFormat df = new DecimalFormat("0.00");
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+"):");
TwosideShops.AddSession(SessionState.UPDATE, player, s);
} else { } else {
if (shop.GetAmount()>0) { 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())+")"); 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())+")");
@ -1644,19 +1696,26 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} }
} else } else
if (s.getLine(0).equalsIgnoreCase("buyshop")) { if (s.getLine(0).equalsIgnoreCase("buyshop")) {
if (!WorldShop.shopSignExists(chest.getLocation())) {
//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_PRICE, 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);
Chest c = (Chest)chest.getState();
ss.SetAmt(GenericFunctions.CountEmptySpace(c.getInventory(), item));
ss.SetItem(item); ss.SetItem(item);
player.sendMessage("How many of this item do you want to buy?"); player.sendMessage("Input how much you will pay for each "+ChatColor.GREEN+GenericFunctions.GetItemName(ss.getItem())+ChatColor.WHITE+":");
//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 {
player.sendMessage(ChatColor.RED+"Sorry! "+ChatColor.WHITE+" A shop has already been setup here!");
}
} 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-")) {
@ -1669,8 +1728,10 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
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+"."); DecimalFormat df = new DecimalFormat("0.00");
TwosideShops.AddSession(SessionState.BUY_EDIT, player, s); //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+".");
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+"):");
TwosideShops.AddSession(SessionState.BUY_UPDATE, player, s);
} else { } else {
if (shop.GetAmount()>0) { 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()))+")"); 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()))+")");
@ -1981,6 +2042,13 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
itemCube_saveConfig(id,itemcube_contents); itemCube_saveConfig(id,itemcube_contents);
pd.isViewingItemCube=false; pd.isViewingItemCube=false;
} }
if (ev.getInventory().getLocation()!=null) {
Block b = ev.getInventory().getLocation().getBlock();
if (b.getType()==Material.CHEST || b.getType()==Material.TRAPPED_CHEST) {
//This is a valid shop. Now update the shop sign for it.
WorldShop.updateShopSign(b.getLocation());
}
}
} }
} }
@ -2557,14 +2625,24 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
@EventHandler(priority=EventPriority.LOW) @EventHandler(priority=EventPriority.LOW)
public void MonsterSpawnEvent(CreatureSpawnEvent ev) { public void MonsterSpawnEvent(CreatureSpawnEvent ev) {
log("Reason for spawn: "+ev.getSpawnReason().toString(),5);
if ((ev.getSpawnReason().equals(SpawnReason.NATURAL) || if ((ev.getSpawnReason().equals(SpawnReason.NATURAL) ||
ev.getSpawnReason().equals(SpawnReason.SPAWNER_EGG)) && ev.getSpawnReason().equals(SpawnReason.SPAWNER_EGG) ||
ev.getSpawnReason().equals(SpawnReason.REINFORCEMENTS)) &&
ev.getEntity() instanceof Monster) { ev.getEntity() instanceof Monster) {
if (!MonsterController.MobHeightControl(ev.getEntity())) { if (ev.getSpawnReason().equals(SpawnReason.REINFORCEMENTS)) {
//Remove this one and spawn another one.
Location loc = ev.getEntity().getLocation().clone();
Monster m = (Monster)loc.getWorld().spawnEntity(loc, EntityType.ZOMBIE);
m.setTarget(((Monster)ev.getEntity()).getTarget());
MonsterController.MobHeightControl(m,true);
ev.getEntity().remove();
} else
if (!MonsterController.MobHeightControl(ev.getEntity(),false)) {
ev.setCancelled(true); ev.setCancelled(true);
//This spawn was not allowed by the mob height controller. //This spawn was not allowed by the mob height controller.
} }
} else {
log("Reason for spawn: "+ev.getSpawnReason().toString(),4);
} }
if (ev.getLocation().getWorld().getName().equalsIgnoreCase("world") && if (ev.getLocation().getWorld().getName().equalsIgnoreCase("world") &&
ev.getEntityType()==EntityType.HORSE) { ev.getEntityType()==EntityType.HORSE) {
@ -2978,8 +3056,26 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} }
} }
@EventHandler(priority=EventPriority.LOW)
public void onLightningStrike(LightningStrikeEvent ev) {
LightningStrike lightning = ev.getLightning();
for (int i=0;i<4;i++) {
Item it = lightning.getLocation().getWorld().dropItemNaturally(lightning.getLocation().add(0,2,0), Artifact.createArtifactItem(ArtifactItem.MYSTERIOUS_ESSENCE));
it.setVelocity(new Vector(Math.random()*10-15,Math.random()*5,Math.random()*10-15));
//Make them move in a direction violently and spontaneously.
}
}
@EventHandler(priority=EventPriority.LOW) @EventHandler(priority=EventPriority.LOW)
public void monsterDeathEvent(final EntityDeathEvent ev) { public void monsterDeathEvent(final EntityDeathEvent ev) {
if (ev.getEntity() instanceof Bat) {
//Drop an essence.
if (Math.random()<=0.3) {
//Rarely drop a lost essence.
ev.getEntity().getLocation().getWorld().dropItemNaturally(ev.getEntity().getLocation(), Artifact.createArtifactItem(ArtifactItem.LOST_ESSENCE));
}
ev.getEntity().getLocation().getWorld().dropItemNaturally(ev.getEntity().getLocation(), Artifact.createArtifactItem(ArtifactItem.MYSTERIOUS_ESSENCE));
}
if (ev.getEntity() instanceof Monster) { if (ev.getEntity() instanceof Monster) {
List<ItemStack> droplist = ev.getDrops(); List<ItemStack> droplist = ev.getDrops();
@ -3162,9 +3258,17 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
log(p.getName()+" has broken block "+GenericFunctions.UserFriendlyMaterialName(new ItemStack(ev.getBlock().getType())),3); log(p.getName()+" has broken block "+GenericFunctions.UserFriendlyMaterialName(new ItemStack(ev.getBlock().getType())),3);
} }
if (ev.getBlock().getType()==Material.WALL_SIGN) { if (ev.getBlock().getType()==Material.WALL_SIGN ||
ev.getBlock().getType()==Material.CHEST ||
ev.getBlock().getType()==Material.TRAPPED_CHEST) {
//We're going to make sure if it's a shop or not. //We're going to make sure if it's a shop or not.
Sign s = (Sign)(ev.getBlock().getState()); Sign s = null;
if (ev.getBlock().getType()==Material.WALL_SIGN) {
s = (Sign)(ev.getBlock().getState());
} else {
s = WorldShop.grabShopSign(ev.getBlock().getLocation());
}
if (s!=null) {
if (s.getLine(0).equalsIgnoreCase(ChatColor.BLUE+"-- SHOP --")) { if (s.getLine(0).equalsIgnoreCase(ChatColor.BLUE+"-- SHOP --")) {
//This is a shop. Let's find out who the owner is. //This is a shop. Let's find out who the owner is.
int shopID = TwosideShops.GetShopID(s); int shopID = TwosideShops.GetShopID(s);
@ -3172,7 +3276,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
String owner = shop.GetOwner(); String owner = shop.GetOwner();
if (owner.equalsIgnoreCase(p.getName()) || p.isOp()) { if (owner.equalsIgnoreCase(p.getName()) || p.isOp()) {
//We are going to see if this shop had items in it. //We are going to see if this shop had items in it.
if (shop.GetAmount()>0) { /*if (shop.GetAmount()>0) { //LEGACY CODE.
//It did, we are going to release those items. //It did, we are going to release those items.
ItemStack drop = shop.GetItem(); ItemStack drop = shop.GetItem();
int dropAmt = shop.GetAmount(); int dropAmt = shop.GetAmount();
@ -3188,17 +3292,31 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} }
} }
//ev.getPlayer().getLocation().getWorld().dropItemNaturally(ev.getPlayer().getLocation(), drop).setPickupDelay(0); //ev.getPlayer().getLocation().getWorld().dropItemNaturally(ev.getPlayer().getLocation(), drop).setPickupDelay(0);
} }*/
//Remove the itemstack that represented this item. //Remove the itemstack that represented this item.
Collection<Entity> nearby = ev.getPlayer().getWorld().getNearbyEntities(ev.getBlock().getLocation(), 3, 3, 3); Collection<Entity> nearby = WorldShop.getBlockShopSignAttachedTo(s).getWorld().getNearbyEntities(WorldShop.getBlockShopSignAttachedTo(s).getLocation().add(0.5,0,0.5), 0.3, 1, 0.3);
for (int i=0;i<nearby.size();i++) { for (int i=0;i<nearby.size();i++) {
Entity e = Iterables.get(nearby, i); Entity e = Iterables.get(nearby, i);
if (e.getType()==EntityType.DROPPED_ITEM) { if (e.getType()==EntityType.DROPPED_ITEM) {
log("Found a drop.",5); log("Found a drop.",5);
Item it = (Item)e; Item it = (Item)e;
if (it.getItemStack().getType()==shop.GetItem().getType() &&
ItemStack checkdrop = shop.GetItem().clone();
checkdrop = Artifact.convert(checkdrop);
checkdrop.removeEnchantment(Enchantment.LUCK);
ItemMeta m = checkdrop.getItemMeta();
List<String> lore = new ArrayList<String>();
if (m.hasLore()) {
lore = m.getLore();
}
lore.add("WorldShop Display Item");
m.setLore(lore);
checkdrop.setItemMeta(m);
log("Comparing item "+it.getItemStack().toString()+" to "+checkdrop.toString(),2);
if (it.getItemStack().isSimilar(checkdrop) &&
Artifact.isArtifact(it.getItemStack())) { Artifact.isArtifact(it.getItemStack())) {
log("Same type.",5); log("Same type.",2);
e.remove(); e.remove();
e.setCustomNameVisible(false); e.setCustomNameVisible(false);
e.setCustomName(null); e.setCustomName(null);
@ -3220,7 +3338,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
String owner = shop.GetOwner(); String owner = shop.GetOwner();
if (owner.equalsIgnoreCase(p.getName()) || p.isOp()) { if (owner.equalsIgnoreCase(p.getName()) || p.isOp()) {
//We are going to see if this shop had items in it. //We are going to see if this shop had items in it.
if (shop.GetStoredAmount()>0) { /*if (shop.GetStoredAmount()>0) { //LEGACY CODE.
//It did, we are going to release those items. //It did, we are going to release those items.
ItemStack drop = shop.GetItem(); ItemStack drop = shop.GetItem();
int dropAmt = shop.GetStoredAmount(); int dropAmt = shop.GetStoredAmount();
@ -3236,17 +3354,30 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} }
} }
//ev.getPlayer().getLocation().getWorld().dropItemNaturally(ev.getPlayer().getLocation(), drop).setPickupDelay(0); //ev.getPlayer().getLocation().getWorld().dropItemNaturally(ev.getPlayer().getLocation(), drop).setPickupDelay(0);
} }*/
//Remove the itemstack that represented this item. //Remove the itemstack that represented this item.
Collection<Entity> nearby = ev.getPlayer().getWorld().getNearbyEntities(ev.getBlock().getLocation(), 3, 3, 3); Collection<Entity> nearby = WorldShop.getBlockShopSignAttachedTo(s).getWorld().getNearbyEntities(WorldShop.getBlockShopSignAttachedTo(s).getLocation().add(0.5,0,0.5), 0.3, 1, 0.3);
for (int i=0;i<nearby.size();i++) { for (int i=0;i<nearby.size();i++) {
Entity e = Iterables.get(nearby, i); Entity e = Iterables.get(nearby, i);
if (e.getType()==EntityType.DROPPED_ITEM) { if (e.getType()==EntityType.DROPPED_ITEM) {
log("Found a drop.",5); log("Found a drop.",5);
Item it = (Item)e; Item it = (Item)e;
if (it.getItemStack().getType()==shop.GetItem().getType() &&
Artifact.isArtifact(it.getItemStack())) { ItemStack checkdrop = shop.GetItem().clone();
log("Same type.",5); checkdrop = Artifact.convert(checkdrop);
checkdrop.removeEnchantment(Enchantment.LUCK);
ItemMeta m = checkdrop.getItemMeta();
List<String> lore = new ArrayList<String>();
if (m.hasLore()) {
lore = m.getLore();
}
lore.add("WorldShop Display Item");
m.setLore(lore);
checkdrop.setItemMeta(m);
log("Comparing item "+it.getItemStack().toString()+" to "+checkdrop.toString(),2);
if (it.getItemStack().isSimilar(checkdrop)) {
log("Same type.",2);
e.remove(); e.remove();
e.setCustomNameVisible(false); e.setCustomNameVisible(false);
e.setCustomName(null); e.setCustomName(null);
@ -3260,6 +3391,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
ev.setCancelled(true); ev.setCancelled(true);
} }
} }
}
} else { } else {
//Make sure there's no world sign on this block. //Make sure there's no world sign on this block.
if (WorldShop.hasShopSignAttached(ev.getBlock())) { if (WorldShop.hasShopSignAttached(ev.getBlock())) {
@ -3698,6 +3830,29 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} }
@EventHandler(priority=EventPriority.LOW)
public void MinecartBreakEvent(VehicleDestroyEvent ev) {
if (ev.getVehicle().getType()==EntityType.MINECART ||
ev.getVehicle().getType()==EntityType.MINECART_FURNACE ||
ev.getVehicle().getType()==EntityType.MINECART_TNT) {
ev.setCancelled(true);
ev.getVehicle().remove();
switch (ev.getVehicle().getType()) {
case MINECART:{
ev.getVehicle().getLocation().getWorld().dropItemNaturally(ev.getVehicle().getLocation(), new ItemStack(Material.MINECART));
}break;
case MINECART_FURNACE:{
ev.getVehicle().getLocation().getWorld().dropItemNaturally(ev.getVehicle().getLocation(), new ItemStack(Material.MINECART));
ev.getVehicle().getLocation().getWorld().dropItemNaturally(ev.getVehicle().getLocation(), new ItemStack(Material.FURNACE));
}break;
case MINECART_TNT:{
ev.getVehicle().getLocation().getWorld().dropItemNaturally(ev.getVehicle().getLocation(), new ItemStack(Material.MINECART));
ev.getVehicle().getLocation().getWorld().dropItemNaturally(ev.getVehicle().getLocation(), new ItemStack(Material.TNT));
}break;
}
}
}
@EventHandler(priority=EventPriority.LOW) @EventHandler(priority=EventPriority.LOW)
public void MinecartExitEvent(VehicleExitEvent ev) { public void MinecartExitEvent(VehicleExitEvent ev) {
if (ev.getExited() instanceof Player && if (ev.getExited() instanceof Player &&

View File

@ -52,7 +52,44 @@ public class WorldShopManager {
return newshop; return newshop;
} }
public void UpdateSign(WorldShop shop, int id, Sign s, boolean purchaseshop) { public static void UpdateSign(WorldShop shop, Sign s) {
//Convert the sign.
String[] lines = s.getLines();
List<String> sign_lines = new ArrayList<String>();
//Determine if it's a purchase shop by reading the sign.
boolean purchaseshop=false;
if (!lines[0].equalsIgnoreCase(ChatColor.BLUE+"-- SHOP --")) {
purchaseshop=true;
}
//Create a shop out of this.
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());
} else {
sign_lines.add(GenericFunctions.UserFriendlyMaterialName(shop.GetItem()));
}
DecimalFormat df = new DecimalFormat("0.00");
sign_lines.add("$"+df.format(shop.GetUnitPrice())+ChatColor.DARK_BLUE+" [x"+shop.GetAmount()+"]");
DecimalFormat df2 = new DecimalFormat("000000");
sign_lines.add(ChatColor.DARK_GRAY+df2.format(shop.getID()));
for (int i=0;i<4;i++) {
s.setLine(i, sign_lines.get(i));
}
s.update();
}
public static void UpdateSign(WorldShop shop, int id, Sign s, boolean purchaseshop) {
//Convert the sign. //Convert the sign.
String[] lines = s.getLines(); String[] lines = s.getLines();
List<String> sign_lines = new ArrayList<String>(); List<String> sign_lines = new ArrayList<String>();
@ -86,6 +123,10 @@ public class WorldShopManager {
return Integer.parseInt(s.getLines()[3].replace(ChatColor.DARK_GRAY+"", "")); return Integer.parseInt(s.getLines()[3].replace(ChatColor.DARK_GRAY+"", ""));
} }
public WorldShop LoadWorldShopData(Sign s) {
return LoadWorldShopData(GetShopID(s));
}
public WorldShop LoadWorldShopData(int id) { public WorldShop LoadWorldShopData(int id) {
File config; File config;
config = new File(TwosideKeeper.filesave,"worldshop.data"); config = new File(TwosideKeeper.filesave,"worldshop.data");
@ -142,10 +183,18 @@ public class WorldShopManager {
return -1; return -1;
} }
public WorldShopSession AddSession(SessionState type, Player p, Sign s) { public WorldShopSession AddSession(SessionState type, Player p, Sign s) {
//If the player is in a session, simply update the session type.
if (IsPlayerUsingTerminal(p)) {
UpdateSession(type,p);
WorldShopSession ss = GetSession(p);
ss.SetSign(s);
return ss;
} else {
WorldShopSession sss = new WorldShopSession(p, TwosideKeeper.getServerTickTime(), type, s); WorldShopSession sss = new WorldShopSession(p, TwosideKeeper.getServerTickTime(), type, s);
sessions.add(sss); sessions.add(sss);
return sss; return sss;
} }
}
public void UpdateSession(SessionState type, Player p) { public void UpdateSession(SessionState type, Player p) {
int term = GetPlayerTerminal(p); int term = GetPlayerTerminal(p);
if (term!=-1) { if (term!=-1) {