diff options
Diffstat (limited to 'src/main/java/de/torui/coflsky/EventRegistry.java')
-rw-r--r-- | src/main/java/de/torui/coflsky/EventRegistry.java | 90 |
1 files changed, 41 insertions, 49 deletions
diff --git a/src/main/java/de/torui/coflsky/EventRegistry.java b/src/main/java/de/torui/coflsky/EventRegistry.java index aa1592d..4ef15a9 100644 --- a/src/main/java/de/torui/coflsky/EventRegistry.java +++ b/src/main/java/de/torui/coflsky/EventRegistry.java @@ -1,70 +1,62 @@ package de.torui.coflsky; -import java.net.URI; -import java.net.URISyntaxException; +import java.util.UUID; -import de.torui.coflsky.websocket.WSClient; import net.minecraft.client.Minecraft; -import net.minecraft.client.multiplayer.ServerData; -import net.minecraftforge.fml.common.SidedProxy; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.gui.MinecraftServerGui; +import net.minecraftforge.event.world.WorldEvent; +import net.minecraftforge.fml.client.FMLClientHandler; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent; import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedOutEvent; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; +import net.minecraftforge.fml.common.network.FMLNetworkEvent; +import net.minecraftforge.fml.common.network.FMLNetworkEvent.ClientConnectedToServerEvent; +import net.minecraftforge.fml.common.network.FMLNetworkEvent.ClientDisconnectionFromServerEvent; +import net.minecraftforge.fml.server.FMLServerHandler; public class EventRegistry{ - @SideOnly(Side.CLIENT) @SubscribeEvent - public void PlayerLoggedIn(PlayerLoggedInEvent plie) { - - System.out.println("COFLSKY initialized"); + public void onConnectedToServerEvent(ClientConnectedToServerEvent event) { - if(plie.player.getEntityWorld().isRemote) { - //is a server - /*ServerData sd = Minecraft.getMinecraft().getCurrentServerData(); - if(sd != null) { - System.out.println("ServerIP:= " + sd.serverIP); - } else { - System.out.println("Could not get serverdata"); - } - */ - if(CoflSky.WS == null) { - try { - String uuid = Minecraft.getMinecraft().thePlayer.getPersistentID().toString(); - //String uuid = Minecraft.getMinecraft().thePlayer.getUUID(null) - CoflSky.WS = new WSClient(new URI("wss://sky-commands.coflnet.com/modsocket?uuid=" + uuid)); - } catch (URISyntaxException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - Thread t = new Thread(CoflSky.WS); + if(!event.isLocal) { + String serverIP = Minecraft.getMinecraft().getCurrentServerData().serverIP; + + if(false && serverIP.equals("hypixel.net")) { } + //UUID.randomUUID().toString(); - } else { - System.out.println("World is not remote"); + //String username = Minecraft.getSessionInfo().get("X-Minecraft-Username"); + + //String id = FMLClientHandler.instance().getClient().thePlayer.getUniqueID().toString(); + + String id = UUID.randomUUID().toString();//Minecraft.getMinecraft().thePlayer.getUniqueID().toString(); + System.out.println("PlayerUUID:" + id); + CoflSky.PlayerUUID = id; + + System.out.println("Connected to server"); + CoflSky.Wrapper.start(); + System.out.println("CoflSky started"); } - - } + } + + @SubscribeEvent + public void onDisconnectedFromServerEvent(ClientDisconnectionFromServerEvent event) { + System.out.println("Disconnected from server"); + CoflSky.Wrapper.stop(); + System.out.println("CoflSky stopped"); + } + /*@SubscribeEvent +public void OnSomething(FMLNetworkEvent.ClientConnectedToServerEvent event) { + System.out.println("Client connect to server from network"); +} - @SideOnly(Side.CLIENT) @SubscribeEvent public void PlayerLoggedOut(PlayerLoggedOutEvent ploe) { - System.out.println("COFLSKY disabled"); - - if(CoflSky.WS != null) { - try { - CoflSky.WS.closeBlocking(); - CoflSky.WS = null; - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } - } + //CoflSky.Wrapper.stop(); + System.out.println("COFLSKY disabled"); + }*/ } |