Option for skill bar casting to disable sneak support

This commit is contained in:
Indyuce 2022-11-10 16:49:33 +01:00
parent da777d5ac5
commit e056f2c34f
5 changed files with 25 additions and 20 deletions

View File

@ -996,7 +996,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
return Objects.requireNonNull(skillCasting, "Player not in casting mode"); return Objects.requireNonNull(skillCasting, "Player not in casting mode");
} }
public void leaveCastingMode() { public void leaveSkillCasting() {
Validate.isTrue(isCasting(), "Player not in casting mode"); Validate.isTrue(isCasting(), "Player not in casting mode");
skillCasting.close(); skillCasting.close();
this.skillCasting = null; this.skillCasting = null;

View File

@ -40,7 +40,7 @@ public abstract class SkillCastingHandler extends BukkitRunnable implements List
@Override @Override
public void run() { public void run() {
if (!caster.isOnline() || caster.getPlayer().isDead()) if (!caster.isOnline() || caster.getPlayer().isDead())
caster.leaveCastingMode(); caster.leaveSkillCasting();
else { else {
// Apply casting particles // Apply casting particles

View File

@ -19,6 +19,7 @@ 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;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.*; import java.util.*;
@ -80,7 +81,7 @@ public class KeyCombos implements Listener {
return; return;
} }
CustomSkillCastingHandler casting = null; @Nullable CustomSkillCastingHandler casting = null;
// Player is already casting // Player is already casting
if (event.getData().isCasting()) if (event.getData().isCasting())
@ -88,7 +89,7 @@ public class KeyCombos implements Listener {
// Start combo when there is NO initializer key // Start combo when there is NO initializer key
else { else {
final ComboMap comboMap = Objects.requireNonNullElse(playerData.getProfess().getComboMap(), this.comboMap); final @NotNull ComboMap comboMap = Objects.requireNonNullElse(playerData.getProfess().getComboMap(), this.comboMap);
if (comboMap.isComboStart(event.getPressed())) { if (comboMap.isComboStart(event.getPressed())) {
casting = new CustomSkillCastingHandler(playerData); casting = new CustomSkillCastingHandler(playerData);
playerData.setSkillCasting(casting); playerData.setSkillCasting(casting);
@ -113,7 +114,7 @@ public class KeyCombos implements Listener {
// Hash current combo and check // Hash current combo and check
if (casting.combos.getCombos().containsKey(casting.current)) { if (casting.combos.getCombos().containsKey(casting.current)) {
final int spellSlot = casting.combos.getCombos().get(casting.current) - 1; final int spellSlot = casting.combos.getCombos().get(casting.current) - 1;
playerData.leaveCastingMode(); playerData.leaveSkillCasting();
// Cast spell // Cast spell
if (playerData.hasSkillBound(spellSlot)) { if (playerData.hasSkillBound(spellSlot)) {
@ -125,7 +126,7 @@ public class KeyCombos implements Listener {
// Check if current combo is too large // Check if current combo is too large
if (casting.current.countKeys() >= casting.combos.getLongest()) { if (casting.current.countKeys() >= casting.combos.getLongest()) {
playerData.leaveCastingMode(); playerData.leaveSkillCasting();
if (failComboSound != null) if (failComboSound != null)
failComboSound.playTo(player); failComboSound.playTo(player);
} }

View File

@ -5,12 +5,10 @@ import io.lumine.mythic.lib.api.player.EquipmentSlot;
import io.lumine.mythic.lib.player.PlayerMetadata; import io.lumine.mythic.lib.player.PlayerMetadata;
import io.lumine.mythic.lib.skill.trigger.TriggerMetadata; import io.lumine.mythic.lib.skill.trigger.TriggerMetadata;
import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.event.PlayerKeyPressEvent;
import net.Indyuce.mmocore.api.SoundEvent; import net.Indyuce.mmocore.api.SoundEvent;
import net.Indyuce.mmocore.loot.chest.particle.CastingParticle; import net.Indyuce.mmocore.api.event.PlayerKeyPressEvent;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.skill.ClassSkill; import net.Indyuce.mmocore.skill.ClassSkill;
import net.Indyuce.mmocore.skill.RegisteredSkill;
import net.Indyuce.mmocore.skill.cast.PlayerKey; import net.Indyuce.mmocore.skill.cast.PlayerKey;
import net.Indyuce.mmocore.skill.cast.SkillCastingHandler; import net.Indyuce.mmocore.skill.cast.SkillCastingHandler;
import org.bukkit.GameMode; import org.bukkit.GameMode;
@ -25,9 +23,11 @@ import java.util.Objects;
public class SkillBar implements Listener { public class SkillBar implements Listener {
private final PlayerKey mainKey; private final PlayerKey mainKey;
private final boolean disableSneak;
public SkillBar(ConfigurationSection config) { public SkillBar(ConfigurationSection config) {
mainKey = PlayerKey.valueOf(UtilityMethods.enumName(Objects.requireNonNull(config.getString("open"), "Could not find open key"))); mainKey = PlayerKey.valueOf(UtilityMethods.enumName(Objects.requireNonNull(config.getString("open"), "Could not find open key")));
disableSneak = config.getBoolean("disable-sneak");
} }
@EventHandler @EventHandler
@ -62,10 +62,13 @@ public class SkillBar implements Listener {
@EventHandler @EventHandler
public void onSkillCast(PlayerItemHeldEvent event) { public void onSkillCast(PlayerItemHeldEvent event) {
Player player = event.getPlayer();
if (!getCaster().isOnline()) return;
if (!event.getPlayer().equals(getCaster().getPlayer())) return; if (!event.getPlayer().equals(getCaster().getPlayer())) return;
if (!getCaster().isOnline()) {
getCaster().leaveSkillCasting();
return;
}
/* /*
* When the event is cancelled, another playerItemHeldEvent is * When the event is cancelled, another playerItemHeldEvent is
* called and previous and next slots are equal. the event must not * called and previous and next slots are equal. the event must not
@ -73,8 +76,9 @@ public class SkillBar implements Listener {
*/ */
if (event.getPreviousSlot() == event.getNewSlot()) return; if (event.getPreviousSlot() == event.getNewSlot()) return;
//If the player is sneaking, we don't trigger the casting mode (used to avoid conflicts with other plugins using shift+F to open GUI. // Extra option to improve support with other plugins
if(player.isSneaking()) return; final Player player = event.getPlayer();
if (disableSneak && player.isSneaking()) return;
event.setCancelled(true); event.setCancelled(true);
int slot = event.getNewSlot() + (event.getNewSlot() >= player.getInventory().getHeldItemSlot() ? -1 : 0); int slot = event.getNewSlot() + (event.getNewSlot() >= player.getInventory().getHeldItemSlot() ? -1 : 0);
@ -86,8 +90,8 @@ public class SkillBar implements Listener {
*/ */
if (slot >= 0 && getCaster().hasSkillBound(slot)) { if (slot >= 0 && getCaster().hasSkillBound(slot)) {
PlayerMetadata caster = getCaster().getMMOPlayerData().getStatMap().cache(EquipmentSlot.MAIN_HAND); PlayerMetadata caster = getCaster().getMMOPlayerData().getStatMap().cache(EquipmentSlot.MAIN_HAND);
int delay= getCaster().getBoundSkill(slot).getDelay(getCaster()); int delay = getCaster().getBoundSkill(slot).getDelay(getCaster());
getCaster().getBoundSkill(slot).toCastable(getCaster()).cast(new TriggerMetadata(caster, null, null),delay); getCaster().getBoundSkill(slot).toCastable(getCaster()).cast(new TriggerMetadata(caster, null, null), delay);
} }
} }
@ -103,7 +107,7 @@ public class SkillBar implements Listener {
MMOCore.plugin.configManager.getSimpleMessage("casting.no-longer").send(getCaster().getPlayer()); MMOCore.plugin.configManager.getSimpleMessage("casting.no-longer").send(getCaster().getPlayer());
} }
}.runTask(MMOCore.plugin); }.runTask(MMOCore.plugin);
PlayerData.get(player).leaveCastingMode(); getCaster().leaveSkillCasting();
} }
} }
@ -115,7 +119,7 @@ public class SkillBar implements Listener {
str.append((str.length() == 0) ? "" : split).append((onCooldown(data, skill) ? onCooldown.replace("{cooldown}", str.append((str.length() == 0) ? "" : split).append((onCooldown(data, skill) ? onCooldown.replace("{cooldown}",
String.valueOf(data.getCooldownMap().getInfo(skill).getRemaining() / 1000)) : noMana(data, skill) ? noMana : (noStamina( String.valueOf(data.getCooldownMap().getInfo(skill).getRemaining() / 1000)) : noMana(data, skill) ? noMana : (noStamina(
data, skill) ? noStamina : ready)).replace("{index}", data, skill) ? noStamina : ready)).replace("{index}",
"" + (j + 1 + (data.getPlayer().getInventory().getHeldItemSlot() <= j ? 1 : 0))) "" + (j + 1 + (data.getPlayer().getInventory().getHeldItemSlot() <= j ? 1 : 0)))
.replace("{skill}", data.getBoundSkill(j).getSkill().getName())); .replace("{skill}", data.getBoundSkill(j).getSkill().getName()));
} }
return MMOCore.plugin.placeholderParser.parse(data.getPlayer(), str.toString()); return MMOCore.plugin.placeholderParser.parse(data.getPlayer(), str.toString());

View File

@ -54,7 +54,7 @@ public class SkillScroller implements Listener {
if (event.getPressed().shouldCancelEvent()) if (event.getPressed().shouldCancelEvent())
event.setCancelled(true); event.setCancelled(true);
playerData.leaveCastingMode(); playerData.leaveSkillCasting();
if (leaveSound != null) if (leaveSound != null)
leaveSound.playTo(player); leaveSound.playTo(player);
return; return;
@ -94,7 +94,7 @@ public class SkillScroller implements Listener {
return; return;
if (playerData.getBoundSkills().isEmpty()) { if (playerData.getBoundSkills().isEmpty()) {
playerData.leaveCastingMode(); playerData.leaveSkillCasting();
return; return;
} }