mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-23 01:27:37 +00:00
part 1
This commit is contained in:
parent
294f8db528
commit
583394d22e
@ -8,6 +8,7 @@ import dev.plex.cache.player.PlayerCache;
|
|||||||
import dev.plex.cache.player.SQLPlayerData;
|
import dev.plex.cache.player.SQLPlayerData;
|
||||||
import dev.plex.cache.sql.SQLNotes;
|
import dev.plex.cache.sql.SQLNotes;
|
||||||
import dev.plex.cache.sql.SQLPunishment;
|
import dev.plex.cache.sql.SQLPunishment;
|
||||||
|
import dev.plex.cmdblocker.CommandBlockerManager;
|
||||||
import dev.plex.config.Config;
|
import dev.plex.config.Config;
|
||||||
import dev.plex.handlers.CommandHandler;
|
import dev.plex.handlers.CommandHandler;
|
||||||
import dev.plex.handlers.ListenerHandler;
|
import dev.plex.handlers.ListenerHandler;
|
||||||
@ -44,6 +45,7 @@ public class Plex extends JavaPlugin
|
|||||||
public Config config;
|
public Config config;
|
||||||
public Config messages;
|
public Config messages;
|
||||||
public Config indefBans;
|
public Config indefBans;
|
||||||
|
public Config blockedCommands;
|
||||||
|
|
||||||
public File modulesFolder;
|
public File modulesFolder;
|
||||||
private StorageType storageType = StorageType.SQLITE;
|
private StorageType storageType = StorageType.SQLITE;
|
||||||
@ -62,6 +64,7 @@ public class Plex extends JavaPlugin
|
|||||||
private RankManager rankManager;
|
private RankManager rankManager;
|
||||||
private ServiceManager serviceManager;
|
private ServiceManager serviceManager;
|
||||||
private PunishmentManager punishmentManager;
|
private PunishmentManager punishmentManager;
|
||||||
|
private CommandBlockerManager commandBlockerManager;
|
||||||
|
|
||||||
private AdminList adminList;
|
private AdminList adminList;
|
||||||
private UpdateChecker updateChecker;
|
private UpdateChecker updateChecker;
|
||||||
@ -79,6 +82,7 @@ public class Plex extends JavaPlugin
|
|||||||
config = new Config(this, "config.yml");
|
config = new Config(this, "config.yml");
|
||||||
messages = new Config(this, "messages.yml");
|
messages = new Config(this, "messages.yml");
|
||||||
indefBans = new Config(this, "indefbans.yml");
|
indefBans = new Config(this, "indefbans.yml");
|
||||||
|
blockedCommands = new Config(this, "commands.yml");
|
||||||
build.load(this);
|
build.load(this);
|
||||||
|
|
||||||
modulesFolder = new File(this.getDataFolder() + File.separator + "modules");
|
modulesFolder = new File(this.getDataFolder() + File.separator + "modules");
|
||||||
@ -99,6 +103,7 @@ public class Plex extends JavaPlugin
|
|||||||
messages.load();
|
messages.load();
|
||||||
// Don't add default entries to indefinite ban file
|
// Don't add default entries to indefinite ban file
|
||||||
indefBans.load(false);
|
indefBans.load(false);
|
||||||
|
blockedCommands.load();
|
||||||
|
|
||||||
sqlConnection = new SQLConnection();
|
sqlConnection = new SQLConnection();
|
||||||
mongoConnection = new MongoConnection();
|
mongoConnection = new MongoConnection();
|
||||||
@ -158,6 +163,9 @@ public class Plex extends JavaPlugin
|
|||||||
punishmentManager.mergeIndefiniteBans();
|
punishmentManager.mergeIndefiniteBans();
|
||||||
PlexLog.log("Punishment System initialized");
|
PlexLog.log("Punishment System initialized");
|
||||||
|
|
||||||
|
commandBlockerManager = new CommandBlockerManager();
|
||||||
|
PlexLog.log("Command Blocker initialized");
|
||||||
|
|
||||||
generateWorlds();
|
generateWorlds();
|
||||||
|
|
||||||
serviceManager = new ServiceManager();
|
serviceManager = new ServiceManager();
|
||||||
|
17
src/main/java/dev/plex/cmdblocker/BaseCommand.java
Normal file
17
src/main/java/dev/plex/cmdblocker/BaseCommand.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package dev.plex.cmdblocker;
|
||||||
|
|
||||||
|
import dev.plex.rank.enums.Rank;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class BaseCommand
|
||||||
|
{
|
||||||
|
public final Rank rank;
|
||||||
|
public final String message;
|
||||||
|
|
||||||
|
public BaseCommand(Rank r, String m)
|
||||||
|
{
|
||||||
|
rank = r;
|
||||||
|
message = m;
|
||||||
|
}
|
||||||
|
}
|
46
src/main/java/dev/plex/cmdblocker/CommandBlockerManager.java
Normal file
46
src/main/java/dev/plex/cmdblocker/CommandBlockerManager.java
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package dev.plex.cmdblocker;
|
||||||
|
|
||||||
|
import dev.plex.Plex;
|
||||||
|
import dev.plex.rank.enums.Rank;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class CommandBlockerManager
|
||||||
|
{
|
||||||
|
private List<BaseCommand> blockedCommands = new ArrayList<>();
|
||||||
|
|
||||||
|
public void syncCommands()
|
||||||
|
{
|
||||||
|
blockedCommands.clear();
|
||||||
|
|
||||||
|
List<String> raw = Plex.get().blockedCommands.getStringList("blockedCommands");
|
||||||
|
|
||||||
|
for (String cmd : raw)
|
||||||
|
{
|
||||||
|
List<String> pieces = new ArrayList<>();
|
||||||
|
|
||||||
|
int lastDelim = cmd.lastIndexOf(':');
|
||||||
|
|
||||||
|
String cmdWithoutMsg = cmd.substring(0, lastDelim);
|
||||||
|
String[] rawPieces = cmdWithoutMsg.split(":", 3);
|
||||||
|
|
||||||
|
pieces.add(rawPieces[0].toLowerCase()); // type
|
||||||
|
pieces.add(rawPieces[1].toLowerCase()); // rank
|
||||||
|
pieces.add(rawPieces[2]); // RegEx or match
|
||||||
|
pieces.add(cmd.substring(lastDelim + 1)); // Message (w/o : in it)
|
||||||
|
|
||||||
|
Rank rank = Plex.get().getRankManager().getRankFromString(pieces.get(1));
|
||||||
|
|
||||||
|
if (pieces.get(0).equals("r"))
|
||||||
|
{
|
||||||
|
blockedCommands.add(new RegexCommand(Pattern.compile(pieces.get(2)), rank, pieces.get(3)));
|
||||||
|
}
|
||||||
|
else if (pieces.get(0).equals("m"))
|
||||||
|
{
|
||||||
|
blockedCommands.add(new MatchCommand(pieces.get(2), rank, pieces.get(3)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
16
src/main/java/dev/plex/cmdblocker/MatchCommand.java
Normal file
16
src/main/java/dev/plex/cmdblocker/MatchCommand.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package dev.plex.cmdblocker;
|
||||||
|
|
||||||
|
import dev.plex.rank.enums.Rank;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class MatchCommand extends BaseCommand
|
||||||
|
{
|
||||||
|
public final String match;
|
||||||
|
|
||||||
|
public MatchCommand(String r1, Rank r2, String m1)
|
||||||
|
{
|
||||||
|
super(r2, m1);
|
||||||
|
match = r1;
|
||||||
|
}
|
||||||
|
}
|
18
src/main/java/dev/plex/cmdblocker/RegexCommand.java
Normal file
18
src/main/java/dev/plex/cmdblocker/RegexCommand.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package dev.plex.cmdblocker;
|
||||||
|
|
||||||
|
import dev.plex.rank.enums.Rank;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class RegexCommand extends BaseCommand
|
||||||
|
{
|
||||||
|
public final Pattern regex;
|
||||||
|
|
||||||
|
public RegexCommand(Pattern r1, Rank r2, String m1)
|
||||||
|
{
|
||||||
|
super(r2, m1);
|
||||||
|
regex = r1;
|
||||||
|
}
|
||||||
|
}
|
@ -18,6 +18,7 @@ import dev.plex.util.PlexLog;
|
|||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -51,13 +52,16 @@ public class PlexCMD extends PlexCommand
|
|||||||
plugin.indefBans.load(false);
|
plugin.indefBans.load(false);
|
||||||
plugin.getPunishmentManager().mergeIndefiniteBans();
|
plugin.getPunishmentManager().mergeIndefiniteBans();
|
||||||
send(sender, "Reloaded indefinite bans");
|
send(sender, "Reloaded indefinite bans");
|
||||||
|
plugin.blockedCommands.load();
|
||||||
|
plugin.getCommandBlockerManager().syncCommands();
|
||||||
|
send(sender, "Reloaded blocked commands file");
|
||||||
plugin.getRankManager().importDefaultRanks();
|
plugin.getRankManager().importDefaultRanks();
|
||||||
send(sender, "Imported ranks");
|
send(sender, "Imported ranks");
|
||||||
send(sender, "Plex successfully reloaded.");
|
|
||||||
plugin.setSystem(plugin.config.getString("system"));
|
plugin.setSystem(plugin.config.getString("system"));
|
||||||
plugin.getServiceManager().endServices();
|
plugin.getServiceManager().endServices();
|
||||||
plugin.getServiceManager().startServices();
|
plugin.getServiceManager().startServices();
|
||||||
PlexLog.debug("Restarted services");
|
PlexLog.debug("Restarted services");
|
||||||
|
send(sender, "Plex successfully reloaded.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
else if (args[0].equalsIgnoreCase("redis"))
|
else if (args[0].equalsIgnoreCase("redis"))
|
||||||
|
19
src/main/java/dev/plex/listener/impl/CmdBlockerListener.java
Normal file
19
src/main/java/dev/plex/listener/impl/CmdBlockerListener.java
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package dev.plex.listener.impl;
|
||||||
|
|
||||||
|
import dev.plex.listener.PlexListener;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
|
||||||
|
public class CmdBlockerListener extends PlexListener
|
||||||
|
{
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
|
||||||
|
{
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
String message = event.getMessage().substring(1);
|
||||||
|
// check if commands are blocked here
|
||||||
|
// DEFAULT message is named "commandBlocked"
|
||||||
|
}
|
||||||
|
}
|
19
src/main/resources/commands.yml
Normal file
19
src/main/resources/commands.yml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#
|
||||||
|
# Command Blocker
|
||||||
|
#
|
||||||
|
# Format:
|
||||||
|
# - "<regex or match>:<rank>:command name no slash:Block message"
|
||||||
|
#
|
||||||
|
# Symbols to use:
|
||||||
|
# - r for RegEx
|
||||||
|
# - m for matching
|
||||||
|
# - The ranks are "e" for everyone, "a" for admin and "s" for senior admin
|
||||||
|
# - 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
|
||||||
|
#
|
||||||
|
# So these would be valid:
|
||||||
|
# - "m:e:mail sendall:You cannot send messages to everyone on the server"
|
||||||
|
# - "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"
|
@ -166,4 +166,5 @@ noRemovedEntities: "<gray>No entities were removed."
|
|||||||
removedMobs: "<red>{0} - Removed {1} mobs"
|
removedMobs: "<red>{0} - Removed {1} mobs"
|
||||||
autoWipeDisabled: "<gray>Item wiping is currently disabled in the config!"
|
autoWipeDisabled: "<gray>Item wiping is currently disabled in the config!"
|
||||||
allowDropsDisabled: "<gray>No longer allowing drops from players."
|
allowDropsDisabled: "<gray>No longer allowing drops from players."
|
||||||
allowDropsEnabled: "<gray>Now allowing drops from players."
|
allowDropsEnabled: "<gray>Now allowing drops from players."
|
||||||
|
commandBlocked: "<gray>This command is blocked"
|
Loading…
Reference in New Issue
Block a user