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");
}
public void leaveCastingMode() {
public void leaveSkillCasting() {
Validate.isTrue(isCasting(), "Player not in casting mode");
skillCasting.close();
this.skillCasting = null;

View File

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

View File

@ -19,6 +19,7 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
import java.util.*;
@ -80,7 +81,7 @@ public class KeyCombos implements Listener {
return;
}
CustomSkillCastingHandler casting = null;
@Nullable CustomSkillCastingHandler casting = null;
// Player is already casting
if (event.getData().isCasting())
@ -88,7 +89,7 @@ public class KeyCombos implements Listener {
// Start combo when there is NO initializer key
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())) {
casting = new CustomSkillCastingHandler(playerData);
playerData.setSkillCasting(casting);
@ -113,7 +114,7 @@ public class KeyCombos implements Listener {
// Hash current combo and check
if (casting.combos.getCombos().containsKey(casting.current)) {
final int spellSlot = casting.combos.getCombos().get(casting.current) - 1;
playerData.leaveCastingMode();
playerData.leaveSkillCasting();
// Cast spell
if (playerData.hasSkillBound(spellSlot)) {
@ -125,7 +126,7 @@ public class KeyCombos implements Listener {
// Check if current combo is too large
if (casting.current.countKeys() >= casting.combos.getLongest()) {
playerData.leaveCastingMode();
playerData.leaveSkillCasting();
if (failComboSound != null)
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.skill.trigger.TriggerMetadata;
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.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.RegisteredSkill;
import net.Indyuce.mmocore.skill.cast.PlayerKey;
import net.Indyuce.mmocore.skill.cast.SkillCastingHandler;
import org.bukkit.GameMode;
@ -25,9 +23,11 @@ import java.util.Objects;
public class SkillBar implements Listener {
private final PlayerKey mainKey;
private final boolean disableSneak;
public SkillBar(ConfigurationSection config) {
mainKey = PlayerKey.valueOf(UtilityMethods.enumName(Objects.requireNonNull(config.getString("open"), "Could not find open key")));
disableSneak = config.getBoolean("disable-sneak");
}
@EventHandler
@ -62,10 +62,13 @@ public class SkillBar implements Listener {
@EventHandler
public void onSkillCast(PlayerItemHeldEvent event) {
Player player = event.getPlayer();
if (!getCaster().isOnline()) return;
if (!event.getPlayer().equals(getCaster().getPlayer())) return;
if (!getCaster().isOnline()) {
getCaster().leaveSkillCasting();
return;
}
/*
* When the event is cancelled, another playerItemHeldEvent is
* 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 the player is sneaking, we don't trigger the casting mode (used to avoid conflicts with other plugins using shift+F to open GUI.
if(player.isSneaking()) return;
// Extra option to improve support with other plugins
final Player player = event.getPlayer();
if (disableSneak && player.isSneaking()) return;
event.setCancelled(true);
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)) {
PlayerMetadata caster = getCaster().getMMOPlayerData().getStatMap().cache(EquipmentSlot.MAIN_HAND);
int delay= getCaster().getBoundSkill(slot).getDelay(getCaster());
getCaster().getBoundSkill(slot).toCastable(getCaster()).cast(new TriggerMetadata(caster, null, null),delay);
int delay = getCaster().getBoundSkill(slot).getDelay(getCaster());
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());
}
}.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}",
String.valueOf(data.getCooldownMap().getInfo(skill).getRemaining() / 1000)) : noMana(data, skill) ? noMana : (noStamina(
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()));
}
return MMOCore.plugin.placeholderParser.parse(data.getPlayer(), str.toString());

View File

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