From 4b52f74fc565a2900df1958aad19372cb5ab4548 Mon Sep 17 00:00:00 2001 From: Shiewk Date: Fri, 19 Sep 2025 18:09:52 +0200 Subject: [PATCH] (1.8.0) Allow disabling plugin features from the config (#10) --- docs/config.md | 18 +++++-- gradle.properties | 2 +- .../smoderation/paper/SModerationPaper.java | 49 ++++++++++++------- src/main/resources/default-config.yml | 10 +++- 4 files changed, 53 insertions(+), 26 deletions(-) diff --git a/docs/config.md b/docs/config.md index 8010e2c..fcbd5d7 100644 --- a/docs/config.md +++ b/docs/config.md @@ -1,7 +1,15 @@ # SModeration config -| Key | What it does | -|--------------------------|--------------------------------------------------------------------| -| socialspy-commands | The commands that `/socialspy` will listen to. | -| force-reason | Whether a reason is required for every punishment. | -| muted-forbidden-commands | Commands that players are not allowed to run while they are muted. | \ No newline at end of file +| Key | What it does | +|--------------------------|------------------------------------------------------------------------------------------------------------------------| +| socialspy-commands | The commands that `/socialspy` will listen to. | +| force-reason | Whether a reason is required for every punishment. | +| muted-forbidden-commands | Commands that players are not allowed to run while they are muted. | +| features | Controls which plugin features are enabled. | +| features.punishments | Whether the plugin provides punishing features (kick, ban, mute) | +| features.smodmenu | If punishments are enabled, controls whether the SMod Menu can be opened. Has no effect when punishments are disabled. | +| features.invsee | Whether the plugin provides invsee feature | +| features.enderchestsee | Whether the plugin provides enderchestsee feature | +| features.offlinetp | Whether the plugin provides the offlinetp feature | +| features.socialspy | Whether the plugin provides the SocialSpy feature | +| features.vanish | Whether the plugin provides the vanish feature | \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index cd7f99f..08f97cf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -pluginVersion = 1.7.1 \ No newline at end of file +pluginVersion = 1.8.0 \ No newline at end of file diff --git a/src/main/java/de/shiewk/smoderation/paper/SModerationPaper.java b/src/main/java/de/shiewk/smoderation/paper/SModerationPaper.java index 3612648..ddfb723 100644 --- a/src/main/java/de/shiewk/smoderation/paper/SModerationPaper.java +++ b/src/main/java/de/shiewk/smoderation/paper/SModerationPaper.java @@ -72,31 +72,44 @@ public final class SModerationPaper extends JavaPlugin { updateConfig(); } + public boolean isFeatureEnabled(String feature){ + return getConfig().getBoolean("features."+feature, true); + } + @Override public void onEnable() { - listen(new PunishmentListener()); + LOGGER.info("Folia: {}", SchedulerUtil.isFolia ? "yes" : "no"); + + if (isFeatureEnabled("punishments")) listen(new PunishmentListener()); + if (isFeatureEnabled("invsee")) listen(new InvSeeListener()); + if (isFeatureEnabled("enderchestsee")) listen(new EnderchestSeeListener()); + if (isFeatureEnabled("socialspy")) listen(new SocialSpyListener()); + if (isFeatureEnabled("vanish")) listen(new VanishListener()); + listen(new CustomInventoryListener()); - listen(new InvSeeListener()); - listen(new EnderchestSeeListener()); - listen(new VanishListener()); listen(new ChatInputListener()); - listen(new SocialSpyListener()); getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, event -> { Commands commands = event.registrar(); - registerCommand(commands, new KickCommand()); - registerCommand(commands, new ModLogsCommand()); - registerCommand(commands, new SModCommand()); - registerCommand(commands, new InvseeCommand()); - registerCommand(commands, new EnderchestSeeCommand()); - registerCommand(commands, new SocialSpyCommand()); - registerCommand(commands, new VanishCommand()); - registerCommand(commands, new UnmuteCommand()); - registerCommand(commands, new UnbanCommand()); - registerCommand(commands, new MuteCommand()); - registerCommand(commands, new BanCommand()); - registerCommand(commands, new OfflineTPCommand()); + if (isFeatureEnabled("punishments")){ + registerCommand(commands, new KickCommand()); + registerCommand(commands, new ModLogsCommand()); + registerCommand(commands, new UnmuteCommand()); + registerCommand(commands, new UnbanCommand()); + registerCommand(commands, new MuteCommand()); + registerCommand(commands, new BanCommand()); + + if (isFeatureEnabled("smodmenu")){ + registerCommand(commands, new SModCommand()); + } + } + + if (isFeatureEnabled("invsee")) registerCommand(commands, new InvseeCommand()); + if (isFeatureEnabled("enderchestsee")) registerCommand(commands, new EnderchestSeeCommand()); + if (isFeatureEnabled("socialspy")) registerCommand(commands, new SocialSpyCommand()); + if (isFeatureEnabled("vanish")) registerCommand(commands, new VanishCommand()); + if (isFeatureEnabled("offlinetp")) registerCommand(commands, new OfflineTPCommand()); }); if (SchedulerUtil.isFolia){ @@ -109,8 +122,6 @@ public final class SModerationPaper extends JavaPlugin { SchedulerUtil.scheduleGlobalRepeating(PLUGIN, ChatInput::tickAll, 1, 1); container.load(SAVE_FILE); - - LOGGER.info("Folia: {}", SchedulerUtil.isFolia ? "yes" : "no"); } private void listen(Listener listener) { diff --git a/src/main/resources/default-config.yml b/src/main/resources/default-config.yml index 947cbce..30632fd 100644 --- a/src/main/resources/default-config.yml +++ b/src/main/resources/default-config.yml @@ -22,4 +22,12 @@ muted-forbidden-commands: - minecraft:msg - minecraft:teammsg - minecraft:tm - - minecraft:me \ No newline at end of file + - minecraft:me +features: + punishments: true + smodmenu: true + invsee: true + enderchestsee: true + offlinetp: true + socialspy: true + vanish: true \ No newline at end of file