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,150 +16,151 @@ 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
public void a(PlayerSwapHandItemsEvent event) {
Player player = event.getPlayer();
ConfigManager.SwapAction action = player.isSneaking()
? MMOCore.plugin.configManager.sneakingSwapAction
: MMOCore.plugin.configManager.normalSwapAction;
if(action == ConfigManager.SwapAction.VANILLA) return; @EventHandler
PlayerData playerData = PlayerData.get(player); public void a(PlayerSwapHandItemsEvent event) {
event.setCancelled(true); Player player = event.getPlayer();
ConfigManager.SwapAction action = player.isSneaking() ? MMOCore.plugin.configManager.sneakingSwapAction : MMOCore.plugin.configManager.normalSwapAction;
/* // Vanilla action does nothing
* hotbar swap feature only if the player is sneaking while entering if (action == ConfigManager.SwapAction.VANILLA)
* skill casting mode return;
*/
if (action == ConfigManager.SwapAction.HOTBAR_SWAP) {
MMOCore.plugin.soundManager.play(player, SoundManager.SoundEvent.HOTBAR_SWAP);
for (int j = 0; j < 9; j++) {
ItemStack replaced = player.getInventory().getItem(j + 9 * 3);
player.getInventory().setItem(j + 9 * 3, player.getInventory().getItem(j));
player.getInventory().setItem(j, replaced);
}
return;
}
if (!((!MMOCore.plugin.configManager.canCreativeCast && player.getGameMode() == GameMode.CREATIVE) || player.getGameMode() == GameMode.SPECTATOR) // Always cancel event if it's not the vanilla action
&& !playerData.isCasting() && playerData.getBoundSkills().size() > 0) { event.setCancelled(true);
playerData.skillCasting = new SkillCasting(playerData);
MMOCore.plugin.soundManager.play(player, SoundManager.SoundEvent.SPELL_CAST_BEGIN);
}
}
public class SkillCasting extends BukkitRunnable implements Listener { /*
private final PlayerData playerData; * Hotbar swap feature, this entirely switches the
* player's hotbar with their 9 lowest inventory slots
*/
if (action == ConfigManager.SwapAction.HOTBAR_SWAP) {
MMOCore.plugin.soundManager.play(player, SoundManager.SoundEvent.HOTBAR_SWAP);
for (int j = 0; j < 9; j++) {
ItemStack replaced = player.getInventory().getItem(j + 9 * 3);
player.getInventory().setItem(j + 9 * 3, player.getInventory().getItem(j));
player.getInventory().setItem(j, replaced);
}
return;
}
private final String ready = MMOCore.plugin.configManager.getSimpleMessage("casting.action-bar.ready").message(); // Enter spell casting
private final String onCooldown = MMOCore.plugin.configManager.getSimpleMessage("casting.action-bar.on-cooldown").message(); PlayerData playerData = PlayerData.get(player);
private final String noMana = MMOCore.plugin.configManager.getSimpleMessage("casting.action-bar.no-mana").message(); if (player.getGameMode() != GameMode.SPECTATOR
private final String split = MMOCore.plugin.configManager.getSimpleMessage("casting.split").message(); && (MMOCore.plugin.configManager.canCreativeCast || player.getGameMode() != GameMode.CREATIVE)
&& !playerData.isCasting()
&& playerData.getBoundSkills().size() > 0) {
playerData.skillCasting = new SkillCasting(playerData);
MMOCore.plugin.soundManager.play(player, SoundManager.SoundEvent.SPELL_CAST_BEGIN);
}
}
private int j; public class SkillCasting extends BukkitRunnable implements Listener {
private final PlayerData playerData;
public SkillCasting(PlayerData playerData) { private final String ready = MMOCore.plugin.configManager.getSimpleMessage("casting.action-bar.ready").message();
this.playerData = playerData; private final String onCooldown = MMOCore.plugin.configManager.getSimpleMessage("casting.action-bar.on-cooldown").message();
private final String noMana = MMOCore.plugin.configManager.getSimpleMessage("casting.action-bar.no-mana").message();
private final String split = MMOCore.plugin.configManager.getSimpleMessage("casting.split").message();
Bukkit.getPluginManager().registerEvents(this, MMOCore.plugin); private int j;
runTaskTimer(MMOCore.plugin, 0, 1);
}
@EventHandler() public SkillCasting(PlayerData playerData) {
public void onSkillCast(PlayerItemHeldEvent event) { this.playerData = playerData;
Player player = event.getPlayer();
if(!playerData.isOnline()) return;
if (!event.getPlayer().equals(playerData.getPlayer()))
return;
/* Bukkit.getPluginManager().registerEvents(this, MMOCore.plugin);
* when the event is cancelled, another playerItemHeldEvent is runTaskTimer(MMOCore.plugin, 0, 1);
* called and previous and next slots are equal. the event must not }
* listen to that non-player called event.
*/
if (event.getPreviousSlot() == event.getNewSlot())
return;
event.setCancelled(true); @EventHandler()
int slot = event.getNewSlot() + (event.getNewSlot() >= player.getInventory().getHeldItemSlot() ? -1 : 0); public void onSkillCast(PlayerItemHeldEvent event) {
Player player = event.getPlayer();
if (!playerData.isOnline()) return;
if (!event.getPlayer().equals(playerData.getPlayer()))
return;
/* /*
* the event is called again soon after the first since when * when the event is cancelled, another playerItemHeldEvent is
* cancelling the first one, the player held item slot must go back * called and previous and next slots are equal. the event must not
* to the previous one. * listen to that non-player called event.
*/ */
if (slot >= 0 && playerData.hasSkillBound(slot)) if (event.getPreviousSlot() == event.getNewSlot())
playerData.cast(playerData.getBoundSkill(slot)); return;
}
@EventHandler event.setCancelled(true);
public void stopCasting(PlayerSwapHandItemsEvent event) { int slot = event.getNewSlot() + (event.getNewSlot() >= player.getInventory().getHeldItemSlot() ? -1 : 0);
Player player = event.getPlayer();
ConfigManager.SwapAction action = player.isSneaking()
? MMOCore.plugin.configManager.sneakingSwapAction
: MMOCore.plugin.configManager.normalSwapAction;
if(action != ConfigManager.SwapAction.SPELL_CAST || !playerData.isOnline()) return;
if (event.getPlayer().equals(playerData.getPlayer())) {
MMOCore.plugin.soundManager.play(player, SoundManager.SoundEvent.SPELL_CAST_END);
MMOCore.plugin.configManager.getSimpleMessage("casting.no-longer").send(playerData.getPlayer());
close();
}
}
private void close() { /*
playerData.skillCasting = null; * the event is called again soon after the first since when
HandlerList.unregisterAll(this); * cancelling the first one, the player held item slot must go back
cancel(); * to the previous one.
} */
if (slot >= 0 && playerData.hasSkillBound(slot))
playerData.cast(playerData.getBoundSkill(slot));
}
private String getFormat(PlayerData data) { @EventHandler
StringBuilder str = new StringBuilder(); public void stopCasting(PlayerSwapHandItemsEvent event) {
if(!data.isOnline()) return str.toString(); Player player = event.getPlayer();
for (int j = 0; j < data.getBoundSkills().size(); j++) { ConfigManager.SwapAction action = player.isSneaking()
SkillInfo skill = data.getBoundSkill(j); ? MMOCore.plugin.configManager.sneakingSwapAction
str.append((str.length() == 0) ? "" : split).append((onCooldown(data, skill) : MMOCore.plugin.configManager.normalSwapAction;
? onCooldown .replace("{cooldown}", "" + data.getSkillData().getCooldown(skill) / 1000) if (action != ConfigManager.SwapAction.SPELL_CAST || !playerData.isOnline()) return;
: noMana(data, skill) ? noMana : ready).replace("{index}", "" + (j + 1 + (data.getPlayer().getInventory().getHeldItemSlot() if (event.getPlayer().equals(playerData.getPlayer())) {
<= j ? 1 : 0))).replace("{skill}", data.getBoundSkill(j).getSkill().getName())); MMOCore.plugin.soundManager.play(player, SoundManager.SoundEvent.SPELL_CAST_END);
} MMOCore.plugin.configManager.getSimpleMessage("casting.no-longer").send(playerData.getPlayer());
close();
}
}
return str.toString(); private void close() {
} playerData.skillCasting = null;
HandlerList.unregisterAll(this);
cancel();
}
/* private String getFormat(PlayerData data) {
* no longer use index as arguments because data.getBoundSkill(int) has StringBuilder str = new StringBuilder();
* n-complexity, it has to iterate through a list. using skillInfo if (!data.isOnline()) return str.toString();
* argument uses only one iteration for (int j = 0; j < data.getBoundSkills().size(); j++) {
*/ SkillInfo skill = data.getBoundSkill(j);
private boolean onCooldown(PlayerData data, SkillInfo skill) { str.append((str.length() == 0) ? "" : split).append((onCooldown(data, skill)
return skill.getSkill().hasModifier("cooldown") && data.getSkillData().getCooldown(skill) > 0; ? onCooldown.replace("{cooldown}", "" + data.getSkillData().getCooldown(skill) / 1000)
} : noMana(data, skill) ? noMana : ready).replace("{index}", "" + (j + 1 + (data.getPlayer().getInventory().getHeldItemSlot()
<= j ? 1 : 0))).replace("{skill}", data.getBoundSkill(j).getSkill().getName()));
}
private boolean noMana(PlayerData data, SkillInfo skill) { return str.toString();
return skill.getSkill().hasModifier("mana") && skill.getModifier("mana", data.getSkillLevel(skill.getSkill())) > data.getMana(); }
}
@Override /*
public void run() { * no longer use index as arguments because data.getBoundSkill(int) has
if (!playerData.isOnline() || playerData.getPlayer().isDead()) { * n-complexity, it has to iterate through a list. using skillInfo
close(); return; * argument uses only one iteration
} */
private boolean onCooldown(PlayerData data, SkillInfo skill) {
return skill.getSkill().hasModifier("cooldown") && data.getSkillData().getCooldown(skill) > 0;
}
if (j % 20 == 0) private boolean noMana(PlayerData data, SkillInfo skill) {
playerData.displayActionBar(getFormat(playerData)); return skill.getSkill().hasModifier("mana") && skill.getModifier("mana", data.getSkillLevel(skill.getSkill())) > data.getMana();
}
for (int k = 0; k < 2; k++) { @Override
double a = (double) j++ / 5; public void run() {
playerData.getProfess().getCastParticle() if (!playerData.isOnline() || playerData.getPlayer().isDead()) {
.display(playerData.getPlayer().getLocation().add(Math.cos(a), 1 + Math.sin(a / 3) / 1.3, Math.sin(a))); close();
} return;
} }
}
if (j % 20 == 0)
playerData.displayActionBar(getFormat(playerData));
for (int k = 0; k < 2; k++) {
double a = (double) j++ / 5;
playerData.getProfess().getCastParticle()
.display(playerData.getPlayer().getLocation().add(Math.cos(a), 1 + Math.sin(a / 3) / 1.3, Math.sin(a)));
}
}
}
} }

