Key combo casting changes.

This commit is contained in:
Ka0rX 2022-08-17 15:33:27 +02:00
parent 8da44fb7d7
commit b3b2f5c37d
4 changed files with 90 additions and 18 deletions

View File

@ -5,6 +5,7 @@ import io.lumine.mythic.lib.manager.StatManager;
import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerActivity; import net.Indyuce.mmocore.api.player.PlayerActivity;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.gui.api.item.Placeholders;
import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.attribute.Attribute; import org.bukkit.attribute.Attribute;
@ -37,7 +38,13 @@ public class PlayerActionBar extends BukkitRunnable {
public void run() { public void run() {
for (PlayerData data : PlayerData.getAll()) for (PlayerData data : PlayerData.getAll())
if (data.isOnline() && !data.getPlayer().isDead() && !data.isCasting() && data.getActivityTimeOut(PlayerActivity.ACTION_BAR_MESSAGE) == 0) { if (data.isOnline() && !data.getPlayer().isDead() && !data.isCasting() && data.getActivityTimeOut(PlayerActivity.ACTION_BAR_MESSAGE) == 0) {
data.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(MMOCore.plugin.placeholderParser.parse(data.getPlayer(), Placeholders holders=getActionBarPlaceholder(data);
data.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(
holders.apply(data.getPlayer(), data.getProfess().hasActionBar() ? data.getProfess().getActionBar() : config.format)));
/*
data.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(MMOCore.plugin.placeholderParser.parse(data.getPlayer(),data.getProfess().hasActionBar() ? data.getProfess().getActionBar() : config.format));
MythicLib.plugin.parseColors((data.getProfess().hasActionBar() ? data.getProfess().getActionBar() : config.format) MythicLib.plugin.parseColors((data.getProfess().hasActionBar() ? data.getProfess().getActionBar() : config.format)
.replace("{health}", digit.format(data.getPlayer().getHealth())) .replace("{health}", digit.format(data.getPlayer().getHealth()))
.replace("{max_health}", StatManager.format("MAX_HEALTH", data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue())) .replace("{max_health}", StatManager.format("MAX_HEALTH", data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()))
@ -52,10 +59,30 @@ public class PlayerActionBar extends BukkitRunnable {
.replace("{xp}", MythicLib.plugin.getMMOConfig().decimal.format(data.getExperience())) .replace("{xp}", MythicLib.plugin.getMMOConfig().decimal.format(data.getExperience()))
.replace("{armor}", StatManager.format("ARMOR", data.getPlayer().getAttribute(Attribute.GENERIC_ARMOR).getValue())) .replace("{armor}", StatManager.format("ARMOR", data.getPlayer().getAttribute(Attribute.GENERIC_ARMOR).getValue()))
.replace("{level}", "" + data.getLevel()) .replace("{level}", "" + data.getLevel())
.replace("{name}", data.getPlayer().getDisplayName()))))); .replace("{name}", data.getPlayer().getDisplayName())))));*/
} }
} }
public Placeholders getActionBarPlaceholder(PlayerData data) {
Placeholders holders= new Placeholders();
holders.register("health", digit.format(data.getPlayer().getHealth()));
holders.register("max_health", StatManager.format("MAX_HEALTH", data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()));
holders.register("mana_icon", data.getProfess().getManaDisplay().getIcon());
holders.register("mana", digit.format(data.getMana()));
holders.register("max_mana", StatManager.format("MAX_MANA", data.getStats().getStat("MAX_MANA")));
holders.register("stamina", digit.format(data.getStamina()));
holders.register("max_stamina", StatManager.format("MAX_STAMINA", data.getStats().getStat("MAX_STAMINA")));
holders.register("stellium", digit.format(data.getStellium()));
holders.register("max_stellium", StatManager.format("MAX_STELLIUM", data.getStats().getStat("MAX_STELLIUM")));
holders.register("class", data.getProfess().getName());
holders.register("xp", MythicLib.plugin.getMMOConfig().decimal.format(data.getExperience()));
holders.register("armor", StatManager.format("ARMOR", data.getPlayer().getAttribute(Attribute.GENERIC_ARMOR).getValue()));
holders.register("level", "" + data.getLevel());
holders.register("name", data.getPlayer().getDisplayName());
return holders;
}
private static class ActionBarConfig { private static class ActionBarConfig {
private final boolean enabled; private final boolean enabled;
private final int ticks, timeout; private final int ticks, timeout;

View File

@ -76,6 +76,10 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject {
// If the class redefines its own key combos. // If the class redefines its own key combos.
private final Map<KeyCombo, Integer> combos = new HashMap<>(); private final Map<KeyCombo, Integer> combos = new HashMap<>();
private final Set<PlayerKey> firstComboKeys= new HashSet<>();
private int longestCombo; private int longestCombo;
private final Map<PlayerResource, ResourceRegeneration> resourceHandlers = new HashMap<>(); private final Map<PlayerResource, ResourceRegeneration> resourceHandlers = new HashMap<>();
@ -153,6 +157,7 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject {
combo.registerKey(PlayerKey.valueOf(UtilityMethods.enumName(str))); combo.registerKey(PlayerKey.valueOf(UtilityMethods.enumName(str)));
combos.put(combo, spellSlot); combos.put(combo, spellSlot);
firstComboKeys.add(combo.getAt(0));
longestCombo = Math.max(longestCombo, combo.countKeys()); longestCombo = Math.max(longestCombo, combo.countKeys());
} catch (RuntimeException exception) { } catch (RuntimeException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load key combo '" + key + "': " + exception.getMessage()); MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load key combo '" + key + "': " + exception.getMessage());
@ -441,6 +446,10 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject {
return combos; return combos;
} }
public Set<PlayerKey> getFirstComboKeys() {
return firstComboKeys;
}
public int getLongestCombo() { public int getLongestCombo() {
return longestCombo; return longestCombo;
} }

View File

@ -25,6 +25,9 @@ public class Placeholders {
@Nullable String found = placeholders.get(holder); @Nullable String found = placeholders.get(holder);
if (found != null) if (found != null)
str = str.replace("{" + holder + "}", found); str = str.replace("{" + holder + "}", found);
else
str = str.replace("{" + holder + "}", "PHE");
} }
// External placeholders // External placeholders

View File

@ -10,6 +10,7 @@ import io.lumine.mythic.lib.skill.trigger.TriggerType;
import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.event.PlayerKeyPressEvent; import net.Indyuce.mmocore.api.event.PlayerKeyPressEvent;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.gui.api.item.Placeholders;
import net.Indyuce.mmocore.skill.cast.PlayerKey; import net.Indyuce.mmocore.skill.cast.PlayerKey;
import net.Indyuce.mmocore.api.SoundObject; import net.Indyuce.mmocore.api.SoundObject;
import net.Indyuce.mmocore.skill.cast.KeyCombo; import net.Indyuce.mmocore.skill.cast.KeyCombo;
@ -33,10 +34,15 @@ public class KeyCombos implements Listener {
* hash code method * hash code method
*/ */
private final Map<KeyCombo, Integer> combos = new HashMap<>(); private final Map<KeyCombo, Integer> combos = new HashMap<>();
/**
* All the keys that are at the start of a combo.
*/
private final Set<PlayerKey> firstComboKeys = new HashSet<>();
/** /**
* Key players need to press to start a combo * Key players need to press to start a combo
*/ */
private final boolean needsInitializerKey;
private final PlayerKey initializerKey; private final PlayerKey initializerKey;
private final int longestCombo; private final int longestCombo;
@ -65,6 +71,7 @@ public class KeyCombos implements Listener {
combo.registerKey(PlayerKey.valueOf(UtilityMethods.enumName(str))); combo.registerKey(PlayerKey.valueOf(UtilityMethods.enumName(str)));
combos.put(combo, spellSlot); combos.put(combo, spellSlot);
firstComboKeys.add(combo.getAt(0));
longestCombo = Math.max(longestCombo, combo.countKeys()); longestCombo = Math.max(longestCombo, combo.countKeys());
} catch (RuntimeException exception) { } catch (RuntimeException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load key combo '" + key + "': " + exception.getMessage()); MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load key combo '" + key + "': " + exception.getMessage());
@ -80,8 +87,13 @@ public class KeyCombos implements Listener {
comboClickSound = config.contains("sound.combo-key") ? new SoundObject(config.getConfigurationSection("sound.combo-key")) : null; comboClickSound = config.contains("sound.combo-key") ? new SoundObject(config.getConfigurationSection("sound.combo-key")) : null;
failComboSound = config.contains("sound.fail-combo") ? new SoundObject(config.getConfigurationSection("sound.fail-combo")) : null; failComboSound = config.contains("sound.fail-combo") ? new SoundObject(config.getConfigurationSection("sound.fail-combo")) : null;
needsInitializerKey = config.getBoolean("needs-initializer-key", true);
// Find initializer key // Find initializer key
initializerKey = PlayerKey.valueOf(UtilityMethods.enumName(Objects.requireNonNull(config.getString("initializer-key"), "Could not find initializer key"))); initializerKey = needsInitializerKey ? PlayerKey.valueOf(UtilityMethods.enumName(Objects.requireNonNull(
config.getString("initializer-key"), "Could not find initializer key"))) : null;
} }
@EventHandler @EventHandler
@ -90,17 +102,34 @@ public class KeyCombos implements Listener {
Player player = playerData.getPlayer(); Player player = playerData.getPlayer();
if (!event.getData().isCasting()) { if (!event.getData().isCasting()) {
if (event.getPressed() == initializerKey) { if (needsInitializerKey) {
if (event.getPressed() == initializerKey) {
// Always cancel event // Always cancel event
event.setCancelled(true); event.setCancelled(true);
// Start combo // Start combo
playerData.setSkillCasting(new CustomSkillCastingHandler(playerData)); playerData.setSkillCasting(new CustomSkillCastingHandler(playerData));
if (beginComboSound != null) if (beginComboSound != null)
beginComboSound.playTo(player); beginComboSound.playTo(player);
}
return;
} else {
Set<PlayerKey> firstKeys = playerData.getProfess().getFirstComboKeys().isEmpty() ? firstComboKeys : playerData.getProfess().getFirstComboKeys();
if (firstKeys.contains(event.getPressed())) {
// Always cancel event
event.setCancelled(true);
// Start combo
CustomSkillCastingHandler casting =new CustomSkillCastingHandler(playerData);
playerData.setSkillCasting(casting);
casting.current.registerKey(event.getPressed());
if (beginComboSound != null)
beginComboSound.playTo(player);
}
return;
} }
return;
} }
@ -193,7 +222,7 @@ public class KeyCombos implements Listener {
private class ActionBarOptions { private class ActionBarOptions {
private final String separator, noKey; private final String separator, noKey, prefix, suffix;
/** /**
* Saves the names for all the players keys. Used when displaying * Saves the names for all the players keys. Used when displaying
@ -203,7 +232,8 @@ public class KeyCombos implements Listener {
private final boolean isSubtitle; private final boolean isSubtitle;
ActionBarOptions(ConfigurationSection config) { ActionBarOptions(ConfigurationSection config) {
this.prefix = config.contains("prefix") ? config.getString("prefix") : "";
this.suffix = config.contains("suffix") ? config.getString("suffix") : "";
this.separator = Objects.requireNonNull(config.getString("separator"), "Could not find action bar option 'separator'"); this.separator = Objects.requireNonNull(config.getString("separator"), "Could not find action bar option 'separator'");
this.noKey = Objects.requireNonNull(config.getString("no-key"), "Could not find action bar option 'no-key'"); this.noKey = Objects.requireNonNull(config.getString("no-key"), "Could not find action bar option 'no-key'");
this.isSubtitle = config.getBoolean("is-subtitle", false); this.isSubtitle = config.getBoolean("is-subtitle", false);
@ -212,19 +242,22 @@ public class KeyCombos implements Listener {
} }
public String format(CustomSkillCastingHandler casting) { public String format(CustomSkillCastingHandler casting) {
StringBuilder builder = new StringBuilder();
Placeholders holders = MMOCore.plugin.actionBarManager.getActionBarPlaceholder(casting.getCaster());
builder.append(prefix);
// Join all keys with separator // Join all keys with separator
String builder = casting.current.countKeys() == 0 ? noKey : keyNames.get(casting.current.getAt(0)); builder.append(casting.current.countKeys() == 0 ? noKey : keyNames.get(casting.current.getAt(0)));
int j = 1; int j = 1;
for (; j < casting.current.countKeys(); j++) for (; j < casting.current.countKeys(); j++)
builder += separator + keyNames.get(casting.current.getAt(j)); builder.append(separator + keyNames.get(casting.current.getAt(j)));
// All remaining // All remaining
for (; j < casting.classLongestCombo; j++) for (; j < casting.classLongestCombo; j++)
builder += separator + noKey; builder.append(separator + noKey);
builder.append(suffix);
return MythicLib.plugin.parseColors(builder); return holders.apply(casting.getCaster().getPlayer(), builder.toString());
} }
} }
} }