Merge pull request #974 from jayoevans/wip

Added overrideable CoreAbility#getMovePreview, renamed BindChangeEven…
This commit is contained in:
Jay 2018-08-12 06:15:35 +10:00 committed by GitHub
commit 4a569ad032
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 101 additions and 14 deletions

View file

@ -110,7 +110,7 @@ import com.projectkorra.projectkorra.earthbending.EarthBlast;
import com.projectkorra.projectkorra.earthbending.passive.EarthPassive; import com.projectkorra.projectkorra.earthbending.passive.EarthPassive;
import com.projectkorra.projectkorra.event.BendingPlayerCreationEvent; import com.projectkorra.projectkorra.event.BendingPlayerCreationEvent;
import com.projectkorra.projectkorra.event.BendingReloadEvent; 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.FireBlast;
import com.projectkorra.projectkorra.firebending.FireShield; import com.projectkorra.projectkorra.firebending.FireShield;
import com.projectkorra.projectkorra.firebending.combustion.Combustion; import com.projectkorra.projectkorra.firebending.combustion.Combustion;
@ -651,16 +651,7 @@ public class GeneralMethods {
final CoreAbility ability = CoreAbility.getAbility(displayedMessage); final CoreAbility ability = CoreAbility.getAbility(displayedMessage);
if (ability != null && bPlayer != null) { if (ability != null && bPlayer != null) {
if (bPlayer.isOnCooldown(ability)) { displayedMessage = ability.getMovePreview(player);
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();
}
}
} else if (displayedMessage == null || displayedMessage.isEmpty() || displayedMessage.equals("")) { } else if (displayedMessage == null || displayedMessage.isEmpty() || displayedMessage.equals("")) {
displayedMessage = ""; displayedMessage = "";
} }
@ -1909,7 +1900,7 @@ public class GeneralMethods {
} }
final String uuid = bPlayer.getUUIDString(); 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); Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) { if (event.isCancelled()) {
return; return;

View file

@ -18,6 +18,7 @@ import java.util.concurrent.ConcurrentSkipListMap;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player; 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.AbilityEndEvent;
import com.projectkorra.projectkorra.event.AbilityProgressEvent; import com.projectkorra.projectkorra.event.AbilityProgressEvent;
import com.projectkorra.projectkorra.event.AbilityStartEvent; import com.projectkorra.projectkorra.event.AbilityStartEvent;
import com.projectkorra.projectkorra.util.TimeUtil;
import sun.reflect.ReflectionFactory; import sun.reflect.ReflectionFactory;
@ -783,6 +785,22 @@ public abstract class CoreAbility implements Ability {
return ConfigManager.languageConfig.get().getString("Abilities." + elementName + "." + this.getName() + ".Description"); return ConfigManager.languageConfig.get().getString("Abilities." + elementName + "." + this.getName() + ".Description");
} }
public String getMovePreview(final 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 @Override
public Player getPlayer() { public Player getPlayer() {
return this.player; return this.player;

View file

@ -15,7 +15,7 @@ import com.projectkorra.projectkorra.BendingPlayer;
import com.projectkorra.projectkorra.Element; import com.projectkorra.projectkorra.Element;
import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.ProjectKorra;
import com.projectkorra.projectkorra.event.BindChangeEvent; import com.projectkorra.projectkorra.event.PlayerBindChangeEvent;
public class MultiAbilityManager { public class MultiAbilityManager {
@ -43,7 +43,7 @@ public class MultiAbilityManager {
* @param multiAbility MultiAbility being bound * @param multiAbility MultiAbility being bound
*/ */
public static void bindMultiAbility(final Player player, final String multiAbility) { 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); Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) { if (event.isCancelled()) {
return; return;

View file

@ -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;
}
}