diff --git a/TwosideKeeper.jar b/TwosideKeeper.jar index a6e900f..690bb89 100644 Binary files a/TwosideKeeper.jar and b/TwosideKeeper.jar differ diff --git a/src/plugin.yml b/src/plugin.yml index e347bf4..998d3bc 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: TwosideKeeper main: sig.plugin.TwosideKeeper.TwosideKeeper -version: 3.7.2 +version: 3.7.3-alpha1 commands: money: description: Tells the player the amount of money they are holding. diff --git a/src/sig/plugin/TwosideKeeper/DeathManager.java b/src/sig/plugin/TwosideKeeper/DeathManager.java index d41ebd1..513d712 100644 --- a/src/sig/plugin/TwosideKeeper/DeathManager.java +++ b/src/sig/plugin/TwosideKeeper/DeathManager.java @@ -29,9 +29,13 @@ public class DeathManager { public static void addNewDeathStructure(List deathinv, Location deathloc, Player p) { ds.add(new DeathStructure(deathinv,deathloc,p)); + TwosideKeeper.log("Added a new Death Structure: "+ds.get(ds.size()-1).toString(),5); } public static void removeDeathStructure(Player p) { ds.remove(getDeathStructure(p)); + PlayerStructure pd = PlayerStructure.GetPlayerStructure(p); + pd.deathloot.clear(); + pd.hasDied=false; } public static boolean deathStructureExists(Player p) { if (getDeathStructure(p)!=null) { diff --git a/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java b/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java index 7e96968..7255fe8 100644 --- a/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java +++ b/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java @@ -445,7 +445,7 @@ public class GenericFunctions { return "Clay"; } case COBBLE_WALL:{ - return "Cobblestone Wall"; + return "Mossy Cobblestone Wall"; } case COMMAND:{ return "Command Block"; @@ -605,9 +605,12 @@ public class GenericFunctions { case MILK_BUCKET:{ return "Milk"; } - case NETHER_BRICK_ITEM:{ + case NETHER_BRICK:{ return "Nether Bricks"; } + case NETHER_BRICK_ITEM:{ + return "Nether Brick"; + } case NETHER_WARTS:{ return "Nether Wart"; } @@ -615,7 +618,7 @@ public class GenericFunctions { return "Nether Wart"; } case GOLD_PLATE:{ - return "Gold Pressure Plate"; + return "Weighted Pressure Plate (Light)"; } case PISTON_BASE:{ return "Piston"; @@ -724,7 +727,20 @@ public class GenericFunctions { return "Skull"; } case SMOOTH_BRICK:{ - return "Stone Brick"; + switch (type.getDurability()) { + case 0:{ + return "Stone Brick"; + } + case 1:{ + return "Mossy Stone Brick"; + } + case 2:{ + return "Cracked Stone Brick"; + } + case 3:{ + return "Chiseled Stone Brick"; + } + } } case SMOOTH_STAIRS:{ return "Stone Brick Stairs"; @@ -1553,6 +1569,50 @@ public class GenericFunctions { case WORKBENCH:{ return "Crafting Table"; } + case CLAY:{ + return "Clay Block"; + } + case WOOD_PLATE:{ + return "Wooden Pressure Plate"; + } + case STONE_PLATE:{ + return "Stone Pressure Plate"; + } + case IRON_PLATE:{ + return "Weighted Pressure Plate (Heavy)"; + } + case MOSSY_COBBLESTONE:{ + return "Moss Stone"; + } + case SANDSTONE:{ + switch (type.getDurability()) { + case 0:{ + return "Sandstone"; + } + case 1:{ + return "Chiseled Sandstone"; + } + case 2:{ + return "Smooth Sandstone"; + } + } + } + case RED_SANDSTONE:{ + switch (type.getDurability()) { + case 0:{ + return "Red Sandstone"; + } + case 1:{ + return "Chiseled Red Sandstone"; + } + case 2:{ + return "Smooth Red Sandstone"; + } + } + } + case TRAP_DOOR:{ + return "Wooden Trapdoor"; + } default:{ return GenericFunctions.CapitalizeFirstLetters(type.getType().toString().replace("_", " ")); } diff --git a/src/sig/plugin/TwosideKeeper/HelperStructures/DeathStructure.java b/src/sig/plugin/TwosideKeeper/HelperStructures/DeathStructure.java index f1d7b0f..c86fd5a 100644 --- a/src/sig/plugin/TwosideKeeper/HelperStructures/DeathStructure.java +++ b/src/sig/plugin/TwosideKeeper/HelperStructures/DeathStructure.java @@ -17,4 +17,8 @@ public class DeathStructure { this.deathloc=dl; this.p=p.getName(); } + + public String toString() { + return "Death Inventory: "+deathinventory.size()+" items, belongs to Player "+p+". Death location is "+deathloc.toString(); + } } diff --git a/src/sig/plugin/TwosideKeeper/HelperStructures/Loot.java b/src/sig/plugin/TwosideKeeper/HelperStructures/Loot.java index eeb298b..57a8956 100644 --- a/src/sig/plugin/TwosideKeeper/HelperStructures/Loot.java +++ b/src/sig/plugin/TwosideKeeper/HelperStructures/Loot.java @@ -35,6 +35,10 @@ public class Loot { raresword.setItemMeta(sword_meta); raresword = addEnchantments(raresword,true); } + /* + if (GenericFunctions.isArmor(raresword)) { + raresword = GenerateSetPiece(); + }*/ return raresword; } diff --git a/src/sig/plugin/TwosideKeeper/HelperStructures/WorldShop.java b/src/sig/plugin/TwosideKeeper/HelperStructures/WorldShop.java index 4e4b208..456e321 100644 --- a/src/sig/plugin/TwosideKeeper/HelperStructures/WorldShop.java +++ b/src/sig/plugin/TwosideKeeper/HelperStructures/WorldShop.java @@ -716,6 +716,10 @@ public class WorldShop { //it.teleport(ev.getClickedBlock().getLocation().add(-ev.getBlockFace().getModX()+0.5, -ev.getBlockFace().getModY()+1.5, -ev.getBlockFace().getModZ()+0.5)); } } + + public static void removeShopItem(Sign s) { + removeShopItem(s, TwosideKeeper.TwosideShops.LoadWorldShopData(s)); + } public static void removeShopItem(Sign s, WorldShop shop) { Collection nearby = WorldShop.getBlockShopSignAttachedTo(s).getWorld().getNearbyEntities(WorldShop.getBlockShopSignAttachedTo(s).getLocation().add(0.5,0,0.5), 0.3, 1, 0.3); @@ -792,4 +796,14 @@ public class WorldShop { it.teleport(ev.getClickedBlock().getLocation().add(-ev.getBlockFace().getModX()+0.5, -ev.getBlockFace().getModY()+1.5, -ev.getBlockFace().getModZ()+0.5)); } } + + public static boolean hasPermissionToBreakWorldShopSign(Sign s, Player p) { + String[] lines = s.getLines(); + WorldShop shop = TwosideKeeper.TwosideShops.LoadWorldShopData(s); + if (shop.GetOwner().equalsIgnoreCase(p.getName()) || p.isOp()) { + return true; + } else { + return false; + } + } } diff --git a/src/sig/plugin/TwosideKeeper/NewCombat.java b/src/sig/plugin/TwosideKeeper/NewCombat.java index bc5ebe8..ab9644b 100644 --- a/src/sig/plugin/TwosideKeeper/NewCombat.java +++ b/src/sig/plugin/TwosideKeeper/NewCombat.java @@ -36,6 +36,8 @@ import org.bukkit.metadata.MetadataValue; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.util.Vector; +import org.inventivetalent.glow.GlowAPI; +import org.inventivetalent.glow.GlowAPI.Color; import com.google.common.collect.Iterables; diff --git a/src/sig/plugin/TwosideKeeper/PlayerStructure.java b/src/sig/plugin/TwosideKeeper/PlayerStructure.java index 40fd60a..85a8bc7 100644 --- a/src/sig/plugin/TwosideKeeper/PlayerStructure.java +++ b/src/sig/plugin/TwosideKeeper/PlayerStructure.java @@ -10,6 +10,7 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Entity; @@ -19,6 +20,7 @@ import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; +import sig.plugin.TwosideKeeper.HelperStructures.DeathStructure; import sig.plugin.TwosideKeeper.Logging.DamageLogger; /*PLAYER STRUCTURE @@ -77,6 +79,12 @@ public class PlayerStructure { public long last_rejuvenate=TwosideKeeper.getServerTickTime(); public DamageLogger damagedata; public boolean damagelogging=false; + public boolean hasDied=false; + public double deathloc_x = 0; + public double deathloc_y = 0; + public double deathloc_z = 0; + public String deathloc_world = ""; + public List deathloot = new ArrayList(); public double prev_weapondmg=0.0; public double prev_buffdmg=0.0; @@ -205,6 +213,24 @@ public class PlayerStructure { workable.set("spleef_pts", spleef_pts); workable.set("spleef_wins", spleef_wins); workable.set("sounds_enabled", sounds_enabled); + workable.set("hasDied", hasDied); + ConfigurationSection deathlootlist = workable.createSection("deathloot"); + if (DeathManager.deathStructureExists(Bukkit.getPlayer(name))) { + DeathStructure ds = DeathManager.getDeathStructure(Bukkit.getPlayer(name)); + deathloc_x = ds.deathloc.getX(); + deathloc_y = ds.deathloc.getY(); + deathloc_z = ds.deathloc.getZ(); + deathloc_world = ds.deathloc.getWorld().getName(); + for (int i=0;i deathlootlist = new ArrayList(); + ConfigurationSection deathlootsection = workable.getConfigurationSection("deathloot"); + for (int i=0;i nodes; + HashMap itemmap; + int totalitems=0; boolean choosing = false; public RecyclingCenter() { nodes = new ArrayList(); + itemmap = new HashMap(); } public void AddNode(World world, int locx,int locy,int locz) { @@ -100,7 +109,112 @@ public class RecyclingCenter { } } + public void populateItemListFromAllNodes() { + for (int i=0;i0) { + Location rand_node=getRandomNode(); + rand_node.getWorld().loadChunk(rand_node.getChunk()); //Load that chunk to make sure we can throw items into it. + Block b = rand_node.getWorld().getBlockAt(rand_node); + if (b!=null && b.getType()==Material.CHEST || + b.getType()==Material.TRAPPED_CHEST) { + if (b.getState()!=null) { + Chest c = (Chest) b.getState(); + //Choose a random inventory slot and copy the vanished item into it. + double chancer = 100.0; + for (int j=0;j<27;j++) { + if (c.getBlockInventory().getItem(j)!=null && c.getBlockInventory().getItem(j).getType()==i.getItemStack().getType()) { + chancer-=TwosideKeeper.RECYCLEDECAYAMT; + } + } + int itemslot = (int)Math.floor(Math.random()*27); + ItemStack oldItem = c.getBlockInventory().getItem(itemslot); + //There is also a chance to move this item to another random spot. + if (!isCommon(i.getItemStack().getType())) { + if (oldItem!=null && Math.random()*100<=TwosideKeeper.RECYCLECHANCE) { + int itemslot2 = (int)Math.floor(Math.random()*27); + c.getBlockInventory().setItem(itemslot2, oldItem); + } + c.getBlockInventory().setItem(itemslot, i.getItemStack()); + populateItemList(i.getItemStack()); + TwosideKeeper.log("Sent "+ChatColor.AQUA+GenericFunctions.UserFriendlyMaterialName(i.getItemStack())+((i.getItemStack().getAmount()>1)?ChatColor.YELLOW+" x"+i.getItemStack().getAmount():"")+ChatColor.RESET+" to Recycling Center Node "+rand_node.toString(),3); + } + } + } + } else { + TwosideKeeper.log("No Recycling Center Nodes set! All dropped items will continue to be discarded. Use /recyclingcenter to define them.",1); + } + } + } + + private boolean isCommon(Material m) { + if (itemmap.containsKey(m)) { + int amt = itemmap.get(m); + double chance = (amt/(double)totalitems*100d); + if (totalitems>0 && chance>=TwosideKeeper.COMMONITEMPCT) { + DecimalFormat df = new DecimalFormat("0.00"); + TwosideKeeper.log(df.format(chance)+"% of items in nodes are "+GenericFunctions.UserFriendlyMaterialName(m)+". Common item detected...", 3); + return true; + } + } + return false; + } } diff --git a/src/sig/plugin/TwosideKeeper/TwosideKeeper.java b/src/sig/plugin/TwosideKeeper/TwosideKeeper.java index 4881d93..248019e 100644 --- a/src/sig/plugin/TwosideKeeper/TwosideKeeper.java +++ b/src/sig/plugin/TwosideKeeper/TwosideKeeper.java @@ -157,6 +157,7 @@ import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionType; import org.bukkit.projectiles.ProjectileSource; import org.bukkit.util.Vector; +import org.inventivetalent.glow.GlowAPI; import com.google.common.collect.Iterables; import com.google.common.collect.Iterators; @@ -238,6 +239,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { public static int LOGGING_LEVEL=0; //The logging level the server will output in for the console. 0 = No Debug Messages. Toggled with /log. public static double ARTIFACT_RARITY=1.5; //The multiplier of artifact drops. public static ServerType SERVER_TYPE=ServerType.TEST; //The type of server this is running on. + public static int COMMONITEMPCT=3; public static final int DODGE_COOLDOWN=100; public static final int DEATHMARK_COOLDOWN=240; @@ -331,6 +333,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { TwosideRecyclingCenter = new RecyclingCenter(); TwosideRecyclingCenter.loadConfig(); + TwosideRecyclingCenter.populateItemListFromAllNodes(); log("Recycling Centers Loaded: "+TwosideRecyclingCenter.getNumberOfNodes(),3); pluginupdater = new AutoUpdatePlugin(this); @@ -1827,6 +1830,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { TwosideRecyclingCenter.setChoosingRecyclingCenter(false); //Create a new Recycling Center. TwosideRecyclingCenter.AddNode(ev.getClickedBlock().getWorld(), ev.getClickedBlock().getLocation().getBlockX(), ev.getClickedBlock().getLocation().getBlockY(), ev.getClickedBlock().getLocation().getBlockZ()); + TwosideRecyclingCenter.populateItemListFromNode(ev.getClickedBlock().getLocation()); ev.getPlayer().sendMessage(ChatColor.DARK_BLUE+"New Recycling Center successfully created at "+ev.getClickedBlock().getLocation().toString()); } @@ -2241,7 +2245,10 @@ public class TwosideKeeper extends JavaPlugin implements Listener { log("This is a buy shop sign.",5); int shopID = TwosideShops.GetShopID(s); WorldShop shop = TwosideShops.LoadWorldShopData(shopID); - + Chest c = (Chest)chest.getState(); + shop.UpdateAmount(GenericFunctions.CountItems(c.getInventory(), shop.GetItem())); + TwosideShops.UpdateSign(shop, shop.getID(),s,false); + TwosideShops.SaveWorldShopData(shop); Location newloc = ev.getClickedBlock().getLocation().add(-ev.getBlockFace().getModX()+0.5, -ev.getBlockFace().getModY()+1.5, -ev.getBlockFace().getModZ()+0.5); WorldShop.spawnShopItem(ev,newloc,shop); @@ -2262,7 +2269,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { 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())+")"); + //player.sendMessage("How many "+Cha tColor.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())+")"); TextComponent message1 = new TextComponent("How many "); TextComponent message2 = new TextComponent(ChatColor.GREEN+"["+shop.GetItemName()+ChatColor.RESET+""+ChatColor.GREEN+"]"); message2.setHoverEvent(new HoverEvent( HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(shop.GetItemName()+WorldShop.GetItemInfo(shop.GetItem())).create())); @@ -2325,6 +2332,10 @@ public class TwosideKeeper extends JavaPlugin implements Listener { //This is a buy shop. int shopID = TwosideShops.GetShopID(s); WorldShop shop = TwosideShops.LoadWorldShopData(shopID); + Chest c = (Chest)chest.getState(); + shop.UpdateAmount(GenericFunctions.CountItems(c.getInventory(), shop.GetItem())); + TwosideShops.UpdateSign(shop, shop.getID(),s,false); + TwosideShops.SaveWorldShopData(shop); Location newloc = ev.getClickedBlock().getLocation().add(-ev.getBlockFace().getModX()+0.5, -ev.getBlockFace().getModY()+1.5, -ev.getBlockFace().getModZ()+0.5); WorldShop.spawnShopItem(ev,newloc,shop); @@ -2528,6 +2539,8 @@ public class TwosideKeeper extends JavaPlugin implements Listener { log("Y position is "+p.getLocation().getY(), 4); DeathManager.addNewDeathStructure(ev.getDrops(), (p.getLocation().getY()<0)?p.getLocation().add(0,-p.getLocation().getY()+256,0) //This means they fell into the void. Might as well put it way higher. :p.getLocation(), p); + PlayerStructure pd = PlayerStructure.GetPlayerStructure(p); + pd.hasDied=true; p.getInventory().clear(); } } @@ -3392,42 +3405,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { log("Respawn this shop item.",5); } } - //There is a % chance of it going to a recycling center. - if (Math.random()*100<=RECYCLECHANCE && - TwosideRecyclingCenter.IsItemAllowed(i.getItemStack())) { - //Recycle allowed. Now figure out which node to go to. - if (TwosideRecyclingCenter.getNumberOfNodes()>0) { - Location rand_node=TwosideRecyclingCenter.getRandomNode(); - rand_node.getWorld().loadChunk(rand_node.getChunk()); //Load that chunk to make sure we can throw items into it. - Block b = rand_node.getWorld().getBlockAt(rand_node); - if (b!=null && b.getType()==Material.CHEST || - b.getType()==Material.TRAPPED_CHEST) { - if (b.getState()!=null) { - Chest c = (Chest) b.getState(); - //Choose a random inventory slot and copy the vanished item into it. - double chancer = 100.0; - for (int j=0;j<27;j++) { - if (c.getBlockInventory().getItem(j)!=null && c.getBlockInventory().getItem(j).getType()==i.getItemStack().getType()) { - chancer-=RECYCLEDECAYAMT; - } - } - int itemslot = (int)Math.floor(Math.random()*27); - ItemStack oldItem = c.getBlockInventory().getItem(itemslot); - //There is also a chance to move this item to another random spot. - if (chancer>0 && Math.random()*1001)?ChatColor.YELLOW+" x"+i.getItemStack().getAmount():"")+ChatColor.RESET+" to Recycling Center Node "+rand_node.toString(),3); - } - } - } - } else { - log("No Recycling Center Nodes set! All dropped items will continue to be discarded. Use /recyclingcenter to define them.",1); - } - } + TwosideRecyclingCenter.AddItemToRecyclingCenter(i); } @EventHandler(priority=EventPriority.LOW,ignoreCancelled = true) @@ -3928,7 +3906,6 @@ public class TwosideKeeper extends JavaPlugin implements Listener { double oldhp=((LivingEntity)ev.getEntity()).getHealth(); GenericFunctions.subtractHealth((LivingEntity)ev.getEntity(), NewCombat.getDamagerEntity(ev.getDamager()), dmg); if (NewCombat.getDamagerEntity(ev.getDamager()) instanceof Player) { - //GenericFunctions.subtractHealth((LivingEntity)ev.getEntity(), NewCombat.getDamagerEntity(ev.getDamager()), dmg); if (ev.getDamager() instanceof Projectile) { ev.getDamager().remove(); } @@ -4192,6 +4169,8 @@ public class TwosideKeeper extends JavaPlugin implements Listener { } } },20); + PlayerStructure pd = PlayerStructure.GetPlayerStructure(p); + pd.hasDied=false; } @EventHandler(priority=EventPriority.LOW,ignoreCancelled = true) diff --git a/src/sig/plugin/TwosideKeeper/TwosideKeeperAPI.java b/src/sig/plugin/TwosideKeeper/TwosideKeeperAPI.java index dfaea06..f404aee 100644 --- a/src/sig/plugin/TwosideKeeper/TwosideKeeperAPI.java +++ b/src/sig/plugin/TwosideKeeper/TwosideKeeperAPI.java @@ -5,6 +5,7 @@ import java.util.List; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.Sign; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; @@ -173,6 +174,12 @@ public final class TwosideKeeperAPI { public static boolean isWorldShop(Location l) { return WorldShop.shopSignExists(l); } + public static boolean hasPermissionToBreakWorldShopSign(Sign s, Player p) { + return WorldShop.hasPermissionToBreakWorldShopSign(s,p); + } + public static void removeWorldShopDisplayItem(Sign s) { + WorldShop.removeShopItem(s); + } //Recycling Center COMMANDS. public static boolean isRecyclingCenter(Block b) {