mirror of
https://github.com/TotalFreedomMC/TF-ProjectKorra.git
synced 2025-02-14 04:47:51 +00:00
Convert Suffocate to new system
This commit is contained in:
parent
1d907fe134
commit
187bf0ec98
2 changed files with 48 additions and 47 deletions
|
@ -19,7 +19,7 @@ public class AirbendingManager implements Runnable {
|
||||||
AirPassive.handlePassive(Bukkit.getServer());
|
AirPassive.handlePassive(Bukkit.getServer());
|
||||||
AirBurst.progressAll(StockAbilities.AirBurst);
|
AirBurst.progressAll(StockAbilities.AirBurst);
|
||||||
AirScooter.progressAll(StockAbilities.AirScooter);
|
AirScooter.progressAll(StockAbilities.AirScooter);
|
||||||
Suffocate.progressAll();
|
Suffocate.progressAll(StockAbilities.Suffocate);
|
||||||
AirSpout.progressAll(StockAbilities.AirSpout);
|
AirSpout.progressAll(StockAbilities.AirSpout);
|
||||||
AirBubble.handleBubbles(Bukkit.getServer());
|
AirBubble.handleBubbles(Bukkit.getServer());
|
||||||
AirSuction.progressAll();
|
AirSuction.progressAll();
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
package com.projectkorra.ProjectKorra.airbending;
|
package com.projectkorra.ProjectKorra.airbending;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -19,6 +18,8 @@ import com.projectkorra.ProjectKorra.BendingPlayer;
|
||||||
import com.projectkorra.ProjectKorra.GeneralMethods;
|
import com.projectkorra.ProjectKorra.GeneralMethods;
|
||||||
import com.projectkorra.ProjectKorra.ProjectKorra;
|
import com.projectkorra.ProjectKorra.ProjectKorra;
|
||||||
import com.projectkorra.ProjectKorra.Ability.AvatarState;
|
import com.projectkorra.ProjectKorra.Ability.AvatarState;
|
||||||
|
import com.projectkorra.ProjectKorra.Ability.BaseAbility;
|
||||||
|
import com.projectkorra.ProjectKorra.Ability.StockAbilities;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Suffocate
|
* Suffocate
|
||||||
|
@ -30,14 +31,11 @@ import com.projectkorra.ProjectKorra.Ability.AvatarState;
|
||||||
* be used on multiple entities within a large radius.
|
* be used on multiple entities within a large radius.
|
||||||
* If the user is damaged while performing this ability then the ability is removed.
|
* If the user is damaged while performing this ability then the ability is removed.
|
||||||
*/
|
*/
|
||||||
public class Suffocate {
|
public class Suffocate extends BaseAbility {
|
||||||
public static enum SpiralType {
|
public static enum SpiralType {
|
||||||
HORIZONTAL1, HORIZONTAL2, VERTICAL1, VERTICAL2, DIAGONAL1, DIAGONAL2
|
HORIZONTAL1, HORIZONTAL2, VERTICAL1, VERTICAL2, DIAGONAL1, DIAGONAL2
|
||||||
};
|
};
|
||||||
|
|
||||||
private static ConcurrentHashMap<Player, Suffocate> instances = new ConcurrentHashMap<Player, Suffocate>();
|
|
||||||
|
|
||||||
private static FileConfiguration config = ProjectKorra.plugin.getConfig();
|
|
||||||
private static final boolean CAN_SUFFOCATE_UNDEAD = config.getBoolean("Abilities.Air.Suffocate.CanBeUsedOnUndeadMobs");
|
private static final boolean CAN_SUFFOCATE_UNDEAD = config.getBoolean("Abilities.Air.Suffocate.CanBeUsedOnUndeadMobs");
|
||||||
private static final boolean REQUIRE_CONSTANT_AIM = config.getBoolean("Abilities.Air.Suffocate.RequireConstantAim");
|
private static final boolean REQUIRE_CONSTANT_AIM = config.getBoolean("Abilities.Air.Suffocate.RequireConstantAim");
|
||||||
private static final double ANIM_RADIUS = config.getDouble("Abilities.Air.Suffocate.AnimationRadius");
|
private static final double ANIM_RADIUS = config.getDouble("Abilities.Air.Suffocate.AnimationRadius");
|
||||||
|
@ -59,6 +57,7 @@ public class Suffocate {
|
||||||
private static double BLIND_INTERVAL = config.getDouble("Abilities.Air.Suffocate.BlindInterval");
|
private static double BLIND_INTERVAL = config.getDouble("Abilities.Air.Suffocate.BlindInterval");
|
||||||
|
|
||||||
private Player player;
|
private Player player;
|
||||||
|
private UUID uuid;
|
||||||
private BendingPlayer bplayer;
|
private BendingPlayer bplayer;
|
||||||
private boolean started = false;
|
private boolean started = false;
|
||||||
private long time;
|
private long time;
|
||||||
|
@ -77,6 +76,7 @@ public class Suffocate {
|
||||||
|
|
||||||
public Suffocate(Player player) {
|
public Suffocate(Player player) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
this.uuid = player.getUniqueId();
|
||||||
bplayer = GeneralMethods.getBendingPlayer(player.getName());
|
bplayer = GeneralMethods.getBendingPlayer(player.getName());
|
||||||
targets = new ArrayList<LivingEntity>();
|
targets = new ArrayList<LivingEntity>();
|
||||||
tasks = new ArrayList<BukkitRunnable>();
|
tasks = new ArrayList<BukkitRunnable>();
|
||||||
|
@ -101,7 +101,7 @@ public class Suffocate {
|
||||||
blindDelay = BLIND_DELAY;
|
blindDelay = BLIND_DELAY;
|
||||||
blindRepeat = BLIND_INTERVAL;
|
blindRepeat = BLIND_INTERVAL;
|
||||||
|
|
||||||
if(instances.containsKey(player))
|
if(getInstances().containsKey(player.getUniqueId()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(AvatarState.isAvatarState(player)) {
|
if(AvatarState.isAvatarState(player)) {
|
||||||
|
@ -146,25 +146,30 @@ public class Suffocate {
|
||||||
else if(bplayer.isOnCooldown("suffocate"))
|
else if(bplayer.isOnCooldown("suffocate"))
|
||||||
return;
|
return;
|
||||||
bplayer.addCooldown("suffocate", cooldown);
|
bplayer.addCooldown("suffocate", cooldown);
|
||||||
instances.put(player,this);
|
//instances.put(player,this);
|
||||||
|
putInstance(StockAbilities.Suffocate, uuid, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Progresses this instance of Suffocate by 1 tick. **/
|
/**
|
||||||
public void progress() {
|
* Progresses this instance of Suffocate by 1 tick.
|
||||||
|
*
|
||||||
|
* @return true If progress does not stop, progresses succesfully
|
||||||
|
*/
|
||||||
|
public boolean progress() {
|
||||||
if(targets.size() == 0) {
|
if(targets.size() == 0) {
|
||||||
remove();
|
remove();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
if (player.isDead() || !player.isOnline()) {
|
if (player.isDead() || !player.isOnline()) {
|
||||||
remove();
|
remove();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
String ability = GeneralMethods.getBoundAbility(player);
|
String ability = GeneralMethods.getBoundAbility(player);
|
||||||
if(ability == null
|
if(ability == null
|
||||||
|| !ability.equalsIgnoreCase("Suffocate")
|
|| !ability.equalsIgnoreCase("Suffocate")
|
||||||
|| !GeneralMethods.canBend(player.getName(), "Suffocate")) {
|
|| !GeneralMethods.canBend(player.getName(), "Suffocate")) {
|
||||||
remove();
|
remove();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < targets.size(); i++) {
|
for(int i = 0; i < targets.size(); i++) {
|
||||||
|
@ -185,7 +190,7 @@ public class Suffocate {
|
||||||
}
|
}
|
||||||
if(targets.size() == 0) {
|
if(targets.size() == 0) {
|
||||||
remove();
|
remove();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(reqConstantAim) {
|
if(reqConstantAim) {
|
||||||
|
@ -203,12 +208,12 @@ public class Suffocate {
|
||||||
}
|
}
|
||||||
if(targets.size() == 0) {
|
if(targets.size() == 0) {
|
||||||
remove();
|
remove();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(System.currentTimeMillis() - time < chargeTime) {
|
if(System.currentTimeMillis() - time < chargeTime) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
else if(!started) {
|
else if(!started) {
|
||||||
started = true;
|
started = true;
|
||||||
|
@ -246,8 +251,9 @@ public class Suffocate {
|
||||||
animate();
|
animate();
|
||||||
if(!player.isSneaking()) {
|
if(!player.isSneaking()) {
|
||||||
remove();
|
remove();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -411,15 +417,10 @@ public class Suffocate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Progresses every instance of Suffocate by 1 tick **/
|
|
||||||
public static void progressAll() {
|
|
||||||
for(Suffocate suff : instances.values())
|
|
||||||
suff.progress();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Removes this instance of the ability **/
|
/** Removes this instance of the ability **/
|
||||||
public void remove() {
|
public void remove() {
|
||||||
instances.remove(player);
|
//instances.remove(player);
|
||||||
|
removeInstance(StockAbilities.Suffocate, uuid);
|
||||||
for(int i = 0; i < tasks.size(); i++) {
|
for(int i = 0; i < tasks.size(); i++) {
|
||||||
tasks.get(i).cancel();
|
tasks.get(i).cancel();
|
||||||
tasks.remove(i);
|
tasks.remove(i);
|
||||||
|
@ -433,10 +434,10 @@ public class Suffocate {
|
||||||
* @param causer: the player causing this instance to be removed
|
* @param causer: the player causing this instance to be removed
|
||||||
* **/
|
* **/
|
||||||
public static boolean removeAtLocation(Player causer, Location loc, double radius) {
|
public static boolean removeAtLocation(Player causer, Location loc, double radius) {
|
||||||
Iterator<Player> it = instances.keySet().iterator();
|
Iterator<UUID> it = getInstances().keySet().iterator();
|
||||||
while(it.hasNext()) {
|
while(it.hasNext()) {
|
||||||
Player key = it.next();
|
UUID key = it.next();
|
||||||
Suffocate val = instances.get(key);
|
Suffocate val = (Suffocate) getInstances().get(key);
|
||||||
|
|
||||||
if (causer == null || !key.equals(causer)) {
|
if (causer == null || !key.equals(causer)) {
|
||||||
Location playerLoc = val.getPlayer().getLocation();
|
Location playerLoc = val.getPlayer().getLocation();
|
||||||
|
@ -451,21 +452,13 @@ public class Suffocate {
|
||||||
|
|
||||||
/** Removes an instance of Suffocate if player is the one suffocating entities **/
|
/** Removes an instance of Suffocate if player is the one suffocating entities **/
|
||||||
public static void remove(Player player) {
|
public static void remove(Player player) {
|
||||||
if (instances.containsKey(player))
|
if (getInstances().containsKey(player.getUniqueId()))
|
||||||
instances.get(player).remove();
|
getInstances().get(player.getUniqueId()).remove();
|
||||||
}
|
|
||||||
|
|
||||||
/** Removes every instance of Suffocate **/
|
|
||||||
public static void removeAll() {
|
|
||||||
Enumeration<Player> keys = instances.keys();
|
|
||||||
while(keys.hasMoreElements()) {
|
|
||||||
instances.get(keys.nextElement()).remove();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Determines if a player is Suffocating entities **/
|
/** Determines if a player is Suffocating entities **/
|
||||||
public static boolean isChannelingSphere(Player player){
|
public static boolean isChannelingSphere(Player player){
|
||||||
if(instances.containsKey(player)) return true;
|
if (getInstances().containsKey(player.getUniqueId())) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -477,25 +470,27 @@ public class Suffocate {
|
||||||
|
|
||||||
/** Stops an entity from being suffocated **/
|
/** Stops an entity from being suffocated **/
|
||||||
public static void breakSuffocate(Entity entity) {
|
public static void breakSuffocate(Entity entity) {
|
||||||
for (Player player : instances.keySet()) {
|
for (UUID uuid : getInstances().keySet()) {
|
||||||
if (instances.get(player).targets.contains(entity)) {
|
Suffocate suffocate = (Suffocate) getInstances().get(uuid);
|
||||||
instances.get(player).breakSuffocateLocal(entity);
|
if (suffocate.targets.contains(entity)) {
|
||||||
|
suffocate.breakSuffocateLocal(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Checks if an entity is being suffocated **/
|
/** Checks if an entity is being suffocated **/
|
||||||
public static boolean isBreathbent(Entity entity) {
|
public static boolean isBreathbent(Entity entity) {
|
||||||
for (Player player : instances.keySet()) {
|
for (UUID uuid : getInstances().keySet()) {
|
||||||
if (instances.get(player).targets.contains(entity)) {
|
Suffocate suffocate = (Suffocate) getInstances().get(uuid);
|
||||||
return instances.get(player).started;
|
if (suffocate.targets.contains(entity)) {
|
||||||
|
return suffocate.started;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConcurrentHashMap<Player, Suffocate> getInstances() {
|
public static ConcurrentHashMap<UUID, ? extends BaseAbility> getInstances() {
|
||||||
return instances;
|
return getInstance(StockAbilities.Suffocate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
|
@ -677,4 +672,10 @@ public class Suffocate {
|
||||||
public void setBlindRepeat(double blindRepeat) {
|
public void setBlindRepeat(double blindRepeat) {
|
||||||
this.blindRepeat = blindRepeat;
|
this.blindRepeat = blindRepeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reloadVariables() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue