part 4.... . .. .

incomplete
This commit is contained in:
ayunami2000 2022-04-08 02:36:56 -04:00
parent 4320e789d4
commit 9bb316b80b
3 changed files with 50 additions and 56 deletions

View File

@ -164,7 +164,11 @@ public class Plex extends JavaPlugin
PlexLog.log("Punishment System initialized");
commandBlockerManager = new CommandBlockerManager();
getServer().getScheduler().scheduleSyncDelayedTask(this, () -> commandBlockerManager.syncCommands());
// todo: make this a service lmao --v
getServer().getScheduler().scheduleSyncDelayedTask(this, () -> {
commandBlockerManager.syncCommands();
PlexLog.log("Command Blocker commands loaded");
});
PlexLog.log("Command Blocker initialized");
generateWorlds();

View File

@ -1,55 +0,0 @@
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;
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)
{
if (!plugin.getCommandBlockerManager().loadedYet)
{
event.setCancelled(true);
return;
}
Player player = event.getPlayer();
String message = event.getMessage().substring(1);
for (BaseCommand blockedCommand : plugin.getCommandBlockerManager().getBlockedCommands()) {
if (DataUtils.getPlayer(player.getUniqueId()).getRankFromString().ordinal() > blockedCommand.getRank().ordinal())
{
return;
}
boolean isBlocked = false;
if (blockedCommand instanceof RegexCommand regexCommand)
{
if (regexCommand.getRegex().matcher(message).matches())
{
isBlocked = true;
}
}
else if(blockedCommand instanceof MatchCommand matchCommand)
{
if (message.equalsIgnoreCase(matchCommand.getMessage()) || message.toLowerCase().startsWith(matchCommand.getMessage().toLowerCase() + " "))
{
isBlocked = true;
}
}
if (isBlocked)
{
event.setCancelled(true);
player.sendMessage(MiniMessage.miniMessage().deserialize(PlexUtils.messageString("blockedCommandColor") + blockedCommand.getMessage()));
}
}
}
}

View File

@ -1,7 +1,13 @@
package dev.plex.listener.impl;
import dev.plex.cache.DataUtils;
import dev.plex.cache.player.PlayerCache;
import dev.plex.cmdblocker.BaseCommand;
import dev.plex.cmdblocker.MatchCommand;
import dev.plex.cmdblocker.RegexCommand;
import dev.plex.listener.PlexListener;
import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
@ -23,5 +29,44 @@ public class CommandListener extends PlexListener
pl.sendMessage(ChatColor.GRAY + player.getName() + ": " + command);
}
});
if (!plugin.getCommandBlockerManager().loadedYet)
{
event.setCancelled(true);
return;
}
Player player = event.getPlayer();
String message = event.getMessage().substring(1);
for (BaseCommand blockedCommand : plugin.getCommandBlockerManager().getBlockedCommands()) {
if (DataUtils.getPlayer(player.getUniqueId()).getRankFromString().ordinal() > blockedCommand.getRank().ordinal())
{
continue;
}
boolean isBlocked = false;
if (blockedCommand instanceof RegexCommand regexCommand)
{
System.out.println(regexCommand.getRegex());
System.out.println(message);
System.out.println(regexCommand.getRegex().matcher(message).results());
if (regexCommand.getRegex().matcher(message).matches())
{
isBlocked = true;
}
}
else if(blockedCommand instanceof MatchCommand matchCommand)
{
if (message.equalsIgnoreCase(matchCommand.getMatch()) || message.toLowerCase().startsWith(matchCommand.getMatch().toLowerCase() + " "))
{
isBlocked = true;
}
}
if (isBlocked)
{
System.out.println("BLOCKED?!??!???!!!");
event.setCancelled(true);
player.sendMessage(MiniMessage.miniMessage().deserialize(PlexUtils.messageString("blockedCommandColor") + blockedCommand.getMessage()));
return;
}
}
}
}