From f3460fc37467e3dc298a2bf87d989e489d551560 Mon Sep 17 00:00:00 2001 From: BryanGaming <47282239+BryanGamingDV@users.noreply.github.com> Date: Tue, 2 Feb 2021 23:40:02 -0500 Subject: [PATCH] Bugs fixed! --- .../java/bryangaming/code/EffectRanks.java | 15 ----- src/main/java/bryangaming/code/Manager.java | 6 +- .../bryangaming/code/api/EffectsModify.java | 18 ++++++ .../code/api/EffectsModifyImpl.java | 55 +++++++++++++++++++ .../code/api/events/EnableEffectsEvent.java | 43 +++++++++++++++ .../code/commands/PowerCommand.java | 24 +++++++- .../bryangaming/code/listener/ClickEvent.java | 9 +++ .../bryangaming/code/modules/RankMethod.java | 5 +- .../code/registry/CommandsRegistry.java | 2 + 9 files changed, 157 insertions(+), 20 deletions(-) create mode 100644 src/main/java/bryangaming/code/api/EffectsModify.java create mode 100644 src/main/java/bryangaming/code/api/EffectsModifyImpl.java create mode 100644 src/main/java/bryangaming/code/api/events/EnableEffectsEvent.java diff --git a/src/main/java/bryangaming/code/EffectRanks.java b/src/main/java/bryangaming/code/EffectRanks.java index 1707047..d6f5a19 100644 --- a/src/main/java/bryangaming/code/EffectRanks.java +++ b/src/main/java/bryangaming/code/EffectRanks.java @@ -20,20 +20,5 @@ public void registerManager() { public void onDisable() { getLogger().info("Thx for using this plugin <3"); - getDisableMessage(); - } - - public void getDisableMessage() { - int number = (int)(Math.random() * 2.0 + 1.0); - - if (number == 1) { - getLogger().info("Goodbye!"); - } - else if (number == 2) { - getLogger().info("See you later!"); - } - else { - getLogger().info("You shouldn't watch this.."); - } } } diff --git a/src/main/java/bryangaming/code/Manager.java b/src/main/java/bryangaming/code/Manager.java index 2a2557c..dfafe52 100644 --- a/src/main/java/bryangaming/code/Manager.java +++ b/src/main/java/bryangaming/code/Manager.java @@ -1,12 +1,12 @@ package bryangaming.code; +import bryangaming.code.api.EffectsModifyImpl; import bryangaming.code.debug.DebugLogger; import net.milkbowl.vault.permission.*; import bryangaming.code.utils.*; import bryangaming.code.modules.*; import bryangaming.code.registry.*; import org.bukkit.*; -import org.bukkit.event.EventHandler; import org.bukkit.plugin.*; public class Manager { @@ -23,6 +23,8 @@ public class Manager { private CommandsRegistry commandsRegistry; private ListenersRegistry listenersRegistry; + private EffectsModifyImpl effectsModifyImpl; + private ConfigManager configManager; public Manager(final EffectRanks plugin) { @@ -44,6 +46,8 @@ public void setup() { commandsRegistry = new CommandsRegistry(this); listenersRegistry = new ListenersRegistry(this); + + effectsModifyImpl = new EffectsModifyImpl(this); } public void setupPermisions() { diff --git a/src/main/java/bryangaming/code/api/EffectsModify.java b/src/main/java/bryangaming/code/api/EffectsModify.java new file mode 100644 index 0000000..244fd8e --- /dev/null +++ b/src/main/java/bryangaming/code/api/EffectsModify.java @@ -0,0 +1,18 @@ +package bryangaming.code.api; + +import org.bukkit.entity.Player; + +public interface EffectsModify { + + + /** + * Activate the effects according the rank that have the player. + * + * @param player The player that will activate his effects. + * + */ + + static void giveEffectRank(Player player){ + + } +} diff --git a/src/main/java/bryangaming/code/api/EffectsModifyImpl.java b/src/main/java/bryangaming/code/api/EffectsModifyImpl.java new file mode 100644 index 0000000..391ed26 --- /dev/null +++ b/src/main/java/bryangaming/code/api/EffectsModifyImpl.java @@ -0,0 +1,55 @@ +package bryangaming.code.api; + +import bryangaming.code.Manager; +import bryangaming.code.modules.CooldownMethod; +import bryangaming.code.modules.MethodManager; +import bryangaming.code.modules.PowerMethod; +import bryangaming.code.modules.RankMethod; +import bryangaming.code.modules.player.PlayerMessage; +import bryangaming.code.registry.ConfigManager; +import bryangaming.code.utils.Configuration; +import org.bukkit.entity.Player; + +public class EffectsModifyImpl implements EffectsModify { + + private Manager manager; + + private static MethodManager methodManager; + private static ConfigManager files; + + public EffectsModifyImpl(Manager manager){ + this.manager = manager; + methodManager = manager.getPlayerMethods(); + files = manager.getFiles(); + } + + + public static void giveEffectRank(Player player){ + + RankMethod rankMethod = methodManager.getLoopMethod(); + CooldownMethod cooldownMethod = methodManager.getCooldownMethod(); + PowerMethod powerMethod = methodManager.getPowerMethod(); + + PlayerMessage playersender = methodManager.getSender(); + + Configuration config = files.getConfig(); + Configuration messages = files.getMessages(); + Configuration commands = files.getCommands(); + + if (cooldownMethod.playerIsInCooldown(player)) { + playersender.sendMessage(player, messages.getString("error.cooldown.wait-time") + .replace("%time%", cooldownMethod.getTextRankCooldown(player))); + return; + } + + if (rankMethod.getPlayerRank(player).equalsIgnoreCase("default") && config.getConfigurationSection("default") == null) { + playersender.sendMessage(player, messages.getString("error.effects.empty-effects")); + return; + } + + powerMethod.setPower(player.getUniqueId()); + playersender.sendMessage(player, commands.getString("commands.effects.status-on")); + cooldownMethod.putCooldown(player, (System.currentTimeMillis() / 1000) + cooldownMethod.getRankCooldown(player)); + + } +} \ No newline at end of file diff --git a/src/main/java/bryangaming/code/api/events/EnableEffectsEvent.java b/src/main/java/bryangaming/code/api/events/EnableEffectsEvent.java new file mode 100644 index 0000000..e6073c8 --- /dev/null +++ b/src/main/java/bryangaming/code/api/events/EnableEffectsEvent.java @@ -0,0 +1,43 @@ +package bryangaming.code.api.events; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +public class EnableEffectsEvent extends Event implements Cancellable{ + + private final Player player; + private boolean isCancelled; + + public EnableEffectsEvent(Player player){ + this.player = player; + this.isCancelled = false; + } + + public Player getPlayer() { + return player; + } + + @Override + public boolean isCancelled() { + return isCancelled; + } + + @Override + public void setCancelled(boolean isCancelled) { + this.isCancelled = isCancelled; + } + + private static final HandlerList HANDLERS = new HandlerList(); + + @Override + public @NotNull HandlerList getHandlers() { + return HANDLERS; + } + + public static HandlerList getHandlerList() { + return HANDLERS; + } +} diff --git a/src/main/java/bryangaming/code/commands/PowerCommand.java b/src/main/java/bryangaming/code/commands/PowerCommand.java index 2ba66d7..eca3b22 100644 --- a/src/main/java/bryangaming/code/commands/PowerCommand.java +++ b/src/main/java/bryangaming/code/commands/PowerCommand.java @@ -3,6 +3,8 @@ import bryangaming.code.Manager; import bryangaming.code.EffectRanks; +import bryangaming.code.api.EffectsModify; +import bryangaming.code.api.events.EnableEffectsEvent; import bryangaming.code.modules.CooldownMethod; import bryangaming.code.modules.PowerMethod; import bryangaming.code.modules.RankMethod; @@ -14,6 +16,7 @@ import me.fixeddev.commandflow.annotated.annotation.Command; import me.fixeddev.commandflow.bukkit.annotation.Sender; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffectType; @@ -51,13 +54,20 @@ public boolean onCommand(@Sender Player player) { StringFormat stringFormat = manager.getVariables(); playersender.sendMessage(player, messages.getString("error.unknown-args") - .replace("%usage%", stringFormat.getUsage("effects", "on, off, transfer, list"))); + .replace("%usage%", stringFormat.getUsage("effects", "on, off, convert, list"))); return true; } @Command(names = "on") public boolean onOnSubCommand(@Sender Player player) { + EnableEffectsEvent enableEffectsEvent = new EnableEffectsEvent(player); + Bukkit.getPluginManager().callEvent(enableEffectsEvent); + + if (enableEffectsEvent.isCancelled()){ + return false; + } + RankMethod rankMethod = manager.getPlayerMethods().getLoopMethod(); CooldownMethod cooldownMethod = manager.getPlayerMethods().getCooldownMethod(); @@ -71,12 +81,24 @@ public boolean onOnSubCommand(@Sender Player player) { playersender.sendMessage(player, messages.getString("error.effects.empty-effects")); return true; } + EffectsModify.giveEffectRank(player); + + powerMethod.setPower(player.getUniqueId()); + playersender.sendMessage(player, commands.getString("commands.effects.status-on")); + cooldownMethod.putCooldown(player, (System.currentTimeMillis() / 1000) + cooldownMethod.getRankCooldown(player)); return true; } @Command(names = "convert") public boolean onConvertSubCommand(@Sender Player player) { + EnableEffectsEvent enableEffectsEvent = new EnableEffectsEvent(player); + Bukkit.getPluginManager().callEvent(enableEffectsEvent); + + if (enableEffectsEvent.isCancelled()){ + return false; + } + RankMethod rankMethod = manager.getPlayerMethods().getLoopMethod(); CooldownMethod cooldownMethod = manager.getPlayerMethods().getCooldownMethod(); ConvertPotion convertPotion = manager.getPlayerMethods().getConvertPotion(); diff --git a/src/main/java/bryangaming/code/listener/ClickEvent.java b/src/main/java/bryangaming/code/listener/ClickEvent.java index f8a0b3d..d83450f 100644 --- a/src/main/java/bryangaming/code/listener/ClickEvent.java +++ b/src/main/java/bryangaming/code/listener/ClickEvent.java @@ -1,11 +1,13 @@ package bryangaming.code.listener; import bryangaming.code.Manager; +import bryangaming.code.api.events.EnableEffectsEvent; import bryangaming.code.modules.CooldownMethod; import bryangaming.code.modules.PowerMethod; import bryangaming.code.modules.RankMethod; import bryangaming.code.modules.player.PlayerMessage; import bryangaming.code.utils.Configuration; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -82,6 +84,13 @@ public void onClick(PlayerInteractEvent event){ public void setPower(Player player){ + EnableEffectsEvent enableEffectsEvent = new EnableEffectsEvent(player); + Bukkit.getPluginManager().callEvent(enableEffectsEvent); + + if (enableEffectsEvent.isCancelled()){ + return; + } + CooldownMethod cooldownMethod = manager.getPlayerMethods().getCooldownMethod(); if (cooldownMethod.playerIsInCooldown(player)){ diff --git a/src/main/java/bryangaming/code/modules/RankMethod.java b/src/main/java/bryangaming/code/modules/RankMethod.java index a338141..f1d1808 100644 --- a/src/main/java/bryangaming/code/modules/RankMethod.java +++ b/src/main/java/bryangaming/code/modules/RankMethod.java @@ -29,7 +29,7 @@ public RankMethod(Manager manager) { } public Set getRanks() { - ConfigurationSection rankconfig = config.getConfigurationSection("groups."); + ConfigurationSection rankconfig = config.getConfigurationSection("groups"); return rankconfig.getKeys(false); } @@ -38,7 +38,6 @@ public String getPlayerRank(Player player) { if (!Bukkit.getPluginManager().isPluginEnabled("Vault")){ return "default"; } - if (manager.getPermission() == null){ return "default"; } @@ -47,7 +46,7 @@ public String getPlayerRank(Player player) { return "default"; } - if (config.getString("config.status").equalsIgnoreCase("power")) { + if (config.getString("config.status").equalsIgnoreCase("permission")) { for (String getrank : getRanks()) { if (player.hasPermission(getrank)){ return getrank; diff --git a/src/main/java/bryangaming/code/registry/CommandsRegistry.java b/src/main/java/bryangaming/code/registry/CommandsRegistry.java index 88c9f63..fc22a3b 100644 --- a/src/main/java/bryangaming/code/registry/CommandsRegistry.java +++ b/src/main/java/bryangaming/code/registry/CommandsRegistry.java @@ -42,6 +42,8 @@ private void createCommandManager() { commandManager = new BukkitCommandManager("EffectRanks"); commandManager.getTranslator().setProvider(new CustomLanguage(manager)); + + PartInjector injector = PartInjector.create(); injector.install(new DefaultsModule());