Package com.sk89q.craftbook.mechanics.variables

Source Code of com.sk89q.craftbook.mechanics.variables.VariablePacketModifier

package com.sk89q.craftbook.mechanics.variables;

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
import com.sk89q.craftbook.bukkit.CraftBookPlugin;
import com.sk89q.craftbook.util.ParsingUtil;

public class VariablePacketModifier {

    public VariablePacketModifier() {

        ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(CraftBookPlugin.inst(), PacketType.Play.Server.CHAT) {
            @Override
            public void onPacketSending(PacketEvent event) {
                WrappedChatComponent chat = event.getPacket().getChatComponents().read(0);
                chat.setJson(ParsingUtil.parseVariables(chat.getJson(), event.getPlayer()));

                event.getPacket().getChatComponents().write(0, chat);
            }
        });
    }
}
TOP

Related Classes of com.sk89q.craftbook.mechanics.variables.VariablePacketModifier

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.