From 679731099db8dc292d7f54fc84e0fc85f4cdd172 Mon Sep 17 00:00:00 2001 From: AmiT177 <8685831+amit177@users.noreply.github.com> Date: Sat, 4 Apr 2020 17:44:03 +0300 Subject: [PATCH] Initial Commit --- .gitignore | 2 + NoConsoleCmds.iml | 2 + README.md | 4 +- pom.xml | 39 +++++++++++++ .../spigot/noconsolecmds/NoConsoleCmds.java | 55 +++++++++++++++++++ src/main/resources/config.yml | 2 + src/main/resources/plugin.yml | 6 ++ 7 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 NoConsoleCmds.iml create mode 100644 pom.xml create mode 100644 src/main/java/systems/amit/spigot/noconsolecmds/NoConsoleCmds.java create mode 100644 src/main/resources/config.yml create mode 100644 src/main/resources/plugin.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..92322c4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/ +target/ diff --git a/NoConsoleCmds.iml b/NoConsoleCmds.iml new file mode 100644 index 0000000..78b2cc5 --- /dev/null +++ b/NoConsoleCmds.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/README.md b/README.md index 86c9118..cfaf25a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ # NoConsoleCmds -A spigot plugin that blocks console from executing specific commands +A spigot plugin that blocks console from executing commands + +By default, the plugin blocks the command 'list' to prevent multicraft from spamming the console. \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..f84b673 --- /dev/null +++ b/pom.xml @@ -0,0 +1,39 @@ + + + 4.0.0 + + systems.amit.spigot.noconsolecmds + NoConsoleCmds + 1.0-SNAPSHOT + + + UTF-8 + 1.8 + 1.8 + 666 + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + + org.spigotmc + spigot-api + 1.8.8-R0.1-SNAPSHOT + provided + + + + + + NoConsoleCmds + + \ No newline at end of file diff --git a/src/main/java/systems/amit/spigot/noconsolecmds/NoConsoleCmds.java b/src/main/java/systems/amit/spigot/noconsolecmds/NoConsoleCmds.java new file mode 100644 index 0000000..5a99287 --- /dev/null +++ b/src/main/java/systems/amit/spigot/noconsolecmds/NoConsoleCmds.java @@ -0,0 +1,55 @@ +package systems.amit.spigot.noconsolecmds; + +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.server.ServerCommandEvent; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.ArrayList; + +public class NoConsoleCmds extends JavaPlugin implements Listener { + + private ArrayList blockedCmds = new ArrayList<>(); + + @Override + public void onEnable() { + if (!loadConfig()) { + getLogger().severe("Could not load config, disabling."); + Bukkit.getPluginManager().disablePlugin(this); + return; + } + + getServer().getPluginManager().registerEvents(this, this); + + getLogger().info("The plugin has been enabled (" + blockedCmds.size() + " blocked commands)"); + } + + @Override + public void onDisable() { + blockedCmds.clear(); + getLogger().info("The plugin has been disabled"); + } + + private boolean loadConfig() { + saveDefaultConfig(); + if (!getConfig().contains("commands-blocked")) { + getLogger().severe("The config is missing the 'commands-blocked' section"); + return false; + } + blockedCmds.addAll(getConfig().getStringList("commands-blocked")); + if (blockedCmds.size() == 0) { + getLogger().severe("No commands listed in config."); + return false; + } + return true; + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onConsoleCommand(ServerCommandEvent e) { + if (blockedCmds.contains(e.getCommand())) { + e.setCancelled(true); + } + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..fbff137 --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,2 @@ +commands-blocked: + - list \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..8e83ba6 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,6 @@ +name: NoConsoleCmds +author: amit177 +version: 1.0 +description: A plugin that blocks console from executing commands +main: systems.amit.spigot.noconsolecmds.NoConsoleCmds +commands: \ No newline at end of file