diff --git a/TwosideKeeper.jar b/TwosideKeeper.jar index 4c08ce1..274640d 100644 Binary files a/TwosideKeeper.jar and b/TwosideKeeper.jar differ diff --git a/src/plugin.yml b/src/plugin.yml index f0ce181..f5a4add 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: TwosideKeeper main: sig.plugin.TwosideKeeper.TwosideKeeper -version: 3.6.2r3 +version: 3.7.0 commands: money: description: Tells the player the amount of money they are holding. @@ -101,4 +101,9 @@ commands: description: Displays information about a mode. usage: /mode permission: TwosideKeeper.money + permission-message: No permissions! + dps: + description: DPS Logger. + usage: /dps + permission: TwosideKeeper.money permission-message: No permissions! \ No newline at end of file diff --git a/src/sig/plugin/TwosideKeeper/AwakenedArtifact.java b/src/sig/plugin/TwosideKeeper/AwakenedArtifact.java index d1bd9a4..b986677 100644 --- a/src/sig/plugin/TwosideKeeper/AwakenedArtifact.java +++ b/src/sig/plugin/TwosideKeeper/AwakenedArtifact.java @@ -109,7 +109,7 @@ public class AwakenedArtifact { tc.addExtra(ac); tc.addExtra(" to open up the ability upgrade menu."); p.spigot().sendMessage(tc);*/ - p.spigot().sendMessage(ArtifactAbility.GenerateMenu(ArtifactItemType.getArtifactItemTypeFromItemStack(p.getInventory().getItem(GenericFunctions.CalculateSlot(artifact,p))).getUpgradePath(), TwosideKeeper.CalculateWeaponDamage(p,null), artifact,GenericFunctions.CalculateSlot(artifact,p))); + p.spigot().sendMessage(ArtifactAbility.GenerateMenu(ArtifactItemType.getArtifactItemTypeFromItemStack(p.getInventory().getItem(GenericFunctions.CalculateSlot(artifact,p))).getUpgradePath(), NewCombat.CalculateWeaponDamage(p,null), artifact,GenericFunctions.CalculateSlot(artifact,p))); return item; } else { return setEXP(artifact,totalval); diff --git a/src/sig/plugin/TwosideKeeper/ChargeZombie.java b/src/sig/plugin/TwosideKeeper/ChargeZombie.java index eef67f5..c8b5289 100644 --- a/src/sig/plugin/TwosideKeeper/ChargeZombie.java +++ b/src/sig/plugin/TwosideKeeper/ChargeZombie.java @@ -5,8 +5,6 @@ import org.bukkit.Sound; import org.bukkit.block.Block; import org.bukkit.entity.Monster; -import aPlugin.BlockUtils; -import aPlugin.Utils; import net.minecraft.server.v1_9_R1.BlockPosition; import sig.plugin.TwosideKeeper.HelperStructures.BlockToughness; @@ -35,7 +33,7 @@ public class ChargeZombie { if (Math.abs(x)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. @@ -56,9 +54,9 @@ public class ChargeZombie { 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())); + aPlugin.API.sendBlockBreakPacket(m.getLocation().add(x,y,z).getBlock(), -1); } else { - 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()), 4, Utils.seedRandomID(m.getLocation().add(x,y,z).getBlock())); + aPlugin.API.sendBlockBreakPacket(m.getLocation().add(x,y,z).getBlock(), (int)(Math.random()*6)+3); } } } @@ -69,7 +67,7 @@ public class ChargeZombie { //This block can be destroyed if it is a liquid. if (m.getLocation().add(x,y,z).getBlock().isLiquid()) { 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())); + aPlugin.API.sendBlockBreakPacket(m.getLocation().add(x,y,z).getBlock(), -1); } } } diff --git a/src/sig/plugin/TwosideKeeper/DiscordStatusUpdater.java b/src/sig/plugin/TwosideKeeper/DiscordStatusUpdater.java new file mode 100644 index 0000000..ae52885 --- /dev/null +++ b/src/sig/plugin/TwosideKeeper/DiscordStatusUpdater.java @@ -0,0 +1,24 @@ +package sig.plugin.TwosideKeeper; + +import java.text.DecimalFormat; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; + +import aPlugin.DiscordMessageSender; +import net.minecraft.server.v1_9_R1.MinecraftServer; + +public class DiscordStatusUpdater implements Runnable{ + + @Override + public void run() { + DiscordMessageSender.setPlaying(ProduceMessage()); + Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(Bukkit.getPluginManager().getPlugin("TwosideKeeper"), this, 300l); + } + + String ProduceMessage() { + DecimalFormat df = new DecimalFormat("0.00"); + return ChatColor.stripColor("TPS: "+df.format(MinecraftServer.getServer().recentTps[0])+" "+TwosideKeeper.getWeatherIcon()+" "+TwosideKeeper.getTimeOfDay()+" ("+Bukkit.getOnlinePlayers().size()+")"); + } + +} diff --git a/src/sig/plugin/TwosideKeeper/HelperStructures/ArtifactAbility.java b/src/sig/plugin/TwosideKeeper/HelperStructures/ArtifactAbility.java index 6caf9da..248d88d 100644 --- a/src/sig/plugin/TwosideKeeper/HelperStructures/ArtifactAbility.java +++ b/src/sig/plugin/TwosideKeeper/HelperStructures/ArtifactAbility.java @@ -18,6 +18,7 @@ import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.TextComponent; import sig.plugin.TwosideKeeper.AwakenedArtifact; +import sig.plugin.TwosideKeeper.NewCombat; import sig.plugin.TwosideKeeper.TwosideKeeper; import sig.plugin.TwosideKeeper.HelperStructures.Common.GenericFunctions; @@ -87,11 +88,11 @@ public enum ArtifactAbility { //Shovel abilities SUPPRESS("Suppression",ChatColor.GRAY+"[Unimplemented] Suppresses a mob on hit for [VAL] seconds.\n\n" - + "Suppression prevents movement, attacking, and teleportation.",new double[]{0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1}, + + "Suppression prevents movement, attacking, exploding, and teleportation.",new double[]{0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1}, new double[]{1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0},100,1000,UpgradePath.SHOVEL), - ERUPTION("Eruption","Sneak while Left-clicking a mob to damage mobs for [VAL] damage and knock them up. The eruption also destroys the ground beneath you.",new double[]{6.0,7,8.0,9,10.0,11,12.0,13,14.0,15}, + ERUPTION("Eruption","Sneak while Left-clicking a mob to damage mobs for [VAL] damage and knock them up. The eruption also destroys the ground beneath you.",new double[]{11.0,13,15.0,17,19.0,21,24.0,27,30.0,40}, new double[]{1.0,0.925,0.85,0.775,0.7,0.625,0.55,0.475,0.4,0.325},100,40,UpgradePath.SHOVEL), - EARTHWAVE("Earth Wave","While in combat, destroy a block to send a wave of earth towards your enemies. Enemies standing inside of the waves take [VAL] damage every second.",new double[]{8,9,10,11,12,13,14,15,16,18}, + EARTHWAVE("Earth Wave","While in combat, destroy a block to send a wave of earth towards your enemies. Enemies standing inside of the waves take [VAL] damage every second.",new double[]{10,12,14,16,18,20,22,24,26,30}, new double[]{2.4,2.2,2.0,1.9,1.8,1.7,1.6,1.5,1.4,1.2},100,100,UpgradePath.SHOVEL), //Axe abilities @@ -435,7 +436,7 @@ public enum ArtifactAbility { tc.addExtra(ac); tc.addExtra(" to open up the ability upgrade menu.");;*/ p.spigot().sendMessage(tc); - p.spigot().sendMessage(ArtifactAbility.GenerateMenu(ArtifactItemType.getArtifactItemTypeFromItemStack(p.getInventory().getItem(GenericFunctions.CalculateSlot(item,p))).getUpgradePath(), TwosideKeeper.CalculateWeaponDamage(p,null), item,GenericFunctions.CalculateSlot(item,p))); + p.spigot().sendMessage(ArtifactAbility.GenerateMenu(ArtifactItemType.getArtifactItemTypeFromItemStack(p.getInventory().getItem(GenericFunctions.CalculateSlot(item,p))).getUpgradePath(), NewCombat.CalculateWeaponDamage(p,null), item,GenericFunctions.CalculateSlot(item,p))); } } else { if (ability.GetMaxLevel()<=level) { diff --git a/src/sig/plugin/TwosideKeeper/HelperStructures/ArtifactAbilityApplyEffects.java b/src/sig/plugin/TwosideKeeper/HelperStructures/ArtifactAbilityApplyEffects.java new file mode 100644 index 0000000..86bce09 --- /dev/null +++ b/src/sig/plugin/TwosideKeeper/HelperStructures/ArtifactAbilityApplyEffects.java @@ -0,0 +1,30 @@ +package sig.plugin.TwosideKeeper.HelperStructures; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import sig.plugin.TwosideKeeper.HelperStructures.Common.GenericFunctions; + +/** + * Defines all the effects and calculations applied by artifact abilities. + */ +public class ArtifactAbilityApplyEffects { + //Returns true if the player has this artifact ability on one of their equipment. + public static boolean canExecuteArtifactAbility(ArtifactAbility ab, Player p) { + //First check the main hand. + ItemStack[] testitems = { + p.getEquipment().getItemInMainHand(), + p.getEquipment().getHelmet(), + p.getEquipment().getChestplate(), + p.getEquipment().getLeggings(), + p.getEquipment().getBoots(), + }; + for (int i=0;i=0 && p.getLocation().add(0,0,0).getBlock().getLightLevel()<=4) { @@ -2518,28 +2541,13 @@ public class GenericFunctions { } } + @Deprecated public static void DealDamageToMob(double dmg, LivingEntity target, LivingEntity damager, boolean truedmg) { - if (damager!=null && (target instanceof Monster) && !target.isDead()) { - Monster m = (Monster)target; - m.setTarget(damager); - } - - double finaldmg = 0; - if (truedmg) { - finaldmg = dmg; - } else { - finaldmg = TwosideKeeper.CalculateDamageReduction(dmg, target, damager); - } - - if (target.hasPotionEffect(PotionEffectType.ABSORPTION)) { - //We attempt to absorb the amount of damage of absorption level we have. - finaldmg-=(GenericFunctions.getPotionEffectLevel(PotionEffectType.ABSORPTION, target)+1)*4; - if (finaldmg<0) { - finaldmg=0; - } - } - - if ((target instanceof Monster) && damager!=null) { + DealDamageToMob(dmg,target,damager); + } + + public static void DealDamageToMob(double dmg, LivingEntity target, LivingEntity damager) { + if (damager!=null && (target instanceof Monster)) { Monster m = (Monster)target; m.setTarget(damager); if (TwosideKeeper.monsterdata.containsKey(m.getUniqueId())) { @@ -2549,19 +2557,14 @@ public class GenericFunctions { TwosideKeeper.monsterdata.put(m.getUniqueId(),new MonsterStructure(damager)); } } - TwosideKeeper.log("Attack is dealing "+finaldmg, 2); - if (target.getHealth()>finaldmg) { - TwosideKeeper.log("NOT FULL HEALTH. HP: "+target.getHealth(), 5); - target.setHealth(target.getHealth()-finaldmg); - target.damage(0.000001); - target.setNoDamageTicks(20); - } else { - //Bukkit.getPluginManager().callEvent(new EntityDamageByEntityEvent(damager,target,DamageCause.ENTITY_ATTACK,finaldmg)); - target.setHealth(0.0001); - target.damage(99999); - target.setHealth(0); - } - } + aPlugin.API.sendEntityHurtAnimation(target); + TwosideKeeper.log("Call event with "+dmg, 5); + TwosideKeeper.log(GenericFunctions.GetEntityDisplayName(damager)+"->"+ + GenericFunctions.GetEntityDisplayName(target)+ChatColor.WHITE+": Damage dealt was "+dmg,2); + double oldhp=((LivingEntity)target).getHealth(); + GenericFunctions.subtractHealth(target, dmg); + TwosideKeeper.log(ChatColor.BLUE+" "+oldhp+"->"+((LivingEntity)target).getHealth()+" HP",3); + } public static boolean searchfor(List stringy, String searchfor) { for (int i=0;idmg) { + entity.setHealth(entity.getHealth()-dmg); + } else { + /*List drops = new ArrayList(); + EntityDeathEvent ev = new EntityDeathEvent(entity,drops); + Bukkit.getPluginManager().callEvent(ev); + entity.setHealth(0);*/ + entity.damage(Integer.MAX_VALUE); + } + } + + public static boolean isViewingInventory(Player p) { + PlayerStructure pd = PlayerStructure.GetPlayerStructure(p); + return pd.isViewingInventory; + } + + public static void addIFrame(Player p, int ticks) { + p.removePotionEffect(PotionEffectType.GLOWING); + p.addPotionEffect(new PotionEffect(PotionEffectType.GLOWING,ticks,0)); + p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION,ticks,0)); + } + + public static void PerformRejuvenate(Player player) { + PlayerStructure pd = (PlayerStructure)TwosideKeeper.playerdata.get(player.getUniqueId()); + if (pd.last_rejuvenate+TwosideKeeper.REJUVENATE_COOLDOWN<=TwosideKeeper.getServerTickTime()) { + player.playSound(player.getLocation(), Sound.ENTITY_ZOMBIE_VILLAGER_CURE, 1.0f, 1.0f); + addIFrame(player,40); + player.removePotionEffect(PotionEffectType.REGENERATION); + player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION,200,9)); + aPlugin.API.damageItem(player, player.getEquipment().getItemInMainHand(), 20); + pd.last_rejuvenate = TwosideKeeper.getServerTickTime(); + } + } + + public static boolean isArmoredMob(Monster m) { + if (m.getType()==EntityType.ZOMBIE || + m.getType()==EntityType.PIG_ZOMBIE || + m.getType()==EntityType.SKELETON) { + return true; + } + return false; + } } diff --git a/src/sig/plugin/TwosideKeeper/HelperStructures/Loot.java b/src/sig/plugin/TwosideKeeper/HelperStructures/Loot.java index 256dec1..eeb298b 100644 --- a/src/sig/plugin/TwosideKeeper/HelperStructures/Loot.java +++ b/src/sig/plugin/TwosideKeeper/HelperStructures/Loot.java @@ -192,12 +192,6 @@ public class Loot { if (Math.random()<0.08*HARDENED_ENCHANT_MULT) {item.addUnsafeEnchantment(Enchantment.THORNS, GetEnchantmentLevels(item.getType(),hardened));} //item.addUnsafeEnchantment(Enchantment.KNOCKBACK, 1); if (Math.random()<0.001*HARDENED_ENCHANT_MULT) {item.addUnsafeEnchantment(Enchantment.MENDING, GetEnchantmentLevels(item.getType(),hardened));} - } else - if (item.getType()==Material.FISHING_ROD) { - 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, (int)(((Math.random()*3)+2)*((hardened)?HARDENED_ENCHANT_MULT:1))); } else { //Generic Random Enchantments. for (int i=0;i lore = m.getLore(); String material_name = lore.get(1).split("'")[1]; - if (lore.get(1).contains("Arrow of")) { - return "Tipped Arrow"; - } else - if (lore.get(1).contains("Splash Potion")) { - return "Splash Potion"; - } else - if (lore.get(1).contains("Lingering Potion")) { - return "Lingering Potion"; - } else - if (lore.get(1).contains("Potion")) { - return "Potion"; - } else if (lore.get(1).contains("Jack o")) { return "Jack o'Lantern"; } else { diff --git a/src/sig/plugin/TwosideKeeper/HelperStructures/MonsterDifficulty.java b/src/sig/plugin/TwosideKeeper/HelperStructures/MonsterDifficulty.java index 920e301..bccedb6 100644 --- a/src/sig/plugin/TwosideKeeper/HelperStructures/MonsterDifficulty.java +++ b/src/sig/plugin/TwosideKeeper/HelperStructures/MonsterDifficulty.java @@ -204,7 +204,7 @@ public enum MonsterDifficulty { for (int i=0;i0) { //This is a common roll. ItemStack gen_loot = DistributeRandomLoot(this.loot_regular, isRanger); @@ -213,7 +213,7 @@ public enum MonsterDifficulty { TwosideKeeper.Loot_Logger.AddCommonLoot(); } //Rare Loot roll. - if (Math.random()0) { //This is a common roll. ItemStack gen_loot = DistributeRandomLoot(this.loot_rare, isRanger); @@ -238,7 +238,7 @@ public enum MonsterDifficulty { TwosideKeeper.Loot_Logger.AddRareLoot(); } //Legendary Loot roll. - if (Math.random()0) { //This is a common roll. ItemStack gen_loot = DistributeRandomLoot(this.loot_legendary, isRanger); diff --git a/src/sig/plugin/TwosideKeeper/HelperStructures/ShopPurchase.java b/src/sig/plugin/TwosideKeeper/HelperStructures/ShopPurchase.java index b172d55..2b6d63e 100644 --- a/src/sig/plugin/TwosideKeeper/HelperStructures/ShopPurchase.java +++ b/src/sig/plugin/TwosideKeeper/HelperStructures/ShopPurchase.java @@ -16,22 +16,22 @@ import sig.plugin.TwosideKeeper.HelperStructures.Common.GenericFunctions; public class ShopPurchase { String player; String customer; - int shopID; + ItemStack item; double money; int amt; boolean sell; - public ShopPurchase(String p, Player customer, int shopID, double money, int amt) { - ShopPurchase(p,customer,shopID,money,amt,true); //Assume this is a selling purchase by default. + public ShopPurchase(String p, Player customer, ItemStack item, double money, int amt) { + ShopPurchase(p,customer,item,money,amt,true); //Assume this is a selling purchase by default. } - public ShopPurchase(String p, Player customer, int shopID, double money, int amt, boolean sell) { - ShopPurchase(p,customer,shopID,money,amt,sell); //Assume this is a selling purchase by default. + public ShopPurchase(String p, Player customer, ItemStack item, double money, int amt, boolean sell) { + ShopPurchase(p,customer,item,money,amt,sell); //Assume this is a selling purchase by default. } - public void ShopPurchase(String p, Player customer, int shopID, double money, int amt, boolean sell) { + public void ShopPurchase(String p, Player customer, ItemStack item, double money, int amt, boolean sell) { this.player = p; this.customer=customer.getName(); - this.shopID = shopID; + this.item=item; this.money = money; this.amt=amt; this.sell=sell; @@ -47,20 +47,18 @@ public class ShopPurchase { public TextComponent announcementString() { DecimalFormat df = new DecimalFormat("0.00"); if (sell) { - WorldShop ss = TwosideKeeper.TwosideShops.LoadWorldShopData(shopID); TextComponent message1 = new TextComponent("Player "+ChatColor.BLUE+customer+ChatColor.WHITE+" has purchased "+ChatColor.YELLOW+amt+ChatColor.WHITE+" of your "); - TextComponent message2 = new TextComponent(ChatColor.GREEN+"["+GenericFunctions.GetItemName(ss.GetItem())+ChatColor.RESET+""+ChatColor.GREEN+"]"); - message2.setHoverEvent(new HoverEvent( HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(GenericFunctions.GetItemName(ss.GetItem())+WorldShop.GetItemInfo(ss.GetItem())).create())); + TextComponent message2 = new TextComponent(ChatColor.GREEN+"["+GenericFunctions.GetItemName(this.item)+ChatColor.RESET+""+ChatColor.GREEN+"]"); + message2.setHoverEvent(new HoverEvent( HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(GenericFunctions.GetItemName(this.item)+WorldShop.GetItemInfo(this.item)).create())); TextComponent message3 = new TextComponent(". You have earned $"+df.format(money)+". "+ChatColor.GRAY+""+ChatColor.ITALIC+"(See /money)"); TextComponent finalmsg = message1; finalmsg.addExtra(message2); finalmsg.addExtra(message3); return finalmsg; } else { - WorldShop ss = TwosideKeeper.TwosideShops.LoadWorldShopData(shopID); TextComponent message1 = new TextComponent("Player "+ChatColor.BLUE+customer+ChatColor.WHITE+" has sold "+ChatColor.YELLOW+amt+ChatColor.WHITE+" "); - TextComponent message2 = new TextComponent(ChatColor.GREEN+"["+GenericFunctions.GetItemName(ss.GetItem())+ChatColor.RESET+""+ChatColor.GREEN+"]"); - message2.setHoverEvent(new HoverEvent( HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(GenericFunctions.GetItemName(ss.GetItem())+WorldShop.GetItemInfo(ss.GetItem())).create())); + TextComponent message2 = new TextComponent(ChatColor.GREEN+"["+GenericFunctions.GetItemName(this.item)+ChatColor.RESET+""+ChatColor.GREEN+"]"); + message2.setHoverEvent(new HoverEvent( HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(GenericFunctions.GetItemName(this.item)+WorldShop.GetItemInfo(this.item)).create())); TextComponent message3 = new TextComponent(" to you. $"+df.format(money)+" has been deducted from your bank account. "+ChatColor.GRAY+""+ChatColor.ITALIC+"(Check your shop to collect your items.)"); TextComponent finalmsg = message1; finalmsg.addExtra(message2); diff --git a/src/sig/plugin/TwosideKeeper/HelperStructures/WorldShop.java b/src/sig/plugin/TwosideKeeper/HelperStructures/WorldShop.java index a37182a..4e4b208 100644 --- a/src/sig/plugin/TwosideKeeper/HelperStructures/WorldShop.java +++ b/src/sig/plugin/TwosideKeeper/HelperStructures/WorldShop.java @@ -80,6 +80,9 @@ public class WorldShop { public void UpdateUnitPrice(double price) { this.price=price; } + public void UpdateItem(ItemStack item) { + this.item=item; + } public ItemStack GetItem() { return item; @@ -714,6 +717,38 @@ public class WorldShop { } } + 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); + for (int i=0;i lore = new ArrayList(); + if (m.hasLore()) { + lore = m.getLore(); + } + lore.add("WorldShop Display Item"); + m.setLore(lore); + checkdrop.setItemMeta(m); + + TwosideKeeper.log("Comparing item "+it.getItemStack().toString()+" to "+checkdrop.toString(),5); + if (it.getItemStack().isSimilar(checkdrop) && + Artifact.isArtifact(it.getItemStack())) { + TwosideKeeper.log("Same type.",5); + e.remove(); + e.setCustomNameVisible(false); + e.setCustomName(null); + } + } + } + } + public static void spawnShopItem(PlayerInteractEvent ev, Location loc, WorldShop shop) { //See if a drop entity is already here. boolean item_here=false; diff --git a/src/sig/plugin/TwosideKeeper/ItemCubeWindow.java b/src/sig/plugin/TwosideKeeper/ItemCubeWindow.java index e4a44e2..d868faa 100644 --- a/src/sig/plugin/TwosideKeeper/ItemCubeWindow.java +++ b/src/sig/plugin/TwosideKeeper/ItemCubeWindow.java @@ -17,14 +17,14 @@ public class ItemCubeWindow { } public static void addItemCubeWindow(Player p, int id, int size) { - PlayerStructure pd = (PlayerStructure)TwosideKeeper.playerdata.get(p.getUniqueId()); + PlayerStructure pd = PlayerStructure.GetPlayerStructure(p); pd.openeditemcube.add(new ItemCubeWindow(id, size)); pd.opened_inventory = true; TwosideKeeper.log("Item Cube Window added. List is now size "+pd.openeditemcube.size(),2); } public static void popItemCubeWindow(Player p) { - PlayerStructure pd = (PlayerStructure)TwosideKeeper.playerdata.get(p.getUniqueId()); + PlayerStructure pd = PlayerStructure.GetPlayerStructure(p); if (!pd.opened_inventory && pd.openeditemcube.size()>0) { ItemCubeWindow window = pd.openeditemcube.remove(pd.openeditemcube.size()-1); @@ -36,14 +36,14 @@ public class ItemCubeWindow { } public static void removeAllItemCubeWindows(Player p) { - PlayerStructure pd = (PlayerStructure)TwosideKeeper.playerdata.get(p.getUniqueId()); + PlayerStructure pd = PlayerStructure.GetPlayerStructure(p); pd.openeditemcube.clear(); } //New open item cube method to handle all opening of item cubes. public static void openItemCube(Player p, int id, int size, boolean addToList) { TwosideKeeper.log("Called.", 2); - PlayerStructure pd = (PlayerStructure)TwosideKeeper.playerdata.get(p.getUniqueId()); + PlayerStructure pd = PlayerStructure.GetPlayerStructure(p); if (addToList && isViewingItemCubeInventory(p)) { addItemCubeWindow(p,getViewingItemCubeID(p),getViewingItemCubeInventorySize(p)); @@ -62,7 +62,7 @@ public class ItemCubeWindow { } public static boolean isViewingItemCubeInventory(Player p) { - PlayerStructure pd = (PlayerStructure)TwosideKeeper.playerdata.get(p.getUniqueId()); + PlayerStructure pd = PlayerStructure.GetPlayerStructure(p); TwosideKeeper.log("Are we viewing it? "+pd.isViewingItemCube,2); return pd.isViewingItemCube; } diff --git a/src/sig/plugin/TwosideKeeper/Logging/DamageLogger.java b/src/sig/plugin/TwosideKeeper/Logging/DamageLogger.java new file mode 100644 index 0000000..74832d8 --- /dev/null +++ b/src/sig/plugin/TwosideKeeper/Logging/DamageLogger.java @@ -0,0 +1,132 @@ +package sig.plugin.TwosideKeeper.Logging; + +import java.text.DecimalFormat; +import java.util.HashMap; + +import org.bukkit.entity.Player; + +import com.google.common.collect.Iterables; + +import net.md_5.bungee.api.ChatColor; +import sig.plugin.TwosideKeeper.PlayerStructure; +import sig.plugin.TwosideKeeper.TwosideKeeper; + +public class DamageLogger { + HashMap breakdownlist; + double totaldmg; + double actualtotaldmg=0.0; + double calculatedtotaldmg=0.0; + double totalmult=0.0; + int totalhits=0; + String player; + long recordtime; + + public DamageLogger(Player p) { + this.breakdownlist=new HashMap(); + totaldmg=0; + this.player=p.getName(); + this.recordtime=TwosideKeeper.getServerTickTime(); + } + + public void startRecording() { + this.totaldmg=0; + this.calculatedtotaldmg=0.0; + this.actualtotaldmg=0.0; + this.breakdownlist.clear(); + this.totalmult=0.0; + this.totalhits=0; + this.recordtime=TwosideKeeper.getServerTickTime(); + } + + public void addMultiplierToLogger(String name, double val) { + if (val!=1.0) { + if (breakdownlist.containsKey(name)) { + //Add to the already existing value. + double dmg = breakdownlist.get(name); + dmg+=val; + breakdownlist.put(name, dmg); + } else { + breakdownlist.put(name, val); + } + totalmult+=val; + } + } + + public void addEventToLogger(String name, double val) { + if (val!=0.0) { + if (breakdownlist.containsKey(name)) { + //Add to the already existing value. + double dmg = breakdownlist.get(name); + dmg+=val; + breakdownlist.put(name, dmg); + } else { + breakdownlist.put(name, val); + } + totaldmg+=val; + } + } + + public void addCalculatedActualDamage(double val) { + this.actualtotaldmg+=val; + this.totalhits++; + } + + public void addCalculatedTotalDamage(double val) { + this.calculatedtotaldmg+=val; + } + + public String OutputResults() { + StringBuilder finalstring = new StringBuilder(); + DecimalFormat df = new DecimalFormat("0.00"); + for (int i=0;i0) { + finalstring.append(breakdownlist.keySet().toArray()[i]+": "+getPercentColor(breakdownlist.get(breakdownlist.keySet().toArray()[i]),totalmult)+"x"+df.format(breakdownlist.get(breakdownlist.keySet().toArray()[i])/this.totalhits)+" - "+df.format(((this.actualtotaldmg-this.totaldmg)*(breakdownlist.get(breakdownlist.keySet().toArray()[i])/this.totalmult)))+" dmg"); + } + } else { + if (breakdownlist.get(breakdownlist.keySet().toArray()[i])!=0.0d) { + finalstring.append(breakdownlist.keySet().toArray()[i]+": "+getPercentColor(breakdownlist.get(breakdownlist.keySet().toArray()[i]),totaldmg)+df.format(breakdownlist.get(breakdownlist.keySet().toArray()[i]))); + } + } + finalstring.append("\n"); + } + finalstring.append(ChatColor.GRAY+""+ChatColor.BOLD+" Raw Damage: "+df.format(actualtotaldmg)+"\n"); + finalstring.append(ChatColor.GOLD+""+ChatColor.ITALIC+" Final Damage: "+df.format(calculatedtotaldmg)+" (Average "+df.format((1-(this.calculatedtotaldmg/this.actualtotaldmg))*100)+"% Reduction)\n"); + double elapsedtime = ((TwosideKeeper.getServerTickTime()-recordtime)/20d); + double dps = actualtotaldmg/elapsedtime; + finalstring.append(ChatColor.YELLOW+" Elapsed Time: "+ChatColor.AQUA+df.format(elapsedtime)+"s "+ChatColor.WHITE+"("+df.format(dps)+" damage/sec)"); + return finalstring.toString(); + } + + private ChatColor getPercentColor(Double val, Double total) { + if (val/total>=0.9) { + return ChatColor.DARK_RED; + }else + if (val/total>=0.8) { + return ChatColor.RED; + }else + if (val/total>=0.7) { + return ChatColor.GOLD; + }else + if (val/total>=0.5) { + return ChatColor.YELLOW; + }else + if (val/total>=0.3) { + return ChatColor.GREEN; + }else + if (val/total>=0.2) { + return ChatColor.AQUA; + }else + if (val/total>=0.1) { + return ChatColor.DARK_AQUA; + } + return ChatColor.GRAY; + } + + public static void AddNewCalculation(Player p, String name, double val, double reducedval) { + PlayerStructure pd = TwosideKeeper.playerdata.get(p.getUniqueId()); + pd.damagedata.addEventToLogger(name, val); + pd.damagedata.addCalculatedActualDamage(val); + pd.damagedata.addCalculatedTotalDamage(reducedval); + } +} diff --git a/src/sig/plugin/TwosideKeeper/MonsterController.java b/src/sig/plugin/TwosideKeeper/MonsterController.java index 6841a69..308cb3a 100644 --- a/src/sig/plugin/TwosideKeeper/MonsterController.java +++ b/src/sig/plugin/TwosideKeeper/MonsterController.java @@ -13,6 +13,7 @@ import org.bukkit.block.banner.Pattern; import org.bukkit.block.banner.PatternType; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.EntityType; +import org.bukkit.entity.Guardian; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Monster; import org.bukkit.entity.Skeleton; @@ -65,7 +66,7 @@ public class MonsterController { } else { if (isZombieLeader(ent)) { Monster m = (Monster)ent; - m.setCustomName(ChatColor.WHITE+"Zombie Leader"); + SetupCustomName("",m); } return true; } @@ -78,7 +79,7 @@ public class MonsterController { } else { if (isZombieLeader(ent)) { Monster m = (Monster)ent; - m.setCustomName(ChatColor.WHITE+"Zombie Leader"); + SetupCustomName("",m); } return true; } @@ -92,7 +93,7 @@ public class MonsterController { } else { if (isZombieLeader(ent)) { Monster m = (Monster)ent; - m.setCustomName(ChatColor.WHITE+"Zombie Leader"); + SetupCustomName("",m); } return true; } @@ -515,7 +516,7 @@ public class MonsterController { ( (md==MonsterDifficulty.NORMAL && ent.getMaxHealth()>20) || (md==MonsterDifficulty.DANGEROUS && ent.getMaxHealth()>20*2) || - (md==MonsterDifficulty.DEADLY && ent.getMaxHealth()>20*2) || + (md==MonsterDifficulty.DEADLY && ent.getMaxHealth()>20*3) || (md==MonsterDifficulty.HELLFIRE && ent.getMaxHealth()>20*4) ) { @@ -560,11 +561,27 @@ public class MonsterController { } } + public static void SetupCustomName(String prefix, Monster m) { + String MonsterName = m.getType().toString().toLowerCase(); + if (m.getType()==EntityType.SKELETON) { + Skeleton ss = (Skeleton)m; + if (ss.getSkeletonType()==SkeletonType.WITHER) { + MonsterName = "wither skeleton"; + } + } + if (m.getType()==EntityType.GUARDIAN) { + Guardian gg = (Guardian)m; + if (gg.isElder()) { + MonsterName = "guardian boss"; + } + } + m.setCustomName(prefix.equalsIgnoreCase("")?"":(prefix+" ")+GenericFunctions.CapitalizeFirstLetters(MonsterName.replaceAll("_", " ")+(isZombieLeader(m)?" Leader":""))); + } + public static Monster convertMonster(Monster m, MonsterDifficulty md) { switch (md) { case DANGEROUS: { - String MonsterName = m.getType().toString().toLowerCase(); - m.setCustomName(ChatColor.DARK_AQUA+"Dangerous "+GenericFunctions.CapitalizeFirstLetters(MonsterName.replaceAll("_", " ")+(isZombieLeader(m)?" Leader":""))); + SetupCustomName(ChatColor.DARK_AQUA+"Dangerous",m); m.setMaxHealth(m.getMaxHealth()*2.0); m.setHealth(m.getMaxHealth()); if (isAllowedToEquipItems(m)) { @@ -576,11 +593,13 @@ public class MonsterController { m.setMaxHealth(20); m.setHealth(m.getMaxHealth()); } + if (!GenericFunctions.isArmoredMob(m)) { + m.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE,Integer.MAX_VALUE,1)); + } }break; case DEADLY: { - String MonsterName = m.getType().toString().toLowerCase(); - m.setCustomName(ChatColor.GOLD+"Deadly "+GenericFunctions.CapitalizeFirstLetters(MonsterName.replaceAll("_", " ")+(isZombieLeader(m)?" Leader":""))); - m.setMaxHealth(m.getMaxHealth()*2.0); + SetupCustomName(ChatColor.GOLD+"Deadly",m); + m.setMaxHealth(m.getMaxHealth()*3.0); m.setHealth(m.getMaxHealth()); if (isAllowedToEquipItems(m)) { m.getEquipment().clear(); @@ -592,10 +611,12 @@ public class MonsterController { m.setMaxHealth(50); m.setHealth(m.getMaxHealth()); } + if (!GenericFunctions.isArmoredMob(m)) { + m.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE,Integer.MAX_VALUE,3)); + } }break; case HELLFIRE:{ - String MonsterName = m.getType().toString().toLowerCase(); - m.setCustomName(ChatColor.DARK_RED+"Hellfire "+GenericFunctions.CapitalizeFirstLetters(MonsterName.replaceAll("_", " ")+(isZombieLeader(m)?" Leader":""))); + SetupCustomName(ChatColor.DARK_RED+"Hellfire",m); //m.setCustomName(ChatColor.DARK_AQUA+"Dangerous Mob"); //m.setCustomNameVisible(true); m.setMaxHealth(m.getMaxHealth()*4.0); @@ -615,15 +636,16 @@ public class MonsterController { m.setMaxHealth(200); m.setHealth(m.getMaxHealth()); } + if (!GenericFunctions.isArmoredMob(m)) { + m.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE,Integer.MAX_VALUE,5)); + } }break; default: { if (isAllowedToEquipItems(m)) { m.getEquipment().clear(); RandomizeEquipment(m,0); } - if (isZombieLeader(m)) { - m.setCustomName(ChatColor.WHITE+"Zombie Leader"); - } + SetupCustomName("",m); if(isZombieLeader(m)) { m.setMaxHealth(40); @@ -693,4 +715,24 @@ public class MonsterController { Monster m = (Monster)loc.getWorld().spawnEntity(loc, et); return MonsterController.convertMonster(m); } + + public static boolean isChargeZombie(Monster m) { + if (m.getType()==EntityType.ZOMBIE && + MonsterController.getMonsterDifficulty((Monster)m)==MonsterDifficulty.HELLFIRE && + !TwosideKeeper.chargezombies.contains((Monster)m)) { + return true; + } + return false; + } + + public static boolean isUndead(Monster m) { + if (m.getType()==EntityType.ZOMBIE || + m.getType()==EntityType.PIG_ZOMBIE || + m.getType()==EntityType.GIANT || + m.getType()==EntityType.SKELETON + ) { + return true; + } + return false; + } } diff --git a/src/sig/plugin/TwosideKeeper/NewCombat.java b/src/sig/plugin/TwosideKeeper/NewCombat.java new file mode 100644 index 0000000..53c14b2 --- /dev/null +++ b/src/sig/plugin/TwosideKeeper/NewCombat.java @@ -0,0 +1,1264 @@ +package sig.plugin.TwosideKeeper; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Difficulty; +import org.bukkit.Effect; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.block.Block; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Arrow; +import org.bukkit.entity.Creeper; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.MagmaCube; +import org.bukkit.entity.Monster; +import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; +import org.bukkit.entity.Skeleton; +import org.bukkit.entity.Slime; +import org.bukkit.entity.Spider; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.entity.EntityDamageEvent.DamageModifier; +import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import com.google.common.collect.Iterables; + +import sig.plugin.TwosideKeeper.HelperStructures.ArtifactAbility; +import sig.plugin.TwosideKeeper.HelperStructures.ArtifactAbilityApplyEffects; +import sig.plugin.TwosideKeeper.HelperStructures.BowMode; +import sig.plugin.TwosideKeeper.HelperStructures.Common.DamageType; +import sig.plugin.TwosideKeeper.HelperStructures.Common.GenericFunctions; + +public class NewCombat { + /** + * Returns the amount of damage dealt to target. + */ + public static double applyDamage(LivingEntity target, Entity damager) { + switch (DamageType.DetectType(target, damager)) { + case MOBVSMOB: + case MOBPROJECTILEVSMOB: + case MOBPROJECTILEVSPLAYER: + case MOBVSPLAYER: { + return calculateMobDamage(target, damager); + } + case PLAYERPROJECTILEVSMOB: + case PLAYERVSMOB: { + return calculatePlayerDamage(target, damager); + } + case OTHER: + default: { + return -1.0; + } + } + } + + //Set all damage modifiers from the game to 0. We will calculate our own value. + public static void setupTrueDamage(EntityDamageEvent ev) { + for (int i=0;i nearby = p.getNearbyEntities(2, 2, 2); + for (int i=0;i nearby =m.getLocation().getWorld().getNearbyEntities(m.getLocation(), range, range, range); + for (int i=0;i1.0; + addMultiplierToPlayerLogger(damager,"Headshot Mult",headshot_mult); + basemult*=headshot_mult; + //This is an arrow shot from a bow. + } + } + + applyOnHitEffects(weapon,basedmg * basemult,damager,target); + } else { + if (damager instanceof Arrow) { + return 4.5; //This is a basic arrow with no shooter. Deal some damage. + } else { + return 1.0; + } + } + + setPlayerTarget(damager,target,headshot,preemptive); + + return basedmg * basemult; + } + + private static void setPlayerTarget(Entity damager, LivingEntity target, boolean headshot, boolean preemptive) { + + LivingEntity shooter = getDamagerEntity(damager); + + if (shooter instanceof Player) { + Player pl = (shooter instanceof Player)?(Player)shooter:(Player)target; + PlayerStructure pd = (PlayerStructure)TwosideKeeper.playerdata.get(pl.getUniqueId()); + if (shooter instanceof Player) { + pd.target=getDamagerEntity(target); + } + TwosideKeeper.updateTitle(pl,headshot,preemptive); + } + } + + private static void performMegaKnockback(Entity damager,final LivingEntity target) { + if (damager instanceof Player) { + Player p = (Player)damager; + if (GenericFunctions.isRanger(p)) { + Bukkit.getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("TwosideKeeper"), new Runnable() { + public void run() { + target.setVelocity(target.getVelocity().setY(0.1).multiply(8)); + }} + ,1); + } + } + } + + private static double calculatePoisonEffectMultiplier(LivingEntity target) { + double mult = 1.0; + if (target!=null) { + mult += (GenericFunctions.getPotionEffectLevel(PotionEffectType.POISON, target)+1)*0.5; + mult += (GenericFunctions.getPotionEffectLevel(PotionEffectType.BLINDNESS, target)+1)*0.5; + } + return mult; + } + + static double calculatePartyAttackMultiplier(Player p) { + int partylevel = 0; + PlayerStructure pd = PlayerStructure.GetPlayerStructure(p); + if (pd.partybonus>0) { + return 1.0+(pd.partybonus*0.1); + } + return 1.0; + } + + static double getBaseArtifactDamageByType(ItemStack weapon) { + if (weapon.getType().toString().contains("SWORD")) { + return 3.0; + } else + if (weapon.getType().toString().contains("PICKAXE")) { + return 1.25; + } else + if (weapon.getType().toString().contains("PICKAXE")) { + return 1.25; + } else + if (weapon.getType().toString().contains("AXE")) { + return 4.0; + } else + if (weapon.getType().toString().contains("SPADE")) { + return 1.5; + } else + if (weapon.getType().toString().contains("BOW")) { + return 4.5; + } + return 1.0; + } + + static double getBaseDamageByType(ItemStack weapon) { + switch (weapon.getType()) { + case WOOD_SWORD:{ + return 3.0; + } + case STONE_SWORD:{ + return 4.0; + } + case GOLD_SWORD:{ + return 10.0; + } + case IRON_SWORD:{ + return 7.0; + } + case DIAMOND_SWORD:{ + return 9.0; + } + case WOOD_SPADE:{ + return 1.5; + } + case STONE_SPADE:{ + return 2.5; + } + case GOLD_SPADE:{ + return 8.0; + } + case IRON_SPADE:{ + return 5.0; + } + case DIAMOND_SPADE:{ + return 7.0; + } + case WOOD_PICKAXE:{ + return 1.25; + } + case STONE_PICKAXE:{ + return 2.0; + } + case GOLD_PICKAXE:{ + return 7.5; + } + case IRON_PICKAXE:{ + return 4.5; + } + case DIAMOND_PICKAXE:{ + return 6.0; + } + case WOOD_AXE:{ + return 4.0; + } + case STONE_AXE:{ + return 5.0; + } + case GOLD_AXE:{ + return 11.0; + } + case IRON_AXE:{ + return 8.0; + } + case DIAMOND_AXE:{ + return 9.0; + } + case BOW:{ + return 4.5; + } + default:{ + return 1.0; + } + } + } + + static LivingEntity getDamagerEntity(Entity damager) { + return (damager instanceof LivingEntity)?((LivingEntity)damager): + ((damager instanceof Projectile) && (((Projectile)damager).getShooter() instanceof LivingEntity))?(LivingEntity)((Projectile)damager).getShooter():null; + } + + static double calculateEnchantmentMultiplier(ItemStack weapon, Entity damager, LivingEntity target) { + double mult = 1.0; + boolean isBow = (weapon!=null && weapon.getType()==Material.BOW); //An exception for melee'ing with bows. + if (isBow && (damager instanceof Arrow)) { + double mult1 = (weapon.containsEnchantment(Enchantment.ARROW_DAMAGE))?1.0+weapon.getEnchantmentLevel(Enchantment.ARROW_DAMAGE)*0.1:1.0; + addMultiplierToPlayerLogger(damager,"POWER Mult",mult1); + mult*=mult1; + } else { + mult*=(weapon.containsEnchantment(Enchantment.DAMAGE_ALL))?1.0+weapon.getEnchantmentLevel(Enchantment.DAMAGE_ALL)*0.1:1.0; + if (weapon.containsEnchantment(Enchantment.DAMAGE_ARTHROPODS) && + (target instanceof Spider)) { + double mult1 = 1.0+weapon.getEnchantmentLevel(Enchantment.DAMAGE_ARTHROPODS)*0.1; + addMultiplierToPlayerLogger(damager,"BANE OF ARTHROPODS Mult",mult1); + mult*=mult1; + } + if (weapon.containsEnchantment(Enchantment.DAMAGE_UNDEAD) && + (target instanceof Monster) && MonsterController.isUndead((Monster)target)) { + double mult1 = 1.0+weapon.getEnchantmentLevel(Enchantment.DAMAGE_UNDEAD)*0.1; + addMultiplierToPlayerLogger(damager,"SMITE Mult",mult1); + mult*=mult1; + } + } + return mult; + } + + static double calculateArtifactAbilityDamageIncrease(ItemStack weapon, Entity damager, + LivingEntity target) { + double dmg = 0.0; + double dmg1 = GenericFunctions.getAbilityValue(ArtifactAbility.DAMAGE,weapon); + addToPlayerLogger(damager,"Artifact Ability - DAMAGE",dmg1); + dmg+=dmg1; + dmg1 = calculateExecutionDamage(weapon,target); + addToPlayerLogger(damager,"Artifact Ability - EXECUTION",dmg1); + dmg+=dmg1; + dmg1 = calculateHighwinderDamage(weapon,damager); + addToPlayerLogger(damager,"Artifact Ability - HIGHWINDER",dmg1); + dmg+=dmg1; + return dmg; + } + + private static double calculateHighwinderDamage(ItemStack weapon, Entity damager) { + double dmg = 0.0; + if (damager instanceof Player) { + Player p = (Player)damager; + PlayerStructure pd = PlayerStructure.GetPlayerStructure(p); + dmg += 93.182445*pd.velocity*GenericFunctions.getAbilityValue(ArtifactAbility.HIGHWINDER, weapon); + } + return dmg; + } + + static double calculateExecutionDamage(ItemStack weapon, LivingEntity target) { + if (target!=null) { + return getPercentHealthRemaining(target) + /20 + *GenericFunctions.getAbilityValue(ArtifactAbility.EXECUTION,weapon); + } + return 0.0; + } + + //Returns between 0-100. + static double getPercentHealthRemaining(LivingEntity target) { + return 100-(target.getHealth()/target.getMaxHealth()*100); + } + + static double calculateArtifactAbilityMultiplier(ItemStack weapon, Entity damager, LivingEntity target) { + double mult = 1.0; + double mult1 = calculatePlayerCriticalStrike(weapon,damager); + addMultiplierToPlayerLogger(damager,"Critical Strike Mult",mult1); + mult*=mult1; + mult1 = calculateBeliggerentMultiplier(weapon,damager); + addMultiplierToPlayerLogger(damager,"Belliggerent Mult",mult1); + mult*=mult1; + return mult; + } + + static double calculatePlayerCriticalStrike(ItemStack weapon, Entity damager) { + boolean criticalstrike=false; + TwosideKeeper.log("Crit Strike chance is "+0.01*GenericFunctions.getAbilityValue(ArtifactAbility.CRITICAL,weapon), 4); + criticalstrike = isCriticalStrike(0.01*GenericFunctions.getAbilityValue(ArtifactAbility.CRITICAL,weapon)); + if (damager instanceof Player && criticalstrike) { + Player p = (Player)damager; + p.playSound(p.getLocation(), Sound.ENTITY_PLAYER_ATTACK_CRIT, 1.0f, 1.0f); + } + return criticalstrike?(calculateCriticalStrikeMultiplier(weapon)):1.0; + } + + //Chance is between 0.0-1.0. 1.0 is 100%. + static boolean isCriticalStrike(double chance) { + return (Math.random()<=chance); + } + + static double calculateCriticalStrikeMultiplier(ItemStack weapon) { + double critdmg=2.0; + if (ArtifactAbility.containsEnchantment(ArtifactAbility.CRIT_DMG, weapon)) { + critdmg+=(GenericFunctions.getAbilityValue(ArtifactAbility.CRIT_DMG,weapon)-200)/100d; + } + return critdmg; + } + + static double calculateBeliggerentMultiplier(ItemStack weapon, Entity damager) { + double mult=1.0; + if (damager instanceof Player) { + Player p = (Player)damager; + PlayerStructure pd = PlayerStructure.GetPlayerStructure(p); + mult+=pd.swordcombo*GenericFunctions.getAbilityValue(ArtifactAbility.COMBO, weapon)/100d; + } + return mult; + } + + static double calculateStrikerMultiplier(Entity damager) { + double mult=1.0; + if (damager instanceof Player) { + Player p = (Player)damager; + if (GenericFunctions.isStriker(p)) { + double mult1 = (1-(p.getHealth()/p.getMaxHealth())); + addMultiplierToPlayerLogger(damager,"Striker Missing Health Mult",mult1); + mult += mult1; + mult1 = 0.10; + addMultiplierToPlayerLogger(damager,"Striker Passive Mult",mult1); + mult += mult1; //10% damage increase - striker passive. + } + } + return mult; + } + + static double calculateRangerMultiplier(Entity damager) { + double mult=1.0; + LivingEntity shooter = getDamagerEntity(damager); + if (shooter instanceof Player) { + Player p = (Player)shooter; + if (GenericFunctions.isRanger(p)) { + double mult1 = 4.0; + addMultiplierToPlayerLogger(damager,"Ranger Passive Mult",mult1); + mult *= mult1; //x4 damage - Ranger passive. + } + } + return mult; + } + + static double calculatePotionEffectMultiplier(LivingEntity damager) { + double mult = 1.0; + double mult1 = 1.0+(GenericFunctions.getPotionEffectLevel(PotionEffectType.INCREASE_DAMAGE, damager)+1)*0.1; + addMultiplierToPlayerLogger(damager,"STRENGTH Mult",mult1); + mult *= mult1; + + int weaknesslv = GenericFunctions.getPotionEffectLevel(PotionEffectType.WEAKNESS, damager)+1; + if (weaknesslv<=10) { + mult1 = 1.0-(weaknesslv*0.1); + addMultiplierToPlayerLogger(damager,ChatColor.RED+"WEAKNESS Mult",mult1); + mult *= 1.0-(weaknesslv*0.1); + } else { + addMultiplierToPlayerLogger(damager,ChatColor.RED+"WEAKNESS Mult",0.0); + mult = 0.0; + } + return mult; + } + + static boolean meleeWithBow(ItemStack weapon, Entity damager) { + if (weapon!=null && + weapon.getType()==Material.BOW && + (damager instanceof Player)) { + //That means this player melee'd with a bow. + TwosideKeeper.log("Melee with bow",2); + return true; + } else { + return false; + } + } + + static double calculateBowDrawbackMultiplier(ItemStack weapon, Entity damager) { + double mult=1.0; + LivingEntity shooter = getDamagerEntity(damager); + if (weapon.getType()==Material.BOW && + shooter instanceof Player) { + Player p = (Player)shooter; + PlayerStructure pd = PlayerStructure.GetPlayerStructure(p); + double mult1 = (pd.lastarrowwasinrangermode)?(pd.lastarrowpower/9000000d):(pd.lastarrowpower/9d); + addMultiplierToPlayerLogger(damager,"Base Arrow Damage Mult",mult1); + mult = mult1; + } + TwosideKeeper.log("mult is "+mult,5); + return mult; + } + + static void applyOnHitEffects(ItemStack weapon, double dmg, Entity damager, LivingEntity target) { + if (damager instanceof Player && target!=null) { + Player p = (Player)damager; + if (GenericFunctions.isArtifactEquip(p.getEquipment().getItemInMainHand()) && + GenericFunctions.isArtifactWeapon(p.getEquipment().getItemInMainHand())) { + double ratio = 1.0-CalculateDamageReduction(1,target,p); + AwakenedArtifact.addPotentialEXP(p.getEquipment().getItemInMainHand(), (int)(ratio*20)+5, p); + increaseArtifactArmorXP(p,(int)(ratio*10)+1); + List hitlist = getAOEList(weapon,target); + + boolean applyDeathMark=false; + + if (ArtifactAbility.getEnchantmentLevel(ArtifactAbility.DEATHMARK, p.getEquipment().getItemInMainHand())>0) { + applyDeathMark=true; + } + + for (int i=0;i finallist = hitlist; + Bukkit.getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("TwosideKeeper"), new Runnable() { + public void run() { + for (int i=0;i=TwosideKeeper.getServerTickTime()) { + pd.last_swordhit=TwosideKeeper.getServerTickTime(); + pd.swordcombo++; + } else { + pd.last_swordhit=TwosideKeeper.getServerTickTime(); + pd.swordcombo=1; + } + } + } + + static List getAOEList(ItemStack weapon, LivingEntity target) { + List list = new ArrayList(); + if (ArtifactAbility.containsEnchantment(ArtifactAbility.AOE, weapon)) { + double aoerange = GenericFunctions.getAbilityValue(ArtifactAbility.AOE, weapon); + if (target!=null) { + List nearbylist=target.getNearbyEntities(aoerange,aoerange,aoerange); + list = trimNonLivingEntities(nearbylist); + //list.remove(target); + } + } + list.add(target); + return list; + } + + static List trimNonLivingEntities(List entitylist) { + List livinglist = new ArrayList(); + for (int i=0;i0) { + protectionlevel+=armor[i].getEnchantmentLevel(Enchantment.PROTECTION_ENVIRONMENTAL); + } + if ((damager instanceof Projectile) && armor[i].getEnchantmentLevel(Enchantment.PROTECTION_PROJECTILE)>0) { + protectionlevel+=armor[i].getEnchantmentLevel(Enchantment.PROTECTION_PROJECTILE); + } + if ((damager instanceof Creeper) && armor[i].getEnchantmentLevel(Enchantment.PROTECTION_EXPLOSIONS)>0) { + protectionlevel+=armor[i].getEnchantmentLevel(Enchantment.PROTECTION_EXPLOSIONS); + } + + boolean isBlockArmor = GenericFunctions.isHardenedItem(armor[i]); + + if (target instanceof Monster) { + isBlockArmor=true; + } + + //If this is an artifact armor, we totally override the base damage reduction. + if (GenericFunctions.isArmor(armor[i]) && Artifact.isArtifact(armor[i])) { + //Let's change up the damage. + //double dmgval = ArtifactItemType.valueOf(Artifact.returnRawTool(armor[i].getType())).getDamageAmt(armor[i].getEnchantmentLevel(Enchantment.LUCK)); + double dmgval=-1; + if (dmgval!=-1) { + dmgreduction += dmgval; + } + } else { + switch (armor[i].getType()) { + case LEATHER_BOOTS: + case LEATHER_LEGGINGS: + case LEATHER_CHESTPLATE: + case LEATHER_HELMET: { + dmgreduction+=3*((isBlockArmor)?2:1); + }break; + case IRON_BOOTS: + case IRON_LEGGINGS: + case IRON_CHESTPLATE: + case IRON_HELMET: { + dmgreduction+=5*((isBlockArmor)?2:1); + }break; + case GOLD_BOOTS: + case GOLD_LEGGINGS: + case GOLD_CHESTPLATE: + case GOLD_HELMET: { + dmgreduction+=10*((isBlockArmor)?2:1); + }break; + case DIAMOND_BOOTS: + case DIAMOND_LEGGINGS: + case DIAMOND_CHESTPLATE: + case DIAMOND_HELMET: { + dmgreduction+=8*((isBlockArmor)?2:1); + }break; + } + } + + if (GenericFunctions.isArtifactEquip(armor[i])) { + double reductionamt = GenericFunctions.getAbilityValue(ArtifactAbility.DAMAGE_REDUCTION, armor[i]); + dmgreduction+=reductionamt; + TwosideKeeper.log("Reducing damage by "+reductionamt+"%",5); + if (ArtifactAbility.containsEnchantment(ArtifactAbility.GREED, armor[i])) { + dmgreduction /= Math.pow(ArtifactAbility.getEnchantmentLevel(ArtifactAbility.GREED, armor[i]),2); + } + } + } + } + + + //Check for resistance effect. + Collection target_effects = target.getActivePotionEffects(); + for (int i=0;i9) {partylevel=9;} + if (p.getLocation().getY()>=0) {TwosideKeeper.log("Light level: "+p.getLocation().add(0,0,0).getBlock().getLightLevel(),5);} + for (int i=0;i=0 && + p.isOnGround() && p.getLocation().add(0,0,0).getBlock().getLightLevel()<=4) { + double dmgreduce = 1d-(GenericFunctions.getAbilityValue(ArtifactAbility.SHADOWWALKER, p.getEquipment().getArmorContents()[i])/100d); + basedmg *= dmgreduce; + TwosideKeeper.log("Base damage became "+(dmgreduce*100)+"% of original amount.",5); + } + if (ArtifactAbility.containsEnchantment(ArtifactAbility.GREED, p.getEquipment().getArmorContents()[i])) { + dmgreduction /= Math.pow(ArtifactAbility.getEnchantmentLevel(ArtifactAbility.GREED, p.getEquipment().getArmorContents()[i]),2); + } + } + if (ArtifactAbility.containsEnchantment(ArtifactAbility.GREED, p.getEquipment().getItemInMainHand())) { + dmgreduction /= Math.pow(ArtifactAbility.getEnchantmentLevel(ArtifactAbility.GREED, p.getEquipment().getItemInMainHand()),2); + } + } + + //Blocking: -((p.isBlocking())?ev.getDamage()*0.33:0) //33% damage will be reduced if we are blocking. + //Shield: -((p.getEquipment().getItemInOffHand()!=null && p.getEquipment().getItemInOffHand().getType()==Material.SHIELD)?ev.getDamage()*0.05:0) //5% damage will be reduced if we are holding a shield. + + + resistlevel=(resistlevel>10)?10:resistlevel; + protectionlevel=(protectionlevel>100)?100:protectionlevel; + partylevel=(partylevel>100)?100:partylevel; + double finaldmg=(basedmg-(basedmg*(dmgreduction/100.0d))) + *((10-resistlevel)*0.1) + *((100-protectionlevel)*0.01) + *((10-partylevel)*0.1) + *((target instanceof Player && ((Player)target).isBlocking())?(GenericFunctions.isDefender((Player)target))?0.30:0.50:1) + *((target instanceof Player)?((GenericFunctions.isDefender((Player)target))?0.9:(target.getEquipment().getItemInOffHand()!=null && target.getEquipment().getItemInOffHand().getType()==Material.SHIELD)?0.95:1):1); + + if (basedmg!=finaldmg) { + TwosideKeeper.log("Original damage was: "+basedmg,5); + TwosideKeeper.log(finaldmg+" damage calculated for: "+target.getName()+".",5); + } + + if (damager instanceof Player) { + Player p = (Player)damager; + double healamt = finaldmg*GenericFunctions.getAbilityValue(ArtifactAbility.LIFESTEAL, p.getEquipment().getItemInMainHand())/100; + //log("Healed "+healamt+" damage.",2); + double newhealth = p.getHealth()+healamt; + if (newhealth>p.getMaxHealth()) { + p.setMaxHealth(p.getMaxHealth()); + } else { + p.setHealth(newhealth); + } + } + if (target instanceof Player) { + Player p = (Player)target; + PlayerStructure pd = PlayerStructure.GetPlayerStructure(p); + pd.prev_armordef = finaldmg; + } + return finaldmg; + } + + private static void playerAddArtifactEXP(LivingEntity target, double dmg) { + if (target instanceof Player) { + Player p = (Player)target; + increaseArtifactArmorXP(p,(int)dmg); + } + } + + private static double calculateHeadshotMultiplier(Entity arrow, ItemStack weapon, LivingEntity target) { + double mult = 1.0; + if (target instanceof Monster && + arrow instanceof Projectile) { + //Headshot conditions: + /* + * If Target is WEARING Helmet: + * ->Direction difference has to be anywhere between 110-250 degrees. + * + * In Addition, for ALL targets: + * ->Y must be greater than or equal to Eye Height - 0.22f . + * ->Perks or abilities with increased headshot hitbox size will multiply the 0.08 further, giving + * more access to the target's body. + */ + Monster m = (Monster)target; + Projectile proj = (Projectile)arrow; + Location arrowLoc = proj.getLocation(); + Location monsterHead = m.getEyeLocation(); + + double headshotvaly=0.22/TwosideKeeper.HEADSHOT_ACC; + double directionvaly=0.25/TwosideKeeper.HEADSHOT_ACC; + + if (proj.getShooter() instanceof Player) { + Player p = (Player)proj.getShooter(); + if (GenericFunctions.isRanger(p) && + GenericFunctions.getBowMode(weapon)==BowMode.SNIPE) { + headshotvaly *= 4; + } + + if (GenericFunctions.isArtifactEquip(weapon) && + ArtifactAbility.containsEnchantment(ArtifactAbility.MARKSMAN, weapon)) { + headshotvaly *= 1+(GenericFunctions.getAbilityValue(ArtifactAbility.MARKSMAN, weapon)/100d); + } + + if (proj.getTicksLived()>=4 || GenericFunctions.isRanger(p)) { + if (arrowWithinYBounds(arrowLoc,monsterHead,headshotvaly) && + arrowWithinHelmetBounds(arrowLoc,m,directionvaly)) { + + PlayerStructure pd = PlayerStructure.GetPlayerStructure(p); + + if (GenericFunctions.isRanger(p) && GenericFunctions.getBowMode(p.getEquipment().getItemInMainHand())==BowMode.SNIPE) { + if (pd.headshotcombo<8) {pd.headshotcombo++;} + double headshotincrease = (2+(pd.headshotcombo*0.25)); + mult*=headshotincrease; + p.sendMessage(ChatColor.DARK_RED+"Headshot! x"+(headshotincrease)+" Damage"); + if (p.hasPotionEffect(PotionEffectType.SLOW)) { + //Add to the current stack of SLOW. + for (int i1=0;i1monsterHead.getY(); + } + + private static void applyOnHitMobEffects(LivingEntity target, Entity damager) { + if (target instanceof Player) { + Player p = (Player)target; + if (GenericFunctions.isDefender(p)) { + int resistlevel = GenericFunctions.getPotionEffectLevel(PotionEffectType.DAMAGE_RESISTANCE, p); + if (resistlevel<4) { + p.removePotionEffect(PotionEffectType.DAMAGE_RESISTANCE); + p.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE,100,resistlevel+1)); + } else { + p.removePotionEffect(PotionEffectType.DAMAGE_RESISTANCE); + p.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE,100,resistlevel)); + } + } + } + } + + private static void addToPlayerLogger(Entity p, String event, double val) { + LivingEntity l = getDamagerEntity(p); + if (l!=null && l instanceof Player) { + PlayerStructure pd = PlayerStructure.GetPlayerStructure((Player)l); + if (pd.damagelogging) { + pd.damagedata.addEventToLogger(event, val); + } + } + } + + private static void addMultiplierToPlayerLogger(Entity p, String event, double val) { + LivingEntity l = getDamagerEntity(p); + if (l!=null && l instanceof Player) { + PlayerStructure pd = PlayerStructure.GetPlayerStructure((Player)l); + if (pd.damagelogging) { + pd.damagedata.addMultiplierToLogger(event, val); + } + } + } +} diff --git a/src/sig/plugin/TwosideKeeper/PlayerStructure.java b/src/sig/plugin/TwosideKeeper/PlayerStructure.java index facff77..40fd60a 100644 --- a/src/sig/plugin/TwosideKeeper/PlayerStructure.java +++ b/src/sig/plugin/TwosideKeeper/PlayerStructure.java @@ -3,6 +3,7 @@ package sig.plugin.TwosideKeeper; import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import org.bukkit.Bukkit; @@ -18,6 +19,8 @@ import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; +import sig.plugin.TwosideKeeper.Logging.DamageLogger; + /*PLAYER STRUCTURE * * Keeps external data and info about the player @@ -64,11 +67,16 @@ public class PlayerStructure { public int nextarrowxp = 0; //How much bonus XP to give to an Artifact Bow. public boolean hasfullrangerset=false; public double lastarrowpower=0; + public boolean lastarrowwasinrangermode=false; //true is ranger mode. public int headshotcombo=0; public List openeditemcube; public boolean openinginventory=false; public boolean fulldodge=false; public long last_dodge=TwosideKeeper.getServerTickTime(); + public long last_laugh_time=TwosideKeeper.getServerTickTime(); + public long last_rejuvenate=TwosideKeeper.getServerTickTime(); + public DamageLogger damagedata; + public boolean damagelogging=false; public double prev_weapondmg=0.0; public double prev_buffdmg=0.0; @@ -76,6 +84,8 @@ public class PlayerStructure { public double prev_armordef=0.0; public int debuffcount=0; + public boolean isViewingInventory=false; + public boolean destroyedminecart=false; //Needs the instance of the player object to get all other info. Only to be called at the beginning. public PlayerStructure(Player p, long serverTickTime) { @@ -114,10 +124,17 @@ public class PlayerStructure { this.openinginventory = false; this.fulldodge=false; this.last_dodge=TwosideKeeper.getServerTickTime(); + this.lastarrowwasinrangermode=false; + this.isViewingInventory=false; + this.destroyedminecart=false; + this.last_laugh_time=TwosideKeeper.getServerTickTime(); + this.last_rejuvenate=TwosideKeeper.getServerTickTime(); + this.damagedata = new DamageLogger(p); + this.damagelogging=false; //Set defaults first, in case this is a new user. + setDefaultCooldowns(p); loadConfig(); - - p.getInventory().addItem(new ItemStack(Material.PORTAL)); + p.getInventory().addItem(new ItemStack(Material.PORTAL)); //Check if new player. if (this.firstjoined == serverTickTime) { @@ -149,6 +166,27 @@ public class PlayerStructure { } } + private void setDefaultCooldowns(Player p) { + aPlugin.API.sendCooldownPacket(p, Material.BOW, TwosideKeeper.DODGE_COOLDOWN); + aPlugin.API.sendCooldownPacket(p, Material.BOW, TwosideKeeper.DODGE_COOLDOWN); + applyCooldownToAllTypes(p,"HOE",TwosideKeeper.DEATHMARK_COOLDOWN); + applyCooldownToAllTypes(p,"HOE",TwosideKeeper.DEATHMARK_COOLDOWN); + applyCooldownToAllTypes(p,"SPADE",TwosideKeeper.EARTHWAVE_COOLDOWN); + applyCooldownToAllTypes(p,"SPADE",TwosideKeeper.EARTHWAVE_COOLDOWN); + applyCooldownToAllTypes(p,"SWORD",TwosideKeeper.LINEDRIVE_COOLDOWN); + applyCooldownToAllTypes(p,"SWORD",TwosideKeeper.LINEDRIVE_COOLDOWN); + aPlugin.API.sendCooldownPacket(p, Material.SHIELD, TwosideKeeper.REJUVENATE_COOLDOWN); + aPlugin.API.sendCooldownPacket(p, Material.SHIELD, TwosideKeeper.REJUVENATE_COOLDOWN); + } + + private void applyCooldownToAllTypes(Player p, String item, int cooldown) { + aPlugin.API.sendCooldownPacket(p, Material.valueOf("WOOD_"+item), cooldown); + aPlugin.API.sendCooldownPacket(p, Material.valueOf("IRON_"+item), cooldown); + aPlugin.API.sendCooldownPacket(p, Material.valueOf("STONE_"+item), cooldown); + aPlugin.API.sendCooldownPacket(p, Material.valueOf("DIAMOND_"+item), cooldown); + aPlugin.API.sendCooldownPacket(p, Material.valueOf("GOLD_"+item), cooldown); + } + //Save the configuration. public void saveConfig() { File config; @@ -218,4 +256,13 @@ public class PlayerStructure { e.printStackTrace(); } } + + public static PlayerStructure GetPlayerStructure(Player p) { + if (TwosideKeeper.playerdata.containsKey(p.getUniqueId())) { + return TwosideKeeper.playerdata.get(p.getUniqueId()); + } else { + TwosideKeeper.log(ChatColor.DARK_RED+"[ERROR] Player Structure for player "+p.getName()+" was not initialized! Now creating one...",0); + return TwosideKeeper.playerdata.put(p.getUniqueId(), new PlayerStructure(p,TwosideKeeper.getServerTickTime())); + } + } } diff --git a/src/sig/plugin/TwosideKeeper/RecyclingCenter.java b/src/sig/plugin/TwosideKeeper/RecyclingCenter.java index 5ea8086..e6f2136 100644 --- a/src/sig/plugin/TwosideKeeper/RecyclingCenter.java +++ b/src/sig/plugin/TwosideKeeper/RecyclingCenter.java @@ -9,6 +9,7 @@ import java.util.Vector; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; +import org.bukkit.block.Block; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.inventory.ItemStack; @@ -98,4 +99,8 @@ public class RecyclingCenter { e.printStackTrace(); } } + + public static boolean isRecyclingCenter(Block b) { + return TwosideKeeper.TwosideRecyclingCenter.nodes.contains(new Location(b.getWorld(),b.getLocation().getBlockX(),b.getLocation().getBlockY(),b.getLocation().getBlockZ())); + } } diff --git a/src/sig/plugin/TwosideKeeper/TwosideKeeper.java b/src/sig/plugin/TwosideKeeper/TwosideKeeper.java index 03fbcb5..3e6256d 100644 --- a/src/sig/plugin/TwosideKeeper/TwosideKeeper.java +++ b/src/sig/plugin/TwosideKeeper/TwosideKeeper.java @@ -19,6 +19,7 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Color; import org.bukkit.Effect; +import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Particle; @@ -72,6 +73,8 @@ import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.entity.AreaEffectCloudApplyEvent; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; +import org.bukkit.event.entity.EntityCombustByBlockEvent; +import org.bukkit.event.entity.EntityCombustEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; @@ -109,6 +112,7 @@ import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerExpChangeEvent; import org.bukkit.event.player.PlayerFishEvent; import org.bukkit.event.player.PlayerFishEvent.State; +import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerItemBreakEvent; import org.bukkit.event.player.PlayerItemConsumeEvent; @@ -128,6 +132,7 @@ 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.EquipmentSlot; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.ItemStack; @@ -156,6 +161,10 @@ import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.TextComponent; +import net.minecraft.server.v1_9_R1.AttributeInstance; +import net.minecraft.server.v1_9_R1.EntityInsentient; +import net.minecraft.server.v1_9_R1.EntityLiving; +import net.minecraft.server.v1_9_R1.GenericAttributes; import net.minecraft.server.v1_9_R1.MinecraftServer; import net.minecraft.server.v1_9_R1.Vector3f; import sig.plugin.TwosideKeeper.HelperStructures.AnvilItem; @@ -181,6 +190,7 @@ import sig.plugin.TwosideKeeper.HelperStructures.WorldShop; import sig.plugin.TwosideKeeper.HelperStructures.WorldShopSession; import sig.plugin.TwosideKeeper.HelperStructures.Common.GenericFunctions; import sig.plugin.TwosideKeeper.Logging.BowModeLogger; +import sig.plugin.TwosideKeeper.Logging.DamageLogger; import sig.plugin.TwosideKeeper.Logging.LootLogger; import sig.plugin.TwosideKeeper.Logging.MysteriousEssenceLogger; import net.minecraft.server.v1_9_R1.MinecraftServer; @@ -213,31 +223,38 @@ 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.001953125; // 1/512 chance + public static double LEGENDARY_DROP_RATE=0.00390625; // 1/256 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. 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 final int DODGE_COOLDOWN=100; + public static final int DEATHMARK_COOLDOWN=240; + public static final int EARTHWAVE_COOLDOWN=300; + public static final int ERUPTION_COOLDOWN=100; + public static final int LINEDRIVE_COOLDOWN=160; + public static final int REJUVENATE_COOLDOWN=2400; + public static File filesave; - public static HashMap playerdata; - public static HashMap monsterdata; + public static HashMap playerdata; + public static HashMap monsterdata; public static SpleefManager TwosideSpleefGames; public static WorldShopManager TwosideShops; public static MysteriousEssenceLogger EssenceLogger; //The logger for Essences. public static BowModeLogger BowLogger; //The logger for Bow Modes. public static LootLogger Loot_Logger; //The logger for Loot. public static AutoUpdatePlugin pluginupdater; - public static Lag tpstracker; public static boolean restarting_server=false; public int TeamCounter = 0; public static List PartyList = new ArrayList(); public List colors_used = new ArrayList(); - public List chargezombies = new ArrayList(); + public static List chargezombies = new ArrayList(); - public RecyclingCenter TwosideRecyclingCenter; + public static RecyclingCenter TwosideRecyclingCenter; //Bank timers and users. public static HashMap banksessions; @@ -393,16 +410,11 @@ public class TwosideKeeper extends JavaPlugin implements Listener { if (SERVER_TYPE==ServerType.MAIN) { //Only perform this on the official servers. Test servers do not require constant updating. //Every 5 minutes, check for a plugin update. if (!restarting_server) { - Bukkit.getScheduler().scheduleSyncRepeatingTask(this, pluginupdater, 20*300, 20*300); + Bukkit.getScheduler().runTaskTimerAsynchronously(this, pluginupdater, 6000l, 6000l); } } - getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){ - public void run(){ - DecimalFormat df = new DecimalFormat("0.00"); - DiscordMessageSender.setPlaying(ChatColor.stripColor("TPS: "+df.format(MinecraftServer.getServer().recentTps[0])+" "+getWeatherIcon()+" "+getTimeOfDay()+" ("+Bukkit.getOnlinePlayers().size()+")")); - } - }, 300l, 300l); + getServer().getScheduler().runTaskLaterAsynchronously(this, new DiscordStatusUpdater(), 300l); //This is the constant timing method. getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){ @@ -425,9 +437,6 @@ public class TwosideKeeper extends JavaPlugin implements Listener { getServer().broadcastMessage(" "); */ //End Advertisements. - - - LASTSERVERCHECK=getServerTickTime(); } @@ -435,30 +444,34 @@ public class TwosideKeeper extends JavaPlugin implements Listener { Collection players = (Collection) getServer().getOnlinePlayers(); //Count the number of players sleeping. Compare to "sleepingplayers" count. log("[DEBUG] Time: "+Bukkit.getWorld("world").getTime()+" Full Time: "+Bukkit.getWorld("world").getFullTime() + " SERVERTICKTIME: "+getServerTickTime(),4); - if (players.size()>=2) { //This functionality only makes sense when two or more players are on. - int sleeping=0; - for (int i=0;i1) { getServer().broadcastMessage(ChatColor.GOLD+""+sleepingPlayers+" Player"+(sleepingPlayers!=1?"s are":" is")+" in bed "+ChatColor.WHITE+"("+sleepingPlayers+"/"+(players.size()/2)+")"); } - if (sleepingPlayers>=players.size()/2) { - //Make it the next day. + } + if (sleepingPlayers>=Math.max(players.size()/2,1)) { + //Make it the next day. + if (players.size()>1) { getServer().broadcastMessage(ChatColor.GOLD+"Enough Players sleeping! It's now morning!"); - - SERVERTICK=getServerTickTime(); - Bukkit.getWorld("world").setTime(0); - Bukkit.getWorld("world").setThundering(false); - STARTTIME=Bukkit.getWorld("world").getFullTime(); - LASTSERVERCHECK=getServerTickTime(); - //Make sure we keep SERVERTICK in check. - sleepingPlayers=0; } + Bukkit.getWorld("world").setFullTime(Bukkit.getWorld("world").getFullTime()+10); + + SERVERTICK=getServerTickTime(); + Bukkit.getWorld("world").setTime(0); + Bukkit.getWorld("world").setThundering(false); + STARTTIME=Bukkit.getWorld("world").getFullTime(); + LASTSERVERCHECK=getServerTickTime(); + //Make sure we keep SERVERTICK in check. + sleepingPlayers=0; } } @@ -474,7 +487,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { log("Debuffcount went up...",5); for (int i1=0;i14.317) { pd.velocity/=2; @@ -537,7 +550,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { pd.target=null; } - p.getAttribute(Attribute.GENERIC_ARMOR).setBaseValue(20*(1.0d-CalculateDamageReduction(1,p,p))+subtractVanillaArmorBar(p.getEquipment().getArmorContents())); + p.getAttribute(Attribute.GENERIC_ARMOR).setBaseValue(20*(1.0d-NewCombat.CalculateDamageReduction(1,p,p))+subtractVanillaArmorBar(p.getEquipment().getArmorContents())); if (pd.last_regen_time+HEALTH_REGENERATION_RATE<=getServerTickTime()) { pd.last_regen_time=getServerTickTime(); @@ -552,7 +565,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { double bonusregen = 0.0; for (int i1=0;i1=900) { if (p.getInventory().getArmorContents()[Integer.parseInt(args[1])-900]!=null) { - p.spigot().sendMessage(ArtifactAbility.GenerateMenu(ArtifactItemType.getArtifactItemTypeFromItemStack(p.getInventory().getArmorContents()[Integer.parseInt(args[1])-900]).getUpgradePath(), CalculateDamageReduction(1,p,p), p.getInventory().getArmorContents()[Integer.parseInt(args[1])-900],Integer.parseInt(args[1]))); + p.spigot().sendMessage(ArtifactAbility.GenerateMenu(ArtifactItemType.getArtifactItemTypeFromItemStack(p.getInventory().getArmorContents()[Integer.parseInt(args[1])-900]).getUpgradePath(), NewCombat.CalculateWeaponDamage(p, null), p.getInventory().getArmorContents()[Integer.parseInt(args[1])-900],Integer.parseInt(args[1]))); } } else { if (p.getEquipment().getItemInMainHand()!=null && GenericFunctions.isArtifactEquip(p.getEquipment().getItemInMainHand())) { - p.spigot().sendMessage(ArtifactAbility.GenerateMenu(ArtifactItemType.getArtifactItemTypeFromItemStack(p.getEquipment().getItemInMainHand()).getUpgradePath(), CalculateDamageReduction(1,p,p), p.getEquipment().getItemInMainHand())); + p.spigot().sendMessage(ArtifactAbility.GenerateMenu(ArtifactItemType.getArtifactItemTypeFromItemStack(p.getEquipment().getItemInMainHand()).getUpgradePath(), NewCombat.CalculateWeaponDamage(p, null), p.getEquipment().getItemInMainHand())); } } } else @@ -1044,7 +1064,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { p.getEquipment().getItemInMainHand().getType()!=Material.AIR && GenericFunctions.isArtifactEquip(p.getEquipment().getItemInMainHand())) { p.sendMessage("");p.sendMessage(""); - p.spigot().sendMessage(ArtifactAbility.GenerateMenu(ArtifactItemType.getArtifactItemTypeFromItemStack(p.getEquipment().getItemInMainHand()).getUpgradePath(), CalculateDamageReduction(1,p,p), p.getEquipment().getItemInMainHand())); + p.spigot().sendMessage(ArtifactAbility.GenerateMenu(ArtifactItemType.getArtifactItemTypeFromItemStack(p.getEquipment().getItemInMainHand()).getUpgradePath(), NewCombat.CalculateDamageReduction(1,p,p), p.getEquipment().getItemInMainHand())); } } return true; @@ -1065,6 +1085,17 @@ public class TwosideKeeper extends JavaPlugin implements Listener { } else { sender.sendMessage("Wrong arguments!"); } + } else + if (cmd.getName().equalsIgnoreCase("dps")) { + PlayerStructure pd = PlayerStructure.GetPlayerStructure((Player)sender); + if (pd.damagelogging) { + ((Player)sender).sendMessage(pd.damagedata.OutputResults()); + } else { + pd.damagedata.startRecording(); + ((Player)sender).sendMessage("Damage tracking has begun..."); + } + pd.damagelogging=!pd.damagelogging; + return true; } } else { //Implement console/admin version later (Let's you check any name's money.) @@ -1114,7 +1145,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { } if (SERVER_TYPE==ServerType.MAIN && !restarting_server) { - Bukkit.getScheduler().scheduleSyncDelayedTask(this, pluginupdater,1); + Bukkit.getScheduler().runTaskAsynchronously(this, pluginupdater); } playerdata.put(ev.getPlayer().getUniqueId(), new PlayerStructure(ev.getPlayer(),getServerTickTime())); log("[TASK] New Player Data has been added. Size of array: "+playerdata.size(),4); @@ -1579,7 +1610,8 @@ public class TwosideKeeper extends JavaPlugin implements Listener { 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(); + Chest c = (Chest)WorldShop.getBlockShopSignAttachedTo(current_session.GetSign()).getState(); + final Chest cc = c; ItemStack shopItem = shop.GetItem(); int dropAmt = amt; while (dropAmt>0) { @@ -1590,7 +1622,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { @Override public void run() { ev.getPlayer().getWorld().dropItem(ev.getPlayer().getLocation(), dropitem).setPickupDelay(0); - c.getInventory().removeItem(dropitem); + cc.getInventory().removeItem(dropitem); } },1); dropAmt-=shop.GetItem().getMaxStackSize(); @@ -1601,17 +1633,25 @@ public class TwosideKeeper extends JavaPlugin implements Listener { @Override public void run() { ev.getPlayer().getWorld().dropItem(ev.getPlayer().getLocation(), dropitem).setPickupDelay(0); - c.getInventory().removeItem(dropitem); + cc.getInventory().removeItem(dropitem); } },1); dropAmt=0; } } - TwosideShops.UpdateSign(shop, shopID, current_session.GetSign(),false); + TwosideShops.UpdateSign(shop, shop.getID(), current_session.GetSign(),false); TwosideShops.SaveWorldShopData(shop); + TwosideShops.AddNewPurchase(shop.GetOwner(), ev.getPlayer(), shop.GetItem(), amt*shop.GetUnitPrice(), amt); + final int ID = shopID; + Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() { + @Override + public void run() { + WorldShop shop = TwosideShops.SetupNextItemShop(TwosideShops.LoadWorldShopData(ID), cc, current_session.GetSign()); + TwosideShops.UpdateSign(shop, shop.getID(), current_session.GetSign(),false); + TwosideShops.SaveWorldShopData(shop); + }},1); TwosideShops.RemoveSession(ev.getPlayer()); givePlayerMoney(ev.getPlayer(), -amt*shop.GetUnitPrice()); - TwosideShops.AddNewPurchase(shop.GetOwner(), ev.getPlayer(), shop.getID(), amt*shop.GetUnitPrice(), amt); if (Bukkit.getPlayer(shop.GetOwner())!=null) { givePlayerMoney(Bukkit.getPlayer(shop.GetOwner()), amt*shop.GetUnitPrice()); } else { @@ -1669,7 +1709,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { TwosideShops.RemoveSession(ev.getPlayer()); givePlayerMoney(ev.getPlayer(), amt*shop.GetUnitPrice()); givePlayerBankMoney(shop.GetOwner(), -amt*shop.GetUnitPrice()); - TwosideShops.AddNewPurchase(shop.GetOwner(), ev.getPlayer(), shop.getID(), amt*shop.GetUnitPrice(), amt, false); + TwosideShops.AddNewPurchase(shop.GetOwner(), ev.getPlayer(), shop.GetItem(), amt*shop.GetUnitPrice(), amt, false); } else { ev.getPlayer().sendMessage(ChatColor.LIGHT_PURPLE+shop.GetOwner()+ChatColor.WHITE+" only has enough money in their bank to buy "+ChatColor.GREEN+(int)(getPlayerBankMoney(shop.GetOwner())/shop.GetUnitPrice())+ChatColor.WHITE+" of "+ChatColor.GREEN+shop.GetItemName()+ChatColor.WHITE+"! Please try again."); } @@ -1705,8 +1745,8 @@ public class TwosideKeeper extends JavaPlugin implements Listener { pos = ev.getMessage().indexOf("[]"); ev.setMessage(ev.getMessage().replace("[]", "")); log("pos is "+pos+" message is: {"+ev.getMessage()+"}",5); - DiscordMessageSender.sendRawMessageDiscord(("**"+ev.getPlayer().getName()+"** "+ev.getMessage().substring(0, pos)+"**["+ChatColor.stripColor(GenericFunctions.GetItemName(ev.getPlayer().getEquipment().getItemInMainHand()))+"]**"+"\n```"+WorldShop.GetItemInfo(ev.getPlayer().getEquipment().getItemInMainHand())+" ```\n"+ev.getMessage().substring(pos))); - Bukkit.dispatchCommand(Bukkit.getConsoleSender(),"tellraw @a [\"\",{\"text\":\"<"+ev.getPlayer().getName()+"> \"},{\"text\":\""+ev.getMessage().substring(0, pos)+"\"},{\"text\":\""+ChatColor.GREEN+"["+GenericFunctions.GetItemName(ev.getPlayer().getEquipment().getItemInMainHand())+ChatColor.RESET+ChatColor.GREEN+"]"+ChatColor.WHITE+"\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\""+GenericFunctions.GetItemName(ev.getPlayer().getEquipment().getItemInMainHand())+""+WorldShop.GetItemInfo(ev.getPlayer().getEquipment().getItemInMainHand()).replace("\"", "\\\"")+"\"}},{\"text\":\""+ev.getMessage().substring(pos)+"\"}]"); + DiscordMessageSender.sendRawMessageDiscord(("**"+ev.getPlayer().getName()+"** "+ev.getMessage().substring(0, pos)+"**["+ChatColor.stripColor(GenericFunctions.GetItemName(ev.getPlayer().getEquipment().getItemInMainHand()))+((ev.getPlayer().getEquipment().getItemInMainHand().getAmount()>1)?" x"+ev.getPlayer().getEquipment().getItemInMainHand().getAmount():"")+"]**"+"\n```"+WorldShop.GetItemInfo(ev.getPlayer().getEquipment().getItemInMainHand())+" ```\n"+ev.getMessage().substring(pos))); + Bukkit.dispatchCommand(Bukkit.getConsoleSender(),"tellraw @a [\"\",{\"text\":\"<"+ev.getPlayer().getName()+"> \"},{\"text\":\""+ev.getMessage().substring(0, pos)+"\"},{\"text\":\""+ChatColor.GREEN+"["+GenericFunctions.GetItemName(ev.getPlayer().getEquipment().getItemInMainHand())+ChatColor.RESET+ChatColor.YELLOW+((ev.getPlayer().getEquipment().getItemInMainHand().getAmount()>1)?" x"+ev.getPlayer().getEquipment().getItemInMainHand().getAmount():"")+ChatColor.GREEN+"]"+ChatColor.WHITE+"\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\""+GenericFunctions.GetItemName(ev.getPlayer().getEquipment().getItemInMainHand())+""+WorldShop.GetItemInfo(ev.getPlayer().getEquipment().getItemInMainHand()).replace("\"", "\\\"")+"\"}},{\"text\":\""+ev.getMessage().substring(pos)+"\"}]"); ev.setCancelled(true); } @@ -1734,8 +1774,16 @@ public class TwosideKeeper extends JavaPlugin implements Listener { } } + /*@EventHandler(priority=EventPriority.LOW) + public void onPlayerInteract(PlayerInteractEntityEvent ev) { + log("Clicked with "+ ev.getHand().name(),2); + log("Clicked on: "+ev.getRightClicked().getName(),2); + if (ev.getHand()==EquipmentSlot.OFF_HAND) {aPlugin.API.swingOffHand(ev.getPlayer());}; + }*/ + @EventHandler(priority=EventPriority.LOW) public void onPlayerInteract(PlayerInteractEvent ev) { + if (ev.isCancelled() && ev.getAction() == Action.RIGHT_CLICK_BLOCK) { return; } else { @@ -1815,20 +1863,14 @@ public class TwosideKeeper extends JavaPlugin implements Listener { } } - //Check for a roll attempt here. - if ((ev.getAction()==Action.LEFT_CLICK_AIR || ev.getAction()==Action.LEFT_CLICK_BLOCK)) { - Player p = ev.getPlayer(); - GenericFunctions.PerformDodge(p); - } - //Check for a Scythe right click here. if ((ev.getAction()==Action.RIGHT_CLICK_AIR || ev.getAction()==Action.RIGHT_CLICK_BLOCK) && GenericFunctions.isArtifactEquip(player.getEquipment().getItemInMainHand())) { PlayerStructure pd = (PlayerStructure)playerdata.get(player.getUniqueId()); //Make sure it's off cooldown. - if (pd.last_deathmark+2400) { - double dmg = ArtifactAbility.calculateValue(ArtifactAbility.DEATHMARK, player.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.LUCK), ArtifactAbility.getEnchantmentLevel(ArtifactAbility.DEATHMARK, player.getEquipment().getItemInMainHand())); + double dmg = GenericFunctions.getAbilityValue(ArtifactAbility.DEATHMARK, player.getEquipment().getItemInMainHand()); //Look for nearby mobs up to 10 blocks away. List nearby = player.getNearbyEntities(10, 10, 10); for (int i=0;i entities = player.getNearbyEntities(16, 16, 16); for (int i=0;i1)?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); } - } + } } @EventHandler(priority=EventPriority.LOW,ignoreCancelled = true) @@ -3440,7 +3523,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { } if (poisonlv>0 && ev.getCause()!=DamageCause.POISON) { ev.setDamage(ev.getDamage()+(ev.getDamage()*poisonlv*0.5)); - log("New damage set to "+ev.getDamage()+" from Poison "+poisonlv,3); + log("New damage set to "+ev.getDamage()+" from Poison "+poisonlv,5); } } @@ -3455,7 +3538,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { } if (poisonlv>0) { ev.setDamage(ev.getDamage()+(ev.getDamage()*poisonlv*0.5)); - log("New damage set to "+ev.getDamage()+" from Poison "+poisonlv,3); + log("New damage set to "+ev.getDamage()+" from Poison "+poisonlv,5); } } } @@ -3466,7 +3549,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { final Player p = (Player)e; if (GenericFunctions.isDefender(p) && p.isBlocking()) { - log("Reducing knockback...",2); + log("Reducing knockback...",3); Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() { public void run() { if (p!=null) { @@ -3497,7 +3580,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { } } - ev.setDamage(CalculateDamageReduction(ev.getDamage()*EXPLOSION_DMG_MULT*((100-protectionlevel)*0.01),p,null)); + ev.setDamage(NewCombat.CalculateDamageReduction(ev.getDamage()*EXPLOSION_DMG_MULT*((100-protectionlevel)*0.01),p,null)); log("Damage is "+ev.getDamage(),4); //ev.setDamage(CalculateDamageReduction(ev.getDamage()*EXPLOSION_DMG_MULT,p,null)); } @@ -3529,7 +3612,11 @@ public class TwosideKeeper extends JavaPlugin implements Listener { }} ,40); } else { - p.sendMessage(ChatColor.RED+""+ChatColor.ITALIC+"A Mysterious Entity looks at your empty pockets with disdain, then laughs chaotically as you fall to your doom."); + PlayerStructure pd = (PlayerStructure)playerdata.get(p.getUniqueId()); + if (pd.last_laugh_time+400 nearby = m.getLocation().getWorld().getNearbyEntities(m.getLocation(), 10, 10, 10); - for (int i=0;i hitlist = new ArrayList(); - //Apply Death mark to these mobs that got hit. - boolean applyDeathmark=false; - if (ArtifactAbility.getEnchantmentLevel(ArtifactAbility.DEATHMARK, p.getEquipment().getItemInMainHand())>0) { - hitlist.add(m); - applyDeathmark=true; - GenericFunctions.ApplyDeathMark(m); - } - //Deal AoE damage. - if (ArtifactAbility.containsEnchantment(ArtifactAbility.AOE, p.getEquipment().getItemInMainHand())) { - double checkrange = ArtifactAbility.calculateValue(ArtifactAbility.AOE, p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.LUCK), ArtifactAbility.getEnchantmentLevel(ArtifactAbility.AOE, p.getEquipment().getItemInMainHand())); - List entities = m.getNearbyEntities(checkrange, checkrange, checkrange); - int totalexp = 0; - for (int i=0;i finallist = hitlist; - Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() { - public void run() { - for (int i=0;i=getServerTickTime()) { - pd.last_swordhit=getServerTickTime(); - pd.swordcombo++; - log("Sword combo count is "+pd.swordcombo,5); - } else { - pd.last_swordhit=getServerTickTime(); - pd.swordcombo=1; - } - } - } - PlayerStructure pd = (PlayerStructure)playerdata.get(p.getUniqueId()); - if (GenericFunctions.isArtifactEquip(p.getEquipment().getItemInMainHand()) && - p.getEquipment().getItemInMainHand().getType().toString().contains("SPADE") && p.isSneaking()) { - if (ArtifactAbility.containsEnchantment(ArtifactAbility.ERUPTION, p.getEquipment().getItemInMainHand()) && - pd.last_shovelspell nearby = p.getNearbyEntities(2, 2, 2); - for (int i=0;i"+ + GenericFunctions.GetEntityDisplayName(ev.getEntity())+ChatColor.GRAY+": Damage dealt was "+dmg,2); } - else - if ((ev.getDamager() instanceof Arrow && - ev.getEntity() instanceof LivingEntity)) { - if (((Arrow)(ev.getDamager())).getShooter() instanceof Player) { - Player p = (Player)((Arrow)(ev.getDamager())).getShooter(); - LivingEntity m = (LivingEntity)ev.getEntity(); - if (m instanceof Monster) { - ((Monster)m).setTarget(p); - if (monsterdata.containsKey(((Monster)m).getUniqueId())) { - MonsterStructure ms = (MonsterStructure)monsterdata.get(((Monster)m).getUniqueId()); - ms.SetTarget(p); - } else { - monsterdata.put(((Monster)m).getUniqueId(),new MonsterStructure(p)); - } - } - - //Headshot detection. - //log("Abs() subtraction: "+(((Arrow)(ev.getDamager())).getLocation().subtract(m.getEyeLocation())).toString(),2); - - //Headshot conditions: - /* - * X and Z have to be within abs(2). - * Y has to be within abs(0.15). - */ - ev.setDamage(DamageModifier.MAGIC,0); - ev.setDamage(DamageModifier.RESISTANCE,0); - ev.setDamage(DamageModifier.ARMOR,0); - - Location arrowLoc = ((Arrow)(ev.getDamager())).getLocation().add(ev.getDamager().getVelocity()); - - - Location monsterHead = m.getEyeLocation(); - - log("Arrow Original Hit: "+((Arrow)(ev.getDamager())).getLocation().toString()+", Arrow+Velocity: "+arrowLoc.toString()+"::Velocity: "+ev.getDamager().getVelocity().toString()+", Head Target: "+monsterHead.toString(),2); - - boolean headshot=false; - - ev.setDamage(CalculateWeaponDamage(p,m)); - - - double headshotvalx=3.0/HEADSHOT_ACC; - double headshotvalz=3.0/HEADSHOT_ACC; - double headshotvaly=0.165/HEADSHOT_ACC; - - if (GenericFunctions.isArtifactEquip(p.getEquipment().getItemInMainHand())) { - headshotvalx+=headshotvalx*ArtifactAbility.calculateValue(ArtifactAbility.MARKSMAN, p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.LUCK), ArtifactAbility.getEnchantmentLevel(ArtifactAbility.MARKSMAN, p.getEquipment().getItemInMainHand()))/100; - headshotvaly+=headshotvaly*ArtifactAbility.calculateValue(ArtifactAbility.MARKSMAN, p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.LUCK), ArtifactAbility.getEnchantmentLevel(ArtifactAbility.MARKSMAN, p.getEquipment().getItemInMainHand()))/100; - headshotvalz+=headshotvalz*ArtifactAbility.calculateValue(ArtifactAbility.MARKSMAN, p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.LUCK), ArtifactAbility.getEnchantmentLevel(ArtifactAbility.MARKSMAN, p.getEquipment().getItemInMainHand()))/100; - } - - if (GenericFunctions.isRanger(p)) { - if (p.getLocation().distanceSquared(m.getLocation())>=64 || GenericFunctions.getBowMode(p.getEquipment().getItemInMainHand())==BowMode.CLOSE) { - headshotvalx*=4; - headshotvaly*=4; - headshotvalz*=4; - } - if (GenericFunctions.getBowMode(p.getEquipment().getItemInMainHand())==BowMode.SNIPE) { - headshotvalx*=3; - headshotvaly*=3; - headshotvalz*=3; - aPlugin.API.sendSoundlessExplosion(arrowLoc, 1); - } - } - - //Get the headshot multiplier based on arrow power. - PlayerStructure pd = (PlayerStructure)playerdata.get(p.getUniqueId()); - double mult=1d; - mult = (GenericFunctions.isRanger(p))?(pd.lastarrowpower/140d):(pd.lastarrowpower/9d); - ev.setDamage(ev.getDamage()*mult); - headshotvalx*=mult; - headshotvaly*=mult; - headshotvalz*=mult; - - log("Headshot hitbox size Multiplier: x"+mult,4); - log(headshotvalx+","+headshotvaly+","+headshotvalz,5); - log("X: "+Math.abs(arrowLoc.getX()-monsterHead.getX())+", Y: "+Math.abs(arrowLoc.getY()-monsterHead.getY())+", Z: "+Math.abs(arrowLoc.getZ()-monsterHead.getZ()),2); - - if (ev.getDamager().getTicksLived()>=4 || GenericFunctions.isRanger(p)) { - if (Math.abs(arrowLoc.getY()-monsterHead.getY())<=headshotvaly) { - if (Math.abs(arrowLoc.getZ()-monsterHead.getZ())<=headshotvalz && - Math.abs(arrowLoc.getX()-monsterHead.getX())<=headshotvalx) { - - if (GenericFunctions.isRanger(p) && GenericFunctions.getBowMode(p.getEquipment().getItemInMainHand())==BowMode.SNIPE) { - if (pd.headshotcombo<8) {pd.headshotcombo++;} - ev.setDamage(ev.getDamage()*(2+(pd.headshotcombo*0.25))); - p.sendMessage(ChatColor.DARK_RED+"Headshot! x"+(2+(pd.headshotcombo*0.25))+" Damage"); - if (p.hasPotionEffect(PotionEffectType.SLOW)) { - //Add to the current stack of BLINDNESS. - for (int i1=0;i1=0) { + NewCombat.setupTrueDamage(ev); //Apply this as true damage. + ev.setDamage(0); + if (ev.getEntity() instanceof LivingEntity) { + ((LivingEntity)ev.getEntity()).setNoDamageTicks(10); + double oldhp=((LivingEntity)ev.getEntity()).getHealth(); + GenericFunctions.subtractHealth((LivingEntity)ev.getEntity(),dmg); + log(ChatColor.BLUE+" "+oldhp+"->"+((LivingEntity)ev.getEntity()).getHealth()+" HP",3); + } + } //Negative damage doesn't make sense. We'd apply it normally. } @EventHandler(priority=EventPriority.LOW,ignoreCancelled = true) @@ -4325,6 +3859,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { @EventHandler(priority=EventPriority.LOW,ignoreCancelled = true) public void monsterDeathEvent(final EntityDeathEvent ev) { log("Has died.",5); + if (monsterdata.containsKey(ev.getEntity().getUniqueId())){ev.setDroppedExp(ev.getDroppedExp()+5);} if (ev.getEntity() instanceof Bat) { //Drop an essence. if (Math.random()<=0.3) { @@ -4343,12 +3878,12 @@ public class TwosideKeeper extends JavaPlugin implements Listener { final Location deathloc = m.getLocation(); MonsterStructure ms = null; if (monsterdata.containsKey(m.getUniqueId())) { - log("Killed by a player.",5); - killedByPlayer = true; ms = (MonsterStructure)monsterdata.get(m.getUniqueId()); } if (ms!=null && (ms.GetTarget() instanceof Player)) { + log("Killed by a player.",5); + killedByPlayer = true; Player p = (Player)ms.GetTarget(); if (p!=null && p.isOnline()) { if (GenericFunctions.isArtifactEquip(p.getEquipment().getItemInMainHand()) && @@ -4378,11 +3913,11 @@ public class TwosideKeeper extends JavaPlugin implements Listener { for (int i=0;i affected = ev.getAffectedEntities(); for (int i=0;i 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 lore = new ArrayList(); - 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(),5); - if (it.getItemStack().isSimilar(checkdrop) && - Artifact.isArtifact(it.getItemStack())) { - log("Same type.",5); - e.remove(); - e.setCustomNameVisible(false); - e.setCustomName(null); - TwosideShops.RemoveSession(p); - } - } - } + WorldShop.removeShopItem(s,shop); + TwosideKeeper.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!"); @@ -4988,7 +4500,9 @@ public class TwosideKeeper extends JavaPlugin implements Listener { arr.getCustomName()==null) { Player p = (Player)arr.getShooter(); if (GenericFunctions.isRanger(p)) { - arr.setVelocity(arr.getVelocity().multiply(4)); + if (GenericFunctions.getBowMode(p.getEquipment().getItemInMainHand())==BowMode.SNIPE) {arr.setVelocity(arr.getVelocity().multiply(1000));} + log(arr.getVelocity().lengthSquared()+"",5); + //arr.setVelocity(arr.getVelocity().multiply(3.0/arr.getVelocity().lengthSquared())); if (GenericFunctions.getBowMode(p.getEquipment().getItemInMainHand())==BowMode.SNIPE) { aPlugin.API.damageItem(p, p.getEquipment().getItemInMainHand(), 3); //p.getEquipment().getItemInMainHand().setDurability((short)(p.getEquipment().getItemInMainHand().getDurability()+1)); @@ -4997,7 +4511,8 @@ public class TwosideKeeper extends JavaPlugin implements Listener { } PlayerStructure pd = (PlayerStructure)playerdata.get(p.getUniqueId()); pd.lastarrowpower=arr.getVelocity().lengthSquared(); - log("Arrow velocity is "+arr.getVelocity().lengthSquared(),4); + pd.lastarrowwasinrangermode=(GenericFunctions.isRanger(p)&&GenericFunctions.getBowMode(p.getEquipment().getItemInMainHand())==BowMode.SNIPE); + log("Arrow velocity is "+arr.getVelocity().lengthSquared(),5); } } } @@ -5402,16 +4917,36 @@ public class TwosideKeeper extends JavaPlugin implements Listener { } } } + + @EventHandler(priority=EventPriority.LOW,ignoreCancelled = true) + public void MinecartDestroyEvent(VehicleDestroyEvent ev) { + if (ev.getAttacker() instanceof Player && + ev.getVehicle().getType()==EntityType.MINECART) { + Player p = (Player)(ev.getAttacker()); + PlayerStructure pd = (PlayerStructure)playerdata.get(p.getUniqueId()); + //p.sendMessage("Off."); + //Drop a minecart at the position. + pd.destroyedminecart=true; + ev.setCancelled(true); + ev.getVehicle().remove(); + ev.getVehicle().getWorld().dropItemNaturally(ev.getVehicle().getLocation().add(0,1,0), new ItemStack(Material.MINECART)); + } + } @EventHandler(priority=EventPriority.LOW,ignoreCancelled = true) public void MinecartExitEvent(VehicleExitEvent ev) { if (ev.getExited() instanceof Player && ev.getVehicle().getType()==EntityType.MINECART) { Player p = (Player)(ev.getExited()); + PlayerStructure pd = (PlayerStructure)playerdata.get(p.getUniqueId()); //p.sendMessage("Off."); //Drop a minecart at the position. - ev.getVehicle().getWorld().dropItemNaturally(ev.getVehicle().getLocation().add(0,1,0), new ItemStack(Material.MINECART)); - ev.getVehicle().remove(); + if (!pd.destroyedminecart) { + ev.getVehicle().remove(); + ev.getVehicle().getWorld().dropItemNaturally(ev.getExited().getLocation().add(0,1,0), new ItemStack(Material.MINECART)); + } else { + pd.destroyedminecart=false; + } } } @@ -5421,12 +4956,6 @@ public class TwosideKeeper extends JavaPlugin implements Listener { Player p = ev.getPlayer(); PlayerStructure pd = (PlayerStructure)playerdata.get(p.getUniqueId()); //This is the player data structure we are looking for. - if (!pd.enderdragon_spawned) { - pd.enderdragon_spawned=true; - //Spawn an ender dragon... - EnderDragon dragon = (EnderDragon)(ev.getTo().getWorld().spawnEntity(ev.getTo().add(new Location(ev.getTo().getWorld(),0,64,0)), EntityType.ENDER_DRAGON)); - dragon.setPhase(Phase.CIRCLING); - } } final Player p = ev.getPlayer(); Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() { @@ -5436,14 +4965,14 @@ public class TwosideKeeper extends JavaPlugin implements Listener { },20); } - public String getWeatherIcon() { + public static String getWeatherIcon() { long time = Bukkit.getWorld("world").getTime(); String weather = ""; if (Bukkit.getWorld("world").hasStorm()) {weather="\u2602";} else {if (time>=10000) {weather="\u263D";} else {weather="\u2600";}} return weather; } - public String getTimeOfDay() { + public static String getTimeOfDay() { long time = Bukkit.getWorld("world").getTime(); String tod = ""; if (time>0 && time<=3000) { @@ -5690,7 +5219,9 @@ public class TwosideKeeper extends JavaPlugin implements Listener { public static long getServerTickTime() { //As the SERVERTICK variable is never actually updated, //we have to recalculate the actual value of it if we want to use it. - return Math.round((Bukkit.getWorld("world").getFullTime()-STARTTIME)*DAYMULT+SERVERTICK); + long time = Math.round((Bukkit.getWorld("world").getFullTime()-STARTTIME)*DAYMULT+SERVERTICK); + log("Server Tick Time: "+time,5); + return time; } public static boolean isInteger(String s) { @@ -6043,8 +5574,8 @@ public class TwosideKeeper extends JavaPlugin implements Listener { } } if (GenericFunctions.isArtifactEquip(equipment[i])) { - log("Add in "+ArtifactAbility.calculateValue(ArtifactAbility.HEALTH, equipment[i].getEnchantmentLevel(Enchantment.LUCK), ArtifactAbility.getEnchantmentLevel(ArtifactAbility.HEALTH, equipment[i])),5); - hp += (double)ArtifactAbility.calculateValue(ArtifactAbility.HEALTH, equipment[i].getEnchantmentLevel(Enchantment.LUCK), ArtifactAbility.getEnchantmentLevel(ArtifactAbility.HEALTH, equipment[i])); + log("Add in "+GenericFunctions.getAbilityValue(ArtifactAbility.HEALTH, equipment[i]),5); + hp += (double)GenericFunctions.getAbilityValue(ArtifactAbility.HEALTH, equipment[i]); if (ArtifactAbility.containsEnchantment(ArtifactAbility.GREED, equipment[i])) { maxdeduction /= Math.pow(ArtifactAbility.getEnchantmentLevel(ArtifactAbility.GREED, equipment[i]),2)+1; @@ -6091,7 +5622,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { - public void updateTitle(final Player p, boolean headshot, boolean preemptive) { + public static void updateTitle(final Player p, boolean headshot, boolean preemptive) { if (preemptive) { updateTitle(p,ChatColor.BLUE+"!"); /* @@ -6106,7 +5637,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { } - public void updateTitle(final Player p, boolean headshot) { + public static void updateTitle(final Player p, boolean headshot) { if (headshot) { updateTitle(p,ChatColor.DARK_RED+"HEADSHOT !"); /* @@ -6120,15 +5651,15 @@ public class TwosideKeeper extends JavaPlugin implements Listener { } } - public void updateTitle(final Player p) { + public static void updateTitle(final Player p) { updateTitle(p, ""); } - public void updateTitle(final Player p, final String message1) { + public static void updateTitle(final Player p, final String message1) { //Updates the target title for this player. PlayerStructure pd = (PlayerStructure)playerdata.get(p.getUniqueId()); final PlayerStructure pd2=pd; - Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() { + Bukkit.getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("TwosideKeeper"), new Runnable() { public void run() { if (Bukkit.getPlayer(pd2.name)!=null && pd2.target!=null) { String MonsterName = pd2.target.getType().toString().toLowerCase(); @@ -6184,7 +5715,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { Bukkit.getScheduler().cancelTask(pd.title_task); pd.title_task=-1; } - pd.title_task=Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() { + pd.title_task=Bukkit.getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("TwosideKeeper"), new Runnable() { public void run() { if (Bukkit.getPlayer(pd2.name)!=null) { PlayerStructure pd = (PlayerStructure)playerdata.get(p.getUniqueId()); @@ -6208,233 +5739,6 @@ public class TwosideKeeper extends JavaPlugin implements Listener { }} ,1);*/ - public static double CalculateWeaponDamage(LivingEntity p, LivingEntity target) { - - ItemStack weapon = p.getEquipment().getItemInMainHand(); - - double basedmg = 0.0; - if (weapon!=null) { - switch (weapon.getType()) { - case WOOD_SWORD:{ - basedmg = 3.0; - }break; - case STONE_SWORD:{ - basedmg = 4.0; - }break; - case GOLD_SWORD:{ - basedmg = 10.0; - }break; - case IRON_SWORD:{ - basedmg = 7.0; - }break; - case DIAMOND_SWORD:{ - basedmg = 9.0; - }break; - case WOOD_SPADE:{ - basedmg = 1.5; - }break; - case STONE_SPADE:{ - basedmg = 2.5; - }break; - case GOLD_SPADE:{ - basedmg = 8.0; - }break; - case IRON_SPADE:{ - basedmg = 5.0; - }break; - case DIAMOND_SPADE:{ - basedmg = 7.0; - }break; - case WOOD_PICKAXE:{ - basedmg = 1.25; - }break; - case STONE_PICKAXE:{ - basedmg = 2.0; - }break; - case GOLD_PICKAXE:{ - basedmg = 7.5; - }break; - case IRON_PICKAXE:{ - basedmg = 4.5; - }break; - case DIAMOND_PICKAXE:{ - basedmg = 6.0; - }break; - case WOOD_AXE:{ - basedmg = 4.0; - }break; - case STONE_AXE:{ - basedmg = 5.0; - }break; - case GOLD_AXE:{ - basedmg = 11.0; - }break; - case IRON_AXE:{ - basedmg = 8.0; - }break; - case DIAMOND_AXE:{ - basedmg = 9.0; - }break; - default:{ - basedmg = 1.0; - } - } - } else { - basedmg=1.0; - } - - //If this is an artifact weapon, we totally override the base damage. - if (GenericFunctions.isTool(weapon) && Artifact.isArtifact(weapon)) { - //Let's change up the damage. - /* - * double dmgval = ArtifactItemType.valueOf(Artifact.returnRawTool(weapon.getType())).getDamageAmt(weapon.getEnchantmentLevel(Enchantment.LUCK)); - */ - double dmgval=-1; - if (dmgval!=-1) { - basedmg = dmgval+1.0; - } else { - basedmg = 1.0d; - } - } - - if (GenericFunctions.isHardenedItem(weapon)) { - basedmg*=2; - log("Damage: "+basedmg,2); - } - - if (weapon.getType()==Material.BOW) { - basedmg = 4.5; - } - - boolean striker=false; - boolean ranger=false; - if ((p instanceof Player) && GenericFunctions.isStriker((Player)p)) { - striker=true; - } - if ((p instanceof Player) && GenericFunctions.isRanger((Player)p)) { - ranger=true; - } - - - int partylevel = 0; - PlayerStructure pd = (PlayerStructure)playerdata.get(p.getUniqueId()); - if (pd.partybonus>0) { - partylevel = pd.partybonus; - log("Party level is "+partylevel,5); - if (partylevel>9) {partylevel=9;} - } - - pd.prev_partydmg = partylevel; - int sharpnesslevel=0; - //Apply player enchantments next. - //Each sharpness level increases damage by 0.5. - //Both Smite and Bane of Arthropods increases damage by 1.0 per level. - if (p.getEquipment().getItemInMainHand()!=null) { - if (weapon.getType()==Material.BOW) { - if (p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.ARROW_DAMAGE)>0) { - sharpnesslevel+=p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.ARROW_DAMAGE); - log("Player "+p.getName()+" has Power "+p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.ARROW_DAMAGE)+".",5); - } - } - else { - if (p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.DAMAGE_ALL)>0) { - sharpnesslevel+=p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.DAMAGE_ALL); - log("Player "+p.getName()+" has Sharpness "+p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.DAMAGE_ALL)+".",5); - } else - if (target!=null) { - if ((target.getType()==EntityType.ZOMBIE || target.getType()==EntityType.PIG_ZOMBIE || - target.getType()==EntityType.WITHER || target.getType()==EntityType.SKELETON) && - p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.DAMAGE_UNDEAD)>0) { - sharpnesslevel+=p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.DAMAGE_UNDEAD)*2; - log("Player "+p.getName()+" has Smite "+p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.DAMAGE_UNDEAD)+".",5); - } else - if ((target.getType()==EntityType.SPIDER || target.getType()==EntityType.CAVE_SPIDER || - target.getType()==EntityType.SILVERFISH || target.getType()==EntityType.ENDERMITE) && - p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.DAMAGE_ARTHROPODS)>0) { - sharpnesslevel+=p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.DAMAGE_ARTHROPODS)*2; - log("Player "+p.getName()+" has Bane of Arthropods "+p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.DAMAGE_ARTHROPODS)+".",5); - } - } - } - } - - - //Apply Artifact abilities next. - if (GenericFunctions.isArtifactEquip(p.getEquipment().getItemInMainHand())) { - //ArtifactAbility.calculateValue(ArtifactAbility.ARMOR_PEN, p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.LUCK), ArtifactAbility.getEnchantmentLevel(ArtifactAbility.ARMOR_PEN, p.getEquipment().getItemInMainHand())); - basedmg += ArtifactAbility.calculateValue(ArtifactAbility.DAMAGE, p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.LUCK), ArtifactAbility.getEnchantmentLevel(ArtifactAbility.DAMAGE, p.getEquipment().getItemInMainHand())); - if (target!=null) { - basedmg +=(100-(target.getHealth()/target.getMaxHealth()*100))/20*ArtifactAbility.calculateValue(ArtifactAbility.EXECUTION, p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.LUCK), ArtifactAbility.getEnchantmentLevel(ArtifactAbility.EXECUTION, p.getEquipment().getItemInMainHand())); - if ((striker && Math.random()<=0.2) || Math.random()<=0.01*ArtifactAbility.calculateValue(ArtifactAbility.CRITICAL, p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.LUCK), ArtifactAbility.getEnchantmentLevel(ArtifactAbility.CRITICAL, p.getEquipment().getItemInMainHand()))) { - //Landed a critical strike. - //log("Critical strike!",2); - if (p instanceof Player) { - ((Player)p).playSound(p.getLocation(), Sound.ENTITY_PLAYER_ATTACK_CRIT, 1.0f, 1.0f); - } - double dmgamt = 2d; - if (ArtifactAbility.containsEnchantment(ArtifactAbility.CRIT_DMG, p.getEquipment().getItemInMainHand())) { - dmgamt = 2d+((ArtifactAbility.calculateValue(ArtifactAbility.CRIT_DMG, p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.LUCK), ArtifactAbility.getEnchantmentLevel(ArtifactAbility.CRIT_DMG, p.getEquipment().getItemInMainHand()))-200)/100d); - } - log("Crit dmg multiplied by x"+dmgamt,5); - basedmg*=dmgamt; - } - } - if (93.182445*pd.velocity>4.317) { - double dmgamt = 93.182445*pd.velocity*ArtifactAbility.calculateValue(ArtifactAbility.HIGHWINDER, p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.LUCK), ArtifactAbility.getEnchantmentLevel(ArtifactAbility.HIGHWINDER, p.getEquipment().getItemInMainHand())); - log("Highwinder damage is "+dmgamt,5); - basedmg+=dmgamt; - } - - - double combopct = pd.swordcombo*ArtifactAbility.calculateValue(ArtifactAbility.COMBO, p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.LUCK), ArtifactAbility.getEnchantmentLevel(ArtifactAbility.COMBO, p.getEquipment().getItemInMainHand()))/100d; - log(combopct+" dmg added.",5); - basedmg = basedmg + (basedmg*combopct); - } - - if (striker) { - double dmgamt = 1+(1-(p.getHealth()/p.getMaxHealth())); - log("Damage increased by x"+dmgamt,5); - basedmg*=dmgamt; - } - - if (pd!=null) { - pd.prev_weapondmg = basedmg; - } - - int weaknesslevel = 0; - int strengthlevel = 0; - //Finally, apply a strength buff if the player has one. - //Strength effect increases damage by 10% per level of strength. - //Apply weakness if the player has it for some reason as well. - //Weakness effect decreases damage by 10% per level of weakness. - Collection player_effects = p.getActivePotionEffects(); - for (int i=0;i10)?10:weaknesslevel; - - double finalamt = (basedmg+(sharpnesslevel*0.5)) - *(1 + 0.1*partylevel) - *(1 + 0.1*strengthlevel) - *((10-weaknesslevel)*0.1) - *((striker)?1.1:1) - *((ranger)?4.0:1); - - return finalamt; - } - static public void openItemCubeInventory(Inventory inv, InventoryView inv_view) { //Check if this is an Item Cube inventory. //p.sendMessage("This is an Item Cube inventory."); @@ -6452,159 +5756,6 @@ public class TwosideKeeper extends JavaPlugin implements Listener { } } - static public double CalculateDamageReduction(double basedmg,LivingEntity target,Entity damager) { - ItemStack[] armor = target.getEquipment().getArmorContents(); - double dmgreduction = 0.0; - - int protectionlevel = 0; - int resistlevel = 0; - int partylevel = 0; - - if (target instanceof Player) { - if (GenericFunctions.HasFullRangerSet((Player)target)) { - dmgreduction+=20.0; - } - } - - for (int i=0;i0) { - protectionlevel+=armor[i].getEnchantmentLevel(Enchantment.PROTECTION_ENVIRONMENTAL); - } - if ((damager instanceof Arrow) && armor[i].getEnchantmentLevel(Enchantment.PROTECTION_PROJECTILE)>0) { - protectionlevel+=armor[i].getEnchantmentLevel(Enchantment.PROTECTION_PROJECTILE); - } - if ((damager instanceof Creeper) && armor[i].getEnchantmentLevel(Enchantment.PROTECTION_EXPLOSIONS)>0) { - protectionlevel+=armor[i].getEnchantmentLevel(Enchantment.PROTECTION_EXPLOSIONS); - } - - boolean isBlockArmor = GenericFunctions.isHardenedItem(armor[i]); - - if (target instanceof Monster) { - isBlockArmor=true; - } - - //If this is an artifact armor, we totally override the base damage reduction. - if (GenericFunctions.isArmor(armor[i]) && Artifact.isArtifact(armor[i])) { - //Let's change up the damage. - //double dmgval = ArtifactItemType.valueOf(Artifact.returnRawTool(armor[i].getType())).getDamageAmt(armor[i].getEnchantmentLevel(Enchantment.LUCK)); - double dmgval=-1; - if (dmgval!=-1) { - dmgreduction += dmgval; - } - } else { - switch (armor[i].getType()) { - case LEATHER_BOOTS: - case LEATHER_LEGGINGS: - case LEATHER_CHESTPLATE: - case LEATHER_HELMET: { - dmgreduction+=3*((isBlockArmor)?2:1); - }break; - case IRON_BOOTS: - case IRON_LEGGINGS: - case IRON_CHESTPLATE: - case IRON_HELMET: { - dmgreduction+=5*((isBlockArmor)?2:1); - }break; - case GOLD_BOOTS: - case GOLD_LEGGINGS: - case GOLD_CHESTPLATE: - case GOLD_HELMET: { - dmgreduction+=10*((isBlockArmor)?2:1); - }break; - case DIAMOND_BOOTS: - case DIAMOND_LEGGINGS: - case DIAMOND_CHESTPLATE: - case DIAMOND_HELMET: { - dmgreduction+=8*((isBlockArmor)?2:1); - }break; - } - } - - if (GenericFunctions.isArtifactEquip(armor[i])) { - double reductionamt = ArtifactAbility.calculateValue(ArtifactAbility.DAMAGE_REDUCTION, armor[i].getEnchantmentLevel(Enchantment.LUCK), ArtifactAbility.getEnchantmentLevel(ArtifactAbility.DAMAGE_REDUCTION, armor[i])); - dmgreduction+=reductionamt; - log("Reducing damage by "+reductionamt+"%",5); - if (ArtifactAbility.containsEnchantment(ArtifactAbility.GREED, armor[i])) { - dmgreduction /= Math.pow(ArtifactAbility.getEnchantmentLevel(ArtifactAbility.GREED, armor[i]),2); - } - } - } - } - - - //Check for resistance effect. - Collection target_effects = target.getActivePotionEffects(); - for (int i=0;i9) {partylevel=9;} - if (p.getLocation().getY()>=0) {log("Light level: "+p.getLocation().add(0,0,0).getBlock().getLightLevel(),5);} - for (int i=0;i=0 && - p.isOnGround() && p.getLocation().add(0,0,0).getBlock().getLightLevel()<=4) { - double dmgreduce = 1d-(ArtifactAbility.calculateValue(ArtifactAbility.SHADOWWALKER, p.getEquipment().getArmorContents()[i].getEnchantmentLevel(Enchantment.LUCK), ArtifactAbility.getEnchantmentLevel(ArtifactAbility.SHADOWWALKER, p.getEquipment().getArmorContents()[i]))/100d); - basedmg *= dmgreduce; - log("Base damage became "+(dmgreduce*100)+"% of original amount.",5); - } - if (ArtifactAbility.containsEnchantment(ArtifactAbility.GREED, p.getEquipment().getArmorContents()[i])) { - dmgreduction /= Math.pow(ArtifactAbility.getEnchantmentLevel(ArtifactAbility.GREED, p.getEquipment().getArmorContents()[i]),2); - } - } - if (ArtifactAbility.containsEnchantment(ArtifactAbility.GREED, p.getEquipment().getItemInMainHand())) { - dmgreduction /= Math.pow(ArtifactAbility.getEnchantmentLevel(ArtifactAbility.GREED, p.getEquipment().getItemInMainHand()),2); - } - } - - //Blocking: -((p.isBlocking())?ev.getDamage()*0.33:0) //33% damage will be reduced if we are blocking. - //Shield: -((p.getEquipment().getItemInOffHand()!=null && p.getEquipment().getItemInOffHand().getType()==Material.SHIELD)?ev.getDamage()*0.05:0) //5% damage will be reduced if we are holding a shield. - - - resistlevel=(resistlevel>10)?10:resistlevel; - protectionlevel=(protectionlevel>100)?100:protectionlevel; - partylevel=(partylevel>100)?100:partylevel; - double finaldmg=(basedmg-(basedmg*(dmgreduction/100.0d))) - *((10-resistlevel)*0.1) - *((100-protectionlevel)*0.01) - *((10-partylevel)*0.1) - *((target instanceof Player && ((Player)target).isBlocking())?(GenericFunctions.isDefender((Player)target))?0.30:0.50:1) - *((target instanceof Player)?((GenericFunctions.isDefender((Player)target))?0.9:(target.getEquipment().getItemInOffHand()!=null && target.getEquipment().getItemInOffHand().getType()==Material.SHIELD)?0.95:1):1); - - if (basedmg!=finaldmg) { - log("Original damage was: "+basedmg,5); - log(finaldmg+" damage calculated for: "+target.getName()+".",5); - } - - if (damager instanceof Player) { - Player p = (Player)damager; - double healamt = finaldmg*ArtifactAbility.calculateValue(ArtifactAbility.LIFESTEAL, p.getEquipment().getItemInMainHand().getEnchantmentLevel(Enchantment.LUCK), ArtifactAbility.getEnchantmentLevel(ArtifactAbility.LIFESTEAL, p.getEquipment().getItemInMainHand()))/100; - //log("Healed "+healamt+" damage.",2); - double newhealth = p.getHealth()+healamt; - if (newhealth>p.getMaxHealth()) { - p.setMaxHealth(p.getMaxHealth()); - } else { - p.setHealth(newhealth); - } - } - if (target instanceof Player) { - Player p = (Player)target; - PlayerStructure pd = (PlayerStructure)playerdata.get(p.getUniqueId()); - pd.prev_armordef = finaldmg; - } - return finaldmg; - } - /** * Removes amt amount of items from a player's inventory, given * an item. @@ -6628,7 +5779,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { } } - public ChatColor GetHeartColor(int colorval) { + public static ChatColor GetHeartColor(int colorval) { switch (colorval % 10) { case 0:{ return ChatColor.DARK_GRAY; @@ -6671,27 +5822,27 @@ public class TwosideKeeper extends JavaPlugin implements Listener { switch (loglv) { case 0: { //Only game breaking messages appear in level 0. - Bukkit.getLogger().severe(logmessage); + Bukkit.getConsoleSender().sendMessage(ChatColor.RED+ChatColor.stripColor(logmessage)); }break; case 1: { //Only warning messages appear in level 1. - Bukkit.getLogger().warning(logmessage); + Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW+ChatColor.stripColor(logmessage)); }break; case 2: { //Regular Gameplay information can appear here. - Bukkit.getLogger().info(logmessage); + Bukkit.getConsoleSender().sendMessage(logmessage); }break; case 3: { //Debug messages that generalize the events happening in the world. - Bukkit.getLogger().info(logmessage); + Bukkit.getConsoleSender().sendMessage(logmessage); }break; case 4: { //Debug messages that define the specifics of an event happening, including logic / number calculations. - Bukkit.getLogger().info(logmessage); + Bukkit.getConsoleSender().sendMessage(logmessage); }break; case 5: { //All messages possible. This may include messages that have very distinct purposes. - Bukkit.getLogger().info(logmessage); + Bukkit.getConsoleSender().sendMessage(logmessage); }break; } } @@ -6701,7 +5852,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { Bukkit.getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("TwosideKeeper"), new Runnable() { @Override public void run() { - Bukkit.getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("TwosideKeeper"), pluginupdater,1); + Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getPluginManager().getPlugin("TwosideKeeper"), pluginupdater); DiscordMessageSender.sendItalicizedRawMessageDiscord("The server is restarting in 1 minute for a plugin update!"); Bukkit.broadcastMessage(ChatColor.YELLOW+"The server is restarting in 1 minute for a plugin update!"); } @@ -6709,7 +5860,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { Bukkit.getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("TwosideKeeper"), new Runnable() { @Override public void run() { - Bukkit.getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("TwosideKeeper"), pluginupdater,1); + Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getPluginManager().getPlugin("TwosideKeeper"), pluginupdater); DiscordMessageSender.sendItalicizedRawMessageDiscord("The server is restarting in 10 seconds!"); Bukkit.broadcastMessage(ChatColor.RED+"The server is restarting in 10 seconds!"); } @@ -6717,7 +5868,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { Bukkit.getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("TwosideKeeper"), new Runnable() { @Override public void run() { - Bukkit.getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("TwosideKeeper"), pluginupdater,1); + Bukkit.getScheduler().runTask(Bukkit.getPluginManager().getPlugin("TwosideKeeper"), pluginupdater); Bukkit.savePlayers(); DiscordMessageSender.sendItalicizedRawMessageDiscord("Server is shutting down..."); for (int i=0;i=4 && i!=enchants.size()-1) { tc1.addExtra("\n"); @@ -6793,7 +5943,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { */ @Deprecated public static void DealDamageToMob(ItemStack weapon, LivingEntity damager, LivingEntity target) { - GenericFunctions.DealDamageToMob(CalculateWeaponDamage(damager,target), target, damager, false); + GenericFunctions.DealDamageToMob(NewCombat.CalculateWeaponDamage(damager,target), target, damager); } public static ServerType getServerType() { @@ -6817,4 +5967,8 @@ public class TwosideKeeper extends JavaPlugin implements Listener { p.playSound(p.getLocation(), Sound.ENTITY_ITEM_BREAK, 1.0f, 1.0f); p.sendMessage(ChatColor.DARK_RED+"Your "+ChatColor.YELLOW+((item.hasItemMeta() && item.getItemMeta().hasDisplayName())?item.getItemMeta().getDisplayName():GenericFunctions.UserFriendlyMaterialName(item))+ChatColor.DARK_RED+" has broken!"); } + + public static double CalculateDamageReduction(double dmg_amt, LivingEntity target, LivingEntity damager) { + return NewCombat.CalculateDamageReduction(dmg_amt, target, damager); + } } \ No newline at end of file diff --git a/src/sig/plugin/TwosideKeeper/TwosideKeeperAPI.java b/src/sig/plugin/TwosideKeeper/TwosideKeeperAPI.java index ee76bcd..6a55acc 100644 --- a/src/sig/plugin/TwosideKeeper/TwosideKeeperAPI.java +++ b/src/sig/plugin/TwosideKeeper/TwosideKeeperAPI.java @@ -4,6 +4,7 @@ import java.util.List; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.block.Block; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Monster; @@ -16,6 +17,7 @@ import sig.plugin.TwosideKeeper.HelperStructures.Loot; import sig.plugin.TwosideKeeper.HelperStructures.MonsterDifficulty; import sig.plugin.TwosideKeeper.HelperStructures.MonsterType; import sig.plugin.TwosideKeeper.HelperStructures.ServerType; +import sig.plugin.TwosideKeeper.HelperStructures.WorldShop; import sig.plugin.TwosideKeeper.HelperStructures.Common.GenericFunctions; public final class TwosideKeeperAPI { @@ -157,6 +159,16 @@ public final class TwosideKeeperAPI { return SpleefManager.playerIsPlayingSpleef(p); } + //World Shop COMMANDS. + public static boolean isWorldShop(Location l) { + return WorldShop.shopSignExists(l); + } + + //Recycling Center COMMANDS. + public static boolean isRecyclingCenter(Block b) { + return RecyclingCenter.isRecyclingCenter(b); + } + //Localization COMMANDS. public static String getLocalizedItemName(ItemStack i) { return GenericFunctions.UserFriendlyMaterialName(i); @@ -167,4 +179,9 @@ public final class TwosideKeeperAPI { public static String getLocalizedItemName(Material i, byte data) { return GenericFunctions.UserFriendlyMaterialName(i,data); } + + //Player COMMANDS. + public static double getPlayerVelocity(Player p) { + return GenericFunctions.GetPlayerVelocity(p); + } } diff --git a/src/sig/plugin/TwosideKeeper/WorldShopManager.java b/src/sig/plugin/TwosideKeeper/WorldShopManager.java index df4ac22..97e3dde 100644 --- a/src/sig/plugin/TwosideKeeper/WorldShopManager.java +++ b/src/sig/plugin/TwosideKeeper/WorldShopManager.java @@ -9,6 +9,7 @@ import java.util.List; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; +import org.bukkit.block.Chest; import org.bukkit.block.Sign; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; @@ -216,11 +217,11 @@ public class WorldShopManager { sessions.remove(ss); } - public void AddNewPurchase(String owner, Player purchaser, int shopID, double price, int amt) { - purchases.add(new ShopPurchase(owner, purchaser, shopID, price, amt)); + public void AddNewPurchase(String owner, Player purchaser, ItemStack item, double price, int amt) { + purchases.add(new ShopPurchase(owner, purchaser, item, price, amt)); } - public void AddNewPurchase(String owner, Player purchaser, int shopID, double price, int amt, boolean sell) { - purchases.add(new ShopPurchase(owner, purchaser, shopID, price, amt, sell)); + public void AddNewPurchase(String owner, Player purchaser, ItemStack item, double price, int amt, boolean sell) { + purchases.add(new ShopPurchase(owner, purchaser, item, price, amt, sell)); } public boolean PlayerHasPurchases(Player p) { for (int i=0;i