Skip to content

Commit

Permalink
do not parse markdown for messages
Browse files Browse the repository at this point in the history
  • Loading branch information
YouHaveTrouble committed Oct 24, 2021
1 parent 7c3a06e commit 48fbd59
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 46 deletions.
2 changes: 1 addition & 1 deletion CommandWhitelistBukkit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId>
<version>2.2.0</version>
<version>2.2.1</version>
</parent>

<artifactId>Bukkit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import eu.endermite.commandwhitelist.bukkit.listeners.protocollib.PacketCommandSendListener;
import eu.endermite.commandwhitelist.common.CWGroup;
import eu.endermite.commandwhitelist.common.ConfigCache;
import eu.endermite.commandwhitelist.common.commands.CWCommand;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
Expand Down Expand Up @@ -79,7 +79,7 @@ public void reloadPluginConfig(CommandSender sender) {
for (Player p : Bukkit.getOnlinePlayers()) {
p.updateCommands();
}
audiences.sender(sender).sendMessage(MiniMessage.markdown().parse(configCache.prefix + configCache.config_reloaded));
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + configCache.config_reloaded));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import eu.endermite.commandwhitelist.common.commands.CWCommand;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
Expand All @@ -31,34 +30,34 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
switch (commandType) {
case RELOAD:
if (!sender.hasPermission(CWPermission.RELOAD.permission())) {
audiences.sender(sender).sendMessage(MiniMessage.markdown().parse(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().no_permission));
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().no_permission));
return true;
}
CommandWhitelistBukkit.getPlugin().reloadPluginConfig(sender);
return true;
case ADD:
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
audiences.sender(sender).sendMessage(MiniMessage.markdown().parse(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().no_permission));
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().no_permission));
return true;
}
if (args.length == 3) {
if (CWCommand.addToWhitelist(CommandWhitelistBukkit.getConfigCache(), args[2], args[1]))
audiences.sender(sender).sendMessage(MiniMessage.markdown().parse(String.format(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().added_to_whitelist, args[2], args[1])));
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(String.format(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().added_to_whitelist, args[2], args[1])));
else
audiences.sender(sender).sendMessage(MiniMessage.markdown().parse(String.format(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().group_doesnt_exist, args[1])));
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(String.format(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().group_doesnt_exist, args[1])));
} else
audiences.sender(sender).sendMessage(Component.text("/" + label + " add <group> <command>"));
return true;
case REMOVE:
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
audiences.sender(sender).sendMessage(MiniMessage.markdown().parse(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().no_permission));
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().no_permission));
return true;
}
if (args.length == 3) {
if (CWCommand.removeFromWhitelist(CommandWhitelistBukkit.getConfigCache(), args[2], args[1]))
audiences.sender(sender).sendMessage(MiniMessage.markdown().parse(String.format(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().removed_from_whitelist, args[2], args[1])));
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(String.format(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().removed_from_whitelist, args[2], args[1])));
else
audiences.sender(sender).sendMessage(MiniMessage.markdown().parse(String.format(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().group_doesnt_exist, args[1])));
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(String.format(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().group_doesnt_exist, args[1])));
} else
audiences.sender(sender).sendMessage(Component.text("/" + label + " remove <group> <command>"));
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit;
import eu.endermite.commandwhitelist.common.CommandUtil;
import eu.endermite.commandwhitelist.common.ConfigCache;
import eu.endermite.commandwhitelist.common.commands.CWCommand;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand All @@ -24,15 +24,15 @@ public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandPreproce
HashSet<String> commands = CommandWhitelistBukkit.getCommands(player);
if (!commands.contains(label)) {
event.setCancelled(true);
audiences.player(player).sendMessage(MiniMessage.markdown().parse(config.prefix + config.command_denied));
audiences.player(player).sendMessage(CWCommand.miniMessage.parse(config.prefix + config.command_denied));
return;
}

