Add Discord syntax and fix some small bugs
Signed-off-by: Etzelia <etzelia@hotmail.com>discord_syntax
parent
af7abe9ca7
commit
325ece3594
|
@ -29,7 +29,7 @@ public class ColorsCommand implements CommandExecutor {
|
||||||
ChatColor.DARK_GRAY + "\n&8 - Dark Gray" +
|
ChatColor.DARK_GRAY + "\n&8 - Dark Gray" +
|
||||||
ChatColor.BLUE + "\n&9 - Blue" +
|
ChatColor.BLUE + "\n&9 - Blue" +
|
||||||
ChatColor.GREEN + "\n&a - Green" +
|
ChatColor.GREEN + "\n&a - Green" +
|
||||||
ChatColor.AQUA + "\n&b - Aqu" +
|
ChatColor.AQUA + "\n&b - Aqua" +
|
||||||
ChatColor.RED + "\n&c - Red" +
|
ChatColor.RED + "\n&c - Red" +
|
||||||
ChatColor.LIGHT_PURPLE + "\n&d - Light Purple" +
|
ChatColor.LIGHT_PURPLE + "\n&d - Light Purple" +
|
||||||
ChatColor.YELLOW + "\n&e - Yellow" +
|
ChatColor.YELLOW + "\n&e - Yellow" +
|
||||||
|
|
|
@ -1,23 +1,28 @@
|
||||||
package xyz.etztech.qol.listeners;
|
package xyz.etztech.qol.listeners;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
import org.bukkit.event.server.ServerListPingEvent;
|
|
||||||
import org.bukkit.util.CachedServerIcon;
|
|
||||||
import xyz.etztech.qol.QoL;
|
import xyz.etztech.qol.QoL;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import java.util.Arrays;
|
||||||
import java.awt.*;
|
import java.util.List;
|
||||||
import java.awt.image.BufferedImage;
|
import java.util.regex.Matcher;
|
||||||
import java.io.File;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class AsyncPlayerChatListener implements Listener {
|
public class AsyncPlayerChatListener implements Listener {
|
||||||
|
|
||||||
|
private final List<Pattern> discordSyntax = Arrays.asList(
|
||||||
|
Pattern.compile("__([^_]+)__"), // 0: __underline__
|
||||||
|
Pattern.compile("_([^_]+)_"), // 1: _italic_
|
||||||
|
Pattern.compile("\\*\\*([^*]+)\\*\\*"), // 2: **bold**
|
||||||
|
Pattern.compile("\\*([^*]+)\\*"), // 3: *italic*
|
||||||
|
Pattern.compile("~~([^~]+)~~") // 4: ~~strikethrough~~
|
||||||
|
);
|
||||||
|
|
||||||
private QoL plugin;
|
private QoL plugin;
|
||||||
|
|
||||||
public AsyncPlayerChatListener(QoL plugin) {
|
public AsyncPlayerChatListener(QoL plugin) {
|
||||||
|
@ -36,6 +41,35 @@ public class AsyncPlayerChatListener implements Listener {
|
||||||
if (QoL.getTimeout() && !player.hasPermission("qol.timeout.bypass")) {
|
if (QoL.getTimeout() && !player.hasPermission("qol.timeout.bypass")) {
|
||||||
event.getRecipients().clear();
|
event.getRecipients().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Discord syntax for font emphasis
|
||||||
|
if (player.hasPermission("qol.discord")) {
|
||||||
|
String chat = event.getMessage();
|
||||||
|
Pattern syntax;
|
||||||
|
Matcher matcher;
|
||||||
|
for (int i = 0; i < discordSyntax.size(); i++) {
|
||||||
|
syntax = discordSyntax.get(i);
|
||||||
|
matcher = syntax.matcher(chat);
|
||||||
|
switch (i) {
|
||||||
|
case 0:
|
||||||
|
chat = matcher.replaceAll("&n$1&r");
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
case 3:
|
||||||
|
chat = matcher.replaceAll("&o$1&r");
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
chat = matcher.replaceAll("&l$1&r");
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
chat = matcher.replaceAll("&m$1&r");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
event.setMessage(ChatColor.translateAlternateColorCodes('&', chat));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -92,4 +92,4 @@ disable-fire:
|
||||||
|
|
||||||
# Overrides view distance per world, format is [World Name]: [View Distance]
|
# Overrides view distance per world, format is [World Name]: [View Distance]
|
||||||
view-distances:
|
view-distances:
|
||||||
# world: 2
|
world: 2
|
||||||
|
|
|
@ -49,6 +49,9 @@ permissions:
|
||||||
qol.admin:
|
qol.admin:
|
||||||
description: Ability to reload the plugin
|
description: Ability to reload the plugin
|
||||||
default: op
|
default: op
|
||||||
|
qol.discord:
|
||||||
|
description: Ability to use limited Discord syntax for chat formatting
|
||||||
|
default: op
|
||||||
qol.priority:
|
qol.priority:
|
||||||
description: Allows a player on past the player cap
|
description: Allows a player on past the player cap
|
||||||
default: op
|
default: op
|
||||||
|
|
Loading…
Reference in New Issue