Skip to content

Commit

Permalink
improve handling of hex color codes and colored nicknames
Browse files Browse the repository at this point in the history
  • Loading branch information
CaptnSisko committed Apr 1, 2023
1 parent 6e1cff0 commit bba22a4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 33 deletions.
6 changes: 4 additions & 2 deletions src/main/java/me/sisko/left4chat/util/Colors.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ public static TextComponent format(String text) {
} else if (texts[i].length() >= 7 && texts[i].charAt(0) == '#') {
try {
lastColor = ChatColor.of(texts[i].substring(0, 7));
txt.setText(texts[i].substring(7));
} catch (IllegalArgumentException e) {
Main.getPlugin().getLogger().warning("Attempted to translate invalid color code: " + texts[i].substring(0, 7));
// interpret invalid hex codes as text
txt.setText("&" + texts[i]);
// Main.getPlugin().getLogger().warning("Attempted to translate invalid color code: " + texts[i].substring(0, 7));
}
txt.setColor(lastColor);
txt.setText(texts[i].substring(7));

// reset formatting
obfuscated = false;
Expand Down
62 changes: 31 additions & 31 deletions src/main/java/me/sisko/left4chat/util/Main.java
Original file line number Diff line number Diff line change
@@ -1,40 +1,10 @@
package me.sisko.left4chat.util;

import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;

import io.loyloy.nicky.Nick;
import me.sisko.left4chat.commands.AfkCommand;
import me.sisko.left4chat.commands.AnnounceCommand;
import me.sisko.left4chat.commands.DiscordCommand;
import me.sisko.left4chat.commands.GGiveCosmeticCommand;
import me.sisko.left4chat.commands.GameCommand;
import me.sisko.left4chat.commands.LockdownCommand;
import me.sisko.left4chat.commands.MessageCommand;
import me.sisko.left4chat.commands.MessageTabComplete;
import me.sisko.left4chat.commands.ReloadCommand;
import me.sisko.left4chat.commands.ReplyCommand;
import me.sisko.left4chat.commands.VerifyCommand;
import me.sisko.left4chat.commands.ListCommand;
import me.sisko.left4chat.sql.AsyncKeepAlive;
import me.sisko.left4chat.sql.AsyncUserUpdate;
import me.sisko.left4chat.sql.SQLManager;

import java.sql.Connection;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.UUID;

import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.chat.ComponentBuilder.FormatRetention;
import net.md_5.bungee.api.chat.HoverEvent.Action;
import net.md_5.bungee.api.chat.hover.content.Text;
import net.luckperms.api.LuckPerms;
import net.milkbowl.vault.chat.Chat;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
Expand All @@ -60,6 +30,35 @@
import org.json.JSONException;
import org.json.JSONObject;

import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;

import io.loyloy.nicky.Nicky;
import me.sisko.left4chat.commands.AfkCommand;
import me.sisko.left4chat.commands.AnnounceCommand;
import me.sisko.left4chat.commands.DiscordCommand;
import me.sisko.left4chat.commands.GGiveCosmeticCommand;
import me.sisko.left4chat.commands.GameCommand;
import me.sisko.left4chat.commands.ListCommand;
import me.sisko.left4chat.commands.LockdownCommand;
import me.sisko.left4chat.commands.MessageCommand;
import me.sisko.left4chat.commands.MessageTabComplete;
import me.sisko.left4chat.commands.ReloadCommand;
import me.sisko.left4chat.commands.ReplyCommand;
import me.sisko.left4chat.commands.VerifyCommand;
import me.sisko.left4chat.sql.AsyncKeepAlive;
import me.sisko.left4chat.sql.AsyncUserUpdate;
import me.sisko.left4chat.sql.SQLManager;
import net.luckperms.api.LuckPerms;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.ComponentBuilder.FormatRetention;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.HoverEvent.Action;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.chat.hover.content.Text;
import net.milkbowl.vault.chat.Chat;
import net.milkbowl.vault.permission.Permission;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPubSub;

Expand Down Expand Up @@ -239,7 +238,8 @@ public void onChat(AsyncPlayerChatEvent e) {
this.setAFK(e.getPlayer(), false, true);
moveTimes.put(e.getPlayer(), System.currentTimeMillis());
String group = perms.getPrimaryGroup(e.getPlayer());
String name = new Nick(e.getPlayer()).get();
String name = Nicky.getNickDatabase().downloadNick(e.getPlayer().getUniqueId().toString());
// String name = new Nick(e.getPlayer()).get();
if (name == null) {
name = e.getPlayer().getName();
}
Expand Down

0 comments on commit bba22a4

Please sign in to comment.