mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2025-01-07 07:17:46 +01:00
Fixed skill scroller, added option for action bar format
This commit is contained in:
parent
e784230ce7
commit
ede2991066
@ -49,7 +49,7 @@ public abstract class SkillCastingInstance extends BukkitRunnable implements Lis
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!caster.isOnline() || caster.getPlayer().isDead()) {
|
||||
if (!caster.isOnline() || caster.getPlayer().isDead() || caster.getBoundSkills().isEmpty()) {
|
||||
caster.leaveSkillCasting(true);
|
||||
return;
|
||||
}
|
||||
|
@ -16,13 +16,12 @@ import org.bukkit.GameMode;
|
||||
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.*;
|
||||
|
||||
public class KeyCombos extends SkillCastingHandler implements Listener {
|
||||
public class KeyCombos extends SkillCastingHandler {
|
||||
private final ComboMap comboMap;
|
||||
|
||||
/**
|
||||
@ -152,8 +151,7 @@ public class KeyCombos extends SkillCastingHandler implements Listener {
|
||||
|
||||
@Override
|
||||
public void onTick() {
|
||||
if (getCaster().getBoundSkills().isEmpty()) getCaster().leaveSkillCasting(true);
|
||||
else if (actionBarOptions != null) if (actionBarOptions.isSubtitle)
|
||||
if (actionBarOptions != null) if (actionBarOptions.isSubtitle)
|
||||
getCaster().getPlayer().sendTitle(" ", actionBarOptions.format(this), 0, 20, 0);
|
||||
else getCaster().displayActionBar(actionBarOptions.format(this));
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.Indyuce.mmocore.skill.cast.handler;
|
||||
|
||||
import io.lumine.mythic.lib.MythicLib;
|
||||
import io.lumine.mythic.lib.UtilityMethods;
|
||||
import io.lumine.mythic.lib.api.player.EquipmentSlot;
|
||||
import io.lumine.mythic.lib.player.PlayerMetadata;
|
||||
@ -8,6 +9,7 @@ import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.SoundObject;
|
||||
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.cast.PlayerKey;
|
||||
import net.Indyuce.mmocore.skill.cast.SkillCastingHandler;
|
||||
import net.Indyuce.mmocore.skill.cast.SkillCastingInstance;
|
||||
@ -32,6 +34,8 @@ public class SkillScroller extends SkillCastingHandler {
|
||||
@Nullable
|
||||
private final SoundObject enterSound, changeSound, leaveSound;
|
||||
|
||||
private final String actionBarFormat;
|
||||
|
||||
public SkillScroller(@NotNull ConfigurationSection config) {
|
||||
super(config);
|
||||
|
||||
@ -40,6 +44,8 @@ public class SkillScroller extends SkillCastingHandler {
|
||||
changeSound = config.contains("sound.change") ? new SoundObject(config.getConfigurationSection("sound.change")) : null;
|
||||
leaveSound = config.contains("sound.leave") ? new SoundObject(config.getConfigurationSection("sound.leave")) : null;
|
||||
|
||||
actionBarFormat = config.getString("action-bar-format", "CLICK TO CAST: {selected}");
|
||||
|
||||
// Find keybinds
|
||||
enterKey = PlayerKey.valueOf(UtilityMethods.enumName(Objects.requireNonNull(config.getString("enter-key"), "Could not find enter key")));
|
||||
castKey = PlayerKey.valueOf(UtilityMethods.enumName(Objects.requireNonNull(config.getString("cast-key"), "Could not find cast key")));
|
||||
@ -95,44 +101,10 @@ public class SkillScroller extends SkillCastingHandler {
|
||||
|
||||
CustomSkillCastingInstance casting = (CustomSkillCastingInstance) playerData.getSkillCasting();
|
||||
PlayerMetadata caster = playerData.getMMOPlayerData().getStatMap().cache(EquipmentSlot.MAIN_HAND);
|
||||
playerData.getBoundSkill(casting.index).toCastable(playerData).cast(new TriggerMetadata(caster, null, null));
|
||||
casting.getSelected().toCastable(playerData).cast(new TriggerMetadata(caster, null, null));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onScroll(PlayerItemHeldEvent event) {
|
||||
PlayerData playerData = PlayerData.get(event.getPlayer());
|
||||
if (!playerData.isCasting()) return;
|
||||
|
||||
if (playerData.getBoundSkills().isEmpty()) {
|
||||
playerData.leaveSkillCasting(true);
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
final int previous = event.getPreviousSlot(), current = event.getNewSlot();
|
||||
final int dist1 = 9 + current - previous, dist2 = current - previous, dist3 = current - previous - 9;
|
||||
final int change = Math.abs(dist1) < Math.abs(dist2) ? (Math.abs(dist1) < Math.abs(dist3) ? dist1 : dist3) : (Math.abs(dist3) < Math.abs(dist2) ? dist3 : dist2);
|
||||
|
||||
// Scroll trough items
|
||||
final CustomSkillCastingInstance casting = (CustomSkillCastingInstance) playerData.getSkillCasting();
|
||||
casting.index = mod(casting.index + change, playerData.getBoundSkills().size());
|
||||
casting.onTick();
|
||||
casting.refreshTimeOut();
|
||||
|
||||
if (changeSound != null) changeSound.playTo(event.getPlayer());
|
||||
}
|
||||
|
||||
private int mod(int x, int n) {
|
||||
|
||||
while (x < 0) x += n;
|
||||
|
||||
while (x >= n) x -= n;
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
public class CustomSkillCastingInstance extends SkillCastingInstance {
|
||||
private int index = 0;
|
||||
|
||||
@ -142,7 +114,44 @@ public class SkillScroller extends SkillCastingHandler {
|
||||
|
||||
@Override
|
||||
public void onTick() {
|
||||
getCaster().displayActionBar("CLICK: " + getCaster().getBoundSkill(index).getSkill().getName());
|
||||
final String skillName = getSelected().getSkill().getName();
|
||||
final String actionBarFormat = MythicLib.plugin.getPlaceholderParser().parse(getCaster().getPlayer(), SkillScroller.this.actionBarFormat.replace("{selected}", skillName));
|
||||
getCaster().displayActionBar(actionBarFormat);
|
||||
}
|
||||
|
||||
public ClassSkill getSelected() {
|
||||
return getCaster().getBoundSkill(index + 1);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onScroll(PlayerItemHeldEvent event) {
|
||||
if (!event.getPlayer().equals(getCaster().getPlayer())) return;
|
||||
|
||||
PlayerData playerData = PlayerData.get(event.getPlayer());
|
||||
if (playerData.getBoundSkills().isEmpty()) {
|
||||
playerData.leaveSkillCasting(true);
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
final int previous = event.getPreviousSlot(), current = event.getNewSlot();
|
||||
final int dist1 = 9 + current - previous, dist2 = current - previous, dist3 = current - previous - 9;
|
||||
final int change = Math.abs(dist1) < Math.abs(dist2) ? (Math.abs(dist1) < Math.abs(dist3) ? dist1 : dist3) : (Math.abs(dist3) < Math.abs(dist2) ? dist3 : dist2);
|
||||
|
||||
// Scroll trough items
|
||||
final CustomSkillCastingInstance casting = (CustomSkillCastingInstance) playerData.getSkillCasting();
|
||||
casting.index = mod(casting.index + change, playerData.getBoundSkills().size());
|
||||
casting.onTick();
|
||||
casting.refreshTimeOut();
|
||||
|
||||
if (changeSound != null) changeSound.playTo(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
private int mod(int x, int n) {
|
||||
while (x < 0) x += n;
|
||||
while (x >= n) x -= n;
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user