Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
amit177 committed Apr 4, 2020
1 parent 1853d8a commit 6797310
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea/
target/
2 changes: 2 additions & 0 deletions NoConsoleCmds.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4" />
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.
39 changes: 39 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>systems.amit.spigot.noconsolecmds</groupId>
<artifactId>NoConsoleCmds</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<build.number>666</build.number>
</properties>

<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>

<dependencies>
<!--Spigot API-->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>


<build>
<finalName>NoConsoleCmds</finalName>
</build>
</project>
55 changes: 55 additions & 0 deletions src/main/java/systems/amit/spigot/noconsolecmds/NoConsoleCmds.java
Original file line number Diff line number Diff line change
@@ -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<String> 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);
}
}
}
2 changes: 2 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
commands-blocked:
- list
6 changes: 6 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -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:

0 comments on commit 6797310

Please sign in to comment.