From 71b7727a152d41e3bf2fe5b95b7fc42c9c93f225 Mon Sep 17 00:00:00 2001 From: Starmism Date: Mon, 24 Apr 2023 14:40:23 -0600 Subject: [PATCH 01/11] feat(conditions): Add Weather and Time conditions --- .../mmocore/api/load/DefaultMMOLoader.java | 6 +++ .../loot/chest/condition/TimeCondition.java | 37 +++++++++++++++++++ .../chest/condition/WeatherCondition.java | 34 +++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 MMOCore-API/src/main/java/net/Indyuce/mmocore/loot/chest/condition/TimeCondition.java create mode 100644 MMOCore-API/src/main/java/net/Indyuce/mmocore/loot/chest/condition/WeatherCondition.java diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java index 53458d1b..6e87d2ab 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java @@ -119,6 +119,12 @@ public class DefaultMMOLoader extends MMOLoader { if (config.getKey().equals("permission")) return new PermissionCondition(config); + if (config.getKey().equals("weather")) + return new WeatherCondition(config); + + if (config.getKey().equals("time")) + return new TimeCondition(config); + return null; } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/loot/chest/condition/TimeCondition.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/loot/chest/condition/TimeCondition.java new file mode 100644 index 00000000..1e0fc82e --- /dev/null +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/loot/chest/condition/TimeCondition.java @@ -0,0 +1,37 @@ +package net.Indyuce.mmocore.loot.chest.condition; + +import io.lumine.mythic.lib.api.MMOLineConfig; +import org.apache.commons.lang.Validate; +import org.bukkit.entity.Player; + +public class TimeCondition extends Condition { + + private final int min; + private final int max; + + public TimeCondition(MMOLineConfig config) { + super(config); + + Validate.isTrue(config.contains("min")); + Validate.isTrue(config.contains("max")); + + min = config.getInt("min"); + max = config.getInt("max"); + } + + @Override + public boolean isMet(ConditionInstance entity) { + if (entity.getEntity() instanceof Player player) { + long time = player.getWorld().getTime(); + + if (min < max) { + return time > min && time < max; + } else { + // Allows for wrapping times, such as min=20000 max=6000 + return time > min || time < max; + } + } + + return false; + } +} diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/loot/chest/condition/WeatherCondition.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/loot/chest/condition/WeatherCondition.java new file mode 100644 index 00000000..37285a1f --- /dev/null +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/loot/chest/condition/WeatherCondition.java @@ -0,0 +1,34 @@ +package net.Indyuce.mmocore.loot.chest.condition; + +import io.lumine.mythic.lib.api.MMOLineConfig; +import org.apache.commons.lang.Validate; +import org.bukkit.entity.Player; + +public class WeatherCondition extends Condition { + + private final String condition; + + public WeatherCondition(MMOLineConfig config) { + super(config); + + Validate.isTrue(config.contains("condition")); + + condition = config.getString("condition"); + } + + @Override + public boolean isMet(ConditionInstance entity) { + if (entity.getEntity() instanceof Player player) { + boolean isClear = player.getWorld().isClearWeather(); + boolean hasStorm = player.getWorld().hasStorm(); + + if (condition.equalsIgnoreCase("clear")) { + return isClear; + } else if (condition.equalsIgnoreCase("stormy")) { + return hasStorm; + } + } + + return false; + } +} From 222fbfc833012971ae465a7134b9bdae685b445d Mon Sep 17 00:00:00 2001 From: Rosenthalk0 Date: Mon, 12 Jun 2023 13:06:57 -0500 Subject: [PATCH 02/11] Events for Casting Mode --- .../event/PlayerEnterCastingModeEvent.java | 38 +++++++++++++++++++ .../api/event/PlayerExitCastingModeEvent.java | 38 +++++++++++++++++++ .../mmocore/api/player/PlayerData.java | 17 +++++++-- 3 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerEnterCastingModeEvent.java create mode 100644 MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerExitCastingModeEvent.java diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerEnterCastingModeEvent.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerEnterCastingModeEvent.java new file mode 100644 index 00000000..7cefbaa9 --- /dev/null +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerEnterCastingModeEvent.java @@ -0,0 +1,38 @@ +package net.Indyuce.mmocore.api.event; + +import lombok.Getter; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; +import org.jetbrains.annotations.NotNull; + +@Getter +public class PlayerEnterCastingModeEvent extends PlayerEvent implements Cancellable { + private static HandlerList handlerList = new HandlerList(); + private boolean cancelled = false; + + public PlayerEnterCastingModeEvent(@NotNull Player who) { + super(who); + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return getHandlerList(); + } + + public static HandlerList getHandlerList(){ + return handlerList; + } +} diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerExitCastingModeEvent.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerExitCastingModeEvent.java new file mode 100644 index 00000000..ce98c45c --- /dev/null +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerExitCastingModeEvent.java @@ -0,0 +1,38 @@ +package net.Indyuce.mmocore.api.event; + +import lombok.Getter; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; +import org.jetbrains.annotations.NotNull; + +@Getter +public class PlayerExitCastingModeEvent extends PlayerEvent implements Cancellable { + private static final HandlerList handlerList = new HandlerList(); + private boolean cancelled = false; + + public PlayerExitCastingModeEvent(@NotNull Player who) { + super(who); + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return handlerList; + } + + public static HandlerList getHandlerList() { + return handlerList; + } +} diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index 291b0c6f..089ce5ff 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -9,9 +9,7 @@ import io.lumine.mythic.lib.player.cooldown.CooldownMap; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.ConfigMessage; import net.Indyuce.mmocore.api.SoundEvent; -import net.Indyuce.mmocore.api.event.PlayerExperienceGainEvent; -import net.Indyuce.mmocore.api.event.PlayerLevelUpEvent; -import net.Indyuce.mmocore.api.event.PlayerResourceUpdateEvent; +import net.Indyuce.mmocore.api.event.*; import net.Indyuce.mmocore.api.event.unlocking.ItemLockedEvent; import net.Indyuce.mmocore.api.event.unlocking.ItemUnlockedEvent; import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute; @@ -1007,6 +1005,12 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD public void setSkillCasting(@NotNull SkillCastingInstance skillCasting) { Validate.isTrue(!isCasting(), "Player already in casting mode"); + PlayerEnterCastingModeEvent event = new PlayerEnterCastingModeEvent(getPlayer()); + Bukkit.getPluginManager().callEvent(event); + + if (event.isCancelled()){ + return; + } this.skillCasting = skillCasting; } @@ -1025,6 +1029,13 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD public void leaveSkillCasting() { Validate.isTrue(isCasting(), "Player not in casting mode"); + PlayerExitCastingModeEvent event = new PlayerExitCastingModeEvent(getPlayer()); + Bukkit.getPluginManager().callEvent(event); + + if (event.isCancelled()){ + return; + } + skillCasting.close(); this.skillCasting = null; setLastActivity(PlayerActivity.ACTION_BAR_MESSAGE, 0); // Reset action bar From 59816c163d75b9f0bb26aadb078c81fa3e32ebfb Mon Sep 17 00:00:00 2001 From: Jules Date: Sun, 18 Jun 2023 15:53:07 +0200 Subject: [PATCH 03/11] Update license --- LICENSE | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index 5102ff96..c4e8ca16 100644 --- a/LICENSE +++ b/LICENSE @@ -6,12 +6,12 @@ Things can you CANNOT do: - Issue a refund on PayPal without our explicit permission, as this is a digital good. - Redistribute, sell or give an official/modified version of the plugin (with or without any type of counterpart) to anyone else. - Modify and compile the project source code to bypass an anti-piracy protection. -- Download, compile, decompile or use the plugin on a production server without purchasing a license. +- Download, compile, decompile or use the plugin on any server without purchasing a license. Things can you CAN do when purchasing the plugin: - Download and decompile the plugin file. - Fork and modify the project source code to meet your production server's needs. -- Use it on ONE production server or network (= proxy-connected servers) at a time. +- Use it on ONE production server or network (= proxy-connected servers) and one private test server at a time. You may propose a merge request, under the terms that you grant full rights to us using any pushed code. From 74a170e66ccf0bcb88007f2b604aa457f3234633 Mon Sep 17 00:00:00 2001 From: Jules Date: Sun, 18 Jun 2023 16:51:08 +0200 Subject: [PATCH 04/11] !Use of newest methods of ML for data saving --- .../main/java/net/Indyuce/mmocore/MMOCore.java | 15 +-------------- .../command/rpg/admin/ExportDataTreeNode.java | 2 +- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/MMOCore.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/MMOCore.java index 103362ea..d1ec3e6e 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/MMOCore.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/MMOCore.java @@ -275,25 +275,12 @@ public class MMOCore extends JavaPlugin { @Override public void onDisable() { - // Executes all the pending asynchronous task (like saving the playerData) - Bukkit.getScheduler().getPendingTasks().forEach(worker -> { - if (worker.getOwner().equals(this)) { - ((Runnable) worker).run(); - } - }); - - // Save player data - for (PlayerData data : PlayerData.getAll()) - if (data.isSynchronized()) { - data.close(); - dataProvider.getDataManager().getDataHandler().saveData(data, true); - } - // Save guild info for (Guild guild : dataProvider.getGuildManager().getAll()) dataProvider.getGuildManager().save(guild); // Close MySQL data provider (memory leaks) + playerDataManager.saveAll(false); playerDataManager.getDataHandler().close(); // Reset active blocks diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ExportDataTreeNode.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ExportDataTreeNode.java index 250962cd..f5b36328 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ExportDataTreeNode.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ExportDataTreeNode.java @@ -92,7 +92,7 @@ public class ExportDataTreeNode extends CommandTreeNode { MMOCore.plugin.dataProvider.getDataManager().getDataHandler().loadData(offlinePlayerData); // Player data is loaded, now it gets saved through SQL - sqlHandler.saveData(offlinePlayerData, true); + sqlHandler.saveData(offlinePlayerData, false); } catch (RuntimeException exception) { errorCount++; exception.printStackTrace(); From 6088c8b343cfa5109c93815b86dd0367dec64a13 Mon Sep 17 00:00:00 2001 From: Rosenthalk0 Date: Sun, 18 Jun 2023 15:36:00 -0500 Subject: [PATCH 05/11] Fix of small bugs relate to the events! --- .../main/java/net/Indyuce/mmocore/api/player/PlayerData.java | 1 + .../net/Indyuce/mmocore/skill/cast/listener/KeyCombos.java | 3 +++ .../java/net/Indyuce/mmocore/skill/cast/listener/SkillBar.java | 3 +++ .../net/Indyuce/mmocore/skill/cast/listener/SkillScroller.java | 3 +++ 4 files changed, 10 insertions(+) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index 089ce5ff..fb5c562d 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -1009,6 +1009,7 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()){ + skillCasting.close(); return; } this.skillCasting = skillCasting; diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/KeyCombos.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/KeyCombos.java index 9fe2c397..b6de6f7f 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/KeyCombos.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/KeyCombos.java @@ -96,6 +96,9 @@ public class KeyCombos implements SkillCastingListener { if (comboMap.isComboStart(event.getPressed())) { casting = new CustomSkillCastingInstance(playerData); playerData.setSkillCasting(casting); + if (!playerData.isCasting()){ + return; + } if (beginComboSound != null) beginComboSound.playTo(player); } } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/SkillBar.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/SkillBar.java index ca459b64..f4e5873a 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/SkillBar.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/SkillBar.java @@ -57,6 +57,9 @@ public class SkillBar implements SkillCastingListener { final PlayerData playerData = event.getData(); if (player.getGameMode() != GameMode.SPECTATOR && (MMOCore.plugin.configManager.canCreativeCast || player.getGameMode() != GameMode.CREATIVE) && !playerData.isCasting() && !playerData.getBoundSkills().isEmpty()) { playerData.setSkillCasting(new CustomSkillCastingInstance(playerData)); + if (!playerData.isCasting()){ + return; + } MMOCore.plugin.soundManager.getSound(SoundEvent.SPELL_CAST_BEGIN).playTo(player); } } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/SkillScroller.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/SkillScroller.java index 92acb49e..72a2db96 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/SkillScroller.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/SkillScroller.java @@ -78,6 +78,9 @@ public class SkillScroller implements SkillCastingListener { // Enter casting mode playerData.setSkillCasting(new CustomSkillCastingInstance(playerData)); + if (!playerData.isCasting()){ + return; + } if (enterSound != null) enterSound.playTo(player); } From 839ccd4942416e5b4e47b4437cbd44b5a024dc39 Mon Sep 17 00:00:00 2001 From: Rosenthalk0 Date: Fri, 23 Jun 2023 13:39:28 -0500 Subject: [PATCH 06/11] Use MMOCore PlayerDataEvent --- .../mmocore/api/event/PlayerEnterCastingModeEvent.java | 8 ++++---- .../mmocore/api/event/PlayerExitCastingModeEvent.java | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerEnterCastingModeEvent.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerEnterCastingModeEvent.java index 7cefbaa9..3656a398 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerEnterCastingModeEvent.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerEnterCastingModeEvent.java @@ -1,19 +1,19 @@ package net.Indyuce.mmocore.api.event; import lombok.Getter; +import net.Indyuce.mmocore.api.player.PlayerData; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; -import org.bukkit.event.player.PlayerEvent; import org.jetbrains.annotations.NotNull; @Getter -public class PlayerEnterCastingModeEvent extends PlayerEvent implements Cancellable { - private static HandlerList handlerList = new HandlerList(); +public class PlayerEnterCastingModeEvent extends PlayerDataEvent implements Cancellable { + private static final HandlerList handlerList = new HandlerList(); private boolean cancelled = false; public PlayerEnterCastingModeEvent(@NotNull Player who) { - super(who); + super(PlayerData.get(who.getUniqueId())); } @Override diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerExitCastingModeEvent.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerExitCastingModeEvent.java index ce98c45c..4f065738 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerExitCastingModeEvent.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerExitCastingModeEvent.java @@ -1,19 +1,19 @@ package net.Indyuce.mmocore.api.event; import lombok.Getter; +import net.Indyuce.mmocore.api.player.PlayerData; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; -import org.bukkit.event.player.PlayerEvent; import org.jetbrains.annotations.NotNull; @Getter -public class PlayerExitCastingModeEvent extends PlayerEvent implements Cancellable { +public class PlayerExitCastingModeEvent extends PlayerDataEvent implements Cancellable { private static final HandlerList handlerList = new HandlerList(); private boolean cancelled = false; public PlayerExitCastingModeEvent(@NotNull Player who) { - super(who); + super(PlayerData.get(who.getUniqueId())); } @Override From 96ac7a9c00a7acc699da4073fdc5cce258a05c16 Mon Sep 17 00:00:00 2001 From: Rosenthalk0 Date: Fri, 23 Jun 2023 14:00:48 -0500 Subject: [PATCH 07/11] API method for leaveSkillCasting to fire event! --- .../mmocore/api/player/PlayerData.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index fb5c562d..b9347df0 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -1028,15 +1028,26 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD return Objects.requireNonNull(skillCasting, "Player not in casting mode"); } - public void leaveSkillCasting() { + /** + * API Method to leave casting mode and fire the PlayerExitCastingModeEvent + */ + public void leaveSkillCasting(){ + this.leaveSkillCasting(false); + } + + /** + * @param skipEvent Skip the PlayerExitCastingModeEvent + */ + public void leaveSkillCasting(boolean skipEvent) { Validate.isTrue(isCasting(), "Player not in casting mode"); - PlayerExitCastingModeEvent event = new PlayerExitCastingModeEvent(getPlayer()); - Bukkit.getPluginManager().callEvent(event); + if (!skipEvent) { + PlayerExitCastingModeEvent event = new PlayerExitCastingModeEvent(getPlayer()); + Bukkit.getPluginManager().callEvent(event); - if (event.isCancelled()){ - return; + if (event.isCancelled()) { + return; + } } - skillCasting.close(); this.skillCasting = null; setLastActivity(PlayerActivity.ACTION_BAR_MESSAGE, 0); // Reset action bar From e90a1cea281dc6ceac23c8547cdba2e81d493214 Mon Sep 17 00:00:00 2001 From: Rosenthalk0 Date: Fri, 23 Jun 2023 16:47:49 -0500 Subject: [PATCH 08/11] Fix for case insensitivity --- .../src/main/java/net/Indyuce/mmocore/api/SoundObject.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/SoundObject.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/SoundObject.java index d9e4eba4..5c1045ee 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/SoundObject.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/SoundObject.java @@ -92,7 +92,7 @@ public class SoundObject { public void playTo(Player player, float volume, float pitch) { if (isCustom()) - player.playSound(player.getLocation(), key, volume, pitch); + player.playSound(player.getLocation(), key.toLowerCase(), volume, pitch); else player.playSound(player.getLocation(), sound, volume, pitch); } @@ -103,7 +103,7 @@ public class SoundObject { public void playAt(Location loc, float volume, float pitch) { if (isCustom()) - loc.getWorld().playSound(loc, key, volume, pitch); + loc.getWorld().playSound(loc, key.toLowerCase(), volume, pitch); else loc.getWorld().playSound(loc, sound, volume, pitch); } From 09e12417350490308bd88a81b9e7df3cdf3b8071 Mon Sep 17 00:00:00 2001 From: Rosenthalk0 Date: Fri, 23 Jun 2023 16:48:13 -0500 Subject: [PATCH 09/11] Fix for case insensitivity --- .../src/main/java/net/Indyuce/mmocore/api/SoundObject.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/SoundObject.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/SoundObject.java index 5c1045ee..4acfe5ff 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/SoundObject.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/SoundObject.java @@ -54,7 +54,7 @@ public class SoundObject { } this.sound = sound; - this.key = key; + this.key = key.toLowerCase(); volume = (float) config.getDouble("volume", 1); pitch = (float) config.getDouble("pitch", 1); @@ -92,7 +92,7 @@ public class SoundObject { public void playTo(Player player, float volume, float pitch) { if (isCustom()) - player.playSound(player.getLocation(), key.toLowerCase(), volume, pitch); + player.playSound(player.getLocation(), key, volume, pitch); else player.playSound(player.getLocation(), sound, volume, pitch); } @@ -103,7 +103,7 @@ public class SoundObject { public void playAt(Location loc, float volume, float pitch) { if (isCustom()) - loc.getWorld().playSound(loc, key.toLowerCase(), volume, pitch); + loc.getWorld().playSound(loc, key, volume, pitch); else loc.getWorld().playSound(loc, sound, volume, pitch); } From a40e7b119cad1715d342b2a4a086c04bea26f7f9 Mon Sep 17 00:00:00 2001 From: Rosenthalk0 Date: Fri, 23 Jun 2023 16:48:27 -0500 Subject: [PATCH 10/11] Fix for case insensitivity --- .../src/main/java/net/Indyuce/mmocore/api/SoundObject.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/SoundObject.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/SoundObject.java index 4acfe5ff..ace91e51 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/SoundObject.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/SoundObject.java @@ -36,7 +36,7 @@ public class SoundObject { } this.sound = sound; - this.key = key; + this.key = key.toLowerCase(); volume = split.length > 1 ? Float.parseFloat(split[1]) : 1; pitch = split.length > 2 ? Float.parseFloat(split[2]) : 1; From f8758ebe74b906960b27a456015ea9c244ea148b Mon Sep 17 00:00:00 2001 From: Guillaume Date: Sun, 25 Jun 2023 08:04:42 +0000 Subject: [PATCH 11/11] Revert "Merge branch 'custom-sound-case-sensitivity-fix' into 'master'" This reverts merge request !28 --- .../net/Indyuce/mmocore/api/SoundObject.java | 4 +- .../event/PlayerEnterCastingModeEvent.java | 38 ------------------- .../api/event/PlayerExitCastingModeEvent.java | 38 ------------------- .../mmocore/api/player/PlayerData.java | 31 ++------------- .../skill/cast/listener/KeyCombos.java | 3 -- .../mmocore/skill/cast/listener/SkillBar.java | 3 -- .../skill/cast/listener/SkillScroller.java | 3 -- 7 files changed, 6 insertions(+), 114 deletions(-) delete mode 100644 MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerEnterCastingModeEvent.java delete mode 100644 MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerExitCastingModeEvent.java diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/SoundObject.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/SoundObject.java index ace91e51..d9e4eba4 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/SoundObject.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/SoundObject.java @@ -36,7 +36,7 @@ public class SoundObject { } this.sound = sound; - this.key = key.toLowerCase(); + this.key = key; volume = split.length > 1 ? Float.parseFloat(split[1]) : 1; pitch = split.length > 2 ? Float.parseFloat(split[2]) : 1; @@ -54,7 +54,7 @@ public class SoundObject { } this.sound = sound; - this.key = key.toLowerCase(); + this.key = key; volume = (float) config.getDouble("volume", 1); pitch = (float) config.getDouble("pitch", 1); diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerEnterCastingModeEvent.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerEnterCastingModeEvent.java deleted file mode 100644 index 3656a398..00000000 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerEnterCastingModeEvent.java +++ /dev/null @@ -1,38 +0,0 @@ -package net.Indyuce.mmocore.api.event; - -import lombok.Getter; -import net.Indyuce.mmocore.api.player.PlayerData; -import org.bukkit.entity.Player; -import org.bukkit.event.Cancellable; -import org.bukkit.event.HandlerList; -import org.jetbrains.annotations.NotNull; - -@Getter -public class PlayerEnterCastingModeEvent extends PlayerDataEvent implements Cancellable { - private static final HandlerList handlerList = new HandlerList(); - private boolean cancelled = false; - - public PlayerEnterCastingModeEvent(@NotNull Player who) { - super(PlayerData.get(who.getUniqueId())); - } - - @Override - public boolean isCancelled() { - return cancelled; - } - - @Override - public void setCancelled(boolean cancelled) { - this.cancelled = cancelled; - } - - @NotNull - @Override - public HandlerList getHandlers() { - return getHandlerList(); - } - - public static HandlerList getHandlerList(){ - return handlerList; - } -} diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerExitCastingModeEvent.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerExitCastingModeEvent.java deleted file mode 100644 index 4f065738..00000000 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerExitCastingModeEvent.java +++ /dev/null @@ -1,38 +0,0 @@ -package net.Indyuce.mmocore.api.event; - -import lombok.Getter; -import net.Indyuce.mmocore.api.player.PlayerData; -import org.bukkit.entity.Player; -import org.bukkit.event.Cancellable; -import org.bukkit.event.HandlerList; -import org.jetbrains.annotations.NotNull; - -@Getter -public class PlayerExitCastingModeEvent extends PlayerDataEvent implements Cancellable { - private static final HandlerList handlerList = new HandlerList(); - private boolean cancelled = false; - - public PlayerExitCastingModeEvent(@NotNull Player who) { - super(PlayerData.get(who.getUniqueId())); - } - - @Override - public boolean isCancelled() { - return cancelled; - } - - @Override - public void setCancelled(boolean cancelled) { - this.cancelled = cancelled; - } - - @NotNull - @Override - public HandlerList getHandlers() { - return handlerList; - } - - public static HandlerList getHandlerList() { - return handlerList; - } -} diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index b9347df0..291b0c6f 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -9,7 +9,9 @@ import io.lumine.mythic.lib.player.cooldown.CooldownMap; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.ConfigMessage; import net.Indyuce.mmocore.api.SoundEvent; -import net.Indyuce.mmocore.api.event.*; +import net.Indyuce.mmocore.api.event.PlayerExperienceGainEvent; +import net.Indyuce.mmocore.api.event.PlayerLevelUpEvent; +import net.Indyuce.mmocore.api.event.PlayerResourceUpdateEvent; import net.Indyuce.mmocore.api.event.unlocking.ItemLockedEvent; import net.Indyuce.mmocore.api.event.unlocking.ItemUnlockedEvent; import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute; @@ -1005,13 +1007,6 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD public void setSkillCasting(@NotNull SkillCastingInstance skillCasting) { Validate.isTrue(!isCasting(), "Player already in casting mode"); - PlayerEnterCastingModeEvent event = new PlayerEnterCastingModeEvent(getPlayer()); - Bukkit.getPluginManager().callEvent(event); - - if (event.isCancelled()){ - skillCasting.close(); - return; - } this.skillCasting = skillCasting; } @@ -1028,26 +1023,8 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD return Objects.requireNonNull(skillCasting, "Player not in casting mode"); } - /** - * API Method to leave casting mode and fire the PlayerExitCastingModeEvent - */ - public void leaveSkillCasting(){ - this.leaveSkillCasting(false); - } - - /** - * @param skipEvent Skip the PlayerExitCastingModeEvent - */ - public void leaveSkillCasting(boolean skipEvent) { + public void leaveSkillCasting() { Validate.isTrue(isCasting(), "Player not in casting mode"); - if (!skipEvent) { - PlayerExitCastingModeEvent event = new PlayerExitCastingModeEvent(getPlayer()); - Bukkit.getPluginManager().callEvent(event); - - if (event.isCancelled()) { - return; - } - } skillCasting.close(); this.skillCasting = null; setLastActivity(PlayerActivity.ACTION_BAR_MESSAGE, 0); // Reset action bar diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/KeyCombos.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/KeyCombos.java index b6de6f7f..9fe2c397 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/KeyCombos.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/KeyCombos.java @@ -96,9 +96,6 @@ public class KeyCombos implements SkillCastingListener { if (comboMap.isComboStart(event.getPressed())) { casting = new CustomSkillCastingInstance(playerData); playerData.setSkillCasting(casting); - if (!playerData.isCasting()){ - return; - } if (beginComboSound != null) beginComboSound.playTo(player); } } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/SkillBar.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/SkillBar.java index f4e5873a..ca459b64 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/SkillBar.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/SkillBar.java @@ -57,9 +57,6 @@ public class SkillBar implements SkillCastingListener { final PlayerData playerData = event.getData(); if (player.getGameMode() != GameMode.SPECTATOR && (MMOCore.plugin.configManager.canCreativeCast || player.getGameMode() != GameMode.CREATIVE) && !playerData.isCasting() && !playerData.getBoundSkills().isEmpty()) { playerData.setSkillCasting(new CustomSkillCastingInstance(playerData)); - if (!playerData.isCasting()){ - return; - } MMOCore.plugin.soundManager.getSound(SoundEvent.SPELL_CAST_BEGIN).playTo(player); } } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/SkillScroller.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/SkillScroller.java index 72a2db96..92acb49e 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/SkillScroller.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/SkillScroller.java @@ -78,9 +78,6 @@ public class SkillScroller implements SkillCastingListener { // Enter casting mode playerData.setSkillCasting(new CustomSkillCastingInstance(playerData)); - if (!playerData.isCasting()){ - return; - } if (enterSound != null) enterSound.playTo(player); }