more cleanup

This commit is contained in:
Indyuce 2021-08-25 22:57:26 +02:00
parent 3cf8886349
commit 591e92c46c
2 changed files with 214 additions and 211 deletions

View File

@ -1,5 +1,10 @@
package net.Indyuce.mmocore.listener; package net.Indyuce.mmocore.listener;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.manager.ConfigManager;
import net.Indyuce.mmocore.manager.SoundManager;
import net.Indyuce.mmocore.skill.Skill.SkillInfo;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -11,27 +16,23 @@ import org.bukkit.event.player.PlayerSwapHandItemsEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.skill.Skill.SkillInfo;
import net.Indyuce.mmocore.manager.ConfigManager;
import net.Indyuce.mmocore.manager.SoundManager;
public class SpellCast implements Listener { public class SpellCast implements Listener {
@EventHandler @EventHandler
public void a(PlayerSwapHandItemsEvent event) { public void a(PlayerSwapHandItemsEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
ConfigManager.SwapAction action = player.isSneaking() ConfigManager.SwapAction action = player.isSneaking() ? MMOCore.plugin.configManager.sneakingSwapAction : MMOCore.plugin.configManager.normalSwapAction;
? MMOCore.plugin.configManager.sneakingSwapAction
: MMOCore.plugin.configManager.normalSwapAction;
if(action == ConfigManager.SwapAction.VANILLA) return; // Vanilla action does nothing
PlayerData playerData = PlayerData.get(player); if (action == ConfigManager.SwapAction.VANILLA)
return;
// Always cancel event if it's not the vanilla action
event.setCancelled(true); event.setCancelled(true);
/* /*
* hotbar swap feature only if the player is sneaking while entering * Hotbar swap feature, this entirely switches the
* skill casting mode * player's hotbar with their 9 lowest inventory slots
*/ */
if (action == ConfigManager.SwapAction.HOTBAR_SWAP) { if (action == ConfigManager.SwapAction.HOTBAR_SWAP) {
MMOCore.plugin.soundManager.play(player, SoundManager.SoundEvent.HOTBAR_SWAP); MMOCore.plugin.soundManager.play(player, SoundManager.SoundEvent.HOTBAR_SWAP);
@ -43,8 +44,12 @@ public class SpellCast implements Listener {
return; return;
} }
if (!((!MMOCore.plugin.configManager.canCreativeCast && player.getGameMode() == GameMode.CREATIVE) || player.getGameMode() == GameMode.SPECTATOR) // Enter spell casting
&& !playerData.isCasting() && playerData.getBoundSkills().size() > 0) { PlayerData playerData = PlayerData.get(player);
if (player.getGameMode() != GameMode.SPECTATOR
&& (MMOCore.plugin.configManager.canCreativeCast || player.getGameMode() != GameMode.CREATIVE)
&& !playerData.isCasting()
&& playerData.getBoundSkills().size() > 0) {
playerData.skillCasting = new SkillCasting(playerData); playerData.skillCasting = new SkillCasting(playerData);
MMOCore.plugin.soundManager.play(player, SoundManager.SoundEvent.SPELL_CAST_BEGIN); MMOCore.plugin.soundManager.play(player, SoundManager.SoundEvent.SPELL_CAST_BEGIN);
} }
@ -70,7 +75,7 @@ public class SpellCast implements Listener {
@EventHandler() @EventHandler()
public void onSkillCast(PlayerItemHeldEvent event) { public void onSkillCast(PlayerItemHeldEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if(!playerData.isOnline()) return; if (!playerData.isOnline()) return;
if (!event.getPlayer().equals(playerData.getPlayer())) if (!event.getPlayer().equals(playerData.getPlayer()))
return; return;
@ -100,7 +105,7 @@ public class SpellCast implements Listener {
ConfigManager.SwapAction action = player.isSneaking() ConfigManager.SwapAction action = player.isSneaking()
? MMOCore.plugin.configManager.sneakingSwapAction ? MMOCore.plugin.configManager.sneakingSwapAction
: MMOCore.plugin.configManager.normalSwapAction; : MMOCore.plugin.configManager.normalSwapAction;
if(action != ConfigManager.SwapAction.SPELL_CAST || !playerData.isOnline()) return; if (action != ConfigManager.SwapAction.SPELL_CAST || !playerData.isOnline()) return;
if (event.getPlayer().equals(playerData.getPlayer())) { if (event.getPlayer().equals(playerData.getPlayer())) {
MMOCore.plugin.soundManager.play(player, SoundManager.SoundEvent.SPELL_CAST_END); MMOCore.plugin.soundManager.play(player, SoundManager.SoundEvent.SPELL_CAST_END);
MMOCore.plugin.configManager.getSimpleMessage("casting.no-longer").send(playerData.getPlayer()); MMOCore.plugin.configManager.getSimpleMessage("casting.no-longer").send(playerData.getPlayer());
@ -116,11 +121,11 @@ public class SpellCast implements Listener {
private String getFormat(PlayerData data) { private String getFormat(PlayerData data) {
StringBuilder str = new StringBuilder(); StringBuilder str = new StringBuilder();
if(!data.isOnline()) return str.toString(); if (!data.isOnline()) return str.toString();
for (int j = 0; j < data.getBoundSkills().size(); j++) { for (int j = 0; j < data.getBoundSkills().size(); j++) {
SkillInfo skill = data.getBoundSkill(j); SkillInfo skill = data.getBoundSkill(j);
str.append((str.length() == 0) ? "" : split).append((onCooldown(data, skill) str.append((str.length() == 0) ? "" : split).append((onCooldown(data, skill)
? onCooldown .replace("{cooldown}", "" + data.getSkillData().getCooldown(skill) / 1000) ? onCooldown.replace("{cooldown}", "" + data.getSkillData().getCooldown(skill) / 1000)
: noMana(data, skill) ? noMana : ready).replace("{index}", "" + (j + 1 + (data.getPlayer().getInventory().getHeldItemSlot() : noMana(data, skill) ? noMana : ready).replace("{index}", "" + (j + 1 + (data.getPlayer().getInventory().getHeldItemSlot()
<= j ? 1 : 0))).replace("{skill}", data.getBoundSkill(j).getSkill().getName())); <= j ? 1 : 0))).replace("{skill}", data.getBoundSkill(j).getSkill().getName()));
} }
@ -144,7 +149,8 @@ public class SpellCast implements Listener {
@Override @Override
public void run() { public void run() {
if (!playerData.isOnline() || playerData.getPlayer().isDead()) { if (!playerData.isOnline() || playerData.getPlayer().isDead()) {
close(); return; close();
return;
} }
if (j % 20 == 0) if (j % 20 == 0)

View File

@ -135,17 +135,14 @@ death-exp-loss:
# Percentage of current EXP you lose when dying. # Percentage of current EXP you lose when dying.
percent: 30 percent: 30
# Put the "value" of the action you want. # Modify the keybinds for the 'swap hand items' key (F by default)
# If the value is invalid or empty it will #
# default to the vanilla minecraft action. # Available actions:
# spell_cast # - spell_cast (enters the default spell casting mode)
# Enters the default spell casting mode # - vanilla (swaps hand items)
# hotbar_swap # - hotbar_swap (swap the player's horbat with the 9 lowest inventory slots)
# Players can swap their hotbar with the 9 inventory slots #
# right above it by pressing [swap items] while crouching. # If the action is invalid, it will use 'vanilla' by default
# THis allows players to have two combat item sets.
# - vanilla
# The default F action, swapping main hand and offhand.
swap-keybind: swap-keybind:
normal: spell_cast normal: spell_cast
sneaking: hotbar_swap sneaking: hotbar_swap