mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-11-27 00:45:40 +01:00
Initializer key cleanup
This commit is contained in:
parent
908db88dae
commit
174898ba72
@ -1,6 +1,5 @@
|
|||||||
package net.Indyuce.mmocore.skill.cast.listener;
|
package net.Indyuce.mmocore.skill.cast.listener;
|
||||||
|
|
||||||
import io.lumine.mythic.lib.MythicLib;
|
|
||||||
import io.lumine.mythic.lib.UtilityMethods;
|
import io.lumine.mythic.lib.UtilityMethods;
|
||||||
import io.lumine.mythic.lib.api.event.skill.PlayerCastSkillEvent;
|
import io.lumine.mythic.lib.api.event.skill.PlayerCastSkillEvent;
|
||||||
import io.lumine.mythic.lib.api.player.EquipmentSlot;
|
import io.lumine.mythic.lib.api.player.EquipmentSlot;
|
||||||
@ -8,15 +7,14 @@ import io.lumine.mythic.lib.player.PlayerMetadata;
|
|||||||
import io.lumine.mythic.lib.skill.trigger.TriggerMetadata;
|
import io.lumine.mythic.lib.skill.trigger.TriggerMetadata;
|
||||||
import io.lumine.mythic.lib.skill.trigger.TriggerType;
|
import io.lumine.mythic.lib.skill.trigger.TriggerType;
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
|
import net.Indyuce.mmocore.api.SoundObject;
|
||||||
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.gui.api.item.Placeholders;
|
||||||
import net.Indyuce.mmocore.skill.cast.PlayerKey;
|
|
||||||
import net.Indyuce.mmocore.api.SoundObject;
|
|
||||||
import net.Indyuce.mmocore.skill.cast.KeyCombo;
|
import net.Indyuce.mmocore.skill.cast.KeyCombo;
|
||||||
|
import net.Indyuce.mmocore.skill.cast.PlayerKey;
|
||||||
import net.Indyuce.mmocore.skill.cast.SkillCastingHandler;
|
import net.Indyuce.mmocore.skill.cast.SkillCastingHandler;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -34,15 +32,18 @@ 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.
|
* All the keys that are at the start of a combo.
|
||||||
*/
|
*/
|
||||||
private final Set<PlayerKey> firstComboKeys = new HashSet<>();
|
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. If it's set to
|
||||||
|
* null then the player can press any key which starts a combo.
|
||||||
|
* These "starting keys" are saved in {@link #firstComboKeys}
|
||||||
*/
|
*/
|
||||||
private final boolean needsInitializerKey;
|
@Nullable
|
||||||
private final PlayerKey initializerKey;
|
private final PlayerKey initializerKey;
|
||||||
private final int longestCombo;
|
private final int longestCombo;
|
||||||
|
|
||||||
@ -58,9 +59,8 @@ public class KeyCombos implements Listener {
|
|||||||
|
|
||||||
public KeyCombos(ConfigurationSection config) {
|
public KeyCombos(ConfigurationSection config) {
|
||||||
|
|
||||||
int longestCombo = 0;
|
|
||||||
|
|
||||||
// Load different combos
|
// Load different combos
|
||||||
|
int currentLongestCombo = 0;
|
||||||
for (String key : config.getConfigurationSection("combos").getKeys(false))
|
for (String key : config.getConfigurationSection("combos").getKeys(false))
|
||||||
try {
|
try {
|
||||||
int spellSlot = Integer.valueOf(key);
|
int spellSlot = Integer.valueOf(key);
|
||||||
@ -72,12 +72,12 @@ public class KeyCombos implements Listener {
|
|||||||
|
|
||||||
combos.put(combo, spellSlot);
|
combos.put(combo, spellSlot);
|
||||||
firstComboKeys.add(combo.getAt(0));
|
firstComboKeys.add(combo.getAt(0));
|
||||||
longestCombo = Math.max(longestCombo, combo.countKeys());
|
currentLongestCombo = Math.max(currentLongestCombo, 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());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.longestCombo = longestCombo;
|
this.longestCombo = currentLongestCombo;
|
||||||
|
|
||||||
// Load player key names
|
// Load player key names
|
||||||
actionBarOptions = config.contains("action-bar") ? new ActionBarOptions(config.getConfigurationSection("action-bar")) : null;
|
actionBarOptions = config.contains("action-bar") ? new ActionBarOptions(config.getConfigurationSection("action-bar")) : null;
|
||||||
@ -87,13 +87,9 @@ 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 = needsInitializerKey ? PlayerKey.valueOf(UtilityMethods.enumName(Objects.requireNonNull(
|
initializerKey = config.contains("initializer-key") ? PlayerKey.valueOf(UtilityMethods.enumName(Objects.requireNonNull(
|
||||||
config.getString("initializer-key"), "Could not find initializer key"))) : null;
|
config.getString("initializer-key"), "Could not find initializer key"))) : null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -102,7 +98,7 @@ public class KeyCombos implements Listener {
|
|||||||
Player player = playerData.getPlayer();
|
Player player = playerData.getPlayer();
|
||||||
|
|
||||||
if (!event.getData().isCasting()) {
|
if (!event.getData().isCasting()) {
|
||||||
if (needsInitializerKey) {
|
if (initializerKey != null) {
|
||||||
if (event.getPressed() == initializerKey) {
|
if (event.getPressed() == initializerKey) {
|
||||||
|
|
||||||
// Always cancel event
|
// Always cancel event
|
||||||
@ -122,7 +118,7 @@ public class KeyCombos implements Listener {
|
|||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
||||||
// Start combo
|
// Start combo
|
||||||
CustomSkillCastingHandler casting =new CustomSkillCastingHandler(playerData);
|
CustomSkillCastingHandler casting = new CustomSkillCastingHandler(playerData);
|
||||||
playerData.setSkillCasting(casting);
|
playerData.setSkillCasting(casting);
|
||||||
casting.current.registerKey(event.getPressed());
|
casting.current.registerKey(event.getPressed());
|
||||||
if (beginComboSound != null)
|
if (beginComboSound != null)
|
||||||
@ -132,7 +128,6 @@ public class KeyCombos implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Adding pressed key
|
// Adding pressed key
|
||||||
CustomSkillCastingHandler casting = (CustomSkillCastingHandler) playerData.getSkillCasting();
|
CustomSkillCastingHandler casting = (CustomSkillCastingHandler) playerData.getSkillCasting();
|
||||||
casting.current.registerKey(event.getPressed());
|
casting.current.registerKey(event.getPressed());
|
||||||
|
Loading…
Reference in New Issue
Block a user