Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@
/**
* Represents a code block with a chest (can have parameters + tags)
*/
public interface ChestCodeBlock extends CodeBlock {
public interface ChestCodeBlock{

List<Value> getParameters();

List<Tag> getTags();

@Override
String getBlock();

String getAction();

int getWeight();

default JsonObject toJson() {
JsonObject json = CodeBlock.super.toJson();
JsonObject args = new JsonObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

public interface CodeBlock {

List<Value> getParameters();

String getBlock();

String getAction();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package net.ryanland.dfschematics.df.code;

import com.google.gson.JsonObject;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MessageHandlerRegistry {


private static final Map<String, MessageHandler> handlers = new HashMap<>();

static {
handlers.put("default", new DefaultHandler());
handlers.put("auth", new AuthHandler());
handlers.put("write_code read_plot default", new AuthHandler());
handlers.put("BASIC", new SizeHandler());
handlers.put("LARGE", new SizeHandler());
handlers.put("MASSIVE", new SizeHandler());
handlers.put("MEGA", new SizeHandler());
}

interface MessageHandler {
void handle(String msg);
}

// Implementación del manejador para el mensaje "default"
static class DefaultHandler implements MessageHandler {
@Override
public void handle(String msg) {
socket.send("scopes write_code read_plot");
MainController.instance.error("Please authorize DFSchematics to place templates in-game...");
}
}

static class AuthHandler implements MessageHandler {
@Override
public void handle(String msg) {
socket.send("size");
}
}

static class SizeHandler implements MessageHandler {
@Override
public void handle(String msg) {
List<CodeBlock> codeBlocks = MainController.schematic.getTemplateFactory().generateCodeBlocks();
placeTemplates(MainController.schematic.getTemplateFactory().splitCodeBlocks(codeBlocks));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.ryanland.dfschematics.df.code;

public abstract class SetVariable implements ChestCodeBlock {
public abstract class SetVariable implements CodeBlock {

@Override
public String getBlock() {
Expand Down