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.
dev
sigonasr2 9 years ago
parent e670b07554
commit ce0dc8c206
  1. BIN
      TwosideKeeper.jar
  2. 2
      src/plugin.yml
  3. 15
      src/sig/plugin/TwosideKeeper/ChargeZombie.java
  4. 58
      src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java
  5. 2
      src/sig/plugin/TwosideKeeper/HelperStructures/Loot.java
  6. 16
      src/sig/plugin/TwosideKeeper/HelperStructures/MonsterDifficulty.java
  7. 165
      src/sig/plugin/TwosideKeeper/HelperStructures/WorldShop.java
  8. 3
      src/sig/plugin/TwosideKeeper/HelperStructures/WorldShopSession.java
  9. 9
      src/sig/plugin/TwosideKeeper/MonsterController.java
  10. 2
      src/sig/plugin/TwosideKeeper/Recipes.java
  11. 449
      src/sig/plugin/TwosideKeeper/TwosideKeeper.java
  12. 57
      src/sig/plugin/TwosideKeeper/WorldShopManager.java

Binary file not shown.

@ -1,6 +1,6 @@
name: TwosideKeeper
main: sig.plugin.TwosideKeeper.TwosideKeeper
version: 3.4.4r2
version: 3.4.6
commands:
money:
description: Tells the player the amount of money they are holding.

