var S02PacketChat = Java.type('net.minecraft.network.play.server.S02PacketChat'),
    Minecraft = Java.type('net.minecraft.client.Minecraft'),
    messageAmount = 0,
    lastMessage = '',
    messageLine = 0;
var script = registerScript({
    name: 'Anti Spammer',
    version: '0.0.0',
    authors: ['Shurpe']
});
script.registerModule({
    name: 'AntiSpammer',
    description: '',
    category: 'Fun'

}, function (module) {
    module.on('packet', function (e) {
        var packet = e.getPacket()
        if (packet instanceof S02PacketChat) {
            var message = packet.getChatComponent(),
                formattedMessage = message.getFormattedText(),
                chatGUI = Minecraft.getMinecraft().ingameGUI.getChatGUI();
            if (lastMessage === formattedMessage) {
                messageAmount++;
                chatGUI.deleteChatLine(messageLine);
                packet.getChatComponent().appendText(' §7x' + messageAmount);
            } else {
                messageAmount = 1;
            }
            messageLine > 256 ? messageLine = 0 : messageLine++;
            lastMessage = formattedMessage;
            chatGUI.printChatMessageWithOptionalDeletion(message, messageLine);
            e.cancelEvent();
        }
    });
});