mirror of
https://github.com/TotalFreedomMC/TF-ProjectKorra.git
synced 2024-12-23 00:15:05 +00:00
Updated PassiveHandler
This commit is contained in:
parent
b4ec8c30e4
commit
736998dd4a
5 changed files with 51 additions and 34 deletions
|
@ -1307,7 +1307,7 @@ public class PKListener implements Listener {
|
|||
if (bPlayer != null) {
|
||||
try (MCTiming timing = TimingPlayerMoveAirChiPassiveCheck) {
|
||||
if (bPlayer.hasElement(Element.AIR) || bPlayer.hasElement(Element.CHI)) {
|
||||
PassiveHandler.checkExhaustionPassives(player);
|
||||
ModuleManager.getModule(PassiveHandler.class).checkExhaustionPassives(player);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ public class PassiveAbilityManager extends Module {
|
|||
});
|
||||
}
|
||||
|
||||
private boolean canUsePassive(Player player, Class<? extends Ability> abilityClass) {
|
||||
public boolean canUsePassive(Player player, Class<? extends Ability> abilityClass) {
|
||||
BendingPlayer bendingPlayer = this.bendingPlayerManager.getBendingPlayer(player);
|
||||
PassiveAbilityLoader passiveAbilityLoader = this.abilities.get(abilityClass);
|
||||
|
||||
|
@ -80,6 +80,10 @@ public class PassiveAbilityManager extends Module {
|
|||
return true;
|
||||
}
|
||||
|
||||
public PassiveAbilityLoader getPassiveAbility(Class<? extends Ability> abilityClass) {
|
||||
return this.abilities.get(abilityClass);
|
||||
}
|
||||
|
||||
public List<Class<? extends Ability>> getPassivesForElement(Element element) {
|
||||
List<Class<? extends Ability>> abilities = new ArrayList<>();
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.projectkorra.projectkorra.ability.Ability;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.World.Environment;
|
||||
|
@ -26,7 +27,7 @@ import com.projectkorra.projectkorra.configuration.configs.properties.WaterPrope
|
|||
* Air, Water, Earth, Fire, Chi, or AvatarAbility. This class is mainly used to
|
||||
* keep CoreAbility from becoming too cluttered.
|
||||
*/
|
||||
public abstract class ElementalAbility<C extends AbilityConfig> extends CoreAbility<C> {
|
||||
public abstract class ElementalAbility<C extends AbilityConfig> extends Ability<C> {
|
||||
private static final PotionEffectType[] POSITIVE_EFFECTS = { PotionEffectType.ABSORPTION, PotionEffectType.DAMAGE_RESISTANCE, PotionEffectType.FAST_DIGGING, PotionEffectType.FIRE_RESISTANCE, PotionEffectType.HEAL, PotionEffectType.HEALTH_BOOST, PotionEffectType.INCREASE_DAMAGE, PotionEffectType.JUMP, PotionEffectType.NIGHT_VISION, PotionEffectType.REGENERATION, PotionEffectType.SATURATION, PotionEffectType.SPEED, PotionEffectType.WATER_BREATHING };
|
||||
private static final PotionEffectType[] NEUTRAL_EFFECTS = { PotionEffectType.INVISIBILITY };
|
||||
private static final PotionEffectType[] NEGATIVE_EFFECTS = { PotionEffectType.POISON, PotionEffectType.BLINDNESS, PotionEffectType.CONFUSION, PotionEffectType.HARM, PotionEffectType.HUNGER, PotionEffectType.SLOW, PotionEffectType.SLOW_DIGGING, PotionEffectType.WEAKNESS, PotionEffectType.WITHER };
|
||||
|
|
|
@ -4,11 +4,11 @@ import com.projectkorra.projectkorra.GeneralMethods;
|
|||
import com.projectkorra.projectkorra.ability.Ability;
|
||||
import com.projectkorra.projectkorra.ability.AbilityInfo;
|
||||
import com.projectkorra.projectkorra.ability.AbilityManager;
|
||||
import com.projectkorra.projectkorra.ability.bind.AbilityBindManager;
|
||||
import com.projectkorra.projectkorra.ability.PassiveAbilityManager;
|
||||
import com.projectkorra.projectkorra.ability.api.ChiAbility;
|
||||
import com.projectkorra.projectkorra.ability.bind.AbilityBindManager;
|
||||
import com.projectkorra.projectkorra.ability.loader.AbilityLoader;
|
||||
import com.projectkorra.projectkorra.ability.loader.AvatarAbilityLoader;
|
||||
import com.projectkorra.projectkorra.ability.util.PassiveManager;
|
||||
import com.projectkorra.projectkorra.cooldown.CooldownManager;
|
||||
import com.projectkorra.projectkorra.element.Element;
|
||||
import com.projectkorra.projectkorra.element.ElementManager;
|
||||
|
@ -23,6 +23,7 @@ public class BendingPlayer {
|
|||
private final BendingPlayerManager manager;
|
||||
private final ElementManager elementManager;
|
||||
private final AbilityManager abilityManager;
|
||||
private final PassiveAbilityManager passiveAbilityManager;
|
||||
private final AbilityBindManager abilityBindManager;
|
||||
private final CooldownManager cooldownManager;
|
||||
|
||||
|
@ -48,6 +49,7 @@ public class BendingPlayer {
|
|||
this.manager = ModuleManager.getModule(BendingPlayerManager.class);
|
||||
this.elementManager = ModuleManager.getModule(ElementManager.class);
|
||||
this.abilityManager = ModuleManager.getModule(AbilityManager.class);
|
||||
this.passiveAbilityManager = ModuleManager.getModule(PassiveAbilityManager.class);
|
||||
this.abilityBindManager = ModuleManager.getModule(AbilityBindManager.class);
|
||||
this.cooldownManager = ModuleManager.getModule(CooldownManager.class);
|
||||
|
||||
|
@ -266,7 +268,7 @@ public class BendingPlayer {
|
|||
|
||||
public void toggleBending() {
|
||||
this.toggled = !this.toggled;
|
||||
PassiveManager.registerPassives(this.player); // TODO redo this passive system
|
||||
this.passiveAbilityManager.registerPassives(this.player);
|
||||
}
|
||||
|
||||
public boolean isTremorSensing() {
|
||||
|
|
|
@ -1,45 +1,58 @@
|
|||
package com.projectkorra.projectkorra.util;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.projectkorra.projectkorra.BendingPlayer;
|
||||
import com.projectkorra.projectkorra.ability.CoreAbility;
|
||||
import com.projectkorra.projectkorra.ability.util.PassiveManager;
|
||||
import com.projectkorra.projectkorra.ability.PassiveAbilityManager;
|
||||
import com.projectkorra.projectkorra.ability.loader.PassiveAbilityLoader;
|
||||
import com.projectkorra.projectkorra.airbending.passive.AirSaturation;
|
||||
import com.projectkorra.projectkorra.chiblocking.passive.ChiSaturation;
|
||||
import com.projectkorra.projectkorra.command.Commands;
|
||||
import com.projectkorra.projectkorra.configuration.ConfigManager;
|
||||
import com.projectkorra.projectkorra.configuration.configs.properties.GeneralPropertiesConfig;
|
||||
import com.projectkorra.projectkorra.module.Module;
|
||||
import com.projectkorra.projectkorra.module.ModuleManager;
|
||||
import com.projectkorra.projectkorra.player.BendingPlayerManager;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PassiveHandler {
|
||||
private static final Map<Player, Float> FOOD = new ConcurrentHashMap<>();
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public static float getExhaustion(final Player player, float level, final double factor) {
|
||||
if (!FOOD.keySet().contains(player)) {
|
||||
FOOD.put(player, level);
|
||||
public class PassiveHandler extends Module {
|
||||
|
||||
private final BendingPlayerManager bendingPlayerManager;
|
||||
private final PassiveAbilityManager passiveAbilityManager;
|
||||
|
||||
private final Map<UUID, Float> food = new HashMap<>();
|
||||
|
||||
private PassiveHandler() {
|
||||
super("Passive");
|
||||
|
||||
this.bendingPlayerManager = ModuleManager.getModule(BendingPlayerManager.class);
|
||||
this.passiveAbilityManager = ModuleManager.getModule(PassiveAbilityManager.class);
|
||||
}
|
||||
|
||||
public float getExhaustion(final Player player, float level, final double factor) {
|
||||
if (!this.food.keySet().contains(player.getUniqueId())) {
|
||||
this.food.put(player.getUniqueId(), level);
|
||||
return level;
|
||||
} else {
|
||||
final float oldlevel = FOOD.get(player);
|
||||
final float oldlevel = this.food.get(player.getUniqueId());
|
||||
if (level < oldlevel) {
|
||||
level = 0;
|
||||
} else {
|
||||
level = (float) ((level - oldlevel) * factor + oldlevel);
|
||||
}
|
||||
|
||||
FOOD.put(player, level);
|
||||
this.food.put(player.getUniqueId(), level);
|
||||
return level;
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkExhaustionPassives(final Player player) {
|
||||
CoreAbility airsat = CoreAbility.getAbility(AirSaturation.class);
|
||||
CoreAbility chisat = CoreAbility.getAbility(ChiSaturation.class);
|
||||
public void checkExhaustionPassives(final Player player) {
|
||||
PassiveAbilityLoader airsat = this.passiveAbilityManager.getPassiveAbility(AirSaturation.class);
|
||||
PassiveAbilityLoader chisat = this.passiveAbilityManager.getPassiveAbility(ChiSaturation.class);
|
||||
|
||||
if ((airsat == null || !airsat.isEnabled()) && (chisat == null || !chisat.isEnabled())) {
|
||||
if (airsat == null && chisat == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -54,21 +67,18 @@ public class PassiveHandler {
|
|||
return;
|
||||
}
|
||||
|
||||
final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player);
|
||||
com.projectkorra.projectkorra.player.BendingPlayer bendingPlayer = this.bendingPlayerManager.getBendingPlayer(player);
|
||||
|
||||
if (bPlayer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!PassiveManager.hasPassive(player, airsat)) {
|
||||
if (!this.passiveAbilityManager.canUsePassive(player, AirSaturation.class)) {
|
||||
air = 0;
|
||||
}
|
||||
|
||||
if (!PassiveManager.hasPassive(player, chisat)) {
|
||||
if (!this.passiveAbilityManager.canUsePassive(player, ChiSaturation.class)) {
|
||||
chi = 0;
|
||||
}
|
||||
|
||||
final double max = Math.max(air, chi);
|
||||
|
||||
if (max == 0) {
|
||||
return;
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue