Skip to content

Commit a9834f7

Browse files
committed
api for swap and compacter and mode
1 parent 67de16b commit a9834f7

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ yarn_mappings=1.20.2+build.4
88
loader_version=0.14.24
99

1010
# Mod Properties
11-
mod_version=1.5.8
11+
mod_version=1.5.9
1212
maven_group=dev.dfonline
1313
archives_base_name=CodeClient
1414

src/main/java/dev/dfonline/codeclient/websocket/SocketHandler.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.net.InetSocketAddress;
44
import java.util.ArrayList;
5+
import java.util.List;
56
import java.util.Objects;
67

78
import com.google.gson.JsonObject;
@@ -79,8 +80,13 @@ public static void onMessage(String message) {
7980
case "inv" -> SocketHandler.actionQueue.add(new SendInventory());
8081
case "setinv" -> SocketHandler.actionQueue.add(new SetInventory(content));
8182
case "give" -> SocketHandler.actionQueue.add(new Give(content));
83+
case "mode" -> SocketHandler.actionQueue.add(new Mode(content));
8284
default -> connection.send("invalid");
8385
}
86+
topAction = getTopAction();
87+
if(topAction != null && arguments.length > 1 && Objects.equals(topAction.name, arguments[0])) {
88+
topAction.message(connection,content);
89+
}
8490
Action firstAction = actionQueue.get(0);
8591
if(firstAction == null) return;
8692
if(firstAction.active) return;
@@ -199,7 +205,7 @@ private enum Method {
199205
SWAP((ArrayList<ItemStack> templates, WebSocket responder) -> Utility.createSwapper(templates, () -> {
200206
CodeClient.currentAction = new None();
201207
if(responder.isOpen()) responder.send("place done");
202-
next();})),
208+
next();}).swap()),
203209
;
204210

205211
public final CreatePlacer createPlacer;
@@ -332,4 +338,29 @@ public void start(WebSocket responder) {
332338
@Override
333339
public void message(WebSocket responder, String message) {}
334340
}
341+
private static class Mode extends SocketHandler.Action {
342+
private static final List<String> commands = List.of("play","build","code","dev");
343+
private final String command;
344+
345+
Mode(String command) {
346+
super("mode");
347+
this.command = commands.contains(command) ? command : "";
348+
}
349+
350+
@Override
351+
public void set(WebSocket responder) {
352+
353+
}
354+
@Override
355+
public void start(WebSocket responder) {
356+
if (CodeClient.location instanceof Plot && !command.isEmpty()) {
357+
CodeClient.MC.getNetworkHandler().sendCommand(command);
358+
} else {
359+
responder.send(CodeClient.location.name());
360+
}
361+
next();
362+
}
363+
@Override
364+
public void message(WebSocket responder, String message) {}
365+
}
335366
}

0 commit comments

Comments
 (0)