@ -33,7 +33,7 @@ public class ChargeZombie {
for (int z=-radius;z<radius+1;z++) {
if (!BlockUtils.isExplosionProof(m.getLocation().add(x,y,z).getBlock().getType()) ||
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.
boolean brokeliquid = false;
//Break it.
@ -43,13 +43,14 @@ public class ChargeZombie {
m.getLocation().add(x,y,z).getBlock().getType()==Material.LAVA ||
m.getLocation().add(x,y,z).getBlock().getType()==Material.STATIONARY_LAVA) {
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_STONE_BREAK, 1.0f, 1.0f);
}
if (brokeliquid) {
m.getLocation().getWorld().playSound(m.getLocation().add(x,y,z),Sound.BLOCK_WATER_AMBIENT, 0.03f, 0.5f);
//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().add(x,y,z).getBlock().breakNaturally();
Utils.sendBlockBreakAnimation(null, new BlockPosition(m.getLocation().add(x,y,z).getBlockX(),m.getLocation().add(x,y,z).getBlockY(),m.getLocation().add(x,y,z).getBlockZ()), -1, Utils.seedRandomID(m.getLocation().add(x,y,z).getBlock()));
} else {

@ -496,6 +496,9 @@ public class GenericFunctions {
case SIGN_POST:{
return "Sign";
}
case WALL_SIGN:{
return "Sign";
}
case SKULL_ITEM:{
return "Skull";
}
@ -1169,22 +1172,60 @@ public class GenericFunctions {
/**
* This function will return the number of items of this type
* that exist in your inventory. It will not include your
* equipment.
* @param p
* that exist in an inventory.
* @param it
* @param item
* @return
*/
public static int CountItems(Player p, ItemStack item) {
public static int CountItems(Inventory it, ItemStack item) {
int totalcount=0;
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();
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
* that exist in your inventory. It will not include your
* equipment.
* @param p
* @param item
* @return
*/
public static int CountItems(Player p, ItemStack item) {
return CountItems(p.getInventory(),item);
}
public static ItemStack convertToHardenedPiece(ItemStack item, int breaks) {
if (item!=null && item.hasItemMeta()) {
@ -1248,6 +1289,7 @@ public class GenericFunctions {
item.getType().toString().contains("AXE") ||
item.getType().toString().contains("SWORD") ||
item.getType().toString().contains("HOE") ||
item.getType().toString().contains("FISHING_ROD") ||
item.getType().toString().contains("BOW")) {
return true;
} else {

@ -130,7 +130,7 @@ public class Loot {
item.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, GetEnchantmentLevels(item.getType(),hardened));
item.addUnsafeEnchantment(Enchantment.DURABILITY, 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 {
//Generic Random Enchantments.
for (int i=0;i<Enchantment.values().length;i++) {

@ -201,13 +201,13 @@ public enum MonsterDifficulty {
droplist.add(gen_loot);
switch (this) {
case DANGEROUS:
droplist.add(sig.plugin.TwosideKeeper.Artifact.createArtifactItem(ArtifactItem.ANCIENT_CORE));
droplist.add(sig.plugin.TwosideKeeper.Artifact.createArtifactItem(ArtifactItem.ANCIENT_CORE));
break;
case DEADLY:
droplist.add(sig.plugin.TwosideKeeper.Artifact.createArtifactItem(ArtifactItem.LOST_CORE));
droplist.add(sig.plugin.TwosideKeeper.Artifact.createArtifactItem(ArtifactItem.LOST_CORE));
break;
case HELLFIRE:
droplist.add(sig.plugin.TwosideKeeper.Artifact.createArtifactItem(ArtifactItem.DIVINE_CORE));
droplist.add(sig.plugin.TwosideKeeper.Artifact.createArtifactItem(ArtifactItem.DIVINE_CORE));
break;
case NORMAL:
droplist.add(sig.plugin.TwosideKeeper.Artifact.createArtifactItem(ArtifactItem.ARTIFACT_CORE));
@ -239,7 +239,15 @@ public enum MonsterDifficulty {
LootStructure ls = lootlist[(int)((Math.random())*lootlist.length)];
if (GenericFunctions.isEquip(new ItemStack(ls.GetMaterial()))) {
//Turn it into a Mega Piece.
return Loot.GenerateMegaPiece(ls.GetMaterial(), ls.GetHardened());
if (GenericFunctions.isTool(new ItemStack(ls.GetMaterial()))) {
if (Math.random()<=0.1) {
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 {
//Turn it into a normal item.
return new ItemStack(ls.GetMaterial(),ls.GetAmount());

@ -12,6 +12,8 @@ import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Chest;
import org.bukkit.block.DoubleChest;
import org.bukkit.block.Sign;
import org.bukkit.block.banner.Pattern;
import org.bukkit.block.banner.PatternType;
@ -21,6 +23,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BannerMeta;
import org.bukkit.inventory.meta.BookMeta;
@ -496,10 +499,21 @@ public class WorldShop {
}
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) {
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;
} else {
return false;
@ -533,6 +547,151 @@ public class WorldShop {
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) {
//See if a drop entity is already here.
boolean item_here=false;
@ -566,7 +725,7 @@ public class WorldShop {
lore.add("WorldShop Display Item");
m.setLore(lore);
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.setVelocity(new Vector(0,0,0));
it.setCustomName(""+shop.getID());

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

@ -34,9 +34,16 @@ public class MonsterController {
/**
* @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.
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)) {
//Zombie leaders have faster movement.
ent.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,999999,1));

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

@ -30,6 +30,7 @@ import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Bat;
import org.bukkit.entity.ComplexLivingEntity;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.EnderDragon;
@ -41,6 +42,7 @@ import org.bukkit.entity.Horse;
import org.bukkit.entity.Horse.Variant;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Item;
import org.bukkit.entity.LightningStrike;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Monster;
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.ServerListPingEvent;
import org.bukkit.event.vehicle.VehicleCreateEvent;
import org.bukkit.event.vehicle.VehicleDestroyEvent;
import org.bukkit.event.vehicle.VehicleExitEvent;
import org.bukkit.event.weather.LightningStrikeEvent;
import org.bukkit.event.world.WorldSaveEvent;
import org.bukkit.inventory.Inventory;
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 COMMON_DROP_RATE=0.1; // 1/10 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 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.
@ -184,7 +188,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
public static File filesave;
public static HashMap playerdata;
public static SpleefManager TwosideSpleefGames;
public WorldShopManager TwosideShops;
public static WorldShopManager TwosideShops;
public static MysteriousEssenceLogger EssenceLogger; //The logger for Essences.
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_WoolRecolor_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"));
@ -946,7 +951,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
final WorldShopSession current_session = TwosideShops.GetSession(ev.getPlayer());
current_session.UpdateTime(); //Make sure our session does not expire.
switch (current_session.GetSessionType()) {
case CREATE:
/*case CREATE: //OBSOLETE.
if (ev.getMessage().length()<=9 && isNumeric(ev.getMessage()) && isInteger(ev.getMessage())) {
int amt = Integer.parseInt(ev.getMessage());
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!");
TwosideShops.RemoveSession(ev.getPlayer());
}
break;
case BUY_CREATE:
break;*/
/*case BUY_CREATE: //OBSOLETE.
if (ev.getMessage().length()<=9 && isNumeric(ev.getMessage()) && isInteger(ev.getMessage())) {
int amt = Integer.parseInt(ev.getMessage());
if (amt>0) {
@ -981,7 +986,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
ev.getPlayer().sendMessage("That is not a valid number!");
TwosideShops.RemoveSession(ev.getPlayer());
}
break;
break;*/
case PRICE:
if (isNumeric(ev.getMessage())) {
final DecimalFormat df = new DecimalFormat("0.00");
@ -991,14 +996,13 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
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())
);
RemoveItemAmount(ev.getPlayer(), current_session.getItem(), current_session.getAmt());
WorldShop newshop = 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()); //We now handle items via chest.
TwosideShops.RemoveSession(ev.getPlayer());
}
},1);
} else {
if (amt>999999999999.99) {
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() {
@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)
);
WorldShop newshop = 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());
}
},1);
@ -1053,7 +1057,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
TwosideShops.SaveWorldShopData(shop);
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+":");
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);
} else {
@ -1103,7 +1107,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
if (shop.GetAmount()>0) {
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 {
ev.getPlayer().sendMessage(ChatColor.DARK_BLUE+"Shop successfully updated!");
TwosideShops.RemoveSession(ev.getPlayer());
@ -1117,7 +1121,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
TwosideShops.RemoveSession(ev.getPlayer());
}
break;
case BUY_EDIT:
/*case BUY_EDIT: //LEGACY CODE.
if (ev.getMessage().length()<=9 && isNumeric(ev.getMessage()) && isInteger(ev.getMessage())) {
int amt = Integer.parseInt(ev.getMessage());
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!");
TwosideShops.RemoveSession(ev.getPlayer());
}
break;
break;*/
case UPDATE:
if (isNumeric(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()) {
ev.getPlayer().sendMessage(ChatColor.DARK_BLUE+"Successfully bought "+amt+" "+ChatColor.GREEN+shop.GetItemName()+ChatColor.WHITE+"!");
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();
int dropAmt = amt;
while (dropAmt>0) {
@ -1244,6 +1250,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
@Override
public void run() {
ev.getPlayer().getWorld().dropItemNaturally(ev.getPlayer().getLocation(), dropitem).setPickupDelay(0);
c.getInventory().removeItem(dropitem);
}
},1);
dropAmt-=shop.GetItem().getMaxStackSize();
@ -1254,6 +1261,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
@Override
public void run() {
ev.getPlayer().getWorld().dropItemNaturally(ev.getPlayer().getLocation(), dropitem).setPickupDelay(0);
c.getInventory().removeItem(dropitem);
}
},1);
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+"!");
shop.UpdateAmount(shop.GetAmount()-amt);
shop.UpdateStoredAmount(shop.GetStoredAmount()+amt);
final Chest c = (Chest)WorldShop.getBlockShopSignAttachedTo(current_session.GetSign()).getState();
ItemStack shopItem = shop.GetItem();
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.SaveWorldShopData(shop);
TwosideShops.RemoveSession(ev.getPlayer());
@ -1413,6 +1437,22 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
},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.
if ((ev.getAction()==Action.RIGHT_CLICK_AIR ||
ev.getAction()==Action.RIGHT_CLICK_BLOCK) &&
@ -1576,13 +1616,17 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
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.");
} else {
ev.getPlayer().sendMessage("Stored "+ChatColor.AQUA+count+ChatColor.WHITE+" items inside the chest.");
if (count>0) {
ev.getPlayer().sendMessage("Stored "+ChatColor.AQUA+count+ChatColor.WHITE+" items inside the chest.");
}
}
virtualinventory.clear();
//Save the Item Cube.
itemCube_saveConfig(itemcube_id,save_items);
//This may have been a shop. Update the shop too.
WorldShop.updateShopSign(ev.getClickedBlock().getLocation());
}
}
if (b!=null && (b.getType() == Material.SIGN ||
@ -1592,8 +1636,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
Sign s = (Sign)(b.getState());
//Determine if this is a shop sign.
if (b.getType()==Material.WALL_SIGN &&
!TwosideShops.IsPlayerUsingTerminal(player)) { //Shop signs can only be wall signs.
if (b.getType()==Material.WALL_SIGN) { //Shop signs can only be wall signs.
log("This is a wall sign.",5);
//Make sure it is on a chest. Or trapped chest.
org.bukkit.material.Sign s1 = (org.bukkit.material.Sign)(b.getState().getData());
@ -1601,20 +1644,27 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
if (chest.getType()==Material.CHEST ||
chest.getType()==Material.TRAPPED_CHEST) {
if (s.getLine(0).equalsIgnoreCase("shop")) {
log("This is a shop sign.",5);
//Create a new shop.
ItemStack item = player.getEquipment().getItemInMainHand();
if (item.getType()!=Material.AIR) {
WorldShopSession ss = TwosideShops.AddSession(SessionState.CREATE, player, s);
player.sendMessage("Creating a shop to sell "+ChatColor.GREEN+GenericFunctions.GetItemName(item)+ChatColor.WHITE+".");
int totalcount = 0;
totalcount = GenericFunctions.CountItems(player, item);
log("We have "+totalcount+" items in our inventory.",4);
ss.SetItem(item);
player.sendMessage("How many of this item do you want to sell? "+ChatColor.GREEN+"(MAX: "+ChatColor.YELLOW+totalcount+ChatColor.GREEN+")");
if (!WorldShop.shopSignExists(chest.getLocation())) {
log("This is a shop sign.",5);
//Create a new shop.
ItemStack item = player.getEquipment().getItemInMainHand();
if (item.getType()!=Material.AIR) {
WorldShopSession ss = TwosideShops.AddSession(SessionState.PRICE, player, s);
player.sendMessage("Creating a shop to sell "+ChatColor.GREEN+GenericFunctions.GetItemName(item)+ChatColor.WHITE+".");
int totalcount = 0;
totalcount = GenericFunctions.CountItems(player, item);
log("We have "+totalcount+" items in our inventory.",4);
ss.SetItem(item);
//player.sendMessage("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 {
player.sendMessage(ChatColor.RED+"Cannot create a shop with nothing! "+ChatColor.WHITE+"Right-click the sign"
+ " with the item you want to sell in your hand.");
}
} else {
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.");
player.sendMessage(ChatColor.RED+"Sorry! "+ChatColor.WHITE+" A shop has already been setup here!");
}
} else
if (s.getLine(0).equalsIgnoreCase(ChatColor.BLUE+"-- SHOP --")) {
@ -1628,8 +1678,10 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
if (shop.GetOwner().equalsIgnoreCase(ev.getPlayer().getName())) {
player.sendMessage(ChatColor.DARK_PURPLE+"Editing shop...");
player.sendMessage("Insert more "+ChatColor.GREEN+shop.GetItemName()+ChatColor.WHITE+" by typing a positive amount "+ChatColor.GREEN+"(MAX:"+GenericFunctions.CountItems(player,shop.GetItem())+")"+ChatColor.WHITE+". Or withdraw "+ChatColor.GREEN+shop.GetItemName()+ChatColor.WHITE+" by typing a negative amount "+ChatColor.GREEN+"(MAX:"+shop.GetAmount()+")"+ChatColor.WHITE+".");
TwosideShops.AddSession(SessionState.EDIT, player, s);
//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!
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 {
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())+")");
@ -1644,18 +1696,25 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
}
} else
if (s.getLine(0).equalsIgnoreCase("buyshop")) {
//Create a new buy shop.
ItemStack item = player.getEquipment().getItemInMainHand();
if (item.getType()!=Material.AIR) {
WorldShopSession ss = TwosideShops.AddSession(SessionState.BUY_CREATE, player, s);
player.sendMessage("Creating a shop to buy "+ChatColor.GREEN+GenericFunctions.GetItemName(item)+ChatColor.WHITE+".");
int totalcount = 0;
totalcount = GenericFunctions.CountItems(player, item);
ss.SetItem(item);
player.sendMessage("How many of this item do you want to buy?");
if (!WorldShop.shopSignExists(chest.getLocation())) {
//Create a new buy shop.
ItemStack item = player.getEquipment().getItemInMainHand();
if (item.getType()!=Material.AIR) {
WorldShopSession ss = TwosideShops.AddSession(SessionState.BUY_PRICE, player, s);
player.sendMessage("Creating a shop to buy "+ChatColor.GREEN+GenericFunctions.GetItemName(item)+ChatColor.WHITE+".");
int totalcount = 0;
//totalcount = GenericFunctions.CountItems(player, item);
Chest c = (Chest)chest.getState();
ss.SetAmt(GenericFunctions.CountEmptySpace(c.getInventory(), item));
ss.SetItem(item);
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 {
player.sendMessage(ChatColor.RED+"Cannot create a shop with nothing! "+ChatColor.WHITE+"Right-click the sign"
+ " with the item you want to buy in your hand.");
}
} else {
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.");
player.sendMessage(ChatColor.RED+"Sorry! "+ChatColor.WHITE+" A shop has already been setup here!");
}
} else
if (s.getLine(0).equalsIgnoreCase(ChatColor.BLUE+"- BUYING SHOP -") ||
@ -1669,8 +1728,10 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
if (shop.GetOwner().equalsIgnoreCase(ev.getPlayer().getName())) {
player.sendMessage(ChatColor.DARK_PURPLE+"Editing shop...");
player.sendMessage("Request more "+ChatColor.GREEN+shop.GetItemName()+ChatColor.WHITE+" by typing a positive amount "+ChatColor.WHITE+". Or withdraw stored "+ChatColor.GREEN+shop.GetItemName()+ChatColor.WHITE+" by typing a negative amount "+ChatColor.GREEN+"(MAX:"+shop.GetStoredAmount()+")"+ChatColor.WHITE+".");
TwosideShops.AddSession(SessionState.BUY_EDIT, player, s);
DecimalFormat df = new DecimalFormat("0.00");
//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 {
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()))+")");
@ -1981,6 +2042,13 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
itemCube_saveConfig(id,itemcube_contents);
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)
public void MonsterSpawnEvent(CreatureSpawnEvent ev) {
log("Reason for spawn: "+ev.getSpawnReason().toString(),5);
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) {
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);
//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") &&
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)
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) {
List<ItemStack> droplist = ev.getDrops();
@ -3162,103 +3258,139 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
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.
Sign s = (Sign)(ev.getBlock().getState());
if (s.getLine(0).equalsIgnoreCase(ChatColor.BLUE+"-- SHOP --")) {
//This is a shop. Let's find out who the owner is.
int shopID = TwosideShops.GetShopID(s);
WorldShop shop = TwosideShops.LoadWorldShopData(shopID);
String owner = shop.GetOwner();
if (owner.equalsIgnoreCase(p.getName()) || p.isOp()) {
//We are going to see if this shop had items in it.
if (shop.GetAmount()>0) {
//It did, we are going to release those items.
ItemStack drop = shop.GetItem();
int dropAmt = shop.GetAmount();
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;
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 --")) {
//This is a shop. Let's find out who the owner is.
int shopID = TwosideShops.GetShopID(s);
WorldShop shop = TwosideShops.LoadWorldShopData(shopID);
String owner = shop.GetOwner();
if (owner.equalsIgnoreCase(p.getName()) || p.isOp()) {
//We are going to see if this shop had items in it.
/*if (shop.GetAmount()>0) { //LEGACY CODE.
//It did, we are going to release those items.
ItemStack drop = shop.GetItem();
int dropAmt = shop.GetAmount();
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<Entity> nearby = ev.getPlayer().getWorld().getNearbyEntities(ev.getBlock().getLocation(), 3, 3, 3);
for (int i=0;i<nearby.size();i++) {
Entity e = Iterables.get(nearby, i);
if (e.getType()==EntityType.DROPPED_ITEM) {
log("Found a drop.",5);
Item it = (Item)e;
if (it.getItemStack().getType()==shop.GetItem().getType() &&
Artifact.isArtifact(it.getItemStack())) {
log("Same type.",5);
e.remove();
e.setCustomNameVisible(false);
e.setCustomName(null);
TwosideShops.RemoveSession(p);
}
}
}
} else {
//They are not the owner! Do not allow this shop to be broken.
p.sendMessage("This shop belongs to "+ChatColor.LIGHT_PURPLE+owner+ChatColor.WHITE+"! You cannot break others' shops!");
ev.setCancelled(true);
}
} else
if (s.getLine(0).equalsIgnoreCase(ChatColor.BLUE+"- BUYING SHOP -") ||
s.getLine(0).equalsIgnoreCase(ChatColor.YELLOW+""+ChatColor.BOLD+"-BUYING SHOP-")) {
//This is a shop. Let's find out who the owner is.
int shopID = TwosideShops.GetShopID(s);
WorldShop shop = TwosideShops.LoadWorldShopData(shopID);
String owner = shop.GetOwner();
if (owner.equalsIgnoreCase(p.getName()) || p.isOp()) {
//We are going to see if this shop had items in it.
if (shop.GetStoredAmount()>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<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++) {
Entity e = Iterables.get(nearby, i);
if (e.getType()==EntityType.DROPPED_ITEM) {
log("Found a drop.",5);
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);
log("Comparing item "+it.getItemStack().toString()+" to "+checkdrop.toString(),2);
if (it.getItemStack().isSimilar(checkdrop) &&
Artifact.isArtifact(it.getItemStack())) {
log("Same type.",2);
e.remove();
e.setCustomNameVisible(false);
e.setCustomName(null);
TwosideShops.RemoveSession(p);
}
}
}
} else {
//They are not the owner! Do not allow this shop to be broken.
p.sendMessage("This shop belongs to "+ChatColor.LIGHT_PURPLE+owner+ChatColor.WHITE+"! You cannot break others' shops!");
ev.setCancelled(true);
}
} else
if (s.getLine(0).equalsIgnoreCase(ChatColor.BLUE+"- BUYING SHOP -") ||
s.getLine(0).equalsIgnoreCase(ChatColor.YELLOW+""+ChatColor.BOLD+"-BUYING SHOP-")) {
//This is a shop. Let's find out who the owner is.
int shopID = TwosideShops.GetShopID(s);
WorldShop shop = TwosideShops.LoadWorldShopData(shopID);
String owner = shop.GetOwner();
if (owner.equalsIgnoreCase(p.getName()) || p.isOp()) {
//We are going to see if this shop had items in it.
/*if (shop.GetStoredAmount()>0) { //LEGACY CODE.
//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<Entity> nearby = ev.getPlayer().getWorld().getNearbyEntities(ev.getBlock().getLocation(), 3, 3, 3);
for (int i=0;i<nearby.size();i++) {
Entity e = Iterables.get(nearby, i);
if (e.getType()==EntityType.DROPPED_ITEM) {
log("Found a drop.",5);
Item it = (Item)e;
if (it.getItemStack().getType()==shop.GetItem().getType() &&
Artifact.isArtifact(it.getItemStack())) {
log("Same type.",5);
e.remove();
e.setCustomNameVisible(false);
e.setCustomName(null);
TwosideShops.RemoveSession(p);
}
}
}
} else {
//They are not the owner! Do not allow this shop to be broken.
p.sendMessage("This shop belongs to "+ChatColor.LIGHT_PURPLE+owner+ChatColor.WHITE+"! You cannot break others' shops!");
ev.setCancelled(true);
}
//ev.getPlayer().getLocation().getWorld().dropItemNaturally(ev.getPlayer().getLocation(), drop).setPickupDelay(0);
}*/
//Remove the itemstack that represented this item.
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++) {
Entity e = Iterables.get(nearby, i);
if (e.getType()==EntityType.DROPPED_ITEM) {
log("Found a drop.",5);
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);
log("Comparing item "+it.getItemStack().toString()+" to "+checkdrop.toString(),2);
if (it.getItemStack().isSimilar(checkdrop)) {
log("Same type.",2);
e.remove();
e.setCustomNameVisible(false);
e.setCustomName(null);
TwosideShops.RemoveSession(p);
}
}
}
} else {
//They are not the owner! Do not allow this shop to be broken.
p.sendMessage("This shop belongs to "+ChatColor.LIGHT_PURPLE+owner+ChatColor.WHITE+"! You cannot break others' shops!");
ev.setCancelled(true);
}
}
}
} else {
//Make sure there's no world sign on this block.
@ -3697,6 +3829,29 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
}//A general clear recipe table check for any non-artifact items.
}
@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)
public void MinecartExitEvent(VehicleExitEvent ev) {

@ -51,8 +51,45 @@ public class WorldShopManager {
TwosideKeeper.WORLD_SHOP_ID++;
return newshop;
}
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 void UpdateSign(WorldShop shop, int id, Sign s, boolean purchaseshop) {
public static void UpdateSign(WorldShop shop, int id, Sign s, boolean purchaseshop) {
//Convert the sign.
String[] lines = s.getLines();
List<String> sign_lines = new ArrayList<String>();
@ -85,6 +122,10 @@ public class WorldShopManager {
public int GetShopID(Sign s) {
return Integer.parseInt(s.getLines()[3].replace(ChatColor.DARK_GRAY+"", ""));
}
public WorldShop LoadWorldShopData(Sign s) {
return LoadWorldShopData(GetShopID(s));
}
public WorldShop LoadWorldShopData(int id) {
File config;
@ -142,9 +183,17 @@ public class WorldShopManager {
return -1;
}
public WorldShopSession AddSession(SessionState type, Player p, Sign s) {
WorldShopSession sss = new WorldShopSession(p, TwosideKeeper.getServerTickTime(), type, s);
sessions.add(sss);
return sss;
//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);
sessions.add(sss);
return sss;
}
}
public void UpdateSession(SessionState type, Player p) {
int term = GetPlayerTerminal(p);

Loading…
Cancel
Save