mirror of
https://github.com/RayzsYT/ProAntiTab.git
synced 2026-12-02 21:39:45 -05:00
Replace Messages
This commit is contained in:
1 parent
5021f5ef87
commit
92445658ba
9 files changed
+39
-11
No files matched your search
@@ -7,6 +7,7 @@ import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.Storage;
|
||||
import de.rayzs.pat.plugin.brand.CustomServerBrand;
|
||||
import de.rayzs.pat.plugin.brand.ServerBrand;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import io.netty.channel.Channel;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
@@ -58,7 +59,7 @@ public class BukkitServerBrand implements ServerBrand {
|
||||
AtomicInteger animationState = new AtomicInteger(0);
|
||||
TASK = Bukkit.getScheduler().scheduleSyncRepeatingTask(BukkitLoader.getPlugin(), () -> {
|
||||
if(animationState.getAndIncrement() >= Storage.CUSTOM_SERVER_BRANDS.size() - 1) animationState.set(0);
|
||||
BRAND = Storage.CUSTOM_SERVER_BRANDS.get(animationState.get());
|
||||
BRAND = MessageTranslator.replaceMessage(Storage.CUSTOM_SERVER_BRANDS.get(animationState.get())) + "§r";
|
||||
Bukkit.getOnlinePlayers().forEach(this::send);
|
||||
}, Storage.CUSTOM_SERVER_BRAND_REPEAT_DELAY, Storage.CUSTOM_SERVER_BRAND_REPEAT_DELAY);
|
||||
}
|
||||
@@ -85,7 +86,7 @@ public class BukkitServerBrand implements ServerBrand {
|
||||
Player player = (Player) playerObj;
|
||||
|
||||
if(!WEIRD) {
|
||||
PacketUtils.BrandManipulate serverBrand = new PacketUtils.BrandManipulate(BRAND.replace("&", "§") + "§r");
|
||||
PacketUtils.BrandManipulate serverBrand = new PacketUtils.BrandManipulate(BRAND);
|
||||
player.sendPluginMessage(BukkitLoader.getPlugin(), CustomServerBrand.CHANNEL_NAME, serverBrand.getBytes());
|
||||
return;
|
||||
}
|
||||
@@ -94,7 +95,7 @@ public class BukkitServerBrand implements ServerBrand {
|
||||
Channel channel = PacketAnalyzer.INJECTED_PLAYERS.get(player.getUniqueId());
|
||||
if(channel == null) return;
|
||||
|
||||
Object brandPayloadObj = brandPayloadClass.getDeclaredConstructor(String.class).newInstance(BRAND.replace("&", "§") + "§r"),
|
||||
Object brandPayloadObj = brandPayloadClass.getDeclaredConstructor(String.class).newInstance(BRAND),
|
||||
customPacketPayloadPacket = clientBoundCustomPacketPayloadPacketClass.getDeclaredConstructor(customPacketPayloadPacketClass).newInstance(brandPayloadObj);
|
||||
channel.pipeline().writeAndFlush(customPacketPayloadPacket);
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import de.rayzs.pat.plugin.BungeeLoader;
|
||||
import de.rayzs.pat.utils.PacketUtils;
|
||||
import de.rayzs.pat.utils.Storage;
|
||||
import de.rayzs.pat.plugin.brand.ServerBrand;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.scheduler.ScheduledTask;
|
||||
@@ -30,7 +31,7 @@ public class BungeeServerBrand implements ServerBrand {
|
||||
AtomicInteger animationState = new AtomicInteger(0);
|
||||
TASK = SERVER.getScheduler().schedule(BungeeLoader.getPlugin(), () -> {
|
||||
if(animationState.getAndIncrement() >= Storage.CUSTOM_SERVER_BRANDS.size() - 1) animationState.set(0);
|
||||
BRAND = Storage.CUSTOM_SERVER_BRANDS.get(animationState.get());
|
||||
BRAND = MessageTranslator.replaceMessage(Storage.CUSTOM_SERVER_BRANDS.get(animationState.get())) + "§r";
|
||||
SERVER.getPlayers().forEach(this::send);
|
||||
}, Storage.CUSTOM_SERVER_BRAND_REPEAT_DELAY, Storage.CUSTOM_SERVER_BRAND_REPEAT_DELAY, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import de.rayzs.pat.utils.PacketUtils;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.Storage;
|
||||
import de.rayzs.pat.plugin.brand.ServerBrand;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
|
||||
@@ -38,7 +39,7 @@ public class VelocityServerBrand implements ServerBrand {
|
||||
AtomicInteger animationState = new AtomicInteger(0);
|
||||
TASK = SERVER.getScheduler().buildTask(VelocityLoader.getInstance(), () -> {
|
||||
if(animationState.getAndIncrement() >= Storage.CUSTOM_SERVER_BRANDS.size() - 1) animationState.set(0);
|
||||
BRAND = Storage.CUSTOM_SERVER_BRANDS.get(animationState.get());
|
||||
BRAND = MessageTranslator.replaceMessage(Storage.CUSTOM_SERVER_BRANDS.get(animationState.get())) + "§r";
|
||||
SERVER.getAllPlayers().forEach(this::send);
|
||||
}).repeat(Storage.CUSTOM_SERVER_BRAND_REPEAT_DELAY, TimeUnit.MILLISECONDS).schedule();
|
||||
}
|
||||
|
||||
@@ -20,14 +20,13 @@ public class Logger {
|
||||
public static void warning(String text) { send(Priority.WARNING, text); }
|
||||
|
||||
protected static void send(Priority priority, String text) {
|
||||
text = text.replace("%current_version%", Storage.CURRENT_VERSION_NAME).replace("%newest_version%", Storage.NEWEST_VERSION_NAME).replace("\\n", "\n");
|
||||
text = MessageTranslator.replaceMessage(text);
|
||||
|
||||
if(LOGGER == null) {
|
||||
System.out.println(text);
|
||||
return;
|
||||
}
|
||||
|
||||
text = text.replace("&", "§");
|
||||
boolean hasColors = text.contains("§");
|
||||
if(hasColors) {
|
||||
if (Reflection.isProxyServer()) MessageTranslator.send(ProxyServer.getInstance().getConsole(), text);
|
||||
|
||||
@@ -41,8 +41,12 @@ public class MessageTranslator {
|
||||
: new BukkitMessageTranslator();
|
||||
}
|
||||
|
||||
public static String replaceMessage(String text) {
|
||||
return text.replace("&", "§").replace("%newest_version%", Storage.NEWEST_VERSION_NAME).replace("\\n", "\n");
|
||||
}
|
||||
|
||||
public static String translateLegacy(String text) {
|
||||
text = text.replace("&", "§");
|
||||
text = replaceMessage(text);
|
||||
if(!text.contains("§")) return text;
|
||||
|
||||
for (Map.Entry<Character, String> entry : colors.entrySet())
|
||||
@@ -51,8 +55,8 @@ public class MessageTranslator {
|
||||
return text;
|
||||
}
|
||||
|
||||
public static String clean(String text) {
|
||||
text = text.replace("&", "§");
|
||||
public static String colorless(String text) {
|
||||
text = replaceMessage(text);
|
||||
if(!text.contains("§")) return text;
|
||||
|
||||
for (Map.Entry<Character, String> entry : colors.entrySet())
|
||||
@@ -62,7 +66,7 @@ public class MessageTranslator {
|
||||
}
|
||||
|
||||
public static void send(Object target, String text) {
|
||||
text = text.replace("%current_version%", Storage.CURRENT_VERSION_NAME).replace("%newest_version%", Storage.NEWEST_VERSION_NAME).replace("\\n", "\n");
|
||||
text = replaceMessage(text);
|
||||
if(translator == null) {
|
||||
CommandSender sender = target instanceof CommandSender ? (CommandSender) target : new CommandSender(target);
|
||||
sender.sendMessage(text);
|
||||
@@ -72,6 +76,10 @@ public class MessageTranslator {
|
||||
translator.send(target, text);
|
||||
}
|
||||
|
||||
public static String translateIntoMiniMessage(String text) {
|
||||
return translator.translate(replaceMessage(text));
|
||||
}
|
||||
|
||||
public static void closeAudiences() {
|
||||
if(translator == null) return;
|
||||
translator.close();
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package de.rayzs.pat.utils.message;
|
||||
|
||||
public interface Translator {
|
||||
|
||||
String translate(String text);
|
||||
void send(Object target, String text);
|
||||
void close();
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import de.rayzs.pat.plugin.BukkitLoader;
|
||||
import de.rayzs.pat.utils.message.*;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -17,6 +18,11 @@ public class BukkitMessageTranslator implements Translator {
|
||||
audiences = BukkitAudiences.create(BukkitLoader.getPlugin());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String translate(String text) {
|
||||
return miniMessage.serialize(miniMessage.deserialize(MessageTranslator.translateLegacy(text)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Object target, String text) {
|
||||
Audience audience = target instanceof Player ? audiences.player((Player) target) : audiences.sender((CommandSender) target);
|
||||
|
||||
@@ -18,6 +18,11 @@ public class BungeeMessageTranslator implements Translator {
|
||||
audiences = BungeeAudiences.create(BungeeLoader.getPlugin());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String translate(String text) {
|
||||
return miniMessage.serialize(miniMessage.deserialize(MessageTranslator.translateLegacy(text)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Object target, String text) {
|
||||
Audience audience = target instanceof ProxiedPlayer ? audiences.player((ProxiedPlayer) target) : audiences.sender((CommandSender) target);
|
||||
|
||||
@@ -9,6 +9,11 @@ public class VelocityMessageTranslator implements Translator {
|
||||
|
||||
private final MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
|
||||
@Override
|
||||
public String translate(String text) {
|
||||
return miniMessage.serialize(miniMessage.deserialize(MessageTranslator.translateLegacy(text)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Object target, String text) {
|
||||
if(target instanceof Player)
|
||||
|
||||
Reference in new issue
Block a user