mirror of
https://github.com/TotalFreedomMC/TF-ProjectKorra.git
synced 2025-02-11 11:40:40 +00:00
Rework Suffocate's code
This commit is contained in:
parent
feb44e39d6
commit
dabd53afb0
1 changed files with 67 additions and 123 deletions
|
@ -1,6 +1,8 @@
|
|||
package com.projectkorra.ProjectKorra.airbending;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
@ -21,12 +23,11 @@ public class Suffocate {
|
|||
|
||||
public static ConcurrentHashMap<Player, Suffocate> instances = new ConcurrentHashMap<Player, Suffocate>();
|
||||
|
||||
ConcurrentHashMap<Entity, Location> targetentities = new ConcurrentHashMap<Entity, Location>();
|
||||
|
||||
private static boolean canBeUsedOnUndead = ProjectKorra.plugin.getConfig().getBoolean("Abilities.Air.Suffocate.CanBeUsedOnUndeadMobs");
|
||||
private int range = ProjectKorra.plugin.getConfig().getInt("Abilities.Air.Suffocate.Range");
|
||||
private double damage = ProjectKorra.plugin.getConfig().getDouble("Abilities.Air.Suffocate.Damage");
|
||||
|
||||
private Map<Entity, Location> targets = new HashMap<Entity, Location>();
|
||||
private Player player;
|
||||
private long time;
|
||||
private long warmup = 2000;
|
||||
|
@ -42,142 +43,94 @@ public class Suffocate {
|
|||
|
||||
if (AvatarState.isAvatarState(player)) {
|
||||
range = AvatarState.getValue(range);
|
||||
for (Entity entity : Methods.getEntitiesAroundPoint(player.getLocation(), range)) {
|
||||
if (entity instanceof LivingEntity) {
|
||||
if (entity instanceof Player) {
|
||||
if (Methods.isRegionProtectedFromBuild(player, "Bloodbending", entity.getLocation()) || entity.getEntityId() == player.getEntityId())
|
||||
continue;
|
||||
}
|
||||
if (System.currentTimeMillis() >= time + warmup) {
|
||||
Methods.damageEntity(player, entity, 0);
|
||||
}
|
||||
targetentities.put(entity, entity.getLocation().clone());
|
||||
for (Entity entity: Methods.getEntitiesAroundPoint(player.getLocation(), range)) {
|
||||
if (entity instanceof LivingEntity && entity.getEntityId() != player.getEntityId()) {
|
||||
targets.put(entity, entity.getLocation());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Entity target = Methods.getTargetedEntity(player, range, new ArrayList<Entity>());
|
||||
if (target == null)
|
||||
return;
|
||||
if (!(target instanceof LivingEntity)|| Methods.isRegionProtectedFromBuild(player, "Bloodbending", target.getLocation()))
|
||||
return;
|
||||
if (!canBeUsedOnUndead && isUndead(target)) {
|
||||
return;
|
||||
Entity en = Methods.getTargetedEntity(player, range, new ArrayList<Entity>());
|
||||
if (en != null && en instanceof LivingEntity && en.getEntityId() != player.getEntityId()) {
|
||||
targets.put(en, en.getLocation());
|
||||
}
|
||||
if (System.currentTimeMillis() >= time + warmup) {
|
||||
Methods.damageEntity(player, target, 0);
|
||||
}
|
||||
targetentities.put(target, target.getLocation().clone());
|
||||
}
|
||||
|
||||
this.player = player;
|
||||
instances.put(player, this);
|
||||
time = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
private void progress() {
|
||||
|
||||
if (!player.isSneaking()) {
|
||||
remove(player);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!canBeUsedOnUndead) {
|
||||
for (Entity entity: targetentities.keySet()) {
|
||||
if (isUndead(entity)) {
|
||||
targetentities.remove(entity);
|
||||
}
|
||||
}
|
||||
if (player.isDead()) {
|
||||
remove(player);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Methods.canBend(player.getName(), "Suffocate")) {
|
||||
remove(player);
|
||||
return;
|
||||
}
|
||||
if (Methods.getBoundAbility(player) == null) {
|
||||
remove(player);
|
||||
return;
|
||||
}
|
||||
if (!Methods.getBoundAbility(player).equalsIgnoreCase("Suffocate")) {
|
||||
|
||||
if (Methods.getBoundAbility(player) == null || !Methods.getBoundAbility(player).equalsIgnoreCase("Suffocate")) {
|
||||
remove(player);
|
||||
return;
|
||||
}
|
||||
|
||||
if (AvatarState.isAvatarState(player)) {
|
||||
ArrayList<Entity> entities = new ArrayList<Entity>();
|
||||
for (Entity entity : Methods.getEntitiesAroundPoint(player.getLocation(), range)) {
|
||||
if (Methods.isRegionProtectedFromBuild(player, "Suffocate", entity.getLocation()))
|
||||
continue;
|
||||
if (entity.getEntityId() == player.getEntityId()) continue;
|
||||
entities.add(entity);
|
||||
if (entity.getLocation().distance(player.getLocation()) >= range) {
|
||||
for (Entity entity: targets.keySet()) {
|
||||
if (targets.isEmpty()) {
|
||||
remove(player);
|
||||
return;
|
||||
}
|
||||
if (isUndead(entity) && !canBeUsedOnUndead) {
|
||||
breakSuffocate(entity);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Methods.isRegionProtectedFromBuild(player, "Suffocate", entity.getLocation())) {
|
||||
remove(player);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (entity.getLocation().distance(player.getLocation()) >= range) {
|
||||
breakSuffocate(entity);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Methods.isObstructed(player.getLocation(), entity.getLocation())) {
|
||||
breakSuffocate(entity);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (entity instanceof Player) {
|
||||
if (AvatarState.isAvatarState((Player) entity)) {
|
||||
breakSuffocate(entity);
|
||||
}
|
||||
if (!targetentities.containsKey(entity) && entity instanceof LivingEntity) {
|
||||
if (System.currentTimeMillis() >= time + warmup) {
|
||||
Methods.damageEntity(player, entity, damage);
|
||||
}
|
||||
targetentities.put(entity, entity.getLocation().clone());
|
||||
}
|
||||
if (entity instanceof LivingEntity) {
|
||||
if (Methods.isObstructed(player.getLocation(), entity.getLocation())) {
|
||||
breakSuffocate(entity);
|
||||
}
|
||||
if (System.currentTimeMillis() >= time + warmup) {
|
||||
Methods.damageEntity(player, entity, damage);
|
||||
}
|
||||
new TempPotionEffect((LivingEntity) entity, slow);
|
||||
new TempPotionEffect((LivingEntity) entity, nausea);
|
||||
entity.setFallDistance(0);
|
||||
if (entity instanceof Creature) {
|
||||
((Creature) entity).setTarget(player);
|
||||
}
|
||||
if (entity instanceof Player) {
|
||||
if (AvatarState.isAvatarState((Player) entity)) {
|
||||
remove(player);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (entity.isDead()) {
|
||||
instances.remove(player);
|
||||
}
|
||||
entity.teleport(entity);
|
||||
for(Location airsphere : Methods.getCircle(entity.getLocation(), 3, 3, false, true, 0)) {
|
||||
Methods.playAirbendingParticles(airsphere, 1);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
for (Entity entity : targetentities.keySet()) {
|
||||
if (!entities.contains(entity))
|
||||
targetentities.remove(entity);
|
||||
|
||||
if (entity.isDead()) {
|
||||
breakSuffocate(entity);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
for (Entity entity : targetentities.keySet()) {
|
||||
if(entity instanceof LivingEntity) {
|
||||
if (Methods.isObstructed(player.getLocation(), entity.getLocation())) {
|
||||
breakSuffocate(entity);
|
||||
}
|
||||
if (System.currentTimeMillis() >= time + warmup) {
|
||||
Methods.damageEntity(player, entity, damage);
|
||||
}
|
||||
new TempPotionEffect((LivingEntity) entity, slow);
|
||||
new TempPotionEffect((LivingEntity) entity, nausea);
|
||||
entity.setFallDistance(0);
|
||||
if (entity instanceof Creature) {
|
||||
((Creature) entity).setTarget(null);
|
||||
}
|
||||
if (entity instanceof Player) {
|
||||
if (AvatarState.isAvatarState((Player) entity)) {
|
||||
remove(player);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (entity.isDead()) {
|
||||
instances.remove(player);
|
||||
}
|
||||
entity.teleport(entity);
|
||||
for(Location airsphere : Methods.getCircle(entity.getLocation(), 3, 3, true, true, 0)) {
|
||||
Methods.playAirbendingParticles(airsphere, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (entity instanceof Creature) {
|
||||
((Creature) entity).setTarget(player);
|
||||
}
|
||||
|
||||
for(Location airsphere : Methods.getCircle(entity.getLocation(), 3, 3, false, true, 0)) {
|
||||
Methods.playAirbendingParticles(airsphere, 1);
|
||||
}
|
||||
entity.setFallDistance(0);
|
||||
new TempPotionEffect((LivingEntity) entity, slow);
|
||||
new TempPotionEffect((LivingEntity) entity, nausea);
|
||||
if (System.currentTimeMillis() >= time + warmup) {
|
||||
Methods.damageEntity(player, entity, damage);
|
||||
entity.teleport(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -196,15 +149,15 @@ public class Suffocate {
|
|||
|
||||
public static void breakSuffocate(Entity entity) {
|
||||
for (Player player : instances.keySet()) {
|
||||
if (instances.get(player).targetentities.containsKey(entity)) {
|
||||
instances.remove(player);
|
||||
if (instances.get(player).targets.containsKey(entity)) {
|
||||
instances.get(player).targets.remove(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isBreathbent(Entity entity) {
|
||||
for (Player player : instances.keySet()) {
|
||||
if (instances.get(player).targetentities.containsKey(entity)) {
|
||||
if (instances.get(player).targets.containsKey(entity)) {
|
||||
if (System.currentTimeMillis() >= instances.get(player).time + instances.get(player).warmup) {
|
||||
return true;
|
||||
}
|
||||
|
@ -231,15 +184,6 @@ public class Suffocate {
|
|||
return false;
|
||||
}
|
||||
|
||||
public static Location getSuffocateLocation(Entity entity) {
|
||||
for (Player player : instances.keySet()) {
|
||||
if (instances.get(player).targetentities.containsKey(entity)) {
|
||||
return instances.get(player).targetentities.get(entity);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isChannelingSphere(Player player){
|
||||
if(instances.containsKey(player)) return true;
|
||||
return false;
|
||||
|
|
Loading…
Reference in a new issue