From 085e1683f72600323cd66081400bdaa0b9118060 Mon Sep 17 00:00:00 2001 From: UltraFaceguy Date: Thu, 26 Mar 2020 19:20:46 -0400 Subject: [PATCH 01/13] bumping version for development --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index fc741639..17499512 100644 --- a/pom.xml +++ b/pom.xml @@ -32,7 +32,7 @@ strife - 3.0.5 + 3.0.6-SNAPSHOT jar strife From 2aa93d66e03115813a62add65ea7c4e5a0797854 Mon Sep 17 00:00:00 2001 From: UltraFaceguy Date: Fri, 3 Apr 2020 22:47:14 -0400 Subject: [PATCH 02/13] Adding headdb and colorable leather armor to equipment --- pom.xml | 7 +++- .../managers/EntityEquipmentManager.java | 37 +++++++++++++++++-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 17499512..fd761076 100644 --- a/pom.xml +++ b/pom.xml @@ -89,7 +89,7 @@ LibsDisguises LibsDisguises - 9.9.3-SNAPSHOT + 9.9.9-SNAPSHOT provided @@ -104,6 +104,11 @@ 1.0.2 provided + + com.github.shynixn.headdatabase + hdb-api + 1.0 + diff --git a/src/main/java/land/face/strife/managers/EntityEquipmentManager.java b/src/main/java/land/face/strife/managers/EntityEquipmentManager.java index 97f03321..cab2520e 100644 --- a/src/main/java/land/face/strife/managers/EntityEquipmentManager.java +++ b/src/main/java/land/face/strife/managers/EntityEquipmentManager.java @@ -9,14 +9,19 @@ import java.util.Map; import land.face.strife.util.ItemUtil; import land.face.strife.util.LogUtil; +import me.arcaniax.hdb.api.HeadDatabaseAPI; +import org.bukkit.Bukkit; +import org.bukkit.Color; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.LeatherArmorMeta; public class EntityEquipmentManager { public static final EquipmentSlot[] SLOTS = EquipmentSlot.values(); + private HeadDatabaseAPI headDatabaseAPI = new HeadDatabaseAPI(); private final Map itemMap; public EntityEquipmentManager() { @@ -54,13 +59,39 @@ public void loadEquipmentItem(String key, ConfigurationSection cs) { ItemStack stack = new ItemStack(material); if (material == Material.PLAYER_HEAD) { - String base64 = cs.getString("base64", - "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNTIyODRlMTMyYmZkNjU5YmM2YWRhNDk3YzRmYTMwOTRjZDkzMjMxYTZiNTA1YTEyY2U3Y2Q1MTM1YmE4ZmY5MyJ9fX0="); - stack = ItemUtil.withBase64(stack, base64); + String base64 = cs.getString("base64"); + String hdbId = cs.getString("head-db-id"); + if (StringUtils.isNotBlank(base64)) { + stack = ItemUtil.withBase64(stack, base64); + } else if (StringUtils.isNotBlank(hdbId)) { + try { + stack = headDatabaseAPI.getItemHead(hdbId); + } catch (NullPointerException e) { + Bukkit.getLogger().warning("Invalid HeadDatabaseID! " + key + " | " + hdbId); + return; + } + Bukkit.getLogger().info("Loaded HDB Head " + hdbId + " successfully!"); + } else { + Bukkit.getLogger().warning("Invalid head config for key " + key); + return; + } + if (stack == null) { + Bukkit.getLogger().warning("Null head stack! Aborting... Key:" + key); + return; + } } else { stack = new ItemStack(material); } + if (stack.getItemMeta() instanceof LeatherArmorMeta) { + int rgb = cs.getInt("dye-rgb", -1); + if (rgb != -1) { + LeatherArmorMeta meta = ((LeatherArmorMeta) stack.getItemMeta()); + meta.setColor(Color.fromRGB(rgb)); + stack.setItemMeta(meta); + } + } + String name = cs.getString("name", ""); if (StringUtils.isNotBlank(name)) { ItemStackExtensionsKt.setDisplayName(stack, TextUtils.color(name)); From 0eb9c0e89d0cf7caab841edbbd752a424df9ed5b Mon Sep 17 00:00:00 2001 From: UltraFaceguy Date: Sat, 4 Apr 2020 13:12:01 -0400 Subject: [PATCH 03/13] Adding HeadDatabase as a softdepend to ensure the API is loaded --- src/main/resources/plugin.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index e4e48917..ab5895fd 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -3,7 +3,7 @@ version: ${project.version} main: land.face.strife.StrifePlugin api-version: 1.15 depend: [Facecore, ProtocolLib] -softdepend: [Loot, Bullion, LibsDisguises, SnazzyParties, DiscordSRV] +softdepend: [Loot, Bullion, LibsDisguises, SnazzyParties, DiscordSRV, HeadDatabase] commands: cast: From 3077b053251967b14016fc25f42477f42b726f08 Mon Sep 17 00:00:00 2001 From: UltraFaceguy Date: Sat, 4 Apr 2020 13:14:23 -0400 Subject: [PATCH 04/13] Massive optimization of memory usage! allowing gc to handle saved entities via WeakHashMaps Switching from FixedMetadataValue to weak references to prevent memory leak associated with that class --- .../java/land/face/strife/StrifePlugin.java | 10 +- .../java/land/face/strife/data/Spawner.java | 12 +-- .../land/face/strife/data/StrifeBossBar.java | 8 +- .../java/land/face/strife/data/StrifeMob.java | 53 ++++------ .../face/strife/data/effects/Counter.java | 3 +- .../strife/data/effects/EvokerFangEffect.java | 9 +- .../face/strife/data/effects/ShootBlock.java | 13 +-- .../strife/data/effects/ShootProjectile.java | 10 +- .../face/strife/listeners/CombatListener.java | 27 ++--- .../face/strife/listeners/DataListener.java | 13 +-- .../face/strife/listeners/DeathListener.java | 23 ++-- .../listeners/EvokerFangEffectListener.java | 12 ++- .../strife/listeners/ExperienceListener.java | 9 +- .../face/strife/listeners/FallListener.java | 3 +- .../face/strife/listeners/MinionListener.java | 5 +- .../face/strife/listeners/ShootListener.java | 9 +- .../face/strife/listeners/SpawnListener.java | 11 +- .../strife/listeners/StatUpdateListener.java | 10 +- .../strife/listeners/TargetingListener.java | 14 +-- .../listeners/UniqueSplashListener.java | 8 +- .../face/strife/managers/AbilityManager.java | 2 +- .../face/strife/managers/BossBarManager.java | 41 +++---- .../face/strife/managers/CounterManager.java | 25 +++-- .../managers/EntityEquipmentManager.java | 5 +- .../strife/managers/IndicatorManager.java | 5 - .../face/strife/managers/SpawnerManager.java | 6 -- .../face/strife/managers/StealthManager.java | 21 +--- .../strife/managers/StrifeMobManager.java | 77 ++++---------- .../strife/managers/UniqueEntityManager.java | 13 +-- ...edPruneTask.java => StrifeMobTracker.java} | 7 +- .../face/strife/timers/FallingBlockTimer.java | 3 +- .../land/face/strife/util/DamageUtil.java | 16 +-- .../land/face/strife/util/FireworkUtil.java | 4 +- .../land/face/strife/util/PlayerDataUtil.java | 2 - .../land/face/strife/util/ProjectileUtil.java | 78 ++++++++------ .../face/strife/util/SpecialStatusUtil.java | 100 ++++++++++++++++++ .../java/land/face/strife/util/StatUtil.java | 26 ++--- .../land/face/strife/util/TargetingUtil.java | 5 +- 38 files changed, 370 insertions(+), 328 deletions(-) rename src/main/java/land/face/strife/tasks/{TrackedPruneTask.java => StrifeMobTracker.java} (84%) create mode 100644 src/main/java/land/face/strife/util/SpecialStatusUtil.java diff --git a/src/main/java/land/face/strife/StrifePlugin.java b/src/main/java/land/face/strife/StrifePlugin.java index dfa5f631..c4c04345 100644 --- a/src/main/java/land/face/strife/StrifePlugin.java +++ b/src/main/java/land/face/strife/StrifePlugin.java @@ -140,7 +140,7 @@ import land.face.strife.tasks.SaveTask; import land.face.strife.tasks.SpawnerSpawnTask; import land.face.strife.tasks.StealthParticleTask; -import land.face.strife.tasks.TrackedPruneTask; +import land.face.strife.tasks.StrifeMobTracker; import land.face.strife.tasks.VirtualEntityTask; import land.face.strife.util.DamageUtil; import land.face.strife.util.LogUtil; @@ -339,7 +339,7 @@ public void enable() { loadSpawners(); SaveTask saveTask = new SaveTask(this); - TrackedPruneTask trackedPruneTask = new TrackedPruneTask(this); + StrifeMobTracker strifeMobTracker = new StrifeMobTracker(this); StealthParticleTask stealthParticleTask = new StealthParticleTask(stealthManager); ForceAttackSpeed forceAttackSpeed = new ForceAttackSpeed(); BarrierTask barrierTask = new BarrierTask(this); @@ -383,7 +383,7 @@ public void enable() { 20L * 5, // Start save after 5s 9L // Run slightly more often than every 0.5s to catch odd rounding )); - taskList.add(trackedPruneTask.runTaskTimer(this, + taskList.add(strifeMobTracker.runTaskTimer(this, 20L * 61, // Start save after 1 minute 20L * 60 // Run every 1 minute after that )); @@ -788,6 +788,10 @@ private void saveSpawners() { LogUtil.printDebug("Spawner " + spawnerId + " has been removed."); } } + if (spawnerManager.getSpawnerMap().size() == 0) { + Bukkit.getLogger().warning("Spawner map size in memory is 0. Not saving."); + return; + } for (String spawnerId : spawnerManager.getSpawnerMap().keySet()) { Spawner spawner = spawnerManager.getSpawnerMap().get(spawnerId); spawnerYAML.set(spawnerId + ".unique", spawner.getUniqueId()); diff --git a/src/main/java/land/face/strife/data/Spawner.java b/src/main/java/land/face/strife/data/Spawner.java index 9fb8124b..c4ef7ccd 100644 --- a/src/main/java/land/face/strife/data/Spawner.java +++ b/src/main/java/land/face/strife/data/Spawner.java @@ -1,7 +1,7 @@ package land.face.strife.data; -import io.netty.util.internal.ConcurrentSet; -import java.util.Set; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; import land.face.strife.StrifePlugin; import land.face.strife.util.LogUtil; import org.bukkit.Location; @@ -13,8 +13,8 @@ public class Spawner extends BukkitRunnable { public static int SPAWNER_OFFSET = 0; - private Set entities = new ConcurrentSet<>(); - private Set respawnTimes = new ConcurrentSet<>(); + private List entities = new CopyOnWriteArrayList<>(); + private List respawnTimes = new CopyOnWriteArrayList<>(); private final String id; private final String uniqueId; private final UniqueEntity uniqueEntity; @@ -124,7 +124,7 @@ public void setRespawnSeconds(long respawnSeconds) { this.respawnSeconds = respawnSeconds; } - public Set getEntities() { + public List getEntities() { return entities; } @@ -132,7 +132,7 @@ public void addEntity(LivingEntity trackedEntity) { entities.add(trackedEntity); } - public Set getRespawnTimes() { + public List getRespawnTimes() { return respawnTimes; } diff --git a/src/main/java/land/face/strife/data/StrifeBossBar.java b/src/main/java/land/face/strife/data/StrifeBossBar.java index 5db0fe0d..540fbb86 100644 --- a/src/main/java/land/face/strife/data/StrifeBossBar.java +++ b/src/main/java/land/face/strife/data/StrifeBossBar.java @@ -8,7 +8,7 @@ public class StrifeBossBar { private StrifeMob owner; - private Map playerUuidTickMap; + private Map viewers; private BossBar barrierBar; private BossBar healthBar; @@ -18,7 +18,7 @@ public StrifeBossBar(StrifeMob owner, BossBar barrierBar, BossBar healthBar) { this.owner = owner; this.healthBar = healthBar; this.barrierBar = barrierBar; - this.playerUuidTickMap = new ConcurrentHashMap<>(); + this.viewers = new ConcurrentHashMap<>(); this.dead = false; } @@ -26,8 +26,8 @@ public StrifeMob getOwner() { return owner; } - public Map getPlayerUuidTickMap() { - return playerUuidTickMap; + public Map getViewers() { + return viewers; } public BossBar getBarrierBar() { diff --git a/src/main/java/land/face/strife/data/StrifeMob.java b/src/main/java/land/face/strife/data/StrifeMob.java index 7f85c747..2b58eac7 100644 --- a/src/main/java/land/face/strife/data/StrifeMob.java +++ b/src/main/java/land/face/strife/data/StrifeMob.java @@ -1,9 +1,11 @@ package land.face.strife.data; import io.netty.util.internal.ConcurrentSet; +import java.lang.ref.WeakReference; import java.util.HashMap; import java.util.HashSet; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; @@ -14,7 +16,6 @@ import land.face.strife.managers.StatUpdateManager; import land.face.strife.stats.StrifeStat; import land.face.strife.stats.StrifeTrait; -import land.face.strife.timers.EntityAbilityTimer; import land.face.strife.util.LogUtil; import land.face.strife.util.StatUtil; import org.bukkit.Bukkit; @@ -29,8 +30,8 @@ public class StrifeMob { private final Map statCache = new HashMap<>(); private final Map tempBonuses = new HashMap<>(); - private final Champion champion; - private LivingEntity livingEntity; + private WeakReference champion; + private WeakReference livingEntity; private EntityAbilitySet abilitySet; private String uniqueEntityId = null; private Set mods = new HashSet<>(); @@ -41,31 +42,23 @@ public class StrifeMob { private boolean despawnOnUnload = false; private boolean charmImmune = false; - private LivingEntity master = null; + private WeakReference master; private final Set minions = new ConcurrentSet<>(); private final Map runningBuffs = new ConcurrentHashMap<>(); private final Map takenDamage = new HashMap<>(); - private EntityAbilityTimer abilityTimer; - private long buffCacheStamp = System.currentTimeMillis(); public StrifeMob(Champion champion) { - this.livingEntity = champion.getPlayer(); - this.champion = champion; + this.livingEntity = new WeakReference<>(champion.getPlayer()); + this.champion = new WeakReference<>(champion); } public StrifeMob(LivingEntity livingEntity) { - this.livingEntity = livingEntity; - this.champion = null; - } - - public void killAllTasks() { - if (abilityTimer != null) { - abilityTimer.cancel(); - } + this.livingEntity = new WeakReference<>(livingEntity); + this.champion = new WeakReference<>(null); } public void trackDamage(StrifeMob attacker, float amount) { @@ -106,11 +99,7 @@ public void forceSetStat(StrifeStat stat, float value) { } public LivingEntity getEntity() { - return livingEntity; - } - - public void setLivingEntity(LivingEntity livingEntity) { - this.livingEntity = livingEntity; + return livingEntity.get(); } public EntityAbilitySet getAbilitySet() { @@ -142,7 +131,7 @@ public void setFactions(Set factions) { } public Champion getChampion() { - return champion; + return champion == null ? null : champion.get(); } public Map getFinalStats() { @@ -195,15 +184,15 @@ public void addBuff(String buffId, Buff buff, double duration) { if (runningBuffs.get(buffId) == null || runningBuffs.get(buffId).isExpired()) { buff.setExpireTimeFromDuration(duration); runningBuffs.put(buffId, buff); - LogUtil.printDebug("Adding new buff: " + buffId + " to " + livingEntity.getName()); + LogUtil.printDebug("Adding new buff: " + buffId + " to " + livingEntity.get().getName()); return; } runningBuffs.get(buffId).bumpBuff(duration); - LogUtil.printDebug("Bumping buff: " + buffId + " for " + livingEntity.getName()); + LogUtil.printDebug("Bumping buff: " + buffId + " for " + livingEntity.get().getName()); } public boolean isMinionOf(StrifeMob strifeMob) { - return master == strifeMob.getEntity(); + return getMaster() == strifeMob.getEntity(); } public boolean isMasterOf(StrifeMob strifeMob) { @@ -220,10 +209,10 @@ public boolean isMasterOf(LivingEntity entity) { } public boolean hasTrait(StrifeTrait trait) { - if (champion == null) { + if (getChampion() == null) { return false; } - return champion.hasTrait(trait); + return Objects.requireNonNull(champion.get()).hasTrait(trait); } public Set getMinions() { @@ -241,15 +230,15 @@ public void addMinion(StrifeMob strifeMob) { strifeMob.forceSetStat(StrifeStat.ACCURACY_MULT, 0f); strifeMob.forceSetStat(StrifeStat.ACCURACY, StatUtil.getAccuracy(this)); strifeMob.setDespawnOnUnload(true); - strifeMob.setMaster(livingEntity); + strifeMob.setMaster(livingEntity.get()); } public LivingEntity getMaster() { - return master; + return master == null ? null : master.get(); } public void setMaster(LivingEntity master) { - this.master = master; + this.master = new WeakReference<>(master); } public Set getTempEffects() { @@ -272,10 +261,6 @@ public void setCharmImmune(boolean charmImmune) { this.charmImmune = charmImmune; } - public void setAbilityTimer(EntityAbilityTimer abilityTimer) { - this.abilityTimer = abilityTimer; - } - private Map getBuffStats() { Map stats = new HashMap<>(); for (Buff buff : runningBuffs.values()) { diff --git a/src/main/java/land/face/strife/data/effects/Counter.java b/src/main/java/land/face/strife/data/effects/Counter.java index 21606697..d4217cf4 100644 --- a/src/main/java/land/face/strife/data/effects/Counter.java +++ b/src/main/java/land/face/strife/data/effects/Counter.java @@ -17,8 +17,7 @@ public void apply(StrifeMob caster, StrifeMob target) { long endStamp = System.currentTimeMillis() + duration; CounterData counterData = new CounterData(endStamp, new ArrayList<>(effects)); counterData.setRemoveOnTrigger(removeOnTrigger); - StrifePlugin.getInstance().getCounterManager() - .addCounter(caster.getEntity().getUniqueId(), counterData); + StrifePlugin.getInstance().getCounterManager().addCounter(caster.getEntity(), counterData); } public void setDuration(int duration) { diff --git a/src/main/java/land/face/strife/data/effects/EvokerFangEffect.java b/src/main/java/land/face/strife/data/effects/EvokerFangEffect.java index 494d795c..f29706af 100644 --- a/src/main/java/land/face/strife/data/effects/EvokerFangEffect.java +++ b/src/main/java/land/face/strife/data/effects/EvokerFangEffect.java @@ -1,11 +1,11 @@ package land.face.strife.data.effects; +import java.util.Map; import java.util.Random; -import land.face.strife.StrifePlugin; +import java.util.WeakHashMap; import land.face.strife.data.StrifeMob; import org.bukkit.Location; import org.bukkit.entity.EvokerFangs; -import org.bukkit.metadata.FixedMetadataValue; public class EvokerFangEffect extends LocationEffect { @@ -15,7 +15,8 @@ public class EvokerFangEffect extends LocationEffect { private static final int MAX_GROUND_CHECK = 9; private static final Random RANDOM = new Random(); - public static final String FANG_META = "EFFECT_FANGS"; + + public static final Map FANG_EFFECT_MAP = new WeakHashMap<>(); @Override public void apply(StrifeMob caster, StrifeMob target) { @@ -46,7 +47,7 @@ public void applyAtLocation(StrifeMob caster, Location location) { } EvokerFangs fangs = fangLoc.getWorld().spawn(fangLoc, EvokerFangs.class); fangs.setOwner(caster.getEntity()); - fangs.setMetadata(FANG_META, new FixedMetadataValue(StrifePlugin.getInstance(), hitEffects)); + FANG_EFFECT_MAP.put(fangs, hitEffects); } } diff --git a/src/main/java/land/face/strife/data/effects/ShootBlock.java b/src/main/java/land/face/strife/data/effects/ShootBlock.java index b2814f12..e9d14cf5 100644 --- a/src/main/java/land/face/strife/data/effects/ShootBlock.java +++ b/src/main/java/land/face/strife/data/effects/ShootBlock.java @@ -1,17 +1,17 @@ package land.face.strife.data.effects; +import com.tealcube.minecraft.bukkit.shade.apache.commons.lang3.StringUtils; import java.util.HashSet; import java.util.List; import java.util.Set; -import land.face.strife.StrifePlugin; import land.face.strife.data.StrifeMob; import land.face.strife.timers.FallingBlockTimer; import land.face.strife.util.DamageUtil.OriginLocation; +import land.face.strife.util.SpecialStatusUtil; import land.face.strife.util.TargetingUtil; import org.bukkit.Location; import org.bukkit.block.data.BlockData; import org.bukkit.entity.FallingBlock; -import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.util.Vector; public class ShootBlock extends LocationEffect { @@ -51,15 +51,8 @@ public void applyAtLocation(StrifeMob caster, Location location) { block.setDropItem(false); block.setHurtEntities(false); - if (!hitEffects.isEmpty()) { - StringBuilder hitString = new StringBuilder(); - for (String s : hitEffects) { - hitString.append(s).append("~"); - } - block.setMetadata("EFFECT_PROJECTILE", - new FixedMetadataValue(StrifePlugin.getInstance(), hitString.toString())); - } FALLING_BLOCKS.add(new FallingBlockTimer(caster, block)); + SpecialStatusUtil.setHandledBlock(block, StringUtils.join(hitEffects, "~")); } } diff --git a/src/main/java/land/face/strife/data/effects/ShootProjectile.java b/src/main/java/land/face/strife/data/effects/ShootProjectile.java index 5cf09e64..1c855d48 100644 --- a/src/main/java/land/face/strife/data/effects/ShootProjectile.java +++ b/src/main/java/land/face/strife/data/effects/ShootProjectile.java @@ -1,7 +1,6 @@ package land.face.strife.data.effects; import java.util.List; -import land.face.strife.StrifePlugin; import land.face.strife.data.StrifeMob; import land.face.strife.stats.StrifeStat; import land.face.strife.util.DamageUtil.OriginLocation; @@ -23,7 +22,6 @@ import org.bukkit.entity.ThrowableProjectile; import org.bukkit.entity.WitherSkull; import org.bukkit.inventory.ItemStack; -import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.util.Vector; public class ShootProjectile extends Effect { @@ -101,11 +99,10 @@ public void apply(StrifeMob caster, StrifeMob target) { ((ShulkerBullet) projectile).setTarget(target.getEntity()); } projectile.setBounce(bounce); - ProjectileUtil.setProjctileAttackSpeedMeta(projectile, attackMultiplier); + ProjectileUtil.setAttackMult(projectile, (float) attackMultiplier); if (blockHitEffects) { - projectile.setMetadata("GROUND_TRIGGER", - new FixedMetadataValue(StrifePlugin.getInstance(), 1)); + ProjectileUtil.setGroundTrigger(projectile); } if (!hitEffects.isEmpty()) { @@ -113,8 +110,7 @@ public void apply(StrifeMob caster, StrifeMob target) { for (String s : hitEffects) { hitString.append(s).append("~"); } - projectile.setMetadata("EFFECT_PROJECTILE", - new FixedMetadataValue(StrifePlugin.getInstance(), hitString.toString())); + ProjectileUtil.setHitEffects(projectile, hitString.toString()); } if (disguise != null) { diff --git a/src/main/java/land/face/strife/listeners/CombatListener.java b/src/main/java/land/face/strife/listeners/CombatListener.java index 5a063ec2..2cf7b1a5 100644 --- a/src/main/java/land/face/strife/listeners/CombatListener.java +++ b/src/main/java/land/face/strife/listeners/CombatListener.java @@ -22,6 +22,7 @@ import static org.bukkit.event.entity.EntityDamageEvent.DamageModifier.BASE; import static org.bukkit.event.entity.EntityDamageEvent.DamageModifier.BLOCKING; +import com.tealcube.minecraft.bukkit.shade.apache.commons.lang3.StringUtils; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -35,9 +36,9 @@ import land.face.strife.util.DamageUtil; import land.face.strife.util.DamageUtil.AttackType; import land.face.strife.util.DamageUtil.DamageType; -import land.face.strife.util.FireworkUtil; import land.face.strife.util.ItemUtil; import land.face.strife.util.ProjectileUtil; +import land.face.strife.util.SpecialStatusUtil; import land.face.strife.util.TargetingUtil; import org.bukkit.Bukkit; import org.bukkit.entity.ArmorStand; @@ -97,8 +98,8 @@ public void handleFireworks(EntityDamageByEntityEvent event) { if (event.isCancelled()) { return; } - if (event.getDamager() instanceof Firework && event.getDamager() - .hasMetadata(FireworkUtil.FW_NO_DMG)) { + if (event.getDamager() instanceof Firework && SpecialStatusUtil + .isNoDamage((Firework) event.getDamager())) { event.setCancelled(true); } } @@ -162,12 +163,13 @@ public void strifeDamageHandler(EntityDamageByEntityEvent event) { if (event.getDamager() instanceof Projectile) { isProjectile = true; projectile = (Projectile) event.getDamager(); - if (projectile.hasMetadata("EFFECT_PROJECTILE")) { - extraEffects = projectile.getMetadata("EFFECT_PROJECTILE").get(0).asString().split("~"); + String hitEffects = ProjectileUtil.getHitEffects(projectile); + if (StringUtils.isNotBlank(hitEffects)) { + extraEffects = hitEffects.split("~"); } - if (projectile.hasMetadata(ProjectileUtil.SHOT_ID_META)) { - int shotId = projectile.getMetadata(ProjectileUtil.SHOT_ID_META).get(0).asInt(); - String idKey = ProjectileUtil.SHOT_ID_META + "_" + shotId; + int shotId = ProjectileUtil.getShotId(projectile); + if (shotId != 0) { + String idKey = "SHOT_HIT_" + shotId; if (defendEntity.hasMetadata(idKey)) { isMultishot = true; } else { @@ -191,8 +193,8 @@ public void strifeDamageHandler(EntityDamageByEntityEvent event) { AttackType attackType = DamageUtil.getAttackType(event); - if (isProjectile && projectile.hasMetadata(ProjectileUtil.ATTACK_SPEED_META)) { - attackMultiplier = projectile.getMetadata(ProjectileUtil.ATTACK_SPEED_META).get(0).asFloat(); + if (isProjectile) { + attackMultiplier = ProjectileUtil.getAttackMult(projectile); } if (attackType == AttackType.MELEE) { @@ -248,11 +250,12 @@ public void strifeDamageHandler(EntityDamageByEntityEvent event) { return; } - Map damage = DamageUtil.buildDamage(attacker, defender, damageModifiers); + Map damage = DamageUtil.buildDamage(attacker, defender, damageModifiers); DamageUtil.reduceDamage(attacker, defender, damage, damageModifiers); float finalDamage = DamageUtil.damage(attacker, defender, damage, damageModifiers); - StrifeDamageEvent strifeDamageEvent = new StrifeDamageEvent(attacker, defender, damageModifiers); + StrifeDamageEvent strifeDamageEvent = new StrifeDamageEvent(attacker, defender, + damageModifiers); strifeDamageEvent.setFinalDamage(finalDamage); Bukkit.getPluginManager().callEvent(strifeDamageEvent); diff --git a/src/main/java/land/face/strife/listeners/DataListener.java b/src/main/java/land/face/strife/listeners/DataListener.java index d65c6dbe..97e85d05 100644 --- a/src/main/java/land/face/strife/listeners/DataListener.java +++ b/src/main/java/land/face/strife/listeners/DataListener.java @@ -24,6 +24,7 @@ import land.face.strife.data.champion.Champion; import land.face.strife.stats.AbilitySlot; import land.face.strife.util.DamageUtil; +import land.face.strife.util.SpecialStatusUtil; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Material; @@ -79,14 +80,14 @@ public void onEntityCombust(final EntityCombustEvent event) { if (event instanceof EntityCombustByBlockEvent) { return; } - if (event.getEntity().hasMetadata("NO_BURN")) { + if (SpecialStatusUtil.isBurnImmune(event.getEntity())) { event.setCancelled(true); } } @EventHandler public void onTameUnique(final EntityTameEvent event) { - if (plugin.getStrifeMobManager().getMobUnsafe(event.getEntity().getUniqueId()) != null) { + if (!plugin.getStrifeMobManager().isTrackedEntity(event.getEntity())) { return; } event.setCancelled(true); @@ -118,7 +119,7 @@ public void onPlayerJoin(final PlayerJoinEvent event) { notifyUnusedPoints(event.getPlayer(), champion.getUnusedStatPoints()); } plugin.getBossBarManager().getSkillBar(champion); - plugin.getCounterManager().clearCounters(event.getPlayer().getUniqueId()); + plugin.getCounterManager().clearCounters(event.getPlayer()); ensureAbilitiesDontInstantCast(event.getPlayer()); Bukkit.getScheduler().runTaskLater(plugin, () -> plugin.getAbilityIconManager().setAllAbilityIcons(event.getPlayer()), 2L); @@ -146,7 +147,7 @@ private void doPlayerLeave(Player player) { plugin.getAbilityIconManager().removeIconItem(player, AbilitySlot.SLOT_A); plugin.getAbilityIconManager().removeIconItem(player, AbilitySlot.SLOT_B); plugin.getAbilityIconManager().removeIconItem(player, AbilitySlot.SLOT_C); - plugin.getCounterManager().clearCounters(player.getUniqueId()); + plugin.getCounterManager().clearCounters(player); } @EventHandler(priority = EventPriority.NORMAL) @@ -160,7 +161,7 @@ public void onPlayerRespawn(final PlayerRespawnEvent event) { plugin.getBarrierManager().createBarrierEntry( plugin.getStrifeMobManager().getStatMob(event.getPlayer())); plugin.getAbilityIconManager().setAllAbilityIcons(event.getPlayer()); - plugin.getCounterManager().clearCounters(event.getPlayer().getUniqueId()); + plugin.getCounterManager().clearCounters(event.getPlayer()); plugin.getEnergyManager().setEnergyUnsafe(event.getPlayer().getUniqueId(), 50000); event.getPlayer().setCooldown(Material.DIAMOND_CHESTPLATE, 100); Bukkit.getScheduler().runTaskLater(plugin, () -> @@ -198,7 +199,7 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) { if (!(event.getEntity() instanceof FallingBlock)) { return; } - if (event.getEntity().hasMetadata("EFFECT_PROJECTILE")) { + if (SpecialStatusUtil.isHandledBlock((FallingBlock) event.getEntity())) { event.setCancelled(true); } } diff --git a/src/main/java/land/face/strife/listeners/DeathListener.java b/src/main/java/land/face/strife/listeners/DeathListener.java index 091b9a61..21b2f296 100644 --- a/src/main/java/land/face/strife/listeners/DeathListener.java +++ b/src/main/java/land/face/strife/listeners/DeathListener.java @@ -18,7 +18,6 @@ */ package land.face.strife.listeners; -import java.util.UUID; import land.face.strife.StrifePlugin; import land.face.strife.data.StrifeMob; import land.face.strife.data.UniqueEntity; @@ -26,6 +25,7 @@ import land.face.strife.data.effects.EndlessEffect; import land.face.strife.stats.AbilitySlot; import land.face.strife.stats.StrifeStat; +import land.face.strife.util.SpecialStatusUtil; import land.face.strife.util.StatUtil; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -51,18 +51,20 @@ public void onEntityDeathEvent(EntityDeathEvent event) { return; } - if (event.getEntity().hasMetadata("SPAWNED")) { + if (SpecialStatusUtil.isSpawnerMob(event.getEntity())) { return; } - StrifeMob mob = plugin.getStrifeMobManager().getMobUnsafe(event.getEntity().getUniqueId()); - - if (mob != null) { - plugin.getAbilityManager().abilityCast(mob, TriggerAbilityType.DEATH); + if (!plugin.getStrifeMobManager().isTrackedEntity(event.getEntity())) { + event.setDroppedExp(0); + return; } - if (mob == null || mob.getMaster() != null || (mob.getUniqueEntityId() == null && mob - .isDespawnOnUnload())) { + StrifeMob mob = plugin.getStrifeMobManager().getStatMob(event.getEntity()); + + plugin.getAbilityManager().abilityCast(mob, TriggerAbilityType.DEATH); + + if (mob.getMaster() != null || (mob.getUniqueEntityId() == null && mob.isDespawnOnUnload())) { event.setDroppedExp(0); return; } @@ -87,9 +89,8 @@ public void onEntityDeathClearIconsAndStrifeMobs(final EntityDeathEvent event) { plugin.getAbilityIconManager().removeIconItem((Player) event.getEntity(), AbilitySlot.SLOT_B); plugin.getAbilityIconManager().removeIconItem((Player) event.getEntity(), AbilitySlot.SLOT_C); } else { - UUID uuid = event.getEntity().getUniqueId(); Bukkit.getScheduler().runTaskLater(plugin, - () -> plugin.getStrifeMobManager().removeMob(uuid), 20L * 30); + () -> plugin.getStrifeMobManager().removeEntity(event.getEntity()), 2L); } } @@ -100,6 +101,6 @@ public void onEntityDeathClearData(final EntityDeathEvent event) { plugin.getRageManager().clearRage(event.getEntity().getUniqueId()); plugin.getBleedManager().clearBleed(event.getEntity().getUniqueId()); plugin.getSpawnerManager().addRespawnTime(event.getEntity()); - plugin.getCounterManager().clearCounters(event.getEntity().getUniqueId()); + plugin.getCounterManager().clearCounters(event.getEntity()); } } diff --git a/src/main/java/land/face/strife/listeners/EvokerFangEffectListener.java b/src/main/java/land/face/strife/listeners/EvokerFangEffectListener.java index 9df1c1ce..aa4c0b62 100644 --- a/src/main/java/land/face/strife/listeners/EvokerFangEffectListener.java +++ b/src/main/java/land/face/strife/listeners/EvokerFangEffectListener.java @@ -1,5 +1,6 @@ package land.face.strife.listeners; +import com.tealcube.minecraft.bukkit.shade.apache.commons.lang3.StringUtils; import java.util.Objects; import land.face.strife.data.StrifeMob; import land.face.strife.data.effects.EvokerFangEffect; @@ -30,17 +31,18 @@ public void onEvokerFangHit(EntityDamageByEntityEvent event) { if (!(event.getEntity() instanceof LivingEntity)) { return; } - if (!event.getDamager().hasMetadata(EvokerFangEffect.FANG_META)) { + String effects = EvokerFangEffect.FANG_EFFECT_MAP.getOrDefault(event.getDamager(), null); + if (StringUtils.isBlank(effects)) { return; } - String[] effects = event.getDamager().getMetadata(EvokerFangEffect.FANG_META).get(0).asString() - .split("~"); - if (effects.length == 0) { + + String[] split = effects.split("~"); + if (split.length == 0) { return; } EvokerFangs fangs = (EvokerFangs) event.getDamager(); StrifeMob attacker = strifeMobManager.getStatMob(Objects.requireNonNull(fangs.getOwner())); - for (String s : effects) { + for (String s : split) { effectManager.execute(effectManager.getEffect(s), attacker, (LivingEntity) event.getEntity()); } event.setCancelled(true); diff --git a/src/main/java/land/face/strife/listeners/ExperienceListener.java b/src/main/java/land/face/strife/listeners/ExperienceListener.java index edb38184..30f2633c 100644 --- a/src/main/java/land/face/strife/listeners/ExperienceListener.java +++ b/src/main/java/land/face/strife/listeners/ExperienceListener.java @@ -27,6 +27,7 @@ import land.face.strife.data.StrifeMob; import land.face.strife.data.champion.Champion; import land.face.strife.events.UniqueKillEvent; +import land.face.strife.util.SpecialStatusUtil; import land.face.strife.util.StatUtil; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -59,14 +60,16 @@ public ExperienceListener(StrifePlugin plugin) { @EventHandler(priority = EventPriority.MONITOR) public void onXpShare(EntityDeathEvent event) { - if (event.getDroppedExp() == 0 || event.getEntity().hasMetadata("SPAWNED")) { + if (event.getDroppedExp() == 0 || SpecialStatusUtil.isSpawnerMob(event.getEntity())) { return; } - StrifeMob mob = plugin.getStrifeMobManager().getMobUnsafe(event.getEntity().getUniqueId()); - if (mob == null) { + + if (!plugin.getStrifeMobManager().isTrackedEntity(event.getEntity())) { return; } + StrifeMob mob = plugin.getStrifeMobManager().getStatMob(event.getEntity()); + Player killer = mob.getKiller(); if (killer == null) { killer = event.getEntity().getKiller(); diff --git a/src/main/java/land/face/strife/listeners/FallListener.java b/src/main/java/land/face/strife/listeners/FallListener.java index 35305d10..9c4c6f1d 100644 --- a/src/main/java/land/face/strife/listeners/FallListener.java +++ b/src/main/java/land/face/strife/listeners/FallListener.java @@ -11,6 +11,7 @@ import land.face.strife.data.champion.LifeSkillType; import land.face.strife.util.DamageUtil; import land.face.strife.util.MoveUtil; +import land.face.strife.util.SpecialStatusUtil; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -35,7 +36,7 @@ public void onFallDamage(EntityDamageEvent event) { if (event.getCause() != DamageCause.FALL || event.isCancelled()) { return; } - if (event.getEntity().hasMetadata("NO_FALL")) { + if (SpecialStatusUtil.isFallImmune(event.getEntity())) { event.setCancelled(true); return; } diff --git a/src/main/java/land/face/strife/listeners/MinionListener.java b/src/main/java/land/face/strife/listeners/MinionListener.java index bf061153..b84d5e54 100644 --- a/src/main/java/land/face/strife/listeners/MinionListener.java +++ b/src/main/java/land/face/strife/listeners/MinionListener.java @@ -65,7 +65,7 @@ public void onMasterTargetMinion(final EntityTargetEvent event) { if (!(event.getEntity() instanceof Mob) || !(event.getTarget() instanceof LivingEntity)) { return; } - if (!entityManager.isTrackedEntity(event.getEntity())) { + if (!entityManager.isTrackedEntity((LivingEntity) event.getEntity())) { return; } StrifeMob attrEnt = entityManager.getStatMob((LivingEntity) event.getEntity()); @@ -89,8 +89,7 @@ public void onEntityDamageMaster(final EntityDamageByEntityEvent event) { if (!(attacker instanceof LivingEntity)) { return; } - if (!(entityManager.isTrackedEntity(event.getEntity()) && entityManager - .isTrackedEntity(attacker))) { + if (!entityManager.isTrackedEntity((LivingEntity) attacker)) { return; } StrifeMob attackMob = entityManager.getStatMob((LivingEntity) attacker); diff --git a/src/main/java/land/face/strife/listeners/ShootListener.java b/src/main/java/land/face/strife/listeners/ShootListener.java index 2e45ae57..16eb306b 100644 --- a/src/main/java/land/face/strife/listeners/ShootListener.java +++ b/src/main/java/land/face/strife/listeners/ShootListener.java @@ -18,6 +18,7 @@ */ package land.face.strife.listeners; +import com.tealcube.minecraft.bukkit.shade.apache.commons.lang3.StringUtils; import java.util.Objects; import land.face.strife.StrifePlugin; import land.face.strife.data.StrifeMob; @@ -181,19 +182,19 @@ public void onGroundEffectProjectileHit(final ProjectileHitEvent event) { if (event.getHitBlock() == null) { return; } - if (!event.getEntity().hasMetadata("GROUND_TRIGGER")) { + if (!ProjectileUtil.isGroundTrigger(event.getEntity())) { return; } StrifeMob caster = plugin.getStrifeMobManager() .getStatMob((LivingEntity) Objects.requireNonNull(event.getEntity().getShooter())); - String[] effects = event.getEntity().getMetadata("EFFECT_PROJECTILE").get(0).asString() - .split("~"); - if (effects.length == 0) { + String effectString = ProjectileUtil.getHitEffects(event.getEntity()); + if (StringUtils.isBlank(effectString)) { LogUtil.printWarning( "A handled GroundProjectile was missing effect meta... something's wrong"); return; } + String[] effects = effectString.split("~"); Location loc = event.getEntity().getLocation().clone() .add(event.getEntity().getLocation().getDirection().multiply(-0.25)); for (String s : effects) { diff --git a/src/main/java/land/face/strife/listeners/SpawnListener.java b/src/main/java/land/face/strife/listeners/SpawnListener.java index 3e0704eb..26e42b81 100644 --- a/src/main/java/land/face/strife/listeners/SpawnListener.java +++ b/src/main/java/land/face/strife/listeners/SpawnListener.java @@ -12,6 +12,8 @@ import land.face.strife.managers.MobModManager; import land.face.strife.stats.StrifeStat; import land.face.strife.util.LogUtil; +import land.face.strife.util.SpecialStatusUtil; +import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.WordUtils; import org.bukkit.Material; import org.bukkit.entity.EntityType; @@ -24,7 +26,6 @@ import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.inventory.EntityEquipment; import org.bukkit.inventory.ItemStack; -import org.bukkit.metadata.FixedMetadataValue; public class SpawnListener implements Listener { @@ -79,11 +80,13 @@ public SpawnListener(StrifePlugin plugin) { @EventHandler(priority = EventPriority.HIGHEST) public void onCreatureSpawnHighest(CreatureSpawnEvent event) { - if (event.isCancelled() || event.getEntity().hasMetadata("UNIQUE_ID") || - event.getEntity().hasMetadata("NPC") + if (event.isCancelled() || event.getEntity().hasMetadata("NPC") || event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.BREEDING) { return; } + if (StringUtils.isNotBlank(SpecialStatusUtil.getUniqueId(event.getEntity()))) { + return; + } LivingEntity entity = event.getEntity(); if (!plugin.getMonsterManager().containsEntityType(event.getEntityType())) { @@ -129,7 +132,7 @@ public void onCreatureSpawnHighest(CreatureSpawnEvent event) { .replace("%LEVEL%", "" + level); entity.setCustomName(name + levelSuffix); - entity.setMetadata("LVL", new FixedMetadataValue(plugin, level)); + SpecialStatusUtil.setMobLevel(entity, level); entity.setCanPickupItems(false); entity.getEquipment().clear(); equipEntity(entity); diff --git a/src/main/java/land/face/strife/listeners/StatUpdateListener.java b/src/main/java/land/face/strife/listeners/StatUpdateListener.java index 0d159367..47a9ff51 100644 --- a/src/main/java/land/face/strife/listeners/StatUpdateListener.java +++ b/src/main/java/land/face/strife/listeners/StatUpdateListener.java @@ -48,7 +48,7 @@ public void onPlayerRespawn(final PlayerRespawnEvent event) { plugin.getChampionManager().updateAll( plugin.getChampionManager().getChampion(event.getPlayer())); plugin.getStatUpdateManager().updateAttributes(event.getPlayer()); - }, 20L); + }, 3L); } @EventHandler(priority = EventPriority.MONITOR) @@ -77,7 +77,7 @@ public void onInventoryClose(InventoryCloseEvent event) { return; } plugin.getChampionManager().updateEquipmentStats( - plugin.getChampionManager().getChampion((Player)event.getPlayer())); + plugin.getChampionManager().getChampion((Player) event.getPlayer())); plugin.getStatUpdateManager().updateAttributes(player); } @@ -90,11 +90,13 @@ public void onPlayerJoin(PlayerJoinEvent event) { @EventHandler(priority = EventPriority.HIGHEST) public void onPlayerQuit(PlayerQuitEvent event) { - plugin.getStrifeMobManager().removeMob(event.getPlayer()); + Bukkit.getScheduler().runTaskLater(plugin, + () -> plugin.getStrifeMobManager().removeEntity(event.getPlayer()), 1L); } @EventHandler(priority = EventPriority.HIGHEST) public void onPlayerKick(PlayerKickEvent event) { - plugin.getStrifeMobManager().removeMob(event.getPlayer()); + Bukkit.getScheduler().runTaskLater(plugin, + () -> plugin.getStrifeMobManager().removeEntity(event.getPlayer()), 1L); } } diff --git a/src/main/java/land/face/strife/listeners/TargetingListener.java b/src/main/java/land/face/strife/listeners/TargetingListener.java index 111c9477..7fa7cb29 100644 --- a/src/main/java/land/face/strife/listeners/TargetingListener.java +++ b/src/main/java/land/face/strife/listeners/TargetingListener.java @@ -28,6 +28,7 @@ import land.face.strife.data.champion.LifeSkillType; import land.face.strife.util.DamageUtil; import land.face.strife.util.LogUtil; +import land.face.strife.util.SpecialStatusUtil; import land.face.strife.util.StatUtil; import land.face.strife.util.TargetingUtil; import org.bukkit.Location; @@ -38,7 +39,6 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityTargetEvent.TargetReason; import org.bukkit.event.entity.EntityTargetLivingEntityEvent; import org.bukkit.util.Vector; @@ -97,12 +97,8 @@ public void onIgnoreHighLevelPlayers(EntityTargetLivingEntityEvent event) { if (event.isCancelled()) { return; } - if (event.getReason() == TargetReason.FOLLOW_LEADER && event - .getEntity().hasMetadata("WEAK_AGGRO")) { - event.setCancelled(true); - return; - } - if (!(event.getTarget() instanceof Player) || !(event.getEntity() instanceof Mob) || event.getReason() != CLOSEST_PLAYER) { + if (!(event.getTarget() instanceof Player) || !(event.getEntity() instanceof Mob) + || event.getReason() != CLOSEST_PLAYER) { return; } if (plugin.getStealthManager().isStealthed(event.getTarget())) { @@ -119,8 +115,8 @@ public void onIgnoreHighLevelPlayers(EntityTargetLivingEntityEvent event) { @EventHandler(priority = EventPriority.HIGHEST) public void onNormalTarget(EntityTargetLivingEntityEvent event) { if (event.isCancelled() || !(event.getTarget() instanceof Player) || !(event - .getEntity() instanceof Mob) || event.getReason() != CLOSEST_PLAYER || event - .getEntity().hasMetadata("IGNORE_SNEAK")) { + .getEntity() instanceof Mob) || event.getReason() != CLOSEST_PLAYER || SpecialStatusUtil + .isSneakImmune(event.getEntity())) { return; } Player player = (Player) event.getTarget(); diff --git a/src/main/java/land/face/strife/listeners/UniqueSplashListener.java b/src/main/java/land/face/strife/listeners/UniqueSplashListener.java index bb9da5b3..cf7bf2ca 100644 --- a/src/main/java/land/face/strife/listeners/UniqueSplashListener.java +++ b/src/main/java/land/face/strife/listeners/UniqueSplashListener.java @@ -1,10 +1,12 @@ package land.face.strife.listeners; +import com.tealcube.minecraft.bukkit.shade.apache.commons.lang3.StringUtils; import land.face.strife.data.StrifeMob; import land.face.strife.managers.BlockManager; import land.face.strife.managers.EffectManager; import land.face.strife.managers.StrifeMobManager; import land.face.strife.util.DamageUtil; +import land.face.strife.util.ProjectileUtil; import land.face.strife.util.StatUtil; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; @@ -28,14 +30,14 @@ public UniqueSplashListener(StrifeMobManager strifeMobManager, BlockManager bloc @EventHandler(priority = EventPriority.HIGHEST) public void onAbilityPotionSplash(PotionSplashEvent event) { - if (!event.getEntity().hasMetadata("EFFECT_PROJECTILE")) { + String hitEffects = ProjectileUtil.getHitEffects(event.getEntity()); + if (StringUtils.isBlank(hitEffects)) { return; } if (!(event.getEntity().getShooter() instanceof LivingEntity)) { return; } - String[] effects = event.getEntity().getMetadata("EFFECT_PROJECTILE").get(0) - .asString().split("~"); + String[] effects = hitEffects.split("~"); if (effects.length == 0) { return; } diff --git a/src/main/java/land/face/strife/managers/AbilityManager.java b/src/main/java/land/face/strife/managers/AbilityManager.java index 02b563d2..dc9a3815 100644 --- a/src/main/java/land/face/strife/managers/AbilityManager.java +++ b/src/main/java/land/face/strife/managers/AbilityManager.java @@ -296,7 +296,7 @@ public void startAbilityTimerTask(StrifeMob mob) { } for (Phase phase : abilitySet.getAbilities(TriggerAbilityType.TIMER).keySet()) { if (!abilitySet.getAbilities(TriggerAbilityType.TIMER).get(phase).isEmpty()) { - mob.setAbilityTimer(new EntityAbilityTimer(mob)); + new EntityAbilityTimer(mob); return; } } diff --git a/src/main/java/land/face/strife/managers/BossBarManager.java b/src/main/java/land/face/strife/managers/BossBarManager.java index 8c6872d8..dbfb492f 100644 --- a/src/main/java/land/face/strife/managers/BossBarManager.java +++ b/src/main/java/land/face/strife/managers/BossBarManager.java @@ -109,13 +109,13 @@ public void pushBar(Player player, StrifeMob target) { removePlayerFromBar(bossBar, player.getUniqueId()); } addPlayerToBar(strifeBossBar, player); - updateBar(target); + updateBar(target.getEntity().getUniqueId(), strifeBossBar); refreshCounter(strifeBossBar, player.getUniqueId()); } public void tickHealthBars() { for (UUID uuid : barMap.keySet()) { - updateBar(barMap.get(uuid).getOwner()); + updateBar(uuid, barMap.get(uuid)); tickDownBar(barMap.get(uuid)); } } @@ -187,13 +187,13 @@ public void doBarDeath(StrifeBossBar bossBar) { bossBar.getBarrierBar().setProgress(0); } bossBar.getHealthBar().setProgress(0); - for (UUID playerUuid : bossBar.getPlayerUuidTickMap().keySet()) { - bossBar.getPlayerUuidTickMap().put(playerUuid, 25); + for (UUID playerUuid : bossBar.getViewers().keySet()) { + bossBar.getViewers().put(playerUuid, 25); } } private void pruneBarIfNoOwners(UUID uuid) { - if (barMap.get(uuid).getPlayerUuidTickMap().isEmpty()) { + if (barMap.get(uuid).getViewers().isEmpty()) { removeBar(uuid); } } @@ -202,37 +202,40 @@ private void tickDownBar(StrifeBossBar strifeBossBar) { if (strifeBossBar == null) { return; } - for (UUID barPlayer : strifeBossBar.getPlayerUuidTickMap().keySet()) { - int ticksRemaining = strifeBossBar.getPlayerUuidTickMap().get(barPlayer); + for (UUID barPlayer : strifeBossBar.getViewers().keySet()) { + int ticksRemaining = strifeBossBar.getViewers().get(barPlayer); if (ticksRemaining < 1) { removePlayerFromBar(strifeBossBar, barPlayer); continue; } - strifeBossBar.getPlayerUuidTickMap().replace(barPlayer, ticksRemaining - 1); + strifeBossBar.getViewers().replace(barPlayer, ticksRemaining - 1); } pruneBarIfNoOwners(strifeBossBar.getOwner().getEntity().getUniqueId()); } - private void updateBar(StrifeMob barOwner) { - UUID uuid = barOwner.getEntity().getUniqueId(); - StrifeBossBar strifeBossBar = barMap.get(uuid); - if (!strifeBossBar.isDead() && !strifeBossBar.getOwner().getEntity().isValid()) { + private void updateBar(UUID uuid, StrifeBossBar bossBar) { + StrifeMob barOwner = bossBar.getOwner(); + if (barOwner == null || barOwner.getEntity() == null) { + removeBar(uuid); + return; + } + if (!bossBar.isDead() && !bossBar.getOwner().getEntity().isValid()) { removeBar(barOwner.getEntity().getUniqueId()); return; } - if (strifeBossBar.isDead()) { + if (bossBar.isDead()) { return; } - updateBarrierProgress(strifeBossBar); - updateHealthProgress(strifeBossBar); - updateBarTitle(strifeBossBar, createBarTitle(barOwner)); + updateBarrierProgress(bossBar); + updateHealthProgress(bossBar); + updateBarTitle(bossBar, createBarTitle(barOwner)); } private void removePlayerFromBar(StrifeBossBar strifeBossBar, Player player) { - if (strifeBossBar == null || strifeBossBar.getPlayerUuidTickMap().isEmpty()) { + if (strifeBossBar == null || strifeBossBar.getViewers().isEmpty()) { return; } - strifeBossBar.getPlayerUuidTickMap().remove(player.getUniqueId()); + strifeBossBar.getViewers().remove(player.getUniqueId()); if (strifeBossBar.getBarrierBar() != null) { strifeBossBar.getBarrierBar().removePlayer(player); } @@ -251,7 +254,7 @@ private void refreshCounter(StrifeBossBar strifeBossBar, UUID uuid) { if (strifeBossBar.isDead()) { return; } - strifeBossBar.getPlayerUuidTickMap().put(uuid, healthDuration); + strifeBossBar.getViewers().put(uuid, healthDuration); } private void updateHealthProgress(StrifeBossBar bar) { diff --git a/src/main/java/land/face/strife/managers/CounterManager.java b/src/main/java/land/face/strife/managers/CounterManager.java index 01fac0dc..8dac8580 100644 --- a/src/main/java/land/face/strife/managers/CounterManager.java +++ b/src/main/java/land/face/strife/managers/CounterManager.java @@ -21,12 +21,11 @@ import static land.face.strife.util.DamageUtil.buildMissIndicator; import com.tealcube.minecraft.bukkit.facecore.utilities.MessageUtils; -import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Set; -import java.util.UUID; +import java.util.WeakHashMap; import land.face.strife.StrifePlugin; import land.face.strife.data.CounterData; import land.face.strife.data.StrifeMob; @@ -36,7 +35,7 @@ public class CounterManager { - private final Map> counterMap = new HashMap<>(); + private final Map> counterMap = new WeakHashMap<>(); private StrifePlugin plugin; private Sound counterSound; private float pitch; @@ -48,27 +47,27 @@ public CounterManager(StrifePlugin plugin) { pitch = (float) plugin.getSettings().getDouble("config.mechanics.counter.pitch", 1); } - public void clearCounters(UUID uuid) { - counterMap.remove(uuid); + public void clearCounters(LivingEntity livingEntity) { + counterMap.remove(livingEntity); } - public void addCounter(UUID uuid, CounterData counterData) { - if (!counterMap.containsKey(uuid)) { - counterMap.put(uuid, new HashSet<>()); + public void addCounter(LivingEntity livingEntity, CounterData counterData) { + if (!counterMap.containsKey(livingEntity)) { + counterMap.put(livingEntity, new HashSet<>()); } - counterMap.get(uuid).add(counterData); + counterMap.get(livingEntity).add(counterData); } public boolean executeCounters(LivingEntity attacker, LivingEntity defender) { - if (!counterMap.containsKey(defender.getUniqueId())) { + if (!counterMap.containsKey(defender)) { return false; } boolean isCountered = false; - Iterator it = counterMap.get(defender.getUniqueId()).iterator(); + Iterator it = counterMap.get(defender).iterator(); while (it.hasNext()) { CounterData data = it.next(); if (System.currentTimeMillis() > data.getEndTime()) { - counterMap.get(defender.getUniqueId()).remove(data); + counterMap.get(defender).remove(data); continue; } isCountered = true; @@ -84,7 +83,7 @@ public boolean executeCounters(LivingEntity attacker, LivingEntity defender) { StrifeMob defenderMob = plugin.getStrifeMobManager().getStatMob(defender); plugin.getEffectManager().execute(defenderMob, attacker, data.getEffects()); if (data.isRemoveOnTrigger()) { - counterMap.get(defender.getUniqueId()).remove(data); + counterMap.get(defender).remove(data); } else { data.setTriggered(true); } diff --git a/src/main/java/land/face/strife/managers/EntityEquipmentManager.java b/src/main/java/land/face/strife/managers/EntityEquipmentManager.java index cab2520e..a5ff74c3 100644 --- a/src/main/java/land/face/strife/managers/EntityEquipmentManager.java +++ b/src/main/java/land/face/strife/managers/EntityEquipmentManager.java @@ -84,10 +84,11 @@ public void loadEquipmentItem(String key, ConfigurationSection cs) { } if (stack.getItemMeta() instanceof LeatherArmorMeta) { - int rgb = cs.getInt("dye-rgb", -1); + int rgb = cs.getInt("dye-red", -1); if (rgb != -1) { LeatherArmorMeta meta = ((LeatherArmorMeta) stack.getItemMeta()); - meta.setColor(Color.fromRGB(rgb)); + meta.setColor(Color + .fromRGB(cs.getInt("dye-red", 0), cs.getInt("dye-green", 0), cs.getInt("dye-blue", 0))); stack.setItemMeta(meta); } } diff --git a/src/main/java/land/face/strife/managers/IndicatorManager.java b/src/main/java/land/face/strife/managers/IndicatorManager.java index 88c86afe..bb9c27b7 100644 --- a/src/main/java/land/face/strife/managers/IndicatorManager.java +++ b/src/main/java/land/face/strife/managers/IndicatorManager.java @@ -9,17 +9,14 @@ import land.face.strife.util.TargetingUtil; import net.minecraft.server.v1_15_R1.ChatComponentText; import net.minecraft.server.v1_15_R1.EntityArmorStand; -import net.minecraft.server.v1_15_R1.ItemStack; import net.minecraft.server.v1_15_R1.PacketPlayOutEntity.PacketPlayOutRelEntityMove; import net.minecraft.server.v1_15_R1.PacketPlayOutEntityDestroy; import net.minecraft.server.v1_15_R1.PacketPlayOutEntityMetadata; import net.minecraft.server.v1_15_R1.PacketPlayOutSpawnEntityLiving; import net.minecraft.server.v1_15_R1.WorldServer; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.util.Vector; @@ -29,8 +26,6 @@ public class IndicatorManager { private Map indicators = new ConcurrentHashMap<>(); public static float GRAVITY_FALL_SPEED; private static final int MAX_STAGE = 10; - private static final ItemStack indicatorItem = CraftItemStack - .asNMSCopy(new org.bukkit.inventory.ItemStack(Material.APPLE)); public IndicatorManager() { GRAVITY_FALL_SPEED = (float) StrifePlugin.getInstance().getSettings() diff --git a/src/main/java/land/face/strife/managers/SpawnerManager.java b/src/main/java/land/face/strife/managers/SpawnerManager.java index 64dd53e2..7525f2a6 100644 --- a/src/main/java/land/face/strife/managers/SpawnerManager.java +++ b/src/main/java/land/face/strife/managers/SpawnerManager.java @@ -56,12 +56,6 @@ public void spawnSpawners() { } } - for (LivingEntity livingEntity : s.getEntities()) { - if (livingEntity == null || !livingEntity.isValid()) { - s.getEntities().remove(livingEntity); - } - } - int existingMobs = s.getRespawnTimes().size() + s.getEntities().size(); if (existingMobs >= maxMobs) { continue; diff --git a/src/main/java/land/face/strife/managers/StealthManager.java b/src/main/java/land/face/strife/managers/StealthManager.java index 661140c9..6a1bc9a6 100644 --- a/src/main/java/land/face/strife/managers/StealthManager.java +++ b/src/main/java/land/face/strife/managers/StealthManager.java @@ -26,9 +26,7 @@ import land.face.strife.util.DamageUtil; import land.face.strife.util.MoveUtil; import land.face.strife.util.PlayerDataUtil; -import land.face.strife.util.ProjectileUtil; import land.face.strife.util.StatUtil; -import land.face.strife.util.TargetingUtil; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Particle; @@ -36,8 +34,6 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Mob; import org.bukkit.entity.Player; -import org.bukkit.entity.Projectile; -import org.bukkit.util.Vector; public class StealthManager { @@ -68,21 +64,7 @@ public StealthManager(StrifePlugin plugin) { this.plugin = plugin; } - public boolean isSneakAttack(LivingEntity attacker, LivingEntity target) { - if (!(attacker instanceof Player) || !((Player) attacker).isSneaking()) { - return false; - } - target = TargetingUtil.getMobTarget(target); - return target == null || !target.isValid(); - } - - public boolean isSneakAttack(Projectile projectile, LivingEntity target) { - if (!projectile.hasMetadata(ProjectileUtil.SNEAK_ATTACK_META)) { - return false; - } - return isSneakAngle(target, projectile.getLocation().getDirection()); - } - + /* public boolean isSneakAngle(LivingEntity target, Vector direction) { if (TargetingUtil.getMobTarget(target) != null) { return false; @@ -91,6 +73,7 @@ public boolean isSneakAngle(LivingEntity target, Vector direction) { float angle = entitySightVector.angle(direction); return angle > 0.6; } + */ public float getSneakActionExp(float enemyLevel, float stealthLevel) { if (stealthLevel != 99 && enemyLevel - stealthLevel > 20) { diff --git a/src/main/java/land/face/strife/managers/StrifeMobManager.java b/src/main/java/land/face/strife/managers/StrifeMobManager.java index 499159c7..d48f1093 100644 --- a/src/main/java/land/face/strife/managers/StrifeMobManager.java +++ b/src/main/java/land/face/strife/managers/StrifeMobManager.java @@ -1,8 +1,7 @@ package land.face.strife.managers; import java.util.Map; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; +import java.util.WeakHashMap; import land.face.strife.StrifePlugin; import land.face.strife.data.LoreAbility; import land.face.strife.data.StrifeMob; @@ -10,21 +9,24 @@ import land.face.strife.data.buff.LoadedBuff; import land.face.strife.data.effects.FiniteUsesEffect; import land.face.strife.stats.StrifeStat; -import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; public class StrifeMobManager { private final StrifePlugin plugin; - private final Map trackedEntities = new ConcurrentHashMap<>(); + private final Map trackedEntities = new WeakHashMap<>(); public StrifeMobManager(StrifePlugin plugin) { this.plugin = plugin; } + public int getMobCount() { + return trackedEntities.size(); + } + public StrifeMob getStatMob(LivingEntity entity) { - if (!trackedEntities.containsKey(entity.getUniqueId())) { + if (!trackedEntities.containsKey(entity)) { StrifeMob strifeMob; if (entity instanceof Player) { strifeMob = new StrifeMob(plugin.getChampionManager().getChampion((Player) entity)); @@ -32,10 +34,9 @@ public StrifeMob getStatMob(LivingEntity entity) { strifeMob = new StrifeMob(entity); } strifeMob.setStats(plugin.getMonsterManager().getBaseStats(entity)); - trackedEntities.put(entity.getUniqueId(), strifeMob); + trackedEntities.put(entity, strifeMob); } - StrifeMob strifeMob = trackedEntities.get(entity.getUniqueId()); - strifeMob.setLivingEntity(entity); + StrifeMob strifeMob = trackedEntities.get(entity); plugin.getBarrierManager().createBarrierEntry(strifeMob); return strifeMob; } @@ -58,77 +59,45 @@ public void addFiniteEffect(StrifeMob mob, LoreAbility loreAbility, int uses, in mob.getTempEffects().add(finiteUsesEffect); } - public void addBuff(UUID uuid, String buffId, double durationMultiplier) { - addBuff(uuid, plugin.getBuffManager().getBuffFromId(buffId), durationMultiplier); + public void addBuff(LivingEntity entity, String buffId, double durationMultiplier) { + addBuff(entity, plugin.getBuffManager().getBuffFromId(buffId), durationMultiplier); } - public void addBuff(UUID uuid, LoadedBuff loadedBuff, double durationMultiplier) { - StrifeMob strifeMob = trackedEntities.get(uuid); + public void addBuff(LivingEntity entity, LoadedBuff loadedBuff, double durationMultiplier) { + StrifeMob strifeMob = trackedEntities.get(entity); Buff buff = plugin.getBuffManager().buildFromLoadedBuff(loadedBuff); strifeMob.addBuff(loadedBuff.getId(), buff, loadedBuff.getSeconds() * durationMultiplier); } - public int removeInvalidEntities() { - int initialSize = trackedEntities.size(); - for (UUID uuid : trackedEntities.keySet()) { - LivingEntity le = trackedEntities.get(uuid).getEntity(); - if (le != null && le.isValid()) { - continue; - } - remove(uuid); - plugin.getCounterManager().clearCounters(uuid); - } - return initialSize - trackedEntities.size(); - } - public StrifeMob setEntityStats(LivingEntity entity, Map statMap) { StrifeMob strifeMob = getStatMob(entity); strifeMob.setStats(statMap); - trackedEntities.put(entity.getUniqueId(), strifeMob); + trackedEntities.put(entity, strifeMob); return strifeMob; } public void despawnAllTempEntities() { for (StrifeMob strifeMob : trackedEntities.values()) { if (strifeMob.getEntity().isValid() && strifeMob.isDespawnOnUnload()) { - remove(strifeMob.getEntity().getUniqueId()); + strifeMob.getEntity().remove(); } } } + public void removeEntity(LivingEntity entity) { + trackedEntities.remove(entity); + } + public void doChunkDespawn(LivingEntity entity) { if (!isTrackedEntity(entity)) { return; } - if (trackedEntities.get(entity.getUniqueId()).isDespawnOnUnload()) { - remove(entity.getUniqueId()); - } - } - - public StrifeMob getMobUnsafe(UUID uuid) { - return trackedEntities.getOrDefault(uuid, null); - } - - public void removeMob(LivingEntity entity) { - remove(entity.getUniqueId()); - } - - public void removeMob(UUID uuid) { - remove(uuid); - } - - public void remove(UUID uuid) { - StrifeMob mob = trackedEntities.get(uuid); - if (mob != null) { - if (mob.getEntity().isValid() && !(mob.getEntity() instanceof Player)) { - mob.getEntity().remove(); - } - mob.killAllTasks(); - trackedEntities.remove(uuid); + if (trackedEntities.get(entity).isDespawnOnUnload()) { + entity.remove(); } } - public boolean isTrackedEntity(Entity entity) { - return trackedEntities.containsKey(entity.getUniqueId()); + public boolean isTrackedEntity(LivingEntity entity) { + return trackedEntities.containsKey(entity); } } diff --git a/src/main/java/land/face/strife/managers/UniqueEntityManager.java b/src/main/java/land/face/strife/managers/UniqueEntityManager.java index c8f47538..ab48c2a4 100644 --- a/src/main/java/land/face/strife/managers/UniqueEntityManager.java +++ b/src/main/java/land/face/strife/managers/UniqueEntityManager.java @@ -14,6 +14,7 @@ import land.face.strife.stats.StrifeStat; import land.face.strife.util.ItemUtil; import land.face.strife.util.LogUtil; +import land.face.strife.util.SpecialStatusUtil; import land.face.strife.util.StatUtil; import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.disguisetypes.Disguise; @@ -29,7 +30,6 @@ import org.bukkit.entity.Rabbit; import org.bukkit.entity.Slime; import org.bukkit.entity.Zombie; -import org.bukkit.metadata.FixedMetadataValue; public class UniqueEntityManager { @@ -78,7 +78,7 @@ StrifeMob spawnUnique(UniqueEntity uniqueEntity, Location location) { assert uniqueEntity.getType().getEntityClass() != null; Entity entity = Objects.requireNonNull(location.getWorld()) .spawn(location, uniqueEntity.getType().getEntityClass(), - e -> e.setMetadata("UNIQUE_ID", new FixedMetadataValue(plugin, uniqueEntity.getId()))); + e -> SpecialStatusUtil.setUniqueId(e, uniqueEntity.getId())); if (!entity.isValid()) { LogUtil.printWarning( @@ -166,16 +166,13 @@ StrifeMob spawnUnique(UniqueEntity uniqueEntity, Location location) { strifeMob.setDespawnOnUnload(true); strifeMob.setCharmImmune(uniqueEntity.isCharmImmune()); if (uniqueEntity.isBurnImmune()) { - le.setMetadata("NO_BURN", new FixedMetadataValue(plugin, true)); + SpecialStatusUtil.setBurnImmune(le); } if (uniqueEntity.isFallImmune()) { - le.setMetadata("NO_FALL", new FixedMetadataValue(plugin, true)); + SpecialStatusUtil.setFallImmune(le); } if (uniqueEntity.isIgnoreSneak()) { - le.setMetadata("IGNORE_SNEAK", new FixedMetadataValue(plugin, true)); - } - if (uniqueEntity.isRemoveFollowMods()) { - le.setMetadata("WEAK_AGGRO", new FixedMetadataValue(plugin, true)); + SpecialStatusUtil.setSneakImmune(le); } if (StringUtils.isNotBlank(uniqueEntity.getMount())) { StrifeMob mountMob = spawnUnique(uniqueEntity.getMount(), location); diff --git a/src/main/java/land/face/strife/tasks/TrackedPruneTask.java b/src/main/java/land/face/strife/tasks/StrifeMobTracker.java similarity index 84% rename from src/main/java/land/face/strife/tasks/TrackedPruneTask.java rename to src/main/java/land/face/strife/tasks/StrifeMobTracker.java index 411ac8e0..bb9313dd 100644 --- a/src/main/java/land/face/strife/tasks/TrackedPruneTask.java +++ b/src/main/java/land/face/strife/tasks/StrifeMobTracker.java @@ -22,17 +22,16 @@ import land.face.strife.util.LogUtil; import org.bukkit.scheduler.BukkitRunnable; -public class TrackedPruneTask extends BukkitRunnable { +public class StrifeMobTracker extends BukkitRunnable { private final StrifePlugin plugin; - public TrackedPruneTask(StrifePlugin plugin) { + public StrifeMobTracker(StrifePlugin plugin) { this.plugin = plugin; } @Override public void run() { - int removed = plugin.getStrifeMobManager().removeInvalidEntities(); - LogUtil.printDebug("Cleared " + removed + " invalid attributed entities."); + LogUtil.printInfo("Current StrifeMobs: " + plugin.getStrifeMobManager().getMobCount()); } } diff --git a/src/main/java/land/face/strife/timers/FallingBlockTimer.java b/src/main/java/land/face/strife/timers/FallingBlockTimer.java index 7bbb3bff..a51442bd 100644 --- a/src/main/java/land/face/strife/timers/FallingBlockTimer.java +++ b/src/main/java/land/face/strife/timers/FallingBlockTimer.java @@ -5,6 +5,7 @@ import land.face.strife.data.effects.Effect; import land.face.strife.data.effects.LocationEffect; import land.face.strife.util.LogUtil; +import land.face.strife.util.SpecialStatusUtil; import org.bukkit.Particle; import org.bukkit.entity.FallingBlock; import org.bukkit.scheduler.BukkitRunnable; @@ -40,7 +41,7 @@ public void run() { block.getWorld().spawnParticle(Particle.BLOCK_DUST, block.getLocation(), 20, 0.7, 0.7, 0.7, block.getBlockData()); block.setDropItem(false); - String[] effects = block.getMetadata("EFFECT_PROJECTILE").get(0).asString().split("~"); + String[] effects = SpecialStatusUtil.getHandledBlockEffects(block).split("~"); if (effects.length == 0) { LogUtil.printWarning("A handled FallingBlock was missing effect meta... something's wrong"); cancel(); diff --git a/src/main/java/land/face/strife/util/DamageUtil.java b/src/main/java/land/face/strife/util/DamageUtil.java index 7cabd8f0..46f0fa1d 100644 --- a/src/main/java/land/face/strife/util/DamageUtil.java +++ b/src/main/java/land/face/strife/util/DamageUtil.java @@ -56,7 +56,6 @@ import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDamageEvent.DamageModifier; -import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.util.Vector; @@ -237,17 +236,18 @@ public static float damage(StrifeMob attacker, StrifeMob defender, rawDamage *= DamageUtil.getMinionMult(attacker); rawDamage += damageMap.getOrDefault(DamageType.TRUE_DAMAGE, 0f); - float postBarrierDamage = plugin.getBarrierManager().damageBarrier(defender, rawDamage); - - if (mods.isSneakAttack() && !defender.getEntity().hasMetadata("IGNORE_SNEAK")) { + if (mods.isSneakAttack() && !SpecialStatusUtil.isSneakImmune(defender.getEntity())) { rawDamage += doSneakAttack(attacker, defender, mods, pvpMult); - boolean finishingBlow = postBarrierDamage > defender.getEntity().getHealth(); + boolean finishingBlow = rawDamage > defender.getEntity().getHealth() + + plugin.getBarrierManager().getCurrentBarrier(defender); float gainedXp = plugin.getStealthManager().getSneakAttackExp(defender.getEntity(), attacker.getChampion().getLifeSkillLevel(LifeSkillType.SNEAK), finishingBlow); plugin.getSkillExperienceManager().addExperience((Player) attacker.getEntity(), LifeSkillType.SNEAK, gainedXp, false); } + float postBarrierDamage = plugin.getBarrierManager().damageBarrier(defender, rawDamage); + String damageString = String.valueOf((int) Math.ceil(rawDamage)); if (overcharge) { damageString = "&l" + damageString; @@ -312,7 +312,9 @@ private static float doSneakAttack(StrifeMob attacker, StrifeMob defender, Damag .callSneakAttackEvent(attacker, defender, sneakSkill, sneakDamage); if (!sneakEvent.isCancelled()) { - defender.getEntity().setMetadata("IGNORE_SNEAK", new FixedMetadataValue(plugin, true)); + if (!(defender.getEntity() instanceof Player)) { + SpecialStatusUtil.setSneakImmune(defender.getEntity()); + } StrifePlugin.getInstance().getIndicatorManager().addIndicator(attacker.getEntity(), defender.getEntity(), buildFloatIndicator((Player) attacker.getEntity()), "&7Sneak Attack!"); @@ -840,7 +842,7 @@ public static void applyBuff(LoadedBuff buff, StrifeMob target) { public static void applyBuff(LoadedBuff loadedBuff, StrifeMob target, double durationMult) { StrifePlugin.getInstance().getStrifeMobManager() - .addBuff(target.getEntity().getUniqueId(), loadedBuff, durationMult); + .addBuff(target.getEntity(), loadedBuff, durationMult); } public static LoadedBuff getBuff(String id) { diff --git a/src/main/java/land/face/strife/util/FireworkUtil.java b/src/main/java/land/face/strife/util/FireworkUtil.java index 9044a5a3..0165bbb9 100644 --- a/src/main/java/land/face/strife/util/FireworkUtil.java +++ b/src/main/java/land/face/strife/util/FireworkUtil.java @@ -1,6 +1,5 @@ package land.face.strife.util; -import land.face.strife.StrifePlugin; import org.bukkit.Color; import org.bukkit.FireworkEffect; import org.bukkit.FireworkEffect.Type; @@ -9,7 +8,6 @@ import org.bukkit.entity.Firework; import org.bukkit.entity.Player; import org.bukkit.inventory.meta.FireworkMeta; -import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.util.Vector; public class FireworkUtil { @@ -29,7 +27,7 @@ public static void spawnFirework(Location loc, Type type, Color color, Color fad .trail(trail).build()); fw.setFireworkMeta(fwm); - fw.setMetadata(FW_NO_DMG, new FixedMetadataValue(StrifePlugin.getInstance(), true)); + SpecialStatusUtil.setNoDamage(fw); fw.setSilent(true); fw.detonate(); } diff --git a/src/main/java/land/face/strife/util/PlayerDataUtil.java b/src/main/java/land/face/strife/util/PlayerDataUtil.java index 5b1460a5..06d2b5ea 100644 --- a/src/main/java/land/face/strife/util/PlayerDataUtil.java +++ b/src/main/java/land/face/strife/util/PlayerDataUtil.java @@ -177,13 +177,11 @@ public static Disguise parseDisguise(ConfigurationSection section, String name, LogUtil.printWarning("Cannot load type " + typeData + " for " + name); } } - mobDisguise.setShowName(true); mobDisguise.setReplaceSounds(true); return mobDisguise; } if (type.isMisc()) { MiscDisguise miscDisguise = new MiscDisguise(type); - miscDisguise.setShowName(true); miscDisguise.setReplaceSounds(true); FlagWatcher watcher = miscDisguise.getWatcher(); try { diff --git a/src/main/java/land/face/strife/util/ProjectileUtil.java b/src/main/java/land/face/strife/util/ProjectileUtil.java index 8e326231..6382b9f0 100644 --- a/src/main/java/land/face/strife/util/ProjectileUtil.java +++ b/src/main/java/land/face/strife/util/ProjectileUtil.java @@ -1,7 +1,8 @@ package land.face.strife.util; +import java.util.Map; import java.util.Random; -import land.face.strife.StrifePlugin; +import java.util.WeakHashMap; import land.face.strife.data.StrifeMob; import land.face.strife.stats.StrifeStat; import org.bukkit.Sound; @@ -13,18 +14,51 @@ import org.bukkit.entity.Projectile; import org.bukkit.entity.ShulkerBullet; import org.bukkit.entity.Trident; -import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.util.Vector; public class ProjectileUtil { - public final static String ATTACK_SPEED_META = "AS_MULT"; - public final static String SNEAK_ATTACK_META = "SNEAK_SHOT"; - public final static String SHOT_ID_META = "SHOT_ID"; private static int shotId = 1; + private static final Map GROUND_TRIGGER = new WeakHashMap<>(); + private static final Map ATTACK_MULT = new WeakHashMap<>(); + private static final Map HIT_EFFECTS = new WeakHashMap<>(); + private static final Map SHOT_ID = new WeakHashMap<>(); + private static final Random RANDOM = new Random(System.currentTimeMillis()); + public static void setGroundTrigger(Projectile projectile) { + GROUND_TRIGGER.put(projectile, true); + } + + public static boolean isGroundTrigger(Projectile projectile) { + return GROUND_TRIGGER.containsKey(projectile); + } + + public static void setAttackMult(Projectile projectile, float mult) { + ATTACK_MULT.put(projectile, mult); + } + + public static float getAttackMult(Projectile projectile) { + return ATTACK_MULT.getOrDefault(projectile, 1f); + } + + public static void setShotId(Projectile projectile) { + SHOT_ID.put(projectile, shotId); + } + + public static int getShotId(Projectile projectile) { + return SHOT_ID.getOrDefault(projectile, 0); + } + + public static void setHitEffects(Projectile projectile, String effectString) { + HIT_EFFECTS.put(projectile, effectString); + } + + public static String getHitEffects(Projectile projectile) { + return HIT_EFFECTS.get(projectile); + } + public static int getTotalProjectiles(double initialProjectiles, double multiShot) { double projectiles = initialProjectiles; if (multiShot > 0) { @@ -77,16 +111,13 @@ public static void createArrow(LivingEntity shooter, double attackMult, float po arrow.setShooter(shooter); arrow.setPickupStatus(PickupStatus.CREATIVE_ONLY); - setProjctileAttackSpeedMeta(arrow, attackMult); - setProjectileShotIdMeta(arrow); + setAttackMult(arrow, (float) attackMult); + setShotId(arrow); if (shooter instanceof Player) { if (attackMult > 0.95) { arrow.setCritical(true); } - if (((Player) shooter).isSneaking()) { - ProjectileUtil.setProjectileSneakMeta(arrow); - } } } @@ -99,12 +130,8 @@ public static void createMagicMissile(LivingEntity shooter, double attackMult, f bullet.setShooter(shooter); bullet.setGravity(gravity); - setProjctileAttackSpeedMeta(bullet, attackMult); - setProjectileShotIdMeta(bullet); - - if (shooter instanceof Player && ((Player) shooter).isSneaking()) { - setProjectileSneakMeta(bullet); - } + setAttackMult(bullet, (float) attackMult); + setShotId(bullet); } public static Vector getProjectileVelocity(LivingEntity shooter, float speed, double spread, @@ -136,24 +163,7 @@ public static void createTrident(Player shooter, Trident trident, float attackMu .spawn(trident.getLocation(), Trident.class, e -> e.setVelocity(vector)); newTrident.setShooter(shooter); newTrident.setPickupStatus(PickupStatus.CREATIVE_ONLY); - ProjectileUtil.setProjctileAttackSpeedMeta(trident, attackMult); - if (shooter.isSneaking()) { - ProjectileUtil.setProjectileSneakMeta(trident); - } - } - - public static void setProjctileAttackSpeedMeta(Projectile proj, double attackMult) { - proj.setMetadata(ATTACK_SPEED_META, - new FixedMetadataValue(StrifePlugin.getInstance(), attackMult)); - } - - public static void setProjectileSneakMeta(Projectile projectile) { - projectile.setMetadata(SNEAK_ATTACK_META, - new FixedMetadataValue(StrifePlugin.getInstance(), true)); - } - - public static void setProjectileShotIdMeta(Projectile proj) { - proj.setMetadata(SHOT_ID_META, new FixedMetadataValue(StrifePlugin.getInstance(), shotId)); + setAttackMult(trident, attackMult); } public static boolean isProjectile(EntityType entityType) { diff --git a/src/main/java/land/face/strife/util/SpecialStatusUtil.java b/src/main/java/land/face/strife/util/SpecialStatusUtil.java new file mode 100644 index 00000000..f1bf36f7 --- /dev/null +++ b/src/main/java/land/face/strife/util/SpecialStatusUtil.java @@ -0,0 +1,100 @@ +package land.face.strife.util; + +import com.tealcube.minecraft.bukkit.shade.apache.commons.lang3.StringUtils; +import java.util.Map; +import java.util.WeakHashMap; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Entity; +import org.bukkit.entity.FallingBlock; +import org.bukkit.entity.Firework; + +public class SpecialStatusUtil { + + private static final Map BURN_IMMUNE = new WeakHashMap<>(); + private static final Map FALL_IMMUNE = new WeakHashMap<>(); + private static final Map SNEAK_IMMUNE = new WeakHashMap<>(); + private static final Map SPAWNER_SPAWNED = new WeakHashMap<>(); + private static final Map STANDODAH = new WeakHashMap<>(); + + private static final Map NO_DAMAGE_FIREWORK = new WeakHashMap<>(); + private static final Map HANDLED_BLOCK = new WeakHashMap<>(); + + private static final Map MOB_LEVEL = new WeakHashMap<>(); + private static final Map UNIQUE_ID = new WeakHashMap<>(); + + public static void setDetectionStand(ArmorStand e) { + STANDODAH.put(e, true); + } + + public static boolean isDetectionStand(Entity e) { + return STANDODAH.getOrDefault(e, false); + } + + public static void setBurnImmune(Entity e) { + BURN_IMMUNE.put(e, true); + } + + public static boolean isBurnImmune(Entity e) { + return BURN_IMMUNE.getOrDefault(e, false); + } + + public static void setFallImmune(Entity e) { + FALL_IMMUNE.put(e, true); + } + + public static boolean isFallImmune(Entity e) { + return FALL_IMMUNE.getOrDefault(e, false); + } + + public static void setSneakImmune(Entity e) { + SNEAK_IMMUNE.put(e, true); + } + + public static boolean isSneakImmune(Entity e) { + return SNEAK_IMMUNE.getOrDefault(e, false); + } + + public static void setSpawnerMob(Entity e) { + SPAWNER_SPAWNED.put(e, true); + } + + public static boolean isSpawnerMob(Entity e) { + return SPAWNER_SPAWNED.getOrDefault(e, false); + } + + public static void setMobLevel(Entity e, int level) { + MOB_LEVEL.put(e, level); + } + + public static String getUniqueId(Entity e) { + return UNIQUE_ID.getOrDefault(e, StringUtils.EMPTY); + } + + public static void setUniqueId(Entity e, String id) { + UNIQUE_ID.put(e, id); + } + + public static boolean isHandledBlock(FallingBlock e) { + return HANDLED_BLOCK.containsKey(e); + } + + public static String getHandledBlockEffects(FallingBlock e) { + return HANDLED_BLOCK.getOrDefault(e, StringUtils.EMPTY); + } + + public static void setHandledBlock(FallingBlock e, String effects) { + HANDLED_BLOCK.put(e, effects); + } + + public static int getMobLevel(Entity e) { + return MOB_LEVEL.getOrDefault(e, -1); + } + + public static void setNoDamage(Firework e) { + NO_DAMAGE_FIREWORK.put(e, true); + } + + public static boolean isNoDamage(Firework e) { + return NO_DAMAGE_FIREWORK.getOrDefault(e, false); + } +} diff --git a/src/main/java/land/face/strife/util/StatUtil.java b/src/main/java/land/face/strife/util/StatUtil.java index 4a2974ff..579fb58f 100644 --- a/src/main/java/land/face/strife/util/StatUtil.java +++ b/src/main/java/land/face/strife/util/StatUtil.java @@ -14,7 +14,6 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; -import org.bukkit.metadata.FixedMetadataValue; public class StatUtil { @@ -60,11 +59,13 @@ public static double getDamageMult(StrifeMob ae) { } public static double getMeleeDamage(StrifeMob ae) { - return ae.getStat(StrifeStat.PHYSICAL_DAMAGE) * (1 + ae.getStat(StrifeStat.MELEE_PHYSICAL_MULT) / 100); + return ae.getStat(StrifeStat.PHYSICAL_DAMAGE) * (1 + + ae.getStat(StrifeStat.MELEE_PHYSICAL_MULT) / 100); } public static double getRangedDamage(StrifeMob ae) { - return ae.getStat(StrifeStat.PHYSICAL_DAMAGE) * (1 + ae.getStat(StrifeStat.RANGED_PHYSICAL_MULT) / 100); + return ae.getStat(StrifeStat.PHYSICAL_DAMAGE) * (1 + + ae.getStat(StrifeStat.RANGED_PHYSICAL_MULT) / 100); } public static double getMagicDamage(StrifeMob ae) { @@ -239,19 +240,20 @@ public static Map getStatMapFromSection(ConfigurationSection } public static int getMobLevel(LivingEntity livingEntity) { - int level; if (livingEntity instanceof Player) { - level = ((Player) livingEntity).getLevel(); - } else if (livingEntity.hasMetadata("LVL")) { - level = livingEntity.getMetadata("LVL").get(0).asInt(); - } else if (StringUtils.isBlank(livingEntity.getCustomName())) { - level = 0; - livingEntity.setMetadata("LVL", new FixedMetadataValue(StrifePlugin.getInstance(), level)); - } else { + return ((Player) livingEntity).getLevel(); + } + int level = SpecialStatusUtil.getMobLevel(livingEntity); + if (level == -1) { + if (StringUtils.isBlank(livingEntity.getCustomName())) { + SpecialStatusUtil.setMobLevel(livingEntity, 0); + return 0; + } String lev = CharMatcher.digit().or(CharMatcher.is('-')).negate() .collapseFrom(ChatColor.stripColor(livingEntity.getCustomName()), ' ').trim(); level = NumberUtils.toInt(lev.split(" ")[0], 0); - livingEntity.setMetadata("LVL", new FixedMetadataValue(StrifePlugin.getInstance(), level)); + SpecialStatusUtil.setMobLevel(livingEntity, level); + return level; } return level; } diff --git a/src/main/java/land/face/strife/util/TargetingUtil.java b/src/main/java/land/face/strife/util/TargetingUtil.java index 3a92bbfd..44e47c1b 100644 --- a/src/main/java/land/face/strife/util/TargetingUtil.java +++ b/src/main/java/land/face/strife/util/TargetingUtil.java @@ -27,7 +27,6 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Mob; import org.bukkit.entity.Player; -import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.util.RayTraceResult; import org.bukkit.util.Vector; @@ -217,7 +216,7 @@ public static boolean isInvalidTarget(Entity e) { } public static boolean isDetectionStand(LivingEntity le) { - return le instanceof ArmorStand && le.hasMetadata("STANDO"); + return le instanceof ArmorStand && SpecialStatusUtil.isDetectionStand(le); } public static ArmorStand buildAndRemoveDetectionStand(Location location) { @@ -233,7 +232,7 @@ private static void applyDetectionStandChanges(ArmorStand stando) { stando.setMarker(true); stando.setGravity(false); stando.setCollidable(false); - stando.setMetadata("STANDO", new FixedMetadataValue(StrifePlugin.getInstance(), "")); + SpecialStatusUtil.setDetectionStand(stando); } public static LivingEntity getTempStand(Location loc, float groundCheckRange) { From 74397699789515ce0964960e9a9410bc8ab65e53 Mon Sep 17 00:00:00 2001 From: UltraFaceguy Date: Wed, 8 Apr 2020 02:53:48 -0400 Subject: [PATCH 05/13] generic ageable entities can be easily disguised --- .../land/face/strife/util/PlayerDataUtil.java | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/main/java/land/face/strife/util/PlayerDataUtil.java b/src/main/java/land/face/strife/util/PlayerDataUtil.java index 06d2b5ea..02547cdf 100644 --- a/src/main/java/land/face/strife/util/PlayerDataUtil.java +++ b/src/main/java/land/face/strife/util/PlayerDataUtil.java @@ -22,8 +22,10 @@ import me.libraryaddict.disguise.disguisetypes.MobDisguise; import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; import me.libraryaddict.disguise.disguisetypes.RabbitType; +import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.DroppedItemWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.FoxWatcher; +import me.libraryaddict.disguise.disguisetypes.watchers.MushroomCowWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.RabbitWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.SheepWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.SlimeWatcher; @@ -41,6 +43,7 @@ import org.bukkit.entity.EntityType; import org.bukkit.entity.Fox; import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.MushroomCow.Variant; import org.bukkit.entity.Player; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; @@ -144,11 +147,22 @@ public static Disguise parseDisguise(ConfigurationSection section, String name, } if (type.isMob()) { String typeData = section.getString("disguise-type-data", ""); + boolean babyData = section.getBoolean("baby", false); MobDisguise mobDisguise = new MobDisguise(type); if (StringUtils.isNotBlank(typeData)) { FlagWatcher watcher = mobDisguise.getWatcher(); + if (watcher instanceof AgeableWatcher) { + ((AgeableWatcher) watcher).setBaby(babyData); + } try { switch (type) { + case MUSHROOM_COW: + if (typeData.toUpperCase().equals("BROWN")) { + ((MushroomCowWatcher) watcher).setVariant(Variant.BROWN); + } else { + ((MushroomCowWatcher) watcher).setVariant(Variant.RED); + } + break; case FOX: Fox.Type foxType = Fox.Type.valueOf(typeData); ((FoxWatcher) watcher).setType(foxType); @@ -162,9 +176,7 @@ public static Disguise parseDisguise(ConfigurationSection section, String name, ((RabbitWatcher) watcher).setType(rabbitType); break; case ZOMBIE: - if (Boolean.parseBoolean(typeData)) { - ((ZombieWatcher) watcher).setBaby(); - } + ((ZombieWatcher) watcher).setBaby(babyData); break; case SLIME: ((SlimeWatcher) watcher).setSize(Integer.parseInt(typeData)); @@ -314,12 +326,21 @@ public static float getLifeSkillExp(Player player, LifeSkillType type) { .getLifeSkillExp(type); } + public static float getLifeSkillExp(Champion champion, LifeSkillType type) { + return champion.getLifeSkillExp(type); + } + public static float getLifeSkillMaxExp(Player player, LifeSkillType type) { int level = StrifePlugin.getInstance().getChampionManager().getChampion(player) .getLifeSkillLevel(type); return StrifePlugin.getInstance().getSkillExperienceManager().getMaxExp(type, level); } + public static float getLifeSkillMaxExp(Champion champion, LifeSkillType type) { + int level = champion.getLifeSkillLevel(type); + return StrifePlugin.getInstance().getSkillExperienceManager().getMaxExp(type, level); + } + public static float getSkillProgress(Champion champion, LifeSkillType type) { return champion.getSaveData().getSkillExp(type) / StrifePlugin.getInstance() .getSkillExperienceManager().getMaxExp(type, champion.getSaveData().getSkillLevel(type)); From fd48ab53b6b0ee420c94a6f595c2757414a2df31 Mon Sep 17 00:00:00 2001 From: UltraFaceguy Date: Wed, 8 Apr 2020 02:54:59 -0400 Subject: [PATCH 06/13] Boss bar refactor for memory efficiency --- .../java/land/face/strife/StrifePlugin.java | 8 +- .../java/land/face/strife/data/SkillBar.java | 45 +++ .../land/face/strife/data/SkillBossBar.java | 38 --- .../java/land/face/strife/data/StatusBar.java | 73 ++++ .../land/face/strife/data/StrifeBossBar.java | 57 ---- .../face/strife/managers/BossBarManager.java | 311 +++++++----------- .../managers/SkillExperienceManager.java | 7 +- .../land/face/strife/tasks/BossBarsTask.java | 3 +- .../face/strife/tasks/PruneBossBarsTask.java | 36 -- 9 files changed, 236 insertions(+), 342 deletions(-) create mode 100644 src/main/java/land/face/strife/data/SkillBar.java delete mode 100644 src/main/java/land/face/strife/data/SkillBossBar.java create mode 100644 src/main/java/land/face/strife/data/StatusBar.java delete mode 100644 src/main/java/land/face/strife/data/StrifeBossBar.java delete mode 100644 src/main/java/land/face/strife/tasks/PruneBossBarsTask.java diff --git a/src/main/java/land/face/strife/StrifePlugin.java b/src/main/java/land/face/strife/StrifePlugin.java index c4c04345..17d1ac27 100644 --- a/src/main/java/land/face/strife/StrifePlugin.java +++ b/src/main/java/land/face/strife/StrifePlugin.java @@ -135,7 +135,6 @@ import land.face.strife.tasks.IndicatorTask; import land.face.strife.tasks.MinionDecayTask; import land.face.strife.tasks.ParticleTask; -import land.face.strife.tasks.PruneBossBarsTask; import land.face.strife.tasks.RegenTask; import land.face.strife.tasks.SaveTask; import land.face.strife.tasks.SpawnerSpawnTask; @@ -346,7 +345,6 @@ public void enable() { BossBarsTask bossBarsTask = new BossBarsTask(bossBarManager); MinionDecayTask minionDecayTask = new MinionDecayTask(minionManager); GlobalMultiplierTask globalMultiplierTask = new GlobalMultiplierTask(globalBoostManager); - PruneBossBarsTask pruneBossBarsTask = new PruneBossBarsTask(bossBarManager); SpawnerSpawnTask spawnerSpawnTask = new SpawnerSpawnTask(spawnerManager); AbilityTickTask iconDuraTask = new AbilityTickTask(abilityManager); VirtualEntityTask virtualEntityTask = new VirtualEntityTask(); @@ -419,10 +417,6 @@ public void enable() { 20L * 15, // Start timer after 15s 20L * 60 // Run it every minute after )); - taskList.add(pruneBossBarsTask.runTaskTimer(this, - 20L * 13, // Start timer after 13s - 20L * 60 * 7 // Run it every 7 minutes - )); taskList.add(particleTask.runTaskTimer(this, 2L, 1L @@ -536,7 +530,7 @@ public void disable() { Bukkit.getScheduler().cancelTasks(this); strifeMobManager.despawnAllTempEntities(); - bossBarManager.removeAllBars(); + bossBarManager.clearBars(); agilityManager.saveLocations(); spawnerManager.cancelAll(); rageManager.endRageTasks(); diff --git a/src/main/java/land/face/strife/data/SkillBar.java b/src/main/java/land/face/strife/data/SkillBar.java new file mode 100644 index 00000000..6967ef00 --- /dev/null +++ b/src/main/java/land/face/strife/data/SkillBar.java @@ -0,0 +1,45 @@ +package land.face.strife.data; + +import java.lang.ref.WeakReference; +import land.face.strife.data.champion.Champion; +import land.face.strife.data.champion.LifeSkillType; +import org.bukkit.boss.BossBar; + +public class SkillBar { + + private WeakReference owner; + private final BossBar skillBar; + private LifeSkillType lifeSkillType; + private int lifeTicks; + + public SkillBar(Champion owner, BossBar skillBar) { + this.owner = new WeakReference<>(owner); + this.lifeTicks = 200; + this.skillBar = skillBar; + } + + public Champion getOwner() { + return owner.get(); + } + + public BossBar getSkillBar() { + return skillBar; + } + + public LifeSkillType getLifeSkillType() { + return lifeSkillType; + } + + public void setLifeSkillType(LifeSkillType lifeSkillType) { + this.lifeSkillType = lifeSkillType; + } + + public int getLifeTicks() { + return lifeTicks; + } + + public void setLifeTicks(int lifeTicks) { + this.lifeTicks = lifeTicks; + } + +} diff --git a/src/main/java/land/face/strife/data/SkillBossBar.java b/src/main/java/land/face/strife/data/SkillBossBar.java deleted file mode 100644 index 4ab22ce0..00000000 --- a/src/main/java/land/face/strife/data/SkillBossBar.java +++ /dev/null @@ -1,38 +0,0 @@ -package land.face.strife.data; - -import land.face.strife.data.champion.Champion; -import org.bukkit.boss.BossBar; - -public class SkillBossBar { - - private Champion owner; - private int displayTicks; - private final BossBar skillBar; - - public SkillBossBar(Champion owner, BossBar skillBar) { - this.owner = owner; - this.displayTicks = 0; - this.skillBar = skillBar; - } - - public Champion getOwner() { - return owner; - } - - public void setOwner(Champion owner) { - this.owner = owner; - } - - public int getDisplayTicks() { - return displayTicks; - } - - public void setDisplayTicks(int displayTicks) { - this.displayTicks = displayTicks; - } - - public BossBar getSkillBar() { - return skillBar; - } - -} diff --git a/src/main/java/land/face/strife/data/StatusBar.java b/src/main/java/land/face/strife/data/StatusBar.java new file mode 100644 index 00000000..be867537 --- /dev/null +++ b/src/main/java/land/face/strife/data/StatusBar.java @@ -0,0 +1,73 @@ +package land.face.strife.data; + +import java.lang.ref.WeakReference; +import java.util.Objects; +import land.face.strife.util.StatUtil; +import org.bukkit.boss.BossBar; + +public class StatusBar { + + private WeakReference target; + private final BossBar barrierBar; + private final BossBar healthBar; + + private int lifeTicks; + private boolean dead; + private boolean hidden; + + public StatusBar(StrifeMob target, BossBar healthBar, BossBar barrierBar) { + this.target = new WeakReference<>(target); + this.healthBar = healthBar; + this.barrierBar = barrierBar; + this.lifeTicks = 400; + this.dead = false; + this.hidden = false; + } + + public StrifeMob getTarget() { + return target.get(); + } + + public void setTarget(StrifeMob target) { + this.target = new WeakReference<>(target); + } + + public BossBar getBarrierBar() { + return barrierBar; + } + + public BossBar getHealthBar() { + return healthBar; + } + + public int getLifeTicks() { + return lifeTicks; + } + + public void setLifeTicks(int lifeTicks) { + this.lifeTicks = lifeTicks; + } + + public boolean isDead() { + return dead; + } + + public void setDead(boolean dead) { + this.dead = dead; + } + + public boolean isHidden() { + return hidden; + } + + public void setHidden(boolean hidden) { + this.hidden = hidden; + healthBar.setVisible(!hidden); + if (target.get() == null) { + barrierBar.setVisible(!hidden); + } else { + barrierBar.setVisible(!hidden && StatUtil.getMaximumBarrier( + Objects.requireNonNull(target.get())) > 1); + } + } +} diff --git a/src/main/java/land/face/strife/data/StrifeBossBar.java b/src/main/java/land/face/strife/data/StrifeBossBar.java deleted file mode 100644 index 540fbb86..00000000 --- a/src/main/java/land/face/strife/data/StrifeBossBar.java +++ /dev/null @@ -1,57 +0,0 @@ -package land.face.strife.data; - -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; -import org.bukkit.boss.BossBar; - -public class StrifeBossBar { - - private StrifeMob owner; - private Map viewers; - private BossBar barrierBar; - private BossBar healthBar; - - private boolean dead; - - public StrifeBossBar(StrifeMob owner, BossBar barrierBar, BossBar healthBar) { - this.owner = owner; - this.healthBar = healthBar; - this.barrierBar = barrierBar; - this.viewers = new ConcurrentHashMap<>(); - this.dead = false; - } - - public StrifeMob getOwner() { - return owner; - } - - public Map getViewers() { - return viewers; - } - - public BossBar getBarrierBar() { - return barrierBar; - } - - public void setBarrierBar(BossBar barrierBar) { - this.barrierBar = barrierBar; - } - - public BossBar getHealthBar() { - return healthBar; - } - - public void setHealthBar(BossBar healthBar) { - this.healthBar = healthBar; - } - - public boolean isDead() { - return dead; - } - - public void setDead(boolean dead) { - this.dead = dead; - } - -} diff --git a/src/main/java/land/face/strife/managers/BossBarManager.java b/src/main/java/land/face/strife/managers/BossBarManager.java index dbfb492f..5806f772 100644 --- a/src/main/java/land/face/strife/managers/BossBarManager.java +++ b/src/main/java/land/face/strife/managers/BossBarManager.java @@ -26,29 +26,25 @@ import java.util.List; import java.util.Map; import java.util.Random; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; +import java.util.WeakHashMap; import land.face.strife.StrifePlugin; -import land.face.strife.data.SkillBossBar; -import land.face.strife.data.StrifeBossBar; +import land.face.strife.data.SkillBar; +import land.face.strife.data.StatusBar; import land.face.strife.data.StrifeMob; -import land.face.strife.data.champion.Champion; import land.face.strife.data.champion.LifeSkillType; import land.face.strife.util.PlayerDataUtil; import land.face.strife.util.StatUtil; import org.bukkit.Bukkit; import org.bukkit.boss.BarColor; -import org.bukkit.boss.BarFlag; import org.bukkit.boss.BarStyle; import org.bukkit.boss.BossBar; -import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; public class BossBarManager { private final StrifePlugin plugin; - private final Map barMap = new ConcurrentHashMap<>(); - private final Map skillBarMap = new HashMap<>(); + private final Map statusBars = new WeakHashMap<>(); + private final Map skillBars = new HashMap<>(); private final List deathMessages; private final int healthDuration; private final int skillDuration; @@ -62,233 +58,136 @@ public BossBarManager(StrifePlugin plugin) { this.skillDuration = plugin.getSettings().getInt("config.mechanics.skill-bar-duration", 200); } - private void createBars(StrifeMob target) { - if (barMap.containsKey(target.getEntity().getUniqueId())) { + private void createHealthBar(Player player, StrifeMob target) { + if (statusBars.containsKey(player)) { return; } - StrifeBossBar bossBar = new StrifeBossBar(target, makeBarrierBar(target), makeHealthBar()); - updateBarTitle(bossBar, createBarTitle(target)); - barMap.put(target.getEntity().getUniqueId(), bossBar); - } + BossBar barrierBar = makeBarrierBar(); + barrierBar.addPlayer(player); + BossBar healthBar = makeHealthBar(); + healthBar.addPlayer(player); - public SkillBossBar getSkillBar(Champion champion) { - if (skillBarMap.containsKey(champion.getUniqueId()) - && skillBarMap.get(champion.getUniqueId()) != null - && skillBarMap.get(champion.getUniqueId()).getSkillBar() != null) { - SkillBossBar bar = skillBarMap.get(champion.getUniqueId()); - for (Player p : bar.getSkillBar().getPlayers()) { - bar.getSkillBar().removePlayer(p); - } - bar.getSkillBar().addPlayer(champion.getPlayer()); - return bar; - } - SkillBossBar skillBar = new SkillBossBar(champion, makeSkillBar()); - skillBar.getSkillBar().setVisible(false); - skillBar.getSkillBar().addPlayer(champion.getPlayer()); - skillBarMap.put(champion.getUniqueId(), skillBar); - return skillBar; - } + StatusBar bar = new StatusBar(target, healthBar, barrierBar); + bar.setLifeTicks(healthDuration); + bar.setHidden(false); + bar.setDead(false); - public void bumpSkillBar(Champion champion, LifeSkillType lifeSkillType) { - String name = lifeSkillType.getName(); - SkillBossBar skillBar = getSkillBar(champion); - skillBar.getSkillBar().setVisible(true); - String barName = name + " Lv" + champion.getSaveData().getSkillLevel(lifeSkillType); - skillBar.getSkillBar().setTitle(barName); - skillBar.getSkillBar().setProgress(PlayerDataUtil.getSkillProgress(champion, lifeSkillType)); - skillBar.setDisplayTicks(skillDuration); + statusBars.put(player, bar); } - public void pushBar(Player player, StrifeMob target) { - createBars(target); - StrifeBossBar strifeBossBar = barMap.get(target.getEntity().getUniqueId()); - for (StrifeBossBar bossBar : barMap.values()) { - if (bossBar.equals(strifeBossBar)) { - continue; - } - removePlayerFromBar(bossBar, player.getUniqueId()); - } - addPlayerToBar(strifeBossBar, player); - updateBar(target.getEntity().getUniqueId(), strifeBossBar); - refreshCounter(strifeBossBar, player.getUniqueId()); - } - - public void tickHealthBars() { - for (UUID uuid : barMap.keySet()) { - updateBar(uuid, barMap.get(uuid)); - tickDownBar(barMap.get(uuid)); - } - } - - public void tickSkillBars() { - for (Player player : Bukkit.getOnlinePlayers()) { - SkillBossBar skillBossBar = skillBarMap.getOrDefault(player.getUniqueId(), - getSkillBar(plugin.getChampionManager().getChampion(player))); - if (!skillBossBar.getSkillBar().isVisible()) { - continue; - } - skillBossBar.setDisplayTicks(skillBossBar.getDisplayTicks() - 1); - if (skillBossBar.getDisplayTicks() < 1) { - skillBossBar.getSkillBar().setVisible(false); - } - } - } - - public void pruneOldBars() { - for (UUID uuid : barMap.keySet()) { - pruneBarIfNoOwners(uuid); - } - } - - public void removeBar(UUID uuid) { - if (!barMap.containsKey(uuid)) { + private void createSkillBar(Player player) { + if (skillBars.containsKey(player)) { return; } - StrifeBossBar strifeBossBar = barMap.get(uuid); - barMap.remove(uuid); - - strifeBossBar.getHealthBar().removeAll(); - if (strifeBossBar.getBarrierBar() != null) { - strifeBossBar.getBarrierBar().removeAll(); - } - - strifeBossBar.setHealthBar(null); - strifeBossBar.setBarrierBar(null); - } - - public void removeAllBars() { - for (UUID uuid : barMap.keySet()) { - removeBar(uuid); - } - } - - private void addPlayerToBar(StrifeBossBar strifeBossBar, Player player) { - if (strifeBossBar.getBarrierBar() != null) { - if (!strifeBossBar.getBarrierBar().getPlayers().contains(player)) { - strifeBossBar.getBarrierBar().addPlayer(player); - } - } - if (!strifeBossBar.getHealthBar().getPlayers().contains(player)) { - strifeBossBar.getHealthBar().addPlayer(player); - } - } + BossBar skillBar = makeSkillBar(); + skillBar.addPlayer(player); - public void doBarDeath(LivingEntity livingEntity) { - StrifeBossBar bossBar = barMap.getOrDefault(livingEntity.getUniqueId(), null); - if (bossBar != null) { - doBarDeath(bossBar); - } - } + SkillBar bar = new SkillBar(plugin.getChampionManager().getChampion(player), skillBar); + bar.setLifeTicks(skillDuration); - public void doBarDeath(StrifeBossBar bossBar) { - bossBar.setDead(true); - updateBarTitle(bossBar, deathMessages.get(random.nextInt(deathMessages.size()))); - if (bossBar.getBarrierBar() != null) { - bossBar.getBarrierBar().setProgress(0); - } - bossBar.getHealthBar().setProgress(0); - for (UUID playerUuid : bossBar.getViewers().keySet()) { - bossBar.getViewers().put(playerUuid, 25); - } + skillBars.put(player, bar); } - private void pruneBarIfNoOwners(UUID uuid) { - if (barMap.get(uuid).getViewers().isEmpty()) { - removeBar(uuid); - } + public void pushSkillBar(Player player, LifeSkillType lifeSkillType) { + createSkillBar(player); + String name = lifeSkillType.getName(); + SkillBar bar = skillBars.get(player); + String barName = name + " Lv" + bar.getOwner().getSaveData().getSkillLevel(lifeSkillType); + bar.getSkillBar().setTitle(barName); + bar.setLifeTicks(skillDuration); + bar.setLifeSkillType(lifeSkillType); + bar.getSkillBar().setVisible(true); + updateSkillBar(bar); } - private void tickDownBar(StrifeBossBar strifeBossBar) { - if (strifeBossBar == null) { - return; - } - for (UUID barPlayer : strifeBossBar.getViewers().keySet()) { - int ticksRemaining = strifeBossBar.getViewers().get(barPlayer); - if (ticksRemaining < 1) { - removePlayerFromBar(strifeBossBar, barPlayer); - continue; + public void pushBar(Player player, StrifeMob target) { + createHealthBar(player, target); + StatusBar bar = statusBars.get(player); + bar.setTarget(target); + bar.setLifeTicks(healthDuration); + bar.setHidden(false); + bar.setDead(false); + updateBar(bar); + } + + public void doBarDeath(Player player) { + if (statusBars.containsKey(player)) { + StatusBar bossBar = statusBars.get(player); + if (!bossBar.isDead()) { + bossBar.setDead(true); + updateBarTitle(bossBar, deathMessages.get(random.nextInt(deathMessages.size()))); + bossBar.getBarrierBar().setProgress(0); + bossBar.getHealthBar().setProgress(0); + bossBar.setLifeTicks(25); } - strifeBossBar.getViewers().replace(barPlayer, ticksRemaining - 1); } - pruneBarIfNoOwners(strifeBossBar.getOwner().getEntity().getUniqueId()); } - private void updateBar(UUID uuid, StrifeBossBar bossBar) { - StrifeMob barOwner = bossBar.getOwner(); - if (barOwner == null || barOwner.getEntity() == null) { - removeBar(uuid); + private void updateBar(StatusBar bossBar) { + if (bossBar.isHidden()) { return; } - if (!bossBar.isDead() && !bossBar.getOwner().getEntity().isValid()) { - removeBar(barOwner.getEntity().getUniqueId()); + bossBar.setLifeTicks(bossBar.getLifeTicks() - 1); + if (bossBar.getTarget() == null || bossBar.getLifeTicks() < 1) { + bossBar.setHidden(true); return; } if (bossBar.isDead()) { return; } - updateBarrierProgress(bossBar); - updateHealthProgress(bossBar); - updateBarTitle(bossBar, createBarTitle(barOwner)); - } - - private void removePlayerFromBar(StrifeBossBar strifeBossBar, Player player) { - if (strifeBossBar == null || strifeBossBar.getViewers().isEmpty()) { + if (bossBar.getTarget().getEntity() == null || !bossBar.getTarget().getEntity().isValid()) { + bossBar.setHidden(true); return; } - strifeBossBar.getViewers().remove(player.getUniqueId()); - if (strifeBossBar.getBarrierBar() != null) { - strifeBossBar.getBarrierBar().removePlayer(player); - } - strifeBossBar.getHealthBar().removePlayer(player); + updateBarTitle(bossBar, createBarTitle(bossBar.getTarget())); + updateHealthProgress(bossBar); + updateBarrierProgress(bossBar); } - private void removePlayerFromBar(StrifeBossBar strifeBossBar, UUID uuid) { - Player player = Bukkit.getPlayer(uuid); - if (player == null) { + private void updateSkillBar(SkillBar skillBar) { + if (!skillBar.getSkillBar().isVisible()) { return; } - removePlayerFromBar(strifeBossBar, player); - } - - private void refreshCounter(StrifeBossBar strifeBossBar, UUID uuid) { - if (strifeBossBar.isDead()) { + if (skillBar.getLifeTicks() < 1) { + skillBar.getSkillBar().setVisible(false); return; } - strifeBossBar.getViewers().put(uuid, healthDuration); + skillBar.setLifeTicks(skillBar.getLifeTicks() - 1); + updateSkillProgress(skillBar); } - private void updateHealthProgress(StrifeBossBar bar) { - double health = bar.getOwner().getEntity().getHealth(); - double maxHealth = bar.getOwner().getEntity().getAttribute(GENERIC_MAX_HEALTH).getValue(); + private void updateHealthProgress(StatusBar bar) { + double health = bar.getTarget().getEntity().getHealth(); + double maxHealth = bar.getTarget().getEntity().getAttribute(GENERIC_MAX_HEALTH).getValue(); bar.getHealthBar().setProgress(Math.min(health / maxHealth, 1D)); } - private void updateBarrierProgress(StrifeBossBar bar) { - if (StatUtil.getMaximumBarrier(bar.getOwner()) < 1) { - bar.setBarrierBar(null); + private void updateBarrierProgress(StatusBar bar) { + if (StatUtil.getMaximumBarrier(bar.getTarget()) < 1) { + bar.getBarrierBar().setVisible(false); return; } - double barrier = plugin.getBarrierManager().getCurrentBarrier(bar.getOwner()); - double maxBarrier = StatUtil.getMaximumBarrier(bar.getOwner()); + double barrier = plugin.getBarrierManager().getCurrentBarrier(bar.getTarget()); + double maxBarrier = StatUtil.getMaximumBarrier(bar.getTarget()); bar.getBarrierBar().setProgress(Math.min(barrier / maxBarrier, 1D)); } - private BossBar makeSkillBar() { - return plugin.getServer().createBossBar("skillbar", BarColor.GREEN, BarStyle.SOLID, - new BarFlag[0]); - } - - private BossBar makeHealthBar() { - return plugin.getServer().createBossBar("healthbar", BarColor.RED, BarStyle.SOLID, - new BarFlag[0]); + private void updateSkillProgress(SkillBar bar) { + bar.getSkillBar().setProgress( + PlayerDataUtil.getSkillProgress(bar.getOwner(), bar.getLifeSkillType())); } - private BossBar makeBarrierBar(StrifeMob entity) { - if (StatUtil.getMaximumBarrier(entity) < 1) { - return null; + public void tickBars() { + for (Player p : Bukkit.getOnlinePlayers()) { + StatusBar bar = statusBars.get(p); + if (bar != null) { + updateBar(bar); + } + SkillBar skillBar = skillBars.get(p); + if (skillBar != null) { + updateSkillBar(skillBar); + } } - return plugin.getServer().createBossBar("barrierBar", BarColor.WHITE, BarStyle.SOLID, - new BarFlag[0]); } private String createBarTitle(StrifeMob barOwner) { @@ -299,15 +198,33 @@ private String createBarTitle(StrifeMob barOwner) { return customName; } - private void updateBarTitle(StrifeBossBar bossBar, String title) { - if (bossBar.getHealthBar() == null) { - return; - } - if (bossBar.getBarrierBar() != null) { + private void updateBarTitle(StatusBar bossBar, String title) { + if (bossBar.getBarrierBar().isVisible()) { bossBar.getBarrierBar().setTitle(title); bossBar.getHealthBar().setTitle(null); - return; + } else { + bossBar.getBarrierBar().setTitle(null); + bossBar.getHealthBar().setTitle(title); } - bossBar.getHealthBar().setTitle(title); + } + + public void clearBars() { + statusBars.clear(); + skillBars.clear(); + } + + private static BossBar makeSkillBar() { + return StrifePlugin.getInstance().getServer() + .createBossBar("skillbar", BarColor.GREEN, BarStyle.SOLID); + } + + private static BossBar makeHealthBar() { + return StrifePlugin.getInstance().getServer() + .createBossBar("healthbar", BarColor.RED, BarStyle.SOLID); + } + + private static BossBar makeBarrierBar() { + return StrifePlugin.getInstance().getServer() + .createBossBar("barrierBar", BarColor.WHITE, BarStyle.SOLID); } } diff --git a/src/main/java/land/face/strife/managers/SkillExperienceManager.java b/src/main/java/land/face/strife/managers/SkillExperienceManager.java index b1316269..ad3f0b76 100644 --- a/src/main/java/land/face/strife/managers/SkillExperienceManager.java +++ b/src/main/java/land/face/strife/managers/SkillExperienceManager.java @@ -104,12 +104,9 @@ public void addExperience(Champion champion, LifeSkillType type, double amount, } saveData.setSkillExp(type, (float) currentExp); - //ChatColor c = type.getColor(); - //String xpMsg = XP_AB.replace("{0}", "" + c).replace("{1}", FORMAT.format((int) currentExp)) - // .replace("{2}", FORMAT.format((int) maxExp)); - //MessageUtils.sendActionBar(champion.getPlayer(), xpMsg); + if (displayXp) { - plugin.getBossBarManager().bumpSkillBar(champion, type); + plugin.getBossBarManager().pushSkillBar(champion.getPlayer(), type); } } diff --git a/src/main/java/land/face/strife/tasks/BossBarsTask.java b/src/main/java/land/face/strife/tasks/BossBarsTask.java index d2b68cb4..b7b9654b 100644 --- a/src/main/java/land/face/strife/tasks/BossBarsTask.java +++ b/src/main/java/land/face/strife/tasks/BossBarsTask.java @@ -31,7 +31,6 @@ public BossBarsTask(BossBarManager bossBarManager) { @Override public void run() { - bossBarManager.tickHealthBars(); - bossBarManager.tickSkillBars(); + bossBarManager.tickBars(); } } diff --git a/src/main/java/land/face/strife/tasks/PruneBossBarsTask.java b/src/main/java/land/face/strife/tasks/PruneBossBarsTask.java deleted file mode 100644 index fda8aa5c..00000000 --- a/src/main/java/land/face/strife/tasks/PruneBossBarsTask.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * The MIT License Copyright (c) 2015 Teal Cube Games - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and - * associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT - * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package land.face.strife.tasks; - -import land.face.strife.managers.BossBarManager; -import org.bukkit.scheduler.BukkitRunnable; - -public class PruneBossBarsTask extends BukkitRunnable { - - private BossBarManager bossBarManager; - - public PruneBossBarsTask(BossBarManager bossBarManager) { - this.bossBarManager = bossBarManager; - } - - @Override - public void run() { - bossBarManager.pruneOldBars(); - } -} From 365c3418e8fc3bde9c0f9f6cb57c870995ebc5d2 Mon Sep 17 00:00:00 2001 From: UltraFaceguy Date: Wed, 8 Apr 2020 02:55:45 -0400 Subject: [PATCH 07/13] fixing wands not firing right on melee hits --- .../java/land/face/strife/listeners/CombatListener.java | 3 +-- src/main/java/land/face/strife/listeners/DataListener.java | 3 --- .../java/land/face/strife/listeners/DeathListener.java | 4 +++- .../java/land/face/strife/listeners/SwingListener.java | 7 ------- src/main/java/land/face/strife/managers/DamageManager.java | 4 ++-- 5 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/main/java/land/face/strife/listeners/CombatListener.java b/src/main/java/land/face/strife/listeners/CombatListener.java index 2cf7b1a5..2ebc69f1 100644 --- a/src/main/java/land/face/strife/listeners/CombatListener.java +++ b/src/main/java/land/face/strife/listeners/CombatListener.java @@ -198,12 +198,11 @@ public void strifeDamageHandler(EntityDamageByEntityEvent event) { } if (attackType == AttackType.MELEE) { - attackMultiplier = plugin.getAttackSpeedManager().getAttackMultiplier(attacker); if (ItemUtil.isWandOrStaff(attackEntity.getEquipment().getItemInMainHand())) { - ProjectileUtil.shootWand(attacker, attackMultiplier); event.setCancelled(true); return; } + attackMultiplier = plugin.getAttackSpeedManager().getAttackMultiplier(attacker); attackMultiplier = (float) Math.pow(attackMultiplier, 1.25); } else if (attackType == AttackType.EXPLOSION) { double distance = event.getDamager().getLocation().distance(event.getEntity().getLocation()); diff --git a/src/main/java/land/face/strife/listeners/DataListener.java b/src/main/java/land/face/strife/listeners/DataListener.java index 97e85d05..aa10b6e7 100644 --- a/src/main/java/land/face/strife/listeners/DataListener.java +++ b/src/main/java/land/face/strife/listeners/DataListener.java @@ -118,7 +118,6 @@ public void onPlayerJoin(final PlayerJoinEvent event) { if (champion.getUnusedStatPoints() > 0) { notifyUnusedPoints(event.getPlayer(), champion.getUnusedStatPoints()); } - plugin.getBossBarManager().getSkillBar(champion); plugin.getCounterManager().clearCounters(event.getPlayer()); ensureAbilitiesDontInstantCast(event.getPlayer()); Bukkit.getScheduler().runTaskLater(plugin, @@ -143,7 +142,6 @@ public void onPlayerKick(final PlayerKickEvent event) { private void doPlayerLeave(Player player) { plugin.getAbilityManager().savePlayerCooldowns(player); - plugin.getBossBarManager().removeBar(player.getUniqueId()); plugin.getAbilityIconManager().removeIconItem(player, AbilitySlot.SLOT_A); plugin.getAbilityIconManager().removeIconItem(player, AbilitySlot.SLOT_B); plugin.getAbilityIconManager().removeIconItem(player, AbilitySlot.SLOT_C); @@ -157,7 +155,6 @@ public void onPlayerRespawn(final PlayerRespawnEvent event) { plugin.getBleedManager().clearBleed(event.getPlayer().getUniqueId()); plugin.getCorruptionManager().clearCorrupt(event.getPlayer().getUniqueId()); plugin.getAbilityManager().loadPlayerCooldowns(event.getPlayer()); - plugin.getBossBarManager().removeBar(event.getPlayer().getUniqueId()); plugin.getBarrierManager().createBarrierEntry( plugin.getStrifeMobManager().getStatMob(event.getPlayer())); plugin.getAbilityIconManager().setAllAbilityIcons(event.getPlayer()); diff --git a/src/main/java/land/face/strife/listeners/DeathListener.java b/src/main/java/land/face/strife/listeners/DeathListener.java index 21b2f296..37942899 100644 --- a/src/main/java/land/face/strife/listeners/DeathListener.java +++ b/src/main/java/land/face/strife/listeners/DeathListener.java @@ -96,7 +96,9 @@ public void onEntityDeathClearIconsAndStrifeMobs(final EntityDeathEvent event) { @EventHandler(priority = EventPriority.MONITOR) public void onEntityDeathClearData(final EntityDeathEvent event) { - plugin.getBossBarManager().doBarDeath(event.getEntity()); + if (event.getEntity().getKiller() != null) { + plugin.getBossBarManager().doBarDeath(event.getEntity().getKiller()); + } plugin.getBarrierManager().removeEntity(event.getEntity()); plugin.getRageManager().clearRage(event.getEntity().getUniqueId()); plugin.getBleedManager().clearBleed(event.getEntity().getUniqueId()); diff --git a/src/main/java/land/face/strife/listeners/SwingListener.java b/src/main/java/land/face/strife/listeners/SwingListener.java index c0f9ad05..7a91b491 100644 --- a/src/main/java/land/face/strife/listeners/SwingListener.java +++ b/src/main/java/land/face/strife/listeners/SwingListener.java @@ -21,7 +21,6 @@ import static org.bukkit.event.block.Action.LEFT_CLICK_AIR; import static org.bukkit.event.block.Action.LEFT_CLICK_BLOCK; -import com.tealcube.minecraft.bukkit.facecore.utilities.MessageUtils; import java.util.HashSet; import java.util.Set; import java.util.UUID; @@ -29,8 +28,6 @@ import land.face.strife.data.StrifeMob; import land.face.strife.util.ItemUtil; import land.face.strife.util.ProjectileUtil; -import org.bukkit.Sound; -import org.bukkit.entity.Player; import org.bukkit.event.Event.Result; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -72,10 +69,6 @@ public void onSwingLeft(PlayerInteractEvent event) { if (ItemUtil.isWandOrStaff(event.getPlayer().getEquipment().getItemInMainHand())) { if (attackMult > 0.2) { ProjectileUtil.shootWand(mob, Math.pow(attackMult, 1.5D)); - } else { - MessageUtils.sendActionBar((Player) mob.getEntity(), notChargedMessage); - mob.getEntity().getWorld() - .playSound(mob.getEntity().getLocation(), Sound.ENTITY_BLAZE_AMBIENT, 0.5f, 2.0f); } event.setCancelled(true); } diff --git a/src/main/java/land/face/strife/managers/DamageManager.java b/src/main/java/land/face/strife/managers/DamageManager.java index 2b5ea488..b13a042e 100644 --- a/src/main/java/land/face/strife/managers/DamageManager.java +++ b/src/main/java/land/face/strife/managers/DamageManager.java @@ -83,9 +83,9 @@ public double dealDamage(StrifeMob attacker, StrifeMob defender, double damage, public IndicatorData buildHitIndicator(Player player) { IndicatorData data = new IndicatorData(new Vector( - IND_GRAVITY_HSPEED - Math.random() * 2 * IND_GRAVITY_HSPEED, + IND_GRAVITY_HSPEED * 6 * (0.5 - Math.random()), IND_GRAVITY_VSPEED * (1 + Math.random()), - IND_GRAVITY_HSPEED - Math.random() * 2 * IND_GRAVITY_HSPEED), + IND_GRAVITY_HSPEED * 6 * (0.5 - Math.random())), IndicatorStyle.GRAVITY); data.addOwner(player); return data; From 8306d5f200a8655f0683b806f856ac65783d059f Mon Sep 17 00:00:00 2001 From: UltraFaceguy Date: Thu, 9 Apr 2020 02:21:32 -0400 Subject: [PATCH 08/13] Remove bossbars on disable --- .../java/land/face/strife/managers/BossBarManager.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/land/face/strife/managers/BossBarManager.java b/src/main/java/land/face/strife/managers/BossBarManager.java index 5806f772..071da609 100644 --- a/src/main/java/land/face/strife/managers/BossBarManager.java +++ b/src/main/java/land/face/strife/managers/BossBarManager.java @@ -209,7 +209,14 @@ private void updateBarTitle(StatusBar bossBar, String title) { } public void clearBars() { + for (Player p : statusBars.keySet()) { + statusBars.get(p).getBarrierBar().removeAll(); + statusBars.get(p).getHealthBar().removeAll(); + } statusBars.clear(); + for (Player p : skillBars.keySet()) { + skillBars.get(p).getSkillBar().removeAll(); + } skillBars.clear(); } From cc2d4ca7ac61ffbb069ebb8d842cb504bf43c4b9 Mon Sep 17 00:00:00 2001 From: UltraFaceguy Date: Thu, 9 Apr 2020 15:59:52 -0400 Subject: [PATCH 09/13] Title indicates how much skillxp until next level --- .../java/land/face/strife/managers/BossBarManager.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/land/face/strife/managers/BossBarManager.java b/src/main/java/land/face/strife/managers/BossBarManager.java index 071da609..d143014f 100644 --- a/src/main/java/land/face/strife/managers/BossBarManager.java +++ b/src/main/java/land/face/strife/managers/BossBarManager.java @@ -35,6 +35,7 @@ import land.face.strife.util.PlayerDataUtil; import land.face.strife.util.StatUtil; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.boss.BarColor; import org.bukkit.boss.BarStyle; import org.bukkit.boss.BossBar; @@ -88,11 +89,14 @@ private void createSkillBar(Player player) { skillBars.put(player, bar); } - public void pushSkillBar(Player player, LifeSkillType lifeSkillType) { + void pushSkillBar(Player player, LifeSkillType lifeSkillType) { createSkillBar(player); String name = lifeSkillType.getName(); SkillBar bar = skillBars.get(player); - String barName = name + " Lv" + bar.getOwner().getSaveData().getSkillLevel(lifeSkillType); + String barName = + name + " Lv" + bar.getOwner().getSaveData().getSkillLevel(lifeSkillType) + ChatColor.GRAY + + " - " + ChatColor.YELLOW + PlayerDataUtil + .getLifeSkillExpToLevel(bar.getOwner(), lifeSkillType) + "XP To Levelup"; bar.getSkillBar().setTitle(barName); bar.setLifeTicks(skillDuration); bar.setLifeSkillType(lifeSkillType); @@ -140,8 +144,8 @@ private void updateBar(StatusBar bossBar) { return; } updateBarTitle(bossBar, createBarTitle(bossBar.getTarget())); - updateHealthProgress(bossBar); updateBarrierProgress(bossBar); + updateHealthProgress(bossBar); } private void updateSkillBar(SkillBar skillBar) { From 0db8f5aaa09a64d63ad7eafd29c9530942a5919f Mon Sep 17 00:00:00 2001 From: UltraFaceguy Date: Tue, 28 Apr 2020 00:59:50 -0400 Subject: [PATCH 10/13] Adding health and barrier value display --- .../face/strife/managers/BossBarManager.java | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/main/java/land/face/strife/managers/BossBarManager.java b/src/main/java/land/face/strife/managers/BossBarManager.java index d143014f..2d2243c9 100644 --- a/src/main/java/land/face/strife/managers/BossBarManager.java +++ b/src/main/java/land/face/strife/managers/BossBarManager.java @@ -21,7 +21,7 @@ import static org.bukkit.attribute.Attribute.GENERIC_MAX_HEALTH; import com.tealcube.minecraft.bukkit.TextUtils; -import com.tealcube.minecraft.bukkit.shade.apache.commons.lang3.StringUtils; +import java.text.DecimalFormat; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -32,6 +32,7 @@ import land.face.strife.data.StatusBar; import land.face.strife.data.StrifeMob; import land.face.strife.data.champion.LifeSkillType; +import land.face.strife.stats.StrifeStat; import land.face.strife.util.PlayerDataUtil; import land.face.strife.util.StatUtil; import org.bukkit.Bukkit; @@ -51,6 +52,8 @@ public class BossBarManager { private final int skillDuration; private final Random random = new Random(); + private static final DecimalFormat INT_FORMAT = new DecimalFormat("#,###,###"); + public BossBarManager(StrifePlugin plugin) { this.plugin = plugin; this.deathMessages = TextUtils @@ -93,10 +96,11 @@ void pushSkillBar(Player player, LifeSkillType lifeSkillType) { createSkillBar(player); String name = lifeSkillType.getName(); SkillBar bar = skillBars.get(player); - String barName = - name + " Lv" + bar.getOwner().getSaveData().getSkillLevel(lifeSkillType) + ChatColor.GRAY - + " - " + ChatColor.YELLOW + PlayerDataUtil - .getLifeSkillExpToLevel(bar.getOwner(), lifeSkillType) + "XP To Levelup"; + int level = bar.getOwner().getSaveData().getSkillLevel(lifeSkillType); + String xp = INT_FORMAT + .format(PlayerDataUtil.getLifeSkillExpToLevel(bar.getOwner(), lifeSkillType)); + String barName = TextUtils.color("&f" + name + " Lv" + level + " &8- " + + "&f(&a" + xp + "xp to " + (level + 1) + "&f)"); bar.getSkillBar().setTitle(barName); bar.setLifeTicks(skillDuration); bar.setLifeSkillType(lifeSkillType); @@ -195,11 +199,19 @@ public void tickBars() { } private String createBarTitle(StrifeMob barOwner) { - String customName = barOwner.getEntity().getCustomName(); - if (StringUtils.isBlank(customName)) { - return StringUtils.capitalize(barOwner.getEntity().getName().replace('_', ' ')); + String name; + if (barOwner.getEntity() instanceof Player) { + name = (barOwner.getEntity().getName()) + ChatColor.GRAY + " Lv" + + ((Player) barOwner.getEntity()).getLevel(); + } else { + name = barOwner.getEntity().getCustomName(); + } + name += " "; + if (barOwner.getStat(StrifeStat.BARRIER) > 0) { + name = name + ChatColor.WHITE + INT_FORMAT.format(StatUtil.getBarrier(barOwner)) + "❤ "; } - return customName; + name = name + ChatColor.RED + INT_FORMAT.format(barOwner.getEntity().getHealth()) + "❤"; + return name; } private void updateBarTitle(StatusBar bossBar, String title) { From f29070f306d40b20f3317caea36b2407bba5219a Mon Sep 17 00:00:00 2001 From: UltraFaceguy Date: Tue, 28 Apr 2020 17:20:18 -0400 Subject: [PATCH 11/13] Moving elemental statuses to a percentage based on attack element model --- .../land/face/strife/util/DamageUtil.java | 159 +++++++++--------- 1 file changed, 82 insertions(+), 77 deletions(-) diff --git a/src/main/java/land/face/strife/util/DamageUtil.java b/src/main/java/land/face/strife/util/DamageUtil.java index 46f0fa1d..fd3ccfca 100644 --- a/src/main/java/land/face/strife/util/DamageUtil.java +++ b/src/main/java/land/face/strife/util/DamageUtil.java @@ -153,9 +153,7 @@ public static boolean preDamage(StrifeMob attacker, StrifeMob defender, DamageMo public static Map buildDamage(StrifeMob attacker, StrifeMob defender, DamageModifiers mods) { - float attackMult = mods.getAttackMultiplier(); - Map damageMap = DamageUtil.buildDamageMap(attacker, mods.getAttackType()); damageMap.replaceAll((t, v) -> damageMap.get(t) * mods.getDamageModifiers().getOrDefault(t, 0f) * attackMult); @@ -166,7 +164,6 @@ public static Map buildDamage(StrifeMob attacker, StrifeMob d } } DamageUtil.applyElementalEffects(attacker, defender, damageMap, mods); - return damageMap; } @@ -199,11 +196,6 @@ public static float damage(StrifeMob attacker, StrifeMob defender, mods.getAbilityMods().getOrDefault(AbilityMod.CRITICAL_DAMAGE, 0f)) / 100; } - boolean overcharge = mods.getAttackMultiplier() > 0.99; - if (overcharge) { - bonusOverchargeMultiplier = attacker.getStat(StrifeStat.OVERCHARGE) / 100; - } - float pvpMult = 1f; if (attacker.getEntity() instanceof Player && defender.getEntity() instanceof Player) { pvpMult = PVP_MULT; @@ -249,11 +241,8 @@ public static float damage(StrifeMob attacker, StrifeMob defender, float postBarrierDamage = plugin.getBarrierManager().damageBarrier(defender, rawDamage); String damageString = String.valueOf((int) Math.ceil(rawDamage)); - if (overcharge) { - damageString = "&l" + damageString; - } if (criticalHit) { - damageString = damageString + "!"; + damageString = "&l" + damageString; } if (attacker.getEntity() instanceof Player) { plugin.getIndicatorManager().addIndicator(attacker.getEntity(), defender.getEntity(), @@ -462,58 +451,83 @@ public static void applyAttackTypeMods(StrifeMob attacker, AttackType attackType } } - public static void applyElementalEffects(StrifeMob attacker, StrifeMob defender, - Map damageMap, DamageModifiers mods) { + private static void applyElementalEffects(StrifeMob attacker, + StrifeMob defender, Map damageMap, DamageModifiers mods) { + if (!mods.isConsumeEarthRunes()) { + int earthRunes = consumeEarthRune(attacker, defender.getEntity()); + if (earthRunes != 0) { + damageMap.put(DamageType.EARTH, damageMap.get(DamageType.EARTH) * (1 + earthRunes * 0.3f)); + } + } + if (!DamageUtil.rollBool(attacker.getStat(StrifeStat.ELEMENTAL_STATUS) / 100, true)) { + return; + } + float totalElementalDamage = 0; + Map elementalDamages = new HashMap<>(); for (DamageType type : damageMap.keySet()) { - float bonus; - switch (type) { - case FIRE: - bonus = attemptIgnite(damageMap.get(type), attacker, defender.getEntity()); - if (bonus != 0) { - mods.getElementalStatuses().add(ElementalStatus.IGNITE); - damageMap.put(type, damageMap.get(type) + bonus); - } - break; - case ICE: - bonus = attemptFreeze(damageMap.get(type), attacker, defender.getEntity()); - if (bonus != 0) { - mods.getElementalStatuses().add(ElementalStatus.FREEZE); - damageMap.put(type, damageMap.get(type) + bonus); - } - break; - case LIGHTNING: - bonus = attemptShock(damageMap.get(type), attacker, defender.getEntity()); - if (bonus != 0) { - mods.getElementalStatuses().add(ElementalStatus.SHOCK); - damageMap.put(type, damageMap.get(type) + bonus); - } - break; - case DARK: - bonus = - damageMap.get(type) * getDarknessManager().getCorruptionMult(defender.getEntity()); - boolean corrupt = attemptCorrupt(damageMap.get(type), attacker, defender.getEntity()); - if (corrupt) { - mods.getElementalStatuses().add(ElementalStatus.CORRUPT); - damageMap.put(type, damageMap.get(type) + bonus); - } - break; - case EARTH: - if (!mods.isConsumeEarthRunes()) { - break; - } - int earthRunes = consumeEarthRune(attacker, defender.getEntity()); - if (earthRunes != 0) { - damageMap.put(type, damageMap.get(type) * (1 + earthRunes * 0.3f)); - } - break; - case LIGHT: - bonus = getLightBonus(damageMap.get(type), attacker, defender.getEntity()); - if (bonus > damageMap.get(type) / 2) { - damageMap.put(type, damageMap.get(type) + bonus); - } - break; + if (type != DamageType.PHYSICAL && type != DamageType.MAGICAL + && type != DamageType.TRUE_DAMAGE && type != DamageType.EARTH) { + float amount = damageMap.get(type); + totalElementalDamage += amount; + elementalDamages.put(type, amount); + } + } + if (totalElementalDamage <= 0.1) { + return; + } + float currentWeight = 0; + totalElementalDamage *= Math.random(); + DamageType finalElementType = null; + for (DamageType type : elementalDamages.keySet()) { + currentWeight += elementalDamages.get(type); + if (currentWeight >= totalElementalDamage) { + finalElementType = type; + break; } } + if (finalElementType == null) { + return; + } + float bonus; + switch (finalElementType) { + case FIRE: + bonus = attemptIgnite(damageMap.get(finalElementType), attacker, defender.getEntity()); + if (bonus != 0) { + mods.getElementalStatuses().add(ElementalStatus.IGNITE); + damageMap.put(finalElementType, damageMap.get(finalElementType) + bonus); + } + break; + case ICE: + bonus = attemptFreeze(damageMap.get(finalElementType), attacker, defender.getEntity()); + if (bonus != 0) { + mods.getElementalStatuses().add(ElementalStatus.FREEZE); + damageMap.put(finalElementType, damageMap.get(finalElementType) + bonus); + } + break; + case LIGHTNING: + bonus = attemptShock(damageMap.get(finalElementType), attacker, defender.getEntity()); + if (bonus != 0) { + mods.getElementalStatuses().add(ElementalStatus.SHOCK); + damageMap.put(finalElementType, damageMap.get(finalElementType) + bonus); + } + break; + case DARK: + bonus = damageMap.get(finalElementType) * getDarknessManager() + .getCorruptionMult(defender.getEntity()); + boolean corrupt = attemptCorrupt(damageMap.get(finalElementType), attacker, + defender.getEntity()); + if (corrupt) { + mods.getElementalStatuses().add(ElementalStatus.CORRUPT); + damageMap.put(finalElementType, damageMap.get(finalElementType) + bonus); + } + break; + case LIGHT: + bonus = getLightBonus(damageMap.get(finalElementType), attacker, defender.getEntity()); + if (bonus > damageMap.get(finalElementType) / 2) { + damageMap.put(finalElementType, damageMap.get(finalElementType) + bonus); + } + break; + } } public static float getDamageReduction(DamageType type, StrifeMob attack, StrifeMob defend, @@ -593,22 +607,19 @@ public static LivingEntity getAttacker(Entity entity) { } public static float attemptIgnite(float damage, StrifeMob attacker, LivingEntity defender) { - if (rollDouble() >= attacker.getStat(StrifeStat.IGNITE_CHANCE) / 100) { - return 0; - } float bonusDamage = defender.getFireTicks() > 0 ? damage : 1f; - defender.setFireTicks(Math.max(60 + (int) damage, defender.getFireTicks())); + defender.setFireTicks(Math.max(25 + (int) damage, defender.getFireTicks())); defender.getWorld().playSound(defender.getEyeLocation(), Sound.ITEM_FLINTANDSTEEL_USE, 1f, 1f); - defender.getWorld() - .spawnParticle(Particle.FLAME, defender.getEyeLocation(), 6 + (int) damage / 2, - 0.3, 0.3, 0.3, 0.03); + defender.getWorld().spawnParticle( + Particle.FLAME, + defender.getEyeLocation(), + 6 + (int) damage / 2, + 0.3, 0.3, 0.3, 0.03 + ); return bonusDamage; } public static float attemptShock(float damage, StrifeMob attacker, LivingEntity defender) { - if (rollDouble() >= attacker.getStat(StrifeStat.SHOCK_CHANCE) / 100) { - return 0; - } float multiplier = 0.5f; float percentHealth = (float) defender.getHealth() / (float) defender.getAttribute(Attribute.GENERIC_MAX_HEALTH) @@ -630,9 +641,6 @@ public static float attemptShock(float damage, StrifeMob attacker, LivingEntity } public static float attemptFreeze(float damage, StrifeMob attacker, LivingEntity defender) { - if (rollDouble() >= attacker.getStat(StrifeStat.FREEZE_CHANCE) / 100) { - return 0; - } float multiplier = 0.25f + 0.25f * (StatUtil.getHealth(attacker) / 100); if (!defender.hasPotionEffect(PotionEffectType.SLOW)) { defender.getActivePotionEffects().add(new PotionEffect(PotionEffectType.SLOW, 30, 1)); @@ -667,9 +675,6 @@ public static float getLightBonus(float damage, StrifeMob attacker, LivingEntity public static boolean attemptCorrupt(float baseDamage, StrifeMob attacker, LivingEntity defender) { - if (rollDouble() >= attacker.getStat(StrifeStat.CORRUPT_CHANCE) / 100) { - return false; - } applyCorrupt(defender, baseDamage); return true; } From 42d5204a824d9328793f554382fd58af660ac5be Mon Sep 17 00:00:00 2001 From: UltraFaceguy Date: Sun, 3 May 2020 18:32:16 -0400 Subject: [PATCH 12/13] Defaulting to no equipment for unique entities --- .../java/land/face/strife/util/ItemUtil.java | 33 +++++++------------ 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/main/java/land/face/strife/util/ItemUtil.java b/src/main/java/land/face/strife/util/ItemUtil.java index 8f8f6327..a357d7a7 100644 --- a/src/main/java/land/face/strife/util/ItemUtil.java +++ b/src/main/java/land/face/strife/util/ItemUtil.java @@ -30,7 +30,9 @@ public class ItemUtil { public static ItemStack withBase64(ItemStack item, String base64) { UUID hashAsId = new UUID(base64.hashCode(), base64.hashCode()); - return Bukkit.getUnsafe().modifyItemStack(item, "{SkullOwner:{Id:\"" + hashAsId + "\",Properties:{textures:[{Value:\"" + base64 + "\"}]}}}"); + return Bukkit.getUnsafe().modifyItemStack(item, + "{SkullOwner:{Id:\"" + hashAsId + "\",Properties:{textures:[{Value:\"" + base64 + + "\"}]}}}"); } public static boolean isArmor(Material material) { @@ -172,36 +174,25 @@ public static Set getTraits(ItemStack stack) { } public static void delayedEquip(Map items, LivingEntity entity) { + entity.setCanPickupItems(false); if (entity.getEquipment() == null) { return; } Bukkit.getScheduler().runTaskLater(StrifePlugin.getInstance(), () -> { - entity.setCanPickupItems(false); + entity.getEquipment().clear(); entity.getEquipment().setHelmetDropChance(0f); entity.getEquipment().setChestplateDropChance(0f); entity.getEquipment().setLeggingsDropChance(0f); entity.getEquipment().setBootsDropChance(0f); entity.getEquipment().setItemInMainHandDropChance(0f); entity.getEquipment().setItemInOffHandDropChance(0f); - if (items.containsKey(EquipmentSlot.HEAD)) { - entity.getEquipment().setHelmet(items.get(EquipmentSlot.HEAD)); - } - if (items.containsKey(EquipmentSlot.CHEST)) { - entity.getEquipment().setChestplate(items.get(EquipmentSlot.CHEST)); - } - if (items.containsKey(EquipmentSlot.LEGS)) { - entity.getEquipment().setLeggings(items.get(EquipmentSlot.LEGS)); - } - if (items.containsKey(EquipmentSlot.FEET)) { - entity.getEquipment().setBoots(items.get(EquipmentSlot.FEET)); - } - if (items.containsKey(EquipmentSlot.HAND)) { - entity.getEquipment().setItemInMainHand(items.get(EquipmentSlot.HAND)); - } - if (items.containsKey(EquipmentSlot.OFF_HAND)) { - entity.getEquipment().setItemInOffHand(items.get(EquipmentSlot.OFF_HAND)); - } - }, 1L); + entity.getEquipment().setHelmet(items.getOrDefault(EquipmentSlot.HEAD, null)); + entity.getEquipment().setChestplate(items.getOrDefault(EquipmentSlot.CHEST, null)); + entity.getEquipment().setLeggings(items.getOrDefault(EquipmentSlot.LEGS, null)); + entity.getEquipment().setBoots(items.getOrDefault(EquipmentSlot.FEET, null)); + entity.getEquipment().setItemInMainHand(items.getOrDefault(EquipmentSlot.HAND, null)); + entity.getEquipment().setItemInOffHand(items.getOrDefault(EquipmentSlot.OFF_HAND, null)); + }, 2L); } public static int getCustomData(ItemStack stack) { From 2399745938ad6b4d7d593678e33cb5254425f787 Mon Sep 17 00:00:00 2001 From: UltraFaceguy Date: Mon, 11 May 2020 16:26:47 -0400 Subject: [PATCH 13/13] Complete damage overhaul Fixed targeting for friendly mobs Added basic guild support Added UniqueSpawnEvent to edit uniques Boost overhaul --- pom.xml | 15 +- .../java/land/face/strife/StrifePlugin.java | 65 ++-- .../face/strife/commands/StrifeCommand.java | 4 +- ...{DamageContainer.java => BonusDamage.java} | 12 +- .../java/land/face/strife/data/Boost.java | 44 +++ .../face/strife/data/DamageModifiers.java | 26 +- .../face/strife/data/GlobalStatBoost.java | 45 --- .../java/land/face/strife/data/Spawner.java | 3 + .../java/land/face/strife/data/StatusBar.java | 2 +- .../java/land/face/strife/data/StrifeMob.java | 20 +- .../land/face/strife/data/UniqueEntity.java | 18 ++ .../strife/data/champion/LifeSkillType.java | 4 +- .../data/conditions/EntityTypeCondition.java | 6 +- .../conditions/NearbyEntitiesCondition.java | 4 +- .../face/strife/data/effects/AreaEffect.java | 39 ++- .../land/face/strife/data/effects/Bleed.java | 6 +- .../land/face/strife/data/effects/Charm.java | 13 +- .../{StandardDamage.java => Damage.java} | 62 +++- .../strife/data/effects/DirectDamage.java | 103 ------ .../land/face/strife/data/effects/Effect.java | 2 +- .../land/face/strife/data/effects/Heal.java | 6 +- .../land/face/strife/data/effects/Ignite.java | 2 + .../strife/data/effects/LocationEffect.java | 11 + .../data/effects/PotionEffectAction.java | 3 +- .../face/strife/data/effects/ShootBlock.java | 8 +- .../strife/data/effects/StrifeParticle.java | 12 +- .../land/face/strife/data/effects/Summon.java | 12 +- .../AbilityComparator.java | 27 ++ .../face/strife/data/effects/Teleport.java | 30 +- .../land/face/strife/data/effects/Title.java | 35 +++ .../face/strife/events/UniqueSpawnEvent.java | 32 ++ .../face/strife/listeners/CombatListener.java | 39 ++- .../face/strife/listeners/DOTListener.java | 132 +++----- .../face/strife/listeners/DataListener.java | 4 +- .../strife/listeners/EntityMagicListener.java | 24 +- .../strife/listeners/ExperienceListener.java | 19 +- .../face/strife/listeners/FallListener.java | 2 +- .../face/strife/listeners/ShootListener.java | 37 ++- .../face/strife/listeners/SpawnListener.java | 4 +- .../strife/listeners/TargetingListener.java | 37 ++- .../face/strife/managers/AbilityManager.java | 25 +- ...balBoostManager.java => BoostManager.java} | 123 +++++--- .../face/strife/managers/BossBarManager.java | 7 +- .../face/strife/managers/ChampionManager.java | 2 +- .../face/strife/managers/ChaserManager.java | 29 +- .../face/strife/managers/CounterManager.java | 6 +- .../face/strife/managers/DamageManager.java | 21 +- .../face/strife/managers/EffectManager.java | 175 ++++++----- .../strife/managers/ExperienceManager.java | 7 +- .../face/strife/managers/SoulManager.java | 9 +- .../strife/managers/StrifeMobManager.java | 9 +- .../strife/managers/UniqueEntityManager.java | 64 +++- .../menus/abilities/AbilityPickerMenu.java | 4 +- .../abilities/AbilityPickerPickerItem.java | 7 +- .../menus/stats/StatsOffenseMenuItem.java | 7 +- .../land/face/strife/stats/StrifeStat.java | 9 +- ...MultiplierTask.java => BoostTickTask.java} | 12 +- .../face/strife/tasks/DamageOverTimeTask.java | 131 ++++++++ .../face/strife/tasks/ItemPassengerTask.java | 45 +++ .../land/face/strife/tasks/ParticleTask.java | 14 +- .../face/strife/tasks/StrifeMobTracker.java | 35 ++- .../strife/timers/EndlessEffectTimer.java | 4 + .../strife/timers/EntityAbilityTimer.java | 3 +- .../land/face/strife/util/DamageUtil.java | 292 +++++++++--------- .../land/face/strife/util/PlayerDataUtil.java | 6 + .../land/face/strife/util/ProjectileUtil.java | 12 +- .../face/strife/util/SpecialStatusUtil.java | 9 + .../java/land/face/strife/util/StatUtil.java | 4 - .../land/face/strife/util/TargetingUtil.java | 85 ++--- src/main/resources/boosts.json | 1 + 70 files changed, 1334 insertions(+), 792 deletions(-) rename src/main/java/land/face/strife/data/{DamageContainer.java => BonusDamage.java} (71%) create mode 100644 src/main/java/land/face/strife/data/Boost.java delete mode 100644 src/main/java/land/face/strife/data/GlobalStatBoost.java rename src/main/java/land/face/strife/data/effects/{StandardDamage.java => Damage.java} (63%) delete mode 100644 src/main/java/land/face/strife/data/effects/DirectDamage.java create mode 100644 src/main/java/land/face/strife/data/effects/TargetingComparators/AbilityComparator.java create mode 100644 src/main/java/land/face/strife/data/effects/Title.java create mode 100644 src/main/java/land/face/strife/events/UniqueSpawnEvent.java rename src/main/java/land/face/strife/managers/{GlobalBoostManager.java => BoostManager.java} (57%) rename src/main/java/land/face/strife/tasks/{GlobalMultiplierTask.java => BoostTickTask.java} (79%) create mode 100644 src/main/java/land/face/strife/tasks/DamageOverTimeTask.java create mode 100644 src/main/java/land/face/strife/tasks/ItemPassengerTask.java create mode 100644 src/main/resources/boosts.json diff --git a/pom.xml b/pom.xml index fd761076..c07dce16 100644 --- a/pom.xml +++ b/pom.xml @@ -32,7 +32,7 @@ strife - 3.0.6-SNAPSHOT + 3.0.6 jar strife @@ -77,7 +77,7 @@ io.pixeloutlaw facecore - 1.15.2.4 + 1.15.2.5 provided @@ -89,7 +89,7 @@ LibsDisguises LibsDisguises - 9.9.9-SNAPSHOT + 10.0.5-SNAPSHOT provided @@ -101,9 +101,16 @@ com.github.UltraFaceguy SnazzyParties - 1.0.2 + 1.0.4 provided + + me.glaremasters + guilds + 3.5.4.9 + system + ${basedir}/lib/Guilds-3.5.4.9.jar + com.github.shynixn.headdatabase hdb-api diff --git a/src/main/java/land/face/strife/StrifePlugin.java b/src/main/java/land/face/strife/StrifePlugin.java index 17d1ac27..cb595cd7 100644 --- a/src/main/java/land/face/strife/StrifePlugin.java +++ b/src/main/java/land/face/strife/StrifePlugin.java @@ -86,6 +86,7 @@ import land.face.strife.managers.BarrierManager; import land.face.strife.managers.BleedManager; import land.face.strife.managers.BlockManager; +import land.face.strife.managers.BoostManager; import land.face.strife.managers.BossBarManager; import land.face.strife.managers.BuffManager; import land.face.strife.managers.ChampionManager; @@ -98,7 +99,6 @@ import land.face.strife.managers.EnergyManager; import land.face.strife.managers.EntityEquipmentManager; import land.face.strife.managers.ExperienceManager; -import land.face.strife.managers.GlobalBoostManager; import land.face.strife.managers.IndicatorManager; import land.face.strife.managers.LoreAbilityManager; import land.face.strife.managers.MinionManager; @@ -126,12 +126,13 @@ import land.face.strife.storage.FlatfileStorage; import land.face.strife.tasks.AbilityTickTask; import land.face.strife.tasks.BarrierTask; +import land.face.strife.tasks.BoostTickTask; import land.face.strife.tasks.BossBarsTask; import land.face.strife.tasks.CombatStatusTask; +import land.face.strife.tasks.DamageOverTimeTask; import land.face.strife.tasks.EnergyRegenTask; import land.face.strife.tasks.EveryTickTask; import land.face.strife.tasks.ForceAttackSpeed; -import land.face.strife.tasks.GlobalMultiplierTask; import land.face.strife.tasks.IndicatorTask; import land.face.strife.tasks.MinionDecayTask; import land.face.strife.tasks.ParticleTask; @@ -213,7 +214,7 @@ public class StrifePlugin extends FacePlugin { private CombatStatusManager combatStatusManager; private SpawnerManager spawnerManager; private MobModManager mobModManager; - private GlobalBoostManager globalBoostManager; + private BoostManager boostManager; private SoulManager soulManager; private EnergyManager energyManager; private WSEManager wseManager; @@ -223,6 +224,7 @@ public class StrifePlugin extends FacePlugin { private List taskList = new ArrayList<>(); private ParticleTask particleTask; + private DamageOverTimeTask damageOverTimeTask; private EnergyRegenTask energyRegenTask; private RegenTask regenTask; @@ -241,9 +243,12 @@ public static StrifePlugin getInstance() { return instance; } + public StrifePlugin() { + instance = this; + } + @Override public void enable() { - instance = this; debugPrinter = new PluginLogger(this); List configurations = new ArrayList<>(); @@ -292,7 +297,7 @@ public void enable() { attackSpeedManager = new AttackSpeedManager(this); indicatorManager = new IndicatorManager(); equipmentManager = new EntityEquipmentManager(); - globalBoostManager = new GlobalBoostManager(); + boostManager = new BoostManager(this); soulManager = new SoulManager(this); energyManager = new EnergyManager(this); barrierManager = new BarrierManager(); @@ -344,13 +349,14 @@ public void enable() { BarrierTask barrierTask = new BarrierTask(this); BossBarsTask bossBarsTask = new BossBarsTask(bossBarManager); MinionDecayTask minionDecayTask = new MinionDecayTask(minionManager); - GlobalMultiplierTask globalMultiplierTask = new GlobalMultiplierTask(globalBoostManager); + BoostTickTask boostTickTask = new BoostTickTask(boostManager); SpawnerSpawnTask spawnerSpawnTask = new SpawnerSpawnTask(spawnerManager); AbilityTickTask iconDuraTask = new AbilityTickTask(abilityManager); VirtualEntityTask virtualEntityTask = new VirtualEntityTask(); CombatStatusTask combatStatusTask = new CombatStatusTask(combatStatusManager); EveryTickTask everyTickTask = new EveryTickTask(); IndicatorTask indicatorTask = new IndicatorTask(this); + damageOverTimeTask = new DamageOverTimeTask(this); particleTask = new ParticleTask(); energyRegenTask = new EnergyRegenTask(this); regenTask = new RegenTask(this); @@ -383,7 +389,7 @@ public void enable() { )); taskList.add(strifeMobTracker.runTaskTimer(this, 20L * 61, // Start save after 1 minute - 20L * 60 // Run every 1 minute after that + 20L * 120 // Run every 2 minutes after that )); taskList.add(saveTask.runTaskTimer(this, 20L * 680, // Start save after 11 minutes, 20 seconds cuz yolo @@ -405,6 +411,10 @@ public void enable() { 11 * 20L, // Start timer after 11s 2L // Run it every 1/5th of a second after )); + taskList.add(damageOverTimeTask.runTaskTimer(this, + 20L, // Start timer after 11s + 5L // Run it every 5 ticks + )); taskList.add(bossBarsTask.runTaskTimer(this, 240L, // Start timer after 12s 2L // Run it every 1/10th of a second after @@ -413,9 +423,9 @@ public void enable() { 220L, // Start timer after 11s 11L )); - taskList.add(globalMultiplierTask.runTaskTimer(this, - 20L * 15, // Start timer after 15s - 20L * 60 // Run it every minute after + taskList.add(boostTickTask.runTaskTimer(this, + 20L, + 20L )); taskList.add(particleTask.runTaskTimer(this, 2L, @@ -445,9 +455,14 @@ public void enable() { 3 * 20L + 2L, // Start timer after 3s 20L )); + taskList.add(Bukkit.getScheduler().runTaskTimer(this, + () -> boostManager.checkBoostSchedule(), + 60L, + 20L * 900 + )); - globalBoostManager.startScheduledEvents(); agilityManager.loadAgilityContainers(); + boostManager.loadBoosts(); Bukkit.getPluginManager().registerEvents(new EndermanListener(), this); Bukkit.getPluginManager().registerEvents(new ExperienceListener(this), this); @@ -477,7 +492,8 @@ public void enable() { Bukkit.getPluginManager().registerEvents(new FallListener(this), this); Bukkit.getPluginManager().registerEvents(new LaunchAndLandListener(this), this); Bukkit.getPluginManager().registerEvents(new DogeListener(strifeMobManager), this); - Bukkit.getPluginManager().registerEvents(new LoreAbilityListener(strifeMobManager, loreAbilityManager), this); + Bukkit.getPluginManager() + .registerEvents(new LoreAbilityListener(strifeMobManager, loreAbilityManager), this); Bukkit.getPluginManager().registerEvents(new InventoryListener(this), this); if (Bukkit.getPluginManager().getPlugin("Bullion") != null) { Bukkit.getPluginManager().registerEvents(new BullionListener(this), this); @@ -494,9 +510,11 @@ public void enable() { menu.setId(menuId); String name = abilityMenus.getString(menuId + ".name", "CONFIGURE ME"); + List lore = abilityMenus.getStringList(menuId + ".lore"); Material material = Material.valueOf(abilityMenus.getString(menuId + ".material", "BARRIER")); int slot = abilityMenus.getInt(menuId + ".slot", 0); - AbilityPickerPickerItem subMenuIcon = new AbilityPickerPickerItem(menu, material, name, slot); + AbilityPickerPickerItem subMenuIcon = new AbilityPickerPickerItem(menu, material, name, lore, + slot); pickerItems.add(subMenuIcon); } @@ -524,6 +542,7 @@ public void enable() { @Override public void disable() { saveSpawners(); + boostManager.saveBoosts(); storage.saveAll(); HandlerList.unregisterAll(this); @@ -655,12 +674,12 @@ private void buildMobMods() { private void loadScheduledBoosts() { ConfigurationSection cs = globalBoostsYAML.getConfigurationSection("scheduled-boosts"); - globalBoostManager.loadScheduledBoosts(cs); + boostManager.loadScheduledBoosts(cs); } private void loadBoosts() { ConfigurationSection cs = globalBoostsYAML.getConfigurationSection("boost-templates"); - globalBoostManager.loadStatBoosts(cs); + boostManager.loadStatBoosts(cs); } private void buildUniqueEnemies() { @@ -686,7 +705,7 @@ private void buildUniqueEnemies() { uniqueEntity.setDisplaceMultiplier(cs.getDouble("displace-multiplier", 1.0)); uniqueEntity.setExperienceMultiplier((float) cs.getDouble("experience-multiplier", 1)); uniqueEntity.setKnockbackImmune(cs.getBoolean("knockback-immune", false)); - uniqueEntity.setCharmImmune(cs.getBoolean("charm-immune", true)); + uniqueEntity.setCharmImmune(cs.getBoolean("charm-immune", false)); uniqueEntity.setBurnImmune(cs.getBoolean("burn-immune", false)); uniqueEntity.setFallImmune(cs.getBoolean("fall-immune", false)); uniqueEntity.setIgnoreSneak(cs.getBoolean("ignore-sneak", false)); @@ -701,6 +720,7 @@ private void buildUniqueEnemies() { uniqueEntity.setSize(cs.getInt("size", -1)); uniqueEntity.getFactions().addAll(cs.getStringList("factions")); uniqueEntity.setBaby(cs.getBoolean("baby", false)); + uniqueEntity.setAngry(cs.getBoolean("angry", false)); uniqueEntity.setBaseLevel(cs.getInt("base-level", -1)); Disguise disguise = PlayerDataUtil.parseDisguise(cs.getConfigurationSection("disguise"), @@ -717,6 +737,11 @@ private void buildUniqueEnemies() { ConfigurationSection equipmentCS = cs.getConfigurationSection("equipment"); uniqueEntity.setEquipment(equipmentManager.buildEquipmentFromConfigSection(equipmentCS)); + String passengerItem = cs.getString("item-passenger", ""); + if (StringUtils.isNotBlank(passengerItem)) { + uniqueEntity.setItemPassenger(equipmentManager.getItem(passengerItem)); + } + String particle = cs.getString("particle", ""); if (StringUtils.isNotBlank(particle)) { Effect effect = effectManager.getEffect(particle); @@ -885,8 +910,8 @@ public SpawnerManager getSpawnerManager() { return spawnerManager; } - public GlobalBoostManager getGlobalBoostManager() { - return globalBoostManager; + public BoostManager getBoostManager() { + return boostManager; } public SoulManager getSoulManager() { @@ -977,6 +1002,10 @@ public EnergyRegenTask getEnergyRegenTask() { return energyRegenTask; } + public DamageOverTimeTask getDamageOverTimeTask() { + return damageOverTimeTask; + } + public RegenTask getRegenTask() { return regenTask; } diff --git a/src/main/java/land/face/strife/commands/StrifeCommand.java b/src/main/java/land/face/strife/commands/StrifeCommand.java index b44d68b6..a669aa41 100644 --- a/src/main/java/land/face/strife/commands/StrifeCommand.java +++ b/src/main/java/land/face/strife/commands/StrifeCommand.java @@ -136,7 +136,7 @@ public void profileCommand(CommandSender sender, @Arg(name = "target") Player ta @Command(identifier = "strife mobinfo", permissions = "strife.command.strife.info") public void infoCommand(CommandSender sender) { List targets = new ArrayList<>( - TargetingUtil.getEntitiesInLine((Player) sender, 30)); + TargetingUtil.getEntitiesInLine(((Player) sender).getEyeLocation(), 30)); if (targets.isEmpty()) { sendMessage(sender, "&eNo target found..."); return; @@ -332,7 +332,7 @@ public void addXpCommand(CommandSender sender, @Arg(name = "target") Player play @Command(identifier = "strife startBoost", permissions = "strife.command.strife.boosts", onlyPlayers = false) public void startBoostCommand(CommandSender sender, @Arg(name = "boostId") String boostId, @Arg(name = "creator") String creator, @Arg(name = "duration") int duration) { - boolean success = plugin.getGlobalBoostManager().createStatBoost(boostId, creator, duration); + boolean success = plugin.getBoostManager().startBoost(creator, boostId, duration); if (!success) { sendMessage(sender, "&cBoost with that ID doesn't exist, or this boost is running"); } diff --git a/src/main/java/land/face/strife/data/DamageContainer.java b/src/main/java/land/face/strife/data/BonusDamage.java similarity index 71% rename from src/main/java/land/face/strife/data/DamageContainer.java rename to src/main/java/land/face/strife/data/BonusDamage.java index c93a388a..73468f73 100644 --- a/src/main/java/land/face/strife/data/DamageContainer.java +++ b/src/main/java/land/face/strife/data/BonusDamage.java @@ -4,14 +4,14 @@ import land.face.strife.util.DamageUtil.DamageScale; import land.face.strife.util.DamageUtil.DamageType; -public class DamageContainer { +public class BonusDamage { - private DamageScale damageScale; - private DamageType damageType; - private StrifeStat damageStat; - private float amount; + private final DamageScale damageScale; + private final DamageType damageType; + private final StrifeStat damageStat; + private final float amount; - public DamageContainer(DamageScale damageScale, DamageType damageType, + public BonusDamage(DamageScale damageScale, DamageType damageType, StrifeStat damageStat, float amount) { this.damageScale = damageScale; this.damageType = damageType; diff --git a/src/main/java/land/face/strife/data/Boost.java b/src/main/java/land/face/strife/data/Boost.java new file mode 100644 index 00000000..6616619d --- /dev/null +++ b/src/main/java/land/face/strife/data/Boost.java @@ -0,0 +1,44 @@ +package land.face.strife.data; + +import java.util.Map; +import land.face.strife.stats.StrifeStat; + +public class Boost { + + private String boostId; + private int secondsRemaining; + private String boosterName; + private Map stats; + + public String getBoostId() { + return boostId; + } + + public void setBoostId(String boostId) { + this.boostId = boostId; + } + + public int getSecondsRemaining() { + return secondsRemaining; + } + + public void setSecondsRemaining(int secondsRemaining) { + this.secondsRemaining = secondsRemaining; + } + + public String getBoosterName() { + return boosterName; + } + + public void setBoosterName(String boosterName) { + this.boosterName = boosterName; + } + + public Map getStats() { + return stats; + } + + public void setStats(Map stats) { + this.stats = stats; + } +} diff --git a/src/main/java/land/face/strife/data/DamageModifiers.java b/src/main/java/land/face/strife/data/DamageModifiers.java index 638547b1..c2c9b611 100644 --- a/src/main/java/land/face/strife/data/DamageModifiers.java +++ b/src/main/java/land/face/strife/data/DamageModifiers.java @@ -1,7 +1,9 @@ package land.face.strife.data; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; import land.face.strife.util.DamageUtil; @@ -16,8 +18,9 @@ public class DamageModifiers { private AttackType attackType = AttackType.OTHER; private float attackMultiplier = 1f; private float healMultiplier = 1f; + private float damageReductionRatio = 1f; private final Map damageModifiers = new HashMap<>(baseDamageMults); - private final Map flatDamageBonuses = new HashMap<>(); + private final List bonusDamages = new ArrayList<>(); private final Map abilityMods = new HashMap<>(); private final Set elementalStatuses = new HashSet<>(); private boolean isSneakAttack = false; @@ -26,6 +29,7 @@ public class DamageModifiers { private boolean canBeEvaded = true; private boolean applyOnHitEffects = true; private boolean consumeEarthRunes = true; + private boolean scaleChancesWithAttack = false; public AttackType getAttackType() { return attackType; @@ -43,6 +47,14 @@ public void setAttackMultiplier(float attackMultiplier) { this.attackMultiplier = attackMultiplier; } + public float getDamageReductionRatio() { + return damageReductionRatio; + } + + public void setDamageReductionRatio(float damageReductionRatio) { + this.damageReductionRatio = damageReductionRatio; + } + public float getHealMultiplier() { return healMultiplier; } @@ -55,8 +67,8 @@ public Map getDamageModifiers() { return damageModifiers; } - public Map getFlatDamageBonuses() { - return flatDamageBonuses; + public List getBonusDamages() { + return bonusDamages; } public Map getAbilityMods() { @@ -107,6 +119,14 @@ public void setApplyOnHitEffects(boolean applyOnHitEffects) { this.applyOnHitEffects = applyOnHitEffects; } + public boolean isScaleChancesWithAttack() { + return scaleChancesWithAttack; + } + + public void setScaleChancesWithAttack(boolean scaleChancesWithAttack) { + this.scaleChancesWithAttack = scaleChancesWithAttack; + } + public boolean isConsumeEarthRunes() { return consumeEarthRunes; } diff --git a/src/main/java/land/face/strife/data/GlobalStatBoost.java b/src/main/java/land/face/strife/data/GlobalStatBoost.java deleted file mode 100644 index 5336e07e..00000000 --- a/src/main/java/land/face/strife/data/GlobalStatBoost.java +++ /dev/null @@ -1,45 +0,0 @@ -package land.face.strife.data; - -import java.util.Map; -import land.face.strife.stats.StrifeStat; - -public class GlobalStatBoost { - - private final String boostId; - private final String creator; - private final Map attributes; - - private int minutesRemaining; - - public GlobalStatBoost(String boostId, String creator, Map attrs, - int minutesRemaining) { - this.boostId = boostId; - this.creator = creator; - this.minutesRemaining = minutesRemaining; - this.attributes = attrs; - } - - public String getBoostId() { - return boostId; - } - - public String getCreator() { - return creator; - } - - public Map getAttributes() { - return attributes; - } - - public double getAttribute(StrifeStat attribute) { - return attributes.getOrDefault(attribute, 0f); - } - - public int getMinutesRemaining() { - return minutesRemaining; - } - - public void setMinutesRemaining(int minutesRemaining) { - this.minutesRemaining = minutesRemaining; - } -} diff --git a/src/main/java/land/face/strife/data/Spawner.java b/src/main/java/land/face/strife/data/Spawner.java index c4ef7ccd..85bc50a8 100644 --- a/src/main/java/land/face/strife/data/Spawner.java +++ b/src/main/java/land/face/strife/data/Spawner.java @@ -53,6 +53,9 @@ public void run() { double zDist = Math.abs(location.getZ() - le.getLocation().getZ()); if (Math.abs(xDist) + Math.abs(zDist) > leashRange) { despawnParticles(le); + if (StrifePlugin.getInstance().getStrifeMobManager().isTrackedEntity(le)) { + StrifePlugin.getInstance().getStrifeMobManager().removeEntity(le); + } le.remove(); LogUtil.printDebug("Cancelled SpawnerTimer with id " + getTaskId() + " due to leash range"); } diff --git a/src/main/java/land/face/strife/data/StatusBar.java b/src/main/java/land/face/strife/data/StatusBar.java index be867537..71bc9204 100644 --- a/src/main/java/land/face/strife/data/StatusBar.java +++ b/src/main/java/land/face/strife/data/StatusBar.java @@ -62,12 +62,12 @@ public boolean isHidden() { public void setHidden(boolean hidden) { this.hidden = hidden; - healthBar.setVisible(!hidden); if (target.get() == null) { barrierBar.setVisible(!hidden); } else { barrierBar.setVisible(!hidden && StatUtil.getMaximumBarrier( Objects.requireNonNull(target.get())) > 1); } + healthBar.setVisible(!hidden); } } diff --git a/src/main/java/land/face/strife/data/StrifeMob.java b/src/main/java/land/face/strife/data/StrifeMob.java index 2b58eac7..1ba36f99 100644 --- a/src/main/java/land/face/strife/data/StrifeMob.java +++ b/src/main/java/land/face/strife/data/StrifeMob.java @@ -1,9 +1,9 @@ package land.face.strife.data; -import io.netty.util.internal.ConcurrentSet; import java.lang.ref.WeakReference; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.Map; import java.util.Objects; import java.util.Set; @@ -35,7 +35,9 @@ public class StrifeMob { private EntityAbilitySet abilitySet; private String uniqueEntityId = null; private Set mods = new HashSet<>(); + private Set factions = new HashSet<>(); + private UUID alliedGuild; private Set tempEffects = new HashSet<>(); @@ -44,7 +46,7 @@ public class StrifeMob { private WeakReference master; - private final Set minions = new ConcurrentSet<>(); + private final Set minions = new HashSet<>(); private final Map runningBuffs = new ConcurrentHashMap<>(); private final Map takenDamage = new HashMap<>(); @@ -122,6 +124,14 @@ public Set getMods() { return mods; } + public UUID getAlliedGuild() { + return alliedGuild; + } + + public void setAlliedGuild(UUID alliedGuild) { + this.alliedGuild = alliedGuild; + } + public Set getFactions() { return factions; } @@ -216,9 +226,11 @@ public boolean hasTrait(StrifeTrait trait) { } public Set getMinions() { - for (StrifeMob minion : minions) { + Iterator iterator = minions.iterator(); + while (iterator.hasNext()) { + StrifeMob minion = (StrifeMob) iterator.next(); if (minion == null || minion.getEntity() == null || !minion.getEntity().isValid()) { - minions.remove(minion); + iterator.remove(); } } return new HashSet<>(minions); diff --git a/src/main/java/land/face/strife/data/UniqueEntity.java b/src/main/java/land/face/strife/data/UniqueEntity.java index 0935582e..f74ee75c 100644 --- a/src/main/java/land/face/strife/data/UniqueEntity.java +++ b/src/main/java/land/face/strife/data/UniqueEntity.java @@ -24,6 +24,7 @@ public class UniqueEntity { private int baseLevel; private boolean showName; private boolean baby; + private boolean angry; private int size; private int followRange = -1; private boolean knockbackImmune; @@ -37,6 +38,7 @@ public class UniqueEntity { private double displaceMultiplier; private String mount; private Map equipment = new HashMap<>(); + private ItemStack itemPassenger = null; private StrifeParticle strifeParticle; public String getId() { @@ -123,6 +125,14 @@ public void setBaby(boolean baby) { this.baby = baby; } + public boolean isAngry() { + return angry; + } + + public void setAngry(boolean angry) { + this.angry = angry; + } + public int getSize() { return size; } @@ -231,6 +241,14 @@ public void setEquipment(Map equipment) { this.equipment = equipment; } + public ItemStack getItemPassenger() { + return itemPassenger; + } + + public void setItemPassenger(ItemStack itemPassenger) { + this.itemPassenger = itemPassenger; + } + public StrifeParticle getStrifeParticle() { return strifeParticle; } diff --git a/src/main/java/land/face/strife/data/champion/LifeSkillType.java b/src/main/java/land/face/strife/data/champion/LifeSkillType.java index 783ff358..97a666b2 100644 --- a/src/main/java/land/face/strife/data/champion/LifeSkillType.java +++ b/src/main/java/land/face/strife/data/champion/LifeSkillType.java @@ -10,6 +10,7 @@ public enum LifeSkillType { MINING("Mining", "mining", ChatColor.DARK_GREEN), FARMING("Farming", "farming", ChatColor.GOLD), COOKING("Cooking", "cooking", ChatColor.YELLOW), + ALCHEMY("Alchemy", "alchemy", ChatColor.GREEN), SNEAK("Sneak", "sneak", ChatColor.GRAY), AGILITY("Agility", "agility", ChatColor.DARK_AQUA), TRADING("Trading", "trading", ChatColor.DARK_GREEN), @@ -18,7 +19,8 @@ public enum LifeSkillType { BLUNT_WEAPONS("Blunt Weapons", "blunt", ChatColor.RED), DUAL_WIELDING("Dual Wielding", "dual", ChatColor.GREEN), SHIELD_MASTERY("Shield Mastery", "shield", ChatColor.YELLOW), - ARCHERY("Marksmanship", "archery", ChatColor.DARK_GREEN), + ARCHERY("Archery", "archery", ChatColor.DARK_GREEN), + MARKSMANSHIP("Marksmanship", "marksmanship", ChatColor.DARK_GREEN), ARCANE_MAGICS("Arcane Magics", "arcane-magic", ChatColor.BLUE), NATURAL_MAGICS("Natural Magics", "natural-magic", ChatColor.DARK_AQUA), BLACK_MAGICS("Black Magics", "dark-magics", ChatColor.DARK_PURPLE), diff --git a/src/main/java/land/face/strife/data/conditions/EntityTypeCondition.java b/src/main/java/land/face/strife/data/conditions/EntityTypeCondition.java index ee0e2a29..cd5c7273 100644 --- a/src/main/java/land/face/strife/data/conditions/EntityTypeCondition.java +++ b/src/main/java/land/face/strife/data/conditions/EntityTypeCondition.java @@ -10,16 +10,18 @@ public class EntityTypeCondition extends Condition { private final Set types; private final boolean whitelist; + private final boolean useDisguise; - public EntityTypeCondition(Set types, boolean whitelist) { + public EntityTypeCondition(Set types, boolean whitelist, boolean useDisguise) { this.types = types; this.whitelist = whitelist; + this.useDisguise = useDisguise; } public boolean isMet(StrifeMob attacker, StrifeMob target) { LogUtil.printDebug("EntityType condition, type=" + target.getEntity().getType()); EntityType type; - if (DisguiseAPI.isDisguised(target.getEntity())) { + if (useDisguise && DisguiseAPI.isDisguised(target.getEntity())) { type = DisguiseAPI.getDisguise(target.getEntity()).getType().getEntityType(); } else { type = target.getEntity().getType(); diff --git a/src/main/java/land/face/strife/data/conditions/NearbyEntitiesCondition.java b/src/main/java/land/face/strife/data/conditions/NearbyEntitiesCondition.java index e752c6dc..bc97857c 100644 --- a/src/main/java/land/face/strife/data/conditions/NearbyEntitiesCondition.java +++ b/src/main/java/land/face/strife/data/conditions/NearbyEntitiesCondition.java @@ -1,6 +1,6 @@ package land.face.strife.data.conditions; -import io.netty.util.internal.ConcurrentSet; +import java.util.HashSet; import java.util.Set; import land.face.strife.data.StrifeMob; import land.face.strife.util.LogUtil; @@ -24,7 +24,7 @@ public boolean isMet(StrifeMob attacker, StrifeMob target) { LogUtil.printDebug("Nearby condition, type=" + target.getEntity().getType()); - Set entities = new ConcurrentSet<>(); + Set entities = new HashSet<>(); for (Entity e : target.getEntity().getWorld().getNearbyEntities( target.getEntity().getLocation(), range, range, range, this::isValid)) { entities.add((LivingEntity) e); diff --git a/src/main/java/land/face/strife/data/effects/AreaEffect.java b/src/main/java/land/face/strife/data/effects/AreaEffect.java index 95346ce6..51df3def 100644 --- a/src/main/java/land/face/strife/data/effects/AreaEffect.java +++ b/src/main/java/land/face/strife/data/effects/AreaEffect.java @@ -18,6 +18,7 @@ import land.face.strife.util.TargetingUtil; import org.bukkit.Location; import org.bukkit.attribute.Attribute; +import org.bukkit.entity.ArmorStand; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Mob; import org.bukkit.entity.Player; @@ -34,7 +35,7 @@ public class AreaEffect extends LocationEffect { private float maxConeRadius; private int maxTargets; private boolean scaleTargetsWithMultishot; - private boolean isLineOfSight; + private LineOfSight lineOfSight; private boolean canBeEvaded; private boolean canBeBlocked; private boolean canBeCountered; @@ -79,12 +80,11 @@ private Set getAreaEffectTargets(StrifeMob caster, Location locati areaTargets.addAll(TargetingUtil.getEntitiesInArea(location, range)); break; case LINE: - areaTargets.addAll(TargetingUtil.getEntitiesInLine(caster.getEntity(), range)); + areaTargets.addAll(TargetingUtil.getEntitiesInLine(location, range)); break; case CONE: - areaTargets.addAll(TargetingUtil.getEntitiesInCone(caster.getEntity(), - caster.getEntity().getLocation(), caster.getEntity().getLocation().getDirection(), - (float) range, maxConeRadius)); + areaTargets.addAll(TargetingUtil.getEntitiesInCone(caster.getEntity().getLocation(), + caster.getEntity().getLocation().getDirection(), (float) range, maxConeRadius)); break; case PARTY: if (caster.getEntity() instanceof Player) { @@ -97,8 +97,17 @@ private Set getAreaEffectTargets(StrifeMob caster, Location locati break; } TargetingUtil.filterFriendlyEntities(areaTargets, caster, isFriendly()); - if (isLineOfSight) { - areaTargets.removeIf(e -> !caster.getEntity().hasLineOfSight(e)); + if (areaTargets.size() == 0) { + return areaTargets; + } + switch (lineOfSight) { + case CASTER: + areaTargets.removeIf(e -> !caster.getEntity().hasLineOfSight(e)); + break; + case CENTER: + ArmorStand detector = TargetingUtil.buildAndRemoveDetectionStand(location); + areaTargets.removeIf(e -> !detector.hasLineOfSight(e)); + break; } if (maxTargets > 0) { int numTargets = maxTargets; @@ -128,7 +137,7 @@ private boolean isCancelled(StrifeMob caster, StrifeMob target) { } if (canBeBlocked) { return StrifePlugin.getInstance().getBlockManager().isAttackBlocked(caster, target, - 1.0f, AttackType.MAGIC, false); + 1.0f, AttackType.AREA, false); } return false; } @@ -188,12 +197,12 @@ public void setCanBeCountered(boolean canBeCountered) { this.canBeCountered = canBeCountered; } - public boolean isLineOfSight() { - return isLineOfSight; + public LineOfSight getLineOfSight() { + return lineOfSight; } - public void setLineOfSight(boolean lineOfSight) { - isLineOfSight = lineOfSight; + public void setLineOfSight(LineOfSight lineOfSight) { + this.lineOfSight = lineOfSight; } public double getRange() { @@ -239,6 +248,12 @@ public void setTargetingCooldown(long targetingCooldown) { this.targetingCooldown = targetingCooldown; } + public enum LineOfSight { + CASTER, + CENTER, + NONE + } + public enum AreaType { PARTY, RADIUS, diff --git a/src/main/java/land/face/strife/data/effects/Bleed.java b/src/main/java/land/face/strife/data/effects/Bleed.java index b489946f..1987dba5 100644 --- a/src/main/java/land/face/strife/data/effects/Bleed.java +++ b/src/main/java/land/face/strife/data/effects/Bleed.java @@ -1,6 +1,6 @@ package land.face.strife.data.effects; -import land.face.strife.data.DamageContainer; +import land.face.strife.data.BonusDamage; import land.face.strife.data.StrifeMob; import land.face.strife.stats.StrifeStat; import land.face.strife.util.DamageUtil; @@ -21,8 +21,8 @@ public void apply(StrifeMob caster, StrifeMob target) { for (StrifeStat attr : getStatMults().keySet()) { bleedAmount += getStatMults().get(attr) * caster.getStat(attr); } - DamageContainer container = new DamageContainer(damageScale, null, null, bleedAmount); - bleedAmount = DamageUtil.applyDamageScale(caster, target, container, null); + BonusDamage container = new BonusDamage(damageScale, null, null, bleedAmount); + bleedAmount = DamageUtil.applyDamageScale(caster, target, container); if (applyBleedMods) { bleedAmount *= 1 + caster.getStat(StrifeStat.BLEED_DAMAGE) / 100; bleedAmount *= 1 - target.getStat(StrifeStat.BLEED_RESIST) / 100; diff --git a/src/main/java/land/face/strife/data/effects/Charm.java b/src/main/java/land/face/strife/data/effects/Charm.java index 5792e169..8b92482a 100644 --- a/src/main/java/land/face/strife/data/effects/Charm.java +++ b/src/main/java/land/face/strife/data/effects/Charm.java @@ -22,35 +22,38 @@ public class Charm extends Effect { public void apply(StrifeMob caster, StrifeMob target) { if (target.isCharmImmune() || !(target.getEntity() instanceof Mob) || target .getEntity() instanceof Player) { + System.out.println("1"); return; } if (!overrideMaster && target.getMaster() != null) { + System.out.println("2"); return; } if (caster.getMinions().size() >= caster.getStat(StrifeStat.MAX_MINIONS)) { + System.out.println("3"); return; } if (target.getEntity() instanceof Wolf) { if (((Wolf) target.getEntity()).getOwner() != null) { + System.out.println("4"); return; } ((Wolf) target.getEntity()).setAngry(true); } if (!rollCharmChance(caster, target)) { + System.out.println("5"); return; } ((Mob) target.getEntity()).setTarget(null); - target.setMaster(caster.getEntity()); - target.setDespawnOnUnload(true); - target.forceSetStat(StrifeStat.MINION_MULT_INTERNAL, caster.getStat(StrifeStat.MINION_DAMAGE)); caster.addMinion(target); + target.getFactions().clear(); StrifePlugin.getInstance().getMinionManager() .addMinion(target.getEntity(), (int) ((lifespanSeconds * 20D) / 11D)); + StrifePlugin.getInstance().getSpawnerManager().addRespawnTime(target.getEntity()); } private boolean rollCharmChance(StrifeMob caster, StrifeMob target) { - int levelDiff = - StatUtil.getMobLevel(caster.getEntity()) - StatUtil.getMobLevel(target.getEntity()); + int levelDiff = StatUtil.getMobLevel(caster.getEntity()) - StatUtil.getMobLevel(target.getEntity()); if (levelDiff >= 0) { return chance + levelDiff * chancePerLevel > random.nextDouble(); } diff --git a/src/main/java/land/face/strife/data/effects/StandardDamage.java b/src/main/java/land/face/strife/data/effects/Damage.java similarity index 63% rename from src/main/java/land/face/strife/data/effects/StandardDamage.java rename to src/main/java/land/face/strife/data/effects/Damage.java index b5478f20..f4a0d279 100644 --- a/src/main/java/land/face/strife/data/effects/StandardDamage.java +++ b/src/main/java/land/face/strife/data/effects/Damage.java @@ -1,8 +1,11 @@ package land.face.strife.data.effects; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import land.face.strife.StrifePlugin; +import land.face.strife.data.BonusDamage; import land.face.strife.data.DamageModifiers; import land.face.strife.data.StrifeMob; import land.face.strife.events.StrifeDamageEvent; @@ -12,18 +15,20 @@ import land.face.strife.util.DamageUtil.DamageType; import org.bukkit.Bukkit; -public class StandardDamage extends Effect { +public class Damage extends Effect { private float attackMultiplier; private float healMultiplier; - private final Map damageModifiers = new HashMap<>(); - private final Map damageBonuses = new HashMap<>(); + private float damageReductionRatio; + private final Map damageMultipliers = new HashMap<>(); + private final List bonusDamages = new ArrayList<>(); private final Map abilityMods = new HashMap<>(); private AttackType attackType; private boolean canBeEvaded; private boolean canBeBlocked; private boolean canSneakAttack; private boolean isBlocking; + private boolean applyOnHitEffects; @Override public void apply(StrifeMob caster, StrifeMob target) { @@ -32,16 +37,17 @@ public void apply(StrifeMob caster, StrifeMob target) { mods.setAttackType(attackType); mods.setAttackMultiplier(attackMultiplier); mods.setHealMultiplier(healMultiplier); + mods.setDamageReductionRatio(damageReductionRatio); mods.setCanBeEvaded(canBeEvaded); mods.setCanBeBlocked(canBeBlocked); - mods.setApplyOnHitEffects(attackMultiplier > 0.75); - if (canSneakAttack && StrifePlugin.getInstance().getStealthManager().isStealthed( - caster.getEntity())) { + mods.setApplyOnHitEffects(applyOnHitEffects); + if (canSneakAttack && StrifePlugin.getInstance().getStealthManager() + .isStealthed(caster.getEntity())) { mods.setSneakAttack(true); } mods.setBlocking(isBlocking); - mods.getFlatDamageBonuses().putAll(damageBonuses); - mods.getDamageModifiers().putAll(damageModifiers); + mods.getBonusDamages().addAll(bonusDamages); + mods.getDamageModifiers().putAll(damageMultipliers); mods.getAbilityMods().putAll(abilityMods); boolean attackSuccess = DamageUtil.preDamage(caster, target, mods); @@ -52,18 +58,32 @@ public void apply(StrifeMob caster, StrifeMob target) { Map damage = DamageUtil.buildDamage(caster, target, mods); DamageUtil.reduceDamage(caster, target, damage, mods); - float finalDamage = DamageUtil.damage(caster, target, damage, mods); + float finalDamage = DamageUtil.calculateFinalDamage(caster, target, damage, mods); StrifeDamageEvent strifeDamageEvent = new StrifeDamageEvent(caster, target, mods); strifeDamageEvent.setFinalDamage(finalDamage); Bukkit.getPluginManager().callEvent(strifeDamageEvent); - if (!strifeDamageEvent.isCancelled()) { - DamageUtil.postDamage(caster, target, damage, mods); - StrifePlugin.getInstance().getDamageManager().dealDamage(caster, target, - (float) strifeDamageEvent.getFinalDamage(), false); + if (strifeDamageEvent.isCancelled()) { + return; + } + if (damage.containsKey(DamageType.PHYSICAL)) { + DamageUtil.attemptBleed(caster, target, damage.get(DamageType.PHYSICAL), mods, false); + } + if (mods.isApplyOnHitEffects()) { + DamageUtil.postDamage(caster, target, mods); } + StrifePlugin.getInstance().getDamageManager().dealDamage(caster, target, + (float) strifeDamageEvent.getFinalDamage()); + } + + public float getDamageReductionRatio() { + return damageReductionRatio; + } + + public void setDamageReductionRatio(float damageReductionRatio) { + this.damageReductionRatio = damageReductionRatio; } public float getHealMultiplier() { @@ -90,12 +110,12 @@ public void setAttackType(AttackType attackType) { this.attackType = attackType; } - public Map getDamageModifiers() { - return damageModifiers; + public Map getDamageMultipliers() { + return damageMultipliers; } - public Map getDamageBonuses() { - return damageBonuses; + public List getBonusDamages() { + return bonusDamages; } public Map getAbilityMods() { @@ -122,6 +142,14 @@ public void setCanSneakAttack(boolean canSneakAttack) { this.canSneakAttack = canSneakAttack; } + public boolean isApplyOnHitEffects() { + return applyOnHitEffects; + } + + public void setApplyOnHitEffects(boolean applyOnHitEffects) { + this.applyOnHitEffects = applyOnHitEffects; + } + public boolean isBlocking() { return isBlocking; } diff --git a/src/main/java/land/face/strife/data/effects/DirectDamage.java b/src/main/java/land/face/strife/data/effects/DirectDamage.java deleted file mode 100644 index e03b1467..00000000 --- a/src/main/java/land/face/strife/data/effects/DirectDamage.java +++ /dev/null @@ -1,103 +0,0 @@ -package land.face.strife.data.effects; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import land.face.strife.StrifePlugin; -import land.face.strife.data.DamageContainer; -import land.face.strife.data.StrifeMob; -import land.face.strife.stats.StrifeStat; -import land.face.strife.util.DamageUtil; -import land.face.strife.util.DamageUtil.AbilityMod; -import land.face.strife.util.DamageUtil.AttackType; -import land.face.strife.util.DamageUtil.DamageType; -import land.face.strife.util.LogUtil; -import org.bukkit.entity.Player; - -public class DirectDamage extends Effect { - - private AttackType attackType; - private Set damages = new HashSet<>(); - private boolean canBeEvaded; - private boolean canBeBlocked; - private final Map abilityMods = new HashMap<>(); - private float damageReductionRatio; - - private static float pvpMult = (float) StrifePlugin.getInstance().getSettings() - .getDouble("config.mechanics.pvp-damage", 0.50); - - @Override - public void apply(StrifeMob caster, StrifeMob target) { - float evasionMultiplier = 1.0f; - if (canBeEvaded) { - evasionMultiplier = DamageUtil.getFullEvasionMult(caster, target, abilityMods); - if (evasionMultiplier < DamageUtil.EVASION_THRESHOLD) { - DamageUtil.doEvasion(caster, target); - LogUtil.printDebug(" [Pre-Damage] Direct damage EVADED!"); - return; - } - } - if (canBeBlocked) { - if (StrifePlugin.getInstance().getCounterManager() - .executeCounters(caster.getEntity(), target.getEntity())) { - LogUtil.printDebug(" [Pre-Damage] Direct damage COUNTERED!"); - return; - } - if (StrifePlugin.getInstance().getBlockManager() - .isAttackBlocked(caster, target, damageReductionRatio, attackType, false)) { - LogUtil.printDebug(" [Pre-Damage] Direct damage BLOCKED!"); - return; - } - } - float damage = 0; - float damageMult = DamageUtil.getDamageMult(caster, target) * evasionMultiplier; - for (DamageContainer container : damages) { - float addDamage = DamageUtil.applyDamageScale(caster, target, container, attackType); - addDamage *= DamageUtil.getDamageReduction(container.getDamageType(), caster, target, - abilityMods); - if (container.getDamageType() != DamageType.TRUE_DAMAGE) { - addDamage *= damageMult; - } - damage += addDamage; - } - for (StrifeStat attr : getStatMults().keySet()) { - damage *= 1 + getStatMults().get(attr) * caster.getStat(attr); - } - if (caster != target && caster.getEntity() instanceof Player && target - .getEntity() instanceof Player) { - damage *= pvpMult; - } - damage = Math.max(0, - damage - target.getStat(StrifeStat.DAMAGE_REDUCTION) * damageReductionRatio * pvpMult); - LogUtil.printDebug(" [Pre-Damage] Target Health: " + target.getEntity().getHealth()); - - target.trackDamage(caster, damage); - StrifePlugin.getInstance().getDamageManager().dealDamage(caster, target, damage, true); - LogUtil.printDebug(" [Post-Damage] Target Health: " + target.getEntity().getHealth()); - } - - public void setDamageReductionRatio(float damageReductionRatio) { - this.damageReductionRatio = damageReductionRatio; - } - - public void setAttackType(AttackType attackType) { - this.attackType = attackType; - } - - public Map getAbilityMods() { - return abilityMods; - } - - public Set getDamages() { - return damages; - } - - public void setCanBeEvaded(boolean canBeEvaded) { - this.canBeEvaded = canBeEvaded; - } - - public void setCanBeBlocked(boolean canBeBlocked) { - this.canBeBlocked = canBeBlocked; - } -} \ No newline at end of file diff --git a/src/main/java/land/face/strife/data/effects/Effect.java b/src/main/java/land/face/strife/data/effects/Effect.java index 7eeffe95..2cbad9f0 100644 --- a/src/main/java/land/face/strife/data/effects/Effect.java +++ b/src/main/java/land/face/strife/data/effects/Effect.java @@ -63,7 +63,6 @@ public Set getConditions() { } public enum EffectType { - STANDARD_DAMAGE, DAMAGE, WORLD_SPACE_ENTITY, CHASER, @@ -89,6 +88,7 @@ public enum EffectType { BLEED, TELEPORT, TELEPORT_BEHIND, + TITLE, CORRUPT, ADD_EARTH_RUNES, CONSUME_BLEED, diff --git a/src/main/java/land/face/strife/data/effects/Heal.java b/src/main/java/land/face/strife/data/effects/Heal.java index ea41a3e0..65438d4a 100644 --- a/src/main/java/land/face/strife/data/effects/Heal.java +++ b/src/main/java/land/face/strife/data/effects/Heal.java @@ -4,7 +4,7 @@ import java.text.DecimalFormat; import land.face.strife.StrifePlugin; -import land.face.strife.data.DamageContainer; +import land.face.strife.data.BonusDamage; import land.face.strife.data.StrifeMob; import land.face.strife.stats.StrifeStat; import land.face.strife.util.DamageUtil; @@ -27,8 +27,8 @@ public void apply(StrifeMob caster, StrifeMob target) { heal += getStatMults().get(attr) * caster.getStat(attr); } - DamageContainer container = new DamageContainer(damageScale, null, null, heal); - heal = DamageUtil.applyDamageScale(caster, target, container, null); + BonusDamage container = new BonusDamage(damageScale, null, null, heal); + heal = DamageUtil.applyDamageScale(caster, target, container); heal += flatBonus; if (useHealingPower) { diff --git a/src/main/java/land/face/strife/data/effects/Ignite.java b/src/main/java/land/face/strife/data/effects/Ignite.java index d23b4f72..16817b9b 100644 --- a/src/main/java/land/face/strife/data/effects/Ignite.java +++ b/src/main/java/land/face/strife/data/effects/Ignite.java @@ -1,5 +1,6 @@ package land.face.strife.data.effects; +import land.face.strife.StrifePlugin; import land.face.strife.data.StrifeMob; public class Ignite extends Effect { @@ -14,6 +15,7 @@ public void apply(StrifeMob caster, StrifeMob target) { } else { target.getEntity().setFireTicks(Math.max(duration, target.getEntity().getFireTicks())); } + StrifePlugin.getInstance().getDamageOverTimeTask().trackBurning(target.getEntity()); } public void setForceDuration(boolean forceDuration) { diff --git a/src/main/java/land/face/strife/data/effects/LocationEffect.java b/src/main/java/land/face/strife/data/effects/LocationEffect.java index 6bc91fe1..4efd22cf 100644 --- a/src/main/java/land/face/strife/data/effects/LocationEffect.java +++ b/src/main/java/land/face/strife/data/effects/LocationEffect.java @@ -1,11 +1,22 @@ package land.face.strife.data.effects; import land.face.strife.data.StrifeMob; +import land.face.strife.util.DamageUtil.OriginLocation; import org.bukkit.Location; public abstract class LocationEffect extends Effect { + private OriginLocation origin = OriginLocation.CENTER; + public void applyAtLocation(StrifeMob caster, Location location) { } + + public OriginLocation getOrigin() { + return origin; + } + + public void setOrigin(OriginLocation origin) { + this.origin = origin; + } } diff --git a/src/main/java/land/face/strife/data/effects/PotionEffectAction.java b/src/main/java/land/face/strife/data/effects/PotionEffectAction.java index 434dea57..197f6867 100644 --- a/src/main/java/land/face/strife/data/effects/PotionEffectAction.java +++ b/src/main/java/land/face/strife/data/effects/PotionEffectAction.java @@ -25,8 +25,7 @@ public void apply(StrifeMob caster, StrifeMob target) { bumpPotionEffect(target.getEntity(), duration); return; } - target.getEntity() - .addPotionEffect(new PotionEffect(potionEffectType, (int) duration, intensity)); + target.getEntity().addPotionEffect(new PotionEffect(potionEffectType, (int) duration, intensity)); } private void bumpPotionEffect(LivingEntity target, double duration) { diff --git a/src/main/java/land/face/strife/data/effects/ShootBlock.java b/src/main/java/land/face/strife/data/effects/ShootBlock.java index e9d14cf5..ecaf4618 100644 --- a/src/main/java/land/face/strife/data/effects/ShootBlock.java +++ b/src/main/java/land/face/strife/data/effects/ShootBlock.java @@ -6,7 +6,6 @@ import java.util.Set; import land.face.strife.data.StrifeMob; import land.face.strife.timers.FallingBlockTimer; -import land.face.strife.util.DamageUtil.OriginLocation; import land.face.strife.util.SpecialStatusUtil; import land.face.strife.util.TargetingUtil; import org.bukkit.Location; @@ -17,7 +16,6 @@ public class ShootBlock extends LocationEffect { private BlockData blockData; - private OriginLocation originType; private int quantity; private double speed; private double spread; @@ -29,7 +27,7 @@ public class ShootBlock extends LocationEffect { @Override public void apply(StrifeMob caster, StrifeMob target) { - Location originLocation = TargetingUtil.getOriginLocation(target.getEntity(), originType); + Location originLocation = TargetingUtil.getOriginLocation(target.getEntity(), getOrigin()); applyAtLocation(caster, originLocation); } @@ -91,10 +89,6 @@ public void setZeroPitch(boolean zeroPitch) { this.zeroPitch = zeroPitch; } - public void setOriginType(OriginLocation originType) { - this.originType = originType; - } - private void applySpread(Vector direction, double spread) { direction.add(new Vector( spread - 2 * spread * Math.random(), diff --git a/src/main/java/land/face/strife/data/effects/StrifeParticle.java b/src/main/java/land/face/strife/data/effects/StrifeParticle.java index ceefcfb3..f449793b 100644 --- a/src/main/java/land/face/strife/data/effects/StrifeParticle.java +++ b/src/main/java/land/face/strife/data/effects/StrifeParticle.java @@ -5,7 +5,6 @@ import land.face.strife.data.StrifeMob; import land.face.strife.stats.StrifeStat; import land.face.strife.tasks.ParticleTask; -import land.face.strife.util.DamageUtil.OriginLocation; import land.face.strife.util.TargetingUtil; import org.bukkit.Location; import org.bukkit.Material; @@ -42,7 +41,6 @@ public class StrifeParticle extends LocationEffect { private int tickDuration; private boolean strictDuration; - private OriginLocation particleOriginLocation = OriginLocation.CENTER; private ItemStack blockData = null; private static Random random = new Random(); @@ -113,14 +111,6 @@ public void setSpread(float spread) { this.spread = spread; } - public OriginLocation getParticleOriginLocation() { - return particleOriginLocation; - } - - public void setParticleOriginLocation(OriginLocation particleOriginLocation) { - this.particleOriginLocation = particleOriginLocation; - } - public void setStyle(ParticleStyle style) { this.style = style; } @@ -190,7 +180,7 @@ public void setStrictDuration(boolean strictDuration) { } public Location getLoc(LivingEntity le) { - return TargetingUtil.getOriginLocation(le, particleOriginLocation); + return TargetingUtil.getOriginLocation(le, getOrigin()); } public void setBlockData(ItemStack blockData) { diff --git a/src/main/java/land/face/strife/data/effects/Summon.java b/src/main/java/land/face/strife/data/effects/Summon.java index b6e6a586..b5e31c1f 100644 --- a/src/main/java/land/face/strife/data/effects/Summon.java +++ b/src/main/java/land/face/strife/data/effects/Summon.java @@ -30,21 +30,22 @@ public void applyAtLocation(StrifeMob caster, Location location) { if (caster.getMinions().size() >= caster.getStat(StrifeStat.MAX_MINIONS)) { return; } + StrifeMob summonedEntity = StrifePlugin.getInstance().getUniqueEntityManager() .spawnUnique(uniqueEntity, location); + if (summonedEntity == null || summonedEntity.getEntity() == null) { return; } + LivingEntity summon = summonedEntity.getEntity(); - summon.setMaxHealth(summon.getMaxHealth() * (1 + (caster.getStat(StrifeStat.MINION_LIFE) / 100))); - summon.setHealth(summon.getMaxHealth()); caster.addMinion(summonedEntity); StrifePlugin.getInstance().getMinionManager() .addMinion(summon, (int) ((lifespanSeconds * 20D) / 11D)); if (caster.getEntity() instanceof Mob && summon instanceof Mob) { - ((Mob)summon).setTarget(((Mob) caster.getEntity()).getTarget()); + ((Mob) summon).setTarget(((Mob) caster.getEntity()).getTarget()); } if (summon instanceof Tameable && caster.getEntity() instanceof Player) { @@ -52,13 +53,16 @@ public void applyAtLocation(StrifeMob caster, Location location) { } if (soundEffect != null) { - PlaySound sound = (PlaySound) StrifePlugin.getInstance().getEffectManager().getEffect(soundEffect); + PlaySound sound = (PlaySound) StrifePlugin.getInstance().getEffectManager() + .getEffect(soundEffect); sound.applyAtLocation(caster, summon.getLocation()); } if (mount) { summon.addPassenger(caster.getEntity()); } + double maxHealth = summon.getMaxHealth() * (1 + (caster.getStat(StrifeStat.MINION_LIFE) / 100)); + summon.setHealth(maxHealth); } public void setUniqueEntity(String uniqueEntity) { diff --git a/src/main/java/land/face/strife/data/effects/TargetingComparators/AbilityComparator.java b/src/main/java/land/face/strife/data/effects/TargetingComparators/AbilityComparator.java new file mode 100644 index 00000000..37a7bf19 --- /dev/null +++ b/src/main/java/land/face/strife/data/effects/TargetingComparators/AbilityComparator.java @@ -0,0 +1,27 @@ +package land.face.strife.data.effects.TargetingComparators; + +import java.util.Comparator; +import land.face.strife.data.ability.Ability; + +public class AbilityComparator implements Comparator { + + public int compare(Ability a1, Ability a2) { + int req1 = 0; + if (a1.getAbilityIconData() != null) { + for (int val : a1.getAbilityIconData().getLifeSkillRequirements().values()) { + if (val > req1) { + req1 = val; + } + } + } + int req2 = 0; + if (a2.getAbilityIconData() != null) { + for (int val : a2.getAbilityIconData().getLifeSkillRequirements().values()) { + if (val > req2) { + req2 = val; + } + } + } + return Integer.compare(req1, req2); + } +} diff --git a/src/main/java/land/face/strife/data/effects/Teleport.java b/src/main/java/land/face/strife/data/effects/Teleport.java index b4b6b770..c56ab5a9 100644 --- a/src/main/java/land/face/strife/data/effects/Teleport.java +++ b/src/main/java/land/face/strife/data/effects/Teleport.java @@ -1,5 +1,8 @@ package land.face.strife.data.effects; +import java.util.ArrayList; +import java.util.List; +import land.face.strife.StrifePlugin; import land.face.strife.data.StrifeMob; import org.bukkit.Location; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -10,25 +13,29 @@ public class Teleport extends Effect { private Vector vector; private boolean targeted; private boolean relative; + private List destinationEffects = new ArrayList<>(); + private List originEffects = new ArrayList<>(); @Override public void apply(StrifeMob caster, StrifeMob target) { + StrifePlugin.getInstance().getEffectManager().execute(caster, caster.getEntity(), originEffects); + target.getEntity().setVelocity(new Vector(0, 0, 0)); if (targeted) { Location location = target.getEntity().getLocation().clone(); location.setDirection(caster.getEntity().getLocation().getDirection()); caster.getEntity().teleport(location, TeleportCause.PLUGIN); - return; - } - if (relative) { + } else if (relative) { Location location = target.getEntity().getLocation().clone(); location.add(vector); caster.getEntity().teleport(location, TeleportCause.PLUGIN); return; + } else { + Location location = new Location(caster.getEntity().getWorld(), + vector.getX(), vector.getY(), vector.getZ()); + location.setDirection(target.getEntity().getLocation().getDirection()); + target.getEntity().teleport(location, TeleportCause.PLUGIN); } - Location location = new Location(caster.getEntity().getWorld(), vector.getX(), vector.getY(), - vector.getZ()); - location.setDirection(target.getEntity().getLocation().getDirection()); - target.getEntity().teleport(location, TeleportCause.PLUGIN); + StrifePlugin.getInstance().getEffectManager().execute(caster, caster.getEntity(), destinationEffects); } public void setVector(Vector vector) { @@ -42,4 +49,13 @@ public void setTargeted(boolean targeted) { public void setRelative(boolean relative) { this.relative = relative; } + + public List getDestinationEffects() { + return destinationEffects; + } + + public List getOriginEffects() { + return originEffects; + } + } diff --git a/src/main/java/land/face/strife/data/effects/Title.java b/src/main/java/land/face/strife/data/effects/Title.java new file mode 100644 index 00000000..09bd203c --- /dev/null +++ b/src/main/java/land/face/strife/data/effects/Title.java @@ -0,0 +1,35 @@ +package land.face.strife.data.effects; + +import com.tealcube.minecraft.bukkit.TextUtils; +import com.tealcube.minecraft.bukkit.facecore.utilities.TitleUtils; +import land.face.strife.data.StrifeMob; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + +public class Title extends Effect { + + private String topTitle; + private String lowerTitle; + private double range; + + @Override + public void apply(StrifeMob caster, StrifeMob target) { + for (Entity e : caster.getEntity().getNearbyEntities(range, range, range)) { + if (e instanceof Player) { + TitleUtils.sendTitle((Player) e, topTitle, lowerTitle); + } + } + } + + public void setTopTitle(String topTitle) { + this.topTitle = TextUtils.color(topTitle); + } + + public void setLowerTitle(String lowerTitle) { + this.lowerTitle = TextUtils.color(lowerTitle); + } + + public void setRange(double range) { + this.range = range; + } +} diff --git a/src/main/java/land/face/strife/events/UniqueSpawnEvent.java b/src/main/java/land/face/strife/events/UniqueSpawnEvent.java new file mode 100644 index 00000000..afae9a23 --- /dev/null +++ b/src/main/java/land/face/strife/events/UniqueSpawnEvent.java @@ -0,0 +1,32 @@ +package land.face.strife.events; + +import land.face.strife.data.StrifeMob; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +public class UniqueSpawnEvent extends Event { + + private static final HandlerList HANDLER_LIST = new HandlerList(); + + public static HandlerList getHandlerList() { + return HANDLER_LIST; + } + + private final StrifeMob strifeMob; + + public UniqueSpawnEvent(StrifeMob strifeMob) { + this.strifeMob = strifeMob; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return HANDLER_LIST; + } + + public StrifeMob getStrifeMob() { + return strifeMob; + } + +} diff --git a/src/main/java/land/face/strife/listeners/CombatListener.java b/src/main/java/land/face/strife/listeners/CombatListener.java index 2ebc69f1..0a3689ad 100644 --- a/src/main/java/land/face/strife/listeners/CombatListener.java +++ b/src/main/java/land/face/strife/listeners/CombatListener.java @@ -31,6 +31,7 @@ import land.face.strife.StrifePlugin; import land.face.strife.data.DamageModifiers; import land.face.strife.data.StrifeMob; +import land.face.strife.data.ability.EntityAbilitySet.TriggerAbilityType; import land.face.strife.events.StrifeDamageEvent; import land.face.strife.stats.StrifeStat; import land.face.strife.util.DamageUtil; @@ -107,7 +108,8 @@ public void handleFireworks(EntityDamageByEntityEvent event) { @EventHandler(priority = EventPriority.LOWEST) public void handleNpcHits(EntityDamageByEntityEvent event) { if (event.getDamager() instanceof Projectile) { - if (event.getEntity().hasMetadata("NPC")) { + if (event.getEntity().isInvulnerable() || event.getEntity().hasMetadata("NPC") || event + .getEntity().hasMetadata("pet")) { event.getDamager().remove(); event.setCancelled(true); } @@ -116,7 +118,7 @@ public void handleNpcHits(EntityDamageByEntityEvent event) { @EventHandler(priority = EventPriority.HIGHEST) public void strifeDamageHandler(EntityDamageByEntityEvent event) { - if (event.isCancelled() || event.getCause() == DamageCause.CUSTOM) { + if (event.isCancelled() || event.getEntity().isInvulnerable()) { return; } if (plugin.getDamageManager().isHandledDamage(event.getDamager())) { @@ -124,6 +126,9 @@ public void strifeDamageHandler(EntityDamageByEntityEvent event) { event.setDamage(BASE, plugin.getDamageManager().getHandledDamage(event.getDamager())); return; } + if (event.getCause() == DamageCause.CUSTOM) { + return; + } if (!(event.getEntity() instanceof LivingEntity) || event.getEntity() instanceof ArmorStand) { return; } @@ -204,7 +209,7 @@ public void strifeDamageHandler(EntityDamageByEntityEvent event) { } attackMultiplier = plugin.getAttackSpeedManager().getAttackMultiplier(attacker); attackMultiplier = (float) Math.pow(attackMultiplier, 1.25); - } else if (attackType == AttackType.EXPLOSION) { + } else if (attackType == AttackType.AREA) { double distance = event.getDamager().getLocation().distance(event.getEntity().getLocation()); attackMultiplier *= Math.max(0.3, 4 / (distance + 3)); healMultiplier = 0.3f; @@ -227,6 +232,13 @@ public void strifeDamageHandler(EntityDamageByEntityEvent event) { putSlimeHit(attackEntity); + boolean mobAbility = plugin.getAbilityManager().abilityCast(attacker, defender, TriggerAbilityType.ON_HIT); + + if (mobAbility) { + event.setCancelled(true); + return; + } + if (attackEntity instanceof Player) { plugin.getStealthManager().unstealthPlayer((Player) attackEntity); } @@ -238,11 +250,14 @@ public void strifeDamageHandler(EntityDamageByEntityEvent event) { damageModifiers.setAttackType(attackType); damageModifiers.setAttackMultiplier(attackMultiplier); damageModifiers.setHealMultiplier(healMultiplier); + damageModifiers.setDamageReductionRatio(1f); + damageModifiers.setScaleChancesWithAttack(true); damageModifiers.setApplyOnHitEffects(applyOnHit); damageModifiers.setSneakAttack(isSneakAttack); damageModifiers.setBlocking(blocked); boolean attackSuccess = DamageUtil.preDamage(attacker, defender, damageModifiers); + if (!attackSuccess) { removeIfExisting(projectile); event.setCancelled(true); @@ -251,7 +266,9 @@ public void strifeDamageHandler(EntityDamageByEntityEvent event) { Map damage = DamageUtil.buildDamage(attacker, defender, damageModifiers); DamageUtil.reduceDamage(attacker, defender, damage, damageModifiers); - float finalDamage = DamageUtil.damage(attacker, defender, damage, damageModifiers); + + float finalDamage = DamageUtil + .calculateFinalDamage(attacker, defender, damage, damageModifiers); StrifeDamageEvent strifeDamageEvent = new StrifeDamageEvent(attacker, defender, damageModifiers); @@ -263,17 +280,25 @@ public void strifeDamageHandler(EntityDamageByEntityEvent event) { return; } - DamageUtil.postDamage(attacker, defender, damage, damageModifiers); + float eventDamage = Math.max(0.002f, plugin.getBarrierManager() + .damageBarrier(defender, (float) strifeDamageEvent.getFinalDamage())); + + if (damage.containsKey(DamageType.PHYSICAL)) { + DamageUtil.attemptBleed(attacker, defender, damage.get(DamageType.PHYSICAL), damageModifiers, + false); + } + DamageUtil.postDamage(attacker, defender, damageModifiers); DamageUtil.applyExtraEffects(attacker, defender, extraEffects); if (attackEntity instanceof Bee) { - plugin.getDamageManager().dealDamage(attacker, defender, finalDamage); + plugin.getDamageManager() + .dealDamage(attacker, defender, (float) strifeDamageEvent.getFinalDamage()); event.setCancelled(true); return; } - event.setDamage(BASE, finalDamage); + event.setDamage(BASE, eventDamage); } @EventHandler(priority = EventPriority.HIGHEST) diff --git a/src/main/java/land/face/strife/listeners/DOTListener.java b/src/main/java/land/face/strife/listeners/DOTListener.java index 6ced723c..98c92499 100644 --- a/src/main/java/land/face/strife/listeners/DOTListener.java +++ b/src/main/java/land/face/strife/listeners/DOTListener.java @@ -19,116 +19,66 @@ package land.face.strife.listeners; import land.face.strife.StrifePlugin; -import land.face.strife.data.StrifeMob; -import land.face.strife.stats.StrifeStat; import land.face.strife.util.DamageUtil; -import land.face.strife.util.StatUtil; -import org.bukkit.Sound; import org.bukkit.entity.LivingEntity; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; public class DOTListener implements Listener { private final StrifePlugin plugin; - private float WITHER_FLAT_DAMAGE; - private float POISON_FLAT_DAMAGE; - private float POISON_PERCENT_MAX_HEALTH_DAMAGE; - private float BURN_FLAT_DAMAGE; - private float BURN_PERCENT_MAX_HEALTH_DAMAGE; - public DOTListener(StrifePlugin plugin) { this.plugin = plugin; - WITHER_FLAT_DAMAGE = (float) plugin.getSettings() - .getDouble("config.mechanics.wither-flat-damage"); - POISON_FLAT_DAMAGE = (float) plugin.getSettings() - .getDouble("config.mechanics.poison-flat-damage"); - POISON_PERCENT_MAX_HEALTH_DAMAGE = (float) plugin.getSettings() - .getDouble("config.mechanics.poison-percent-damage"); - BURN_FLAT_DAMAGE = (float) plugin.getSettings() - .getDouble("config.mechanics.burn-flat-damage"); - BURN_PERCENT_MAX_HEALTH_DAMAGE = (float) plugin.getSettings() - .getDouble("config.mechanics.burn-percent-damage"); } @EventHandler(priority = EventPriority.MONITOR) public void onEntityDOTEvent(EntityDamageEvent event) { - if (!(event.getEntity() instanceof LivingEntity) || event.isCancelled()) { + if (event.isCancelled()) { return; } - LivingEntity entity = (LivingEntity) event.getEntity(); - float damage; - switch (event.getCause()) { - case ENTITY_ATTACK: - case MAGIC: - return; - case STARVATION: - // No longer needed with ENERGY - event.setCancelled(true); - return; - case SUFFOCATION: - case DROWNING: - DamageUtil.removeDamageModifiers(event); - event.setDamage(entity.getMaxHealth() / 10); - return; - case FIRE_TICK: - StrifeMob statEntity = plugin.getStrifeMobManager().getStatMob(entity); - damage = BURN_FLAT_DAMAGE + (float) entity.getHealth() * BURN_PERCENT_MAX_HEALTH_DAMAGE; - damage *= DamageUtil.getResistPotionMult(entity); - damage *= 1 - StatUtil.getFireResist(statEntity) / 100; - damage *= 1 - statEntity.getStat(StrifeStat.BURNING_RESIST) / 100; - if (damage < 0.05) { - event.setCancelled(true); - return; - } - damage = plugin.getBarrierManager().damageBarrier(statEntity, damage); - entity.getWorld().playSound(entity.getLocation(), Sound.ITEM_FIRECHARGE_USE, 0.8f, 0.5f); - dealDirectDamage(entity, damage); - event.setCancelled(true); - break; - case FIRE: - case LAVA: - StrifeMob statEntity2 = plugin.getStrifeMobManager().getStatMob(entity); - damage = BURN_FLAT_DAMAGE + (float) entity.getHealth() * BURN_PERCENT_MAX_HEALTH_DAMAGE; - damage *= DamageUtil.getResistPotionMult(entity); - damage *= 1 - StatUtil.getFireResist(statEntity2) / 100; - if (damage < 0.05) { - event.setCancelled(true); - return; - } - damage = plugin.getBarrierManager().damageBarrier(statEntity2, damage); - event.setDamage(damage); - return; - case WITHER: - StrifeMob statEntity3 = plugin.getStrifeMobManager().getStatMob(entity); - damage = WITHER_FLAT_DAMAGE; - damage *= DamageUtil.getResistPotionMult(entity); - damage *= 1 - statEntity3.getStat(StrifeStat.WITHER_RESIST) / 100; - if (damage < 0.05) { - return; - } - event.setCancelled(true); - dealDirectDamage(entity, Math.min(damage, entity.getHealth() - 1)); - entity.getWorld().playSound(entity.getLocation(), Sound.ENTITY_WITHER_SHOOT, 0.8f, 1.2f); - return; - case POISON: - StrifeMob statEntity4 = plugin.getStrifeMobManager().getStatMob(entity); - damage = POISON_FLAT_DAMAGE + (float) entity.getHealth() * POISON_PERCENT_MAX_HEALTH_DAMAGE; - damage *= DamageUtil.getResistPotionMult(entity); - damage *= 1 - statEntity4.getStat(StrifeStat.POISON_RESIST) / 100; - if (damage < 0.05) { - return; - } - event.setCancelled(true); - dealDirectDamage(entity, Math.min(damage, entity.getHealth() - 1)); - entity.getWorld().playSound(entity.getLocation(), Sound.ENTITY_SPIDER_STEP, 1.5f, 1f); + if (!(event.getEntity() instanceof LivingEntity)) { + return; + } + if (event.getCause() == DamageCause.STARVATION) { + event.setCancelled(true); + return; + } + LivingEntity le = (LivingEntity) event.getEntity(); + if (event.getCause() == DamageCause.LAVA || event.getCause() == DamageCause.FIRE) { + DamageUtil.removeDamageModifiers(event); + event.setDamage(0); + le.setFireTicks(Math.max(le.getFireTicks(), 40)); + plugin.getDamageOverTimeTask().trackBurning(le); + return; + } + if (event.getCause() == DamageCause.HOT_FLOOR) { + le.setFireTicks(40); + plugin.getDamageOverTimeTask().trackBurning(le); + event.setCancelled(true); + return; + } + if (event.getCause() == DamageCause.FIRE_TICK) { + plugin.getDamageOverTimeTask().trackBurning(le); + event.setCancelled(true); + return; + } + if (event.getCause() == DamageCause.POISON) { + plugin.getDamageOverTimeTask().trackPoison(le); + event.setCancelled(true); + return; + } + if (event.getCause() == DamageCause.WITHER) { + plugin.getDamageOverTimeTask().trackWither(le); + event.setCancelled(true); + return; + } + if (event.getCause() == DamageCause.SUFFOCATION || event.getCause() == DamageCause.DROWNING) { + DamageUtil.removeDamageModifiers(event); + event.setDamage(le.getMaxHealth() / 10); } - } - - private void dealDirectDamage(LivingEntity entity, double damage) { - entity.setHealth(Math.max(0, entity.getHealth() - damage)); } } diff --git a/src/main/java/land/face/strife/listeners/DataListener.java b/src/main/java/land/face/strife/listeners/DataListener.java index aa10b6e7..9fc4bd2d 100644 --- a/src/main/java/land/face/strife/listeners/DataListener.java +++ b/src/main/java/land/face/strife/listeners/DataListener.java @@ -72,7 +72,7 @@ public void onPlayerItemDamage(final PlayerItemDamageEvent event) { } } - @EventHandler(priority = EventPriority.HIGHEST) + @EventHandler(priority = EventPriority.HIGH) public void onEntityCombust(final EntityCombustEvent event) { if (event instanceof EntityCombustByEntityEvent) { return; @@ -171,7 +171,7 @@ public void onInteract(final PlayerInteractEntityEvent event) { .getRightClicked() instanceof ArmorStand) { return; } - if (!event.getRightClicked().isValid() || event.getRightClicked().hasMetadata("NPC")) { + if (!event.getRightClicked().isValid() || event.getRightClicked().hasMetadata("NPC") || event.getRightClicked().hasMetadata("pet")) { return; } final Player player = event.getPlayer(); diff --git a/src/main/java/land/face/strife/listeners/EntityMagicListener.java b/src/main/java/land/face/strife/listeners/EntityMagicListener.java index d817aa5f..6a8371fd 100644 --- a/src/main/java/land/face/strife/listeners/EntityMagicListener.java +++ b/src/main/java/land/face/strife/listeners/EntityMagicListener.java @@ -3,7 +3,7 @@ import land.face.strife.StrifePlugin; import land.face.strife.data.LoadedChaser; import land.face.strife.data.StrifeMob; -import land.face.strife.data.effects.StandardDamage; +import land.face.strife.data.effects.Damage; import land.face.strife.data.effects.StrifeParticle; import land.face.strife.data.effects.StrifeParticle.ParticleStyle; import land.face.strife.util.DamageUtil.AttackType; @@ -35,7 +35,7 @@ public class EntityMagicListener implements Listener { private ItemStack skeletonWand; private StrifeParticle chaserParticle; - private StandardDamage witchSpell; + private Damage witchSpell; private static final String WITCH_SPELL_ID = "INTERNAL-WITCH-ATTACK"; @@ -114,15 +114,15 @@ private LoadedChaser buildLoadedChaser() { return loadedChaser; } - private StandardDamage buildStandardDamage() { - StandardDamage standardDamage = new StandardDamage(); - standardDamage.setAttackMultiplier(1.0f); - standardDamage.setHealMultiplier(1.0f); - standardDamage.setAttackType(AttackType.MAGIC); - standardDamage.setCanBeBlocked(true); - standardDamage.setCanBeEvaded(true); - standardDamage.setCanSneakAttack(false); - return standardDamage; + private Damage buildStandardDamage() { + Damage damage = new Damage(); + damage.setAttackMultiplier(1.0f); + damage.setHealMultiplier(1.0f); + damage.setAttackType(AttackType.PROJECTILE); + damage.setCanBeBlocked(true); + damage.setCanBeEvaded(true); + damage.setCanSneakAttack(false); + return damage; } private StrifeParticle buildChaserParticle() { @@ -132,7 +132,7 @@ private StrifeParticle buildChaserParticle() { particle.setRed(0.8); particle.setBlue(0.8); particle.setGreen(0.2); - particle.setParticleOriginLocation(OriginLocation.CENTER); + particle.setOrigin(OriginLocation.CENTER); particle.setStyle(ParticleStyle.NORMAL); particle.setQuantity(5); particle.setSpeed(0.05F); diff --git a/src/main/java/land/face/strife/listeners/ExperienceListener.java b/src/main/java/land/face/strife/listeners/ExperienceListener.java index 30f2633c..0d9554a6 100644 --- a/src/main/java/land/face/strife/listeners/ExperienceListener.java +++ b/src/main/java/land/face/strife/listeners/ExperienceListener.java @@ -103,11 +103,13 @@ public void onXpShare(EntityDeathEvent event) { int levelDiff = Math.max(Math.abs(mobLevel - highestPlayerLevel), Math.abs(mobLevel - lowestPlayerLevel)); + + float expMultiplier = 1f / killers.size() + ((killers.size() - 1) * 0.2f); + if (levelDiff > 7) { + expMultiplier *= Math.pow(0.98, Math.pow(levelDiff - 7, 2)); + } + for (Player player : killers) { - float expMultiplier = (1f / killers.size()) + ((killers.size() - 1) * 0.2f); - if (levelDiff > 7) { - expMultiplier *= Math.pow(0.98, Math.pow(levelDiff - 7, 2)); - } plugin.getExperienceManager().addExperience(player, (droppedXp * expMultiplier), false); } } @@ -124,9 +126,16 @@ public void onPlayerRespawn(PlayerRespawnEvent event) { if (penaltyFreeWorlds.contains(p.getWorld().getName())) { return; } + if (p.getKiller() != null) { + return; + } if (p.getLevel() >= 100) { return; } + if (p.getLevel() < 10) { + sendMessage(p, "&cYou lost &f0 XP &cfrom dying &a(No loss below level 10!)"); + return; + } PlayerInventory inv = p.getInventory(); double lostXP; if (hadSoulShard(inv)) { @@ -135,7 +144,7 @@ public void onPlayerRespawn(PlayerRespawnEvent event) { } else { double xpToLevel = plugin.getLevelingRate().get(p.getLevel()); lostXP = Math.min(xpToLevel * 0.025, p.getExp() * xpToLevel); - sendMessage(p, "You lost " + (int) lostXP + " XP!"); + sendMessage(p, "&cAlas! You lost &f" + (int) lostXP + " XP &cfrom dying!"); p.setExp(Math.max(p.getExp() - 0.025f, 0.00001f)); } plugin.getSoulManager().setLostExp(p, lostXP); diff --git a/src/main/java/land/face/strife/listeners/FallListener.java b/src/main/java/land/face/strife/listeners/FallListener.java index 9c4c6f1d..f18df238 100644 --- a/src/main/java/land/face/strife/listeners/FallListener.java +++ b/src/main/java/land/face/strife/listeners/FallListener.java @@ -58,7 +58,7 @@ public void onFallDamage(EntityDamageEvent event) { MessageUtils.sendActionBar((Player) event.getEntity(), TextUtils.color("&3&l- Roll -")); } else { damage *= 50.0 / (50 + champion.getEffectiveLifeSkillLevel(LifeSkillType.AGILITY, true)); - ((Player) event.getEntity()).addPotionEffect(new PotionEffect(SLOW, 100, 0, true)); + ((Player) event.getEntity()).addPotionEffect(new PotionEffect(SLOW, 100, 0, true), false); } if (((Player) event.getEntity()).hasPotionEffect(DAMAGE_RESISTANCE)) { diff --git a/src/main/java/land/face/strife/listeners/ShootListener.java b/src/main/java/land/face/strife/listeners/ShootListener.java index 16eb306b..099eba5d 100644 --- a/src/main/java/land/face/strife/listeners/ShootListener.java +++ b/src/main/java/land/face/strife/listeners/ShootListener.java @@ -25,10 +25,11 @@ import land.face.strife.data.ability.EntityAbilitySet.TriggerAbilityType; import land.face.strife.data.effects.AreaEffect; import land.face.strife.data.effects.AreaEffect.AreaType; +import land.face.strife.data.effects.AreaEffect.LineOfSight; import land.face.strife.data.effects.AreaEffect.TargetingPriority; +import land.face.strife.data.effects.Damage; import land.face.strife.data.effects.Effect; import land.face.strife.data.effects.LocationEffect; -import land.face.strife.data.effects.StandardDamage; import land.face.strife.data.effects.StrifeParticle; import land.face.strife.data.effects.StrifeParticle.ParticleStyle; import land.face.strife.stats.StrifeStat; @@ -59,7 +60,7 @@ public class ShootListener implements Listener { private StrifeParticle flintlockSmoke; private StrifeParticle flintlockFlare; private AreaEffect flintlockHitscan; - private StandardDamage flintlockDamage; + private Damage flintlockDamage; public ShootListener(StrifePlugin plugin) { this.plugin = plugin; @@ -116,9 +117,7 @@ public void onEntityShoot(ProjectileLaunchEvent event) { StrifeMob mob = plugin.getStrifeMobManager() .getStatMob((LivingEntity) event.getEntity().getShooter()); - if (mob.getAbilitySet() != null - && mob.getAbilitySet().getAbilities(TriggerAbilityType.SHOOT) != null) { - plugin.getAbilityManager().abilityCast(mob, TriggerAbilityType.SHOOT); + if (plugin.getAbilityManager().abilityCast(mob, TriggerAbilityType.SHOOT)) { event.setCancelled(true); return; } @@ -195,8 +194,8 @@ public void onGroundEffectProjectileHit(final ProjectileHitEvent event) { return; } String[] effects = effectString.split("~"); - Location loc = event.getEntity().getLocation().clone() - .add(event.getEntity().getLocation().getDirection().multiply(-0.25)); + Location loc = event.getEntity().getLocation().clone().add( + event.getEntity().getLocation().getDirection().multiply(-0.25)); for (String s : effects) { Effect effect = StrifePlugin.getInstance().getEffectManager().getEffect(s); if (effect instanceof LocationEffect) { @@ -234,7 +233,7 @@ private StrifeParticle buildFlintlockSmoke() { StrifeParticle particle = new StrifeParticle(); particle.setFriendly(true); particle.setParticle(Particle.CAMPFIRE_COSY_SMOKE); - particle.setParticleOriginLocation(OriginLocation.BELOW_HEAD); + particle.setOrigin(OriginLocation.BELOW_HEAD); particle.setStyle(ParticleStyle.LINE); particle.setSize(2); particle.setRadius(0); @@ -246,22 +245,22 @@ private StrifeParticle buildFlintlockSmoke() { return particle; } - private StandardDamage buildStandardDamage() { - StandardDamage standardDamage = new StandardDamage(); - standardDamage.setAttackMultiplier(1.0f); - standardDamage.setHealMultiplier(1.0f); - standardDamage.setAttackType(AttackType.RANGED); - standardDamage.setCanBeBlocked(true); - standardDamage.setCanBeEvaded(true); - standardDamage.setCanSneakAttack(true); - return standardDamage; + private Damage buildStandardDamage() { + Damage damage = new Damage(); + damage.setAttackMultiplier(1.0f); + damage.setHealMultiplier(1.0f); + damage.setAttackType(AttackType.PROJECTILE); + damage.setCanBeBlocked(true); + damage.setCanBeEvaded(true); + damage.setCanSneakAttack(true); + return damage; } private StrifeParticle buildFlintlockFlare() { StrifeParticle particle = new StrifeParticle(); particle.setFriendly(true); particle.setParticle(Particle.FLAME); - particle.setParticleOriginLocation(OriginLocation.BELOW_HEAD); + particle.setOrigin(OriginLocation.BELOW_HEAD); particle.setStyle(ParticleStyle.LINE); particle.setSize(1); particle.setRadius(0); @@ -279,7 +278,7 @@ private AreaEffect buildFlintlockHitscan() { hitscan.setPriority(TargetingPriority.CLOSEST); hitscan.setScaleTargetsWithMultishot(false); hitscan.setRange((float) plugin.getSettings().getDouble("config.flintlock.range", 16f)); - hitscan.setLineOfSight(true); + hitscan.setLineOfSight(LineOfSight.CASTER); hitscan.setMaxTargets(1); hitscan.setCanBeBlocked(false); hitscan.setCanBeEvaded(false); diff --git a/src/main/java/land/face/strife/listeners/SpawnListener.java b/src/main/java/land/face/strife/listeners/SpawnListener.java index 26e42b81..53f322c9 100644 --- a/src/main/java/land/face/strife/listeners/SpawnListener.java +++ b/src/main/java/land/face/strife/listeners/SpawnListener.java @@ -80,8 +80,8 @@ public SpawnListener(StrifePlugin plugin) { @EventHandler(priority = EventPriority.HIGHEST) public void onCreatureSpawnHighest(CreatureSpawnEvent event) { - if (event.isCancelled() || event.getEntity().hasMetadata("NPC") - || event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.BREEDING) { + if (event.isCancelled() || event.getEntity().hasMetadata("NPC") || + event.getEntity().hasMetadata("pet") || event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.BREEDING) { return; } if (StringUtils.isNotBlank(SpecialStatusUtil.getUniqueId(event.getEntity()))) { diff --git a/src/main/java/land/face/strife/listeners/TargetingListener.java b/src/main/java/land/face/strife/listeners/TargetingListener.java index 7fa7cb29..914b30c5 100644 --- a/src/main/java/land/face/strife/listeners/TargetingListener.java +++ b/src/main/java/land/face/strife/listeners/TargetingListener.java @@ -24,6 +24,7 @@ import java.util.Random; import land.face.strife.StrifePlugin; +import land.face.strife.data.StrifeMob; import land.face.strife.data.champion.Champion; import land.face.strife.data.champion.LifeSkillType; import land.face.strife.util.DamageUtil; @@ -39,6 +40,7 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityTargetEvent.TargetReason; import org.bukkit.event.entity.EntityTargetLivingEntityEvent; import org.bukkit.util.Vector; @@ -92,6 +94,20 @@ public void modifyAttackRange(EntityDamageByEntityEvent event) { TargetingUtil.expandMobRange(attacker, (Mob) event.getEntity()); } + @EventHandler(priority = EventPriority.LOWEST) + public void ignoreGuildAllies(EntityTargetLivingEntityEvent event) { + if (!(event.getEntity() instanceof LivingEntity) || !(event.getTarget() instanceof Player)) { + return; + } + StrifeMob mob = plugin.getStrifeMobManager().getStatMob((LivingEntity) event.getEntity()); + if (mob == null || mob.getAlliedGuild() == null) { + return; + } + if (DamageUtil.isGuildAlly(mob, (Player) event.getTarget())) { + event.setCancelled(true); + } + } + @EventHandler(priority = EventPriority.LOW) public void onIgnoreHighLevelPlayers(EntityTargetLivingEntityEvent event) { if (event.isCancelled()) { @@ -114,11 +130,26 @@ public void onIgnoreHighLevelPlayers(EntityTargetLivingEntityEvent event) { @EventHandler(priority = EventPriority.HIGHEST) public void onNormalTarget(EntityTargetLivingEntityEvent event) { - if (event.isCancelled() || !(event.getTarget() instanceof Player) || !(event - .getEntity() instanceof Mob) || event.getReason() != CLOSEST_PLAYER || SpecialStatusUtil - .isSneakImmune(event.getEntity())) { + if (event.isCancelled()) { return; } + if (!(event.getEntity() instanceof Mob)) { + return; + } + if (event.getReason() == TargetReason.TARGET_ATTACKED_NEARBY_ENTITY + || event.getReason() == TargetReason.FOLLOW_LEADER + || event.getReason() == TargetReason.PIG_ZOMBIE_TARGET + || event.getReason() == TargetReason.REINFORCEMENT_TARGET) { + if (SpecialStatusUtil.isWeakAggro(event.getEntity())) { + event.setCancelled(true); + return; + } + } + + if (event.getReason() != CLOSEST_PLAYER || SpecialStatusUtil.isSneakImmune(event.getEntity())) { + return; + } + Player player = (Player) event.getTarget(); if (!plugin.getStealthManager().isStealthed(player)) { return; diff --git a/src/main/java/land/face/strife/managers/AbilityManager.java b/src/main/java/land/face/strife/managers/AbilityManager.java index dc9a3815..de808a2f 100644 --- a/src/main/java/land/face/strife/managers/AbilityManager.java +++ b/src/main/java/land/face/strife/managers/AbilityManager.java @@ -2,10 +2,10 @@ import com.tealcube.minecraft.bukkit.TextUtils; import com.tealcube.minecraft.bukkit.facecore.utilities.MessageUtils; -import io.netty.util.internal.ConcurrentSet; import io.pixeloutlaw.minecraft.spigot.hilt.ItemStackExtensionsKt; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Random; @@ -165,7 +165,7 @@ public void unToggleAbility(StrifeMob mob, String abilityId) { public AbilityCooldownContainer getCooldownContainer(LivingEntity le, String abilityId) { if (coolingDownAbilities.get(le) == null) { - coolingDownAbilities.put(le, new ConcurrentSet<>()); + coolingDownAbilities.put(le, new HashSet<>()); return null; } for (AbilityCooldownContainer cont : coolingDownAbilities.get(le)) { @@ -191,7 +191,9 @@ public void tickAbilityCooldowns() { coolingDownAbilities.remove(le); continue; } - for (AbilityCooldownContainer container : coolingDownAbilities.get(le)) { + Iterator iterator = coolingDownAbilities.get(le).iterator(); + while (iterator.hasNext()) { + AbilityCooldownContainer container = (AbilityCooldownContainer) iterator.next(); Ability ability = getAbility(container.getAbilityId()); if (container.isToggledOn()) { plugin.getAbilityIconManager().updateIconProgress((Player) le, ability); @@ -199,7 +201,8 @@ public void tickAbilityCooldowns() { } if (System.currentTimeMillis() >= container.getEndTime()) { if (container.getSpentCharges() <= 1) { - coolingDownAbilities.get(le).remove(container); + iterator.remove(); + //coolingDownAbilities.get(le).remove(container); LogUtil.printDebug("Final cooldown for " + container.getAbilityId() + ", removing"); if (le instanceof Player) { plugin.getAbilityIconManager().updateIconProgress((Player) le, ability); @@ -232,7 +235,7 @@ public void savePlayerCooldowns(Player player) { } public void loadPlayerCooldowns(Player player) { - coolingDownAbilities.put(player, new ConcurrentSet<>()); + coolingDownAbilities.put(player, new HashSet<>()); if (!savedPlayerCooldowns.containsKey(player.getUniqueId())) { return; } @@ -342,8 +345,6 @@ public boolean abilityCast(StrifeMob caster, StrifeMob target, TriggerAbilityTyp .collect(Collectors.toList()); if (selectorList.isEmpty()) { - LogUtil.printDebug(PlayerDataUtil.getName(caster.getEntity()) + " failed to cast " + - phase + " type " + type); return false; } Ability ability = selectorList.get(random.nextInt(selectorList.size())); @@ -360,7 +361,7 @@ public void setGlobalCooldown(Player player, int ticks) { private void coolDownAbility(LivingEntity livingEntity, Ability ability) { if (!coolingDownAbilities.containsKey(livingEntity)) { - coolingDownAbilities.put(livingEntity, new ConcurrentSet<>()); + coolingDownAbilities.put(livingEntity, new HashSet<>()); } AbilityCooldownContainer container = getCooldownContainer(livingEntity, ability.getId()); if (container == null) { @@ -385,7 +386,7 @@ private boolean toggleAbility(StrifeMob caster, Set targets, Abili throw new IllegalStateException("Attempted to toggle a non toggle ability!"); } if (!coolingDownAbilities.containsKey(caster.getEntity())) { - coolingDownAbilities.put(caster.getEntity(), new ConcurrentSet<>()); + coolingDownAbilities.put(caster.getEntity(), new HashSet<>()); } AbilityCooldownContainer container = getCooldownContainer(caster.getEntity(), ability.getId()); if (container == null) { @@ -450,7 +451,7 @@ private Set getTargets(StrifeMob caster, LivingEntity target, Abil return targets; } LivingEntity newTarget = TargetingUtil - .selectFirstEntityInSight(caster.getEntity(), ability.getRange()); + .selectFirstEntityInSight(caster.getEntity(), ability.getRange(), ability.isFriendly()); if (newTarget != null) { targets.add(newTarget); } @@ -458,7 +459,7 @@ private Set getTargets(StrifeMob caster, LivingEntity target, Abil case TARGET_AREA: Location loc = TargetingUtil.getTargetLocation( caster.getEntity(), target, ability.getRange(), ability.isRaycastsTargetEntities()); - LivingEntity stando = TargetingUtil.getTempStand(loc, 0); + LivingEntity stando = TargetingUtil.getTempStand(loc, -1); if (stando != null) { targets.add(stando); } @@ -466,7 +467,7 @@ private Set getTargets(StrifeMob caster, LivingEntity target, Abil case TARGET_GROUND: Location loc2 = TargetingUtil.getTargetLocation( caster.getEntity(), target, ability.getRange(), ability.isRaycastsTargetEntities()); - LivingEntity stando2 = TargetingUtil.getTempStand(loc2, ability.getRange() + 3); + LivingEntity stando2 = TargetingUtil.getTempStand(loc2, ability.getRange() + 2); if (stando2 != null) { targets.add(stando2); } diff --git a/src/main/java/land/face/strife/managers/GlobalBoostManager.java b/src/main/java/land/face/strife/managers/BoostManager.java similarity index 57% rename from src/main/java/land/face/strife/managers/GlobalBoostManager.java rename to src/main/java/land/face/strife/managers/BoostManager.java index 5f441fec..00a332af 100644 --- a/src/main/java/land/face/strife/managers/GlobalBoostManager.java +++ b/src/main/java/land/face/strife/managers/BoostManager.java @@ -19,72 +19,83 @@ package land.face.strife.managers; import com.tealcube.minecraft.bukkit.TextUtils; +import com.tealcube.minecraft.bukkit.shade.google.gson.Gson; +import com.tealcube.minecraft.bukkit.shade.google.gson.JsonArray; +import com.tealcube.minecraft.bukkit.shade.google.gson.JsonElement; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; import java.time.DayOfWeek; import java.time.LocalDate; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import land.face.strife.data.GlobalStatBoost; +import java.util.concurrent.CopyOnWriteArrayList; +import land.face.strife.StrifePlugin; +import land.face.strife.data.Boost; import land.face.strife.data.LoadedStatBoost; import land.face.strife.stats.StrifeStat; import land.face.strife.util.LogUtil; import land.face.strife.util.StatUtil; import org.bukkit.Bukkit; import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.entity.Player; -public class GlobalBoostManager { +public class BoostManager { - private final Map scheduledBoosts = new HashMap<>(); + private StrifePlugin plugin; + + private final Map boostSchedule = new HashMap<>(); private final Map loadedBoosts = new HashMap<>(); - private final List runningBoosts = new ArrayList<>(); - public double getAttribute(StrifeStat attribute) { - double amount = 0; - for (GlobalStatBoost boost : runningBoosts) { - amount += boost.getAttribute(attribute); - } - return amount; + private final List boosts = new CopyOnWriteArrayList<>(); + + private Gson gson = new Gson(); + + public BoostManager(StrifePlugin plugin) { + this.plugin = plugin; } public Map getAttributes() { Map attrMap = new HashMap<>(); - for (GlobalStatBoost boost : runningBoosts) { - attrMap.putAll(StatUpdateManager.combineMaps(attrMap, boost.getAttributes())); + for (Boost boost : boosts) { + attrMap.putAll(StatUpdateManager.combineMaps(attrMap, boost.getStats())); } return attrMap; } - public boolean createStatBoost(String boostId, String creator, int duration) { - LoadedStatBoost loadedStatBoost = loadedBoosts.get(boostId); - if (loadedStatBoost == null) { + public boolean startBoost(String name, String boostId, int seconds) { + if (!loadedBoosts.containsKey(boostId)) { + LogUtil.printWarning("Invalid boostID Failed to start boost " + boostId + " for " + " name"); return false; } - for (GlobalStatBoost boost : runningBoosts) { - if (boost.getBoostId().equals(boostId)) { - return false; - } - } - GlobalStatBoost boost = new GlobalStatBoost(boostId, creator, loadedStatBoost.getStats(), - duration); - runningBoosts.add(boost); - announceBoost(loadedStatBoost.getAnnounceStart(), creator, duration); + LoadedStatBoost loadedStatBoost = loadedBoosts.get(boostId); + Boost boost = new Boost(); + boost.setBoostId(boostId); + boost.setBoosterName(name); + boost.setSecondsRemaining(seconds); + boost.setStats(new HashMap<>(loadedBoosts.get(boostId).getStats())); + boosts.add(boost); + announceBoost(loadedStatBoost.getAnnounceStart(), name, seconds); return true; } public void tickBoosts() { - for (GlobalStatBoost boost : runningBoosts) { + for (Boost boost : boosts) { LoadedStatBoost loadedStatBoost = loadedBoosts.get(boost.getBoostId()); - int minutesRemaining = boost.getMinutesRemaining(); - if (minutesRemaining == 0) { - announceBoost(loadedStatBoost.getAnnounceEnd(), boost.getCreator(), 0); - runningBoosts.remove(boost); + if (boost.getSecondsRemaining() <= 0) { + for (Player p : Bukkit.getOnlinePlayers()) { + plugin.getChampionManager().updateAll(plugin.getChampionManager().getChampion(p)); + } + announceBoost(loadedStatBoost.getAnnounceEnd(), boost.getBoosterName(), 0); + boosts.remove(boost); continue; } - if (minutesRemaining % loadedStatBoost.getAnnounceInterval() == 0) { - announceBoost(loadedStatBoost.getAnnounceRun(), boost.getCreator(), minutesRemaining); + boost.setSecondsRemaining(boost.getSecondsRemaining() - 1); + if (boost.getSecondsRemaining() % loadedStatBoost.getAnnounceInterval() == 0) { + announceBoost(loadedStatBoost.getAnnounceRun(), boost.getBoosterName(), + boost.getSecondsRemaining()); } - boost.setMinutesRemaining(minutesRemaining - 1); } } @@ -122,30 +133,62 @@ public void loadScheduledBoosts(ConfigurationSection cs) { continue; } String boostId = cs.getString(dayString); - scheduledBoosts.put(dayOfWeek, boostId); + boostSchedule.put(dayOfWeek, boostId); } } - public void startScheduledEvents() { + public void checkBoostSchedule() { LocalDate date = LocalDate.now(); DayOfWeek dow = date.getDayOfWeek(); - String boostId = scheduledBoosts.get(dow); + String boostId = boostSchedule.get(dow); if (boostId == null) { return; } - LoadedStatBoost loadedStatBoost = loadedBoosts.get(scheduledBoosts.get(dow)); + for (Boost b : boosts) { + if (b.getBoostId().equals(boostId)) { + b.setSecondsRemaining(901); + return; + } + } + LoadedStatBoost loadedStatBoost = loadedBoosts.get(boostSchedule.get(dow)); if (loadedStatBoost == null) { LogUtil.printWarning("OI! Invalid event for today?? What is... " + boostId + "??"); return; } - createStatBoost(boostId, loadedStatBoost.getCreator(), loadedStatBoost.getDuration()); + announceBoost(loadedStatBoost.getAnnounceStart(), "SERVER", loadedStatBoost.getDuration()); + startBoost("SERVER", boostId, 901); } - private void announceBoost(List announce, String creator, int minutesRemaining) { + private void announceBoost(List announce, String creator, int secondsRemaining) { + int minutes = secondsRemaining / 60; for (String line : announce) { Bukkit.broadcastMessage(line .replace("{name}", creator) - .replace("{duration}", String.valueOf(minutesRemaining))); + .replace("{seconds}", String.valueOf(secondsRemaining)) + .replace("{minutes}", String.valueOf(minutes))); + } + } + + public void saveBoosts() { + try (FileWriter writer = new FileWriter(plugin.getDataFolder() + "/boosts.json")) { + gson.toJson(boosts.toArray(), writer); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void loadBoosts() { + try (FileReader reader = new FileReader(plugin.getDataFolder() + "/boosts.json")) { + JsonArray array = gson.fromJson(reader, JsonArray.class); + for (JsonElement e : array) { + Boost boost = gson.fromJson(e, Boost.class); + if (boostSchedule.containsValue(boost.getBoostId())) { + continue; + } + boosts.add(boost); + } + } catch (IOException e) { + e.printStackTrace(); } } } diff --git a/src/main/java/land/face/strife/managers/BossBarManager.java b/src/main/java/land/face/strife/managers/BossBarManager.java index 2d2243c9..07bad061 100644 --- a/src/main/java/land/face/strife/managers/BossBarManager.java +++ b/src/main/java/land/face/strife/managers/BossBarManager.java @@ -35,6 +35,8 @@ import land.face.strife.stats.StrifeStat; import land.face.strife.util.PlayerDataUtil; import land.face.strife.util.StatUtil; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.text.WordUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.boss.BarColor; @@ -203,8 +205,11 @@ private String createBarTitle(StrifeMob barOwner) { if (barOwner.getEntity() instanceof Player) { name = (barOwner.getEntity().getName()) + ChatColor.GRAY + " Lv" + ((Player) barOwner.getEntity()).getLevel(); - } else { + } else if (StringUtils.isNotBlank(barOwner.getEntity().getCustomName())) { name = barOwner.getEntity().getCustomName(); + } else { + name = WordUtils.capitalizeFully( + barOwner.getEntity().getType().toString().replaceAll("_", " ")); } name += " "; if (barOwner.getStat(StrifeStat.BARRIER) > 0) { diff --git a/src/main/java/land/face/strife/managers/ChampionManager.java b/src/main/java/land/face/strife/managers/ChampionManager.java index 12ba2ce5..2c2961d2 100644 --- a/src/main/java/land/face/strife/managers/ChampionManager.java +++ b/src/main/java/land/face/strife/managers/ChampionManager.java @@ -278,7 +278,7 @@ public void updateAll(Champion champion) { private void pushChampionUpdate(Champion champion) { champion.recombineCache(); plugin.getStrifeMobManager().setEntityStats(champion.getPlayer(), StatUpdateManager - .combineMaps(champion.getCombinedCache(), plugin.getGlobalBoostManager().getAttributes())); + .combineMaps(champion.getCombinedCache(), plugin.getBoostManager().getAttributes())); } private Set getItemAbilities(EquipmentSlot slot, EntityEquipment equipment) { diff --git a/src/main/java/land/face/strife/managers/ChaserManager.java b/src/main/java/land/face/strife/managers/ChaserManager.java index 635e8c03..803d6a07 100644 --- a/src/main/java/land/face/strife/managers/ChaserManager.java +++ b/src/main/java/land/face/strife/managers/ChaserManager.java @@ -1,7 +1,8 @@ package land.face.strife.managers; -import io.netty.util.internal.ConcurrentSet; import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Set; import land.face.strife.StrifePlugin; @@ -26,7 +27,7 @@ public class ChaserManager { public ChaserManager(StrifePlugin plugin) { this.plugin = plugin; - this.chasers = new ConcurrentSet<>(); + this.chasers = new HashSet<>(); } public void createChaser(StrifeMob caster, String id, Vector velocity, Location spawnLocation, @@ -38,29 +39,37 @@ public void createChaser(StrifeMob caster, String id, Vector velocity, Location } public void tickChasers() { - for (ChaserEntity chaser : chasers) { + Iterator iterator = chasers.iterator(); + while (iterator.hasNext()) { + ChaserEntity chaser = (ChaserEntity) iterator.next(); if (chaser.getCurrentTick() > chaser.getLifespan()) { - chasers.remove(chaser); + iterator.remove(); + //chasers.remove(chaser); continue; } chaser.setCurrentTick(chaser.getCurrentTick() + 1); if (chaser.getTarget() == null || !chaser.getTarget().isValid() || !chaser.getLocation().getWorld().equals(chaser.getTarget().getWorld())) { - chasers.remove(chaser); + iterator.remove(); + //chasers.remove(chaser); continue; } LoadedChaser data = chaserData.get(chaser.getChaserId()); if (data.isRemoveAtSolids() && chaser.getLocation().getBlock().getType().isSolid()) { - chasers.remove(chaser); + iterator.remove(); + //chasers.remove(chaser); continue; } - executeChaserMovement(chaser, data); + boolean hitTarget = executeChaserMovement(chaser, data); + if (hitTarget) { + iterator.remove(); + } } } - private void executeChaserMovement(ChaserEntity chaser, LoadedChaser data) { + private boolean executeChaserMovement(ChaserEntity chaser, LoadedChaser data) { Location targetLocation = TargetingUtil .getOriginLocation(chaser.getTarget(), OriginLocation.CENTER); Vector change = targetLocation.toVector() @@ -79,10 +88,10 @@ private void executeChaserMovement(ChaserEntity chaser, LoadedChaser data) { for (Effect effect : data.getEffectList()) { plugin.getEffectManager().execute(effect, chaser.getCaster(), chaser.getTarget()); } - chasers.remove(chaser); - return; + return true; } chaser.setVelocity(velocity); + return false; } private boolean isChaserCloseEnough(ChaserEntity chaser, LoadedChaser data, Location targetLoc) { diff --git a/src/main/java/land/face/strife/managers/CounterManager.java b/src/main/java/land/face/strife/managers/CounterManager.java index 8dac8580..18db10f4 100644 --- a/src/main/java/land/face/strife/managers/CounterManager.java +++ b/src/main/java/land/face/strife/managers/CounterManager.java @@ -21,8 +21,10 @@ import static land.face.strife.util.DamageUtil.buildMissIndicator; import com.tealcube.minecraft.bukkit.facecore.utilities.MessageUtils; +import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.WeakHashMap; @@ -64,10 +66,11 @@ public boolean executeCounters(LivingEntity attacker, LivingEntity defender) { } boolean isCountered = false; Iterator it = counterMap.get(defender).iterator(); + List removeData = new ArrayList<>(); while (it.hasNext()) { CounterData data = it.next(); if (System.currentTimeMillis() > data.getEndTime()) { - counterMap.get(defender).remove(data); + removeData.add(data); continue; } isCountered = true; @@ -90,6 +93,7 @@ public boolean executeCounters(LivingEntity attacker, LivingEntity defender) { break; } } + counterMap.get(defender).removeAll(removeData); return isCountered; } } diff --git a/src/main/java/land/face/strife/managers/DamageManager.java b/src/main/java/land/face/strife/managers/DamageManager.java index b13a042e..ce8ae16f 100644 --- a/src/main/java/land/face/strife/managers/DamageManager.java +++ b/src/main/java/land/face/strife/managers/DamageManager.java @@ -52,26 +52,17 @@ public double getHandledDamage(Entity entity) { return handledDamages.getOrDefault(entity.getUniqueId(), 0D); } - public double dealDamage(StrifeMob attacker, StrifeMob defender, double damage) { - return dealDamage(attacker, defender, damage, false); - } - - public double dealDamage(StrifeMob attacker, StrifeMob defender, double damage, - boolean indicators) { - if (indicators && attacker.getEntity() instanceof Player) { - plugin.getIndicatorManager().addIndicator(attacker.getEntity(), defender.getEntity(), - buildHitIndicator((Player) attacker.getEntity()), - String.valueOf((int) Math.ceil(damage))); + public double dealDamage(StrifeMob attacker, StrifeMob defender, float damage) { + damage = Math.max(0.002f, plugin.getBarrierManager().damageBarrier(defender, damage)); + if (attacker == defender) { + defender.getEntity().setHealth(defender.getEntity().getHealth() - damage); + return damage; } - - damage = plugin.getBarrierManager().damageBarrier(defender, (float) damage); - damage = Math.min(damage, defender.getEntity().getHealth()); - int noDamageTicks = defender.getEntity().getNoDamageTicks(); Vector velocity = defender.getEntity().getVelocity(); defender.getEntity().setNoDamageTicks(0); - handledDamages.put(attacker.getEntity().getUniqueId(), damage); + handledDamages.put(attacker.getEntity().getUniqueId(), (double) damage); defender.getEntity().damage(damage, attacker.getEntity()); handledDamages.remove(attacker.getEntity().getUniqueId()); diff --git a/src/main/java/land/face/strife/managers/EffectManager.java b/src/main/java/land/face/strife/managers/EffectManager.java index e1368e96..00241cef 100644 --- a/src/main/java/land/face/strife/managers/EffectManager.java +++ b/src/main/java/land/face/strife/managers/EffectManager.java @@ -11,7 +11,7 @@ import java.util.Map; import java.util.Set; import land.face.strife.StrifePlugin; -import land.face.strife.data.DamageContainer; +import land.face.strife.data.BonusDamage; import land.face.strife.data.EquipmentItemData; import land.face.strife.data.LoadedChaser; import land.face.strife.data.StrifeMob; @@ -56,6 +56,7 @@ import land.face.strife.data.effects.AddEarthRunes; import land.face.strife.data.effects.AreaEffect; import land.face.strife.data.effects.AreaEffect.AreaType; +import land.face.strife.data.effects.AreaEffect.LineOfSight; import land.face.strife.data.effects.AreaEffect.TargetingPriority; import land.face.strife.data.effects.Bleed; import land.face.strife.data.effects.BuffEffect; @@ -70,7 +71,7 @@ import land.face.strife.data.effects.Corrupt; import land.face.strife.data.effects.Counter; import land.face.strife.data.effects.CreateWorldSpaceEntity; -import land.face.strife.data.effects.DirectDamage; +import land.face.strife.data.effects.Damage; import land.face.strife.data.effects.Effect; import land.face.strife.data.effects.Effect.EffectType; import land.face.strife.data.effects.EndlessEffect; @@ -96,7 +97,6 @@ import land.face.strife.data.effects.ShootProjectile; import land.face.strife.data.effects.Silence; import land.face.strife.data.effects.Speak; -import land.face.strife.data.effects.StandardDamage; import land.face.strife.data.effects.Stealth; import land.face.strife.data.effects.StrifeParticle; import land.face.strife.data.effects.StrifeParticle.ParticleStyle; @@ -104,6 +104,7 @@ import land.face.strife.data.effects.SwingArm; import land.face.strife.data.effects.Teleport; import land.face.strife.data.effects.TeleportBehind; +import land.face.strife.data.effects.Title; import land.face.strife.data.effects.Undisguise; import land.face.strife.data.effects.UntoggleAbility; import land.face.strife.data.effects.Wait; @@ -172,7 +173,8 @@ public void execute(StrifeMob caster, Set targets, List ef execute(caster, targets, taskEffects, waitTicks); } - private void execute(StrifeMob caster, Set targets, List effects, int delay) { + private void execute(StrifeMob caster, Set targets, List effects, + int delay) { if (delay == 0) { executeEffectList(caster, targets, effects); return; @@ -198,12 +200,21 @@ private void executeEffectList(StrifeMob caster, Set targets, } public void execute(Effect effect, StrifeMob caster, LivingEntity target) { - if (effect instanceof LocationEffect && TargetingUtil.isDetectionStand(target)) { - if (PlayerDataUtil.areConditionsMet(caster, caster, effect.getConditions())) { - ((LocationEffect) effect).applyAtLocation(caster, target.getLocation()); + if (effect instanceof LocationEffect) { + if (TargetingUtil.isDetectionStand(target)) { + if (PlayerDataUtil.areConditionsMet(caster, caster, effect.getConditions())) { + ((LocationEffect) effect).applyAtLocation(caster, TargetingUtil.getOriginLocation(target, + ((LocationEffect) effect).getOrigin())); + } + return; + } + } else { + StrifeMob targetMob = plugin.getStrifeMobManager().getStatMob(target); + if (effect.isFriendly() != TargetingUtil.isFriendly(caster, targetMob)) { return; } - } else if (effect.isForceTargetCaster()) { + } + if (effect.isForceTargetCaster()) { applyEffectIfConditionsMet(effect, caster, null); return; } @@ -268,55 +279,19 @@ public void loadEffect(String key, ConfigurationSection cs) { ((IncreaseRage) effect).setAmount((float) cs.getDouble("amount", 1)); break; case DAMAGE: - effect = new DirectDamage(); - try { - ConfigurationSection damages = cs.getConfigurationSection("damages"); - if (damages != null) { - for (String k : damages.getKeys(false)) { - ConfigurationSection damage = damages.getConfigurationSection(k); - DamageType damageType = DamageType.valueOf(damage.getString("damage-type")); - String scaleString = damage.getString("damage-scale", "FLAT"); - DamageScale scale = DamageScale.valueOf(scaleString); - float amount = (float) damage.getDouble("amount", 1); - String statString = damage.getString("stat", ""); - StrifeStat damageStat = - StringUtils.isBlank(statString) ? null : StrifeStat.valueOf(statString); - DamageContainer container = new DamageContainer(scale, damageType, - damageStat, amount); - ((DirectDamage) effect).getDamages().add(container); - } - } - ((DirectDamage) effect).setAttackType( - AttackType.valueOf(cs.getString("attack-type", "OTHER"))); - ((DirectDamage) effect).setDamageReductionRatio( - (float) cs.getDouble("damage-reduction-ratio", 0.35)); - ((DirectDamage) effect).setCanBeBlocked(cs.getBoolean("can-be-blocked", false)); - ((DirectDamage) effect).setCanBeEvaded(cs.getBoolean("can-be-evaded", false)); - - ConfigurationSection damageMod = cs.getConfigurationSection("attack-mods"); - Map damageModMap = new HashMap<>(); - if (damageMod != null) { - for (String k : damageMod.getKeys(false)) { - AbilityMod mod = AbilityMod.valueOf(k); - damageModMap.put(mod, (float) damageMod.getDouble(k)); - } - } - ((DirectDamage) effect).getAbilityMods().putAll(damageModMap); - } catch (Exception e) { - LogUtil.printError("Skipping effect " + key + " for invalid damage config!"); - return; - } - break; - case STANDARD_DAMAGE: - effect = new StandardDamage(); - ((StandardDamage) effect) - .setAttackMultiplier((float) cs.getDouble("attack-multiplier", 1D)); - ((StandardDamage) effect) - .setHealMultiplier((float) cs.getDouble("heal-multiplier", 0.3D)); - ((StandardDamage) effect).setCanBeBlocked(cs.getBoolean("can-be-blocked", true)); - ((StandardDamage) effect).setCanBeEvaded(cs.getBoolean("can-be-evaded", true)); - ((StandardDamage) effect).setCanSneakAttack(cs.getBoolean("can-sneak-attack", false)); - ((StandardDamage) effect).setAttackType(AttackType.valueOf(cs.getString("attack-type"))); + effect = new Damage(); + float attackMult = (float) cs.getDouble("attack-multiplier", 1D); + ((Damage) effect).setAttackMultiplier(attackMult); + ((Damage) effect).setHealMultiplier( + (float) cs.getDouble("heal-multiplier", 0.3D)); + ((Damage) effect).setDamageReductionRatio( + (float) cs.getDouble("damage-reduction-ratio", 1D)); + ((Damage) effect).setCanBeBlocked(cs.getBoolean("can-be-blocked", true)); + ((Damage) effect).setCanBeEvaded(cs.getBoolean("can-be-evaded", true)); + ((Damage) effect).setCanSneakAttack(cs.getBoolean("can-sneak-attack", false)); + ((Damage) effect) + .setApplyOnHitEffects(cs.getBoolean("apply-on-hit-effects", attackMult > 0.75)); + ((Damage) effect).setAttackType(AttackType.valueOf(cs.getString("attack-type", "OTHER"))); ConfigurationSection multCs = cs.getConfigurationSection("damage-multipliers"); Map multMap = new HashMap<>(); if (multCs != null) { @@ -325,14 +300,8 @@ public void loadEffect(String key, ConfigurationSection cs) { multMap.put(mod, (float) multCs.getDouble(k)); } } - ConfigurationSection flatCs = cs.getConfigurationSection("flat-damage-bonuses"); - Map flatMap = new HashMap<>(); - if (flatCs != null) { - for (String k : flatCs.getKeys(false)) { - DamageType mod = DamageType.valueOf(k); - flatMap.put(mod, (float) flatCs.getDouble(k)); - } - } + List bonusDamages = loadBonusDamages(key, + cs.getConfigurationSection("bonus-damages")); ConfigurationSection modsCs = cs.getConfigurationSection("attack-mods"); Map attackModMap = new HashMap<>(); if (modsCs != null) { @@ -341,9 +310,9 @@ public void loadEffect(String key, ConfigurationSection cs) { attackModMap.put(mod, (float) modsCs.getDouble(k)); } } - ((StandardDamage) effect).getDamageModifiers().putAll(multMap); - ((StandardDamage) effect).getDamageBonuses().putAll(flatMap); - ((StandardDamage) effect).getAbilityMods().putAll(attackModMap); + ((Damage) effect).getDamageMultipliers().putAll(multMap); + ((Damage) effect).getBonusDamages().addAll(bonusDamages); + ((Damage) effect).getAbilityMods().putAll(attackModMap); break; case WORLD_SPACE_ENTITY: effect = new CreateWorldSpaceEntity(); @@ -406,7 +375,8 @@ public void loadEffect(String key, ConfigurationSection cs) { ((AreaEffect) effect).setMaxTargets(cs.getInt("max-targets", -1)); ((AreaEffect) effect) .setScaleTargetsWithMultishot(cs.getBoolean("scale-targets-with-multishot", false)); - ((AreaEffect) effect).setLineOfSight(cs.getBoolean("line-of-sight", true)); + ((AreaEffect) effect).setLineOfSight( + LineOfSight.valueOf(cs.getString("line-of-sight", "CASTER"))); ((AreaEffect) effect).setAreaType(AreaType.valueOf(cs.getString("area-type", "RADIUS"))); boolean canBeBlocked = cs.getBoolean("can-be-blocked", false); ((AreaEffect) effect).setCanBeBlocked(canBeBlocked); @@ -548,7 +518,6 @@ public void loadEffect(String key, ConfigurationSection cs) { return; } ((ShootBlock) effect).setBlockData(Bukkit.getServer().createBlockData(material)); - ((ShootBlock) effect).setOriginType(OriginLocation.valueOf(cs.getString("origin", "HEAD"))); ((ShootBlock) effect).setVerticalBonus(cs.getDouble("vertical-bonus", 0)); ((ShootBlock) effect).setSpread(cs.getDouble("spread", 0)); ((ShootBlock) effect).setSpeed(cs.getDouble("speed", 1)); @@ -588,10 +557,41 @@ public void loadEffect(String key, ConfigurationSection cs) { double z = cs.getDouble("z", 0); ((Teleport) effect).setVector(new Vector(x, y, z)); ((Teleport) effect).setRelative(cs.getBoolean("relative", false)); + Teleport tpEffect = (Teleport) effect; + List destEffects = cs.getStringList("destination-effects"); + Bukkit.getScheduler().runTaskLater(StrifePlugin.getInstance(), () -> { + for (String s : destEffects) { + Effect e = getEffect(s); + if (!(e instanceof LocationEffect)) { + LogUtil.printWarning("Failed to attach effect " + e.getId() + " to " + key); + LogUtil.printWarning("Teleport bonus effects can only be location based!"); + continue; + } + tpEffect.getDestinationEffects().add(e); + } + }, 5L); + List originEffects = cs.getStringList("origin-effects"); + Bukkit.getScheduler().runTaskLater(StrifePlugin.getInstance(), () -> { + for (String s : originEffects) { + Effect e = getEffect(s); + if (!(e instanceof LocationEffect)) { + LogUtil.printWarning("Failed to attach effect " + e.getId() + " to " + key); + LogUtil.printWarning("Teleport bonus effects can only be location based!"); + continue; + } + tpEffect.getOriginEffects().add(e); + } + }, 5L); break; case TELEPORT_BEHIND: effect = new TeleportBehind(); break; + case TITLE: + effect = new Title(); + ((Title) effect).setTopTitle(cs.getString("upper", "")); + ((Title) effect).setLowerTitle(cs.getString("lower", "")); + ((Title) effect).setRange(cs.getDouble("range", 8)); + break; case CONSUME_BLEED: effect = new ConsumeBleed(); ((ConsumeBleed) effect).setDamageRatio(cs.getDouble("damage-ratio", 1)); @@ -756,7 +756,7 @@ public void loadEffect(String key, ConfigurationSection cs) { ((StrifeParticle) effect).setStrictDuration(cs.getBoolean("strict-duration", false)); ((StrifeParticle) effect).setSpeed((float) cs.getDouble("speed", 0)); ((StrifeParticle) effect).setSpread((float) cs.getDouble("spread", 1)); - ((StrifeParticle) effect).setParticleOriginLocation( + ((StrifeParticle) effect).setOrigin( OriginLocation.valueOf(cs.getString("origin", "HEAD"))); ((StrifeParticle) effect).setSize(cs.getDouble("size", 1)); String materialType = cs.getString("material", ""); @@ -765,6 +765,9 @@ public void loadEffect(String key, ConfigurationSection cs) { } break; } + if (effect instanceof LocationEffect) { + ((LocationEffect) effect).setOrigin(OriginLocation.valueOf(cs.getString("origin", "HEAD"))); + } if (effectType != Effect.EffectType.WAIT) { effect.setForceTargetCaster(cs.getBoolean("force-target-caster", false)); effect.setFriendly(cs.getBoolean("friendly", false)); @@ -786,6 +789,33 @@ public void loadEffect(String key, ConfigurationSection cs) { LogUtil.printDebug("Loaded effect " + key + " successfully."); } + private List loadBonusDamages(String effectId, ConfigurationSection section) { + List damages = new ArrayList<>(); + if (section == null) { + return damages; + } + for (String k : section.getKeys(false)) { + ConfigurationSection bonus = section.getConfigurationSection(k); + DamageType type; + DamageScale scale; + StrifeStat stat = null; + try { + type = DamageType.valueOf(bonus.getString("damage-type")); + scale = DamageScale.valueOf(bonus.getString("damage-scale", "FLAT")); + String statString = bonus.getString("damage-stat", ""); + if (StringUtils.isNotBlank(statString)) { + stat = StrifeStat.valueOf(statString); + } + } catch (Exception e) { + LogUtil.printWarning("Check config for " + effectId + " invalid bonus dmg " + k); + continue; + } + double amount = bonus.getDouble("amount", 0); + damages.add(new BonusDamage(scale, type, stat, (float) amount)); + } + return damages; + } + public void loadCondition(String key, ConfigurationSection cs) { String type = cs.getString("type", "NULL").toUpperCase(); ConditionType conditionType; @@ -935,6 +965,7 @@ public void loadCondition(String key, ConfigurationSection cs) { case ENTITY_TYPE: List entityTypes = cs.getStringList("types"); boolean whitelist = cs.getBoolean("whitelist", true); + boolean useDisguise = cs.getBoolean("use-disguise-type", true); Set typesSet = new HashSet<>(); try { for (String s : entityTypes) { @@ -944,7 +975,7 @@ public void loadCondition(String key, ConfigurationSection cs) { LogUtil.printError("Failed to load condition " + key + ". Invalid entity type!"); return; } - condition = new EntityTypeCondition(typesSet, whitelist); + condition = new EntityTypeCondition(typesSet, whitelist, useDisguise); break; case UNIQUE_ID: String uniqueId = cs.getString("unique-id"); diff --git a/src/main/java/land/face/strife/managers/ExperienceManager.java b/src/main/java/land/face/strife/managers/ExperienceManager.java index 457ab656..5479df00 100644 --- a/src/main/java/land/face/strife/managers/ExperienceManager.java +++ b/src/main/java/land/face/strife/managers/ExperienceManager.java @@ -36,7 +36,6 @@ public class ExperienceManager implements StrifeExperienceManager { private final StrifePlugin plugin; - private static final String EXP_TEXT = "&a&l( &f&l{0} &a&l/ &f&l{1} &a&l)"; private static final String EXP_MESSAGE = " &a&l+&f&l{0}&a&lXP"; private static final DecimalFormat FORMAT = new DecimalFormat("###,###,###"); @@ -85,16 +84,12 @@ public void addExperience(Player player, double amount, boolean exact) { } double newExpPercent = currentExpPercent + amount / maxFaceExp; - //int currentExp = (int) (newExpPercent * maxFaceExp); - //String xpMsg = EXP_TEXT.replace("{0}", FORMAT.format(currentExp)) - // .replace("{1}", FORMAT.format(maxFaceExp)); - //MessageUtils.sendActionBar(player, xpMsg); player.setExp((float) newExpPercent); } public Integer getMaxFaceExp(int level) { - if (level == 100) { + if (level >= 100) { return 10000000; } return plugin.getLevelingRate().get(level); diff --git a/src/main/java/land/face/strife/managers/SoulManager.java b/src/main/java/land/face/strife/managers/SoulManager.java index 97d6076b..1432ff03 100644 --- a/src/main/java/land/face/strife/managers/SoulManager.java +++ b/src/main/java/land/face/strife/managers/SoulManager.java @@ -3,7 +3,6 @@ import static com.tealcube.minecraft.bukkit.facecore.utilities.MessageUtils.sendMessage; import com.tealcube.minecraft.bukkit.TextUtils; -import io.netty.util.internal.ConcurrentSet; import java.util.HashSet; import java.util.Set; import land.face.strife.StrifePlugin; @@ -34,7 +33,7 @@ public class SoulManager { private StrifePlugin plugin; - private Set souls = new ConcurrentSet<>(); + private Set souls = new HashSet<>(); private Set deathWorlds = new HashSet<>(); private String reviveMessage; private String soulName; @@ -61,12 +60,16 @@ public boolean canSeeSouls(Player player) { } public void createSoul(Player player) { + SoulTimer oldSoul = null; for (SoulTimer soulTimer : souls) { if (soulTimer.getOwner() == player.getUniqueId()) { - removeSoul(soulTimer); + oldSoul = soulTimer; break; } } + if (oldSoul != null) { + removeSoul(oldSoul); + } Location location = TargetingUtil.getOriginLocation(player, OriginLocation.CENTER); String text = soulName.replace("{n}", player.getName()); diff --git a/src/main/java/land/face/strife/managers/StrifeMobManager.java b/src/main/java/land/face/strife/managers/StrifeMobManager.java index d48f1093..993c7cc1 100644 --- a/src/main/java/land/face/strife/managers/StrifeMobManager.java +++ b/src/main/java/land/face/strife/managers/StrifeMobManager.java @@ -9,6 +9,7 @@ import land.face.strife.data.buff.LoadedBuff; import land.face.strife.data.effects.FiniteUsesEffect; import land.face.strife.stats.StrifeStat; +import org.bukkit.entity.Item; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -21,8 +22,8 @@ public StrifeMobManager(StrifePlugin plugin) { this.plugin = plugin; } - public int getMobCount() { - return trackedEntities.size(); + public Map getMobs() { + return trackedEntities; } public StrifeMob getStatMob(LivingEntity entity) { @@ -85,6 +86,9 @@ public void despawnAllTempEntities() { } public void removeEntity(LivingEntity entity) { + if (entity.getPassengers().size() > 0 && entity.getPassengers().get(0) instanceof Item) { + entity.getPassengers().get(0).remove(); + } trackedEntities.remove(entity); } @@ -94,6 +98,7 @@ public void doChunkDespawn(LivingEntity entity) { } if (trackedEntities.get(entity).isDespawnOnUnload()) { entity.remove(); + removeEntity(entity); } } diff --git a/src/main/java/land/face/strife/managers/UniqueEntityManager.java b/src/main/java/land/face/strife/managers/UniqueEntityManager.java index ab48c2a4..4086d5e8 100644 --- a/src/main/java/land/face/strife/managers/UniqueEntityManager.java +++ b/src/main/java/land/face/strife/managers/UniqueEntityManager.java @@ -11,24 +11,31 @@ import land.face.strife.data.UniqueEntity; import land.face.strife.data.ability.EntityAbilitySet; import land.face.strife.data.ability.EntityAbilitySet.TriggerAbilityType; +import land.face.strife.events.UniqueSpawnEvent; import land.face.strife.stats.StrifeStat; +import land.face.strife.tasks.ItemPassengerTask; import land.face.strife.util.ItemUtil; import land.face.strife.util.LogUtil; import land.face.strife.util.SpecialStatusUtil; import land.face.strife.util.StatUtil; import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.disguisetypes.Disguise; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeInstance; import org.bukkit.attribute.AttributeModifier; import org.bukkit.entity.Ageable; +import org.bukkit.entity.Bee; import org.bukkit.entity.Creeper; import org.bukkit.entity.Entity; +import org.bukkit.entity.Item; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Phantom; import org.bukkit.entity.Rabbit; import org.bukkit.entity.Slime; +import org.bukkit.entity.Vindicator; +import org.bukkit.entity.Wolf; import org.bukkit.entity.Zombie; public class UniqueEntityManager { @@ -68,6 +75,13 @@ public StrifeMob spawnUnique(String unique, Location location) { return spawnUnique(uniqueEntity, location); } + private void lambdaSetup(Entity e, UniqueEntity uniqueEntity) { + SpecialStatusUtil.setUniqueId(e, uniqueEntity.getId()); + if (cachedDisguises.containsKey(uniqueEntity)) { + DisguiseAPI.disguiseToAll(e, cachedDisguises.get(uniqueEntity)); + } + } + StrifeMob spawnUnique(UniqueEntity uniqueEntity, Location location) { if (uniqueEntity.getType() == null) { LogUtil.printWarning("Null entity type: " + uniqueEntity.getName()); @@ -76,9 +90,8 @@ StrifeMob spawnUnique(UniqueEntity uniqueEntity, Location location) { LogUtil.printDebug("Spawning unique entity " + uniqueEntity.getId()); assert uniqueEntity.getType().getEntityClass() != null; - Entity entity = Objects.requireNonNull(location.getWorld()) - .spawn(location, uniqueEntity.getType().getEntityClass(), - e -> SpecialStatusUtil.setUniqueId(e, uniqueEntity.getId())); + Entity entity = Objects.requireNonNull(location.getWorld()).spawn(location, + uniqueEntity.getType().getEntityClass(), e -> lambdaSetup(e, uniqueEntity)); if (!entity.isValid()) { LogUtil.printWarning( @@ -119,6 +132,24 @@ StrifeMob spawnUnique(UniqueEntity uniqueEntity, Location location) { } } + if (le instanceof Bee) { + ((Bee) le).setCannotEnterHiveTicks(Integer.MAX_VALUE); + } + + if (uniqueEntity.isAngry()) { + if (le instanceof Vindicator) { + ((Vindicator) le).setJohnny(true); + } else if (le instanceof Wolf) { + ((Wolf) le).setAngry(true); + } else if (le instanceof Bee) { + ((Bee) le).setAnger(500000); + } + } + + if (uniqueEntity.isRemoveFollowMods()) { + SpecialStatusUtil.setWeakAggro(le); + } + if (uniqueEntity.getFollowRange() != -1) { AttributeInstance attributeInstance = le.getAttribute(GENERIC_FOLLOW_RANGE); if (attributeInstance != null) { @@ -131,7 +162,8 @@ StrifeMob spawnUnique(UniqueEntity uniqueEntity, Location location) { } } - if (uniqueEntity.isKnockbackImmune() && le.getAttribute(Attribute.GENERIC_KNOCKBACK_RESISTANCE) != null) { + if (uniqueEntity.isKnockbackImmune() + && le.getAttribute(Attribute.GENERIC_KNOCKBACK_RESISTANCE) != null) { le.getAttribute(Attribute.GENERIC_KNOCKBACK_RESISTANCE).setBaseValue(100); } @@ -140,6 +172,13 @@ StrifeMob spawnUnique(UniqueEntity uniqueEntity, Location location) { ItemUtil.delayedEquip(uniqueEntity.getEquipment(), le); } + if (uniqueEntity.getItemPassenger() != null) { + Item item = Objects.requireNonNull(location.getWorld()).spawn(location, Item.class, + i -> modifyPassengerItem(le, i)); + item.setItemStack(uniqueEntity.getItemPassenger()); + le.addPassenger(item); + } + le.setCustomName(uniqueEntity.getName()); le.setCustomNameVisible(uniqueEntity.isShowName()); @@ -163,8 +202,10 @@ StrifeMob spawnUnique(UniqueEntity uniqueEntity, Location location) { strifeMob.setUniqueEntityId(uniqueEntity.getId()); strifeMob.setFactions(uniqueEntity.getFactions()); + strifeMob.setAlliedGuild(null); strifeMob.setDespawnOnUnload(true); strifeMob.setCharmImmune(uniqueEntity.isCharmImmune()); + if (uniqueEntity.isBurnImmune()) { SpecialStatusUtil.setBurnImmune(le); } @@ -189,13 +230,22 @@ StrifeMob spawnUnique(UniqueEntity uniqueEntity, Location location) { plugin.getAbilityManager().abilityCast(strifeMob, TriggerAbilityType.PHASE_SHIFT); plugin.getParticleTask().addParticle(le, uniqueEntity.getStrifeParticle()); - if (cachedDisguises.containsKey(uniqueEntity)) { - DisguiseAPI.disguiseToAll(le, cachedDisguises.get(uniqueEntity)); - } plugin.getAbilityManager().startAbilityTimerTask(strifeMob); + + UniqueSpawnEvent event = new UniqueSpawnEvent(strifeMob); + Bukkit.getPluginManager().callEvent(event); + return strifeMob; } + private void modifyPassengerItem(LivingEntity rider, Item item) { + item.setOwner(rider.getUniqueId()); + item.setCanMobPickup(false); + item.setPickupDelay(Integer.MAX_VALUE); + item.setGravity(false); + new ItemPassengerTask(item); + } + public void cacheDisguise(UniqueEntity uniqueEntity, Disguise disguise) { cachedDisguises.put(uniqueEntity, disguise); } diff --git a/src/main/java/land/face/strife/menus/abilities/AbilityPickerMenu.java b/src/main/java/land/face/strife/menus/abilities/AbilityPickerMenu.java index b7ca2c6e..cfaffb21 100644 --- a/src/main/java/land/face/strife/menus/abilities/AbilityPickerMenu.java +++ b/src/main/java/land/face/strife/menus/abilities/AbilityPickerMenu.java @@ -22,17 +22,17 @@ import java.util.List; import land.face.strife.StrifePlugin; import land.face.strife.data.ability.Ability; +import land.face.strife.data.effects.TargetingComparators.AbilityComparator; import land.face.strife.menus.BlankIcon; import ninja.amp.ampmenus.menus.ItemMenu; public class AbilityPickerMenu extends ItemMenu { private String id; - public AbilityPickerMenu(StrifePlugin plugin, String name, List abilities) { super(TextUtils.color(name), Size.fit(abilities.size()), plugin); - int index = 0; + abilities.sort(new AbilityComparator()); for (Ability ability : abilities) { setItem(index, new AbilityPickerItem(plugin, ability)); index++; diff --git a/src/main/java/land/face/strife/menus/abilities/AbilityPickerPickerItem.java b/src/main/java/land/face/strife/menus/abilities/AbilityPickerPickerItem.java index 782f6775..146e5caf 100644 --- a/src/main/java/land/face/strife/menus/abilities/AbilityPickerPickerItem.java +++ b/src/main/java/land/face/strife/menus/abilities/AbilityPickerPickerItem.java @@ -20,6 +20,7 @@ import com.tealcube.minecraft.bukkit.TextUtils; import io.pixeloutlaw.minecraft.spigot.hilt.ItemStackExtensionsKt; +import java.util.List; import land.face.strife.StrifePlugin; import ninja.amp.ampmenus.events.ItemClickEvent; import ninja.amp.ampmenus.items.MenuItem; @@ -34,8 +35,10 @@ public class AbilityPickerPickerItem extends MenuItem { private final AbilityPickerMenu menu; private final int slot; - public AbilityPickerPickerItem(AbilityPickerMenu menu, Material material, String name, int slot) { - super(TextUtils.color(name), new ItemStack(material)); + public AbilityPickerPickerItem(AbilityPickerMenu menu, Material material, String name, + List lore, int slot) { + super(TextUtils.color(name), setNameAndLore(new ItemStack(material), TextUtils.color(name), + TextUtils.color(lore))); this.menu = menu; this.slot = slot; } diff --git a/src/main/java/land/face/strife/menus/stats/StatsOffenseMenuItem.java b/src/main/java/land/face/strife/menus/stats/StatsOffenseMenuItem.java index 01022a18..80ca70e9 100644 --- a/src/main/java/land/face/strife/menus/stats/StatsOffenseMenuItem.java +++ b/src/main/java/land/face/strife/menus/stats/StatsOffenseMenuItem.java @@ -92,8 +92,6 @@ public ItemStack getFinalIcon(Player commandSender) { lore.add(addStat("Accuracy Rating: ", acc, INT_FORMAT)); lore.add(addStat("Attack Speed: ", StatUtil.getAttackTime(pStats), "s", TWO_DECIMAL)); lore.add(breakLine); - lore.add(addStat("Overcharge Multiplier: ", StatUtil.getOverchargeMultiplier(pStats), "x", - TWO_DECIMAL)); if (pStats.getStat(StrifeStat.MULTISHOT) > 0) { if (pStats.getStat(StrifeStat.DOGE) > 0) { lore.add(addStat("MultiTHOT: ", pStats.getStat(StrifeStat.MULTISHOT), "%", INT_FORMAT)); @@ -148,14 +146,11 @@ public ItemStack getFinalIcon(Player commandSender) { } lore.add(breakLine); lore.add(addStat("Fire Damage: ", StatUtil.getFireDamage(pStats), INT_FORMAT)); - lore.add(addStat("Ignite Chance: ", pStats.getStat(StrifeStat.IGNITE_CHANCE), "%", INT_FORMAT)); if (pStats.getStat(StrifeStat.ICE_DAMAGE) > 0) { lore.add(addStat("Ice Damage: ", StatUtil.getIceDamage(pStats), INT_FORMAT)); - lore.add(addStat("Freeze Chance: ", pStats.getStat(StrifeStat.FREEZE_CHANCE), "%", INT_FORMAT)); } if (pStats.getStat(StrifeStat.LIGHTNING_DAMAGE) > 0) { lore.add(addStat("Lightning Damage: ", StatUtil.getLightningDamage(pStats), INT_FORMAT)); - lore.add(addStat("Shock Chance: ", pStats.getStat(StrifeStat.SHOCK_CHANCE), "%", INT_FORMAT)); } if (pStats.getStat(StrifeStat.EARTH_DAMAGE) > 0) { lore.add(addStat("Earth Damage: ", StatUtil.getEarthDamage(pStats), INT_FORMAT)); @@ -166,8 +161,8 @@ public ItemStack getFinalIcon(Player commandSender) { } if (pStats.getStat(StrifeStat.DARK_DAMAGE) > 0) { lore.add(addStat("Shadow Damage: ", StatUtil.getShadowDamage(pStats), INT_FORMAT)); - lore.add(addStat("Corrupt Chance: ", pStats.getStat(StrifeStat.CORRUPT_CHANCE), "%", INT_FORMAT)); } + lore.add(addStat("Elemental Status Chance: ", pStats.getStat(StrifeStat.ELEMENTAL_STATUS), "%", INT_FORMAT)); lore.add(breakLine); lore.add(TextUtils.color("&8&oUse &7&o/help stats &8&ofor info!")); itemMeta.setLore(lore); diff --git a/src/main/java/land/face/strife/stats/StrifeStat.java b/src/main/java/land/face/strife/stats/StrifeStat.java index 45541de9..bc602c35 100644 --- a/src/main/java/land/face/strife/stats/StrifeStat.java +++ b/src/main/java/land/face/strife/stats/StrifeStat.java @@ -68,8 +68,6 @@ public enum StrifeStat { PROJECTILE_REDUCTION("Projectile Protection"), ATTACK_SPEED("Attack Speed"), - OVERCHARGE("Overcharge"), - CRITICAL_RATE("Critical Chance"), CRITICAL_DAMAGE("Critical Damage"), @@ -84,11 +82,7 @@ public enum StrifeStat { LIGHT_DAMAGE("Light Damage"), DARK_DAMAGE("Shadow Damage"), - IGNITE_CHANCE("Ignite Chance"), - IGNITE_DURATION("Ignite Duration"), - SHOCK_CHANCE("Shock Chance"), - FREEZE_CHANCE("Freeze Chance"), - CORRUPT_CHANCE("Corrupt Chance"), + ELEMENTAL_STATUS("Elemental Status Chance"), MAX_EARTH_RUNES("Max Earth Runes"), MAXIMUM_RAGE("Maximum Rage"), @@ -145,7 +139,6 @@ public enum StrifeStat { ACCURACY_MULT(), MINION_MULT_INTERNAL(), - SPELL_STRIKE_RANGE("Spell Strike Range"), EFFECT_DURATION("Effect Duration"); // values() is dumb, so we only run it once, and hit use this to diff --git a/src/main/java/land/face/strife/tasks/GlobalMultiplierTask.java b/src/main/java/land/face/strife/tasks/BoostTickTask.java similarity index 79% rename from src/main/java/land/face/strife/tasks/GlobalMultiplierTask.java rename to src/main/java/land/face/strife/tasks/BoostTickTask.java index 876f2b4c..7259b6f9 100644 --- a/src/main/java/land/face/strife/tasks/GlobalMultiplierTask.java +++ b/src/main/java/land/face/strife/tasks/BoostTickTask.java @@ -18,19 +18,19 @@ */ package land.face.strife.tasks; -import land.face.strife.managers.GlobalBoostManager; +import land.face.strife.managers.BoostManager; import org.bukkit.scheduler.BukkitRunnable; -public class GlobalMultiplierTask extends BukkitRunnable { +public class BoostTickTask extends BukkitRunnable { - private GlobalBoostManager globalBoostManager; + private BoostManager boostManager; - public GlobalMultiplierTask(GlobalBoostManager globalBoostManager) { - this.globalBoostManager = globalBoostManager; + public BoostTickTask(BoostManager boostManager) { + this.boostManager = boostManager; } @Override public void run() { - globalBoostManager.tickBoosts(); + boostManager.tickBoosts(); } } diff --git a/src/main/java/land/face/strife/tasks/DamageOverTimeTask.java b/src/main/java/land/face/strife/tasks/DamageOverTimeTask.java new file mode 100644 index 00000000..b99e15ef --- /dev/null +++ b/src/main/java/land/face/strife/tasks/DamageOverTimeTask.java @@ -0,0 +1,131 @@ +/** + * The MIT License Copyright (c) 2015 Teal Cube Games + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and + * associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, + * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT + * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package land.face.strife.tasks; + +import static org.bukkit.potion.PotionEffectType.FIRE_RESISTANCE; +import static org.bukkit.potion.PotionEffectType.POISON; +import static org.bukkit.potion.PotionEffectType.WITHER; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import land.face.strife.StrifePlugin; +import land.face.strife.stats.StrifeStat; +import land.face.strife.util.StatUtil; +import org.bukkit.entity.LivingEntity; +import org.bukkit.scheduler.BukkitRunnable; + +public class DamageOverTimeTask extends BukkitRunnable { + + private StrifePlugin plugin; + + private float WITHER_FLAT_DAMAGE; + private float BURN_FLAT_DAMAGE; + private float POISON_FLAT_DAMAGE; + private float POISON_PERCENT_MAX_HEALTH_DAMAGE; + + private Set poisonedMobs = new HashSet<>(); + private Set burningMobs = new HashSet<>(); + private Set witheredMobs = new HashSet<>(); + + public DamageOverTimeTask(StrifePlugin plugin) { + this.plugin = plugin; + BURN_FLAT_DAMAGE = (float) plugin.getSettings() + .getDouble("config.mechanics.burn-flat-damage", 6) / 4; + WITHER_FLAT_DAMAGE = (float) plugin.getSettings() + .getDouble("config.mechanics.wither-flat-damage"); + POISON_FLAT_DAMAGE = (float) plugin.getSettings() + .getDouble("config.mechanics.poison-flat-damage"); + POISON_PERCENT_MAX_HEALTH_DAMAGE = (float) plugin.getSettings() + .getDouble("config.mechanics.poison-percent-damage"); + } + + public void trackPoison(LivingEntity livingEntity) { + poisonedMobs.add(livingEntity); + } + + public void trackBurning(LivingEntity livingEntity) { + burningMobs.add(livingEntity); + } + + public void trackWither(LivingEntity livingEntity) { + witheredMobs.add(livingEntity); + } + + @Override + public void run() { + Iterator poisonIterator = poisonedMobs.iterator(); + while (poisonIterator.hasNext()) { + LivingEntity le = (LivingEntity) poisonIterator.next(); + if (le == null || !le.isValid() || !le.hasPotionEffect(POISON)) { + poisonIterator.remove(); + continue; + } + int poisonPower = le.getPotionEffect(POISON).getAmplifier() + 1; + double damage = + poisonPower * (POISON_FLAT_DAMAGE + le.getMaxHealth() * POISON_PERCENT_MAX_HEALTH_DAMAGE); + damage *= + 1 - plugin.getStrifeMobManager().getStatMob(le).getStat(StrifeStat.POISON_RESIST) / 100; + damage *= 0.25; + if (le.getHealth() <= damage) { + le.damage(damage); + } else { + le.setHealth(le.getHealth() - damage); + } + } + Iterator witherIterator = witheredMobs.iterator(); + while (witherIterator.hasNext()) { + LivingEntity le = (LivingEntity) witherIterator.next(); + if (le == null || !le.isValid() || !le.hasPotionEffect(WITHER)) { + witherIterator.remove(); + continue; + } + int witherPower = le.getPotionEffect(WITHER).getAmplifier() + 1; + double damage = witherPower * WITHER_FLAT_DAMAGE; + damage *= + 1 - plugin.getStrifeMobManager().getStatMob(le).getStat(StrifeStat.WITHER_RESIST) / 100; + damage *= 0.25; + if (le.getHealth() <= damage) { + le.damage(damage); + } else { + le.setHealth(le.getHealth() - damage); + } + } + Iterator fireIterator = burningMobs.iterator(); + while (fireIterator.hasNext()) { + LivingEntity le = (LivingEntity) fireIterator.next(); + if (le == null || !le.isValid() || le.getFireTicks() < 1) { + fireIterator.remove(); + continue; + } + if (le.hasPotionEffect(FIRE_RESISTANCE)) { + continue; + } + float damage = BURN_FLAT_DAMAGE; + damage *= 1 - StatUtil.getFireResist(plugin.getStrifeMobManager().getStatMob(le)) / 100; + damage = plugin.getBarrierManager().damageBarrier( + plugin.getStrifeMobManager().getStatMob(le), damage); + if (le.getHealth() <= damage) { + le.damage(damage); + } else { + le.setHealth(le.getHealth() - damage); + } + } + } +} diff --git a/src/main/java/land/face/strife/tasks/ItemPassengerTask.java b/src/main/java/land/face/strife/tasks/ItemPassengerTask.java new file mode 100644 index 00000000..319b40c1 --- /dev/null +++ b/src/main/java/land/face/strife/tasks/ItemPassengerTask.java @@ -0,0 +1,45 @@ +/** + * The MIT License Copyright (c) 2015 Teal Cube Games + *

+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and + * associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, + * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

+ * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + *

+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT + * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package land.face.strife.tasks; + +import land.face.strife.StrifePlugin; +import org.bukkit.entity.Item; +import org.bukkit.scheduler.BukkitRunnable; + +public class ItemPassengerTask extends BukkitRunnable { + + private final Item item; + + public ItemPassengerTask(Item item) { + this.item = item; + runTaskTimer(StrifePlugin.getInstance(), 0L, 200L); + } + + @Override + public void run() { + if (!item.isValid()) { + cancel(); + } + if (item.getVehicle() == null || !item.getVehicle().isValid()) { + item.remove(); + cancel(); + } + item.setTicksLived(1); + } +} diff --git a/src/main/java/land/face/strife/tasks/ParticleTask.java b/src/main/java/land/face/strife/tasks/ParticleTask.java index 30bbcc67..a2c2aa1a 100644 --- a/src/main/java/land/face/strife/tasks/ParticleTask.java +++ b/src/main/java/land/face/strife/tasks/ParticleTask.java @@ -18,7 +18,8 @@ */ package land.face.strife.tasks; -import io.netty.util.internal.ConcurrentSet; +import java.util.HashSet; +import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -45,13 +46,16 @@ public void run() { continuousParticles.remove(le); continue; } - for (ContinuousParticle particle : continuousParticles.get(le)) { + Iterator iterator = continuousParticles.get(le).iterator(); + while (iterator.hasNext()) { + ContinuousParticle particle = (ContinuousParticle) iterator.next(); if (particle.getTicksRemaining() < 1) { - continuousParticles.get(le).remove(particle); + iterator.remove(); + //continuousParticles.get(le).remove(particle); continue; } particle.getParticle().applyAtLocation(null, TargetingUtil - .getOriginLocation(le, particle.getParticle().getParticleOriginLocation())); + .getOriginLocation(le, particle.getParticle().getOrigin())); particle.setTicksRemaining(particle.getTicksRemaining() - 1); } } @@ -66,7 +70,7 @@ public void run() { public void addContinuousParticle(LivingEntity livingEntity, StrifeParticle particle, int ticks) { if (!continuousParticles.containsKey(livingEntity)) { - continuousParticles.put(livingEntity, new ConcurrentSet<>()); + continuousParticles.put(livingEntity, new HashSet<>()); } if (particleUpdate(particle.getId(), ticks, continuousParticles.get(livingEntity))) { return; diff --git a/src/main/java/land/face/strife/tasks/StrifeMobTracker.java b/src/main/java/land/face/strife/tasks/StrifeMobTracker.java index bb9313dd..1db9c4fc 100644 --- a/src/main/java/land/face/strife/tasks/StrifeMobTracker.java +++ b/src/main/java/land/face/strife/tasks/StrifeMobTracker.java @@ -18,8 +18,14 @@ */ package land.face.strife.tasks; +import com.tealcube.minecraft.bukkit.shade.apache.commons.lang3.StringUtils; +import java.util.HashMap; +import java.util.Map; import land.face.strife.StrifePlugin; +import land.face.strife.data.StrifeMob; import land.face.strife.util.LogUtil; +import org.bukkit.Bukkit; +import org.bukkit.entity.LivingEntity; import org.bukkit.scheduler.BukkitRunnable; public class StrifeMobTracker extends BukkitRunnable { @@ -32,6 +38,33 @@ public StrifeMobTracker(StrifePlugin plugin) { @Override public void run() { - LogUtil.printInfo("Current StrifeMobs: " + plugin.getStrifeMobManager().getMobCount()); + int size = plugin.getStrifeMobManager().getMobs().size(); + LogUtil.printInfo("Current StrifeMobs: " + size); + int valid = 0; + int random = 0; + Map unique = new HashMap<>(); + for (LivingEntity le : plugin.getStrifeMobManager().getMobs().keySet()) { + if (le.isValid()) { + valid += 1; + } else { + Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, () -> { + if (plugin.getStrifeMobManager().isTrackedEntity(le)) { + plugin.getStrifeMobManager().getMobs().remove(le); + } + }, 200L); + } + StrifeMob mob = plugin.getStrifeMobManager().getMobs().get(le); + if (StringUtils.isNotBlank(mob.getUniqueEntityId())) { + unique.put(mob.getUniqueEntityId(), unique.getOrDefault(mob.getUniqueEntityId(), 0) + 1); + } else { + random += 1; + } + } + LogUtil.printDebug("-- Expired entity keys: " + (size - valid)); + LogUtil.printDebug("-- Randomized mobs: " + random); + LogUtil.printDebug("-- Unique Map:"); + for (String uniqueId : unique.keySet()) { + LogUtil.printDebug("---- Unique:" + uniqueId + " amount:" + unique.get(uniqueId)); + } } } diff --git a/src/main/java/land/face/strife/timers/EndlessEffectTimer.java b/src/main/java/land/face/strife/timers/EndlessEffectTimer.java index a2ee0818..6d853d4b 100644 --- a/src/main/java/land/face/strife/timers/EndlessEffectTimer.java +++ b/src/main/java/land/face/strife/timers/EndlessEffectTimer.java @@ -44,6 +44,10 @@ public void run() { } } for (Effect effect : endlessEffect.getRunEffects()) { + if (effect == null) { + LogUtil.printWarning("Invalid effect in endless runner " + endlessEffect.getId()); + continue; + } LogUtil.printDebug("Executing " + effect.getId() + " as part of " + endlessEffect.getId()); plugin.getEffectManager().execute(effect, mob, mob.getEntity()); } diff --git a/src/main/java/land/face/strife/timers/EntityAbilityTimer.java b/src/main/java/land/face/strife/timers/EntityAbilityTimer.java index 5f352457..e33f6b9d 100644 --- a/src/main/java/land/face/strife/timers/EntityAbilityTimer.java +++ b/src/main/java/land/face/strife/timers/EntityAbilityTimer.java @@ -35,7 +35,8 @@ public void run() { return; } double max = Math.pow(strifeMob.getEntity().getAttribute(GENERIC_FOLLOW_RANGE).getValue(), 2); - if (strifeMob.getEntity().getLocation().distanceSquared(target.getLocation()) > max) { + if (strifeMob.getEntity().getLocation().getWorld() != target.getLocation().getWorld() + || strifeMob.getEntity().getLocation().distanceSquared(target.getLocation()) > max) { ((Mob) strifeMob.getEntity()).setTarget(null); return; } diff --git a/src/main/java/land/face/strife/util/DamageUtil.java b/src/main/java/land/face/strife/util/DamageUtil.java index fd3ccfca..6b9d4f23 100644 --- a/src/main/java/land/face/strife/util/DamageUtil.java +++ b/src/main/java/land/face/strife/util/DamageUtil.java @@ -16,12 +16,14 @@ import com.tealcube.minecraft.bukkit.shade.apache.commons.lang3.StringUtils; import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Random; +import java.util.UUID; import java.util.stream.Collectors; import java.util.stream.IntStream; import land.face.strife.StrifePlugin; -import land.face.strife.data.DamageContainer; +import land.face.strife.data.BonusDamage; import land.face.strife.data.DamageModifiers; import land.face.strife.data.DamageModifiers.ElementalStatus; import land.face.strife.data.IndicatorData; @@ -39,6 +41,9 @@ import land.face.strife.managers.CorruptionManager; import land.face.strife.stats.StrifeStat; import land.face.strife.stats.StrifeTrait; +import me.glaremasters.guilds.Guilds; +import me.glaremasters.guilds.api.GuildsAPI; +import me.glaremasters.guilds.guild.Guild; import org.bukkit.Bukkit; import org.bukkit.Particle; import org.bukkit.Sound; @@ -49,9 +54,6 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; -import org.bukkit.entity.ShulkerBullet; -import org.bukkit.entity.SmallFireball; -import org.bukkit.entity.WitherSkull; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; @@ -63,6 +65,7 @@ public class DamageUtil { private static StrifePlugin plugin; + private static GuildsAPI guildsAPI; private static final String ATTACK_BLOCKED = TextUtils.color("&f&lBlocked!"); private static final String ATTACK_DODGED = TextUtils.color("&f&lDodge!"); @@ -81,6 +84,7 @@ public class DamageUtil { public static void refresh() { plugin = StrifePlugin.getInstance(); + guildsAPI = Guilds.getApi(); float floatSpeed = (float) plugin.getSettings().getDouble("config.indicators.float-speed", 70); float missSpeed = (float) plugin.getSettings().getDouble("config.indicators.miss-speed", 80); EVASION_THRESHOLD = plugin.getSettings().getDouble("config.mechanics.evasion-threshold", 0.5); @@ -102,6 +106,22 @@ public static void applyExtraEffects(StrifeMob attacker, StrifeMob defender, } } + public static boolean isGuildAlly(StrifeMob attacker, Player target) { + Guild guild = guildsAPI.getGuildHandler().getGuild(target); + if (guild == null) { + return false; + } + if (attacker.getAlliedGuild().equals(guild.getId())) { + return true; + } + for (UUID uuid : guild.getAllies()) { + if (attacker.getAlliedGuild().equals(uuid)) { + return true; + } + } + return false; + } + public static boolean preDamage(StrifeMob attacker, StrifeMob defender, DamageModifiers mods) { if (attacker.getEntity() instanceof Player) { @@ -153,26 +173,20 @@ public static boolean preDamage(StrifeMob attacker, StrifeMob defender, DamageMo public static Map buildDamage(StrifeMob attacker, StrifeMob defender, DamageModifiers mods) { - float attackMult = mods.getAttackMultiplier(); - Map damageMap = DamageUtil.buildDamageMap(attacker, mods.getAttackType()); - damageMap.replaceAll((t, v) -> - damageMap.get(t) * mods.getDamageModifiers().getOrDefault(t, 0f) * attackMult); - for (DamageType type : DMG_TYPES) { - if (mods.getFlatDamageBonuses().containsKey(type)) { - damageMap - .put(type, damageMap.getOrDefault(type, 0f) + mods.getFlatDamageBonuses().get(type)); - } - } - DamageUtil.applyElementalEffects(attacker, defender, damageMap, mods); + Map damageMap = DamageUtil.buildDamageMap(attacker, defender, + mods.getBonusDamages(), mods.getAttackMultiplier()); + applyAttackTypeMods(attacker, mods.getAttackType(), damageMap); + applyElementalEffects(attacker, defender, damageMap, mods); return damageMap; } + public static void reduceDamage(StrifeMob attacker, StrifeMob defender, Map damageMap, DamageModifiers mods) { DamageUtil.applyDamageReductions(attacker, defender, damageMap, mods.getAbilityMods()); } - public static float damage(StrifeMob attacker, StrifeMob defender, + public static float calculateFinalDamage(StrifeMob attacker, StrifeMob defender, Map damageMap, DamageModifiers mods) { double standardDamage = damageMap.getOrDefault(DamageType.PHYSICAL, 0f) + @@ -187,10 +201,8 @@ public static float damage(StrifeMob attacker, StrifeMob defender, float potionMult = DamageUtil.getPotionMult(attacker.getEntity(), defender.getEntity()); float critMult = 0; - double bonusOverchargeMultiplier = 0; - boolean criticalHit = isCriticalHit(attacker, defender, mods.getAttackMultiplier(), - mods.getAbilityMods().getOrDefault(AbilityMod.CRITICAL_CHANCE, 0f)); + boolean criticalHit = isCriticalHit(attacker, defender, mods); if (criticalHit) { critMult = (attacker.getStat(StrifeStat.CRITICAL_DAMAGE) + mods.getAbilityMods().getOrDefault(AbilityMod.CRITICAL_DAMAGE, 0f)) / 100; @@ -201,7 +213,7 @@ public static float damage(StrifeMob attacker, StrifeMob defender, pvpMult = PVP_MULT; } - standardDamage += standardDamage * critMult + standardDamage * bonusOverchargeMultiplier; + standardDamage += standardDamage * critMult; standardDamage *= potionMult; standardDamage *= StatUtil.getDamageMult(attacker); standardDamage *= pvpMult; @@ -216,7 +228,8 @@ public static float damage(StrifeMob attacker, StrifeMob defender, elementalDamage *= StatUtil.getDamageMult(attacker); elementalDamage *= pvpMult; - float damageReduction = defender.getStat(StrifeStat.DAMAGE_REDUCTION) * pvpMult; + float damageReduction = defender.getStat(StrifeStat.DAMAGE_REDUCTION) * + mods.getDamageReductionRatio() * pvpMult; float rawDamage = (float) Math.max(0D, (standardDamage + elementalDamage) - damageReduction); rawDamage *= DamageUtil.getRageMult(defender); @@ -238,10 +251,8 @@ public static float damage(StrifeMob attacker, StrifeMob defender, LifeSkillType.SNEAK, gainedXp, false); } - float postBarrierDamage = plugin.getBarrierManager().damageBarrier(defender, rawDamage); - String damageString = String.valueOf((int) Math.ceil(rawDamage)); - if (criticalHit) { + if (criticalHit && (standardDamage > 1 || attacker.hasTrait(StrifeTrait.ELEMENTAL_CRITS))) { damageString = "&l" + damageString; } if (attacker.getEntity() instanceof Player) { @@ -254,25 +265,17 @@ public static float damage(StrifeMob attacker, StrifeMob defender, "&7" + damageString); } - plugin.getBarrierManager().updateShieldDisplay(defender); - - defender.trackDamage(attacker, postBarrierDamage); - return postBarrierDamage; + defender.trackDamage(attacker, rawDamage); + return rawDamage; } - public static void postDamage(StrifeMob attacker, StrifeMob defender, - Map damageMap, DamageModifiers mods) { + public static void postDamage(StrifeMob attacker, StrifeMob defender, DamageModifiers mods) { float attackMult = mods.getAttackMultiplier(); DamageUtil.applyHealthOnHit(attacker, mods.getAttackMultiplier(), mods.getHealMultiplier(), mods.getAbilityMods().getOrDefault(AbilityMod.HEALTH_ON_HIT, 0f)); - if (damageMap.containsKey(DamageType.PHYSICAL)) { - DamageUtil.attemptBleed(attacker, defender, damageMap.get(DamageType.PHYSICAL), - mods.getAttackMultiplier(), mods.getAbilityMods(), false); - } - DamageUtil.doReflectedDamage(defender, attacker, mods.getAttackType()); if (attacker.getStat(StrifeStat.RAGE_ON_HIT) > 0.1) { @@ -283,7 +286,6 @@ public static void postDamage(StrifeMob attacker, StrifeMob defender, plugin.getRageManager().addRage(defender, defender.getStat(StrifeStat.RAGE_WHEN_HIT)); } - plugin.getAbilityManager().abilityCast(attacker, defender, TriggerAbilityType.ON_HIT); plugin.getAbilityManager().abilityCast(defender, attacker, TriggerAbilityType.WHEN_HIT); } @@ -315,48 +317,45 @@ private static float doSneakAttack(StrifeMob attacker, StrifeMob defender, Damag return 0f; } - private static boolean isCriticalHit(StrifeMob attacker, StrifeMob defender, float attackMult, - float bonusCrit) { - if (DamageUtil.isCrit(attacker, attackMult, bonusCrit)) { + private static boolean isCriticalHit(StrifeMob attacker, StrifeMob defender, + DamageModifiers mods) { + float attackPenalty = 1f; + if (mods.isScaleChancesWithAttack()) { + attackPenalty = mods.getAttackMultiplier(); + } + float critChance = StatUtil.getCriticalChance(attacker, attackPenalty, + mods.getAbilityMods().getOrDefault(AbilityMod.CRITICAL_CHANCE, 0f)); + boolean success = critChance >= rollDouble(hasLuck(attacker.getEntity())); + if (success) { DamageUtil.callCritEvent(attacker, attacker); defender.getEntity().getWorld().playSound(defender.getEntity().getEyeLocation(), Sound.ENTITY_GENERIC_BIG_FALL, 2f, 0.8f); - return true; + if (attacker.getEntity() instanceof Player) { + StrifePlugin.getInstance().getIndicatorManager().addIndicator(attacker.getEntity(), + defender.getEntity(), buildCritIndicator((Player) attacker.getEntity()), "&c&lCRIT!"); + } } - return false; + return success; } - public static float getRawDamage(StrifeMob attacker, DamageType damageType, AttackType type) { + public static float getRawDamage(StrifeMob attacker, DamageType damageType) { switch (damageType) { case PHYSICAL: - float damage = attacker.getStat(StrifeStat.PHYSICAL_DAMAGE); - if (type == AttackType.MELEE) { - damage *= 1 + attacker.getStat(StrifeStat.MELEE_PHYSICAL_MULT) / 100; - } else if (type == AttackType.RANGED || type == AttackType.PROJECTILE) { - damage *= 1 + attacker.getStat(StrifeStat.RANGED_PHYSICAL_MULT) / 100; - } - return damage; + return attacker.getStat(StrifeStat.PHYSICAL_DAMAGE); case MAGICAL: - return attacker.getStat(StrifeStat.MAGIC_DAMAGE) * (1 + attacker.getStat( - StrifeStat.MAGIC_MULT) / 100); + return attacker.getStat(StrifeStat.MAGIC_DAMAGE); case FIRE: - return attacker.getStat(StrifeStat.FIRE_DAMAGE) * (1 + attacker.getStat( - StrifeStat.ELEMENTAL_MULT) / 100); + return attacker.getStat(StrifeStat.FIRE_DAMAGE); case ICE: - return attacker.getStat(StrifeStat.ICE_DAMAGE) * (1 + attacker.getStat( - StrifeStat.ELEMENTAL_MULT) / 100); + return attacker.getStat(StrifeStat.ICE_DAMAGE); case LIGHTNING: - return attacker.getStat(StrifeStat.LIGHTNING_DAMAGE) * (1 + attacker.getStat( - StrifeStat.ELEMENTAL_MULT) / 100); + return attacker.getStat(StrifeStat.LIGHTNING_DAMAGE); case DARK: - return attacker.getStat(StrifeStat.DARK_DAMAGE) * (1 + attacker.getStat( - StrifeStat.ELEMENTAL_MULT) / 100); + return attacker.getStat(StrifeStat.DARK_DAMAGE); case EARTH: - return attacker.getStat(StrifeStat.EARTH_DAMAGE) * (1 + attacker.getStat( - StrifeStat.ELEMENTAL_MULT) / 100); + return attacker.getStat(StrifeStat.EARTH_DAMAGE); case LIGHT: - return attacker.getStat(StrifeStat.LIGHT_DAMAGE) * (1 + attacker.getStat( - StrifeStat.ELEMENTAL_MULT) / 100); + return attacker.getStat(StrifeStat.LIGHT_DAMAGE); case TRUE_DAMAGE: return attacker.getStat(StrifeStat.TRUE_DAMAGE); default: @@ -365,20 +364,19 @@ public static float getRawDamage(StrifeMob attacker, DamageType damageType, Atta } public static float applyDamageScale(StrifeMob caster, StrifeMob target, - DamageContainer damageContainer, AttackType attackType) { - float amount = damageContainer.getAmount(); - switch (damageContainer.getDamageScale()) { + BonusDamage bonusDamage) { + float amount = bonusDamage.getAmount(); + switch (bonusDamage.getDamageScale()) { case FLAT: return amount; case CASTER_STAT_PERCENT: - return damageContainer.getAmount() * caster.getStat(damageContainer.getDamageStat()); + return bonusDamage.getAmount() * caster.getStat(bonusDamage.getDamageStat()); case TARGET_STAT_PERCENT: - return damageContainer.getAmount() * target.getStat(damageContainer.getDamageStat()); + return bonusDamage.getAmount() * target.getStat(bonusDamage.getDamageStat()); case CASTER_LEVEL: return amount * StatUtil.getMobLevel(caster.getEntity()); case CASTER_DAMAGE: - return amount * DamageUtil - .getRawDamage(caster, damageContainer.getDamageType(), attackType); + return amount * DamageUtil.getRawDamage(caster, bonusDamage.getDamageType()); case TARGET_CURRENT_HEALTH: return amount * (float) target.getEntity().getHealth(); case CASTER_CURRENT_HEALTH: @@ -421,14 +419,19 @@ public static float applyDamageScale(StrifeMob caster, StrifeMob target, return amount; } - public static Map buildDamageMap(StrifeMob attacker, AttackType attackType) { + public static Map buildDamageMap(StrifeMob attacker, StrifeMob target, + List bonusDamages, float attackMultiplier) { Map damageMap = new HashMap<>(); for (DamageType damageType : DMG_TYPES) { - float amount = getRawDamage(attacker, damageType, attackType); + float amount = getRawDamage(attacker, damageType); if (amount > 0) { - damageMap.put(damageType, amount); + damageMap.put(damageType, amount * attackMultiplier); } } + for (BonusDamage bd : bonusDamages) { + float bonus = applyDamageScale(attacker, target, bd); + damageMap.put(bd.getDamageType(), damageMap.getOrDefault(bd.getDamageType(), 0f) + bonus); + } return damageMap; } @@ -440,14 +443,38 @@ public static void applyDamageReductions(StrifeMob attacker, StrifeMob defender, public static void applyAttackTypeMods(StrifeMob attacker, AttackType attackType, Map damageMap) { - if (attackType == AttackType.MELEE && damageMap.containsKey(DamageType.PHYSICAL)) { - damageMap.put(DamageType.PHYSICAL, - damageMap.get(DamageType.PHYSICAL) * 1 - + attacker.getStat(StrifeStat.MELEE_PHYSICAL_MULT) / 100); - } else if (attackType == AttackType.RANGED && damageMap.containsKey(DamageType.PHYSICAL)) { - damageMap.put(DamageType.PHYSICAL, - damageMap.get(DamageType.PHYSICAL) * 1 - + attacker.getStat(StrifeStat.RANGED_PHYSICAL_MULT) / 100); + if (damageMap.containsKey(DamageType.PHYSICAL)) { + float physicalDamage = damageMap.get(DamageType.PHYSICAL); + if (attackType == AttackType.MELEE) { + physicalDamage *= 1 + attacker.getStat(StrifeStat.MELEE_PHYSICAL_MULT) / 100; + damageMap.put(DamageType.PHYSICAL, physicalDamage); + } else if (attackType == AttackType.PROJECTILE) { + physicalDamage *= 1 + attacker.getStat(StrifeStat.RANGED_PHYSICAL_MULT) / 100; + damageMap.put(DamageType.PHYSICAL, physicalDamage); + } + } + if (damageMap.containsKey(DamageType.MAGICAL)) { + damageMap.put(DamageType.MAGICAL, damageMap.get(DamageType.MAGICAL) + * (1 + attacker.getStat(StrifeStat.MAGIC_MULT) / 100)); + } + float elementalMult = 1 + (attacker.getStat(StrifeStat.ELEMENTAL_MULT) / 100); + if (damageMap.containsKey(DamageType.FIRE)) { + damageMap.put(DamageType.FIRE, damageMap.get(DamageType.FIRE) * elementalMult); + } + if (damageMap.containsKey(DamageType.ICE)) { + damageMap.put(DamageType.ICE, damageMap.get(DamageType.ICE) * elementalMult); + } + if (damageMap.containsKey(DamageType.LIGHTNING)) { + damageMap.put(DamageType.LIGHTNING, damageMap.get(DamageType.LIGHTNING) * elementalMult); + } + if (damageMap.containsKey(DamageType.EARTH)) { + damageMap.put(DamageType.EARTH, damageMap.get(DamageType.EARTH) * elementalMult); + } + if (damageMap.containsKey(DamageType.DARK)) { + damageMap.put(DamageType.DARK, damageMap.get(DamageType.DARK) * elementalMult); + } + if (damageMap.containsKey(DamageType.LIGHT)) { + damageMap.put(DamageType.LIGHT, damageMap.get(DamageType.LIGHT) * elementalMult); } } @@ -459,7 +486,19 @@ private static void applyElementalEffects(StrifeMob attacker, damageMap.put(DamageType.EARTH, damageMap.get(DamageType.EARTH) * (1 + earthRunes * 0.3f)); } } - if (!DamageUtil.rollBool(attacker.getStat(StrifeStat.ELEMENTAL_STATUS) / 100, true)) { + if (damageMap.containsKey(DamageType.FIRE) && defender.getEntity().getFireTicks() > 0) { + damageMap.put(DamageType.FIRE, damageMap.get(DamageType.FIRE) * 1.5f); + } + float darkDamage = damageMap.getOrDefault(DamageType.DARK, 0f); + if (darkDamage != 0) { + damageMap.put(DamageType.DARK, + darkDamage * getDarknessManager().getCorruptionMult(defender.getEntity())); + } + float chance = attacker.getStat(StrifeStat.ELEMENTAL_STATUS) / 100; + if (mods.isScaleChancesWithAttack()) { + chance *= mods.getAttackMultiplier(); + } + if (!DamageUtil.rollBool(chance, true)) { return; } float totalElementalDamage = 0; @@ -491,35 +530,22 @@ private static void applyElementalEffects(StrifeMob attacker, float bonus; switch (finalElementType) { case FIRE: - bonus = attemptIgnite(damageMap.get(finalElementType), attacker, defender.getEntity()); - if (bonus != 0) { - mods.getElementalStatuses().add(ElementalStatus.IGNITE); - damageMap.put(finalElementType, damageMap.get(finalElementType) + bonus); - } + mods.getElementalStatuses().add(ElementalStatus.IGNITE); + doIgnite(defender.getEntity(), damageMap.get(DamageType.FIRE)); break; case ICE: + mods.getElementalStatuses().add(ElementalStatus.FREEZE); bonus = attemptFreeze(damageMap.get(finalElementType), attacker, defender.getEntity()); - if (bonus != 0) { - mods.getElementalStatuses().add(ElementalStatus.FREEZE); - damageMap.put(finalElementType, damageMap.get(finalElementType) + bonus); - } + damageMap.put(finalElementType, damageMap.get(finalElementType) + bonus); break; case LIGHTNING: - bonus = attemptShock(damageMap.get(finalElementType), attacker, defender.getEntity()); - if (bonus != 0) { - mods.getElementalStatuses().add(ElementalStatus.SHOCK); - damageMap.put(finalElementType, damageMap.get(finalElementType) + bonus); - } + mods.getElementalStatuses().add(ElementalStatus.SHOCK); + bonus = attemptShock(damageMap.get(finalElementType), defender.getEntity()); + damageMap.put(finalElementType, damageMap.get(finalElementType) + bonus); break; case DARK: - bonus = damageMap.get(finalElementType) * getDarknessManager() - .getCorruptionMult(defender.getEntity()); - boolean corrupt = attemptCorrupt(damageMap.get(finalElementType), attacker, - defender.getEntity()); - if (corrupt) { - mods.getElementalStatuses().add(ElementalStatus.CORRUPT); - damageMap.put(finalElementType, damageMap.get(finalElementType) + bonus); - } + mods.getElementalStatuses().add(ElementalStatus.CORRUPT); + applyCorrupt(defender.getEntity(), 5 + darkDamage / 3); break; case LIGHT: bonus = getLightBonus(damageMap.get(finalElementType), attacker, defender.getEntity()); @@ -606,8 +632,7 @@ public static LivingEntity getAttacker(Entity entity) { return null; } - public static float attemptIgnite(float damage, StrifeMob attacker, LivingEntity defender) { - float bonusDamage = defender.getFireTicks() > 0 ? damage : 1f; + private static void doIgnite(LivingEntity defender, float damage) { defender.setFireTicks(Math.max(25 + (int) damage, defender.getFireTicks())); defender.getWorld().playSound(defender.getEyeLocation(), Sound.ITEM_FLINTANDSTEEL_USE, 1f, 1f); defender.getWorld().spawnParticle( @@ -616,14 +641,13 @@ public static float attemptIgnite(float damage, StrifeMob attacker, LivingEntity 6 + (int) damage / 2, 0.3, 0.3, 0.3, 0.03 ); - return bonusDamage; + StrifePlugin.getInstance().getDamageOverTimeTask().trackBurning(defender); } - public static float attemptShock(float damage, StrifeMob attacker, LivingEntity defender) { + public static float attemptShock(float damage, LivingEntity defender) { float multiplier = 0.5f; - float percentHealth = - (float) defender.getHealth() / (float) defender.getAttribute(Attribute.GENERIC_MAX_HEALTH) - .getValue(); + float percentHealth = (float) defender.getHealth() / + (float) defender.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); if (percentHealth < 0.5f) { multiplier = 1f / (float) Math.max(0.16, percentHealth * 2); } @@ -673,17 +697,6 @@ public static float getLightBonus(float damage, StrifeMob attacker, LivingEntity return damage * multiplier; } - public static boolean attemptCorrupt(float baseDamage, StrifeMob attacker, - LivingEntity defender) { - applyCorrupt(defender, baseDamage); - return true; - } - - public static boolean isCrit(StrifeMob attacker, float aMult, float bonusCrit) { - float critChance = StatUtil.getCriticalChance(attacker, aMult, bonusCrit); - return critChance >= rollDouble(hasLuck(attacker.getEntity())); - } - public static float getFullEvasionMult(StrifeMob attacker, StrifeMob defender, Map mods) { @@ -774,9 +787,8 @@ public static boolean canAttack(Player attacker, Player defender) { } public static double getProjectileMultiplier(StrifeMob atk, StrifeMob def) { - return Math.max(0.05D, 1 - + (atk.getStat(StrifeStat.PROJECTILE_DAMAGE) - def.getStat(StrifeStat.PROJECTILE_REDUCTION)) - / 100); + return Math.max(0.05D, 1 + (atk.getStat(StrifeStat.PROJECTILE_DAMAGE) - + def.getStat(StrifeStat.PROJECTILE_REDUCTION)) / 100); } public static void applyLifeSteal(StrifeMob attacker, double damage, double healMultiplier, @@ -793,7 +805,7 @@ public static void applyHealthOnHit(StrifeMob attacker, double attackMultiplier, } public static boolean attemptBleed(StrifeMob attacker, StrifeMob defender, float rawPhysical, - float attackMult, Map abilityMods, boolean bypassBarrier) { + DamageModifiers mods, boolean bypassBarrier) { if (StrifePlugin.getInstance().getBarrierManager().isBarrierUp(defender)) { return false; } @@ -801,11 +813,12 @@ public static boolean attemptBleed(StrifeMob attacker, StrifeMob defender, float return false; } float chance = (attacker.getStat(StrifeStat.BLEED_CHANCE) + - abilityMods.getOrDefault(AbilityMod.BLEED_CHANCE, 0f)) / 100; + mods.getAbilityMods().getOrDefault(AbilityMod.BLEED_CHANCE, 0f)) / 100; if (chance >= rollDouble()) { - float damage = rawPhysical * attackMult * BLEED_PERCENT; + float multiplier = mods.isScaleChancesWithAttack() ? mods.getAttackMultiplier() : 1f; + float damage = rawPhysical * multiplier * BLEED_PERCENT; float damageMult = 1 + (attacker.getStat(StrifeStat.BLEED_DAMAGE) + - abilityMods.getOrDefault(AbilityMod.BLEED_DAMAGE, 0f)) / 100; + mods.getAbilityMods().getOrDefault(AbilityMod.BLEED_DAMAGE, 0f)) / 100; damage *= damageMult; damage *= 1 - defender.getStat(StrifeStat.BLEED_RESIST) / 100; applyBleed(defender, damage, bypassBarrier); @@ -825,8 +838,8 @@ public static void applyBleed(StrifeMob defender, float amount, boolean bypassBa public static void applyCorrupt(LivingEntity defender, float amount) { StrifePlugin.getInstance().getCorruptionManager().applyCorruption(defender, amount); defender.getWorld().playSound(defender.getEyeLocation(), Sound.ENTITY_WITHER_SHOOT, 0.7f, 2f); - defender.getWorld() - .spawnParticle(Particle.SMOKE_NORMAL, defender.getEyeLocation(), 10, 0.4, 0.4, 0.5, 0.1); + defender.getWorld().spawnParticle(Particle.SMOKE_NORMAL, + defender.getEyeLocation(), 10, 0.4, 0.4, 0.5, 0.1); } public static void doReflectedDamage(StrifeMob defender, StrifeMob attacker, @@ -916,13 +929,9 @@ public static void restoreEnergy(StrifeMob strifeMob, float amount) { public static AttackType getAttackType(EntityDamageByEntityEvent event) { if (event.getCause() == DamageCause.ENTITY_EXPLOSION) { - return AttackType.EXPLOSION; - } else if (event.getDamager() instanceof ShulkerBullet || event - .getDamager() instanceof SmallFireball || event.getDamager() instanceof WitherSkull || event - .getDamager() instanceof EvokerFangs) { - return AttackType.MAGIC; + return AttackType.AREA; } else if (event.getDamager() instanceof Projectile) { - return AttackType.RANGED; + return AttackType.PROJECTILE; } return AttackType.MELEE; } @@ -971,6 +980,13 @@ public static IndicatorData buildFloatIndicator(Player player) { return data; } + public static IndicatorData buildCritIndicator(Player player) { + IndicatorData data = new IndicatorData(IND_FLOAT_VECTOR.clone(), IndicatorStyle.FLOAT_UP); + data.addOwner(player); + data.setStage(5); + return data; + } + public enum DamageScale { FLAT, CASTER_STAT_PERCENT, @@ -1033,6 +1049,6 @@ public enum AbilityMod { } public enum AttackType { - MELEE, PROJECTILE, AREA, RANGED, MAGIC, EXPLOSION, OTHER + MELEE, PROJECTILE, AREA, OTHER } } diff --git a/src/main/java/land/face/strife/util/PlayerDataUtil.java b/src/main/java/land/face/strife/util/PlayerDataUtil.java index 02547cdf..1cba2a95 100644 --- a/src/main/java/land/face/strife/util/PlayerDataUtil.java +++ b/src/main/java/land/face/strife/util/PlayerDataUtil.java @@ -341,6 +341,12 @@ public static float getLifeSkillMaxExp(Champion champion, LifeSkillType type) { return StrifePlugin.getInstance().getSkillExperienceManager().getMaxExp(type, level); } + public static int getLifeSkillExpToLevel(Champion champion, LifeSkillType type) { + int level = champion.getLifeSkillLevel(type); + return (int) (StrifePlugin.getInstance().getSkillExperienceManager().getMaxExp(type, level) + - champion.getLifeSkillExp(type)); + } + public static float getSkillProgress(Champion champion, LifeSkillType type) { return champion.getSaveData().getSkillExp(type) / StrifePlugin.getInstance() .getSkillExperienceManager().getMaxExp(type, champion.getSaveData().getSkillLevel(type)); diff --git a/src/main/java/land/face/strife/util/ProjectileUtil.java b/src/main/java/land/face/strife/util/ProjectileUtil.java index 6382b9f0..f26627bf 100644 --- a/src/main/java/land/face/strife/util/ProjectileUtil.java +++ b/src/main/java/land/face/strife/util/ProjectileUtil.java @@ -72,15 +72,15 @@ public static int getTotalProjectiles(double initialProjectiles, double multiSho } public static void shootWand(StrifeMob mob, double attackMult) { - float projectileSpeed = 1 + (mob.getStat(StrifeStat.PROJECTILE_SPEED) / 100); + float projectileSpeed = 0.9f * (1 + mob.getStat(StrifeStat.PROJECTILE_SPEED) / 100); int projectiles = ProjectileUtil.getTotalProjectiles(1, mob.getStat(StrifeStat.MULTISHOT)); - ProjectileUtil.createMagicMissile(mob.getEntity(), attackMult, projectileSpeed, 0, 0.23, true); + ProjectileUtil.createMagicMissile(mob.getEntity(), attackMult, projectileSpeed, 0, 0.24, true); projectiles--; for (int i = projectiles; i > 0; i--) { ProjectileUtil.createMagicMissile(mob.getEntity(), attackMult, projectileSpeed, - randomWandOffset(projectiles), 0.23, true); + randomWandOffset(projectiles), 0.24, true); } mob.getEntity().getWorld() @@ -89,15 +89,15 @@ public static void shootWand(StrifeMob mob, double attackMult) { } public static void shootArrow(StrifeMob mob, float attackMult) { - float projectileSpeed = 2.5f * (1 + (mob.getStat(StrifeStat.PROJECTILE_SPEED) / 100)); + float projectileSpeed = 1.65f * (1 + (mob.getStat(StrifeStat.PROJECTILE_SPEED) / 100)); int projectiles = ProjectileUtil.getTotalProjectiles(1, mob.getStat(StrifeStat.MULTISHOT)); - ProjectileUtil.createArrow(mob.getEntity(), attackMult, projectileSpeed, 0, 0.17); + ProjectileUtil.createArrow(mob.getEntity(), attackMult, projectileSpeed, 0, 0.185); projectiles--; for (int i = projectiles; i > 0; i--) { ProjectileUtil.createArrow(mob.getEntity(), attackMult, projectileSpeed, - randomOffset(projectiles), 0.17); + randomOffset(projectiles), 0.185); } shotId++; } diff --git a/src/main/java/land/face/strife/util/SpecialStatusUtil.java b/src/main/java/land/face/strife/util/SpecialStatusUtil.java index f1bf36f7..1e5933dc 100644 --- a/src/main/java/land/face/strife/util/SpecialStatusUtil.java +++ b/src/main/java/land/face/strife/util/SpecialStatusUtil.java @@ -11,6 +11,7 @@ public class SpecialStatusUtil { private static final Map BURN_IMMUNE = new WeakHashMap<>(); + private static final Map WEAK_AGGRO = new WeakHashMap<>(); private static final Map FALL_IMMUNE = new WeakHashMap<>(); private static final Map SNEAK_IMMUNE = new WeakHashMap<>(); private static final Map SPAWNER_SPAWNED = new WeakHashMap<>(); @@ -38,6 +39,14 @@ public static boolean isBurnImmune(Entity e) { return BURN_IMMUNE.getOrDefault(e, false); } + public static void setWeakAggro(Entity e) { + WEAK_AGGRO.put(e, true); + } + + public static boolean isWeakAggro(Entity e) { + return WEAK_AGGRO.getOrDefault(e, false); + } + public static void setFallImmune(Entity e) { FALL_IMMUNE.put(e, true); } diff --git a/src/main/java/land/face/strife/util/StatUtil.java b/src/main/java/land/face/strife/util/StatUtil.java index 579fb58f..cdb1cf28 100644 --- a/src/main/java/land/face/strife/util/StatUtil.java +++ b/src/main/java/land/face/strife/util/StatUtil.java @@ -94,10 +94,6 @@ public static float getAttackTime(StrifeMob ae) { return attackTime; } - public static float getOverchargeMultiplier(StrifeMob ae) { - return 1 + (ae.getStat(StrifeStat.OVERCHARGE) / 100); - } - public static float getCriticalMultiplier(StrifeMob ae) { return 1 + (ae.getStat(StrifeStat.CRITICAL_DAMAGE) / 100); } diff --git a/src/main/java/land/face/strife/util/TargetingUtil.java b/src/main/java/land/face/strife/util/TargetingUtil.java index 44e47c1b..9ed598e5 100644 --- a/src/main/java/land/face/strife/util/TargetingUtil.java +++ b/src/main/java/land/face/strife/util/TargetingUtil.java @@ -22,6 +22,7 @@ import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.attribute.AttributeInstance; +import org.bukkit.block.BlockFace; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; @@ -108,6 +109,11 @@ public static Set getFriendlyEntities(StrifeMob caster, Set getEntitiesInArea(Location location, double radi return validTargets; } - public static Set getEntitiesInCone(LivingEntity originEntity, Location origin, - Vector direction, float length, float maxConeRadius) { + public static Set getEntitiesInCone(Location origin, Vector direction, float length, + float maxConeRadius) { Collection targetList = Objects.requireNonNull(origin.getWorld()) .getNearbyEntities(origin, length, length, length); targetList.removeIf(TargetingUtil::isInvalidTarget); @@ -163,20 +169,18 @@ public static Set getEntitiesInCone(LivingEntity originEntity, Loc validTargets.add((LivingEntity) entity); } } - targetList.removeAll(validTargets); + validTargets.retainAll(targetList); } - validTargets.removeIf(e -> !originEntity.hasLineOfSight(e)); return validTargets; } - public static Set getEntitiesInLine(LivingEntity caster, double range) { - Collection targetList = Objects.requireNonNull(caster.getLocation().getWorld()) - .getNearbyEntities(caster.getEyeLocation(), range, range, range); + public static Set getEntitiesInLine(Location location, double range) { + Collection targetList = Objects.requireNonNull(location.getWorld()) + .getNearbyEntities(location, range, range, range); targetList.removeIf(TargetingUtil::isInvalidTarget); Set validTargets = new HashSet<>(); for (float incRange = 0; incRange <= range + 0.01; incRange += 0.8) { - Location loc = caster.getEyeLocation().clone() - .add(caster.getEyeLocation().getDirection().clone().multiply(incRange)); + Location loc = location.clone().add(location.getDirection().clone().multiply(incRange)); for (Entity entity : targetList) { if (entityWithinRadius(entity, loc, 0)) { validTargets.add((LivingEntity) entity); @@ -187,25 +191,27 @@ public static Set getEntitiesInLine(LivingEntity caster, double ra } targetList.removeAll(validTargets); } - validTargets.removeIf(e -> !caster.hasLineOfSight(e)); return validTargets; } - public static LivingEntity getFirstEntityInLine(LivingEntity caster, double range) { - RayTraceResult result = caster.getWorld() - .rayTraceEntities(caster.getEyeLocation(), caster.getEyeLocation().getDirection(), range, - 0.8, entity -> isValidRaycastTarget(caster, entity)); + public static LivingEntity getFirstEntityInLine(LivingEntity caster, double range, + boolean friendly) { + RayTraceResult result = caster.getWorld().rayTraceEntities(caster.getEyeLocation(), + caster.getEyeLocation().getDirection(), range, 0.9, entity -> + isValidRaycastTarget(caster, entity) && friendly == isFriendly(caster, + (LivingEntity) entity)); if (result == null || result.getHitEntity() == null) { return null; } return (LivingEntity) result.getHitEntity(); } - public static boolean isInvalidTarget(Entity e) { - if (!e.isValid() || !(e instanceof LivingEntity) || e instanceof ArmorStand) { + private static boolean isInvalidTarget(Entity e) { + if (!e.isValid() || e.isInvulnerable() || !(e instanceof LivingEntity) + || e instanceof ArmorStand) { return true; } - if (e.hasMetadata("NPC")) { + if (e.hasMetadata("NPC") || e.hasMetadata("pet")) { return true; } if (e instanceof Player) { @@ -220,8 +226,11 @@ public static boolean isDetectionStand(LivingEntity le) { } public static ArmorStand buildAndRemoveDetectionStand(Location location) { - ArmorStand stando = location.getWorld().spawn(location, ArmorStand.class, - TargetingUtil::applyDetectionStandChanges); + Location spawnLoc = location.clone(); + spawnLoc.setY(-1); + ArmorStand stando = location.getWorld() + .spawn(spawnLoc, ArmorStand.class, TargetingUtil::applyDetectionStandChanges); + stando.teleport(location); Bukkit.getScheduler().runTaskLater(StrifePlugin.getInstance(), stando::remove, 1L); return stando; } @@ -235,24 +244,25 @@ private static void applyDetectionStandChanges(ArmorStand stando) { SpecialStatusUtil.setDetectionStand(stando); } - public static LivingEntity getTempStand(Location loc, float groundCheckRange) { - if (groundCheckRange < 1) { + public static LivingEntity getTempStand(Location loc, float verticalRange) { + if (verticalRange == -1) { return TargetingUtil.buildAndRemoveDetectionStand(loc); - } else { - for (int i = 0; i < groundCheckRange; i++) { - if (loc.getBlock().getType().isSolid()) { - loc.setY(loc.getBlockY() + 1.3); - return TargetingUtil.buildAndRemoveDetectionStand(loc); - } - loc.add(0, -1, 0); + } + Location detectionLocation = loc.toCenterLocation().clone(); + for (int i = 0; i < verticalRange; i++) { + if (detectionLocation.getBlock().getRelative(BlockFace.DOWN, i).getType().isSolid()) { + detectionLocation.add(0, -i + 0.6, 0); + return TargetingUtil.buildAndRemoveDetectionStand(detectionLocation); } - return null; } + return null; } private static boolean isValidRaycastTarget(LivingEntity caster, Entity entity) { - return entity instanceof LivingEntity && entity != caster && entity.isValid() && !entity - .hasMetadata("NPC"); + return entity.isValid() && !entity.isInvulnerable() && entity instanceof LivingEntity && + entity != caster && !entity.hasMetadata("NPC") && !entity.hasMetadata("pet") && + !(entity instanceof Player && (((Player) entity).getGameMode() == GameMode.CREATIVE + || ((Player) entity).getGameMode() == GameMode.SPECTATOR)); } private static boolean entityWithinRadius(Entity e, Location loc, float radius) { @@ -265,9 +275,10 @@ private static boolean entityWithinRadius(Entity e, Location loc, float radius) && Math.abs(loc.getY() - ey) < Math.max(e.getHeight(), 1.2) + radius; } - public static LivingEntity selectFirstEntityInSight(LivingEntity caster, double range) { + public static LivingEntity selectFirstEntityInSight(LivingEntity caster, double range, + boolean friendly) { LivingEntity mobTarget = TargetingUtil.getMobTarget(caster); - return mobTarget != null ? mobTarget : getFirstEntityInLine(caster, range); + return mobTarget != null ? mobTarget : getFirstEntityInLine(caster, range, friendly); } public static Location getTargetLocation(LivingEntity caster, LivingEntity target, double range, @@ -284,13 +295,11 @@ public static Location getTargetLocation(LivingEntity caster, LivingEntity targe RayTraceResult result; if (targetEntities) { result = caster.getWorld().rayTrace(caster.getEyeLocation(), - caster.getEyeLocation().getDirection(), range, - FluidCollisionMode.NEVER, true, 0.2, + caster.getEyeLocation().getDirection(), range, FluidCollisionMode.NEVER, true, 0.2, entity -> isValidRaycastTarget(caster, entity)); } else { - result = caster.getWorld() - .rayTraceBlocks(caster.getEyeLocation(), caster.getEyeLocation().getDirection(), range, - FluidCollisionMode.NEVER, true); + result = caster.getWorld().rayTraceBlocks(caster.getEyeLocation(), + caster.getEyeLocation().getDirection(), range, FluidCollisionMode.NEVER, true); } if (result == null) { LogUtil.printDebug(" - Using MAX RANGE location calculation"); diff --git a/src/main/resources/boosts.json b/src/main/resources/boosts.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/src/main/resources/boosts.json @@ -0,0 +1 @@ +[] \ No newline at end of file