Skip to content

Commit

Permalink
Unregister listener if disabled #36
Browse files Browse the repository at this point in the history
  • Loading branch information
SrBedrock authored Sep 27, 2023
2 parents aaccaff + 48a5dc5 commit 0f2e73e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "com.armamc"
version = "1.1.0"
version = "1.1.1"

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.armamc.plugincontrol.PluginControl;
import com.armamc.plugincontrol.managers.ConfigManager;
import com.armamc.plugincontrol.managers.MessageManager;
import com.armamc.plugincontrol.managers.PluginsManager;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
Expand All @@ -12,15 +13,18 @@
public class DisableSubCommand implements SubCommand {
private final ConfigManager config;
private final MessageManager message;
private final PluginsManager manager;

public DisableSubCommand(@NotNull PluginControl plugin) {
this.config = plugin.getConfigManager();
this.message = plugin.getMessageManager();
this.manager = plugin.getPluginsManager();
}

@Override
public void execute(CommandSender sender, Command command, String label, String[] args) {
config.setEnabled(false);
manager.unregisterListener();
message.send(sender, message.getPluginDisabled());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.armamc.plugincontrol.PluginControl;
import com.armamc.plugincontrol.managers.ConfigManager;
import com.armamc.plugincontrol.managers.MessageManager;
import com.armamc.plugincontrol.managers.PluginsManager;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.Contract;
Expand All @@ -13,16 +14,19 @@
public class EnableSubCommand implements SubCommand {
private final ConfigManager config;
private final MessageManager message;
private final PluginsManager manager;

@Contract(pure = true)
public EnableSubCommand(@NotNull PluginControl plugin) {
this.config = plugin.getConfigManager();
this.message = plugin.getMessageManager();
this.manager = plugin.getPluginsManager();
}

@Override
public void execute(CommandSender sender, Command command, String label, String[] args) {
config.setEnabled(true);
manager.checkPlugins();
message.send(sender, message.getPluginEnabled());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.armamc.plugincontrol.PluginControl;
import com.armamc.plugincontrol.managers.ConfigManager;
import com.armamc.plugincontrol.managers.MessageManager;
import com.armamc.plugincontrol.managers.PluginsManager;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.Contract;
Expand All @@ -13,19 +14,23 @@
public class ToggleSubCommand implements SubCommand {
private final ConfigManager config;
private final MessageManager message;
private final PluginsManager manager;

@Contract(pure = true)
public ToggleSubCommand(@NotNull PluginControl plugin) {
this.config = plugin.getConfigManager();
this.message = plugin.getMessageManager();
this.manager = plugin.getPluginsManager();
}

@Override
public void execute(CommandSender sender, Command command, String label, String[] args) {
config.setEnabled(!config.isEnabled());
if (config.isEnabled()) {
manager.checkPlugins();
message.send(sender, message.getPluginEnabled());
} else {
manager.unregisterListener();
message.send(sender, message.getPluginDisabled());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public void init() {

@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
private void onPlayerLogin(@NotNull PlayerLoginEvent event) {
if (!plugin.getConfigManager().isEnabled()) return;
if (event.getPlayer().hasPermission(bypass)) return;
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, message.serialize(message.getKickMessage()));
}
Expand Down

0 comments on commit 0f2e73e

Please sign in to comment.