HashSet<String> bannedSubCommands = CommandWhitelistBukkit.getSuggestions(player);
for (String bannedSubCommand : bannedSubCommands) {
if (event.getMessage().toLowerCase().substring(1).startsWith(bannedSubCommand)) {
event.setCancelled(true);
audiences.player(player).sendMessage(MiniMessage.markdown().parse(config.prefix + config.subcommand_denied));
audiences.player(player).sendMessage(CWCommand.miniMessage.parse(config.prefix + config.subcommand_denied));
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import eu.endermite.commandwhitelist.common.CWPermission;
import eu.endermite.commandwhitelist.common.CommandUtil;
import eu.endermite.commandwhitelist.common.ConfigCache;
import net.kyori.adventure.text.minimessage.MiniMessage;
import eu.endermite.commandwhitelist.common.commands.CWCommand;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;

Expand Down Expand Up @@ -39,15 +39,15 @@ public void onPacketReceiving(PacketEvent event) {
HashSet<String> commands = CommandWhitelistBukkit.getCommands(player);
if (!commands.contains(label)) {
event.setCancelled(true);
CommandWhitelistBukkit.getAudiences().player(player).sendMessage(MiniMessage.markdown().parse(config.prefix + config.command_denied));
CommandWhitelistBukkit.getAudiences().player(player).sendMessage(CWCommand.miniMessage.parse(config.prefix + config.command_denied));
return;
}

HashSet<String> bannedSubCommands = CommandWhitelistBukkit.getSuggestions(player);
for (String bannedSubCommand : bannedSubCommands) {
if (string.toLowerCase().substring(1).startsWith(bannedSubCommand)) {
event.setCancelled(true);
CommandWhitelistBukkit.getAudiences().player(player).sendMessage(MiniMessage.markdown().parse(config.prefix + config.subcommand_denied));
CommandWhitelistBukkit.getAudiences().player(player).sendMessage(CWCommand.miniMessage.parse(config.prefix + config.subcommand_denied));
return;
}
}
Expand Down
7 changes: 4 additions & 3 deletions CommandWhitelistBukkit/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version: ${project.version}
api-version: 1.13
main: eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit
authors: [YouHaveTrouble]
website: youhavetrouble.me
softdepend:
- ProtocolLib
description: Control what commands players can use
Expand All @@ -14,8 +15,8 @@ commands:
usage: /commandwhitelist [args]
permissions:
commandwhitelist.reload:
default: OP
default: op
commandwhitelist.admin:
default: OP
default: op
commandwhitelist.bypass:
default: OP
default: op
2 changes: 1 addition & 1 deletion CommandWhitelistCommon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId>
<version>2.2.0</version>
<version>2.2.1</version>
</parent>

<artifactId>Common</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.transformation.TransformationType;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class CWCommand {

public static MiniMessage miniMessage = MiniMessage.builder()
.removeDefaultTransformations()
.transformation(TransformationType.COLOR)
.transformation(TransformationType.DECORATION)
.transformation(TransformationType.GRADIENT)
.transformation(TransformationType.RESET)
.transformation(TransformationType.RAINBOW)
.transformation(TransformationType.PRE)
.build();

public static boolean addToWhitelist(ConfigCache configCache, String command, String group) {
CWGroup cwGroup = configCache.getGroupList().get(group);
if (cwGroup == null) return false;
Expand All @@ -30,7 +41,7 @@ public static boolean removeFromWhitelist(ConfigCache configCache, String comman
}

public static Component helpComponent(String baseCommand, boolean showReloadCommand, boolean showAdminCommands) {
Component component = MiniMessage.markdown().parse("<rainbow><bold>CommandWhitelist by YouHaveTrouble")
Component component = miniMessage.parse("<rainbow><bold>CommandWhitelist by YouHaveTrouble")
.append(Component.newline());
component = component.append(Component.text("/" + baseCommand + " help").color(NamedTextColor.AQUA).append(Component.text(" - Displays this message").color(NamedTextColor.BLUE)));
if (showReloadCommand) {
Expand Down
2 changes: 1 addition & 1 deletion CommandWhitelistVelocity/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId>
<version>2.2.0</version>
<version>2.2.1</version>
</parent>

<artifactId>Velocity</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import eu.endermite.commandwhitelist.common.CWGroup;
import eu.endermite.commandwhitelist.common.CWPermission;
import eu.endermite.commandwhitelist.common.ConfigCache;
import eu.endermite.commandwhitelist.common.commands.CWCommand;
import eu.endermite.commandwhitelist.velocity.command.VelocityMainCommand;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bstats.charts.SimplePie;
import org.bstats.velocity.Metrics;
import org.slf4j.Logger;
Expand Down Expand Up @@ -55,7 +55,7 @@ private static void reloadConfig() {
public static void reloadConfig(CommandSource source) {
server.getScheduler().buildTask(plugin, () -> {
reloadConfig();
source.sendMessage(Identity.nil(), MiniMessage.markdown().parse(getConfigCache().prefix+getConfigCache().config_reloaded));
source.sendMessage(Identity.nil(), CWCommand.miniMessage.parse(getConfigCache().prefix+getConfigCache().config_reloaded));
}).schedule();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import eu.endermite.commandwhitelist.common.commands.CWCommand;
import eu.endermite.commandwhitelist.velocity.CommandWhitelistVelocity;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -30,34 +29,34 @@ public void execute(final Invocation invocation) {
switch (commandType) {
case RELOAD:
if (!sender.hasPermission(CWPermission.RELOAD.permission())) {
sender.sendMessage(MiniMessage.markdown().parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().no_permission));
sender.sendMessage(CWCommand.miniMessage.parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().no_permission));
return;
}
CommandWhitelistVelocity.reloadConfig(sender);
return;
case ADD:
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
sender.sendMessage(MiniMessage.markdown().parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().no_permission));
sender.sendMessage(CWCommand.miniMessage.parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().no_permission));
return;
}
if (args.length == 3) {
if (CWCommand.addToWhitelist(CommandWhitelistVelocity.getConfigCache(), args[2], args[1]))
sender.sendMessage(MiniMessage.markdown().parse(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().added_to_whitelist, args[2], args[1])));
sender.sendMessage(CWCommand.miniMessage.parse(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().added_to_whitelist, args[2], args[1])));
else
sender.sendMessage(MiniMessage.markdown().parse(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().group_doesnt_exist, args[1])));
sender.sendMessage(CWCommand.miniMessage.parse(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().group_doesnt_exist, args[1])));
} else
sender.sendMessage(Component.text("/" + label + " add <group> <command>"));
return;
case REMOVE:
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
sender.sendMessage(MiniMessage.markdown().parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().no_permission));
sender.sendMessage(CWCommand.miniMessage.parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().no_permission));
return;
}
if (args.length == 3) {
if (CWCommand.removeFromWhitelist(CommandWhitelistVelocity.getConfigCache(), args[2], args[1]))
sender.sendMessage(MiniMessage.markdown().parse(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().removed_from_whitelist, args[2], args[1])));
sender.sendMessage(CWCommand.miniMessage.parse(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().removed_from_whitelist, args[2], args[1])));
else
sender.sendMessage(MiniMessage.markdown().parse(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().group_doesnt_exist, args[1])));
sender.sendMessage(CWCommand.miniMessage.parse(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().group_doesnt_exist, args[1])));
} else
sender.sendMessage(Component.text("/" + label + " remove <group> <command>"));
return;
Expand Down
2 changes: 1 addition & 1 deletion CommandWhitelistWaterfall/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId>
<version>2.2.0</version>
<version>2.2.1</version>
</parent>

<artifactId>Waterfall</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import eu.endermite.commandwhitelist.common.CWGroup;
import eu.endermite.commandwhitelist.common.ConfigCache;
import eu.endermite.commandwhitelist.common.commands.CWCommand;
import eu.endermite.commandwhitelist.waterfall.command.BungeeMainCommand;
import eu.endermite.commandwhitelist.waterfall.listeners.BungeeChatEventListener;
import eu.endermite.commandwhitelist.waterfall.listeners.BungeeTabcompleteListener;
Expand Down Expand Up @@ -70,7 +71,7 @@ public void loadConfig() {
public void loadConfigAsync(CommandSender sender) {
getProxy().getScheduler().runAsync(this, () -> {
loadConfig();
audiences.sender(sender).sendMessage(MiniMessage.markdown().parse(CommandWhitelistWaterfall.getConfigCache().prefix + CommandWhitelistWaterfall.getConfigCache().config_reloaded));
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(CommandWhitelistWaterfall.getConfigCache().prefix + CommandWhitelistWaterfall.getConfigCache().config_reloaded));
});
}

Expand Down
Loading

0 comments on commit 48fbd59

Please sign in to comment.