Fix Animation-Disable

This commit is contained in:
RayzsYT committed 2024-05-23 19:07:34 +02:00
1 parent eee782a205
commit 7d19d7e7f8
5 files changed
+81 -21

No files matched your search

@@ -11,11 +11,14 @@ import net.md_5.bungee.api.connection.Server;
import net.md_5.bungee.api.scheduler.ScheduledTask;
import net.md_5.bungee.protocol.ProtocolConstants;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
public class BungeeServerBrand implements ServerBrand {
private static List<ProxiedPlayer> MODIFIED_BRAND_PLAYERS = new ArrayList<>();
private static final ProxyServer SERVER = BungeeLoader.getPlugin().getProxy();
private static ScheduledTask TASK;
private static String BRAND = Storage.ConfigSections.Settings.CUSTOM_BRAND.BRANDS.getLines().get(0);
@@ -24,15 +27,27 @@ public class BungeeServerBrand implements ServerBrand {
@Override
public void initializeTask() {
if(TASK != null) TASK.cancel();
if(!Storage.ConfigSections.Settings.CUSTOM_BRAND.ENABLED || Storage.ConfigSections.Settings.CUSTOM_BRAND.REPEAT_DELAY == -1) return;
if(TASK != null) {
TASK.cancel();
MODIFIED_BRAND_PLAYERS.clear();
}
AtomicInteger animationState = new AtomicInteger(0);
TASK = SERVER.getScheduler().schedule(BungeeLoader.getPlugin(), () -> {
if(animationState.getAndIncrement() >= Storage.ConfigSections.Settings.CUSTOM_BRAND.BRANDS.getLines().size() - 1) animationState.set(0);
BRAND = MessageTranslator.replaceMessage(Storage.ConfigSections.Settings.CUSTOM_BRAND.BRANDS.getLines().get(animationState.get())) + "§r";
SERVER.getPlayers().forEach(this::send);
}, 1, Storage.ConfigSections.Settings.CUSTOM_BRAND.REPEAT_DELAY, TimeUnit.MILLISECONDS);
if(!Storage.ConfigSections.Settings.CUSTOM_BRAND.ENABLED) return;
if(Storage.ConfigSections.Settings.CUSTOM_BRAND.REPEAT_DELAY == -1) {
TASK = SERVER.getScheduler().schedule(BungeeLoader.getPlugin(), () -> {
BRAND = MessageTranslator.replaceMessage(Storage.ConfigSections.Settings.CUSTOM_BRAND.BRANDS.getLines().get(0)) + "§r";
SERVER.getPlayers().stream().filter(player -> !isModified(player)).forEach(this::send);
}, 1, 150, TimeUnit.MILLISECONDS);
} else {
AtomicInteger animationState = new AtomicInteger(0);
TASK = SERVER.getScheduler().schedule(BungeeLoader.getPlugin(), () -> {
if (animationState.getAndIncrement() >= Storage.ConfigSections.Settings.CUSTOM_BRAND.BRANDS.getLines().size() - 1)
animationState.set(0);
BRAND = MessageTranslator.replaceMessage(Storage.ConfigSections.Settings.CUSTOM_BRAND.BRANDS.getLines().get(animationState.get())) + "§r";
SERVER.getPlayers().forEach(this::send);
}, 1, Storage.ConfigSections.Settings.CUSTOM_BRAND.REPEAT_DELAY, TimeUnit.MILLISECONDS);
}
}
@Override
@@ -51,5 +66,16 @@ public class BungeeServerBrand implements ServerBrand {
PacketUtils.BrandManipulate serverBrand = new PacketUtils.BrandManipulate(customBrand);
String brand = player.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_13 ? "minecraft:brand" : "MC|Brand";
player.sendData(brand, serverBrand.getBytes());
if(!MODIFIED_BRAND_PLAYERS.contains(player)) MODIFIED_BRAND_PLAYERS.add(player);
}
private boolean isModified(ProxiedPlayer player) {
if(!Storage.ConfigSections.Settings.CUSTOM_BRAND.ENABLED || Storage.ConfigSections.Settings.CUSTOM_BRAND.REPEAT_DELAY != -1) return false;
return MODIFIED_BRAND_PLAYERS.contains(player);
}
public static void removeFromModified(ProxiedPlayer player) {
MODIFIED_BRAND_PLAYERS.remove(player);
}
}
@@ -12,12 +12,16 @@ import de.rayzs.pat.api.brand.ServerBrand;
import de.rayzs.pat.utils.message.MessageTranslator;
import io.netty.buffer.ByteBuf;
import net.md_5.bungee.protocol.ProtocolConstants;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
public class VelocityServerBrand implements ServerBrand {
private static List<Player> MODIFIED_BRAND_PLAYERS = new ArrayList<>();
private static final ProxyServer SERVER = VelocityLoader.getServer();
private static Class<?> pluginMessagePacketClass, minecraftConnectionClass, connectedPlayerConnectionClass;
private static ScheduledTask TASK;
@@ -25,8 +29,12 @@ public class VelocityServerBrand implements ServerBrand {
@Override
public void initializeTask() {
if(TASK != null) TASK.cancel();
if(!Storage.ConfigSections.Settings.CUSTOM_BRAND.ENABLED || Storage.ConfigSections.Settings.CUSTOM_BRAND.REPEAT_DELAY == -1) return;
if(TASK != null) {
TASK.cancel();
MODIFIED_BRAND_PLAYERS.clear();
}
if(!Storage.ConfigSections.Settings.CUSTOM_BRAND.ENABLED) return;
if(pluginMessagePacketClass == null)
pluginMessagePacketClass = Reflection.getClass("com.velocitypowered.proxy.protocol.packet.PluginMessagePacket");
@@ -37,12 +45,20 @@ public class VelocityServerBrand implements ServerBrand {
if(connectedPlayerConnectionClass == null)
connectedPlayerConnectionClass = Reflection.getClass("com.velocitypowered.proxy.connection.client.ConnectedPlayer");
AtomicInteger animationState = new AtomicInteger(0);
TASK = SERVER.getScheduler().buildTask(VelocityLoader.getInstance(), () -> {
if(animationState.getAndIncrement() >= Storage.ConfigSections.Settings.CUSTOM_BRAND.BRANDS.getLines().size() - 1) animationState.set(0);
BRAND = MessageTranslator.replaceMessage(Storage.ConfigSections.Settings.CUSTOM_BRAND.BRANDS.getLines().get(animationState.get())) + "§r";
SERVER.getAllPlayers().forEach(this::send);
}).repeat(Storage.ConfigSections.Settings.CUSTOM_BRAND.REPEAT_DELAY, TimeUnit.MILLISECONDS).schedule();
if(Storage.ConfigSections.Settings.CUSTOM_BRAND.REPEAT_DELAY == -1) {
TASK = SERVER.getScheduler().buildTask(VelocityLoader.getInstance(), () -> {
BRAND = MessageTranslator.replaceMessage(Storage.ConfigSections.Settings.CUSTOM_BRAND.BRANDS.getLines().get(0)) + "§r";
SERVER.getAllPlayers().stream().filter(player -> !isModified(player)).forEach(this::send);
}).repeat(150, TimeUnit.MILLISECONDS).schedule();
} else {
AtomicInteger animationState = new AtomicInteger(0);
TASK = SERVER.getScheduler().buildTask(VelocityLoader.getInstance(), () -> {
if (animationState.getAndIncrement() >= Storage.ConfigSections.Settings.CUSTOM_BRAND.BRANDS.getLines().size() - 1)
animationState.set(0);
BRAND = MessageTranslator.replaceMessage(Storage.ConfigSections.Settings.CUSTOM_BRAND.BRANDS.getLines().get(animationState.get())) + "§r";
SERVER.getAllPlayers().forEach(this::send);
}).repeat(Storage.ConfigSections.Settings.CUSTOM_BRAND.REPEAT_DELAY, TimeUnit.MILLISECONDS).schedule();
}
}
@@ -68,8 +84,18 @@ public class VelocityServerBrand implements ServerBrand {
Object pluginMessagePacket = pluginMessagePacketClass.getConstructor(String.class, ByteBuf.class).newInstance(brand, serverBrand.getByteBuf());
Reflection.getMethodsByParameterAndName(minecraftConnectionObj, "write", Object.class).get(0).invoke(minecraftConnectionObj, pluginMessagePacket);
if(!MODIFIED_BRAND_PLAYERS.contains(player)) MODIFIED_BRAND_PLAYERS.add(player);
} catch (Exception exception) {
exception.printStackTrace();
}
}
private boolean isModified(Player player) {
if(!Storage.ConfigSections.Settings.CUSTOM_BRAND.ENABLED || Storage.ConfigSections.Settings.CUSTOM_BRAND.REPEAT_DELAY != -1) return false;
return MODIFIED_BRAND_PLAYERS.contains(player);
}
public static void removeFromModified(Player player) {
MODIFIED_BRAND_PLAYERS.remove(player);
}
}
@@ -1,6 +1,6 @@
package de.rayzs.pat.plugin.listeners.bungee;
import de.rayzs.pat.api.brand.CustomServerBrand;
import de.rayzs.pat.api.brand.impl.BungeeServerBrand;
import de.rayzs.pat.api.storage.Storage;
import de.rayzs.pat.plugin.BungeeLoader;
import de.rayzs.pat.utils.PermissionUtil;
@@ -31,7 +31,7 @@ public class BungeePlayerConnectionListener implements Listener {
@EventHandler (priority = EventPriority.LOWEST)
public void onServerSwitch(ServerSwitchEvent event) {
ProxiedPlayer player = event.getPlayer();
CustomServerBrand.sendBrandToPlayer(player);
if(Storage.ConfigSections.Settings.CUSTOM_BRAND.REPEAT_DELAY != -1) return;
BungeeServerBrand.removeFromModified(event.getPlayer());
}
}
@@ -1,9 +1,11 @@
package de.rayzs.pat.plugin.listeners.velocity;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.player.ServerConnectedEvent;
import com.velocitypowered.api.event.player.ServerPreConnectEvent;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import de.rayzs.pat.api.brand.impl.VelocityServerBrand;
import de.rayzs.pat.api.storage.Storage;
import de.rayzs.pat.plugin.VelocityLoader;
import de.rayzs.pat.utils.message.MessageTranslator;
@@ -30,4 +32,10 @@ public class VelocityConnectionListener {
}).delay(1, TimeUnit.SECONDS).schedule();
}
}
@Subscribe
public void onServerSwitch(ServerConnectedEvent event) {
if(Storage.ConfigSections.Settings.CUSTOM_BRAND.REPEAT_DELAY != -1) return;
VelocityServerBrand.removeFromModified(event.getPlayer());
}
}