View File

@ -14,33 +14,33 @@ config-version: 7
# (class, level, etc.) and guild data # (class, level, etc.) and guild data
# (guild names, members, etc.) at a set interval. # (guild names, members, etc.) at a set interval.
auto-save: auto-save:
enabled: true enabled: true
interval: 1800 # In seconds (1800 = 30 minutes) interval: 1800 # In seconds (1800 = 30 minutes)
# MySQL Support # MySQL Support
mysql: mysql:
enabled: false enabled: false
host: localhost host: localhost
port: 3306 port: 3306
database: minecraft database: minecraft
user: mmolover user: mmolover
pass: ILoveAria pass: ILoveAria
properties: properties:
cachePrepStmts: true cachePrepStmts: true
prepStmtCacheSize: 250 prepStmtCacheSize: 250
prepStmtCacheSqlLimit: 2048 prepStmtCacheSqlLimit: 2048
# Will verbose to the console whenever # Will verbose to the console whenever
# data is saved/loaded from the SQL database. # data is saved/loaded from the SQL database.
debug: false debug: false
# The default values for all playerdata # The default values for all playerdata
# All new players will start with these values # All new players will start with these values
default-playerdata: default-playerdata:
level: 1 level: 1
class-points: 0 class-points: 0
skill-points: 0 skill-points: 0
attribute-points: 0 attribute-points: 0
attribute-realloc-points: 0 attribute-realloc-points: 0
# The list of all conditions which must be met for the # The list of all conditions which must be met for the
# BLOCK REGEN and BLOCK RESTRICTIONS to apply. Set to # BLOCK REGEN and BLOCK RESTRICTIONS to apply. Set to
@ -51,8 +51,8 @@ default-playerdata:
# #
# ^ will enable custom mining server wide # ^ will enable custom mining server wide
custom-mine-conditions: custom-mine-conditions:
- 'world{name="world,world_nether,world_the_end"}' - 'world{name="world,world_nether,world_the_end"}'
- 'region{name="example_region,example_region2,__global__"}' - 'region{name="example_region,example_region2,__global__"}'
# Set to true to prevent vanilla blocks from being # Set to true to prevent vanilla blocks from being
# broken when custom mining conditions are met # broken when custom mining conditions are met
@ -64,57 +64,57 @@ should-cobblestone-generators-give-exp: false
loot-chests: loot-chests:
# Time in seconds it takes for a loot chest to # Time in seconds it takes for a loot chest to
# expire after it was spawned. 600 is 10 minutes. # expire after it was spawned. 600 is 10 minutes.
chest-expire-time: 600 chest-expire-time: 600
# Interval in seconds before the same player # Interval in seconds before the same player
# spawns two loot chests in ANY region. # spawns two loot chests in ANY region.
player-cooldown: 600 player-cooldown: 600
# Settings for the default action bar # Settings for the default action bar
action-bar: action-bar:
# Whether or not to use the default action bar. # Whether or not to use the default action bar.
# (This doesn't change any other action bars provided by MMOCore.) # (This doesn't change any other action bars provided by MMOCore.)
enabled: true enabled: true
# The decimal format for stats (not including stat formats in stats.yml) # The decimal format for stats (not including stat formats in stats.yml)
decimal: "0.#" decimal: "0.#"
# The amount of miliseconds the bar will be faded # The amount of miliseconds the bar will be faded
#out when displaying other action bars. #out when displaying other action bars.
time-out: 60 time-out: 60
# The amount of ticks before updating the info # The amount of ticks before updating the info
ticks-to-update: 5 ticks-to-update: 5
# How to display the data. # How to display the data.
format: "&c❤ {health}/{max_health} &f| {mana_icon} {mana}/{max_mana} &f| &7⛨ {armor}" format: "&c❤ {health}/{max_health} &f| {mana_icon} {mana}/{max_mana} &f| &7⛨ {armor}"
party: party:
# Edit party buffs here. You may # Edit party buffs here. You may
# add as many stats as you want. # add as many stats as you want.
buff: buff:
health-regeneration: 3 health-regeneration: 3
additional-experience: 5 additional-experience: 5
# Prefix you need to put in the chat
# to talk in the party chat.
chat-prefix: '@'
# The max players that can be in # Prefix you need to put in the chat
# any given party. Between 2-8. # to talk in the party chat.
max-players: 8 chat-prefix: '@'
# The max players that can be in
# any given party. Between 2-8.
max-players: 8
# Redirects vanilla experience obtained to MMOCore # Redirects vanilla experience obtained to MMOCore
# class experience. You can define the % of the vanilla # class experience. You can define the % of the vanilla
# experience that is being transfered as MMOCore exp. # experience that is being transfered as MMOCore exp.
# Requires a SERVER reload when changed. # Requires a SERVER reload when changed.
vanilla-exp-redirection: vanilla-exp-redirection:
enabled: false enabled: false
ratio: 0.8 ratio: 0.8
# Enable this open to override vanilla EXP and display # Enable this open to override vanilla EXP and display
# level progress on the vanilla experience bar. # level progress on the vanilla experience bar.
@ -130,25 +130,22 @@ display-main-class-exp-holograms: true
# Requires a SERVER reload when changed. # Requires a SERVER reload when changed.
death-exp-loss: death-exp-loss:
enabled: false enabled: false
# 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
# Set this to true to allow players # Set this to true to allow players
# in creative mode to enter casting mode # in creative mode to enter casting mode
@ -163,7 +160,7 @@ prevent-spawner-xp: true
# Timer for combat log to expire (in seconds) # Timer for combat log to expire (in seconds)
combat-log: combat-log:
timer: 10 timer: 10
# Whether or not the default class should save information (level, # Whether or not the default class should save information (level,
# skills, etc.) when selecting a new class # skills, etc.) when selecting a new class
@ -172,9 +169,9 @@ save-default-class-info: false
# Change this to the name of the color you want for # Change this to the name of the color you want for
# the different resource bar placeholders # the different resource bar placeholders
resource-bar-colors: resource-bar-colors:
stamina-whole: 'GREEN' stamina-whole: 'GREEN'
stamina-half: 'DARK_GREEN' stamina-half: 'DARK_GREEN'
stamina-empty: 'WHITE' stamina-empty: 'WHITE'
# Whether or not the admin commands should display # Whether or not the admin commands should display
# the result of the command when ran. # the result of the command when ran.
@ -185,11 +182,11 @@ resource-bar-colors:
# console - Only verbose when ran from console # console - Only verbose when ran from console
# false - Never verbose # false - Never verbose
command-verbose: command-verbose:
attribute: true attribute: true
class: true class: true
experience: true experience: true
level: true level: true
nocd: true nocd: true
points: true points: true
reset: true reset: true
resource: true resource: true