From 5bd2b8b217952c9ca00efdcc8d00643c92c8d2d1 Mon Sep 17 00:00:00 2001 From: jayoevans Date: Sat, 11 Aug 2018 17:36:26 +1000 Subject: [PATCH 1/2] Added overrideable CoreAbility#getMovePreview, renamed BindChangeEvent to PlayerBindChangeEvent --- .../projectkorra/GeneralMethods.java | 15 +--- .../projectkorra/ability/CoreAbility.java | 18 +++++ .../ability/util/MultiAbilityManager.java | 4 +- .../event/PlayerBindChangeEvent.java | 78 +++++++++++++++++++ 4 files changed, 101 insertions(+), 14 deletions(-) create mode 100644 src/com/projectkorra/projectkorra/event/PlayerBindChangeEvent.java diff --git a/src/com/projectkorra/projectkorra/GeneralMethods.java b/src/com/projectkorra/projectkorra/GeneralMethods.java index bd80a3c6..f096efe3 100644 --- a/src/com/projectkorra/projectkorra/GeneralMethods.java +++ b/src/com/projectkorra/projectkorra/GeneralMethods.java @@ -110,7 +110,7 @@ import com.projectkorra.projectkorra.earthbending.EarthBlast; import com.projectkorra.projectkorra.earthbending.passive.EarthPassive; import com.projectkorra.projectkorra.event.BendingPlayerCreationEvent; import com.projectkorra.projectkorra.event.BendingReloadEvent; -import com.projectkorra.projectkorra.event.BindChangeEvent; +import com.projectkorra.projectkorra.event.PlayerBindChangeEvent; import com.projectkorra.projectkorra.firebending.FireBlast; import com.projectkorra.projectkorra.firebending.FireShield; import com.projectkorra.projectkorra.firebending.combustion.Combustion; @@ -651,16 +651,7 @@ public class GeneralMethods { final CoreAbility ability = CoreAbility.getAbility(displayedMessage); if (ability != null && bPlayer != null) { - if (bPlayer.isOnCooldown(ability)) { - final long cooldown = bPlayer.getCooldown(ability.getName()) - System.currentTimeMillis(); - displayedMessage = ability.getElement().getColor() + "" + ChatColor.STRIKETHROUGH + ability.getName() + "" + ability.getElement().getColor() + " - " + TimeUtil.formatTime(cooldown); - } else { - if (bPlayer.getStance() != null && bPlayer.getStance().getName().equals(ability.getName())) { - displayedMessage = ability.getElement().getColor() + "" + ChatColor.UNDERLINE + ability.getName(); - } else { - displayedMessage = ability.getElement().getColor() + ability.getName(); - } - } + displayedMessage = ability.getMovePreview(player); } else if (displayedMessage == null || displayedMessage.isEmpty() || displayedMessage.equals("")) { displayedMessage = ""; } @@ -1909,7 +1900,7 @@ public class GeneralMethods { } final String uuid = bPlayer.getUUIDString(); - final BindChangeEvent event = new BindChangeEvent(Bukkit.getPlayer(UUID.fromString(uuid)), ability, slot, false); + final PlayerBindChangeEvent event = new PlayerBindChangeEvent(Bukkit.getPlayer(UUID.fromString(uuid)), ability, slot, false); Bukkit.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return; diff --git a/src/com/projectkorra/projectkorra/ability/CoreAbility.java b/src/com/projectkorra/projectkorra/ability/CoreAbility.java index dc41014f..b5b0a354 100644 --- a/src/com/projectkorra/projectkorra/ability/CoreAbility.java +++ b/src/com/projectkorra/projectkorra/ability/CoreAbility.java @@ -18,6 +18,7 @@ import java.util.concurrent.ConcurrentSkipListMap; import java.util.jar.JarFile; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; @@ -41,6 +42,7 @@ 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 com.projectkorra.projectkorra.util.TimeUtil; import sun.reflect.ReflectionFactory; @@ -782,6 +784,22 @@ public abstract class CoreAbility implements Ability { } return ConfigManager.languageConfig.get().getString("Abilities." + elementName + "." + this.getName() + ".Description"); } + + public String getMovePreview(Player player) { + BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); + String displayedMessage = ""; + if (bPlayer.isOnCooldown(this)) { + final long cooldown = bPlayer.getCooldown(getName()) - System.currentTimeMillis(); + displayedMessage = getElement().getColor() + "" + ChatColor.STRIKETHROUGH + getName() + "" + getElement().getColor() + " - " + TimeUtil.formatTime(cooldown); + } else { + if (bPlayer.getStance() != null && bPlayer.getStance().getName().equals(getName())) { + displayedMessage = getElement().getColor() + "" + ChatColor.UNDERLINE + getName(); + } else { + displayedMessage = getElement().getColor() + getName(); + } + } + return displayedMessage; + } @Override public Player getPlayer() { diff --git a/src/com/projectkorra/projectkorra/ability/util/MultiAbilityManager.java b/src/com/projectkorra/projectkorra/ability/util/MultiAbilityManager.java index f79cf85b..5dd09165 100644 --- a/src/com/projectkorra/projectkorra/ability/util/MultiAbilityManager.java +++ b/src/com/projectkorra/projectkorra/ability/util/MultiAbilityManager.java @@ -15,7 +15,7 @@ import com.projectkorra.projectkorra.BendingPlayer; import com.projectkorra.projectkorra.Element; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ProjectKorra; -import com.projectkorra.projectkorra.event.BindChangeEvent; +import com.projectkorra.projectkorra.event.PlayerBindChangeEvent; public class MultiAbilityManager { @@ -43,7 +43,7 @@ public class MultiAbilityManager { * @param multiAbility MultiAbility being bound */ public static void bindMultiAbility(final Player player, final String multiAbility) { - final BindChangeEvent event = new BindChangeEvent(player, multiAbility, true); + final PlayerBindChangeEvent event = new PlayerBindChangeEvent(player, multiAbility, true); Bukkit.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return; diff --git a/src/com/projectkorra/projectkorra/event/PlayerBindChangeEvent.java b/src/com/projectkorra/projectkorra/event/PlayerBindChangeEvent.java new file mode 100644 index 00000000..eb2e36d4 --- /dev/null +++ b/src/com/projectkorra/projectkorra/event/PlayerBindChangeEvent.java @@ -0,0 +1,78 @@ +package com.projectkorra.projectkorra.event; + +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +/** + * Called when a player binds or unbinds an ability + * + * @author savior67 + */ +public class PlayerBindChangeEvent extends Event { + + private static final HandlerList handlers = new HandlerList(); + private final Player player; + private final String ability; + private final int slot; // slot is -1 if it is a multiability. + private final boolean isBinding; // true if the ability is being binded, otherwise false. + private final boolean isMultiAbility; // true if the ability is a multiability. + private boolean cancelled; + + // bind event for abilities. + public PlayerBindChangeEvent(final Player player, final String ability, final int slot, final boolean isBinding) { + this.player = player; + this.ability = ability; + this.slot = slot; + this.isBinding = isBinding; + this.cancelled = false; + this.isMultiAbility = false; + } + + // used for multi abilities. + public PlayerBindChangeEvent(final Player player, final String ability, final boolean isBinding) { + this.player = player; + this.ability = ability; + this.slot = -1; + this.isBinding = isBinding; + this.cancelled = false; + this.isMultiAbility = true; + } + + public String getAbility() { + return this.ability; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + public Player getPlayer() { + return this.player; + } + + public int getSlot() { + return this.slot; + } + + public boolean isBinding() { + return this.isBinding; + } + + public boolean isCancelled() { + return this.cancelled; + } + + public boolean isMultiAbility() { + return this.isMultiAbility; + } + + public void setCancelled(final boolean cancelled) { + this.cancelled = cancelled; + } +} From 014fb0793dbe5ccc58358ebfb1ae056504206e38 Mon Sep 17 00:00:00 2001 From: Christopher Martin Date: Sat, 11 Aug 2018 00:59:21 -0700 Subject: [PATCH 2/2] Add final modifier to Player parameter --- src/com/projectkorra/projectkorra/ability/CoreAbility.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/projectkorra/projectkorra/ability/CoreAbility.java b/src/com/projectkorra/projectkorra/ability/CoreAbility.java index b5b0a354..94501e7d 100644 --- a/src/com/projectkorra/projectkorra/ability/CoreAbility.java +++ b/src/com/projectkorra/projectkorra/ability/CoreAbility.java @@ -785,7 +785,7 @@ public abstract class CoreAbility implements Ability { return ConfigManager.languageConfig.get().getString("Abilities." + elementName + "." + this.getName() + ".Description"); } - public String getMovePreview(Player player) { + public String getMovePreview(final Player player) { BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); String displayedMessage = ""; if (bPlayer.isOnCooldown(this)) {