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");
|
PlexLog.log("Punishment System initialized");
|
||||||
|
|
||||||
commandBlockerManager = new CommandBlockerManager();
|
commandBlockerManager = new CommandBlockerManager();
|
||||||
|
getServer().getScheduler().scheduleSyncDelayedTask(this, () -> commandBlockerManager.syncCommands());
|
||||||
PlexLog.log("Command Blocker initialized");
|
PlexLog.log("Command Blocker initialized");
|
||||||
|
|
||||||
generateWorlds();
|
generateWorlds();
|
||||||
|
@ -4,7 +4,6 @@ import dev.plex.Plex;
|
|||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
|
||||||
import org.bukkit.command.PluginCommand;
|
import org.bukkit.command.PluginCommand;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -16,6 +15,8 @@ public class CommandBlockerManager
|
|||||||
{
|
{
|
||||||
private List<BaseCommand> blockedCommands = new ArrayList<>();
|
private List<BaseCommand> blockedCommands = new ArrayList<>();
|
||||||
|
|
||||||
|
public boolean loadedYet = false;
|
||||||
|
|
||||||
public void syncCommands()
|
public void syncCommands()
|
||||||
{
|
{
|
||||||
blockedCommands.clear();
|
blockedCommands.clear();
|
||||||
@ -41,7 +42,31 @@ public class CommandBlockerManager
|
|||||||
pieces.set(3, PlexUtils.messageString("commandBlocked"));
|
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"))
|
if (pieces.get(0).equals("r"))
|
||||||
{
|
{
|
||||||
@ -49,11 +74,11 @@ public class CommandBlockerManager
|
|||||||
}
|
}
|
||||||
else if (pieces.get(0).equals("m"))
|
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);
|
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(' ')));
|
PluginCommand pluginCommand = Plex.get().getServer().getPluginCommand(pieces.get(2).substring(0, pieces.get(2).indexOf(' ')));
|
||||||
if (pluginCommand != null)
|
if (pluginCommand != null)
|
||||||
{
|
{
|
||||||
|
blockedCommands.add(new MatchCommand(pluginCommand.getName() + " " + blockedArgs, rank, pieces.get(3)));
|
||||||
List<String> aliases = pluginCommand.getAliases();
|
List<String> aliases = pluginCommand.getAliases();
|
||||||
for (String alias : aliases)
|
for (String alias : aliases)
|
||||||
{
|
{
|
||||||
@ -62,5 +87,7 @@ public class CommandBlockerManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loadedYet = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package dev.plex.listener.impl;
|
package dev.plex.listener.impl;
|
||||||
|
|
||||||
|
import dev.plex.cache.DataUtils;
|
||||||
import dev.plex.cmdblocker.BaseCommand;
|
import dev.plex.cmdblocker.BaseCommand;
|
||||||
import dev.plex.cmdblocker.MatchCommand;
|
import dev.plex.cmdblocker.MatchCommand;
|
||||||
import dev.plex.cmdblocker.RegexCommand;
|
import dev.plex.cmdblocker.RegexCommand;
|
||||||
import dev.plex.listener.PlexListener;
|
import dev.plex.listener.PlexListener;
|
||||||
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -16,17 +18,21 @@ public class CmdBlockerListener extends PlexListener
|
|||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
|
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
|
||||||
{
|
{
|
||||||
|
if (!plugin.getCommandBlockerManager().loadedYet)
|
||||||
|
{
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
String message = event.getMessage().substring(1);
|
String message = event.getMessage().substring(1);
|
||||||
// check if commands are blocked here
|
|
||||||
// DEFAULT message is named "commandBlocked"
|
|
||||||
for (BaseCommand blockedCommand : plugin.getCommandBlockerManager().getBlockedCommands()) {
|
for (BaseCommand blockedCommand : plugin.getCommandBlockerManager().getBlockedCommands()) {
|
||||||
//first check rank for if it applies
|
if (DataUtils.getPlayer(player.getUniqueId()).getRankFromString().ordinal() > blockedCommand.getRank().ordinal())
|
||||||
//then check if command is blocked
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
boolean isBlocked = false;
|
boolean isBlocked = false;
|
||||||
if (blockedCommand instanceof RegexCommand regexCommand)
|
if (blockedCommand instanceof RegexCommand regexCommand)
|
||||||
{
|
{
|
||||||
// regex
|
|
||||||
if (regexCommand.getRegex().matcher(message).matches())
|
if (regexCommand.getRegex().matcher(message).matches())
|
||||||
{
|
{
|
||||||
isBlocked = true;
|
isBlocked = true;
|
||||||
@ -34,7 +40,6 @@ public class CmdBlockerListener extends PlexListener
|
|||||||
}
|
}
|
||||||
else if(blockedCommand instanceof MatchCommand matchCommand)
|
else if(blockedCommand instanceof MatchCommand matchCommand)
|
||||||
{
|
{
|
||||||
// match command
|
|
||||||
if (message.equalsIgnoreCase(matchCommand.getMessage()) || message.toLowerCase().startsWith(matchCommand.getMessage().toLowerCase() + " "))
|
if (message.equalsIgnoreCase(matchCommand.getMessage()) || message.toLowerCase().startsWith(matchCommand.getMessage().toLowerCase() + " "))
|
||||||
{
|
{
|
||||||
isBlocked = true;
|
isBlocked = true;
|
||||||
|
@ -45,7 +45,16 @@ public class ServiceManager
|
|||||||
{
|
{
|
||||||
if (!service.isRepeating())
|
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());
|
service.setTaskId(task.getTaskId());
|
||||||
}
|
}
|
||||||
else if (service.isRepeating() && service.isAsynchronous())
|
else if (service.isRepeating() && service.isAsynchronous())
|
||||||
|
@ -7,7 +7,8 @@
|
|||||||
# Symbols to use:
|
# Symbols to use:
|
||||||
# - r for RegEx
|
# - r for RegEx
|
||||||
# - m for matching
|
# - 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
|
# - 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
|
# - 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"
|
# - "r:e:(.*:):Plugin specific commands are disabled"
|
||||||
blockedCommands:
|
blockedCommands:
|
||||||
- "m:e:mail sendall:You cannot send messages to everyone on the server"
|
- "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