Various Additions + Fixes

• Added requireAvatar() method to AvatarAbility
• Allows moves to be created that don't require the user to be the
avatar in order to use them (adding back old functionality)
• Added AbilityProgressEvent
• Tweaked Grammar
• Fixed speed/jump passives
• Fixed incorrect tabbing with the remove command
This commit is contained in:
StrangeOne101 2016-04-26 17:43:23 +12:00
parent 9d3d3ab692
commit 6301625a42
9 changed files with 97 additions and 31 deletions

View file

@ -15,6 +15,7 @@ import org.bukkit.entity.Player;
import com.projectkorra.projectkorra.Element.SubElement;
import com.projectkorra.projectkorra.ability.Ability;
import com.projectkorra.projectkorra.ability.AvatarAbility;
import com.projectkorra.projectkorra.ability.ChiAbility;
import com.projectkorra.projectkorra.ability.CoreAbility;
import com.projectkorra.projectkorra.ability.FireAbility;
@ -251,7 +252,7 @@ public class BendingPlayer {
return false;
} else if (!player.hasPermission("bending.ability." + ability.getName())) {
return false;
} else if (!hasElement(ability.getElement())) {
} else if (!hasElement(ability.getElement()) && !(ability instanceof AvatarAbility && !((AvatarAbility)ability).requireAvatar())) {
return false;
} else if (ability.getElement() instanceof SubElement) {
SubElement subElement = (SubElement) ability.getElement();

View file

@ -155,7 +155,6 @@ import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerToggleFlightEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
@ -1109,20 +1108,11 @@ public class PKListener implements Listener {
else {
BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player);
double xDif = event.getTo().getX() - event.getFrom().getX();
double yDif = event.getTo().getY() - event.getFrom().getY();
double zDif = event.getTo().getZ() - event.getFrom().getZ();
if ((xDif > 0.12 || xDif < -0.12) || (yDif > 0.12 || yDif < -0.12) || (zDif > 0.12 || zDif < -0.12)) {
if (bPlayer != null) {
if (bPlayer.hasElement(Element.AIR) || bPlayer.hasElement(Element.CHI) || bPlayer.hasElement(Element.EARTH)) {
if (player.hasPotionEffect(PotionEffectType.SPEED)) {
player.removePotionEffect(PotionEffectType.SPEED);
}
PassiveHandler.checkSpeedPassives(player);
}
if (bPlayer.hasElement(Element.AIR) || bPlayer.hasElement(Element.CHI)) {
if (player.hasPotionEffect(PotionEffectType.JUMP)) {
player.removePotionEffect(PotionEffectType.JUMP);
}
PassiveHandler.checkJumpPassives(player);
PassiveHandler.checkExhaustionPassives(player);
}

View file

@ -13,6 +13,7 @@ import com.projectkorra.projectkorra.firebending.FirebendingManager;
import com.projectkorra.projectkorra.object.Preset;
import com.projectkorra.projectkorra.storage.DBConnection;
import com.projectkorra.projectkorra.util.MetricsLite;
import com.projectkorra.projectkorra.util.PassiveHandler;
import com.projectkorra.projectkorra.util.RevertChecker;
import com.projectkorra.projectkorra.util.Updater;
import com.projectkorra.projectkorra.util.logging.PKLogHandler;
@ -79,8 +80,9 @@ public class ProjectKorra extends JavaPlugin {
getServer().getScheduler().scheduleSyncRepeatingTask(this, new EarthbendingManager(this), 0, 1);
getServer().getScheduler().scheduleSyncRepeatingTask(this, new FirebendingManager(this), 0, 1);
getServer().getScheduler().scheduleSyncRepeatingTask(this, new ChiblockingManager(this), 0, 1);
getServer().getScheduler().scheduleSyncRepeatingTask(this, new PassiveHandler(), 0, 1);
getServer().getScheduler().runTaskTimerAsynchronously(this, new RevertChecker(this), 0, 200);
for (Player player : Bukkit.getOnlinePlayers()) {
PKListener.getJumpStatistics().put(player, player.getStatistic(Statistic.JUMP));
GeneralMethods.createBendingPlayer(player.getUniqueId(), player.getName());

View file

@ -30,5 +30,12 @@ public abstract class AvatarAbility extends ElementalAbility {
public static void playAvatarSound(Location loc) {
loc.getWorld().playSound(loc, Sound.ANVIL_LAND, 1, 10);
}
/**Determines whether the ability requires the user to be an avatar in order to be able
* to use it. Set this to <tt>false</tt> for moves that should be able to be used without
* players needing to have the avatar element*/
public boolean requireAvatar() {
return true;
}
}

View file

@ -33,6 +33,7 @@ import com.projectkorra.projectkorra.ability.util.MultiAbilityManager;
import com.projectkorra.projectkorra.ability.util.MultiAbilityManager.MultiAbilityInfo;
import com.projectkorra.projectkorra.configuration.ConfigManager;
import com.projectkorra.projectkorra.event.AbilityEndEvent;
import com.projectkorra.projectkorra.event.AbilityProgressEvent;
import com.projectkorra.projectkorra.event.AbilityStartEvent;
import sun.reflect.ReflectionFactory;
@ -186,6 +187,7 @@ public abstract class CoreAbility implements Ability {
for (Set<CoreAbility> setAbils : INSTANCES_BY_CLASS.values()) {
for (CoreAbility abil : setAbils) {
abil.progress();
Bukkit.getServer().getPluginManager().callEvent(new AbilityProgressEvent(abil));
}
}
}

View file

@ -112,7 +112,9 @@ public class RemoveCommand extends PKCommand {
}
} else if (args.size() == 1) {
bPlayer.getElements().clear();
bPlayer.getSubElements().clear();
GeneralMethods.saveElements(bPlayer);
GeneralMethods.saveSubElements(bPlayer);
GeneralMethods.removeUnusableAbilities(player.getName());
if (GeneralMethods.hasRPG()) RPGMethods.revokeAvatar(bPlayer.getUUID());
sender.sendMessage(ChatColor.YELLOW + this.succesfullyRemovedAllElementsTargetConfirm.replace("{target}", ChatColor.DARK_AQUA + player.getName() + ChatColor.YELLOW));
@ -140,7 +142,7 @@ public class RemoveCommand extends PKCommand {
protected List<String> getTabCompletion(CommandSender sender, List<String> args) {
if (args.size() >= 2 || !sender.hasPermission("bending.command.remove")) return new ArrayList<String>();
List<String> l = new ArrayList<String>();
if (args.size() == 1) {
if (args.size() == 0) {
for (Player p : Bukkit.getOnlinePlayers()) {
l.add(p.getName());
}

View file

@ -74,7 +74,7 @@ public class ConfigManager {
config.addDefault("Commands.Version.Description", "Displays the installed version of ProjectKorra.");
config.addDefault("Commands.Toggle.Description", "This command will toggle a player's own Bending on or off. If toggled off, all abilities should stop working until it is toggled back on. Logging off will automatically toggle your Bending back on. If you run the command /bending toggle all, Bending will be turned off for all players and cannot be turned back on until the command is run again.");
config.addDefault("Commands.Toggle.ToggledOn", "You have turned your Bending back on.");
config.addDefault("Commands.Toggle.ToggledOn", "You have turned your bending back on.");
config.addDefault("Commands.Toggle.ToggledOff", "Your bending has been toggled off. You will not be able to use most abilities until you toggle it back.");
config.addDefault("Commands.Toggle.ToggleOnSingleElement", "You have toggled on your {element}.");
config.addDefault("Commands.Toggle.ToggleOffSingleElement", "You have toggled off your {element}.");
@ -788,8 +788,7 @@ public class ConfigManager {
config.addDefault("Abilities.Earth.Passive.Duration", 2500);
config.addDefault("Abilities.Earth.Passive.SandRunSpeed", 2);
config.addDefault("Abilities.Earth.Passive.SandRunHeight", 3);
config.addDefault("Abilities.Earth.Catapult.Enabled", true);
config.addDefault("Abilities.Earth.Catapult.Length", 6);
config.addDefault("Abilities.Earth.Catapult.Push", 4);

View file

@ -0,0 +1,34 @@
package com.projectkorra.projectkorra.event;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import com.projectkorra.projectkorra.ability.Ability;
/**
* Called when an ability starts
* @author Philip
*
*/
public class AbilityProgressEvent extends Event {
private static final HandlerList handlers = new HandlerList();
Ability ability;
public AbilityProgressEvent(Ability ability) {
this.ability = ability;
}
public Ability getAbility() {
return ability;
}
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View file

@ -4,6 +4,7 @@ import com.projectkorra.projectkorra.BendingPlayer;
import com.projectkorra.projectkorra.Element;
import com.projectkorra.projectkorra.Element.SubElement;
import com.projectkorra.projectkorra.ability.CoreAbility;
import com.projectkorra.projectkorra.ability.EarthAbility;
import com.projectkorra.projectkorra.airbending.AirPassive;
import com.projectkorra.projectkorra.chiblocking.AcrobatStance;
import com.projectkorra.projectkorra.chiblocking.ChiPassive;
@ -12,7 +13,7 @@ import com.projectkorra.projectkorra.earthbending.EarthArmor;
import com.projectkorra.projectkorra.earthbending.EarthPassive;
import com.projectkorra.projectkorra.waterbending.PlantArmor;
import org.bukkit.Material;
import org.bukkit.Bukkit;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
@ -20,12 +21,10 @@ import org.bukkit.potion.PotionEffectType;
import java.util.concurrent.ConcurrentHashMap;
public class PassiveHandler {
public class PassiveHandler implements Runnable {
private static final ConcurrentHashMap<Player, Float> FOOD = new ConcurrentHashMap<>();
private static int sandRunHeight = ConfigManager.defaultConfig.get().getInt("Abilities.Earth.Passive.SandRunHeight");
public static float getExhaustion(Player player, float level, double factor) {
if (!FOOD.keySet().contains(player)) {
FOOD.put(player, level);
@ -89,6 +88,7 @@ public class PassiveHandler {
}
public static void checkSpeedPassives(Player player) {
if (!player.isSprinting()) return;
int air = AirPassive.getSpeedPower();
int chi = ChiPassive.getSpeedPower();
int earth = EarthPassive.getSandRunSpeed();
@ -101,16 +101,14 @@ public class PassiveHandler {
BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player);
if (bPlayer == null) return;
if (!bPlayer.hasElement(Element.EARTH)) sandbender = false;
if (!bPlayer.canBendPassive(Element.EARTH)) sandbender = false;
if (!bPlayer.hasSubElement(SubElement.SAND)) sandbender = false;
if (!bPlayer.hasElement(Element.AIR)) air = 0;
if (!bPlayer.hasElement(Element.CHI)) chi = 0;
if (!bPlayer.canBendPassive(Element.AIR)) air = 0;
if (!bPlayer.canBendPassive(Element.CHI)) chi = 0;
int max = 0;
if (sandbender && (player.getLocation().getBlock().getRelative(BlockFace.DOWN, sandRunHeight).getType() == Material.SAND
|| player.getLocation().getBlock().getRelative(BlockFace.DOWN, sandRunHeight).getType() == Material.SANDSTONE
|| player.getLocation().getBlock().getRelative(BlockFace.DOWN, sandRunHeight).getType() == Material.RED_SANDSTONE)) {
if (sandbender && EarthAbility.isSand(player.getLocation().getBlock().getRelative(BlockFace.DOWN))) {
if (CoreAbility.hasAbility(player, AcrobatStance.class)) {
AcrobatStance abil = CoreAbility.getAbility(player, AcrobatStance.class);
max = Math.max(air, chi);
@ -131,10 +129,21 @@ public class PassiveHandler {
}
if (max == 0) return;
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 3, max-1));
boolean b = true;
if (player.hasPotionEffect(PotionEffectType.SPEED)) {
for (PotionEffect potion : player.getActivePotionEffects()) {
if (potion.getType() == PotionEffectType.SPEED) {
if (potion.getAmplifier() > max - 1) b = false;
}
}
}
if (b) {
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 3, max-1, true, false), false);
}
}
public static void checkJumpPassives(Player player) {
if (!player.isSprinting()) return;
int air = AirPassive.getJumpPower();
int chi = ChiPassive.getJumpPower();
@ -145,8 +154,8 @@ public class PassiveHandler {
BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player);
if (bPlayer == null) return;
if (!bPlayer.hasElement(Element.AIR)) air = 0;
if (!bPlayer.hasElement(Element.CHI)) chi = 0;
if (!bPlayer.canBendPassive(Element.AIR)) air = 0;
if (!bPlayer.canBendPassive(Element.CHI)) chi = 0;
int max = 0;
if (CoreAbility.hasAbility(player, AcrobatStance.class)) {
AcrobatStance abil = CoreAbility.getAbility(player, AcrobatStance.class);
@ -155,7 +164,27 @@ public class PassiveHandler {
} else {
max = Math.max(air, chi);
}
if (max == 0) return;
player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 3, max-1), false);
boolean b = true;
if (player.hasPotionEffect(PotionEffectType.JUMP)) {
for (PotionEffect potion : player.getActivePotionEffects()) {
if (potion.getType() == PotionEffectType.JUMP) {
if (potion.getAmplifier() > max - 1) b = false;
}
}
}
if (b) {
player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 3, max-1, true, false), false);
}
}
@Override
public void run() {
for (Player player : Bukkit.getOnlinePlayers()) {
checkSpeedPassives(player);
checkJumpPassives(player);
}
}
}