|
2 | 2 |
|
3 | 3 | import java.net.InetSocketAddress; |
4 | 4 | import java.util.ArrayList; |
| 5 | +import java.util.List; |
5 | 6 | import java.util.Objects; |
6 | 7 |
|
7 | 8 | import com.google.gson.JsonObject; |
@@ -79,8 +80,13 @@ public static void onMessage(String message) { |
79 | 80 | case "inv" -> SocketHandler.actionQueue.add(new SendInventory()); |
80 | 81 | case "setinv" -> SocketHandler.actionQueue.add(new SetInventory(content)); |
81 | 82 | case "give" -> SocketHandler.actionQueue.add(new Give(content)); |
| 83 | + case "mode" -> SocketHandler.actionQueue.add(new Mode(content)); |
82 | 84 | default -> connection.send("invalid"); |
83 | 85 | } |
| 86 | + topAction = getTopAction(); |
| 87 | + if(topAction != null && arguments.length > 1 && Objects.equals(topAction.name, arguments[0])) { |
| 88 | + topAction.message(connection,content); |
| 89 | + } |
84 | 90 | Action firstAction = actionQueue.get(0); |
85 | 91 | if(firstAction == null) return; |
86 | 92 | if(firstAction.active) return; |
@@ -199,7 +205,7 @@ private enum Method { |
199 | 205 | SWAP((ArrayList<ItemStack> templates, WebSocket responder) -> Utility.createSwapper(templates, () -> { |
200 | 206 | CodeClient.currentAction = new None(); |
201 | 207 | if(responder.isOpen()) responder.send("place done"); |
202 | | - next();})), |
| 208 | + next();}).swap()), |
203 | 209 | ; |
204 | 210 |
|
205 | 211 | public final CreatePlacer createPlacer; |
@@ -332,4 +338,29 @@ public void start(WebSocket responder) { |
332 | 338 | @Override |
333 | 339 | public void message(WebSocket responder, String message) {} |
334 | 340 | } |
| 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 | + } |
335 | 366 | } |
0 commit comments