mirror of
https://github.com/TotalFreedomMC/TF-ProjectKorra.git
synced 2025-02-11 03:30:10 +00:00
AvatarState
This commit is contained in:
parent
d106eb513a
commit
cafea60f7c
7 changed files with 276 additions and 13 deletions
|
@ -15,7 +15,7 @@ public class AbilityModuleManager {
|
|||
static ProjectKorra plugin;
|
||||
public static List<AbilityModule> ability;
|
||||
private final AbilityLoader<AbilityModule> loader;
|
||||
|
||||
|
||||
public static HashSet<String> abilities;
|
||||
public static HashSet<String> waterbendingabilities;
|
||||
public static HashSet<String> airbendingabilities;
|
||||
|
@ -24,9 +24,9 @@ public class AbilityModuleManager {
|
|||
public static HashSet<String> chiabilities;
|
||||
public static HashSet<String> shiftabilities;
|
||||
public static HashMap<String, String> authors;
|
||||
|
||||
|
||||
public static HashMap<String, String> descriptions;
|
||||
|
||||
|
||||
public AbilityModuleManager(final ProjectKorra plugin) {
|
||||
AbilityModuleManager.plugin = plugin;
|
||||
final File path = new File(plugin.getDataFolder().toString() + "/Abilities/");
|
||||
|
@ -46,9 +46,9 @@ public class AbilityModuleManager {
|
|||
ability = loader.load(AbilityModule.class);
|
||||
fill();
|
||||
}
|
||||
|
||||
|
||||
private void fill() {
|
||||
|
||||
|
||||
for (StockAbilities a: StockAbilities.values()) {
|
||||
if (StockAbilities.isAirbending(a)) {
|
||||
if (ProjectKorra.plugin.getConfig().getBoolean("Abilities.Air." + a.name() + ".Enabled")) {
|
||||
|
@ -57,34 +57,40 @@ public class AbilityModuleManager {
|
|||
descriptions.put(a.name(), ProjectKorra.plugin.getConfig().getString("Abilities.Air." + a.name() + ".Description"));
|
||||
}
|
||||
}
|
||||
if (StockAbilities.isWaterbending(a)) {
|
||||
else if (StockAbilities.isWaterbending(a)) {
|
||||
if (ProjectKorra.plugin.getConfig().getBoolean("Abilities.Water." + a.name() + ".Enabled")) {
|
||||
abilities.add(a.name());
|
||||
waterbendingabilities.add(a.name());
|
||||
descriptions.put(a.name(), ProjectKorra.plugin.getConfig().getString("Abilities.Water." + a.name() + ".Description"));
|
||||
}
|
||||
}
|
||||
if (StockAbilities.isEarthbending(a)) {
|
||||
else if (StockAbilities.isEarthbending(a)) {
|
||||
if (ProjectKorra.plugin.getConfig().getBoolean("Abilities.Earth." + a.name() + ".Enabled")) {
|
||||
abilities.add(a.name());
|
||||
earthbendingabilities.add(a.name());
|
||||
descriptions.put(a.name(), ProjectKorra.plugin.getConfig().getString("Abilities.Earth." + a.name() + ".Description"));
|
||||
}
|
||||
}
|
||||
if (StockAbilities.isFirebending(a)) {
|
||||
else if (StockAbilities.isFirebending(a)) {
|
||||
if (ProjectKorra.plugin.getConfig().getBoolean("Abilities.Fire." + a.name() + ".Enabled")) {
|
||||
abilities.add(a.name());
|
||||
firebendingabilities.add(a.name());
|
||||
descriptions.put(a.name(), ProjectKorra.plugin.getConfig().getString("Abilities.Fire." + a.name() + ".Description"));
|
||||
}
|
||||
}
|
||||
if (StockAbilities.isChiBlocking(a)) {
|
||||
else if (StockAbilities.isChiBlocking(a)) {
|
||||
if (ProjectKorra.plugin.getConfig().getBoolean("Abilities.Chi." + a.name() + ".Enabled")) {
|
||||
abilities.add(a.name());
|
||||
chiabilities.add(a.name());
|
||||
descriptions.put(a.name(), ProjectKorra.plugin.getConfig().getString("Abilities.Chi." + a.name() + ".Description"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (ProjectKorra.plugin.getConfig().getBoolean("Abilities." + a.name() + ".Enabled")) {
|
||||
abilities.add(a.name()); // AvatarState, etc.
|
||||
descriptions.put(a.name(), ProjectKorra.plugin.getConfig().getString("Abilities." + a.name() + ".Description"));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (AbilityModule ab: ability) {
|
||||
if (abilities.contains(ab.getName())) {
|
||||
|
|
85
src/com/projectkorra/ProjectKorra/Ability/AvatarState.java
Normal file
85
src/com/projectkorra/ProjectKorra/Ability/AvatarState.java
Normal file
|
@ -0,0 +1,85 @@
|
|||
package com.projectkorra.ProjectKorra.Ability;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import com.projectkorra.ProjectKorra.Flight;
|
||||
import com.projectkorra.ProjectKorra.Methods;
|
||||
|
||||
public class AvatarState {
|
||||
|
||||
public static ConcurrentHashMap<Player, AvatarState> instances = new ConcurrentHashMap<Player, AvatarState>();
|
||||
|
||||
private static final double factor = 5;
|
||||
|
||||
Player player;
|
||||
|
||||
// boolean canfly = false;
|
||||
|
||||
public AvatarState(Player player) {
|
||||
this.player = player;
|
||||
if (instances.containsKey(player)) {
|
||||
instances.remove(player);
|
||||
} else {
|
||||
new Flight(player);
|
||||
instances.put(player, this);
|
||||
}
|
||||
}
|
||||
|
||||
public static void manageAvatarStates() {
|
||||
for (Player player : instances.keySet()) {
|
||||
progress(player);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean progress(Player player) {
|
||||
return instances.get(player).progress();
|
||||
}
|
||||
|
||||
private boolean progress() {
|
||||
if (!Methods.canBend(player.getName(), StockAbilities.AvatarState.name())) {
|
||||
instances.remove(player);
|
||||
return false;
|
||||
}
|
||||
addPotionEffects();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void addPotionEffects() {
|
||||
int duration = 70;
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION,
|
||||
duration, 3));
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,
|
||||
duration, 2));
|
||||
player.addPotionEffect(new PotionEffect(
|
||||
PotionEffectType.DAMAGE_RESISTANCE, duration, 2));
|
||||
player.addPotionEffect(new PotionEffect(
|
||||
PotionEffectType.FIRE_RESISTANCE, duration, 2));
|
||||
}
|
||||
|
||||
public static boolean isAvatarState(Player player) {
|
||||
if (instances.containsKey(player))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static double getValue(double value) {
|
||||
return factor * value;
|
||||
}
|
||||
|
||||
public static int getValue(int value) {
|
||||
return (int) factor * value;
|
||||
}
|
||||
|
||||
public static ArrayList<Player> getPlayers() {
|
||||
ArrayList<Player> players = new ArrayList<Player>();
|
||||
for (Player player : instances.keySet()) {
|
||||
players.add(player);
|
||||
}
|
||||
return players;
|
||||
}
|
||||
}
|
|
@ -11,6 +11,7 @@ import org.bukkit.WorldType;
|
|||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.projectkorra.ProjectKorra.Ability.AvatarState;
|
||||
import com.projectkorra.ProjectKorra.airbending.AirPassive;
|
||||
import com.projectkorra.ProjectKorra.chiblocking.ChiPassive;
|
||||
import com.projectkorra.ProjectKorra.earthbending.EarthPassive;
|
||||
|
@ -46,6 +47,7 @@ public class BendingManager implements Runnable {
|
|||
time = System.currentTimeMillis();
|
||||
ProjectKorra.time_step = interval;
|
||||
|
||||
AvatarState.manageAvatarStates();
|
||||
AirPassive.handlePassive(Bukkit.getServer());
|
||||
ChiPassive.handlePassive();
|
||||
WaterPassive.handlePassive();
|
||||
|
|
|
@ -731,22 +731,26 @@ public class Commands {
|
|||
s.sendMessage(ChatColor.GRAY + ability + " - ");
|
||||
s.sendMessage(ChatColor.GRAY + AbilityModuleManager.descriptions.get(ability));
|
||||
}
|
||||
if (Methods.isWaterAbility(ability)) {
|
||||
else if (Methods.isWaterAbility(ability)) {
|
||||
s.sendMessage(ChatColor.AQUA + ability + " - ");
|
||||
s.sendMessage(ChatColor.AQUA + AbilityModuleManager.descriptions.get(ability));
|
||||
}
|
||||
if (Methods.isEarthAbility(ability)) {
|
||||
else if (Methods.isEarthAbility(ability)) {
|
||||
s.sendMessage(ChatColor.GREEN + ability + " - ");
|
||||
s.sendMessage(ChatColor.GREEN + AbilityModuleManager.descriptions.get(ability));
|
||||
}
|
||||
if (Methods.isFireAbility(ability)) {
|
||||
else if (Methods.isFireAbility(ability)) {
|
||||
s.sendMessage(ChatColor.RED + ability + " - ");
|
||||
s.sendMessage(ChatColor.RED + AbilityModuleManager.descriptions.get(ability));
|
||||
}
|
||||
if (Methods.isChiAbility(ability)) {
|
||||
else if (Methods.isChiAbility(ability)) {
|
||||
s.sendMessage(ChatColor.GOLD + ability + " - ");
|
||||
s.sendMessage(ChatColor.GOLD + AbilityModuleManager.descriptions.get(ability));
|
||||
}
|
||||
else {
|
||||
s.sendMessage(ChatColor.DARK_PURPLE + ability + " - ");
|
||||
s.sendMessage(ChatColor.DARK_PURPLE + AbilityModuleManager.descriptions.get(ability));
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -44,6 +44,14 @@ public class ConfigManager {
|
|||
|
||||
plugin.getConfig().addDefault("Properties.Chi.CanBendWithWeapons", true);
|
||||
|
||||
plugin.getConfig().addDefault("Abilities.AvatarState.Enabled", true);
|
||||
plugin.getConfig().addDefault("Abilities.AvatarState.Description", "The signature ability of the Avatar, this is a toggle. Click to activate to become "
|
||||
+ "nearly unstoppable. While in the Avatar State, the user takes severely reduced damage from "
|
||||
+ "all sources, regenerates health rapidly, and is granted extreme speed. Nearly all abilities "
|
||||
+ "are incredibly amplified in this state. Additionally, AirShield and FireJet become toggle-able "
|
||||
+ "abilities and last until you deactivate them or the Avatar State. Click again with the Avatar "
|
||||
+ "State selected to deactivate it.");
|
||||
|
||||
plugin.getConfig().addDefault("Abilities.Air.Passive.Factor", 0.3);
|
||||
plugin.getConfig().addDefault("Abilities.Air.Passive.Speed", 2);
|
||||
plugin.getConfig().addDefault("Abilities.Air.Passive.Jump", 3);
|
||||
|
|
128
src/com/projectkorra/ProjectKorra/Flight.java
Normal file
128
src/com/projectkorra/ProjectKorra/Flight.java
Normal file
|
@ -0,0 +1,128 @@
|
|||
package com.projectkorra.ProjectKorra;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.projectkorra.ProjectKorra.Ability.AvatarState;
|
||||
|
||||
public class Flight {
|
||||
|
||||
private static ConcurrentHashMap<Player, Flight> instances = new ConcurrentHashMap<Player, Flight>();
|
||||
|
||||
private static long duration = 5000;
|
||||
|
||||
private Player player = null, source = null;
|
||||
private boolean couldFly = false, wasFlying = false;
|
||||
private long time;
|
||||
|
||||
public Flight(Player player) {
|
||||
this(player, null);
|
||||
}
|
||||
|
||||
public Flight(Player player, Player source) {
|
||||
|
||||
if (instances.containsKey(player)) {
|
||||
Flight flight = instances.get(player);
|
||||
flight.refresh(source);
|
||||
instances.replace(player, flight);
|
||||
return;
|
||||
}
|
||||
|
||||
couldFly = player.getAllowFlight();
|
||||
wasFlying = player.isFlying();
|
||||
this.player = player;
|
||||
this.source = source;
|
||||
time = System.currentTimeMillis();
|
||||
instances.put(player, this);
|
||||
}
|
||||
|
||||
public static Player getLaunchedBy(Player player) {
|
||||
if (instances.containsKey(player)) {
|
||||
return instances.get(player).source;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void revert() {
|
||||
player.setAllowFlight(couldFly);
|
||||
player.setFlying(wasFlying);
|
||||
}
|
||||
|
||||
private void remove() {
|
||||
instances.remove(player);
|
||||
}
|
||||
|
||||
private void refresh(Player source) {
|
||||
this.source = source;
|
||||
time = System.currentTimeMillis();
|
||||
instances.replace(player, this);
|
||||
}
|
||||
|
||||
public static void handle() {
|
||||
|
||||
ArrayList<Player> players = new ArrayList<Player>();
|
||||
ArrayList<Player> newflyingplayers = new ArrayList<Player>();
|
||||
ArrayList<Player> avatarstateplayers = new ArrayList<Player>();
|
||||
ArrayList<Player> airscooterplayers = new ArrayList<Player>();
|
||||
ArrayList<Player> waterspoutplayers = new ArrayList<Player>();
|
||||
ArrayList<Player> airspoutplayers = new ArrayList<Player>();
|
||||
|
||||
players.addAll(Tornado.getPlayers());
|
||||
// players.addAll(Speed.getPlayers());
|
||||
players.addAll(FireJet.getPlayers());
|
||||
players.addAll(Catapult.getPlayers());
|
||||
avatarstateplayers = AvatarState.getPlayers();
|
||||
airscooterplayers = AirScooter.getPlayers();
|
||||
waterspoutplayers = WaterSpout.getPlayers();
|
||||
airspoutplayers = AirSpout.getPlayers();
|
||||
|
||||
for (Player player : instances.keySet()) {
|
||||
Flight flight = instances.get(player);
|
||||
if (avatarstateplayers.contains(player)
|
||||
|| airscooterplayers.contains(player)
|
||||
|| waterspoutplayers.contains(player)
|
||||
|| airspoutplayers.contains(player)) {
|
||||
continue;
|
||||
}
|
||||
if (Bloodbending.isBloodbended(player)) {
|
||||
player.setAllowFlight(true);
|
||||
player.setFlying(false);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (players.contains(player)) {
|
||||
flight.refresh(null);
|
||||
player.setAllowFlight(true);
|
||||
if (player.getGameMode() != GameMode.CREATIVE)
|
||||
player.setFlying(false);
|
||||
newflyingplayers.add(player);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (flight.source == null) {
|
||||
flight.revert();
|
||||
flight.remove();
|
||||
} else {
|
||||
if (System.currentTimeMillis() > flight.time + duration) {
|
||||
flight.remove();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void removeAll() {
|
||||
for (Player player : instances.keySet()) {
|
||||
Flight flight = instances.get(player);
|
||||
if (flight.source != null)
|
||||
flight.revert();
|
||||
flight.remove();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -3,6 +3,7 @@ package com.projectkorra.ProjectKorra;
|
|||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
@ -19,10 +20,13 @@ import org.bukkit.event.entity.EntityCombustEvent;
|
|||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.event.player.PlayerAnimationEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerToggleFlightEvent;
|
||||
import org.kitteh.tag.AsyncPlayerReceiveNameTagEvent;
|
||||
|
||||
import com.projectkorra.ProjectKorra.Ability.AvatarState;
|
||||
import com.projectkorra.ProjectKorra.chiblocking.ChiPassive;
|
||||
import com.projectkorra.ProjectKorra.earthbending.EarthPassive;
|
||||
import com.projectkorra.ProjectKorra.firebending.Enflamed;
|
||||
|
@ -77,6 +81,32 @@ public class PKListener implements Listener {
|
|||
Methods.saveBendingPlayer(e.getPlayer().getName());
|
||||
BendingPlayer.players.remove(e.getPlayer().getName());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onPlayerSwing(PlayerAnimationEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (Bloodbending.isBloodbended(player) || Paralyze.isParalyzed(player)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
String abil = Methods.getBoundAbility(player);
|
||||
if (abil == null) return;
|
||||
if (Methods.canBend(player.getName(), abil)) {
|
||||
if (abil == "AvatarState") {
|
||||
new AvatarState(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onPlayerToggleFlight(PlayerToggleFlightEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
if (Tornado.getplayers().contains(p) || Bloodbending.isBloodbended(p)
|
||||
|| FireJet.getPlayers().contains(p)
|
||||
|| AvatarState.getPlayers().contains(p)) {
|
||||
event.setCancelled(p.getGameMode() != GameMode.CREATIVE);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onEntityCombust(EntityCombustEvent event) {
|
||||
|
|
Loading…
Reference in a new issue