Created a network packet for when a client presses a key. (Mod is now also client sided). Renamed some event handlers. Made it so after a client presses a key their grace period starts. After the grace period ends the player is removed from the list.

This commit is contained in:
micle
2021-06-03 17:01:28 +01:00
parent 21381e07af
commit 2688402c40
8 changed files with 105 additions and 6 deletions

View File

@ -1,16 +1,37 @@
package com.micle.loginprotection.setup;
import com.micle.loginprotection.events.OnEntityDamageEventHandler;
import com.micle.loginprotection.events.OnEntityJoinEventHandler;
import com.micle.loginprotection.LoginProtection;
import com.micle.loginprotection.events.OnPlayerDamageEventHandler;
import com.micle.loginprotection.events.OnPlayerJoinEventHandler;
import com.micle.loginprotection.network.C2SKeyPress;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.network.NetworkRegistry;
import net.minecraftforge.fml.network.simple.SimpleChannel;
public class Registration {
private static final String PROTOCOL_VERSION = "1";
public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel(
new ResourceLocation(LoginProtection.MOD_ID, "main"),
() -> PROTOCOL_VERSION,
PROTOCOL_VERSION::equals,
PROTOCOL_VERSION::equals
);
public static void register() {
IEventBus mod_event_bus = FMLJavaModLoadingContext.get().getModEventBus();
MinecraftForge.EVENT_BUS.register(new OnEntityJoinEventHandler());
MinecraftForge.EVENT_BUS.register(new OnEntityDamageEventHandler());
MinecraftForge.EVENT_BUS.register(new OnPlayerJoinEventHandler());
MinecraftForge.EVENT_BUS.register(new OnPlayerDamageEventHandler());
int id = 0;
INSTANCE.registerMessage(id++,
C2SKeyPress.class,
C2SKeyPress::encode,
C2SKeyPress::decode,
C2SKeyPress::handle
);
}
}