Update nicknames to use Chat's plugin message channels.
This commit is contained in:
parent
3d432a5af6
commit
a4e4982dc3
|
|
@ -509,6 +509,7 @@ public final class Config {
|
|||
public static List<String> NICK_ITEM_LORE = new ArrayList<>();
|
||||
public static List<String> NICK_BLOCKED_COLOR_CODESLIST = new ArrayList<>();
|
||||
public static List<String> NICK_ALLOWED_COLOR_CODESLIST = new ArrayList<>();
|
||||
public static String NICK_CURRENT = "<gold>Current nickname: <nickname><white>(<insert:\"<currentnickname>\"><currentnickname></insert>)";
|
||||
private static void nicknameSettings() {
|
||||
NICK_CHANGED = getString("nicknames.messages.nick-changed", NICK_CHANGED);
|
||||
NICK_NOT_CHANGED = getString("nicknames.messages.nick-not-changed", NICK_NOT_CHANGED);
|
||||
|
|
@ -537,5 +538,6 @@ public final class Config {
|
|||
NICK_ITEM_LORE = getList("nicknames.item-lore", List.of("&bNew nick: %newNick%", "&bOld nick: %oldNick%", "&bLast changed: %lastChanged%", "&aLeft click to Accept &d| &cRight click to Deny"));
|
||||
NICK_BLOCKED_COLOR_CODESLIST = getList("nicknames.blocked-color-codes", List.of("&k", "&l", "&n", "&m", "&o"));
|
||||
NICK_ALLOWED_COLOR_CODESLIST = getList("nicknames.allowed-color-codes", List.of("&0", "&1", "&2", "&3", "&4", "&5", "&6", "&7", "&8", "&9", "&a", "&b", "&c", "&d", "&e", "&f", "&r"));
|
||||
NICK_CURRENT = getString("nicknames.messages.nick-current", NICK_CURRENT);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -193,8 +193,8 @@ public class NickUtilities
|
|||
public static void bungeeMessageHandled(UUID uniqueId, Player player, String channel) {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
|
||||
out.writeUTF("Forward"); // So BungeeCord knows to forward it
|
||||
out.writeUTF("ALL");
|
||||
// out.writeUTF("Forward"); // So BungeeCord knows to forward it
|
||||
// out.writeUTF("ALL");
|
||||
out.writeUTF("NickName" + channel); // The channel name to check if this your data
|
||||
|
||||
ByteArrayOutputStream msgbytes = new ByteArrayOutputStream();
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ import com.alttd.chat.objects.Nick;
|
|||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
|
@ -104,7 +106,11 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
|||
case "current":
|
||||
if (hasPermission(sender, "utility.nick.current")) {
|
||||
ChatUser chatUser = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
player.sendMessage(Component.text("Current nick: ").append(chatUser.getDisplayName()).append(Component.text(" (" + chatUser.getNickNameString() + ")")));
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("nickname", chatUser.getDisplayName()),
|
||||
Placeholder.parsed("currentnickname", chatUser.getNickNameString())
|
||||
);
|
||||
player.sendMiniMessage(Config.NICK_CURRENT, placeholders);
|
||||
}
|
||||
break;
|
||||
case "help":
|
||||
|
|
@ -179,9 +185,9 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
|||
|
||||
if (NickCache.containsKey(uniqueId)) {
|
||||
Nick nick = NickCache.get(uniqueId);
|
||||
long timeSinceLastChange = new Date().getTime() - nick.getLastChangedDate();
|
||||
long timeSinceLastChange = new Date().getTime() - nick.getLastChangedDate();
|
||||
long waitTime = Config.NICK_WAIT_TIME;
|
||||
if (timeSinceLastChange > waitTime) {
|
||||
if (timeSinceLastChange > waitTime || player.hasPermission("utility.nick.admin")) {
|
||||
if (nick.hasRequest()) {
|
||||
player.sendMessage(format(Config.NICK_REQUEST_PLACED
|
||||
.replace("%oldRequestedNick%", nick.getNewNick())
|
||||
|
|
@ -208,8 +214,8 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
|||
|
||||
UUID uniqueId = player.getUniqueId();
|
||||
|
||||
out.writeUTF("Forward"); // So BungeeCord knows to forward it
|
||||
out.writeUTF("ALL");
|
||||
// out.writeUTF("Forward"); // So BungeeCord knows to forward it
|
||||
// out.writeUTF("ALL");
|
||||
out.writeUTF("NickNameRequest"); // The channel name to check if this your data
|
||||
|
||||
ByteArrayOutputStream msgbytes = new ByteArrayOutputStream();
|
||||
|
|
@ -268,7 +274,7 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
|||
.replace("%player%", target.getName())));
|
||||
}
|
||||
|
||||
if (target.isOnline()) {
|
||||
if (target.isOnline() && target.getPlayer() != null) {
|
||||
target.getPlayer().sendMessage(format(Config.NICK_RESET));
|
||||
}
|
||||
|
||||
|
|
@ -290,7 +296,7 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
|||
Nick nick = NickCache.get(target.getUniqueId());
|
||||
nick.setCurrentNick(nickName);
|
||||
nick.setLastChangedDate(new Date().getTime());
|
||||
|
||||
setNick(target.getUniqueId(), nickName);
|
||||
} else {
|
||||
NickCache.put(target.getUniqueId(), new Nick(target.getUniqueId(), nickName, new Date().getTime()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import com.alttd.chat.ChatPlugin;
|
|||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.database.Queries;
|
||||
import com.alttd.chat.objects.Nick;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
|
@ -90,6 +91,7 @@ public class NicknamesEvents implements Listener, PluginMessageListener {
|
|||
|
||||
ByteArrayDataInput in = ByteStreams.newDataInput(message);
|
||||
String subChannel = in.readUTF();
|
||||
ALogger.info(channel + ": " + subChannel);
|
||||
if (!subChannel.equals("NickNameRequest") && !subChannel.equals("NickNameAccepted")
|
||||
&& !subChannel.equals("NickNameDenied") && !subChannel.equals("NickNameSet")) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -191,8 +191,8 @@ public class NicknamesGui implements Listener {
|
|||
|
||||
if (owningPlayer.isOnline() && owningPlayer.getPlayer() != null) {
|
||||
Nicknames.getInstance().setNick(owningPlayer.getUniqueId(), nick.getNewNick());
|
||||
owningPlayer.getPlayer().sendMessage(format(Config.NICK_CHANGED
|
||||
.replace("%nickname%", nick.getNewNick())));
|
||||
// owningPlayer.getPlayer().sendMessage(format(Config.NICK_CHANGED // This message is also send when the plugin message is received
|
||||
// .replace("%nickname%", nick.getNewNick())));
|
||||
}
|
||||
|
||||
NickUtilities.bungeeMessageHandled(uniqueId, e.getWhoClicked().getServer().getPlayer(e.getWhoClicked().getName()), "Accepted");
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ public class PluginMessageListener {
|
|||
}
|
||||
|
||||
// nicknames WIP
|
||||
case "NickNameAccepted" -> {
|
||||
case "NickNameAccepted", "NickNameSet" -> {
|
||||
try {
|
||||
short len = in.readShort();
|
||||
byte[] msgbytes = new byte[len];
|
||||
|
|
@ -88,7 +88,7 @@ public class PluginMessageListener {
|
|||
proxy.getAllServers().forEach(registeredServer ->
|
||||
registeredServer.sendPluginMessage(VelocityChat.getPlugin().getChannelIdentifier(), event.getData()));
|
||||
}
|
||||
case "NickNameRequest", "NickNameSet", "NickNameDenied" -> {
|
||||
case "NickNameRequest", "NickNameDenied" -> {
|
||||
ProxyServer proxy = VelocityChat.getPlugin().getProxy();
|
||||
proxy.getAllServers().forEach(registeredServer ->
|
||||
registeredServer.sendPluginMessage(VelocityChat.getPlugin().getChannelIdentifier(), event.getData()));
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user