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.api.player.PlayerActivity;
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.chat.TextComponent;
import org.bukkit.attribute.Attribute;
@ -37,7 +38,13 @@ public class PlayerActionBar extends BukkitRunnable {
public void run() {
for (PlayerData data : PlayerData.getAll())
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)
.replace("{health}", digit.format(data.getPlayer().getHealth()))
.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("{armor}", StatManager.format("ARMOR", data.getPlayer().getAttribute(Attribute.GENERIC_ARMOR).getValue()))
.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 final boolean enabled;
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.
private final Map<KeyCombo, Integer> combos = new HashMap<>();
private final Set<PlayerKey> firstComboKeys= new HashSet<>();
private int longestCombo;
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)));
combos.put(combo, spellSlot);
firstComboKeys.add(combo.getAt(0));
longestCombo = Math.max(longestCombo, combo.countKeys());
} catch (RuntimeException exception) {
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;
}
public Set<PlayerKey> getFirstComboKeys() {
return firstComboKeys;
}
public int getLongestCombo() {
return longestCombo;
}

View File

@ -25,6 +25,9 @@ public class Placeholders {
@Nullable String found = placeholders.get(holder);
if (found != null)
str = str.replace("{" + holder + "}", found);
else
str = str.replace("{" + holder + "}", "PHE");
}
// 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.api.event.PlayerKeyPressEvent;
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.api.SoundObject;
import net.Indyuce.mmocore.skill.cast.KeyCombo;
@ -33,10 +34,15 @@ public class KeyCombos implements Listener {
* hash code method
*/
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
*/
private final boolean needsInitializerKey;
private final PlayerKey initializerKey;
private final int longestCombo;
@ -65,6 +71,7 @@ public class KeyCombos implements Listener {
combo.registerKey(PlayerKey.valueOf(UtilityMethods.enumName(str)));
combos.put(combo, spellSlot);
firstComboKeys.add(combo.getAt(0));
longestCombo = Math.max(longestCombo, combo.countKeys());
} catch (RuntimeException exception) {
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;
failComboSound = config.contains("sound.fail-combo") ? new SoundObject(config.getConfigurationSection("sound.fail-combo")) : null;
needsInitializerKey = config.getBoolean("needs-initializer-key", true);
// 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
@ -90,17 +102,34 @@ public class KeyCombos implements Listener {
Player player = playerData.getPlayer();
if (!event.getData().isCasting()) {
if (event.getPressed() == initializerKey) {
if (needsInitializerKey) {
if (event.getPressed() == initializerKey) {
// Always cancel event
event.setCancelled(true);
// Always cancel event
event.setCancelled(true);
// Start combo
playerData.setSkillCasting(new CustomSkillCastingHandler(playerData));
if (beginComboSound != null)
beginComboSound.playTo(player);
// Start combo
playerData.setSkillCasting(new CustomSkillCastingHandler(playerData));
if (beginComboSound != null)
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 final String separator, noKey;
private final String separator, noKey, prefix, suffix;
/**
* Saves the names for all the players keys. Used when displaying
@ -203,7 +232,8 @@ public class KeyCombos implements Listener {
private final boolean isSubtitle;
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.noKey = Objects.requireNonNull(config.getString("no-key"), "Could not find action bar option 'no-key'");
this.isSubtitle = config.getBoolean("is-subtitle", false);
@ -212,19 +242,22 @@ public class KeyCombos implements Listener {
}
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
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;
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
for (; j < casting.classLongestCombo; j++)
builder += separator + noKey;
builder.append(separator + noKey);
return MythicLib.plugin.parseColors(builder);
builder.append(suffix);
return holders.apply(casting.getCaster().getPlayer(), builder.toString());
}
}
}