/*
 * Copyright  2014 - 2017 | Wurst-Imperium | All rights reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package net.wurstclient.features.mods;

import java.util.Random;

import io.netty.buffer.Unpooled;
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.play.client.CPacketCustomPayload;
import net.wurstclient.compatibility.WConnection;
import net.wurstclient.events.listeners.UpdateListener;

@Mod.Info(
	description = "Fills the server console with errors so that admins can't see what you are doing.",
	name = "LogSpammer",
	help = "Mods/LogSpammer")
@Mod.Bypasses(ghostMode = false)
public final class LogSpammerMod extends Mod implements UpdateListener
{
	private PacketBuffer payload;
	private Random random;
	private final String[] vulnerableChannels =
		new String[]{"MC|BEdit", "MC|BSign", "MC|TrSel", "MC|PickItem"};
	
	@Override
	public void onEnable()
	{
		random = new Random();
		payload = new PacketBuffer(Unpooled.buffer());
		
		byte[] rawPayload = new byte[random.nextInt(128)];
		random.nextBytes(rawPayload);
		payload.writeBytes(rawPayload);
		
		wurst.events.add(UpdateListener.class, this);
	}
	
	@Override
	public void onUpdate()
	{
		updateMS();
		if(hasTimePassedM(100))
		{
			WConnection.sendPacket(new CPacketCustomPayload(
				vulnerableChannels[random.nextInt(vulnerableChannels.length)],
				payload));
			updateLastMS();
		}
	}
	
	@Override
	public void onDisable()
	{
		wurst.events.remove(UpdateListener.class, this);
	}
}

@@ -691,16 +691,43 @@
 e doing.
+%5Cn%22%0A%09%09+ %22Patched on Spigot.
 %22,%0A%09name
@@ -1338,32 +1338,127 @@
 %09%7D%0A%09%0A%09@Override%0A
+%09public void onDisable()%0A%09%7B%0A%09%09wurst.events.remove(UpdateListener.class, this);%0A%09%7D%0A%09%0A%09@Override%0A
 %09public void onU
@@ -1676,101 +1676,6 @@
 %0A%09%7D%0A
-%09%0A%09@Override%0A%09public void onDisable()%0A%09%7B%0A%09%09wurst.events.remove(UpdateListener.class, this);%0A%09%7D%0A
 %7D%0A

Update LogSpammerMod