mirror of
https://github.com/plexusorg/Plex.git
synced 2025-01-03 14:17:37 +00:00
part 3...?
This commit is contained in:
parent
dd94613b99
commit
4320e789d4
@ -164,6 +164,7 @@ public class Plex extends JavaPlugin
|
||||
PlexLog.log("Punishment System initialized");
|
||||
|
||||
commandBlockerManager = new CommandBlockerManager();
|
||||
getServer().getScheduler().scheduleSyncDelayedTask(this, () -> commandBlockerManager.syncCommands());
|
||||
PlexLog.log("Command Blocker initialized");
|
||||
|
||||
generateWorlds();
|
||||
|
@ -4,7 +4,6 @@ import dev.plex.Plex;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import lombok.Getter;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -16,6 +15,8 @@ public class CommandBlockerManager
|
||||
{
|
||||
private List<BaseCommand> blockedCommands = new ArrayList<>();
|
||||
|
||||
public boolean loadedYet = false;
|
||||
|
||||
public void syncCommands()
|
||||
{
|
||||
blockedCommands.clear();
|
||||
@ -41,7 +42,31 @@ public class CommandBlockerManager
|
||||
pieces.set(3, PlexUtils.messageString("commandBlocked"));
|
||||
}
|
||||
|
||||
Rank rank = Plex.get().getRankManager().getRankFromString(pieces.get(1));
|
||||
Rank rank;
|
||||
|
||||
switch (pieces.get(1))
|
||||
{
|
||||
case "i":
|
||||
rank = Rank.IMPOSTOR;
|
||||
break;
|
||||
case "n":
|
||||
rank = Rank.NONOP;
|
||||
break;
|
||||
case "o":
|
||||
rank = Rank.OP;
|
||||
break;
|
||||
case "a":
|
||||
rank = Rank.ADMIN;
|
||||
break;
|
||||
case "s":
|
||||
rank = Rank.SENIOR_ADMIN;
|
||||
break;
|
||||
case "e":
|
||||
rank = Rank.EXECUTIVE;
|
||||
break;
|
||||
default:
|
||||
rank = Rank.EXECUTIVE;
|
||||
}
|
||||
|
||||
if (pieces.get(0).equals("r"))
|
||||
{
|
||||
@ -49,11 +74,11 @@ public class CommandBlockerManager
|
||||
}
|
||||
else if (pieces.get(0).equals("m"))
|
||||
{
|
||||
blockedCommands.add(new MatchCommand(pieces.get(2), rank, pieces.get(3)));
|
||||
String blockedArgs = pieces.get(2).substring(pieces.get(2).indexOf(' ') + 1);
|
||||
PluginCommand pluginCommand = Plex.get().getServer().getPluginCommand(pieces.get(2).substring(0, pieces.get(2).indexOf(' ')));
|
||||
if (pluginCommand != null)
|
||||
{
|
||||
blockedCommands.add(new MatchCommand(pluginCommand.getName() + " " + blockedArgs, rank, pieces.get(3)));
|
||||
List<String> aliases = pluginCommand.getAliases();
|
||||
for (String alias : aliases)
|
||||
{
|
||||
@ -62,5 +87,7 @@ public class CommandBlockerManager
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loadedYet = true;
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.cmdblocker.BaseCommand;
|
||||
import dev.plex.cmdblocker.MatchCommand;
|
||||
import dev.plex.cmdblocker.RegexCommand;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -16,17 +18,21 @@ public class CmdBlockerListener extends PlexListener
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
if (!plugin.getCommandBlockerManager().loadedYet)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
String message = event.getMessage().substring(1);
|
||||
// check if commands are blocked here
|
||||
// DEFAULT message is named "commandBlocked"
|
||||
for (BaseCommand blockedCommand : plugin.getCommandBlockerManager().getBlockedCommands()) {
|
||||
//first check rank for if it applies
|
||||
//then check if command is blocked
|
||||
if (DataUtils.getPlayer(player.getUniqueId()).getRankFromString().ordinal() > blockedCommand.getRank().ordinal())
|
||||
{
|
||||
return;
|
||||
}
|
||||
boolean isBlocked = false;
|
||||
if (blockedCommand instanceof RegexCommand regexCommand)
|
||||
{
|
||||
// regex
|
||||
if (regexCommand.getRegex().matcher(message).matches())
|
||||
{
|
||||
isBlocked = true;
|
||||
@ -34,7 +40,6 @@ public class CmdBlockerListener extends PlexListener
|
||||
}
|
||||
else if(blockedCommand instanceof MatchCommand matchCommand)
|
||||
{
|
||||
// match command
|
||||
if (message.equalsIgnoreCase(matchCommand.getMessage()) || message.toLowerCase().startsWith(matchCommand.getMessage().toLowerCase() + " "))
|
||||
{
|
||||
isBlocked = true;
|
||||
|
@ -45,7 +45,16 @@ public class ServiceManager
|
||||
{
|
||||
if (!service.isRepeating())
|
||||
{
|
||||
BukkitTask task = Bukkit.getScheduler().runTask(Plex.get(), service::run);
|
||||
int time = service.repeatInSeconds();
|
||||
BukkitTask task;
|
||||
if (time == 0)
|
||||
{
|
||||
task = Bukkit.getScheduler().runTask(Plex.get(), service::run);
|
||||
}
|
||||
else
|
||||
{
|
||||
task = Bukkit.getScheduler().runTaskLater(Plex.get(), service::run, time);
|
||||
}
|
||||
service.setTaskId(task.getTaskId());
|
||||
}
|
||||
else if (service.isRepeating() && service.isAsynchronous())
|
||||
|
@ -7,7 +7,8 @@
|
||||
# Symbols to use:
|
||||
# - r for RegEx
|
||||
# - m for matching
|
||||
# - The ranks are "e" for everyone, "a" for admin and "s" for senior admin
|
||||
# - The ranks are "e" for executive and below, "a" for admin and below, "s" for senior admin and below,
|
||||
######## TODO: DOCUMENT ALL OTHER LETTERS!! ^^^^
|
||||
# - The command is just the command without slashes. Optional arguments are specified as well
|
||||
# - Finally the block message. MUST NOT CONTAIN ":". Use _ to use the default command blocked message as specified in messages.yml, or you can optionally put your own in
|
||||
#
|
||||
@ -16,4 +17,4 @@
|
||||
# - "r:e:(.*:):Plugin specific commands are disabled"
|
||||
blockedCommands:
|
||||
- "m:e:mail sendall:You cannot send messages to everyone on the server"
|
||||
- "r:e:[^ ]+:.*:Plugin specific commands are disabled"
|
||||
- "r:e:^[^ ]+::Plugin specific commands are disabled"
|
Loading…
Reference in New Issue
Block a user