mirror of
https://github.com/YouHaveTrouble/CommandWhitelist.git
synced 2026-05-12 06:26:57 +00:00
Compare commits
58 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7f6315b6b5 | |||
| bbc0e44660 | |||
| 9e255076b0 | |||
| a91af744fd | |||
| 930f73d60a | |||
| c5fdaa95f8 | |||
| 87fc3d7da3 | |||
| 0cc2633604 | |||
| d6909b4f25 | |||
| cd3d527119 | |||
| d43bde0750 | |||
| 48fbd59a50 | |||
| 7c3a06e704 | |||
| 5d7cd9d41f | |||
| f101b68ed8 | |||
| 707bcbbf8b | |||
| fec7e3ba07 | |||
| 7139baf2d9 | |||
| f1d10243ce | |||
| 1647605682 | |||
| aff390369f | |||
| c586a8af05 | |||
| 26a408812d | |||
| 727d6c3227 | |||
| 7e6b793ede | |||
| fd893b931d | |||
| 5bcf5bb130 | |||
| 7c33718190 | |||
| ad599092de | |||
| 1bb2c7ea6a | |||
| a935503239 | |||
| 2a6be9829c | |||
| 097b541a1f | |||
| 5f447e07b6 | |||
| b5e12655f9 | |||
| 14f15aa754 | |||
| 017011fad0 | |||
| 050e3e7af4 | |||
| 8d97d4bedc | |||
| 1e4de5709d | |||
| 0642abd51e | |||
| fc26393dcf | |||
| 55fdf0c076 | |||
| 11beafdae7 | |||
| 7f0141ec36 | |||
| f736179eae | |||
| 526e37b9a2 | |||
| 4a8902ad21 | |||
| bec049570d | |||
| c1950e2670 | |||
| 94dcd640a1 | |||
| 6e08ba6692 | |||
| 88d51b29aa | |||
| 20eb731b93 | |||
| 862fa193e6 | |||
| 60260106a9 | |||
| d4396fdba2 | |||
| 8a16ee39ef |
@@ -1,36 +0,0 @@
|
|||||||
name: Build CommandWhitelist Jar
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout Git repo
|
|
||||||
uses: actions/checkout@v1
|
|
||||||
- name: Restore Maven cache
|
|
||||||
uses: actions/cache@v1
|
|
||||||
with:
|
|
||||||
path: ~/.m2/repository
|
|
||||||
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-maven-
|
|
||||||
- name: Set up JDK 1.8
|
|
||||||
uses: actions/setup-java@v1
|
|
||||||
with:
|
|
||||||
java-version: 1.8
|
|
||||||
- name: Build with Maven
|
|
||||||
run: mvn package --file pom.xml
|
|
||||||
- name: Copy artifacts
|
|
||||||
uses: actions/upload-artifact@master
|
|
||||||
with:
|
|
||||||
name: CommandWhitelist
|
|
||||||
path: target/CommandWhitelist*.jar
|
|
||||||
@@ -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,123 @@
|
|||||||
|
<?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>
|
||||||
|
<parent>
|
||||||
|
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||||
|
<artifactId>CommandWhitelist</artifactId>
|
||||||
|
<version>2.2.2</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>Bukkit</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<name>CommandWhitelist-Bukkit</name>
|
||||||
|
|
||||||
|
<description>You decide what commands players can use or tab complete on your server!</description>
|
||||||
|
<properties>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
<url>youhavetrouble.me</url>
|
||||||
|
|
||||||
|
<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.3.0-SNAPSHOT</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<finalName>${project.name}-${project.parent.version}</finalName>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
|
<relocations>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.bstats</pattern>
|
||||||
|
<shadedPattern>eu.endermite.bstats</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>net.kyori</pattern>
|
||||||
|
<shadedPattern>eu.endermite</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
</relocations>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>sonatype</id>
|
||||||
|
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>dmulloy2-repo</id>
|
||||||
|
<url>https://repo.dmulloy2.net/nexus/repository/public/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>papermc</id>
|
||||||
|
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.papermc.paper</groupId>
|
||||||
|
<artifactId>paper-api</artifactId>
|
||||||
|
<version>1.17.1-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.kyori</groupId>
|
||||||
|
<artifactId>adventure-platform-bukkit</artifactId>
|
||||||
|
<version>4.0.0-SNAPSHOT</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||||
|
<artifactId>Common</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.comphenix.protocol</groupId>
|
||||||
|
<artifactId>ProtocolLib</artifactId>
|
||||||
|
<version>4.6.0</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bstats</groupId>
|
||||||
|
<artifactId>bstats-bukkit</artifactId>
|
||||||
|
<version>2.2.1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mojang</groupId>
|
||||||
|
<artifactId>brigadier</artifactId>
|
||||||
|
<version>1.0.17</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
+154
@@ -0,0 +1,154 @@
|
|||||||
|
package eu.endermite.commandwhitelist.bukkit;
|
||||||
|
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.command.MainCommandExecutor;
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.listeners.AsyncTabCompleteBlockerListener;
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.listeners.PlayerCommandPreProcessListener;
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.listeners.PlayerCommandSendListener;
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.listeners.TabCompleteBlockerListener;
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.listeners.protocollib.PacketCommandPreProcessListener;
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.listeners.protocollib.PacketCommandSendListener;
|
||||||
|
import eu.endermite.commandwhitelist.common.CWGroup;
|
||||||
|
import eu.endermite.commandwhitelist.common.ConfigCache;
|
||||||
|
import eu.endermite.commandwhitelist.common.commands.CWCommand;
|
||||||
|
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||||
|
import org.bstats.bukkit.Metrics;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.PluginCommand;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class CommandWhitelistBukkit extends JavaPlugin {
|
||||||
|
|
||||||
|
private static CommandWhitelistBukkit commandWhitelist;
|
||||||
|
private static ConfigCache configCache;
|
||||||
|
private static BukkitAudiences audiences;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
|
||||||
|
commandWhitelist = this;
|
||||||
|
audiences = BukkitAudiences.create(this);
|
||||||
|
|
||||||
|
reloadPluginConfig();
|
||||||
|
|
||||||
|
Plugin protocollib = getServer().getPluginManager().getPlugin("ProtocolLib");
|
||||||
|
|
||||||
|
if (!getConfigCache().useProtocolLib || protocollib == null || !protocollib.isEnabled()) {
|
||||||
|
getServer().getPluginManager().registerEvents(new PlayerCommandPreProcessListener(), this);
|
||||||
|
getServer().getPluginManager().registerEvents(new PlayerCommandSendListener(), this);
|
||||||
|
} else {
|
||||||
|
PacketCommandPreProcessListener.protocol(this);
|
||||||
|
PacketCommandSendListener.protocol(this);
|
||||||
|
getLogger().info(ChatColor.AQUA + "Using ProtocolLib for command filter!");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// Use paper's async tab completions if possible
|
||||||
|
Class.forName("com.destroystokyo.paper.event.server.AsyncTabCompleteEvent");
|
||||||
|
getServer().getPluginManager().registerEvents(new AsyncTabCompleteBlockerListener(), this);
|
||||||
|
} catch (ClassNotFoundException ignored) {
|
||||||
|
}
|
||||||
|
getServer().getPluginManager().registerEvents(new TabCompleteBlockerListener(), this);
|
||||||
|
|
||||||
|
PluginCommand command = getCommand("commandwhitelist");
|
||||||
|
if (command != null) {
|
||||||
|
MainCommandExecutor executor = new MainCommandExecutor();
|
||||||
|
command.setExecutor(executor);
|
||||||
|
command.setTabCompleter(executor);
|
||||||
|
}
|
||||||
|
|
||||||
|
new Metrics(this, 8705);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void reloadPluginConfig() {
|
||||||
|
File configFile = new File("plugins/CommandWhitelist/config.yml");
|
||||||
|
if (configCache == null) {
|
||||||
|
try {
|
||||||
|
configCache = new ConfigCache(configFile, true, getSLF4JLogger());
|
||||||
|
} catch (NoSuchMethodError e) {
|
||||||
|
configCache = new ConfigCache(configFile, true, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
configCache.reloadConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reloadPluginConfig(CommandSender sender) {
|
||||||
|
getServer().getScheduler().runTaskAsynchronously(this, () -> {
|
||||||
|
reloadPluginConfig();
|
||||||
|
try {
|
||||||
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
|
p.updateCommands();
|
||||||
|
}
|
||||||
|
} catch (Exception ignored) {}
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + configCache.config_reloaded));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CommandWhitelistBukkit getPlugin() {
|
||||||
|
return commandWhitelist;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConfigCache getConfigCache() {
|
||||||
|
return configCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BukkitAudiences getAudiences() {
|
||||||
|
return audiences;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param player Bukkit Player
|
||||||
|
* @return commands available to the player
|
||||||
|
*/
|
||||||
|
public static HashSet<String> getCommands(org.bukkit.entity.Player player) {
|
||||||
|
HashSet<String> commandList = new HashSet<>();
|
||||||
|
HashMap<String, CWGroup> groups = configCache.getGroupList();
|
||||||
|
for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
|
||||||
|
if (s.getKey().equalsIgnoreCase("default"))
|
||||||
|
commandList.addAll(s.getValue().getCommands());
|
||||||
|
else if (player.hasPermission(s.getValue().getPermission()))
|
||||||
|
commandList.addAll(s.getValue().getCommands());
|
||||||
|
}
|
||||||
|
return commandList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param player Bukkit Player
|
||||||
|
* @return subcommands unavailable for the player
|
||||||
|
*/
|
||||||
|
public static HashSet<String> getSuggestions(org.bukkit.entity.Player player) {
|
||||||
|
HashSet<String> suggestionList = new HashSet<>();
|
||||||
|
HashMap<String, CWGroup> groups = configCache.getGroupList();
|
||||||
|
for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
|
||||||
|
if (s.getKey().equalsIgnoreCase("default"))
|
||||||
|
suggestionList.addAll(s.getValue().getSubCommands());
|
||||||
|
if (player.hasPermission(s.getValue().getPermission())) continue;
|
||||||
|
suggestionList.addAll(s.getValue().getSubCommands());
|
||||||
|
}
|
||||||
|
return suggestionList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Command denied message. Will use custom if command exists in any group.
|
||||||
|
*/
|
||||||
|
public static String getCommandDeniedMessage(String command) {
|
||||||
|
String commandDeniedMessage = configCache.command_denied;
|
||||||
|
HashMap<String, CWGroup> groups = configCache.getGroupList();
|
||||||
|
for (CWGroup group : groups.values()) {
|
||||||
|
if (group.getCommands().contains(command)) {
|
||||||
|
if (group.getCommandDeniedMessage() == null || group.getCommandDeniedMessage().isEmpty()) continue;
|
||||||
|
commandDeniedMessage = group.getCommandDeniedMessage();
|
||||||
|
break; // get first message we find
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return commandDeniedMessage;
|
||||||
|
}
|
||||||
|
}
|
||||||
+82
@@ -0,0 +1,82 @@
|
|||||||
|
package eu.endermite.commandwhitelist.bukkit.command;
|
||||||
|
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit;
|
||||||
|
import eu.endermite.commandwhitelist.common.CWPermission;
|
||||||
|
import eu.endermite.commandwhitelist.common.commands.CWCommand;
|
||||||
|
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.TabExecutor;
|
||||||
|
import org.bukkit.help.HelpTopic;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MainCommandExecutor implements TabExecutor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
|
||||||
|
BukkitAudiences audiences = CommandWhitelistBukkit.getAudiences();
|
||||||
|
|
||||||
|
if (args.length == 0) {
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
CWCommand.CommandType commandType = CWCommand.CommandType.valueOf(args[0].toUpperCase());
|
||||||
|
switch (commandType) {
|
||||||
|
case RELOAD:
|
||||||
|
if (!sender.hasPermission(CWPermission.RELOAD.permission())) {
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().no_permission));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
CommandWhitelistBukkit.getPlugin().reloadPluginConfig(sender);
|
||||||
|
return true;
|
||||||
|
case ADD:
|
||||||
|
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().no_permission));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (args.length == 3) {
|
||||||
|
if (CWCommand.addToWhitelist(CommandWhitelistBukkit.getConfigCache(), args[2], args[1]))
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(String.format(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().added_to_whitelist, args[2], args[1])));
|
||||||
|
else
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(String.format(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().group_doesnt_exist, args[1])));
|
||||||
|
} else
|
||||||
|
audiences.sender(sender).sendMessage(Component.text("/" + label + " add <group> <command>"));
|
||||||
|
return true;
|
||||||
|
case REMOVE:
|
||||||
|
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().no_permission));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (args.length == 3) {
|
||||||
|
if (CWCommand.removeFromWhitelist(CommandWhitelistBukkit.getConfigCache(), args[2], args[1]))
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(String.format(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().removed_from_whitelist, args[2], args[1])));
|
||||||
|
else
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(String.format(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().group_doesnt_exist, args[1])));
|
||||||
|
} else
|
||||||
|
audiences.sender(sender).sendMessage(Component.text("/" + label + " remove <group> <command>"));
|
||||||
|
return true;
|
||||||
|
case HELP:
|
||||||
|
default:
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
|
||||||
|
}
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||||
|
List<String> serverCommands = new ArrayList<>();
|
||||||
|
for (HelpTopic topic : Bukkit.getHelpMap().getHelpTopics()) {
|
||||||
|
serverCommands.add(topic.getName());
|
||||||
|
}
|
||||||
|
return CWCommand.commandSuggestions(CommandWhitelistBukkit.getConfigCache(), serverCommands, args, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission()));
|
||||||
|
}
|
||||||
|
}
|
||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
package eu.endermite.commandwhitelist.bukkit.listeners;
|
||||||
|
|
||||||
|
import com.destroystokyo.paper.event.server.AsyncTabCompleteEvent;
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit;
|
||||||
|
import eu.endermite.commandwhitelist.common.CWPermission;
|
||||||
|
import eu.endermite.commandwhitelist.common.CommandUtil;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
|
||||||
|
public class AsyncTabCompleteBlockerListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onCommandTabComplete(AsyncTabCompleteEvent event) {
|
||||||
|
if (!(event.getSender() instanceof Player)) return;
|
||||||
|
Player player = (Player) event.getSender();
|
||||||
|
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||||
|
String buffer = event.getBuffer();
|
||||||
|
if (!buffer.endsWith(" ") && buffer.split(" ").length == 1) event.setCancelled(true);
|
||||||
|
if (event.getCompletions().isEmpty()) return;
|
||||||
|
event.setCompletions(CommandUtil.filterSuggestions(buffer, event.getCompletions(), CommandWhitelistBukkit.getSuggestions(player)));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
package eu.endermite.commandwhitelist.bukkit.listeners;
|
||||||
|
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit;
|
||||||
|
import eu.endermite.commandwhitelist.common.CommandUtil;
|
||||||
|
import eu.endermite.commandwhitelist.common.ConfigCache;
|
||||||
|
import eu.endermite.commandwhitelist.common.commands.CWCommand;
|
||||||
|
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
public class PlayerCommandPreProcessListener implements Listener {
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
if (player.hasPermission("commandwhitelist.bypass")) return;
|
||||||
|
String label = CommandUtil.getCommandLabel(event.getMessage().toLowerCase());
|
||||||
|
BukkitAudiences audiences = CommandWhitelistBukkit.getAudiences();
|
||||||
|
ConfigCache config = CommandWhitelistBukkit.getConfigCache();
|
||||||
|
|
||||||
|
HashSet<String> commands = CommandWhitelistBukkit.getCommands(player);
|
||||||
|
if (!commands.contains(label)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
audiences.player(player).sendMessage(CWCommand.miniMessage.parse(config.prefix + CommandWhitelistBukkit.getCommandDeniedMessage(label)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
HashSet<String> bannedSubCommands = CommandWhitelistBukkit.getSuggestions(player);
|
||||||
|
for (String bannedSubCommand : bannedSubCommands) {
|
||||||
|
if (event.getMessage().toLowerCase().substring(1).startsWith(bannedSubCommand)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
audiences.player(player).sendMessage(CWCommand.miniMessage.parse(config.prefix + config.subcommand_denied));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+7
-6
@@ -1,19 +1,20 @@
|
|||||||
package eu.endermite.commandwhitelist.spigot.listeners;
|
package eu.endermite.commandwhitelist.bukkit.listeners;
|
||||||
|
|
||||||
import eu.endermite.commandwhitelist.api.CommandsList;
|
import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit;
|
||||||
|
import eu.endermite.commandwhitelist.common.CWPermission;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import java.util.*;
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
public class PlayerCommandSendListener implements Listener {
|
public class PlayerCommandSendListener implements Listener {
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandSendEvent event) {
|
public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandSendEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (player.hasPermission("commandwhitelist.bypass"))
|
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||||
return;
|
HashSet<String> commandList = CommandWhitelistBukkit.getCommands(player);
|
||||||
List<String> commandList = CommandsList.getCommands(player);
|
|
||||||
event.getCommands().removeIf((cmd) -> !commandList.contains(cmd));
|
event.getCommands().removeIf((cmd) -> !commandList.contains(cmd));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
package eu.endermite.commandwhitelist.bukkit.listeners;
|
||||||
|
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit;
|
||||||
|
import eu.endermite.commandwhitelist.common.CWPermission;
|
||||||
|
import eu.endermite.commandwhitelist.common.CommandUtil;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.server.TabCompleteEvent;
|
||||||
|
|
||||||
|
public class TabCompleteBlockerListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
|
public void onCommandTabComplete(TabCompleteEvent event) {
|
||||||
|
if (!(event.getSender() instanceof Player)) return;
|
||||||
|
Player player = (Player) event.getSender();
|
||||||
|
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||||
|
String buffer = event.getBuffer();
|
||||||
|
if (!buffer.endsWith(" ") && buffer.split(" ").length == 1) event.setCancelled(true);
|
||||||
|
if (event.getCompletions().isEmpty()) return;
|
||||||
|
event.setCompletions(
|
||||||
|
CommandUtil.filterSuggestions(
|
||||||
|
buffer,
|
||||||
|
event.getCompletions(),
|
||||||
|
CommandWhitelistBukkit.getSuggestions(player)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+58
@@ -0,0 +1,58 @@
|
|||||||
|
package eu.endermite.commandwhitelist.bukkit.listeners.protocollib;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.PacketType;
|
||||||
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
|
import com.comphenix.protocol.ProtocolManager;
|
||||||
|
import com.comphenix.protocol.events.ListenerPriority;
|
||||||
|
import com.comphenix.protocol.events.PacketAdapter;
|
||||||
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
|
import com.comphenix.protocol.events.PacketEvent;
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit;
|
||||||
|
import eu.endermite.commandwhitelist.common.CWPermission;
|
||||||
|
import eu.endermite.commandwhitelist.common.CommandUtil;
|
||||||
|
import eu.endermite.commandwhitelist.common.ConfigCache;
|
||||||
|
import eu.endermite.commandwhitelist.common.commands.CWCommand;
|
||||||
|
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
public class PacketCommandPreProcessListener {
|
||||||
|
|
||||||
|
public static void protocol(CommandWhitelistBukkit plugin) {
|
||||||
|
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
||||||
|
commandExecListener(protocolManager, plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void commandExecListener(ProtocolManager protocolManager, Plugin plugin) {
|
||||||
|
protocolManager.addPacketListener(new PacketAdapter(plugin, ListenerPriority.HIGHEST, PacketType.Play.Client.CHAT) {
|
||||||
|
@Override
|
||||||
|
public void onPacketReceiving(PacketEvent event) {
|
||||||
|
PacketContainer packet = event.getPacket();
|
||||||
|
String string = packet.getStrings().read(0);
|
||||||
|
if (!string.startsWith("/")) return;
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||||
|
|
||||||
|
ConfigCache config = CommandWhitelistBukkit.getConfigCache();
|
||||||
|
String label = CommandUtil.getCommandLabel(string.toLowerCase());
|
||||||
|
HashSet<String> commands = CommandWhitelistBukkit.getCommands(player);
|
||||||
|
BukkitAudiences audiences = CommandWhitelistBukkit.getAudiences();
|
||||||
|
if (!commands.contains(label)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
audiences.player(player).sendMessage(CWCommand.miniMessage.parse(config.prefix + CommandWhitelistBukkit.getCommandDeniedMessage(label)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
HashSet<String> bannedSubCommands = CommandWhitelistBukkit.getSuggestions(player);
|
||||||
|
for (String bannedSubCommand : bannedSubCommands) {
|
||||||
|
if (string.toLowerCase().substring(1).startsWith(bannedSubCommand)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
CommandWhitelistBukkit.getAudiences().player(player).sendMessage(CWCommand.miniMessage.parse(config.prefix + config.subcommand_denied));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
package eu.endermite.commandwhitelist.bukkit.listeners.protocollib;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.PacketType;
|
||||||
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
|
import com.comphenix.protocol.ProtocolManager;
|
||||||
|
import com.comphenix.protocol.events.ListenerPriority;
|
||||||
|
import com.comphenix.protocol.events.PacketAdapter;
|
||||||
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
|
import com.comphenix.protocol.events.PacketEvent;
|
||||||
|
import com.mojang.brigadier.tree.RootCommandNode;
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit;
|
||||||
|
import eu.endermite.commandwhitelist.common.CWPermission;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
public class PacketCommandSendListener {
|
||||||
|
|
||||||
|
public static void protocol(CommandWhitelistBukkit plugin) {
|
||||||
|
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
||||||
|
commandSendListener(protocolManager, plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void commandSendListener(ProtocolManager protocolManager, Plugin plugin) {
|
||||||
|
protocolManager.addPacketListener(new PacketAdapter(plugin, ListenerPriority.HIGHEST, PacketType.Play.Server.COMMANDS) {
|
||||||
|
@Override
|
||||||
|
public void onPacketSending(PacketEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||||
|
|
||||||
|
HashSet<String> commandList = CommandWhitelistBukkit.getCommands(player);
|
||||||
|
PacketContainer packet = event.getPacket();
|
||||||
|
RootCommandNode<?> node = (RootCommandNode<?>) packet.getModifier().getValues().get(0);
|
||||||
|
node.getChildren().removeIf((cmd) -> !commandList.contains(cmd.getName()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+5
-6
@@ -2,8 +2,9 @@ name: CommandWhitelist
|
|||||||
prefix: CommandWhitelist
|
prefix: CommandWhitelist
|
||||||
version: ${project.version}
|
version: ${project.version}
|
||||||
api-version: 1.13
|
api-version: 1.13
|
||||||
main: eu.endermite.commandwhitelist.spigot.CommandWhitelist
|
main: eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit
|
||||||
authors: [YouHaveTrouble]
|
authors: [YouHaveTrouble]
|
||||||
|
website: youhavetrouble.me
|
||||||
softdepend:
|
softdepend:
|
||||||
- ProtocolLib
|
- ProtocolLib
|
||||||
description: Control what commands players can use
|
description: Control what commands players can use
|
||||||
@@ -14,10 +15,8 @@ commands:
|
|||||||
usage: /commandwhitelist [args]
|
usage: /commandwhitelist [args]
|
||||||
permissions:
|
permissions:
|
||||||
commandwhitelist.reload:
|
commandwhitelist.reload:
|
||||||
default: OP
|
default: op
|
||||||
commandwhitelist.admin:
|
commandwhitelist.admin:
|
||||||
default: OP
|
default: op
|
||||||
commandwhitelist.bypass:
|
commandwhitelist.bypass:
|
||||||
default: OP
|
default: op
|
||||||
commandwhitelist.commands.default:
|
|
||||||
default: true
|
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
<?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>
|
||||||
|
<parent>
|
||||||
|
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||||
|
<artifactId>CommandWhitelist</artifactId>
|
||||||
|
<version>2.2.2</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>Common</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<name>CommandWhitelist-Common</name>
|
||||||
|
|
||||||
|
<description>You decide what commands players can use or tab complete on your server!</description>
|
||||||
|
<properties>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
<url>youhavetrouble.me</url>
|
||||||
|
|
||||||
|
<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.4</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
|
<finalName>${project.name}-${project.parent.version}</finalName>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>pluginwiki-repo</id>
|
||||||
|
<url>https://ci.pluginwiki.us/plugin/repository/everything/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>velocitypowered-repo</id>
|
||||||
|
<url>https://repo.velocitypowered.com/releases/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>papermc</id>
|
||||||
|
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.thatsmusic99</groupId>
|
||||||
|
<artifactId>ConfigurationMaster-API</artifactId>
|
||||||
|
<version>v2.0.0-BETA-1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.velocitypowered</groupId>
|
||||||
|
<artifactId>velocity-api</artifactId>
|
||||||
|
<version>1.1.0</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.papermc.paper</groupId>
|
||||||
|
<artifactId>paper-api</artifactId>
|
||||||
|
<version>1.17.1-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.github.waterfallmc</groupId>
|
||||||
|
<artifactId>waterfall-api</artifactId>
|
||||||
|
<version>1.17-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
+65
@@ -0,0 +1,65 @@
|
|||||||
|
package eu.endermite.commandwhitelist.common;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class CWGroup {
|
||||||
|
|
||||||
|
private final String id, permission, commandDeniedMessage;
|
||||||
|
private final HashSet<String> commands = new HashSet<>();
|
||||||
|
private final HashSet<String> subCommands = new HashSet<>();
|
||||||
|
|
||||||
|
public CWGroup(String id, Collection<String> commands, Collection<String> subCommands, String custom_command_denied_message) {
|
||||||
|
this.id = id;
|
||||||
|
this.permission = "commandwhitelist.group." + id;
|
||||||
|
this.commands.addAll(commands);
|
||||||
|
this.commandDeniedMessage = custom_command_denied_message;
|
||||||
|
this.subCommands.addAll(subCommands);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPermission() {
|
||||||
|
return permission;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashSet<String> getCommands() {
|
||||||
|
return commands;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable String getCommandDeniedMessage() {
|
||||||
|
return commandDeniedMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addCommand(String command) {
|
||||||
|
commands.add(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeCommand(String command) {
|
||||||
|
commands.remove(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashSet<String> getSubCommands() {
|
||||||
|
return subCommands;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addSubCommand(String subCommand) {
|
||||||
|
subCommands.add(subCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeSubCommand(String subCommand) {
|
||||||
|
subCommands.remove(subCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<String, Object> serialize() {
|
||||||
|
HashMap<String, Object> serializedGroup = new LinkedHashMap<>();
|
||||||
|
List<String> commands = new ArrayList<>(this.commands);
|
||||||
|
List<String> subCommands = new ArrayList<>(this.subCommands);
|
||||||
|
serializedGroup.put("commands", commands);
|
||||||
|
serializedGroup.put("subcommands", subCommands);
|
||||||
|
return serializedGroup;
|
||||||
|
}
|
||||||
|
}
|
||||||
+32
@@ -0,0 +1,32 @@
|
|||||||
|
package eu.endermite.commandwhitelist.common;
|
||||||
|
|
||||||
|
public enum CWPermission {
|
||||||
|
|
||||||
|
ADMIN("commandwhitelist.admin"),
|
||||||
|
RELOAD("commandwhitelist.reload"),
|
||||||
|
BYPASS("commandwhitelist.bypass");
|
||||||
|
|
||||||
|
private final String permission;
|
||||||
|
|
||||||
|
CWPermission(String permission) {
|
||||||
|
this.permission = permission;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String permission() {
|
||||||
|
return permission;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows to check specific group permission
|
||||||
|
*
|
||||||
|
* @param configCache
|
||||||
|
* @param groupId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getGroupPermission(ConfigCache configCache, String groupId) {
|
||||||
|
if (configCache.getGroupList().containsKey(groupId))
|
||||||
|
return configCache.getGroupList().get(groupId).getPermission();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+64
@@ -0,0 +1,64 @@
|
|||||||
|
package eu.endermite.commandwhitelist.common;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CommandUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters blocked command suggestions from provided collection of strings
|
||||||
|
*
|
||||||
|
* @param buffer Command buffer
|
||||||
|
* @param suggestions Full suggestions list
|
||||||
|
* @param blockedSubCommands Subcommands to filter out
|
||||||
|
* @return Filtered list of suggestions
|
||||||
|
*/
|
||||||
|
public static List<String> filterSuggestions(String buffer, Collection<String> suggestions, Collection<String> blockedSubCommands) {
|
||||||
|
if (buffer.startsWith("/"))
|
||||||
|
buffer = buffer.substring(1);
|
||||||
|
for (String s : blockedSubCommands) {
|
||||||
|
String slast = getLastArgument(s);
|
||||||
|
String scommand = cutLastArgument(s);
|
||||||
|
if (buffer.startsWith(scommand)) {
|
||||||
|
while (suggestions.contains(slast))
|
||||||
|
suggestions.remove(slast);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new ArrayList<>(suggestions);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param cmd The command
|
||||||
|
* @return Last argument of the command
|
||||||
|
*/
|
||||||
|
public static String getLastArgument(String cmd) {
|
||||||
|
String[] parts = cmd.split(" ");
|
||||||
|
if (parts.length == 0) return "";
|
||||||
|
return parts[parts.length - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param cmd The command
|
||||||
|
* @return Command without the last argument.
|
||||||
|
*/
|
||||||
|
public static String cutLastArgument(String cmd) {
|
||||||
|
String[] cmdSplit = cmd.split(" ");
|
||||||
|
StringBuilder cmdBuilder = new StringBuilder();
|
||||||
|
for (int i = 0; i <= cmdSplit.length - 2; i++)
|
||||||
|
cmdBuilder.append(cmdSplit[i]).append(" ");
|
||||||
|
return cmdBuilder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param cmd The command
|
||||||
|
* @return Command label
|
||||||
|
*/
|
||||||
|
public static String getCommandLabel(String cmd) {
|
||||||
|
String[] parts = cmd.split(" ");
|
||||||
|
if (parts[0].startsWith("/"))
|
||||||
|
parts[0] = parts[0].substring(1);
|
||||||
|
return parts[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+167
@@ -0,0 +1,167 @@
|
|||||||
|
package eu.endermite.commandwhitelist.common;
|
||||||
|
|
||||||
|
import io.github.thatsmusic99.configurationmaster.api.ConfigFile;
|
||||||
|
import io.github.thatsmusic99.configurationmaster.api.ConfigSection;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class ConfigCache {
|
||||||
|
|
||||||
|
private final File configFile;
|
||||||
|
private ConfigFile config;
|
||||||
|
private final Object logger;
|
||||||
|
private final boolean canDoProtocolLib;
|
||||||
|
private final HashMap<String, CWGroup> groupList = new LinkedHashMap<>();
|
||||||
|
public String prefix, command_denied, no_permission, no_such_subcommand, config_reloaded, added_to_whitelist,
|
||||||
|
removed_from_whitelist, group_doesnt_exist, subcommand_denied;
|
||||||
|
public boolean useProtocolLib = false;
|
||||||
|
|
||||||
|
public ConfigCache(File configFile, boolean canDoProtocolLib, Object logger) {
|
||||||
|
this.configFile = configFile;
|
||||||
|
this.canDoProtocolLib = canDoProtocolLib;
|
||||||
|
this.logger = logger;
|
||||||
|
|
||||||
|
reloadConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean reloadConfig() {
|
||||||
|
|
||||||
|
createFiles();
|
||||||
|
config = ConfigFile.loadConfig(configFile);
|
||||||
|
|
||||||
|
config.addDefault("messages.prefix", "CommandWhitelist > ");
|
||||||
|
config.addDefault("messages.command_denied", "No such command.");
|
||||||
|
config.addDefault("messages.subcommand_denied", "You cannot use this subcommand");
|
||||||
|
config.addDefault("messages.no_permission", "<red>You don't have permission to do this.");
|
||||||
|
config.addDefault("messages.no_such_subcommand", "<red>No subcommand by that name.");
|
||||||
|
config.addDefault("messages.config_reloaded", "<yellow>Configuration reloaded.");
|
||||||
|
config.addDefault("messages.added_to_whitelist", "<yellow>Whitelisted command <gold>%s <yellow>for permission <gold>%s");
|
||||||
|
config.addDefault("messages.removed_from_whitelist", "<yellow>Removed command <gold>%s <yellow>from permission <gold>%s");
|
||||||
|
config.addDefault("messages.group_doesnt_exist", "<red>Group doesn't exist or error occured");
|
||||||
|
|
||||||
|
config.addComment("messages", "Messages use MiniMessage formatting (https://docs.adventure.kyori.net/minimessage.html#format)");
|
||||||
|
|
||||||
|
if (canDoProtocolLib)
|
||||||
|
config.addDefault("use_protocollib", false, "Do not enable if you don't have issues with aliased commands.\nThis requires server restart to take effect.");
|
||||||
|
|
||||||
|
if (config.isNew()) {
|
||||||
|
List<String> exampleCommands = new ArrayList<>();
|
||||||
|
exampleCommands.add("example");
|
||||||
|
List<String> exampleSubCommands = new ArrayList<>();
|
||||||
|
exampleSubCommands.add("example of");
|
||||||
|
String exampleCustomCommandDeniedMessage = "You don't have commandwhitelist.group.example permission.";
|
||||||
|
|
||||||
|
config.addExample("groups.example.commands", exampleCommands, "This is the WHITELIST of commands that players will be able to see/use in the group \"example\"");
|
||||||
|
config.addExample("groups.example.subcommands", exampleSubCommands, "This is the BLACKLIST of subcommands that players will NOT be able to see/use in the group \"example\"");
|
||||||
|
config.addExample("groups.example.custom_command_denied_message", exampleCustomCommandDeniedMessage, "This is a custom message that players will see if they do not have commandwhitelist.group.<group_name> permission.\ncommandwhitelist.group.example in this case\nIf you don't want to use a custom message, set custom_command_denid_message: \"\"");
|
||||||
|
config.addComment("groups.example", "All groups except from default require commandwhitelist.group.<group_name> permission\ncommandwhitelist.group.example in this case\n If you wish to leave the list empty, put \"commands: []\" or \"subcommands: []\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
config.makeSectionLenient("groups");
|
||||||
|
List<String> defaultCommands = new ArrayList<>();
|
||||||
|
defaultCommands.add("help");
|
||||||
|
defaultCommands.add("spawn");
|
||||||
|
defaultCommands.add("bal");
|
||||||
|
defaultCommands.add("balance");
|
||||||
|
defaultCommands.add("baltop");
|
||||||
|
defaultCommands.add("pay");
|
||||||
|
defaultCommands.add("r");
|
||||||
|
defaultCommands.add("msg");
|
||||||
|
defaultCommands.add("tpa");
|
||||||
|
defaultCommands.add("tpahere");
|
||||||
|
defaultCommands.add("tpaccept");
|
||||||
|
defaultCommands.add("tpdeny");
|
||||||
|
defaultCommands.add("warp");
|
||||||
|
List<String> defaultSubcommands = new ArrayList<>();
|
||||||
|
defaultSubcommands.add("help about");
|
||||||
|
|
||||||
|
String defaultCustomCommandDeniedMessage = "";
|
||||||
|
|
||||||
|
config.addDefault("groups.default", new CWGroup("default", defaultCommands, defaultSubcommands, defaultCustomCommandDeniedMessage).serialize());
|
||||||
|
|
||||||
|
prefix = config.getString("messages.prefix");
|
||||||
|
command_denied = config.getString("messages.command_denied");
|
||||||
|
subcommand_denied = config.getString("messages.subcommand_denied");
|
||||||
|
no_permission = config.getString("messages.no_permission");
|
||||||
|
no_such_subcommand = config.getString("messages.no_such_subcommand");
|
||||||
|
config_reloaded = config.getString("messages.config_reloaded");
|
||||||
|
added_to_whitelist = config.getString("messages.added_to_whitelist");
|
||||||
|
removed_from_whitelist = config.getString("messages.removed_from_whitelist");
|
||||||
|
group_doesnt_exist = config.getString("messages.group_doesnt_exist");
|
||||||
|
useProtocolLib = config.getBoolean("use_protocollib");
|
||||||
|
|
||||||
|
ConfigSection groupSection = config.getConfigSection("groups");
|
||||||
|
for (String key : groupSection.getKeys(false)) {
|
||||||
|
groupList.put(key, loadCWGroup(key, groupSection));
|
||||||
|
}
|
||||||
|
|
||||||
|
return saveConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean saveConfig() {
|
||||||
|
try {
|
||||||
|
config.save();
|
||||||
|
return true;
|
||||||
|
} catch (IOException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createFiles() {
|
||||||
|
try {
|
||||||
|
File parent = new File(configFile.getParent());
|
||||||
|
if (!parent.exists())
|
||||||
|
parent.mkdir();
|
||||||
|
if (!configFile.exists())
|
||||||
|
configFile.createNewFile();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CWGroup loadCWGroup(String id, ConfigSection section) {
|
||||||
|
HashSet<String> commands = new HashSet<>();
|
||||||
|
for (String cmd : section.getStringList(id + ".commands")) {
|
||||||
|
if (cmd.contains(" ")) {
|
||||||
|
String[] cmdSplit = cmd.split(" ");
|
||||||
|
warn("CommandWhitelist - \"" + cmd + "\" is not a command. Loading it as \"" + cmdSplit[0] + "\".");
|
||||||
|
cmd = cmdSplit[0];
|
||||||
|
}
|
||||||
|
if (commands.contains(cmd)) continue;
|
||||||
|
commands.add(cmd);
|
||||||
|
}
|
||||||
|
List<String> subCommands = new ArrayList<>();
|
||||||
|
for (String subCmd : section.getStringList(id + ".subcommands")) {
|
||||||
|
subCommands.add(String.valueOf(subCmd));
|
||||||
|
}
|
||||||
|
String customCommandDeniedMessage = section.getString(id + ".custom_command_denied_message");
|
||||||
|
return new CWGroup(id, commands, subCommands, customCommandDeniedMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveCWGroup(String id, CWGroup group) {
|
||||||
|
config.set("groups." + id, group.serialize());
|
||||||
|
saveConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<String, CWGroup> getGroupList() {
|
||||||
|
return groupList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void warn(String log) {
|
||||||
|
if (logger == null) {
|
||||||
|
System.out.println("WARNING: "+log);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (logger instanceof org.slf4j.Logger) {
|
||||||
|
((org.slf4j.Logger) logger).warn(log);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (logger instanceof java.util.logging.Logger) {
|
||||||
|
((java.util.logging.Logger) logger).warning(log);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+119
@@ -0,0 +1,119 @@
|
|||||||
|
package eu.endermite.commandwhitelist.common.commands;
|
||||||
|
|
||||||
|
import eu.endermite.commandwhitelist.common.CWGroup;
|
||||||
|
import eu.endermite.commandwhitelist.common.ConfigCache;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.kyori.adventure.text.minimessage.transformation.TransformationType;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CWCommand {
|
||||||
|
|
||||||
|
public static MiniMessage miniMessage = MiniMessage.builder()
|
||||||
|
.removeDefaultTransformations()
|
||||||
|
.transformation(TransformationType.COLOR)
|
||||||
|
.transformation(TransformationType.DECORATION)
|
||||||
|
.transformation(TransformationType.GRADIENT)
|
||||||
|
.transformation(TransformationType.RESET)
|
||||||
|
.transformation(TransformationType.RAINBOW)
|
||||||
|
.transformation(TransformationType.PRE)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
public static boolean addToWhitelist(ConfigCache configCache, String command, String group) {
|
||||||
|
CWGroup cwGroup = configCache.getGroupList().get(group);
|
||||||
|
if (cwGroup == null) return false;
|
||||||
|
cwGroup.addCommand(command);
|
||||||
|
configCache.saveCWGroup(group, cwGroup);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean removeFromWhitelist(ConfigCache configCache, String command, String group) {
|
||||||
|
CWGroup cwGroup = configCache.getGroupList().get(group);
|
||||||
|
if (cwGroup == null)
|
||||||
|
return false;
|
||||||
|
cwGroup.removeCommand(command);
|
||||||
|
configCache.saveCWGroup(group, cwGroup);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Component helpComponent(String baseCommand, boolean showReloadCommand, boolean showAdminCommands) {
|
||||||
|
Component component = miniMessage.parse("<rainbow><bold>CommandWhitelist by YouHaveTrouble")
|
||||||
|
.append(Component.newline());
|
||||||
|
component = component.append(Component.text("/" + baseCommand + " help").color(NamedTextColor.AQUA).append(Component.text(" - Displays this message").color(NamedTextColor.BLUE)));
|
||||||
|
if (showReloadCommand) {
|
||||||
|
component = component.append(Component.newline());
|
||||||
|
component = component.append(Component.text("/" + baseCommand + " reload").color(NamedTextColor.AQUA).append(Component.text(" - Reloads plugin configuration").color(NamedTextColor.BLUE)));
|
||||||
|
}
|
||||||
|
if (showAdminCommands) {
|
||||||
|
component = component.append(Component.newline());
|
||||||
|
component = component.append(Component.text("/" + baseCommand + " add <group> <command>").color(NamedTextColor.AQUA).append(Component.text(" - Add a command to selected permission group").color(NamedTextColor.BLUE)));
|
||||||
|
component = component.append(Component.newline());
|
||||||
|
component = component.append(Component.text("/" + baseCommand + " remove <group> <command>").color(NamedTextColor.AQUA).append(Component.text(" - Removes a command from selected permission group").color(NamedTextColor.BLUE)));
|
||||||
|
}
|
||||||
|
return component;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum CommandType {
|
||||||
|
ADD, REMOVE, HELP, RELOAD
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> commandSuggestions(ConfigCache config, Collection<String> serverCommands, String[] args, boolean reloadPerm, boolean adminPerm) {
|
||||||
|
List<String> list = new ArrayList<>();
|
||||||
|
switch (args.length) {
|
||||||
|
case 0:
|
||||||
|
case 1:
|
||||||
|
if ("reload".startsWith(args[0]) && reloadPerm)
|
||||||
|
list.add("reload");
|
||||||
|
if ("add".startsWith(args[0]) && adminPerm)
|
||||||
|
list.add("add");
|
||||||
|
if ("remove".startsWith(args[0]) && adminPerm)
|
||||||
|
list.add("remove");
|
||||||
|
return list;
|
||||||
|
case 2:
|
||||||
|
if (args[0].equalsIgnoreCase("add") || args[0].equalsIgnoreCase("remove")) {
|
||||||
|
if (!adminPerm) return list;
|
||||||
|
for (String s : config.getGroupList().keySet()) {
|
||||||
|
if (s.startsWith(args[1]))
|
||||||
|
list.add(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
case 3:
|
||||||
|
if (args[0].equalsIgnoreCase("remove")) {
|
||||||
|
if (!adminPerm) return list;
|
||||||
|
CWGroup group = config.getGroupList().get(args[1]);
|
||||||
|
if (group == null) return list;
|
||||||
|
for (String s : group.getCommands()) {
|
||||||
|
if (s.startsWith(args[2]))
|
||||||
|
list.add(s);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
if (args[0].equalsIgnoreCase("add")) {
|
||||||
|
if (!adminPerm) return list;
|
||||||
|
CWGroup group = config.getGroupList().get(args[1]);
|
||||||
|
if (group == null) return list;
|
||||||
|
for (String cmd : serverCommands) {
|
||||||
|
if (cmd.startsWith("/"))
|
||||||
|
cmd = cmd.substring(1);
|
||||||
|
if (cmd.contains(":")) {
|
||||||
|
String[] cmdSplit = cmd.split(":");
|
||||||
|
if (cmdSplit.length < 2) continue;
|
||||||
|
cmd = cmdSplit[1];
|
||||||
|
}
|
||||||
|
if (group.getCommands().contains(cmd)) continue;
|
||||||
|
if (cmd.startsWith(args[2]))
|
||||||
|
list.add(cmd);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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,101 @@
|
|||||||
|
<?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>
|
||||||
|
<parent>
|
||||||
|
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||||
|
<artifactId>CommandWhitelist</artifactId>
|
||||||
|
<version>2.2.2</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>Velocity</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<name>CommandWhitelist-Velocity</name>
|
||||||
|
|
||||||
|
<description>You decide what commands players can use or tab complete on your server!</description>
|
||||||
|
<properties>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
<url>youhavetrouble.me</url>
|
||||||
|
|
||||||
|
<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.4</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
|
<finalName>${project.name}-${project.parent.version}</finalName>
|
||||||
|
<relocations>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.bstats</pattern>
|
||||||
|
<shadedPattern>eu.endermite.bstats</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
</relocations>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>velocitypowered-repo</id>
|
||||||
|
<url>https://repo.velocitypowered.com/releases/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>minecraft-libraries</id>
|
||||||
|
<url>https://libraries.minecraft.net/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>spongepowered-repo</id>
|
||||||
|
<url>https://repo.spongepowered.org/maven</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.velocitypowered</groupId>
|
||||||
|
<artifactId>velocity-api</artifactId>
|
||||||
|
<version>3.0.0</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||||
|
<artifactId>Common</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bstats</groupId>
|
||||||
|
<artifactId>bstats-velocity</artifactId>
|
||||||
|
<version>2.2.1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
+132
@@ -0,0 +1,132 @@
|
|||||||
|
package eu.endermite.commandwhitelist.velocity;
|
||||||
|
|
||||||
|
import com.velocitypowered.api.command.CommandMeta;
|
||||||
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
|
import com.velocitypowered.api.event.command.CommandExecuteEvent;
|
||||||
|
import com.velocitypowered.api.event.command.PlayerAvailableCommandsEvent;
|
||||||
|
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||||
|
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
|
import eu.endermite.commandwhitelist.common.CWGroup;
|
||||||
|
import eu.endermite.commandwhitelist.common.CWPermission;
|
||||||
|
import eu.endermite.commandwhitelist.common.ConfigCache;
|
||||||
|
import eu.endermite.commandwhitelist.common.commands.CWCommand;
|
||||||
|
import eu.endermite.commandwhitelist.velocity.command.VelocityMainCommand;
|
||||||
|
import net.kyori.adventure.identity.Identity;
|
||||||
|
import org.bstats.charts.SimplePie;
|
||||||
|
import org.bstats.velocity.Metrics;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class CommandWhitelistVelocity {
|
||||||
|
|
||||||
|
private static CommandWhitelistVelocity plugin;
|
||||||
|
private static ProxyServer server;
|
||||||
|
private static ConfigCache configCache;
|
||||||
|
private static Path folder;
|
||||||
|
private static Logger logger;
|
||||||
|
private final Metrics.Factory metricsFactory;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public CommandWhitelistVelocity(ProxyServer server, Logger logger, @DataDirectory final Path folder, Metrics.Factory metricsFactory) {
|
||||||
|
CommandWhitelistVelocity.server = server;
|
||||||
|
CommandWhitelistVelocity.folder = folder;
|
||||||
|
CommandWhitelistVelocity.plugin = this;
|
||||||
|
CommandWhitelistVelocity.logger = logger;
|
||||||
|
this.metricsFactory = metricsFactory;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void reloadConfig() {
|
||||||
|
if (configCache == null)
|
||||||
|
configCache = new ConfigCache(new File(String.valueOf(folder), "config.yml"), false, logger);
|
||||||
|
else
|
||||||
|
configCache.reloadConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void reloadConfig(CommandSource source) {
|
||||||
|
server.getScheduler().buildTask(plugin, () -> {
|
||||||
|
reloadConfig();
|
||||||
|
source.sendMessage(Identity.nil(), CWCommand.miniMessage.parse(getConfigCache().prefix + getConfigCache().config_reloaded));
|
||||||
|
}).schedule();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||||
|
reloadConfig();
|
||||||
|
CommandMeta commandMeta = server.getCommandManager().metaBuilder("vcw").build();
|
||||||
|
server.getCommandManager().register(commandMeta, new VelocityMainCommand());
|
||||||
|
Metrics metrics = metricsFactory.make(this, 8704);
|
||||||
|
metrics.addCustomChart(new SimplePie("proxy", () -> "Velocity"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onUserCommandSendEvent(PlayerAvailableCommandsEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||||
|
HashSet<String> allowedCommands = CommandWhitelistVelocity.getCommands(player);
|
||||||
|
event.getRootNode().getChildren().removeIf((commandNode) ->
|
||||||
|
server.getCommandManager().hasCommand(commandNode.getName())
|
||||||
|
&& !allowedCommands.contains(commandNode.getName())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onUserCommandExecuteEvent(com.velocitypowered.api.event.command.CommandExecuteEvent event) {
|
||||||
|
if (!(event.getCommandSource() instanceof Player)) return;
|
||||||
|
Player player = (Player) event.getCommandSource();
|
||||||
|
|
||||||
|
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||||
|
|
||||||
|
HashSet<String> allowedCommands = CommandWhitelistVelocity.getCommands(player);
|
||||||
|
String command = event.getCommand().split(" ")[0];
|
||||||
|
if (server.getCommandManager().hasCommand(command)
|
||||||
|
&& !allowedCommands.contains(command))
|
||||||
|
event.setResult(CommandExecuteEvent.CommandResult.forwardToServer());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConfigCache getConfigCache() {
|
||||||
|
return configCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param player Velocity Player
|
||||||
|
* @return commands available to the player
|
||||||
|
*/
|
||||||
|
public static HashSet<String> getCommands(Player player) {
|
||||||
|
HashMap<String, CWGroup> groups = configCache.getGroupList();
|
||||||
|
HashSet<String> commandList = new HashSet<>();
|
||||||
|
for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
|
||||||
|
CWGroup group = s.getValue();
|
||||||
|
if (s.getKey().equalsIgnoreCase("default"))
|
||||||
|
commandList.addAll(group.getCommands());
|
||||||
|
else if (player.hasPermission(group.getPermission()))
|
||||||
|
commandList.addAll(group.getCommands());
|
||||||
|
}
|
||||||
|
return commandList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param player Velocity Player
|
||||||
|
* @return subcommands unavailable for the player
|
||||||
|
*/
|
||||||
|
public static HashSet<String> getSuggestions(Player player, HashMap<String, CWGroup> groups) {
|
||||||
|
HashSet<String> suggestionList = new HashSet<>();
|
||||||
|
for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
|
||||||
|
if (s.getKey().equalsIgnoreCase("default"))
|
||||||
|
suggestionList.addAll(s.getValue().getSubCommands());
|
||||||
|
if (player.hasPermission(s.getValue().getPermission())) continue;
|
||||||
|
suggestionList.addAll(s.getValue().getSubCommands());
|
||||||
|
}
|
||||||
|
return suggestionList;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+83
@@ -0,0 +1,83 @@
|
|||||||
|
package eu.endermite.commandwhitelist.velocity.command;
|
||||||
|
|
||||||
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
|
import com.velocitypowered.api.command.SimpleCommand;
|
||||||
|
import eu.endermite.commandwhitelist.common.CWPermission;
|
||||||
|
import eu.endermite.commandwhitelist.common.commands.CWCommand;
|
||||||
|
import eu.endermite.commandwhitelist.velocity.CommandWhitelistVelocity;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
public class VelocityMainCommand implements SimpleCommand {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(final Invocation invocation) {
|
||||||
|
CommandSource sender = invocation.source();
|
||||||
|
String[] args = invocation.arguments();
|
||||||
|
String label = invocation.alias();
|
||||||
|
|
||||||
|
if (args.length == 0) {
|
||||||
|
sender.sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
CWCommand.CommandType commandType = CWCommand.CommandType.valueOf(args[0].toUpperCase());
|
||||||
|
switch (commandType) {
|
||||||
|
case RELOAD:
|
||||||
|
if (!sender.hasPermission(CWPermission.RELOAD.permission())) {
|
||||||
|
sender.sendMessage(CWCommand.miniMessage.parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().no_permission));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
CommandWhitelistVelocity.reloadConfig(sender);
|
||||||
|
return;
|
||||||
|
case ADD:
|
||||||
|
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
|
||||||
|
sender.sendMessage(CWCommand.miniMessage.parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().no_permission));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (args.length == 3) {
|
||||||
|
if (CWCommand.addToWhitelist(CommandWhitelistVelocity.getConfigCache(), args[2], args[1]))
|
||||||
|
sender.sendMessage(CWCommand.miniMessage.parse(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().added_to_whitelist, args[2], args[1])));
|
||||||
|
else
|
||||||
|
sender.sendMessage(CWCommand.miniMessage.parse(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().group_doesnt_exist, args[1])));
|
||||||
|
} else
|
||||||
|
sender.sendMessage(Component.text("/" + label + " add <group> <command>"));
|
||||||
|
return;
|
||||||
|
case REMOVE:
|
||||||
|
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
|
||||||
|
sender.sendMessage(CWCommand.miniMessage.parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().no_permission));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (args.length == 3) {
|
||||||
|
if (CWCommand.removeFromWhitelist(CommandWhitelistVelocity.getConfigCache(), args[2], args[1]))
|
||||||
|
sender.sendMessage(CWCommand.miniMessage.parse(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().removed_from_whitelist, args[2], args[1])));
|
||||||
|
else
|
||||||
|
sender.sendMessage(CWCommand.miniMessage.parse(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().group_doesnt_exist, args[1])));
|
||||||
|
} else
|
||||||
|
sender.sendMessage(Component.text("/" + label + " remove <group> <command>"));
|
||||||
|
return;
|
||||||
|
case HELP:
|
||||||
|
default:
|
||||||
|
sender.sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
sender.sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<List<String>> suggestAsync(Invocation invocation) {
|
||||||
|
CommandSource source = invocation.source();
|
||||||
|
String[] args = invocation.arguments();
|
||||||
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
|
List<String> serverCommands = new ArrayList<>();
|
||||||
|
return CWCommand.commandSuggestions(CommandWhitelistVelocity.getConfigCache(), serverCommands, args, source.hasPermission(CWPermission.RELOAD.permission()), source.hasPermission(CWPermission.ADMIN.permission()));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"id": "commandwhitelist",
|
||||||
|
"name": "CommandWhitelist",
|
||||||
|
"version": "${project.version}",
|
||||||
|
"description": "You decide what commands players can use or tab complete on your server!",
|
||||||
|
"authors": ["YouHaveTrouble"],
|
||||||
|
"dependencies": [],
|
||||||
|
"main": "eu.endermite.commandwhitelist.velocity.CommandWhitelistVelocity"
|
||||||
|
}
|
||||||
@@ -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,107 @@
|
|||||||
|
<?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>
|
||||||
|
<parent>
|
||||||
|
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||||
|
<artifactId>CommandWhitelist</artifactId>
|
||||||
|
<version>2.2.2</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>Waterfall</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<name>CommandWhitelist-Waterfall</name>
|
||||||
|
|
||||||
|
<description>You decide what commands players can use or tab complete on your server!</description>
|
||||||
|
<properties>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
<url>youhavetrouble.me</url>
|
||||||
|
|
||||||
|
<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.4</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
|
<finalName>${project.name}-${project.parent.version}</finalName>
|
||||||
|
<relocations>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.bstats</pattern>
|
||||||
|
<shadedPattern>eu.endermite.bstats</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>net.kyori</pattern>
|
||||||
|
<shadedPattern>eu.endermite</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
</relocations>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>sonatype</id>
|
||||||
|
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>papermc</id>
|
||||||
|
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||||
|
<artifactId>Common</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.github.waterfallmc</groupId>
|
||||||
|
<artifactId>waterfall-api</artifactId>
|
||||||
|
<version>1.17-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.kyori</groupId>
|
||||||
|
<artifactId>adventure-platform-bungeecord</artifactId>
|
||||||
|
<version>4.0.0-SNAPSHOT</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bstats</groupId>
|
||||||
|
<artifactId>bstats-bungeecord</artifactId>
|
||||||
|
<version>2.2.1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
+125
@@ -0,0 +1,125 @@
|
|||||||
|
package eu.endermite.commandwhitelist.waterfall;
|
||||||
|
|
||||||
|
import eu.endermite.commandwhitelist.common.CWGroup;
|
||||||
|
import eu.endermite.commandwhitelist.common.ConfigCache;
|
||||||
|
import eu.endermite.commandwhitelist.common.commands.CWCommand;
|
||||||
|
import eu.endermite.commandwhitelist.waterfall.command.BungeeMainCommand;
|
||||||
|
import eu.endermite.commandwhitelist.waterfall.listeners.BungeeChatEventListener;
|
||||||
|
import eu.endermite.commandwhitelist.waterfall.listeners.BungeeTabcompleteListener;
|
||||||
|
import eu.endermite.commandwhitelist.waterfall.listeners.WaterfallDefineCommandsListener;
|
||||||
|
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
import org.bstats.bungeecord.Metrics;
|
||||||
|
import org.bstats.charts.SimplePie;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public final class CommandWhitelistWaterfall extends Plugin {
|
||||||
|
|
||||||
|
private static CommandWhitelistWaterfall plugin;
|
||||||
|
private static ConfigCache configCache;
|
||||||
|
private static BungeeAudiences audiences;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
plugin = this;
|
||||||
|
getLogger().info("Running on " + ChatColor.DARK_AQUA + getProxy().getName());
|
||||||
|
loadConfig();
|
||||||
|
audiences = BungeeAudiences.create(this);
|
||||||
|
Metrics metrics = new Metrics(this, 8704);
|
||||||
|
|
||||||
|
this.getProxy().getPluginManager().registerListener(this, new BungeeChatEventListener());
|
||||||
|
try {
|
||||||
|
Class.forName("io.github.waterfallmc.waterfall.event.ProxyDefineCommandsEvent");
|
||||||
|
metrics.addCustomChart(new SimplePie("proxy", () -> "Waterfall"));
|
||||||
|
this.getProxy().getPluginManager().registerListener(this, new WaterfallDefineCommandsListener());
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
metrics.addCustomChart(new SimplePie("proxy", () -> "Bungee"));
|
||||||
|
getLogger().severe("Bungee command completion blocker requires Waterfall other Waterfall fork.");
|
||||||
|
}
|
||||||
|
this.getProxy().getPluginManager().registerListener(this, new BungeeTabcompleteListener());
|
||||||
|
getProxy().getPluginManager().registerCommand(this, new BungeeMainCommand("bcw"));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CommandWhitelistWaterfall getPlugin() {
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConfigCache getConfigCache() {
|
||||||
|
return configCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BungeeAudiences getAudiences() {
|
||||||
|
return audiences;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadConfig() {
|
||||||
|
if (configCache == null)
|
||||||
|
configCache = new ConfigCache(new File(getDataFolder(), "config.yml"), false, getLogger());
|
||||||
|
else
|
||||||
|
configCache.reloadConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadConfigAsync(CommandSender sender) {
|
||||||
|
getProxy().getScheduler().runAsync(this, () -> {
|
||||||
|
loadConfig();
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(CommandWhitelistWaterfall.getConfigCache().prefix + CommandWhitelistWaterfall.getConfigCache().config_reloaded));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param player Bungee Player
|
||||||
|
* @return commands available to the player
|
||||||
|
*/
|
||||||
|
public static HashSet<String> getCommands(ProxiedPlayer player) {
|
||||||
|
HashSet<String> commandList = new HashSet<>();
|
||||||
|
HashMap<String, CWGroup> groups = configCache.getGroupList();
|
||||||
|
for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
|
||||||
|
if (s.getKey().equalsIgnoreCase("default"))
|
||||||
|
commandList.addAll(s.getValue().getCommands());
|
||||||
|
else if (player.hasPermission(s.getValue().getPermission()))
|
||||||
|
commandList.addAll(s.getValue().getCommands());
|
||||||
|
}
|
||||||
|
return commandList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param player Bungee Player
|
||||||
|
* @return subcommands unavailable for the player
|
||||||
|
*/
|
||||||
|
public static HashSet<String> getSuggestions(ProxiedPlayer player) {
|
||||||
|
HashMap<String, CWGroup> groups = configCache.getGroupList();
|
||||||
|
HashSet<String> suggestionList = new HashSet<>();
|
||||||
|
for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
|
||||||
|
if (s.getKey().equalsIgnoreCase("default"))
|
||||||
|
suggestionList.addAll(s.getValue().getSubCommands());
|
||||||
|
if (player.hasPermission(s.getValue().getPermission())) continue;
|
||||||
|
suggestionList.addAll(s.getValue().getSubCommands());
|
||||||
|
}
|
||||||
|
return suggestionList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Command denied message. Will use custom if command exists in any group.
|
||||||
|
*/
|
||||||
|
public static String getCommandDeniedMessage(String command) {
|
||||||
|
String commandDeniedMessage = configCache.command_denied;
|
||||||
|
HashMap<String, CWGroup> groups = configCache.getGroupList();
|
||||||
|
for (CWGroup group : groups.values()) {
|
||||||
|
if (group.getCommands().contains(command)) {
|
||||||
|
if (group.getCommandDeniedMessage() == null || group.getCommandDeniedMessage().isEmpty()) continue;
|
||||||
|
commandDeniedMessage = group.getCommandDeniedMessage();
|
||||||
|
break; // get first message we find
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return commandDeniedMessage;
|
||||||
|
}
|
||||||
|
}
|
||||||
+89
@@ -0,0 +1,89 @@
|
|||||||
|
package eu.endermite.commandwhitelist.waterfall.command;
|
||||||
|
|
||||||
|
import eu.endermite.commandwhitelist.common.CWPermission;
|
||||||
|
import eu.endermite.commandwhitelist.common.ConfigCache;
|
||||||
|
import eu.endermite.commandwhitelist.common.commands.CWCommand;
|
||||||
|
import eu.endermite.commandwhitelist.waterfall.CommandWhitelistWaterfall;
|
||||||
|
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import net.md_5.bungee.api.plugin.Command;
|
||||||
|
import net.md_5.bungee.api.plugin.TabExecutor;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class BungeeMainCommand extends Command implements TabExecutor {
|
||||||
|
|
||||||
|
public BungeeMainCommand(String name) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void execute(CommandSender sender, String[] args) {
|
||||||
|
|
||||||
|
String label = getName();
|
||||||
|
ConfigCache configCache = CommandWhitelistWaterfall.getConfigCache();
|
||||||
|
BungeeAudiences audiences = CommandWhitelistWaterfall.getAudiences();
|
||||||
|
|
||||||
|
if (args.length == 0) {
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
CWCommand.CommandType commandType = CWCommand.CommandType.valueOf(args[0].toUpperCase());
|
||||||
|
switch (commandType) {
|
||||||
|
case RELOAD:
|
||||||
|
if (!sender.hasPermission(CWPermission.RELOAD.permission())) {
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(CommandWhitelistWaterfall.getConfigCache().prefix + configCache.no_permission));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
CommandWhitelistWaterfall.getPlugin().loadConfigAsync(sender);
|
||||||
|
return;
|
||||||
|
case ADD:
|
||||||
|
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + configCache.no_permission));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (args.length == 3) {
|
||||||
|
if (CWCommand.addToWhitelist(configCache, args[2], args[1]))
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + configCache.added_to_whitelist));
|
||||||
|
else
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + configCache.group_doesnt_exist));
|
||||||
|
} else
|
||||||
|
audiences.sender(sender).sendMessage(Component.text("/" + label + " add <group> <command>"));
|
||||||
|
return;
|
||||||
|
case REMOVE:
|
||||||
|
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + configCache.no_permission));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (args.length == 3) {
|
||||||
|
if (CWCommand.removeFromWhitelist(configCache, args[2], args[1]))
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + configCache.removed_from_whitelist));
|
||||||
|
else
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + configCache.group_doesnt_exist));
|
||||||
|
} else
|
||||||
|
audiences.sender(sender).sendMessage(Component.text("/" + label + " remove <group> <command>"));
|
||||||
|
return;
|
||||||
|
case HELP:
|
||||||
|
default:
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
|
||||||
|
List<String> serverCommands = new ArrayList<>();
|
||||||
|
for (Map.Entry<String, Command> command : CommandWhitelistWaterfall.getPlugin().getProxy().getPluginManager().getCommands()) {
|
||||||
|
serverCommands.add(command.getValue().getName());
|
||||||
|
}
|
||||||
|
return CWCommand.commandSuggestions(CommandWhitelistWaterfall.getConfigCache(), serverCommands, args, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission()));
|
||||||
|
}
|
||||||
|
}
|
||||||
+48
@@ -0,0 +1,48 @@
|
|||||||
|
package eu.endermite.commandwhitelist.waterfall.listeners;
|
||||||
|
|
||||||
|
import eu.endermite.commandwhitelist.common.CWPermission;
|
||||||
|
import eu.endermite.commandwhitelist.common.CommandUtil;
|
||||||
|
import eu.endermite.commandwhitelist.common.ConfigCache;
|
||||||
|
import eu.endermite.commandwhitelist.common.commands.CWCommand;
|
||||||
|
import eu.endermite.commandwhitelist.waterfall.CommandWhitelistWaterfall;
|
||||||
|
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
import net.md_5.bungee.api.plugin.Listener;
|
||||||
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
public class BungeeChatEventListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onChatEvent(net.md_5.bungee.api.event.ChatEvent event) {
|
||||||
|
if (event.isCancelled()) return;
|
||||||
|
if (!(event.getSender() instanceof ProxiedPlayer)) return;
|
||||||
|
if (!event.isProxyCommand()) return;
|
||||||
|
ProxiedPlayer player = (ProxiedPlayer) event.getSender();
|
||||||
|
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||||
|
|
||||||
|
String command = event.getMessage().toLowerCase();
|
||||||
|
if (command.startsWith("/"))
|
||||||
|
command = command.substring(1);
|
||||||
|
ConfigCache configCache = CommandWhitelistWaterfall.getConfigCache();
|
||||||
|
BungeeAudiences audiences = CommandWhitelistWaterfall.getAudiences();
|
||||||
|
|
||||||
|
String label = CommandUtil.getCommandLabel(command);
|
||||||
|
HashSet<String> commands = CommandWhitelistWaterfall.getCommands(player);
|
||||||
|
if (!commands.contains(label)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
CommandWhitelistWaterfall.getAudiences().player(player).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + CommandWhitelistWaterfall.getCommandDeniedMessage(label)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
HashSet<String> bannedSubCommands = CommandWhitelistWaterfall.getSuggestions(player);
|
||||||
|
for (String bannedSubCommand : bannedSubCommands) {
|
||||||
|
if (command.startsWith(bannedSubCommand)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
audiences.player(player).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + configCache.subcommand_denied));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+27
@@ -0,0 +1,27 @@
|
|||||||
|
package eu.endermite.commandwhitelist.waterfall.listeners;
|
||||||
|
|
||||||
|
import eu.endermite.commandwhitelist.common.CWPermission;
|
||||||
|
import eu.endermite.commandwhitelist.common.CommandUtil;
|
||||||
|
import eu.endermite.commandwhitelist.waterfall.CommandWhitelistWaterfall;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
import net.md_5.bungee.api.plugin.Listener;
|
||||||
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
|
||||||
|
public class BungeeTabcompleteListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onTabcomplete(net.md_5.bungee.api.event.TabCompleteEvent event) {
|
||||||
|
if (!(event.getReceiver() instanceof ProxiedPlayer)) return;
|
||||||
|
ProxiedPlayer player = (ProxiedPlayer) event.getReceiver();
|
||||||
|
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||||
|
|
||||||
|
CommandUtil.filterSuggestions(
|
||||||
|
event.getCursor(),
|
||||||
|
event.getSuggestions(),
|
||||||
|
CommandWhitelistWaterfall.getSuggestions(player)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+6
-6
@@ -1,7 +1,7 @@
|
|||||||
package eu.endermite.commandwhitelist.bungee.listeners;
|
package eu.endermite.commandwhitelist.waterfall.listeners;
|
||||||
|
|
||||||
import eu.endermite.commandwhitelist.api.CommandsList;
|
import eu.endermite.commandwhitelist.common.CWPermission;
|
||||||
import eu.endermite.commandwhitelist.bungee.CommandWhitelistBungee;
|
import eu.endermite.commandwhitelist.waterfall.CommandWhitelistWaterfall;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import net.md_5.bungee.api.plugin.Command;
|
import net.md_5.bungee.api.plugin.Command;
|
||||||
import net.md_5.bungee.api.plugin.Listener;
|
import net.md_5.bungee.api.plugin.Listener;
|
||||||
@@ -15,11 +15,11 @@ public class WaterfallDefineCommandsListener implements Listener {
|
|||||||
public void onProxyDefineCommandsEvent(io.github.waterfallmc.waterfall.event.ProxyDefineCommandsEvent event) {
|
public void onProxyDefineCommandsEvent(io.github.waterfallmc.waterfall.event.ProxyDefineCommandsEvent event) {
|
||||||
if (event.getReceiver() instanceof ProxiedPlayer) {
|
if (event.getReceiver() instanceof ProxiedPlayer) {
|
||||||
ProxiedPlayer player = (ProxiedPlayer) event.getReceiver();
|
ProxiedPlayer player = (ProxiedPlayer) event.getReceiver();
|
||||||
if (player.hasPermission("commandwhitelist.bypass"))
|
if (player.hasPermission(CWPermission.BYPASS.permission()))
|
||||||
return;
|
return;
|
||||||
HashMap<String, Command> commandHashMap = new HashMap<>();
|
HashMap<String, Command> commandHashMap = new HashMap<>();
|
||||||
CommandsList.getCommands(player).forEach(cmdName ->
|
CommandWhitelistWaterfall.getCommands(player).forEach(cmdName ->
|
||||||
CommandWhitelistBungee.getPlugin().getProxy().getPluginManager().getCommands()
|
CommandWhitelistWaterfall.getPlugin().getProxy().getPluginManager().getCommands()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(commandEntry -> cmdName.equalsIgnoreCase(commandEntry.getValue().getName()))
|
.filter(commandEntry -> cmdName.equalsIgnoreCase(commandEntry.getValue().getName()))
|
||||||
.forEach(commandEntry -> commandHashMap.put(commandEntry.getKey(), commandEntry.getValue())));
|
.forEach(commandEntry -> commandHashMap.put(commandEntry.getKey(), commandEntry.getValue())));
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
name: CommandWhitelist
|
||||||
|
version: ${project.version}
|
||||||
|
main: eu.endermite.commandwhitelist.waterfall.CommandWhitelistWaterfall
|
||||||
|
description: You decide what commands players can use or tab complete on your server!
|
||||||
@@ -4,10 +4,16 @@
|
|||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>eu.endermite</groupId>
|
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||||
<artifactId>CommandWhitelist</artifactId>
|
<artifactId>CommandWhitelist</artifactId>
|
||||||
<version>1.7.7</version>
|
<version>2.2.2</version>
|
||||||
<packaging>jar</packaging>
|
<modules>
|
||||||
|
<module>CommandWhitelistCommon</module>
|
||||||
|
<module>CommandWhitelistBukkit</module>
|
||||||
|
<module>CommandWhitelistVelocity</module>
|
||||||
|
<module>CommandWhitelistWaterfall</module>
|
||||||
|
</modules>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<name>CommandWhitelist</name>
|
<name>CommandWhitelist</name>
|
||||||
|
|
||||||
@@ -17,99 +23,25 @@
|
|||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.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.4</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>
|
<repositories>
|
||||||
<repository>
|
|
||||||
<id>spigotmc-repo</id>
|
|
||||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>sonatype</id>
|
<id>sonatype</id>
|
||||||
<url>https://oss.sonatype.org/content/groups/public/</url>
|
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
|
||||||
<id>jitpack.io</id>
|
|
||||||
<url>https://jitpack.io</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
|
||||||
<id>dmulloy2-repo</id>
|
|
||||||
<url>https://repo.dmulloy2.net/nexus/repository/public/</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
|
||||||
<id>papermc</id>
|
|
||||||
<url>https://papermc.io/repo/repository/maven-public/</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
|
||||||
<id>velocity</id>
|
|
||||||
<url>https://repo.velocitypowered.com/snapshots/</url>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>net.kyori</groupId>
|
||||||
<artifactId>spigot-api</artifactId>
|
<artifactId>adventure-api</artifactId>
|
||||||
<version>1.16.5-R0.1-SNAPSHOT</version>
|
<version>4.9.2</version>
|
||||||
<scope>provided</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.md-5</groupId>
|
<groupId>net.kyori</groupId>
|
||||||
<artifactId>bungeecord-api</artifactId>
|
<artifactId>adventure-text-minimessage</artifactId>
|
||||||
<version>1.15-SNAPSHOT</version>
|
<version>4.1.0-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.github.waterfallmc</groupId>
|
|
||||||
<artifactId>waterfall-api</artifactId>
|
|
||||||
<version>1.16-R0.4-SNAPSHOT</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.velocitypowered</groupId>
|
|
||||||
<artifactId>velocity-api</artifactId>
|
|
||||||
<version>1.1.0-SNAPSHOT</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.comphenix.protocol</groupId>
|
|
||||||
<artifactId>ProtocolLib</artifactId>
|
|
||||||
<version>4.6.0</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -1,20 +1,31 @@
|
|||||||
Command Whitelist is a plugin that allows you to control
|
Command Whitelist is a plugin that allows you to control
|
||||||
precisely what commands players can see and use.
|
precisely what commands players can see and use.
|
||||||
|
|
||||||
<img src="https://img.shields.io/bstats/servers/8705?label=Spigot%20servers%20using%20CommandWhitelist&style=for-the-badge">
|
[](https://www.codefactor.io/repository/github/youhavetrouble/commandwhitelist)
|
||||||
<img src="https://img.shields.io/bstats/servers/8704?label=Proxy%20servers%20using%20CommandWhitelist&style=for-the-badge">
|
[](https://github.com/YouHaveTrouble/CommandWhitelist/releases)
|
||||||
|
[](https://discord.gg/j8KK5dGBps)
|
||||||
|
[](https://www.spigotmc.org/resources/81326/)
|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
<h3>Plugin Features</h3>
|
<h3>Plugin Features</h3>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<li>You can lock certain commands behind permission
|
<li>Lock selected commands behind permission
|
||||||
<li>Overwrites default "no such command" message with your branding
|
<li>Overwrite default "no such command" message with your branding
|
||||||
<li>Blocks tab completion on spigot and bungeecord*</li>
|
<li>Block tab completion</li>
|
||||||
<li>Blocks command execution on spigot and bungeecord</li>
|
<li>Block command execution</li>
|
||||||
<li>Blocks completion and execution of specific subcommands (spigot only)</li>
|
<li>Block completion and execution of specified subcommands</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
\*This only works on Waterfall and its forks
|
<b>Compatible versions</b>: 1.13+
|
||||||
|
|
||||||
|
<b>Compatible software</b>:
|
||||||
|
- Bukkit-based servers (Spigot, Paper, Airplane, Purpur, etc)
|
||||||
|
- Waterfall (NOT Bungeecord!)
|
||||||
|
- Velocity
|
||||||
|
|
||||||
|
[Download latest release](https://github.com/YouHaveTrouble/CommandWhitelist/releases/latest)
|
||||||
|
|
||||||
Having some issues? Make sure to check out <a href="https://github.com/YouHaveTrouble/CommandWhitelist/wiki">Plugin Wiki</a>.
|
Having some issues? Make sure to check out <a href="https://github.com/YouHaveTrouble/CommandWhitelist/wiki">Plugin Wiki</a>.
|
||||||
|
|
||||||
|
|||||||
@@ -1,73 +0,0 @@
|
|||||||
package eu.endermite.commandwhitelist.api;
|
|
||||||
|
|
||||||
import eu.endermite.commandwhitelist.bungee.CommandWhitelistBungee;
|
|
||||||
import eu.endermite.commandwhitelist.spigot.CommandWhitelist;
|
|
||||||
import eu.endermite.commandwhitelist.velocity.CommandWhitelistVelocity;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class CommandsList {
|
|
||||||
|
|
||||||
public static List<String> getCommands(org.bukkit.entity.Player player) {
|
|
||||||
List<String> commandList = new ArrayList<>();
|
|
||||||
for (Map.Entry<String, List<String>> s : CommandWhitelist.getConfigCache().getPermList().entrySet()) {
|
|
||||||
if (s.getKey().equalsIgnoreCase("default"))
|
|
||||||
commandList.addAll(s.getValue());
|
|
||||||
else if (player.hasPermission("commandwhitelist.commands." + s.getKey()))
|
|
||||||
commandList.addAll(s.getValue());
|
|
||||||
}
|
|
||||||
return commandList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> getCommands(net.md_5.bungee.api.connection.ProxiedPlayer player) {
|
|
||||||
List<String> commandList = new ArrayList<>();
|
|
||||||
for (Map.Entry<String, List<String>> s : CommandWhitelistBungee.getConfigCache().getPermList().entrySet()) {
|
|
||||||
if (s.getKey().equalsIgnoreCase("default"))
|
|
||||||
commandList.addAll(s.getValue());
|
|
||||||
else if (player.hasPermission("commandwhitelist.commands." + s.getKey()))
|
|
||||||
commandList.addAll(s.getValue());
|
|
||||||
}
|
|
||||||
return commandList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> getCommands(com.velocitypowered.api.proxy.Player player) {
|
|
||||||
List<String> commandList = new ArrayList<>();
|
|
||||||
for (Map.Entry<String, List<String>> s : CommandWhitelistVelocity.getConfigCache().getPermList().entrySet()) {
|
|
||||||
if (s.getKey().equalsIgnoreCase("default"))
|
|
||||||
commandList.addAll(s.getValue());
|
|
||||||
else if (player.hasPermission("commandwhitelist.commands." + s.getKey()))
|
|
||||||
commandList.addAll(s.getValue());
|
|
||||||
}
|
|
||||||
return commandList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> getSuggestions(org.bukkit.entity.Player player) {
|
|
||||||
List<String> suggestionList = new ArrayList<>();
|
|
||||||
for (Map.Entry<String, List<String>> s : CommandWhitelist.getConfigCache().getPermSubList().entrySet()) {
|
|
||||||
if (player.hasPermission("commandwhitelist.subcommands." + s.getKey()))
|
|
||||||
continue;
|
|
||||||
suggestionList.addAll(s.getValue());
|
|
||||||
}
|
|
||||||
return suggestionList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getLastArgument(String cmd) {
|
|
||||||
String[] parts = cmd.split(" ");
|
|
||||||
if (parts.length <= 1)
|
|
||||||
return "";
|
|
||||||
String last = "";
|
|
||||||
for (String part : parts) {
|
|
||||||
last = part;
|
|
||||||
}
|
|
||||||
return last;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getCommandLabel(String cmd) {
|
|
||||||
String[] parts = cmd.split(" ");
|
|
||||||
if (parts[0].startsWith("/"))
|
|
||||||
parts[0] = parts[0].substring(1);
|
|
||||||
return parts[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
package eu.endermite.commandwhitelist.api;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class RandomStuff {
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param list List of strings to pick a random one from
|
|
||||||
* @param single String that will be used as fallback
|
|
||||||
* @return Randomized message
|
|
||||||
*/
|
|
||||||
|
|
||||||
public static String getMessage(List<String> list, String single) {
|
|
||||||
|
|
||||||
if (list == null || list.size() == 0) {
|
|
||||||
return single;
|
|
||||||
}
|
|
||||||
|
|
||||||
Random random = new Random();
|
|
||||||
int r = random.nextInt(list.size());
|
|
||||||
return list.get(r);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
package eu.endermite.commandwhitelist.bungee;
|
|
||||||
|
|
||||||
import com.google.common.io.ByteStreams;
|
|
||||||
import eu.endermite.commandwhitelist.bungee.command.BungeeMainCommand;
|
|
||||||
import eu.endermite.commandwhitelist.bungee.config.BungeeConfigCache;
|
|
||||||
import eu.endermite.commandwhitelist.bungee.listeners.BungeeChatEventListener;
|
|
||||||
import eu.endermite.commandwhitelist.bungee.listeners.WaterfallDefineCommandsListener;
|
|
||||||
import eu.endermite.commandwhitelist.bungee.metrics.BungeeMetrics;
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
import net.md_5.bungee.api.CommandSender;
|
|
||||||
import net.md_5.bungee.api.plugin.Plugin;
|
|
||||||
import net.md_5.bungee.config.Configuration;
|
|
||||||
import net.md_5.bungee.config.ConfigurationProvider;
|
|
||||||
import net.md_5.bungee.config.YamlConfiguration;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
|
|
||||||
public final class CommandWhitelistBungee extends Plugin {
|
|
||||||
|
|
||||||
private static CommandWhitelistBungee plugin;
|
|
||||||
private static BungeeConfigCache configCache;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onEnable() {
|
|
||||||
plugin = this;
|
|
||||||
getLogger().info("Running on "+ ChatColor.DARK_AQUA+getProxy().getName());
|
|
||||||
loadConfig();
|
|
||||||
this.getProxy().getPluginManager().registerListener(this, new BungeeChatEventListener());
|
|
||||||
try {
|
|
||||||
Class.forName("io.github.waterfallmc.waterfall.conf.WaterfallConfiguration");
|
|
||||||
this.getProxy().getPluginManager().registerListener(this, new WaterfallDefineCommandsListener());
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
getLogger().severe(ChatColor.DARK_RED+"Bungee tab completion blocker requires Waterfall other Waterfall fork.");
|
|
||||||
}
|
|
||||||
|
|
||||||
getProxy().getPluginManager().registerCommand(this, new BungeeMainCommand("bcw"));
|
|
||||||
|
|
||||||
int pluginId = 8704;
|
|
||||||
new BungeeMetrics(this, pluginId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CommandWhitelistBungee getPlugin() {
|
|
||||||
return plugin;
|
|
||||||
}
|
|
||||||
public static BungeeConfigCache getConfigCache() {
|
|
||||||
return configCache;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadConfig() {
|
|
||||||
try {
|
|
||||||
if (!getDataFolder().exists()) {
|
|
||||||
getDataFolder().mkdir();
|
|
||||||
}
|
|
||||||
|
|
||||||
File file = new File(getDataFolder(), "config.yml");
|
|
||||||
|
|
||||||
if (!file.exists()) {
|
|
||||||
file.createNewFile();
|
|
||||||
try (InputStream in = getResourceAsStream("bungeeconfig.yml");
|
|
||||||
OutputStream out = new FileOutputStream(file)) {
|
|
||||||
ByteStreams.copy(in, out);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final Configuration config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
|
|
||||||
ConfigurationProvider.getProvider(YamlConfiguration.class).save(config, new File(getDataFolder(), "config.yml"));
|
|
||||||
configCache = new BungeeConfigCache(config);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadConfigAsync(CommandSender sender) {
|
|
||||||
getProxy().getScheduler().runAsync(this, () -> {
|
|
||||||
loadConfig();
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelistBungee.getConfigCache().getPrefix() + CommandWhitelistBungee.getConfigCache().getConfigReloaded()));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,127 +0,0 @@
|
|||||||
package eu.endermite.commandwhitelist.bungee.command;
|
|
||||||
|
|
||||||
import eu.endermite.commandwhitelist.bungee.CommandWhitelistBungee;
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
import net.md_5.bungee.api.CommandSender;
|
|
||||||
import net.md_5.bungee.api.plugin.Command;
|
|
||||||
import net.md_5.bungee.api.plugin.TabExecutor;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class BungeeMainCommand extends Command implements TabExecutor {
|
|
||||||
|
|
||||||
public BungeeMainCommand(String name) {
|
|
||||||
super(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void execute(CommandSender sender, String[] args) {
|
|
||||||
if (args.length > 0) {
|
|
||||||
if (args[0].equalsIgnoreCase("reload")) {
|
|
||||||
if (sender.hasPermission("commandwhitelist.reload")) {
|
|
||||||
CommandWhitelistBungee.getPlugin().loadConfigAsync(sender);
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelistBungee.getConfigCache().getPrefix() + CommandWhitelistBungee.getConfigCache().getNoPermission()));
|
|
||||||
}
|
|
||||||
} else if (args[0].equalsIgnoreCase("add")) {
|
|
||||||
if (!sender.hasPermission("commandwhitelist.admin")) {
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelistBungee.getConfigCache().getPrefix() + CommandWhitelistBungee.getConfigCache().getNoPermission()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (args.length >= 3) {
|
|
||||||
if (CommandWhitelistBungee.getConfigCache().addCommand(args[2], args[1])) {
|
|
||||||
String msg = String.format(CommandWhitelistBungee.getConfigCache().getWhitelistedCommand(), args[2], args[1]);
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', msg));
|
|
||||||
} else {
|
|
||||||
String msg = CommandWhitelistBungee.getConfigCache().getNoSuchGroup();
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', msg));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sender.sendMessage("/bcw add <group> <command>");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
} else if (args[0].equalsIgnoreCase("remove")) {
|
|
||||||
|
|
||||||
if (!sender.hasPermission("commandwhitelist.admin")) {
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelistBungee.getConfigCache().getPrefix() + CommandWhitelistBungee.getConfigCache().getNoPermission()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (args.length >= 3) {
|
|
||||||
if (CommandWhitelistBungee.getConfigCache().removeCommand(args[2], args[1])) {
|
|
||||||
String msg = String.format(CommandWhitelistBungee.getConfigCache().getRemovedWhitelistedCommand(), args[2], args[1]);
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', msg));
|
|
||||||
} else {
|
|
||||||
String msg = CommandWhitelistBungee.getConfigCache().getNoSuchGroup();
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', msg));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sender.sendMessage("/bcw remove <group> <command>");
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelistBungee.getConfigCache().getPrefix() + CommandWhitelistBungee.getConfigCache().getNoSubCommand()));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&bCommand Whitelist by YouHaveTrouble"));
|
|
||||||
if (sender.hasPermission("commandwhitelist.reload")) {
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&9/bcw reload &b- Reload bungee plugin configuration"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
|
|
||||||
List<String> list = new ArrayList<>();
|
|
||||||
if (args.length == 1) {
|
|
||||||
if ("reload".startsWith(args[0]) && sender.hasPermission("commandwhitelist.reload")) {
|
|
||||||
list.add("reload");
|
|
||||||
}
|
|
||||||
if ("add".startsWith(args[0]) && sender.hasPermission("commandwhitelist.admin")) {
|
|
||||||
list.add("add");
|
|
||||||
}
|
|
||||||
if ("remove".startsWith(args[0]) && sender.hasPermission("commandwhitelist.admin")) {
|
|
||||||
list.add("remove");
|
|
||||||
}
|
|
||||||
} else if (args.length == 2) {
|
|
||||||
if (args[0].equalsIgnoreCase("add") || args[0].equalsIgnoreCase("remove")) {
|
|
||||||
if (!sender.hasPermission("commandwhitelist.admin"))
|
|
||||||
return list;
|
|
||||||
for (Map.Entry<String, List<String>> s : CommandWhitelistBungee.getConfigCache().getPermList().entrySet()) {
|
|
||||||
if (s.getKey().startsWith(args[1])) {
|
|
||||||
list.add(s.getKey());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (args.length == 3) {
|
|
||||||
if (args[0].equalsIgnoreCase("remove")) {
|
|
||||||
if (!sender.hasPermission("commandwhitelist.admin"))
|
|
||||||
return list;
|
|
||||||
try {
|
|
||||||
for (String s : CommandWhitelistBungee.getConfigCache().getPermList().get(args[1])) {
|
|
||||||
if (s.startsWith(args[2])) {
|
|
||||||
list.add(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (NullPointerException ignored) {
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
if (args[0].equalsIgnoreCase("add")) {
|
|
||||||
if (!sender.hasPermission("commandwhitelist.admin"))
|
|
||||||
return list;
|
|
||||||
|
|
||||||
for (Map.Entry<String, Command> command : CommandWhitelistBungee.getPlugin().getProxy().getPluginManager().getCommands()) {
|
|
||||||
if (command.getKey().startsWith("/"))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (CommandWhitelistBungee.getConfigCache().getPermList().get(args[1]).contains(command.getKey()))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (command.getKey().startsWith(args[2]))
|
|
||||||
list.add(command.getKey());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
package eu.endermite.commandwhitelist.bungee.config;
|
|
||||||
|
|
||||||
import eu.endermite.commandwhitelist.bungee.CommandWhitelistBungee;
|
|
||||||
import net.md_5.bungee.config.Configuration;
|
|
||||||
import net.md_5.bungee.config.ConfigurationProvider;
|
|
||||||
import net.md_5.bungee.config.YamlConfiguration;
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class BungeeConfigCache {
|
|
||||||
|
|
||||||
private final Configuration config;
|
|
||||||
private final HashMap<String, List<String>> permList = new HashMap<>();
|
|
||||||
private final String prefix, commandDenied, noPermission, noSubCommand, configReloaded, whitelistedCommand,
|
|
||||||
removedWhitelistedCommand, noSuchGroup;
|
|
||||||
private List<String> commandDeniedList;
|
|
||||||
|
|
||||||
public BungeeConfigCache(Configuration config) {
|
|
||||||
|
|
||||||
this.config = config;
|
|
||||||
|
|
||||||
prefix = config.getString("messages.prefix");
|
|
||||||
commandDenied = config.getString("messages.command-denied", null);
|
|
||||||
commandDeniedList = config.getStringList("messages.command-denied");
|
|
||||||
noPermission = config.getString("messages.no-permission");
|
|
||||||
noSubCommand = config.getString("messages.no-such-subcommand");
|
|
||||||
configReloaded = config.getString("messages.config-reloaded");
|
|
||||||
whitelistedCommand = config.getString("messages.added-to-whitelist", "&eWhitelisted command &6%s &efor permission &6%s");
|
|
||||||
removedWhitelistedCommand = config.getString("messages.removed-from-whitelist", "&eRemoved command &6%s &efrom permission &6%s");
|
|
||||||
noSuchGroup = config.getString("messages.group-doesnt-exist", "&cGroup %s doesn't exist");
|
|
||||||
|
|
||||||
Collection<String> perms = config.getSection("commands").getKeys();
|
|
||||||
for (String s : perms) {
|
|
||||||
this.permList.put(s, config.getStringList("commands."+s));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashMap<String, List<String>> getPermList() {
|
|
||||||
return permList;
|
|
||||||
}
|
|
||||||
public boolean addCommand(String command, String group) {
|
|
||||||
try {
|
|
||||||
this.permList.get(group).add(command);
|
|
||||||
this.config.set("commands."+group, permList.get(group));
|
|
||||||
ConfigurationProvider.getProvider(YamlConfiguration.class).save(config, new File(CommandWhitelistBungee.getPlugin().getDataFolder(), "config.yml"));
|
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public boolean removeCommand(String command, String group) {
|
|
||||||
try {
|
|
||||||
this.permList.get(group).remove(command);
|
|
||||||
this.config.set("commands."+group, permList.get(group));
|
|
||||||
ConfigurationProvider.getProvider(YamlConfiguration.class).save(config, new File(CommandWhitelistBungee.getPlugin().getDataFolder(), "config.yml"));
|
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public String getPrefix() {return prefix;}
|
|
||||||
public String getCommandDenied() {return commandDenied;}
|
|
||||||
public List<String> getCommandDeniedList() {
|
|
||||||
return commandDeniedList;
|
|
||||||
}
|
|
||||||
public String getNoPermission() {return noPermission;}
|
|
||||||
public String getNoSubCommand() {return noSubCommand;}
|
|
||||||
public String getConfigReloaded() {return configReloaded;}
|
|
||||||
public String getWhitelistedCommand() {
|
|
||||||
return whitelistedCommand;
|
|
||||||
}
|
|
||||||
public String getRemovedWhitelistedCommand() {
|
|
||||||
return removedWhitelistedCommand;
|
|
||||||
}
|
|
||||||
public String getNoSuchGroup() {
|
|
||||||
return noSuchGroup;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-48
@@ -1,48 +0,0 @@
|
|||||||
package eu.endermite.commandwhitelist.bungee.listeners;
|
|
||||||
|
|
||||||
import eu.endermite.commandwhitelist.api.RandomStuff;
|
|
||||||
import eu.endermite.commandwhitelist.bungee.CommandWhitelistBungee;
|
|
||||||
import eu.endermite.commandwhitelist.bungee.config.BungeeConfigCache;
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.api.plugin.Listener;
|
|
||||||
import net.md_5.bungee.event.EventHandler;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class BungeeChatEventListener implements Listener {
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onChatEvent(net.md_5.bungee.api.event.ChatEvent event) {
|
|
||||||
if (event.isCancelled())
|
|
||||||
return;
|
|
||||||
if (!(event.getSender() instanceof ProxiedPlayer))
|
|
||||||
return;
|
|
||||||
if (!event.isProxyCommand())
|
|
||||||
return;
|
|
||||||
ProxiedPlayer player = (ProxiedPlayer) event.getSender();
|
|
||||||
if (player.hasPermission("commandwhitelist.bypass"))
|
|
||||||
return;
|
|
||||||
String command = event.getMessage().toLowerCase();
|
|
||||||
boolean found = false;
|
|
||||||
for (Map.Entry<String, List<String>> s : CommandWhitelistBungee.getConfigCache().getPermList().entrySet()) {
|
|
||||||
if (!player.hasPermission("commandwhitelist.commands." + s.getKey()))
|
|
||||||
continue;
|
|
||||||
for (String comm : s.getValue()) {
|
|
||||||
comm = comm.toLowerCase();
|
|
||||||
if (command.equalsIgnoreCase("/" + comm)) {
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
} else if (command.startsWith("/" + comm + " ")) {
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!found) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
BungeeConfigCache config = CommandWhitelistBungee.getConfigCache();
|
|
||||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelistBungee.getConfigCache().getPrefix() + RandomStuff.getMessage(config.getCommandDeniedList(), config.getCommandDenied())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,394 +0,0 @@
|
|||||||
package eu.endermite.commandwhitelist.bungee.metrics;
|
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import net.md_5.bungee.api.plugin.Plugin;
|
|
||||||
import net.md_5.bungee.config.Configuration;
|
|
||||||
import net.md_5.bungee.config.ConfigurationProvider;
|
|
||||||
import net.md_5.bungee.config.YamlConfiguration;
|
|
||||||
|
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
|
||||||
import java.io.*;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.zip.GZIPOutputStream;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* bStats collects some data for plugin authors.
|
|
||||||
* <p>
|
|
||||||
* Check out https://bStats.org/ to learn more about bStats!
|
|
||||||
*/
|
|
||||||
@SuppressWarnings({"WeakerAccess", "unused"})
|
|
||||||
public class BungeeMetrics {
|
|
||||||
|
|
||||||
static {
|
|
||||||
// You can use the property to disable the check in your test environment
|
|
||||||
if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) {
|
|
||||||
// Maven's Relocate is clever and changes strings, too. So we have to use this little "trick" ... :D
|
|
||||||
final String defaultPackage = new String(
|
|
||||||
new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'n', 'g', 'e', 'e', 'c', 'o', 'r', 'd'});
|
|
||||||
final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
|
|
||||||
// We want to make sure nobody just copy & pastes the example and use the wrong package names
|
|
||||||
if (BungeeMetrics.class.getPackage().getName().equals(defaultPackage) || BungeeMetrics.class.getPackage().getName().equals(examplePackage)) {
|
|
||||||
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// The version of this bStats class
|
|
||||||
public static final int B_STATS_VERSION = 1;
|
|
||||||
|
|
||||||
// The url to which the data is sent
|
|
||||||
private static final String URL = "https://bStats.org/submitData/bungeecord";
|
|
||||||
|
|
||||||
// The plugin
|
|
||||||
private final Plugin plugin;
|
|
||||||
|
|
||||||
// The plugin id
|
|
||||||
private final int pluginId;
|
|
||||||
|
|
||||||
// Is bStats enabled on this server?
|
|
||||||
private boolean enabled;
|
|
||||||
|
|
||||||
// The uuid of the server
|
|
||||||
private String serverUUID;
|
|
||||||
|
|
||||||
// Should failed requests be logged?
|
|
||||||
private boolean logFailedRequests = false;
|
|
||||||
|
|
||||||
// Should the sent data be logged?
|
|
||||||
private static boolean logSentData;
|
|
||||||
|
|
||||||
// Should the response text be logged?
|
|
||||||
private static boolean logResponseStatusText;
|
|
||||||
|
|
||||||
// A list with all known metrics class objects including this one
|
|
||||||
private static final List<Object> knownMetricsInstances = new ArrayList<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class constructor.
|
|
||||||
*
|
|
||||||
* @param plugin The plugin which stats should be submitted.
|
|
||||||
* @param pluginId The id of the plugin.
|
|
||||||
* It can be found at <a href="https://bstats.org/what-is-my-plugin-id">What is my plugin id?</a>
|
|
||||||
*/
|
|
||||||
public BungeeMetrics(Plugin plugin, int pluginId) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
this.pluginId = pluginId;
|
|
||||||
|
|
||||||
try {
|
|
||||||
loadConfig();
|
|
||||||
} catch (IOException e) {
|
|
||||||
// Failed to load configuration
|
|
||||||
plugin.getLogger().log(Level.WARNING, "Failed to load bStats config!", e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We are not allowed to send data about this server :(
|
|
||||||
if (!enabled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Class<?> usedMetricsClass = getFirstBStatsClass();
|
|
||||||
if (usedMetricsClass == null) {
|
|
||||||
// Failed to get first metrics class
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (usedMetricsClass == getClass()) {
|
|
||||||
// We are the first! :)
|
|
||||||
linkMetrics(this);
|
|
||||||
startSubmitting();
|
|
||||||
} else {
|
|
||||||
// We aren't the first so we link to the first metrics class
|
|
||||||
try {
|
|
||||||
usedMetricsClass.getMethod("linkMetrics", Object.class).invoke(null, this);
|
|
||||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
|
||||||
if (logFailedRequests) {
|
|
||||||
plugin.getLogger().log(Level.WARNING, "Failed to link to first metrics class " + usedMetricsClass.getName() + "!", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if bStats is enabled.
|
|
||||||
*
|
|
||||||
* @return Whether bStats is enabled or not.
|
|
||||||
*/
|
|
||||||
public boolean isEnabled() {
|
|
||||||
return enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Links an other metrics class with this class.
|
|
||||||
* This method is called using Reflection.
|
|
||||||
*
|
|
||||||
* @param metrics An object of the metrics class to link.
|
|
||||||
*/
|
|
||||||
public static void linkMetrics(Object metrics) {
|
|
||||||
knownMetricsInstances.add(metrics);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the plugin specific data.
|
|
||||||
* This method is called using Reflection.
|
|
||||||
*
|
|
||||||
* @return The plugin specific data.
|
|
||||||
*/
|
|
||||||
public JsonObject getPluginData() {
|
|
||||||
JsonObject data = new JsonObject();
|
|
||||||
|
|
||||||
String pluginName = plugin.getDescription().getName();
|
|
||||||
String pluginVersion = plugin.getDescription().getVersion();
|
|
||||||
|
|
||||||
data.addProperty("pluginName", pluginName);
|
|
||||||
data.addProperty("id", pluginId);
|
|
||||||
data.addProperty("pluginVersion", pluginVersion);
|
|
||||||
|
|
||||||
JsonArray customCharts = new JsonArray();
|
|
||||||
data.add("customCharts", customCharts);
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void startSubmitting() {
|
|
||||||
// The data collection is async, as well as sending the data
|
|
||||||
// Bungeecord does not have a main thread, everything is async
|
|
||||||
plugin.getProxy().getScheduler().schedule(plugin, this::submitData, 2, 30, TimeUnit.MINUTES);
|
|
||||||
// Submit the data every 30 minutes, first time after 2 minutes to give other plugins enough time to start
|
|
||||||
// WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted!
|
|
||||||
// WARNING: Just don't do it!
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the server specific data.
|
|
||||||
*
|
|
||||||
* @return The server specific data.
|
|
||||||
*/
|
|
||||||
private JsonObject getServerData() {
|
|
||||||
// Minecraft specific data
|
|
||||||
int playerAmount = Math.min(plugin.getProxy().getOnlineCount(), 500);
|
|
||||||
int onlineMode = plugin.getProxy().getConfig().isOnlineMode() ? 1 : 0;
|
|
||||||
String bungeecordVersion = plugin.getProxy().getVersion();
|
|
||||||
int managedServers = plugin.getProxy().getServers().size();
|
|
||||||
|
|
||||||
// OS/Java specific data
|
|
||||||
String javaVersion = System.getProperty("java.version");
|
|
||||||
String osName = System.getProperty("os.name");
|
|
||||||
String osArch = System.getProperty("os.arch");
|
|
||||||
String osVersion = System.getProperty("os.version");
|
|
||||||
int coreCount = Runtime.getRuntime().availableProcessors();
|
|
||||||
|
|
||||||
JsonObject data = new JsonObject();
|
|
||||||
|
|
||||||
data.addProperty("serverUUID", serverUUID);
|
|
||||||
|
|
||||||
data.addProperty("playerAmount", playerAmount);
|
|
||||||
data.addProperty("managedServers", managedServers);
|
|
||||||
data.addProperty("onlineMode", onlineMode);
|
|
||||||
data.addProperty("bungeecordVersion", bungeecordVersion);
|
|
||||||
|
|
||||||
data.addProperty("javaVersion", javaVersion);
|
|
||||||
data.addProperty("osName", osName);
|
|
||||||
data.addProperty("osArch", osArch);
|
|
||||||
data.addProperty("osVersion", osVersion);
|
|
||||||
data.addProperty("coreCount", coreCount);
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Collects the data and sends it afterwards.
|
|
||||||
*/
|
|
||||||
private void submitData() {
|
|
||||||
final JsonObject data = getServerData();
|
|
||||||
|
|
||||||
final JsonArray pluginData = new JsonArray();
|
|
||||||
// Search for all other bStats Metrics classes to get their plugin data
|
|
||||||
for (Object metrics : knownMetricsInstances) {
|
|
||||||
try {
|
|
||||||
Object plugin = metrics.getClass().getMethod("getPluginData").invoke(metrics);
|
|
||||||
if (plugin instanceof JsonObject) {
|
|
||||||
pluginData.add((JsonObject) plugin);
|
|
||||||
}
|
|
||||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { }
|
|
||||||
}
|
|
||||||
|
|
||||||
data.add("plugins", pluginData);
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Send the data
|
|
||||||
sendData(plugin, data);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// Something went wrong! :(
|
|
||||||
if (logFailedRequests) {
|
|
||||||
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats!", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads the bStats configuration.
|
|
||||||
*
|
|
||||||
* @throws IOException If something did not work :(
|
|
||||||
*/
|
|
||||||
private void loadConfig() throws IOException {
|
|
||||||
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
|
|
||||||
bStatsFolder.mkdirs();
|
|
||||||
File configFile = new File(bStatsFolder, "config.yml");
|
|
||||||
if (!configFile.exists()) {
|
|
||||||
writeFile(configFile,
|
|
||||||
"#bStats collects some data for plugin authors like how many servers are using their plugins.",
|
|
||||||
"#To honor their work, you should not disable it.",
|
|
||||||
"#This has nearly no effect on the server performance!",
|
|
||||||
"#Check out https://bStats.org/ to learn more :)",
|
|
||||||
"enabled: true",
|
|
||||||
"serverUuid: \"" + UUID.randomUUID() + "\"",
|
|
||||||
"logFailedRequests: false",
|
|
||||||
"logSentData: false",
|
|
||||||
"logResponseStatusText: false");
|
|
||||||
}
|
|
||||||
|
|
||||||
Configuration configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
|
|
||||||
|
|
||||||
// Load configuration
|
|
||||||
enabled = configuration.getBoolean("enabled", true);
|
|
||||||
serverUUID = configuration.getString("serverUuid");
|
|
||||||
logFailedRequests = configuration.getBoolean("logFailedRequests", false);
|
|
||||||
logSentData = configuration.getBoolean("logSentData", false);
|
|
||||||
logResponseStatusText = configuration.getBoolean("logResponseStatusText", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the first bStat Metrics class.
|
|
||||||
*
|
|
||||||
* @return The first bStats metrics class.
|
|
||||||
*/
|
|
||||||
private Class<?> getFirstBStatsClass() {
|
|
||||||
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
|
|
||||||
bStatsFolder.mkdirs();
|
|
||||||
File tempFile = new File(bStatsFolder, "temp.txt");
|
|
||||||
|
|
||||||
try {
|
|
||||||
String className = readFile(tempFile);
|
|
||||||
if (className != null) {
|
|
||||||
try {
|
|
||||||
// Let's check if a class with the given name exists.
|
|
||||||
return Class.forName(className);
|
|
||||||
} catch (ClassNotFoundException ignored) { }
|
|
||||||
}
|
|
||||||
writeFile(tempFile, getClass().getName());
|
|
||||||
return getClass();
|
|
||||||
} catch (IOException e) {
|
|
||||||
if (logFailedRequests) {
|
|
||||||
plugin.getLogger().log(Level.WARNING, "Failed to get first bStats class!", e);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads the first line of the file.
|
|
||||||
*
|
|
||||||
* @param file The file to read. Cannot be null.
|
|
||||||
* @return The first line of the file or {@code null} if the file does not exist or is empty.
|
|
||||||
* @throws IOException If something did not work :(
|
|
||||||
*/
|
|
||||||
private String readFile(File file) throws IOException {
|
|
||||||
if (!file.exists()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) {
|
|
||||||
return bufferedReader.readLine();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes a String to a file. It also adds a note for the user,
|
|
||||||
*
|
|
||||||
* @param file The file to write to. Cannot be null.
|
|
||||||
* @param lines The lines to write.
|
|
||||||
* @throws IOException If something did not work :(
|
|
||||||
*/
|
|
||||||
private void writeFile(File file, String... lines) throws IOException {
|
|
||||||
try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file))) {
|
|
||||||
for (String line : lines) {
|
|
||||||
bufferedWriter.write(line);
|
|
||||||
bufferedWriter.newLine();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends the data to the bStats server.
|
|
||||||
*
|
|
||||||
* @param plugin Any plugin. It's just used to get a logger instance.
|
|
||||||
* @param data The data to send.
|
|
||||||
* @throws Exception If the request failed.
|
|
||||||
*/
|
|
||||||
private static void sendData(Plugin plugin, JsonObject data) throws Exception {
|
|
||||||
if (data == null) {
|
|
||||||
throw new IllegalArgumentException("Data cannot be null");
|
|
||||||
}
|
|
||||||
if (logSentData) {
|
|
||||||
plugin.getLogger().info("Sending data to bStats: " + data);
|
|
||||||
}
|
|
||||||
|
|
||||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
|
|
||||||
|
|
||||||
// Compress the data to save bandwidth
|
|
||||||
byte[] compressedData = compress(data.toString());
|
|
||||||
|
|
||||||
// Add headers
|
|
||||||
connection.setRequestMethod("POST");
|
|
||||||
connection.addRequestProperty("Accept", "application/json");
|
|
||||||
connection.addRequestProperty("Connection", "close");
|
|
||||||
connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
|
|
||||||
connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
|
|
||||||
connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
|
|
||||||
connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
|
|
||||||
|
|
||||||
// Send data
|
|
||||||
connection.setDoOutput(true);
|
|
||||||
try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
|
|
||||||
outputStream.write(compressedData);
|
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
|
||||||
String line;
|
|
||||||
while ((line = bufferedReader.readLine()) != null) {
|
|
||||||
builder.append(line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (logResponseStatusText) {
|
|
||||||
plugin.getLogger().info("Sent data to bStats and received response: " + builder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gzips the given String.
|
|
||||||
*
|
|
||||||
* @param str The string to gzip.
|
|
||||||
* @return The gzipped String.
|
|
||||||
* @throws IOException If the compression failed.
|
|
||||||
*/
|
|
||||||
private static byte[] compress(final String str) throws IOException {
|
|
||||||
if (str == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
||||||
try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) {
|
|
||||||
gzip.write(str.getBytes(StandardCharsets.UTF_8));
|
|
||||||
}
|
|
||||||
return outputStream.toByteArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,100 +0,0 @@
|
|||||||
package eu.endermite.commandwhitelist.spigot;
|
|
||||||
|
|
||||||
import eu.endermite.commandwhitelist.spigot.command.MainCommand;
|
|
||||||
import eu.endermite.commandwhitelist.spigot.config.ConfigCache;
|
|
||||||
import eu.endermite.commandwhitelist.spigot.listeners.*;
|
|
||||||
import eu.endermite.commandwhitelist.spigot.metrics.BukkitMetrics;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
public class CommandWhitelist extends JavaPlugin {
|
|
||||||
|
|
||||||
private static CommandWhitelist commandWhitelist;
|
|
||||||
private static ConfigCache configCache;
|
|
||||||
private static boolean isLegacy;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onEnable() {
|
|
||||||
|
|
||||||
commandWhitelist = this;
|
|
||||||
|
|
||||||
isLegacy = checkLegacy();
|
|
||||||
|
|
||||||
reloadPluginConfig();
|
|
||||||
|
|
||||||
Plugin protocollib = getServer().getPluginManager().getPlugin("ProtocolLib");
|
|
||||||
|
|
||||||
getServer().getPluginManager().registerEvents(new PlayerCommandPreProcessListener(), this);
|
|
||||||
if (!isLegacy) {
|
|
||||||
if (!getConfigCache().isUseProtocolLib() || protocollib == null || !protocollib.isEnabled()) {
|
|
||||||
|
|
||||||
getServer().getPluginManager().registerEvents(new PlayerCommandSendListener(), this);
|
|
||||||
} else {
|
|
||||||
PacketCommandSendListener.protocol(this);
|
|
||||||
getLogger().info(ChatColor.AQUA+"Using ProtocolLib for command filter!");
|
|
||||||
}
|
|
||||||
getServer().getPluginManager().registerEvents(new TabCompleteBlockerListener(), this);
|
|
||||||
} else {
|
|
||||||
getLogger().info(ChatColor.AQUA+"Running in legacy mode...");
|
|
||||||
if (protocollib != null) {
|
|
||||||
LegacyPlayerTabChatCompleteListener.protocol(this);
|
|
||||||
} else {
|
|
||||||
getLogger().info(ChatColor.YELLOW+"ProtocolLib is required for tab completion blocking!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getCommand("commandwhitelist").setExecutor(new MainCommand());
|
|
||||||
getCommand("commandwhitelist").setTabCompleter(new MainCommand());
|
|
||||||
|
|
||||||
int pluginId = 8705;
|
|
||||||
new BukkitMetrics(this, pluginId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reloadPluginConfig() {
|
|
||||||
saveDefaultConfig();
|
|
||||||
reloadConfig();
|
|
||||||
configCache = new ConfigCache(getConfig());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reloadPluginConfig(CommandSender sender) {
|
|
||||||
getServer().getScheduler().runTaskAsynchronously(this, () -> {
|
|
||||||
reloadPluginConfig();
|
|
||||||
if (!isLegacy()) {
|
|
||||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
|
||||||
p.updateCommands();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().getPrefix() + CommandWhitelist.getConfigCache().getConfigReloaded()));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isLegacy() {
|
|
||||||
return isLegacy;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean checkLegacy() {
|
|
||||||
|
|
||||||
String version = Bukkit.getServer().getClass().getPackage().getName().replace("org.bukkit.craftbukkit", "").replace(".", "");
|
|
||||||
|
|
||||||
if (version.contains("v1_8_")) {
|
|
||||||
return true;
|
|
||||||
} else if (version.contains("v1_9_")) {
|
|
||||||
return true;
|
|
||||||
} else if (version.contains("v1_10_")) {
|
|
||||||
return true;
|
|
||||||
} else if (version.contains("v1_11_")) {
|
|
||||||
return true;
|
|
||||||
} else if (version.contains("v1_12_")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CommandWhitelist getPlugin() {return commandWhitelist;}
|
|
||||||
public static ConfigCache getConfigCache() {return configCache;}
|
|
||||||
}
|
|
||||||
@@ -1,143 +0,0 @@
|
|||||||
package eu.endermite.commandwhitelist.spigot.command;
|
|
||||||
|
|
||||||
import eu.endermite.commandwhitelist.spigot.CommandWhitelist;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.command.TabExecutor;
|
|
||||||
import org.bukkit.help.HelpTopic;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class MainCommand implements TabExecutor {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
||||||
if (args.length > 0) {
|
|
||||||
if (args[0].equalsIgnoreCase("reload")) {
|
|
||||||
if (!sender.hasPermission("commandwhitelist.reload")) {
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().getPrefix() + CommandWhitelist.getConfigCache().getNoPermission()));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
CommandWhitelist.getPlugin().reloadPluginConfig(sender);
|
|
||||||
|
|
||||||
} else if (args[0].equalsIgnoreCase("add")) {
|
|
||||||
|
|
||||||
if (!sender.hasPermission("commandwhitelist.admin")) {
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().getPrefix() + CommandWhitelist.getConfigCache().getNoPermission()));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (args.length >= 3) {
|
|
||||||
if (CommandWhitelist.getConfigCache().addCommand(args[2], args[1])) {
|
|
||||||
String msg = String.format(CommandWhitelist.getConfigCache().getWhitelistedCommand(), args[2], args[1]);
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', msg));
|
|
||||||
} else {
|
|
||||||
String msg = CommandWhitelist.getConfigCache().getNoSuchGroup();
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', msg));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sender.sendMessage("/cw add <group> <command>");
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (args[0].equalsIgnoreCase("remove")) {
|
|
||||||
|
|
||||||
if (!sender.hasPermission("commandwhitelist.admin")) {
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().getPrefix() + CommandWhitelist.getConfigCache().getNoPermission()));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (args.length >= 3) {
|
|
||||||
if (CommandWhitelist.getConfigCache().removeCommand(args[2], args[1])) {
|
|
||||||
String msg = String.format(CommandWhitelist.getConfigCache().getRemovedWhitelistedCommand(), args[2], args[1]);
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', msg));
|
|
||||||
} else {
|
|
||||||
String msg = CommandWhitelist.getConfigCache().getNoSuchGroup();
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', msg));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sender.sendMessage("/cw remove <group> <command>");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().getPrefix() + CommandWhitelist.getConfigCache().getNoSubCommand()));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&bCommand Whitelist by YouHaveTrouble"));
|
|
||||||
if (sender.hasPermission("commandwhitelist.reload")) {
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&9/cw reload &b- Reload plugin configuration"));
|
|
||||||
}
|
|
||||||
if (sender.hasPermission("commandwhitelist.admin")) {
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&9/cw add <group> <command> &b- Add command to group"));
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&9/cw remove <group> <command> &b- Remove command from a group"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
|
||||||
List<String> list = new ArrayList<>();
|
|
||||||
if (args.length == 1) {
|
|
||||||
if ("reload".startsWith(args[0]) && sender.hasPermission("commandwhitelist.reload")) {
|
|
||||||
list.add("reload");
|
|
||||||
}
|
|
||||||
if ("add".startsWith(args[0]) && sender.hasPermission("commandwhitelist.admin")) {
|
|
||||||
list.add("add");
|
|
||||||
}
|
|
||||||
if ("remove".startsWith(args[0]) && sender.hasPermission("commandwhitelist.admin")) {
|
|
||||||
list.add("remove");
|
|
||||||
}
|
|
||||||
} else if (args.length == 2) {
|
|
||||||
if (args[0].equalsIgnoreCase("add") || args[0].equalsIgnoreCase("remove")) {
|
|
||||||
if (!sender.hasPermission("commandwhitelist.admin"))
|
|
||||||
return list;
|
|
||||||
for (Map.Entry<String, List<String>> s : CommandWhitelist.getConfigCache().getPermList().entrySet()) {
|
|
||||||
if (s.getKey().startsWith(args[1])) {
|
|
||||||
list.add(s.getKey());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (args.length == 3) {
|
|
||||||
if (args[0].equalsIgnoreCase("remove")) {
|
|
||||||
if (!sender.hasPermission("commandwhitelist.admin"))
|
|
||||||
return list;
|
|
||||||
try {
|
|
||||||
for (String s : CommandWhitelist.getConfigCache().getPermList().get(args[1])) {
|
|
||||||
if (s.startsWith(args[2])) {
|
|
||||||
list.add(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (NullPointerException ignored) {
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
if (args[0].equalsIgnoreCase("add")) {
|
|
||||||
if (!sender.hasPermission("commandwhitelist.admin"))
|
|
||||||
return list;
|
|
||||||
|
|
||||||
for (HelpTopic s : CommandWhitelist.getPlugin().getServer().getHelpMap().getHelpTopics()) {
|
|
||||||
String cmd = s.getName();
|
|
||||||
if (!cmd.startsWith("/"))
|
|
||||||
continue;
|
|
||||||
try {
|
|
||||||
if (cmd.contains(":")) {
|
|
||||||
cmd = cmd.split(":")[1];
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
cmd = cmd.replace("/", "");
|
|
||||||
|
|
||||||
if (CommandWhitelist.getConfigCache().getPermList().get(args[1]).contains(cmd))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (cmd.startsWith(args[2])) {
|
|
||||||
list.add(cmd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
package eu.endermite.commandwhitelist.spigot.config;
|
|
||||||
|
|
||||||
import eu.endermite.commandwhitelist.spigot.CommandWhitelist;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class ConfigCache {
|
|
||||||
|
|
||||||
private FileConfiguration config;
|
|
||||||
private HashMap<String, List<String>> permList = new HashMap<>();
|
|
||||||
private HashMap<String, List<String>> permSubList = new HashMap<>();
|
|
||||||
private final String prefix, commandDenied, noPermission, noSubCommand, configReloaded, whitelistedCommand,
|
|
||||||
removedWhitelistedCommand, noSuchGroup, subCommandDenied;
|
|
||||||
private final List<String> commandDeniedList;
|
|
||||||
private boolean useProtocolLib;
|
|
||||||
|
|
||||||
public ConfigCache(FileConfiguration config) {
|
|
||||||
|
|
||||||
this.config = config;
|
|
||||||
|
|
||||||
prefix = config.getString("messages.prefix", "");
|
|
||||||
commandDenied = config.getString("messages.command-denied", null);
|
|
||||||
commandDeniedList = config.getStringList("messages.command-denied");
|
|
||||||
subCommandDenied = config.getString("messages.subcommand-denied", "You cannot use this subcommand");
|
|
||||||
noPermission = config.getString("messages.no-permission", "&cYou don't have permission to do this.");
|
|
||||||
noSubCommand = config.getString("messages.no-such-subcommand", "&cNo subcommand by that name.");
|
|
||||||
configReloaded = config.getString("messages.config-reloaded", "&eConfiguration reloaded.");
|
|
||||||
whitelistedCommand = config.getString("messages.added-to-whitelist", "&eWhitelisted command &6%s &efor permission &6%s");
|
|
||||||
removedWhitelistedCommand = config.getString("messages.removed-from-whitelist", "&eRemoved command &6%s &efrom permission &6%s");
|
|
||||||
noSuchGroup = config.getString("messages.group-doesnt-exist", "&cGroup %s doesn't exist");
|
|
||||||
|
|
||||||
useProtocolLib = config.getBoolean("use-protocollib-to-detect-commands", false);
|
|
||||||
|
|
||||||
Set<String> perms = config.getConfigurationSection("commands").getKeys(false);
|
|
||||||
for (String s : perms) {
|
|
||||||
this.permList.put(s, config.getStringList("commands."+s));
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<String> subperms = config.getConfigurationSection("tabcompletions").getKeys(false);
|
|
||||||
for (String s : subperms) {
|
|
||||||
this.permSubList.put(s, config.getStringList("tabcompletions."+s));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashMap<String, List<String>> getPermList() {
|
|
||||||
return permList;
|
|
||||||
}
|
|
||||||
public HashMap<String, List<String>> getPermSubList() {
|
|
||||||
return permSubList;
|
|
||||||
}
|
|
||||||
public boolean addCommand(String command, String group) {
|
|
||||||
try {
|
|
||||||
if (this.permList.get(group).contains(command)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
this.permList.get(group).add(command);
|
|
||||||
this.config.set("commands."+group, permList.get(group));
|
|
||||||
config.save(CommandWhitelist.getPlugin().getDataFolder()+"/config.yml");
|
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
|
||||||
player.updateCommands();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public boolean removeCommand(String command, String group) {
|
|
||||||
try {
|
|
||||||
this.permList.get(group).remove(command);
|
|
||||||
this.config.set("commands."+group, permList.get(group));
|
|
||||||
config.save(CommandWhitelist.getPlugin().getDataFolder()+"/config.yml");
|
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
|
||||||
player.updateCommands();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public String getPrefix() {return prefix;}
|
|
||||||
public String getCommandDenied() {return commandDenied;}
|
|
||||||
public List<String> getCommandDeniedList() {
|
|
||||||
return commandDeniedList;
|
|
||||||
}
|
|
||||||
public String getNoPermission() {return noPermission;}
|
|
||||||
public String getNoSubCommand() {return noSubCommand;}
|
|
||||||
public String getConfigReloaded() {return configReloaded;}
|
|
||||||
public String getWhitelistedCommand() {
|
|
||||||
return whitelistedCommand;
|
|
||||||
}
|
|
||||||
public String getRemovedWhitelistedCommand() {
|
|
||||||
return removedWhitelistedCommand;
|
|
||||||
}
|
|
||||||
public String getNoSuchGroup() {
|
|
||||||
return noSuchGroup;
|
|
||||||
}
|
|
||||||
public String getSubCommandDenied() {
|
|
||||||
return subCommandDenied;
|
|
||||||
}
|
|
||||||
public boolean isUseProtocolLib() {
|
|
||||||
return useProtocolLib;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-85
@@ -1,85 +0,0 @@
|
|||||||
package eu.endermite.commandwhitelist.spigot.listeners;
|
|
||||||
|
|
||||||
import com.comphenix.protocol.PacketType;
|
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
|
||||||
import com.comphenix.protocol.ProtocolManager;
|
|
||||||
import com.comphenix.protocol.events.ListenerPriority;
|
|
||||||
import com.comphenix.protocol.events.PacketAdapter;
|
|
||||||
import com.comphenix.protocol.events.PacketContainer;
|
|
||||||
import com.comphenix.protocol.events.PacketEvent;
|
|
||||||
import eu.endermite.commandwhitelist.api.CommandsList;
|
|
||||||
import eu.endermite.commandwhitelist.spigot.CommandWhitelist;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class LegacyPlayerTabChatCompleteListener {
|
|
||||||
|
|
||||||
public static void protocol(CommandWhitelist plugin) {
|
|
||||||
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
|
||||||
tabCompleteServerBound(protocolManager, plugin);
|
|
||||||
tabCompleteClientBound(protocolManager, plugin);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void tabCompleteServerBound(ProtocolManager protocolManager, Plugin plugin) {
|
|
||||||
protocolManager.addPacketListener(new PacketAdapter(plugin, ListenerPriority.HIGHEST, PacketType.Play.Server.TAB_COMPLETE) {
|
|
||||||
@Override
|
|
||||||
public void onPacketSending(PacketEvent event) {
|
|
||||||
try {
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
if (player.hasPermission("commandwhitelist.bypass"))
|
|
||||||
return;
|
|
||||||
PacketContainer packet = event.getPacket();
|
|
||||||
String[] message = packet.getSpecificModifier(String[].class).read(0);
|
|
||||||
List<String> commandList = CommandsList.getCommands(player);
|
|
||||||
List<String> finalList = new ArrayList<>();
|
|
||||||
int components = 0;
|
|
||||||
for (String cmd : message) {
|
|
||||||
for (String cmdFromList : commandList) {
|
|
||||||
if (cmd.equalsIgnoreCase("/" + cmdFromList) || !cmd.startsWith("/")) {
|
|
||||||
finalList.add(components++, cmd);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
String[] toWrite = new String[components];
|
|
||||||
int counter = 0;
|
|
||||||
for (String cmd : finalList) {
|
|
||||||
toWrite[counter++] = cmd;
|
|
||||||
}
|
|
||||||
packet.getSpecificModifier(String[].class).write(0, toWrite);
|
|
||||||
} catch (Exception ignored) {}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void tabCompleteClientBound(ProtocolManager protocolManager, Plugin plugin) {
|
|
||||||
protocolManager.addPacketListener(new PacketAdapter(plugin, ListenerPriority.HIGHEST, PacketType.Play.Client.TAB_COMPLETE) {
|
|
||||||
@Override
|
|
||||||
public void onPacketReceiving(PacketEvent event) {
|
|
||||||
try {
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
if (player.hasPermission("commandwhitelist.bypass")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
PacketContainer packet = event.getPacket();
|
|
||||||
String command = packet.getSpecificModifier(String.class).read(0);
|
|
||||||
String label = CommandsList.getCommandLabel(command);
|
|
||||||
List<String> commandList = CommandsList.getCommands(player);
|
|
||||||
if (command.equals("/"))
|
|
||||||
return;
|
|
||||||
for (String cmd : commandList) {
|
|
||||||
if (cmd.startsWith("/"+label+" "))
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
event.setCancelled(true);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-68
@@ -1,68 +0,0 @@
|
|||||||
package eu.endermite.commandwhitelist.spigot.listeners;
|
|
||||||
|
|
||||||
import com.comphenix.protocol.PacketType;
|
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
|
||||||
import com.comphenix.protocol.ProtocolManager;
|
|
||||||
import com.comphenix.protocol.events.ListenerPriority;
|
|
||||||
import com.comphenix.protocol.events.PacketAdapter;
|
|
||||||
import com.comphenix.protocol.events.PacketContainer;
|
|
||||||
import com.comphenix.protocol.events.PacketEvent;
|
|
||||||
import eu.endermite.commandwhitelist.api.CommandsList;
|
|
||||||
import eu.endermite.commandwhitelist.api.RandomStuff;
|
|
||||||
import eu.endermite.commandwhitelist.spigot.CommandWhitelist;
|
|
||||||
import eu.endermite.commandwhitelist.spigot.config.ConfigCache;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class PacketCommandSendListener {
|
|
||||||
|
|
||||||
public static void protocol(CommandWhitelist plugin) {
|
|
||||||
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
|
||||||
commandExecListener(protocolManager, plugin);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void commandExecListener(ProtocolManager protocolManager, Plugin plugin) {
|
|
||||||
protocolManager.addPacketListener(new PacketAdapter(plugin, ListenerPriority.HIGHEST, PacketType.Play.Client.CHAT) {
|
|
||||||
@Override
|
|
||||||
public void onPacketReceiving(PacketEvent event) {
|
|
||||||
PacketContainer packet = event.getPacket();
|
|
||||||
String string = packet.getStrings().read(0);
|
|
||||||
if (!string.startsWith("/"))
|
|
||||||
return;
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
if (player.hasPermission("commandwhitelist.bypass"))
|
|
||||||
return;
|
|
||||||
String cmd = string.replace("/", "");
|
|
||||||
String[] split = cmd.split("\\s+");
|
|
||||||
String command = split[0].toLowerCase();
|
|
||||||
for (Map.Entry<String, List<String>> s : CommandWhitelist.getConfigCache().getPermList().entrySet()) {
|
|
||||||
if (!player.hasPermission("commandwhitelist.commands." + s.getKey()))
|
|
||||||
continue;
|
|
||||||
for (String comm : s.getValue()) {
|
|
||||||
comm = comm.toLowerCase();
|
|
||||||
if (command.equalsIgnoreCase(comm) || command.startsWith(comm + " ")) {
|
|
||||||
List<String> bannedSubCommands = CommandsList.getSuggestions(player);
|
|
||||||
for (String bannedSubCommand : bannedSubCommands) {
|
|
||||||
if (cmd.startsWith(bannedSubCommand)) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
ConfigCache config = CommandWhitelist.getConfigCache();
|
|
||||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getPrefix() + RandomStuff.getMessage(config.getCommandDeniedList(), config.getSubCommandDenied())));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
event.setCancelled(true);
|
|
||||||
ConfigCache config = CommandWhitelist.getConfigCache();
|
|
||||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getPrefix() + RandomStuff.getMessage(config.getCommandDeniedList(), config.getCommandDenied())));
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-48
@@ -1,48 +0,0 @@
|
|||||||
package eu.endermite.commandwhitelist.spigot.listeners;
|
|
||||||
|
|
||||||
import eu.endermite.commandwhitelist.api.CommandsList;
|
|
||||||
import eu.endermite.commandwhitelist.api.RandomStuff;
|
|
||||||
import eu.endermite.commandwhitelist.spigot.CommandWhitelist;
|
|
||||||
import eu.endermite.commandwhitelist.spigot.config.ConfigCache;
|
|
||||||
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 PlayerCommandPreProcessListener implements Listener {
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
|
||||||
public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent event) {
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
if (player.hasPermission("commandwhitelist.bypass"))
|
|
||||||
return;
|
|
||||||
String command = event.getMessage().toLowerCase();
|
|
||||||
if (command.startsWith("/"))
|
|
||||||
command = command.substring(1);
|
|
||||||
for (Map.Entry<String, List<String>> s : CommandWhitelist.getConfigCache().getPermList().entrySet()) {
|
|
||||||
if (!player.hasPermission("commandwhitelist.commands." + s.getKey()))
|
|
||||||
continue;
|
|
||||||
for (String comm : s.getValue()) {
|
|
||||||
comm = comm.toLowerCase();
|
|
||||||
if (command.equalsIgnoreCase(comm) || command.startsWith(comm + " ")) {
|
|
||||||
String rawCmd = event.getMessage();
|
|
||||||
List<String> bannedSubCommands = CommandsList.getSuggestions(player);
|
|
||||||
for (String bannedSubCommand : bannedSubCommands) {
|
|
||||||
if (rawCmd.startsWith(bannedSubCommand)) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
ConfigCache config = CommandWhitelist.getConfigCache();
|
|
||||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getPrefix() + RandomStuff.getMessage(config.getCommandDeniedList(), config.getSubCommandDenied())));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
event.setCancelled(true);
|
|
||||||
ConfigCache config = CommandWhitelist.getConfigCache();
|
|
||||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getPrefix() + RandomStuff.getMessage(config.getCommandDeniedList(), config.getCommandDenied())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-33
@@ -1,33 +0,0 @@
|
|||||||
package eu.endermite.commandwhitelist.spigot.listeners;
|
|
||||||
|
|
||||||
import eu.endermite.commandwhitelist.api.CommandsList;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class TabCompleteBlockerListener implements Listener {
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
|
||||||
public void onCommandTabComplete(org.bukkit.event.server.TabCompleteEvent event) {
|
|
||||||
if (!(event.getSender() instanceof Player))
|
|
||||||
return;
|
|
||||||
Player player = (Player) event.getSender();
|
|
||||||
String buffer = event.getBuffer();
|
|
||||||
String cmd = buffer.replace(CommandsList.getLastArgument(buffer), "");
|
|
||||||
List<String> blockedCommands = CommandsList.getSuggestions(player);
|
|
||||||
List<String> suggestions = event.getCompletions();
|
|
||||||
for (String s : blockedCommands) {
|
|
||||||
String slast = CommandsList.getLastArgument(s);
|
|
||||||
String scommand = s.replace(slast, "");
|
|
||||||
cmd = cmd.replace(CommandsList.getLastArgument(cmd), "");
|
|
||||||
if (cmd.startsWith("/" + scommand)) {
|
|
||||||
try {
|
|
||||||
while (suggestions.contains(slast))
|
|
||||||
suggestions.remove(slast);
|
|
||||||
} catch (Exception ignored) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
event.setCompletions(suggestions);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,366 +0,0 @@
|
|||||||
package eu.endermite.commandwhitelist.spigot.metrics;
|
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
|
||||||
import org.bukkit.plugin.ServicePriority;
|
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
|
||||||
import java.io.*;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Timer;
|
|
||||||
import java.util.TimerTask;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.zip.GZIPOutputStream;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* bStats collects some data for plugin authors.
|
|
||||||
* <p>
|
|
||||||
* Check out https://bStats.org/ to learn more about bStats!
|
|
||||||
*/
|
|
||||||
@SuppressWarnings({"WeakerAccess", "unused"})
|
|
||||||
public class BukkitMetrics {
|
|
||||||
|
|
||||||
static {
|
|
||||||
// You can use the property to disable the check in your test environment
|
|
||||||
if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) {
|
|
||||||
// Maven's Relocate is clever and changes strings, too. So we have to use this little "trick" ... :D
|
|
||||||
final String defaultPackage = new String(
|
|
||||||
new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't'});
|
|
||||||
final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
|
|
||||||
// We want to make sure nobody just copy & pastes the example and use the wrong package names
|
|
||||||
if (BukkitMetrics.class.getPackage().getName().equals(defaultPackage) || BukkitMetrics.class.getPackage().getName().equals(examplePackage)) {
|
|
||||||
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// The version of this bStats class
|
|
||||||
public static final int B_STATS_VERSION = 1;
|
|
||||||
|
|
||||||
// The url to which the data is sent
|
|
||||||
private static final String URL = "https://bStats.org/submitData/bukkit";
|
|
||||||
|
|
||||||
// Is bStats enabled on this server?
|
|
||||||
private boolean enabled;
|
|
||||||
|
|
||||||
// Should failed requests be logged?
|
|
||||||
private static boolean logFailedRequests;
|
|
||||||
|
|
||||||
// Should the sent data be logged?
|
|
||||||
private static boolean logSentData;
|
|
||||||
|
|
||||||
// Should the response text be logged?
|
|
||||||
private static boolean logResponseStatusText;
|
|
||||||
|
|
||||||
// The uuid of the server
|
|
||||||
private static String serverUUID;
|
|
||||||
|
|
||||||
// The plugin
|
|
||||||
private final Plugin plugin;
|
|
||||||
|
|
||||||
// The plugin id
|
|
||||||
private final int pluginId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class constructor.
|
|
||||||
*
|
|
||||||
* @param plugin The plugin which stats should be submitted.
|
|
||||||
* @param pluginId The id of the plugin.
|
|
||||||
* It can be found at <a href="https://bstats.org/what-is-my-plugin-id">What is my plugin id?</a>
|
|
||||||
*/
|
|
||||||
public BukkitMetrics(Plugin plugin, int pluginId) {
|
|
||||||
if (plugin == null) {
|
|
||||||
throw new IllegalArgumentException("Plugin cannot be null!");
|
|
||||||
}
|
|
||||||
this.plugin = plugin;
|
|
||||||
this.pluginId = pluginId;
|
|
||||||
|
|
||||||
// Get the config file
|
|
||||||
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
|
|
||||||
File configFile = new File(bStatsFolder, "config.yml");
|
|
||||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
|
||||||
|
|
||||||
// Check if the config file exists
|
|
||||||
if (!config.isSet("serverUuid")) {
|
|
||||||
|
|
||||||
// Add default values
|
|
||||||
config.addDefault("enabled", true);
|
|
||||||
// Every server gets it's unique random id.
|
|
||||||
config.addDefault("serverUuid", UUID.randomUUID().toString());
|
|
||||||
// Should failed request be logged?
|
|
||||||
config.addDefault("logFailedRequests", false);
|
|
||||||
// Should the sent data be logged?
|
|
||||||
config.addDefault("logSentData", false);
|
|
||||||
// Should the response text be logged?
|
|
||||||
config.addDefault("logResponseStatusText", false);
|
|
||||||
|
|
||||||
// Inform the server owners about bStats
|
|
||||||
config.options().header(
|
|
||||||
"bStats collects some data for plugin authors like how many servers are using their plugins.\n" +
|
|
||||||
"To honor their work, you should not disable it.\n" +
|
|
||||||
"This has nearly no effect on the server performance!\n" +
|
|
||||||
"Check out https://bStats.org/ to learn more :)"
|
|
||||||
).copyDefaults(true);
|
|
||||||
try {
|
|
||||||
config.save(configFile);
|
|
||||||
} catch (IOException ignored) { }
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load the data
|
|
||||||
serverUUID = config.getString("serverUuid");
|
|
||||||
logFailedRequests = config.getBoolean("logFailedRequests", false);
|
|
||||||
enabled = config.getBoolean("enabled", true);
|
|
||||||
logSentData = config.getBoolean("logSentData", false);
|
|
||||||
logResponseStatusText = config.getBoolean("logResponseStatusText", false);
|
|
||||||
if (enabled) {
|
|
||||||
boolean found = false;
|
|
||||||
// Search for all other bStats Metrics classes to see if we are the first one
|
|
||||||
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
|
|
||||||
try {
|
|
||||||
service.getField("B_STATS_VERSION"); // Our identifier :)
|
|
||||||
found = true; // We aren't the first
|
|
||||||
break;
|
|
||||||
} catch (NoSuchFieldException ignored) { }
|
|
||||||
}
|
|
||||||
// Register our service
|
|
||||||
Bukkit.getServicesManager().register(BukkitMetrics.class, this, plugin, ServicePriority.Normal);
|
|
||||||
if (!found) {
|
|
||||||
// We are the first!
|
|
||||||
startSubmitting();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if bStats is enabled.
|
|
||||||
*
|
|
||||||
* @return Whether bStats is enabled or not.
|
|
||||||
*/
|
|
||||||
public boolean isEnabled() {
|
|
||||||
return enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Starts the Scheduler which submits our data every 30 minutes.
|
|
||||||
*/
|
|
||||||
private void startSubmitting() {
|
|
||||||
final Timer timer = new Timer(true); // We use a timer cause the Bukkit scheduler is affected by server lags
|
|
||||||
timer.scheduleAtFixedRate(new TimerTask() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (!plugin.isEnabled()) { // Plugin was disabled
|
|
||||||
timer.cancel();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler
|
|
||||||
// Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
|
|
||||||
Bukkit.getScheduler().runTask(plugin, () -> submitData());
|
|
||||||
}
|
|
||||||
}, 1000 * 60 * 5, 1000 * 60 * 30);
|
|
||||||
// Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start
|
|
||||||
// WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted!
|
|
||||||
// WARNING: Just don't do it!
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the plugin specific data.
|
|
||||||
* This method is called using Reflection.
|
|
||||||
*
|
|
||||||
* @return The plugin specific data.
|
|
||||||
*/
|
|
||||||
public JsonObject getPluginData() {
|
|
||||||
JsonObject data = new JsonObject();
|
|
||||||
|
|
||||||
String pluginName = plugin.getDescription().getName();
|
|
||||||
String pluginVersion = plugin.getDescription().getVersion();
|
|
||||||
|
|
||||||
data.addProperty("pluginName", pluginName); // Append the name of the plugin
|
|
||||||
data.addProperty("id", pluginId); // Append the id of the plugin
|
|
||||||
data.addProperty("pluginVersion", pluginVersion); // Append the version of the plugin
|
|
||||||
data.add("customCharts", new JsonArray());
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the server specific data.
|
|
||||||
*
|
|
||||||
* @return The server specific data.
|
|
||||||
*/
|
|
||||||
private JsonObject getServerData() {
|
|
||||||
// Minecraft specific data
|
|
||||||
int playerAmount;
|
|
||||||
try {
|
|
||||||
// Around MC 1.8 the return type was changed to a collection from an array,
|
|
||||||
// This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
|
|
||||||
Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
|
|
||||||
playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
|
|
||||||
? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
|
|
||||||
: ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
|
|
||||||
} catch (Exception e) {
|
|
||||||
playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
|
|
||||||
}
|
|
||||||
int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
|
|
||||||
String bukkitVersion = Bukkit.getVersion();
|
|
||||||
String bukkitName = Bukkit.getName();
|
|
||||||
|
|
||||||
// OS/Java specific data
|
|
||||||
String javaVersion = System.getProperty("java.version");
|
|
||||||
String osName = System.getProperty("os.name");
|
|
||||||
String osArch = System.getProperty("os.arch");
|
|
||||||
String osVersion = System.getProperty("os.version");
|
|
||||||
int coreCount = Runtime.getRuntime().availableProcessors();
|
|
||||||
|
|
||||||
JsonObject data = new JsonObject();
|
|
||||||
|
|
||||||
data.addProperty("serverUUID", serverUUID);
|
|
||||||
|
|
||||||
data.addProperty("playerAmount", playerAmount);
|
|
||||||
data.addProperty("onlineMode", onlineMode);
|
|
||||||
data.addProperty("bukkitVersion", bukkitVersion);
|
|
||||||
data.addProperty("bukkitName", bukkitName);
|
|
||||||
|
|
||||||
data.addProperty("javaVersion", javaVersion);
|
|
||||||
data.addProperty("osName", osName);
|
|
||||||
data.addProperty("osArch", osArch);
|
|
||||||
data.addProperty("osVersion", osVersion);
|
|
||||||
data.addProperty("coreCount", coreCount);
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Collects the data and sends it afterwards.
|
|
||||||
*/
|
|
||||||
private void submitData() {
|
|
||||||
final JsonObject data = getServerData();
|
|
||||||
|
|
||||||
JsonArray pluginData = new JsonArray();
|
|
||||||
// Search for all other bStats Metrics classes to get their plugin data
|
|
||||||
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
|
|
||||||
try {
|
|
||||||
service.getField("B_STATS_VERSION"); // Our identifier :)
|
|
||||||
|
|
||||||
for (RegisteredServiceProvider<?> provider : Bukkit.getServicesManager().getRegistrations(service)) {
|
|
||||||
try {
|
|
||||||
Object plugin = provider.getService().getMethod("getPluginData").invoke(provider.getProvider());
|
|
||||||
if (plugin instanceof JsonObject) {
|
|
||||||
pluginData.add((JsonObject) plugin);
|
|
||||||
} else { // old bstats version compatibility
|
|
||||||
try {
|
|
||||||
Class<?> jsonObjectJsonSimple = Class.forName("org.json.simple.JSONObject");
|
|
||||||
if (plugin.getClass().isAssignableFrom(jsonObjectJsonSimple)) {
|
|
||||||
Method jsonStringGetter = jsonObjectJsonSimple.getDeclaredMethod("toJSONString");
|
|
||||||
jsonStringGetter.setAccessible(true);
|
|
||||||
String jsonString = (String) jsonStringGetter.invoke(plugin);
|
|
||||||
JsonObject object = new JsonParser().parse(jsonString).getAsJsonObject();
|
|
||||||
pluginData.add(object);
|
|
||||||
}
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
// minecraft version 1.14+
|
|
||||||
if (logFailedRequests) {
|
|
||||||
this.plugin.getLogger().log(Level.SEVERE, "Encountered unexpected exception ", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (NoSuchFieldException ignored) { }
|
|
||||||
}
|
|
||||||
|
|
||||||
data.add("plugins", pluginData);
|
|
||||||
|
|
||||||
// Create a new thread for the connection to the bStats server
|
|
||||||
new Thread(() -> {
|
|
||||||
try {
|
|
||||||
// Send the data
|
|
||||||
sendData(plugin, data);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// Something went wrong! :(
|
|
||||||
if (logFailedRequests) {
|
|
||||||
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends the data to the bStats server.
|
|
||||||
*
|
|
||||||
* @param plugin Any plugin. It's just used to get a logger instance.
|
|
||||||
* @param data The data to send.
|
|
||||||
* @throws Exception If the request failed.
|
|
||||||
*/
|
|
||||||
private static void sendData(Plugin plugin, JsonObject data) throws Exception {
|
|
||||||
if (data == null) {
|
|
||||||
throw new IllegalArgumentException("Data cannot be null!");
|
|
||||||
}
|
|
||||||
if (Bukkit.isPrimaryThread()) {
|
|
||||||
throw new IllegalAccessException("This method must not be called from the main thread!");
|
|
||||||
}
|
|
||||||
if (logSentData) {
|
|
||||||
plugin.getLogger().info("Sending data to bStats: " + data);
|
|
||||||
}
|
|
||||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
|
|
||||||
|
|
||||||
// Compress the data to save bandwidth
|
|
||||||
byte[] compressedData = compress(data.toString());
|
|
||||||
|
|
||||||
// Add headers
|
|
||||||
connection.setRequestMethod("POST");
|
|
||||||
connection.addRequestProperty("Accept", "application/json");
|
|
||||||
connection.addRequestProperty("Connection", "close");
|
|
||||||
connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
|
|
||||||
connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
|
|
||||||
connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
|
|
||||||
connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
|
|
||||||
|
|
||||||
// Send data
|
|
||||||
connection.setDoOutput(true);
|
|
||||||
try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
|
|
||||||
outputStream.write(compressedData);
|
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
|
||||||
String line;
|
|
||||||
while ((line = bufferedReader.readLine()) != null) {
|
|
||||||
builder.append(line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (logResponseStatusText) {
|
|
||||||
plugin.getLogger().info("Sent data to bStats and received response: " + builder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gzips the given String.
|
|
||||||
*
|
|
||||||
* @param str The string to gzip.
|
|
||||||
* @return The gzipped String.
|
|
||||||
* @throws IOException If the compression failed.
|
|
||||||
*/
|
|
||||||
private static byte[] compress(final String str) throws IOException {
|
|
||||||
if (str == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
||||||
try(GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) {
|
|
||||||
gzip.write(str.getBytes(StandardCharsets.UTF_8));
|
|
||||||
}
|
|
||||||
return outputStream.toByteArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,112 +0,0 @@
|
|||||||
package eu.endermite.commandwhitelist.velocity;
|
|
||||||
|
|
||||||
import com.moandjiezana.toml.Toml;
|
|
||||||
import com.velocitypowered.api.command.CommandMeta;
|
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
|
||||||
import com.velocitypowered.api.event.command.CommandExecuteEvent;
|
|
||||||
import com.velocitypowered.api.event.command.PlayerAvailableCommandsEvent;
|
|
||||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
|
||||||
import com.velocitypowered.api.plugin.Plugin;
|
|
||||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
|
||||||
import com.velocitypowered.api.proxy.Player;
|
|
||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
|
||||||
import eu.endermite.commandwhitelist.api.CommandsList;
|
|
||||||
import eu.endermite.commandwhitelist.velocity.command.VelocityMainCommand;
|
|
||||||
import eu.endermite.commandwhitelist.velocity.config.VelocityConfigCache;
|
|
||||||
import net.kyori.adventure.identity.Identity;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class CommandWhitelistVelocity {
|
|
||||||
|
|
||||||
private static CommandWhitelistVelocity plugin;
|
|
||||||
private static ProxyServer server;
|
|
||||||
private static VelocityConfigCache configCache;
|
|
||||||
private static Path folder;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public CommandWhitelistVelocity(ProxyServer server, Logger logger, @DataDirectory final Path folder) {
|
|
||||||
CommandWhitelistVelocity.server = server;
|
|
||||||
CommandWhitelistVelocity.folder = folder;
|
|
||||||
CommandWhitelistVelocity.plugin = this;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Toml loadConfig(Path path) {
|
|
||||||
File folder = path.toFile();
|
|
||||||
File file = new File(folder, "config.toml");
|
|
||||||
if (!file.getParentFile().exists())
|
|
||||||
file.getParentFile().mkdirs();
|
|
||||||
|
|
||||||
if (!file.exists()) {
|
|
||||||
try (InputStream input = CommandWhitelistVelocity.class.getResourceAsStream("/" + file.getName())) {
|
|
||||||
if (input != null) {
|
|
||||||
Files.copy(input, file.toPath());
|
|
||||||
} else {
|
|
||||||
file.createNewFile();
|
|
||||||
}
|
|
||||||
} catch (IOException exception) {
|
|
||||||
exception.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new Toml().read(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void reloadConfig() {
|
|
||||||
configCache = new VelocityConfigCache(loadConfig(folder));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void reloadConfig(CommandSource source) {
|
|
||||||
server.getScheduler().buildTask(plugin, () -> {
|
|
||||||
reloadConfig();
|
|
||||||
source.sendMessage(Identity.nil(), Component.text(getConfigCache().getConfigReloaded()));
|
|
||||||
}).schedule();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
|
||||||
reloadConfig();
|
|
||||||
CommandMeta commandMeta = server.getCommandManager().metaBuilder("vcw").build();
|
|
||||||
server.getCommandManager().register(commandMeta, new VelocityMainCommand());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onUserCommandSendEvent(PlayerAvailableCommandsEvent event) {
|
|
||||||
if (event.getPlayer().hasPermission("commandwhitelist.bypass"))
|
|
||||||
return;
|
|
||||||
List<String> allowedCommands = CommandsList.getCommands(event.getPlayer());
|
|
||||||
event.getRootNode().getChildren().removeIf((commandNode) ->
|
|
||||||
server.getCommandManager().hasCommand(commandNode.getName())
|
|
||||||
&& !allowedCommands.contains(commandNode.getName())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onUserCommandExecuteEvent(com.velocitypowered.api.event.command.CommandExecuteEvent event) {
|
|
||||||
if (!(event.getCommandSource() instanceof Player))
|
|
||||||
return;
|
|
||||||
Player player = (Player) event.getCommandSource();
|
|
||||||
|
|
||||||
if (player.hasPermission("commandwhitelist.bypass"))
|
|
||||||
return;
|
|
||||||
|
|
||||||
List<String> allowedCommands = CommandsList.getCommands(player);
|
|
||||||
String command = event.getCommand().split(" ")[0];
|
|
||||||
if (server.getCommandManager().hasCommand(command)
|
|
||||||
&& !allowedCommands.contains(command))
|
|
||||||
event.setResult(CommandExecuteEvent.CommandResult.forwardToServer());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static VelocityConfigCache getConfigCache() {
|
|
||||||
return configCache;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
package eu.endermite.commandwhitelist.velocity.command;
|
|
||||||
|
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
|
||||||
import com.velocitypowered.api.command.SimpleCommand;
|
|
||||||
import eu.endermite.commandwhitelist.velocity.CommandWhitelistVelocity;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
public class VelocityMainCommand implements SimpleCommand {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(final Invocation invocation) {
|
|
||||||
CommandSource source = invocation.source();
|
|
||||||
String[] args = invocation.arguments();
|
|
||||||
if (args.length > 0) {
|
|
||||||
if (args.length == 1 && args[0].equalsIgnoreCase("reload")) {
|
|
||||||
if (source.hasPermission("commandwhitelist.reload")) {
|
|
||||||
CommandWhitelistVelocity.reloadConfig(source);
|
|
||||||
} else {
|
|
||||||
source.sendMessage(Component.text(CommandWhitelistVelocity.getConfigCache().getNoPermission()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
source.sendMessage(Component.text("&bCommand Whitelist by YouHaveTrouble".replaceAll("&", "§")));
|
|
||||||
if (source.hasPermission("commandwhitelist.reload")) {
|
|
||||||
source.sendMessage(Component.text("&9/vcw reload &b- Reload velocity plugin configuration".replaceAll("&", "§")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<List<String>> suggestAsync(Invocation invocation) {
|
|
||||||
CommandSource source = invocation.source();
|
|
||||||
String[] args = invocation.arguments();
|
|
||||||
return CompletableFuture.supplyAsync(() -> {
|
|
||||||
List<String> suggestions = new ArrayList<>();
|
|
||||||
if (args.length == 1) {
|
|
||||||
if (source.hasPermission("commandwhitelist.reload") && "reload".startsWith(args[0]))
|
|
||||||
suggestions.add("reload");
|
|
||||||
}
|
|
||||||
return suggestions;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
package eu.endermite.commandwhitelist.velocity.config;
|
|
||||||
|
|
||||||
import com.moandjiezana.toml.Toml;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class VelocityConfigCache {
|
|
||||||
|
|
||||||
private HashMap<String, List<String>> permList = new HashMap<>();
|
|
||||||
private final String noPermission, noSubCommand, configReloaded;
|
|
||||||
|
|
||||||
|
|
||||||
public VelocityConfigCache(Toml config) {
|
|
||||||
|
|
||||||
Toml messages = config.getTable("messages");
|
|
||||||
noPermission = messages.getString("no-permission", "&cYou don't have permission to do this.");
|
|
||||||
noSubCommand = messages.getString("no-such-subcommand", "&cNo subcommand by that name.");
|
|
||||||
configReloaded = messages.getString("config-reloaded", "&eConfiguration reloaded.");
|
|
||||||
|
|
||||||
Toml groups = config.getTable("commands");
|
|
||||||
|
|
||||||
for (Map.Entry<String, Object> set : groups.entrySet()) {
|
|
||||||
this.permList.put(set.getKey(), (List<String>) set.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashMap<String, List<String>> getPermList() {
|
|
||||||
return permList;
|
|
||||||
}
|
|
||||||
public String getNoPermission() {
|
|
||||||
return noPermission.replaceAll("&", "§");
|
|
||||||
}
|
|
||||||
public String getNoSubCommand() {return noSubCommand.replaceAll("&", "§");}
|
|
||||||
public String getConfigReloaded() {return configReloaded.replaceAll("&", "§");}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
name: CommandWhitelistBungee
|
|
||||||
version: ${project.version}
|
|
||||||
main: eu.endermite.commandwhitelist.bungee.CommandWhitelistBungee
|
|
||||||
author: YouHaveTrouble
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
# This is bungeecord version of the config.
|
|
||||||
messages:
|
|
||||||
prefix: "CommandWhitelist > "
|
|
||||||
command-denied: "No such command."
|
|
||||||
no-permission: "&cYou don't have permission to do this."
|
|
||||||
no-such-subcommand: "&cNo subcommand by that name."
|
|
||||||
config-reloaded: "&eConfiguration reloaded."
|
|
||||||
added-to-whitelist: "&eWhitelisted command &6%s &efor permission &6%s"
|
|
||||||
removed-from-whitelist: "&eRemoved command &6%s &efrom permission &6%s"
|
|
||||||
group-doesnt-exist: "&cGroup doesn't exist or error occured"
|
|
||||||
|
|
||||||
commands:
|
|
||||||
# Permissions that control what commands players can use
|
|
||||||
# you can add unlimited amount of whitelists
|
|
||||||
|
|
||||||
# this will be automatically given to players by default
|
|
||||||
default:
|
|
||||||
- glist
|
|
||||||
- server
|
|
||||||
# commandwhitelist.commands.example
|
|
||||||
example:
|
|
||||||
- example
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
# This is velocity version of the config.
|
|
||||||
[messages]
|
|
||||||
prefix="CommandWhitelist > "
|
|
||||||
command-denied="No such command."
|
|
||||||
subcommand-denied="You cannot use this subcommand"
|
|
||||||
no-permission="&cYou don't have permission to do this."
|
|
||||||
no-such-subcommand="&cNo subcommand by that name."
|
|
||||||
config-reloaded="&eConfiguration reloaded."
|
|
||||||
added-to-whitelist="&eWhitelisted command &6%s &efor permission &6%s"
|
|
||||||
removed-from-whitelist="&eRemoved command &6%s &efrom permission &6%s"
|
|
||||||
group-doesnt-exist="&cGroup doesn't exist or error occured"
|
|
||||||
|
|
||||||
# Permissions that control what commands players can use
|
|
||||||
# you can add unlimited amount of whitelists
|
|
||||||
[commands]
|
|
||||||
# this will be automatically given to players by default
|
|
||||||
default= [
|
|
||||||
"velocity",
|
|
||||||
"server",
|
|
||||||
]
|
|
||||||
# commandwhitelist.commands.example
|
|
||||||
example= [
|
|
||||||
"example"
|
|
||||||
]
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
messages:
|
|
||||||
prefix: "CommandWhitelist > "
|
|
||||||
command-denied: "No such command."
|
|
||||||
subcommand-denied: "You cannot use this subcommand"
|
|
||||||
no-permission: "&cYou don't have permission to do this."
|
|
||||||
no-such-subcommand: "&cNo subcommand by that name."
|
|
||||||
config-reloaded: "&eConfiguration reloaded."
|
|
||||||
added-to-whitelist: "&eWhitelisted command &6%s &efor permission &6%s"
|
|
||||||
removed-from-whitelist: "&eRemoved command &6%s &efrom permission &6%s"
|
|
||||||
group-doesnt-exist: "&cGroup doesn't exist or error occured"
|
|
||||||
|
|
||||||
# To cover the 1% of plugins that don't register their commands and/or aliases properly.
|
|
||||||
# Do not enable if you don't have issues with aliased commands.
|
|
||||||
# This requires server restart to take effect.
|
|
||||||
use-protocollib-to-detect-commands: false
|
|
||||||
|
|
||||||
commands:
|
|
||||||
# Permissions that control what commands players can use
|
|
||||||
# you can add unlimited amount of whitelists
|
|
||||||
|
|
||||||
# this will be automatically given to players by default
|
|
||||||
default:
|
|
||||||
- help
|
|
||||||
- spawn
|
|
||||||
- bal
|
|
||||||
- balance
|
|
||||||
- baltop
|
|
||||||
- pay
|
|
||||||
- r
|
|
||||||
- msg
|
|
||||||
- tpa
|
|
||||||
- tpahere
|
|
||||||
- tpaccept
|
|
||||||
- tpdeny
|
|
||||||
- warp
|
|
||||||
# commandwhitelist.commands.example
|
|
||||||
example:
|
|
||||||
- example
|
|
||||||
|
|
||||||
tabcompletions:
|
|
||||||
# This one is working as a blacklist. Player will not be able
|
|
||||||
# to see/use listed subcommands unless they have specified permission
|
|
||||||
# commandwhitelist.subcommands.example
|
|
||||||
example:
|
|
||||||
- help about
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"id":"commandwhitelist",
|
|
||||||
"name":"CommandWhitelist",
|
|
||||||
"version":"${project.version}",
|
|
||||||
"description":"Control what commands players can use",
|
|
||||||
"authors":["YouHaveTrouble"],
|
|
||||||
"dependencies":[],
|
|
||||||
"main":"eu.endermite.commandwhitelist.velocity.CommandWhitelistVelocity"
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user