mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-23 01:27:37 +00:00
commit
08a004d65f
@ -2,15 +2,11 @@ package dev.plex.command.blocker;
|
|||||||
|
|
||||||
import dev.plex.PlexBase;
|
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.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.*;
|
import org.bukkit.command.*;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.SimplePluginManager;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@ -21,18 +17,11 @@ public class CommandBlockerManager extends PlexBase
|
|||||||
|
|
||||||
public boolean loadedYet;
|
public boolean loadedYet;
|
||||||
|
|
||||||
private static CommandMap getCommandMap()
|
|
||||||
{
|
|
||||||
return plugin.getServer().getCommandMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void syncCommands()
|
public void syncCommands()
|
||||||
{
|
{
|
||||||
loadedYet = false;
|
loadedYet = false;
|
||||||
blockedCommands.clear();
|
blockedCommands.clear();
|
||||||
|
|
||||||
CommandMap commandMap = getCommandMap();
|
|
||||||
|
|
||||||
List<String> raw = plugin.blockedCommands.getStringList("blockedCommands");
|
List<String> raw = plugin.blockedCommands.getStringList("blockedCommands");
|
||||||
|
|
||||||
for (String cmd : raw)
|
for (String cmd : raw)
|
||||||
@ -93,13 +82,12 @@ public class CommandBlockerManager extends PlexBase
|
|||||||
}
|
}
|
||||||
String cmdForSearch = ind == -1 ? regexOrMatch : regexOrMatch.substring(0, ind);
|
String cmdForSearch = ind == -1 ? regexOrMatch : regexOrMatch.substring(0, ind);
|
||||||
PluginCommand pluginCommand = Bukkit.getServer().getPluginCommand(cmdForSearch);
|
PluginCommand pluginCommand = Bukkit.getServer().getPluginCommand(cmdForSearch);
|
||||||
Plugin plugin = null;
|
Plugin pl = null;
|
||||||
if (pluginCommand != null) plugin = pluginCommand.getPlugin();
|
if (pluginCommand != null) pl = pluginCommand.getPlugin();
|
||||||
Command command = null;
|
Command command = plugin.getServer().getCommandMap().getCommand(cmdForSearch);
|
||||||
if (commandMap != null) command = commandMap.getCommand(cmdForSearch);
|
|
||||||
if (command != null)
|
if (command != null)
|
||||||
{
|
{
|
||||||
String pluginName = plugin == null ? null : plugin.getName();
|
String pluginName = pl == null ? null : pl.getName();
|
||||||
blockedCommands.add(new MatchCommand(command.getName() + blockedArgs, rank, message));
|
blockedCommands.add(new MatchCommand(command.getName() + blockedArgs, rank, message));
|
||||||
if (pluginName != null) blockedCommands.add(new MatchCommand(pluginName + ":" + command.getName() + blockedArgs, rank, message));
|
if (pluginName != null) blockedCommands.add(new MatchCommand(pluginName + ":" + command.getName() + blockedArgs, rank, message));
|
||||||
List<String> aliases = command.getAliases();
|
List<String> aliases = command.getAliases();
|
||||||
|
@ -55,7 +55,7 @@ public class CommandListener extends PlexListener
|
|||||||
}
|
}
|
||||||
else if (blockedCommand instanceof MatchCommand matchCommand)
|
else if (blockedCommand instanceof MatchCommand matchCommand)
|
||||||
{
|
{
|
||||||
if (message.toLowerCase().startsWith(matchCommand.getMatch().toLowerCase()))
|
if (message.equalsIgnoreCase(matchCommand.getMatch()) || message.toLowerCase().startsWith(matchCommand.getMatch().toLowerCase() + " "))
|
||||||
{
|
{
|
||||||
isBlocked = true;
|
isBlocked = true;
|
||||||
}
|
}
|
||||||
@ -63,8 +63,8 @@ public class CommandListener extends PlexListener
|
|||||||
if (isBlocked)
|
if (isBlocked)
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
//PlexLog.debug("Command blocked.");
|
//PlexLog.debug("Command blocked: " + blockedCommand);
|
||||||
player.sendMessage(PlexUtils.mmDeserialize(PlexUtils.messageString("blockedCommandColor") + blockedCommand.getMessage()));
|
player.sendMessage(PlexUtils.mmDeserialize(blockedCommand.getMessage()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,11 +7,7 @@ import dev.plex.PlexBase;
|
|||||||
import dev.plex.config.Config;
|
import dev.plex.config.Config;
|
||||||
import dev.plex.storage.StorageType;
|
import dev.plex.storage.StorageType;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.minimessage.Context;
|
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import net.kyori.adventure.text.minimessage.ParsingException;
|
|
||||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue;
|
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
import net.kyori.adventure.text.minimessage.tag.standard.*;
|
import net.kyori.adventure.text.minimessage.tag.standard.*;
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
@ -22,8 +18,6 @@ import org.bukkit.command.Command;
|
|||||||
import org.bukkit.command.PluginCommandYamlParser;
|
import org.bukkit.command.PluginCommandYamlParser;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.json.simple.parser.JSONParser;
|
import org.json.simple.parser.JSONParser;
|
||||||
import org.json.simple.parser.ParseException;
|
import org.json.simple.parser.ParseException;
|
||||||
@ -163,32 +157,17 @@ public class PlexUtils extends PlexBase
|
|||||||
StandardTags.reset()
|
StandardTags.reset()
|
||||||
).build()).build();
|
).build()).build();
|
||||||
|
|
||||||
private static final MiniMessage eggMessage = MiniMessage.builder().tags(new TagResolver()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public @Nullable Tag resolve(@NotNull String name, @NotNull ArgumentQueue arguments, @NotNull Context ctx) throws ParsingException
|
|
||||||
{
|
|
||||||
return StandardTags.rainbow().resolve("rainbow", arguments, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean has(@NotNull String name)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
).build();
|
|
||||||
|
|
||||||
public static Component mmDeserialize(String input)
|
public static Component mmDeserialize(String input)
|
||||||
{
|
{
|
||||||
/*Calendar calendar = Calendar.getInstance();
|
boolean aprilFools = true; // true by default
|
||||||
MiniMessage mm = (calendar.get(Calendar.MONTH) == Calendar.APRIL && calendar.get(Calendar.DAY_OF_MONTH) == 1 && (!plugin.config.contains("april_fools") || plugin.config.getBoolean("april_fools"))) ? eggMessage : safeMessage;
|
if (plugin.config.contains("april_fools"))
|
||||||
return mm.deserialize(PlainTextComponentSerializer.plainText().serialize(LegacyComponentSerializer.legacySection().deserialize(input)));*/
|
{
|
||||||
boolean aprilFools = plugin.config.getBoolean("april_fools");
|
aprilFools = plugin.config.getBoolean("april_fools");
|
||||||
|
}
|
||||||
LocalDateTime date = LocalDateTime.now();
|
LocalDateTime date = LocalDateTime.now();
|
||||||
if (aprilFools && date.getMonth() == Month.APRIL && date.getDayOfMonth() == 1)
|
if (aprilFools && date.getMonth() == Month.APRIL && date.getDayOfMonth() == 1)
|
||||||
{
|
{
|
||||||
Component component = PlainTextComponentSerializer.plainText().deserialize(input);
|
Component component = MiniMessage.miniMessage().deserialize(input); // removes existing tags
|
||||||
return MiniMessage.miniMessage().deserialize("<rainbow>" + PlainTextComponentSerializer.plainText().serialize(component));
|
return MiniMessage.miniMessage().deserialize("<rainbow>" + PlainTextComponentSerializer.plainText().serialize(component));
|
||||||
}
|
}
|
||||||
return MiniMessage.miniMessage().deserialize(input);
|
return MiniMessage.miniMessage().deserialize(input);
|
||||||
|
@ -16,6 +16,6 @@
|
|||||||
# - "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"
|
||||||
blockedCommands:
|
blockedCommands:
|
||||||
- "r:e:^[^ :]+::Plugin specific commands are disabled."
|
- "r:e:^[^ :]+::<gray>Plugin specific commands are disabled."
|
||||||
- "m:e:mail sendall:You cannot send messages to everyone on the server."
|
- "m:e:mail sendall:<gray>You cannot send messages to everyone on the server."
|
||||||
- "m:e:mail sendtempall:You cannot send messages to everyone on the server."
|
- "m:e:mail sendtempall:<gray>You cannot send messages to everyone on the server."
|
@ -167,8 +167,7 @@ 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."
|
||||||
blockedCommandColor: "<gray>"
|
commandBlocked: "<gray>That command is blocked."
|
||||||
commandBlocked: "That command is blocked."
|
|
||||||
# 0 - The command sender
|
# 0 - The command sender
|
||||||
# 1 - The message being said
|
# 1 - The message being said
|
||||||
sayCommand: "[Server: {0}] {1}"
|
sayCommand: "[Server: {0}] {1}"
|
Loading…
Reference in New Issue
Block a user