Skip to content

Commit

Permalink
Launch server and client on launch
Browse files Browse the repository at this point in the history
  • Loading branch information
PancakeTAS authored and ScribbleTAS committed Jun 16, 2023
1 parent e0a2f1d commit 56e8f85
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/main/java/com/minecrafttas/tasmod/TASmod.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.minecrafttas.common.events.EventListener;
import com.minecrafttas.common.events.EventServer.EventServerInit;
import com.minecrafttas.common.events.EventServer.EventServerStop;
import com.minecrafttas.server.Server;
import com.minecrafttas.tasmod.commands.clearinputs.ClearInputsPacket;
import com.minecrafttas.tasmod.commands.clearinputs.CommandClearInputs;
import com.minecrafttas.tasmod.commands.folder.CommandFolder;
Expand Down Expand Up @@ -83,6 +84,8 @@ public class TASmod implements ModInitializer, EventServerInit, EventServerStop{

public static final TickScheduler tickSchedulerServer = new TickScheduler();

public static Server server;

@Override
public void onServerInit(MinecraftServer server) {
serverInstance = server;
Expand Down Expand Up @@ -125,9 +128,15 @@ public void onServerInit(MinecraftServer server) {
}

@Override
public void onServerStop(MinecraftServer server) {
public void onServerStop(MinecraftServer mcserver) {
serverInstance=null;
packetServer.close();
try {
if (server != null) server.close();
} catch (IOException e) {
LOGGER.error("Unable to close TASmod server: {}", e);
e.printStackTrace();
}
}

public static MinecraftServer getServerInstance() {
Expand Down Expand Up @@ -193,5 +202,11 @@ public void onInitialize() {

PacketSerializer.registerPacket(PlayUntilPacket.class);

try {
server = new Server(5555);
} catch (Exception e) {
LOGGER.error("Unable to launch TASmod server: {}", e);
}

}
}
15 changes: 15 additions & 0 deletions src/main/java/com/minecrafttas/tasmod/TASmodClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import org.lwjgl.input.Keyboard;

Expand All @@ -15,6 +16,7 @@
import com.minecrafttas.common.events.EventClient.EventPlayerJoinedClientSide;
import com.minecrafttas.common.events.EventClient.EventPlayerLeaveClientSide;
import com.minecrafttas.common.events.EventListener;
import com.minecrafttas.server.Client;
import com.minecrafttas.tasmod.externalGui.InputContainerView;
import com.minecrafttas.tasmod.gui.InfoHud;
import com.minecrafttas.tasmod.handlers.InterpolationHandler;
Expand Down Expand Up @@ -71,6 +73,8 @@ public class TASmodClient implements ClientModInitializer, EventClientInit, Even

public static InterpolationHandler interpolation = new InterpolationHandler();

public static Client client;

public static void createTASDir() {
File tasDir=new File(tasdirectory);
if(!tasDir.exists()) {
Expand Down Expand Up @@ -125,6 +129,17 @@ protected boolean isKeyDown(KeyBinding i) {
EventListener.register(keybindManager);

EventListener.register(interpolation);

try {
// connect to server and authenticate
client = new Client("127.0.0.1", 5555);
UUID uuid = mc.getSession().getProfile().getId();
if (uuid == null) // dev environment
uuid = UUID.randomUUID();
client.authenticate(uuid);
} catch (Exception e) {
TASmod.LOGGER.error("Unable to connect TASmod client: {}", e);
}
}

@Override
Expand Down

0 comments on commit 56e8f85

Please sign in to comment.