mirror of
https://github.com/YouHaveTrouble/CommandWhitelist.git
synced 2026-05-12 06:26:57 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ca18d17c13 | |||
| d7e461cb89 | |||
| 14d0384de0 | |||
| 4edaffaa09 | |||
| 8a431470a2 | |||
| 1362080878 | |||
| c23fd43a70 |
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>eu.endermite</groupId>
|
<groupId>eu.endermite</groupId>
|
||||||
<artifactId>CommandWhitelist</artifactId>
|
<artifactId>CommandWhitelist</artifactId>
|
||||||
<version>1.2.0</version>
|
<version>1.3.0</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>CommandWhitelist</name>
|
<name>CommandWhitelist</name>
|
||||||
@@ -66,6 +66,10 @@
|
|||||||
<id>jitpack.io</id>
|
<id>jitpack.io</id>
|
||||||
<url>https://jitpack.io</url>
|
<url>https://jitpack.io</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>dmulloy2-repo</id>
|
||||||
|
<url>https://repo.dmulloy2.net/nexus/repository/public/</url>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@@ -82,11 +86,15 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.PaperMC</groupId>
|
<groupId>io.github.waterfallmc</groupId>
|
||||||
<artifactId>Waterfall</artifactId>
|
<artifactId>waterfall-api</artifactId>
|
||||||
<version>1.16</version>
|
<version>1.15-SNAPSHOT</version>
|
||||||
<scope>system</scope>
|
<scope>provided</scope>
|
||||||
<systemPath>${project.basedir}/lib/waterfall-366.jar</systemPath>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.comphenix.protocol</groupId>
|
||||||
|
<artifactId>ProtocolLib</artifactId>
|
||||||
|
<version>4.5.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
Command Whitelist is a plugin that allows you to control
|
||||||
|
precisely what commands players can see and use.
|
||||||
|
|
||||||
|
<h3>Plugin Features</h3>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>You can lock certain commands behind permission
|
||||||
|
<li>Overwrites default "no such command" message with your branding
|
||||||
|
<li>Blocks tab completion on spigot and bungeecord*</li>
|
||||||
|
<li>Blocks command execution on spigot and bungeecord</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
\*This only works on Waterfall and its forks
|
||||||
|
|
||||||
|
Having some issues? Make sure to check out <a href="https://github.com/YouHaveTrouble/CommandWhitelist/wiki">Plugin Wiki</a>.
|
||||||
|
|
||||||
|
Found a bug or you think plugin is missing an important feature? <a href="https://github.com/YouHaveTrouble/CommandWhitelist/issues">Create an issue</a>.
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
package eu.endermite.commandwhitelist.spigot;
|
package eu.endermite.commandwhitelist.spigot;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.ProtocolLib;
|
||||||
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
import eu.endermite.commandwhitelist.spigot.command.MainCommand;
|
import eu.endermite.commandwhitelist.spigot.command.MainCommand;
|
||||||
import eu.endermite.commandwhitelist.spigot.config.ConfigCache;
|
import eu.endermite.commandwhitelist.spigot.config.ConfigCache;
|
||||||
|
import eu.endermite.commandwhitelist.spigot.listeners.LegacyPlayerTabChatCompleteListener;
|
||||||
import eu.endermite.commandwhitelist.spigot.listeners.PlayerCommandPreProcessListener;
|
import eu.endermite.commandwhitelist.spigot.listeners.PlayerCommandPreProcessListener;
|
||||||
import eu.endermite.commandwhitelist.spigot.listeners.PlayerCommandSendListener;
|
import eu.endermite.commandwhitelist.spigot.listeners.PlayerCommandSendListener;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@@ -14,15 +17,30 @@ public class CommandWhitelist extends JavaPlugin {
|
|||||||
|
|
||||||
private static CommandWhitelist commandWhitelist;
|
private static CommandWhitelist commandWhitelist;
|
||||||
private static ConfigCache configCache;
|
private static ConfigCache configCache;
|
||||||
|
private static boolean isLegacy;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
|
||||||
commandWhitelist = this;
|
commandWhitelist = this;
|
||||||
|
|
||||||
|
isLegacy = checkLegacy();
|
||||||
|
|
||||||
|
|
||||||
reloadPluginConfig();
|
reloadPluginConfig();
|
||||||
|
|
||||||
getServer().getPluginManager().registerEvents(new PlayerCommandPreProcessListener(), this);
|
getServer().getPluginManager().registerEvents(new PlayerCommandPreProcessListener(), this);
|
||||||
|
if (!isLegacy) {
|
||||||
getServer().getPluginManager().registerEvents(new PlayerCommandSendListener(), this);
|
getServer().getPluginManager().registerEvents(new PlayerCommandSendListener(), this);
|
||||||
|
} else {
|
||||||
|
getLogger().info(ChatColor.AQUA+"Running in legacy mode...");
|
||||||
|
if (getServer().getPluginManager().getPlugin("ProtocolLib") != null) {
|
||||||
|
LegacyPlayerTabChatCompleteListener.protocol(this);
|
||||||
|
} else {
|
||||||
|
getLogger().info(ChatColor.YELLOW+"ProtocolLib is required for tab completion blocking!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
getCommand("commandwhitelist").setExecutor(new MainCommand());
|
getCommand("commandwhitelist").setExecutor(new MainCommand());
|
||||||
getCommand("commandwhitelist").setTabCompleter(new MainCommand());
|
getCommand("commandwhitelist").setTabCompleter(new MainCommand());
|
||||||
|
|
||||||
@@ -37,13 +55,46 @@ public class CommandWhitelist extends JavaPlugin {
|
|||||||
public void reloadPluginConfig(CommandSender sender) {
|
public void reloadPluginConfig(CommandSender sender) {
|
||||||
getServer().getScheduler().runTaskAsynchronously(this, () -> {
|
getServer().getScheduler().runTaskAsynchronously(this, () -> {
|
||||||
reloadPluginConfig();
|
reloadPluginConfig();
|
||||||
|
if (!isLegacy()) {
|
||||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
p.updateCommands();
|
p.updateCommands();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().getPrefix() + CommandWhitelist.getConfigCache().getConfigReloaded()));
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().getPrefix() + CommandWhitelist.getConfigCache().getConfigReloaded()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isLegacy() {
|
||||||
|
return isLegacy;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkLegacy() {
|
||||||
|
|
||||||
|
String version = getServer().getVersion();
|
||||||
|
|
||||||
|
if (version.contains("1.8")) {
|
||||||
|
return true;
|
||||||
|
} else if (version.contains("1.9")) {
|
||||||
|
return true;
|
||||||
|
} else if (version.contains("1.10")) {
|
||||||
|
return true;
|
||||||
|
} else if (version.contains("1.11")) {
|
||||||
|
return true;
|
||||||
|
} else if (version.contains("1.12")) {
|
||||||
|
return true;
|
||||||
|
} else if (version.contains("1.13")) {
|
||||||
|
return false;
|
||||||
|
} else if (version.contains("1.14")) {
|
||||||
|
return false;
|
||||||
|
} else if (version.contains("1.15")) {
|
||||||
|
return false;
|
||||||
|
} else if (version.contains("1.16")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public static CommandWhitelist getPlugin() {return commandWhitelist;}
|
public static CommandWhitelist getPlugin() {return commandWhitelist;}
|
||||||
public static ConfigCache getConfigCache() {return configCache;}
|
public static ConfigCache getConfigCache() {return configCache;}
|
||||||
}
|
}
|
||||||
|
|||||||
+110
@@ -0,0 +1,110 @@
|
|||||||
|
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.spigot.CommandWhitelist;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
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 = new ArrayList<>();
|
||||||
|
for (Map.Entry<String, List<String>> s : CommandWhitelist.getConfigCache().getPermList().entrySet()) {
|
||||||
|
if (player.hasPermission("commandwhitelist.commands." + s.getKey())) {
|
||||||
|
commandList.addAll(s.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
System.out.println(command);
|
||||||
|
|
||||||
|
for (Map.Entry<String, List<String>> s : CommandWhitelist.getConfigCache().getPermList().entrySet()) {
|
||||||
|
if (player.hasPermission("commandwhitelist.commands." + s.getKey())) {
|
||||||
|
for (String comm : s.getValue()) {
|
||||||
|
comm = comm.toLowerCase();
|
||||||
|
if (command.equalsIgnoreCase("/"+comm))
|
||||||
|
return;
|
||||||
|
else if (command.startsWith("/" + comm + " ")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
event.setCancelled(true);
|
||||||
|
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
name: CommandWhitelist
|
name: CommandWhitelist
|
||||||
version: ${project.version}
|
version: ${project.version}
|
||||||
main: eu.endermite.commandwhitelist.spigot.CommandWhitelist
|
main: eu.endermite.commandwhitelist.spigot.CommandWhitelist
|
||||||
api-version: 1.13
|
|
||||||
authors: [YouHaveTrouble]
|
authors: [YouHaveTrouble]
|
||||||
|
softdepend:
|
||||||
|
- ProtocolLib
|
||||||
description: Control what commands players can use
|
description: Control what commands players can use
|
||||||
commands:
|
commands:
|
||||||
commandwhitelist:
|
commandwhitelist:
|
||||||
|
|||||||
Reference in New Issue
Block a user