Search in sources :

Example 1 with ColorSettings

use of com.loohp.interactivechat.utils.PlayerUtils.ColorSettings in project InteractiveChat by LOOHP.

the class ClientSettingPacket method clientSettingsListener.

public static void clientSettingsListener() {
    Bukkit.getPluginManager().registerEvents(new ClientSettingPacket(), InteractiveChat.plugin);
    InteractiveChat.protocolManager.addPacketListener(new PacketAdapter(PacketAdapter.params().plugin(InteractiveChat.plugin).listenerPriority(ListenerPriority.MONITOR).types(PacketType.Play.Client.SETTINGS)) {

        @Override
        public void onPacketSending(PacketEvent event) {
        // do nothing
        }

        @Override
        public void onPacketReceiving(PacketEvent event) {
            if (!event.getPacketType().equals(PacketType.Play.Client.SETTINGS)) {
                return;
            }
            PacketContainer packet = event.getPacket();
            Player player = event.getPlayer();
            boolean colorSettings = packet.getBooleans().read(0);
            ColorSettings originalColorSettings = getSettings(player);
            if ((originalColorSettings.equals(ColorSettings.WAITING) || originalColorSettings.equals(ColorSettings.ON)) && !colorSettings) {
                Bukkit.getScheduler().runTaskLater(InteractiveChat.plugin, () -> player.sendMessage(ChatColorUtils.translateAlternateColorCodes('&', ConfigManager.getConfig().getString("Messages.ColorsDisabled"))), 5);
            }
            if (originalColorSettings.equals(ColorSettings.OFF) && colorSettings) {
                Bukkit.getScheduler().runTaskLater(InteractiveChat.plugin, () -> player.sendMessage(ChatColorUtils.translateAlternateColorCodes('&', ConfigManager.getConfig().getString("Messages.ColorsReEnabled"))), 5);
            }
            colorSettingsMap.put(player, colorSettings);
        }
    });
}
Also used : PacketContainer(com.comphenix.protocol.events.PacketContainer) Player(org.bukkit.entity.Player) PacketAdapter(com.comphenix.protocol.events.PacketAdapter) PacketEvent(com.comphenix.protocol.events.PacketEvent) ColorSettings(com.loohp.interactivechat.utils.PlayerUtils.ColorSettings)

Aggregations

PacketAdapter (com.comphenix.protocol.events.PacketAdapter)1 PacketContainer (com.comphenix.protocol.events.PacketContainer)1 PacketEvent (com.comphenix.protocol.events.PacketEvent)1 ColorSettings (com.loohp.interactivechat.utils.PlayerUtils.ColorSettings)1 Player (org.bukkit.entity.Player)1