mirror of
https://github.com/YouHaveTrouble/CommandWhitelist.git
synced 2026-05-11 22:16:57 +00:00
Initial commit
This commit is contained in:
+113
@@ -0,0 +1,113 @@
|
|||||||
|
# User-specific stuff
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
out/
|
||||||
|
|
||||||
|
# Compiled class file
|
||||||
|
*.class
|
||||||
|
|
||||||
|
# Log file
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# BlueJ files
|
||||||
|
*.ctxt
|
||||||
|
|
||||||
|
# Package Files #
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.nar
|
||||||
|
*.ear
|
||||||
|
*.zip
|
||||||
|
*.tar.gz
|
||||||
|
*.rar
|
||||||
|
|
||||||
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
|
hs_err_pid*
|
||||||
|
|
||||||
|
*~
|
||||||
|
|
||||||
|
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||||
|
.fuse_hidden*
|
||||||
|
|
||||||
|
# KDE directory preferences
|
||||||
|
.directory
|
||||||
|
|
||||||
|
# Linux trash folder which might appear on any partition or disk
|
||||||
|
.Trash-*
|
||||||
|
|
||||||
|
# .nfs files are created when an open file is removed but is still being accessed
|
||||||
|
.nfs*
|
||||||
|
|
||||||
|
# General
|
||||||
|
.DS_Store
|
||||||
|
.AppleDouble
|
||||||
|
.LSOverride
|
||||||
|
|
||||||
|
# Icon must end with two \r
|
||||||
|
Icon
|
||||||
|
|
||||||
|
# Thumbnails
|
||||||
|
._*
|
||||||
|
|
||||||
|
# Files that might appear in the root of a volume
|
||||||
|
.DocumentRevisions-V100
|
||||||
|
.fseventsd
|
||||||
|
.Spotlight-V100
|
||||||
|
.TemporaryItems
|
||||||
|
.Trashes
|
||||||
|
.VolumeIcon.icns
|
||||||
|
.com.apple.timemachine.donotpresent
|
||||||
|
|
||||||
|
# Directories potentially created on remote AFP share
|
||||||
|
.AppleDB
|
||||||
|
.AppleDesktop
|
||||||
|
Network Trash Folder
|
||||||
|
Temporary Items
|
||||||
|
.apdisk
|
||||||
|
|
||||||
|
# Windows thumbnail cache files
|
||||||
|
Thumbs.db
|
||||||
|
Thumbs.db:encryptable
|
||||||
|
ehthumbs.db
|
||||||
|
ehthumbs_vista.db
|
||||||
|
|
||||||
|
# Dump file
|
||||||
|
*.stackdump
|
||||||
|
|
||||||
|
# Folder config file
|
||||||
|
[Dd]esktop.ini
|
||||||
|
|
||||||
|
# Recycle Bin used on file shares
|
||||||
|
$RECYCLE.BIN/
|
||||||
|
|
||||||
|
# Windows Installer files
|
||||||
|
*.cab
|
||||||
|
*.msi
|
||||||
|
*.msix
|
||||||
|
*.msm
|
||||||
|
*.msp
|
||||||
|
|
||||||
|
# Windows shortcuts
|
||||||
|
*.lnk
|
||||||
|
|
||||||
|
target/
|
||||||
|
|
||||||
|
pom.xml.tag
|
||||||
|
pom.xml.releaseBackup
|
||||||
|
pom.xml.versionsBackup
|
||||||
|
pom.xml.next
|
||||||
|
|
||||||
|
release.properties
|
||||||
|
dependency-reduced-pom.xml
|
||||||
|
buildNumber.properties
|
||||||
|
.mvn/timing.properties
|
||||||
|
.mvn/wrapper/maven-wrapper.jar
|
||||||
|
.flattened-pom.xml
|
||||||
|
|
||||||
|
# Common working directory
|
||||||
|
run/
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
<?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>eu.endermite</groupId>
|
||||||
|
<artifactId>CommandWhitelist</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>CommandWhitelist</name>
|
||||||
|
|
||||||
|
<description>Control what commands players can use</description>
|
||||||
|
<properties>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>${java.version}</source>
|
||||||
|
<target>${java.version}</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.2</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>spigotmc-repo</id>
|
||||||
|
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>sonatype</id>
|
||||||
|
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot-api</artifactId>
|
||||||
|
<version>1.16.1-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package eu.endermite.commandwhitelist;
|
||||||
|
|
||||||
|
import eu.endermite.commandwhitelist.config.ConfigCache;
|
||||||
|
import eu.endermite.commandwhitelist.listeners.PlayerCommandPreProcess;
|
||||||
|
import eu.endermite.commandwhitelist.listeners.PlayerCommandSend;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
public final class CommandWhitelist extends JavaPlugin {
|
||||||
|
|
||||||
|
private static CommandWhitelist commandWhitelist;
|
||||||
|
private static ConfigCache configCache;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
|
||||||
|
commandWhitelist = this;
|
||||||
|
reloadPluginConfig();
|
||||||
|
|
||||||
|
getServer().getPluginManager().registerEvents(new PlayerCommandPreProcess(), this);
|
||||||
|
getServer().getPluginManager().registerEvents(new PlayerCommandSend(), this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
// Plugin shutdown logic
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reloadPluginConfig() {
|
||||||
|
saveDefaultConfig();
|
||||||
|
configCache = new ConfigCache(this.getConfig());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CommandWhitelist getPlugin() {return commandWhitelist;}
|
||||||
|
public static ConfigCache getConfigCache() {return configCache;}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package eu.endermite.commandwhitelist.config;
|
||||||
|
|
||||||
|
import eu.endermite.commandwhitelist.CommandWhitelist;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class ConfigCache {
|
||||||
|
|
||||||
|
private final HashMap<String, List<String>> permList = new HashMap<>();
|
||||||
|
private final String prefix;
|
||||||
|
private final String commandDenied;
|
||||||
|
|
||||||
|
public ConfigCache(FileConfiguration yamlConfiguration) {
|
||||||
|
Set<String> perms = yamlConfiguration.getConfigurationSection("commands").getKeys(false);
|
||||||
|
for (String s : perms) {
|
||||||
|
this.permList.put(s, CommandWhitelist.getPlugin().getConfig().getStringList("commands."+s));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.prefix = CommandWhitelist.getPlugin().getConfig().getString("messages.prefix");
|
||||||
|
this.commandDenied = CommandWhitelist.getPlugin().getConfig().getString("messages.command-denied");
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<String, List<String>> getPermList() {
|
||||||
|
return permList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getPerm(String s) {
|
||||||
|
return permList.get(s);
|
||||||
|
}
|
||||||
|
public String getPrefix() {return prefix;}
|
||||||
|
public String getCommandDenied() {return commandDenied;}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package eu.endermite.commandwhitelist.listeners;
|
||||||
|
|
||||||
|
import eu.endermite.commandwhitelist.CommandWhitelist;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class PlayerCommandPreProcess implements Listener {
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
|
public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
|
if (player.hasPermission("commandwhitelist.bypass:")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String command = event.getMessage();
|
||||||
|
|
||||||
|
for (Map.Entry<String, List<String>> s : CommandWhitelist.getConfigCache().getPermList().entrySet()) {
|
||||||
|
if (player.hasPermission("commandwhitelist.commands." + s.getKey())) {
|
||||||
|
for (String comm : s.getValue()) {
|
||||||
|
if (command.startsWith("/" + comm)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
event.setCancelled(true);
|
||||||
|
player.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().getPrefix() + " " + CommandWhitelist.getConfigCache().getCommandDenied()));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package eu.endermite.commandwhitelist.listeners;
|
||||||
|
|
||||||
|
import eu.endermite.commandwhitelist.CommandWhitelist;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class PlayerCommandSend implements Listener {
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
|
public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandSendEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
|
if (player.hasPermission("commandwhitelist.bypass:")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> commandList = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Map.Entry<String, List<String>> s : CommandWhitelist.getConfigCache().getPermList().entrySet()) {
|
||||||
|
if (player.hasPermission("commandwhitelist.commands."+s.getKey())) {
|
||||||
|
commandList.addAll(s.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
event.getCommands().removeIf((cmd) -> !commandList.contains(cmd));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
messages:
|
||||||
|
prefix: "CommandWhitelist >"
|
||||||
|
command-denied: "No such command."
|
||||||
|
|
||||||
|
commands:
|
||||||
|
default:
|
||||||
|
- ?
|
||||||
|
- help
|
||||||
|
- spawn
|
||||||
|
- bal
|
||||||
|
- balance
|
||||||
|
- baltop
|
||||||
|
- pay
|
||||||
|
- r
|
||||||
|
- msg
|
||||||
|
- tpa
|
||||||
|
- tpahere
|
||||||
|
- tpaccept
|
||||||
|
- tpdeny
|
||||||
|
- warp
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
name: CommandWhitelist
|
||||||
|
version: ${project.version}
|
||||||
|
main: eu.endermite.commandwhitelist.CommandWhitelist
|
||||||
|
api-version: 1.16
|
||||||
|
authors: [YouHaveTrouble]
|
||||||
|
description: Control what commands players can use
|
||||||
|
permissions:
|
||||||
|
commandwhitelist.bypass:
|
||||||
|
default: OP
|
||||||
|
commandwhitelist.commands.default:
|
||||||
|
default: true
|
||||||
Reference in New Issue
Block a user