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;
|
package com.projectkorra.ProjectKorra.airbending;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
@ -21,12 +23,11 @@ public class Suffocate {
|
||||||
|
|
||||||
public static ConcurrentHashMap<Player, Suffocate> instances = new ConcurrentHashMap<Player, 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 static boolean canBeUsedOnUndead = ProjectKorra.plugin.getConfig().getBoolean("Abilities.Air.Suffocate.CanBeUsedOnUndeadMobs");
|
||||||
private int range = ProjectKorra.plugin.getConfig().getInt("Abilities.Air.Suffocate.Range");
|
private int range = ProjectKorra.plugin.getConfig().getInt("Abilities.Air.Suffocate.Range");
|
||||||
private double damage = ProjectKorra.plugin.getConfig().getDouble("Abilities.Air.Suffocate.Damage");
|
private double damage = ProjectKorra.plugin.getConfig().getDouble("Abilities.Air.Suffocate.Damage");
|
||||||
|
|
||||||
|
private Map<Entity, Location> targets = new HashMap<Entity, Location>();
|
||||||
private Player player;
|
private Player player;
|
||||||
private long time;
|
private long time;
|
||||||
private long warmup = 2000;
|
private long warmup = 2000;
|
||||||
|
@ -39,145 +40,97 @@ public class Suffocate {
|
||||||
remove(player);
|
remove(player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (AvatarState.isAvatarState(player)) {
|
if (AvatarState.isAvatarState(player)) {
|
||||||
range = AvatarState.getValue(range);
|
range = AvatarState.getValue(range);
|
||||||
for (Entity entity : Methods.getEntitiesAroundPoint(player.getLocation(), range)) {
|
for (Entity entity: Methods.getEntitiesAroundPoint(player.getLocation(), range)) {
|
||||||
if (entity instanceof LivingEntity) {
|
if (entity instanceof LivingEntity && entity.getEntityId() != player.getEntityId()) {
|
||||||
if (entity instanceof Player) {
|
targets.put(entity, entity.getLocation());
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Entity target = Methods.getTargetedEntity(player, range, new ArrayList<Entity>());
|
Entity en = Methods.getTargetedEntity(player, range, new ArrayList<Entity>());
|
||||||
if (target == null)
|
if (en != null && en instanceof LivingEntity && en.getEntityId() != player.getEntityId()) {
|
||||||
return;
|
targets.put(en, en.getLocation());
|
||||||
if (!(target instanceof LivingEntity)|| Methods.isRegionProtectedFromBuild(player, "Bloodbending", target.getLocation()))
|
|
||||||
return;
|
|
||||||
if (!canBeUsedOnUndead && isUndead(target)) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (System.currentTimeMillis() >= time + warmup) {
|
|
||||||
Methods.damageEntity(player, target, 0);
|
|
||||||
}
|
|
||||||
targetentities.put(target, target.getLocation().clone());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.player = player;
|
this.player = player;
|
||||||
instances.put(player, this);
|
instances.put(player, this);
|
||||||
time = System.currentTimeMillis();
|
time = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void progress() {
|
private void progress() {
|
||||||
|
|
||||||
if (!player.isSneaking()) {
|
if (!player.isSneaking()) {
|
||||||
remove(player);
|
remove(player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!canBeUsedOnUndead) {
|
if (player.isDead()) {
|
||||||
for (Entity entity: targetentities.keySet()) {
|
remove(player);
|
||||||
if (isUndead(entity)) {
|
return;
|
||||||
targetentities.remove(entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Methods.canBend(player.getName(), "Suffocate")) {
|
if (!Methods.canBend(player.getName(), "Suffocate")) {
|
||||||
remove(player);
|
remove(player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Methods.getBoundAbility(player) == null) {
|
|
||||||
|
if (Methods.getBoundAbility(player) == null || !Methods.getBoundAbility(player).equalsIgnoreCase("Suffocate")) {
|
||||||
remove(player);
|
remove(player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!Methods.getBoundAbility(player).equalsIgnoreCase("Suffocate")) {
|
|
||||||
remove(player);
|
for (Entity entity: targets.keySet()) {
|
||||||
return;
|
if (targets.isEmpty()) {
|
||||||
}
|
remove(player);
|
||||||
|
return;
|
||||||
if (AvatarState.isAvatarState(player)) {
|
}
|
||||||
ArrayList<Entity> entities = new ArrayList<Entity>();
|
if (isUndead(entity) && !canBeUsedOnUndead) {
|
||||||
for (Entity entity : Methods.getEntitiesAroundPoint(player.getLocation(), range)) {
|
breakSuffocate(entity);
|
||||||
if (Methods.isRegionProtectedFromBuild(player, "Suffocate", entity.getLocation()))
|
continue;
|
||||||
continue;
|
}
|
||||||
if (entity.getEntityId() == player.getEntityId()) continue;
|
|
||||||
entities.add(entity);
|
if (Methods.isRegionProtectedFromBuild(player, "Suffocate", entity.getLocation())) {
|
||||||
if (entity.getLocation().distance(player.getLocation()) >= range) {
|
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);
|
breakSuffocate(entity);
|
||||||
}
|
continue;
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entity entity : targetentities.keySet()) {
|
|
||||||
if (!entities.contains(entity))
|
if (entity.isDead()) {
|
||||||
targetentities.remove(entity);
|
breakSuffocate(entity);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
for (Entity entity : targetentities.keySet()) {
|
if (entity instanceof Creature) {
|
||||||
if(entity instanceof LivingEntity) {
|
((Creature) entity).setTarget(player);
|
||||||
if (Methods.isObstructed(player.getLocation(), entity.getLocation())) {
|
}
|
||||||
breakSuffocate(entity);
|
|
||||||
}
|
for(Location airsphere : Methods.getCircle(entity.getLocation(), 3, 3, false, true, 0)) {
|
||||||
if (System.currentTimeMillis() >= time + warmup) {
|
Methods.playAirbendingParticles(airsphere, 1);
|
||||||
Methods.damageEntity(player, entity, damage);
|
}
|
||||||
}
|
entity.setFallDistance(0);
|
||||||
new TempPotionEffect((LivingEntity) entity, slow);
|
new TempPotionEffect((LivingEntity) entity, slow);
|
||||||
new TempPotionEffect((LivingEntity) entity, nausea);
|
new TempPotionEffect((LivingEntity) entity, nausea);
|
||||||
entity.setFallDistance(0);
|
if (System.currentTimeMillis() >= time + warmup) {
|
||||||
if (entity instanceof Creature) {
|
Methods.damageEntity(player, entity, damage);
|
||||||
((Creature) entity).setTarget(null);
|
entity.teleport(entity);
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -196,15 +149,15 @@ public class Suffocate {
|
||||||
|
|
||||||
public static void breakSuffocate(Entity entity) {
|
public static void breakSuffocate(Entity entity) {
|
||||||
for (Player player : instances.keySet()) {
|
for (Player player : instances.keySet()) {
|
||||||
if (instances.get(player).targetentities.containsKey(entity)) {
|
if (instances.get(player).targets.containsKey(entity)) {
|
||||||
instances.remove(player);
|
instances.get(player).targets.remove(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isBreathbent(Entity entity) {
|
public static boolean isBreathbent(Entity entity) {
|
||||||
for (Player player : instances.keySet()) {
|
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) {
|
if (System.currentTimeMillis() >= instances.get(player).time + instances.get(player).warmup) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -231,15 +184,6 @@ public class Suffocate {
|
||||||
return false;
|
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){
|
public static boolean isChannelingSphere(Player player){
|
||||||
if(instances.containsKey(player)) return true;
|
if(instances.containsKey(player)) return true;
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in a new issue