mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-23 01:27:37 +00:00
Try to improve things
This commit is contained in:
parent
15b50ac8ae
commit
9297eb6703
@ -1,10 +1,12 @@
|
|||||||
package dev.plex.cmdblocker;
|
package dev.plex.cmdblocker;
|
||||||
|
|
||||||
import dev.plex.Plex;
|
import dev.plex.Plex;
|
||||||
|
import dev.plex.PlexBase;
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
import dev.plex.util.PlexLog;
|
import dev.plex.util.PlexLog;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.PluginCommand;
|
import org.bukkit.command.PluginCommand;
|
||||||
import org.bukkit.command.PluginCommandYamlParser;
|
import org.bukkit.command.PluginCommandYamlParser;
|
||||||
@ -16,18 +18,18 @@ import java.util.List;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class CommandBlockerManager
|
public class CommandBlockerManager extends PlexBase
|
||||||
{
|
{
|
||||||
private List<BaseCommand> blockedCommands = new ArrayList<>();
|
private List<BaseCommand> blockedCommands = new ArrayList<>();
|
||||||
|
|
||||||
public boolean loadedYet = false;
|
public boolean loadedYet;
|
||||||
|
|
||||||
public void syncCommands()
|
public void syncCommands()
|
||||||
{
|
{
|
||||||
loadedYet = false;
|
loadedYet = false;
|
||||||
blockedCommands.clear();
|
blockedCommands.clear();
|
||||||
|
|
||||||
List<String> raw = Plex.get().blockedCommands.getStringList("blockedCommands");
|
List<String> raw = plugin.blockedCommands.getStringList("blockedCommands");
|
||||||
|
|
||||||
for (String cmd : raw)
|
for (String cmd : raw)
|
||||||
{
|
{
|
||||||
@ -46,31 +48,12 @@ public class CommandBlockerManager
|
|||||||
message = PlexUtils.messageString("commandBlocked");
|
message = PlexUtils.messageString("commandBlocked");
|
||||||
}
|
}
|
||||||
|
|
||||||
Rank rank;
|
Rank rank = switch (rawRank)
|
||||||
|
{
|
||||||
switch (rawRank)
|
case "e" -> Rank.IMPOSTOR;
|
||||||
{
|
case "a" -> Rank.ADMIN;
|
||||||
case "i":
|
case "s" -> Rank.SENIOR_ADMIN;
|
||||||
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 (rawType.equals("r"))
|
if (rawType.equals("r"))
|
||||||
{
|
{
|
||||||
@ -82,7 +65,7 @@ public class CommandBlockerManager
|
|||||||
if (ind == -1 && regexOrMatch.endsWith(":"))
|
if (ind == -1 && regexOrMatch.endsWith(":"))
|
||||||
{
|
{
|
||||||
String pluginName = regexOrMatch.substring(0, regexOrMatch.length() - 1);
|
String pluginName = regexOrMatch.substring(0, regexOrMatch.length() - 1);
|
||||||
Plugin plugin = Arrays.stream(Plex.get().getServer().getPluginManager().getPlugins()).filter(pl -> pl.getName().equalsIgnoreCase(pluginName)).findAny().orElse(null);
|
Plugin plugin = Arrays.stream(Bukkit.getServer().getPluginManager().getPlugins()).filter(pl -> pl.getName().equalsIgnoreCase(pluginName)).findAny().orElse(null);
|
||||||
if (plugin != null)
|
if (plugin != null)
|
||||||
{
|
{
|
||||||
List<Command> commandList = PluginCommandYamlParser.parse(plugin);
|
List<Command> commandList = PluginCommandYamlParser.parse(plugin);
|
||||||
@ -90,7 +73,8 @@ public class CommandBlockerManager
|
|||||||
{
|
{
|
||||||
blockedCommands.add(new MatchCommand(command.getName(), rank, message));
|
blockedCommands.add(new MatchCommand(command.getName(), rank, message));
|
||||||
blockedCommands.add(new MatchCommand(pluginName + ":" + command.getName(), rank, message));
|
blockedCommands.add(new MatchCommand(pluginName + ":" + command.getName(), rank, message));
|
||||||
for (String alias : command.getAliases()) {
|
for (String alias : command.getAliases())
|
||||||
|
{
|
||||||
blockedCommands.add(new MatchCommand(alias, rank, message));
|
blockedCommands.add(new MatchCommand(alias, rank, message));
|
||||||
blockedCommands.add(new MatchCommand(pluginName + ":" + alias, rank, message));
|
blockedCommands.add(new MatchCommand(pluginName + ":" + alias, rank, message));
|
||||||
}
|
}
|
||||||
@ -98,7 +82,10 @@ public class CommandBlockerManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
String blockedArgs = ind == -1 ? "" : regexOrMatch.substring(ind + 1);
|
String blockedArgs = ind == -1 ? "" : regexOrMatch.substring(ind + 1);
|
||||||
if (!blockedArgs.isEmpty()) blockedArgs = " " + blockedArgs; // necessary in case no args
|
if (!blockedArgs.isEmpty())
|
||||||
|
{
|
||||||
|
blockedArgs = " " + blockedArgs; // necessary in case no args
|
||||||
|
}
|
||||||
PluginCommand pluginCommand = Plex.get().getServer().getPluginCommand(ind == -1 ? regexOrMatch : regexOrMatch.substring(0, ind));
|
PluginCommand pluginCommand = Plex.get().getServer().getPluginCommand(ind == -1 ? regexOrMatch : regexOrMatch.substring(0, ind));
|
||||||
if (pluginCommand != null)
|
if (pluginCommand != null)
|
||||||
{
|
{
|
||||||
@ -116,7 +103,8 @@ public class CommandBlockerManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
PlexLog.debug("Blocked commands:");
|
PlexLog.debug("Blocked commands:");
|
||||||
for (BaseCommand blockedCommand : blockedCommands) {
|
for (BaseCommand blockedCommand : blockedCommands)
|
||||||
|
{
|
||||||
PlexLog.debug(" - {0}", blockedCommand);
|
PlexLog.debug(" - {0}", blockedCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,9 +38,10 @@ public class CommandListener extends PlexListener
|
|||||||
}
|
}
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
String message = event.getMessage().substring(1).stripLeading(); // stripLeading() is VITAL for workaround blocking (/ minecraft:summon)
|
String message = event.getMessage().substring(1).stripLeading(); // stripLeading() is VITAL for workaround blocking (/ minecraft:summon)
|
||||||
for (BaseCommand blockedCommand : plugin.getCommandBlockerManager().getBlockedCommands()) {
|
for (BaseCommand blockedCommand : plugin.getCommandBlockerManager().getBlockedCommands())
|
||||||
|
{
|
||||||
PlexPlayer plexPlayer = DataUtils.getPlayer(player.getUniqueId());
|
PlexPlayer plexPlayer = DataUtils.getPlayer(player.getUniqueId());
|
||||||
if (!plexPlayer.getRepresentedRank().isAtMost(blockedCommand.getRank()))
|
if (!plexPlayer.getRankFromString().isAtMost(blockedCommand.getRank()))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -53,9 +54,9 @@ public class CommandListener extends PlexListener
|
|||||||
isBlocked = true;
|
isBlocked = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(blockedCommand instanceof MatchCommand matchCommand)
|
else if (blockedCommand instanceof MatchCommand matchCommand)
|
||||||
{
|
{
|
||||||
if (message.toLowerCase().startsWith(matchCommand.getMatch().toLowerCase()) /*message.equalsIgnoreCase(matchCommand.getMatch()) || message.toLowerCase().startsWith(matchCommand.getMatch().toLowerCase() + " ")*/)
|
if (message.toLowerCase().startsWith(matchCommand.getMatch().toLowerCase()))
|
||||||
{
|
{
|
||||||
isBlocked = true;
|
isBlocked = true;
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ public class PlexPlayer
|
|||||||
public Rank getRankFromString()
|
public Rank getRankFromString()
|
||||||
{
|
{
|
||||||
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
|
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
|
||||||
if (rank.isEmpty())
|
if (rank.isEmpty() || !isAdminActive())
|
||||||
{
|
{
|
||||||
if (player.isOp())
|
if (player.isOp())
|
||||||
{
|
{
|
||||||
@ -115,13 +115,6 @@ public class PlexPlayer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Rank getRepresentedRank()
|
|
||||||
{
|
|
||||||
int representedLevel = this.getRankFromString().getLevel();
|
|
||||||
if (!this.adminActive) representedLevel = Math.min(Rank.OP.getLevel(), representedLevel);
|
|
||||||
return Rank.values()[representedLevel];
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadPunishments()
|
public void loadPunishments()
|
||||||
{
|
{
|
||||||
if (Plex.get().getStorageType() != StorageType.MONGODB)
|
if (Plex.get().getStorageType() != StorageType.MONGODB)
|
||||||
|
@ -18,7 +18,7 @@ public class ServiceManager
|
|||||||
registerService(new GameRuleService());
|
registerService(new GameRuleService());
|
||||||
registerService(new UpdateCheckerService());
|
registerService(new UpdateCheckerService());
|
||||||
registerService(new AutoWipeService());
|
registerService(new AutoWipeService());
|
||||||
registerService(new CmdBlockerService());
|
registerService(new CommandBlockerService());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startServices()
|
public void startServices()
|
||||||
|
@ -3,9 +3,9 @@ package dev.plex.services.impl;
|
|||||||
import dev.plex.services.AbstractService;
|
import dev.plex.services.AbstractService;
|
||||||
import dev.plex.util.PlexLog;
|
import dev.plex.util.PlexLog;
|
||||||
|
|
||||||
public class CmdBlockerService extends AbstractService
|
public class CommandBlockerService extends AbstractService
|
||||||
{
|
{
|
||||||
public CmdBlockerService()
|
public CommandBlockerService()
|
||||||
{
|
{
|
||||||
super(false, true);
|
super(false, true);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user