Skip to content

Commit

Permalink
More iteration + adapt MCLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Martin committed Jun 10, 2024
1 parent 3c45313 commit 8aff31d
Show file tree
Hide file tree
Showing 74 changed files with 649 additions and 2,429 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package group.aelysium.rustyconnector.common.lang;

import group.aelysium.rustyconnector.toolkit.common.logger.PluginLogger;
import group.aelysium.rustyconnector.toolkit.common.logger.IPluginLogger;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.JoinConfiguration;

Expand All @@ -21,7 +21,7 @@ public final static JoinConfiguration newlines() {
public interface Message {
Component build();

default void send(PluginLogger sender) {
default void send(IPluginLogger sender) {
sender.send(
join(
newlines(),
Expand All @@ -34,7 +34,7 @@ default void send(PluginLogger sender) {
public interface ParameterizedMessage1<A1> {
Component build(A1 arg1);

default void send(PluginLogger sender, A1 arg1) {
default void send(IPluginLogger sender, A1 arg1) {
sender.send(
join(
JoinConfiguration.separator(newline()),
Expand All @@ -47,7 +47,7 @@ default void send(PluginLogger sender, A1 arg1) {
public interface ParameterizedMessage2<A1, A2> {
Component build(A1 arg1, A2 arg2);

default void send(PluginLogger sender, A1 arg1, A2 arg2) {
default void send(IPluginLogger sender, A1 arg1, A2 arg2) {
sender.send(
join(
newlines(),
Expand All @@ -60,7 +60,7 @@ default void send(PluginLogger sender, A1 arg1, A2 arg2) {
public interface ParameterizedMessage3<A1, A2, A3> {
Component build(A1 arg1, A2 arg2, A3 arg3);

default void send(PluginLogger sender, A1 arg1, A2 arg2, A3 arg3) {
default void send(IPluginLogger sender, A1 arg1, A2 arg2, A3 arg3) {
sender.send(
join(
newlines(),
Expand All @@ -73,7 +73,7 @@ default void send(PluginLogger sender, A1 arg1, A2 arg2, A3 arg3) {
public interface ParameterizedMessage4<A1, A2, A3, A4> {
Component build(A1 arg1, A2 arg2, A3 arg3, A4 arg4);

default void send(PluginLogger sender, A1 arg1, A2 arg2, A3 arg3, A4 arg4) {
default void send(IPluginLogger sender, A1 arg1, A2 arg2, A3 arg3, A4 arg4) {
sender.send(
join(
newlines(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected <T> T getNode(String node, Class<T> type) throws IllegalStateException
} catch (ClassCastException e) {
throw new IllegalStateException("The node ["+node+"] is of the wrong data type! Make sure you are using the correct type of data!");
} catch (Exception e) {
throw new IllegalStateException("Unable to register the node: "+node);
throw new IllegalStateException("Unable to registerProxy the node: "+node);
}
}
public String getRaw(String key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import group.aelysium.rustyconnector.toolkit.common.config.IConfigService;
import group.aelysium.rustyconnector.toolkit.common.config.IYAML;
import group.aelysium.rustyconnector.toolkit.common.logger.PluginLogger;
import group.aelysium.rustyconnector.toolkit.common.logger.IPluginLogger;
import group.aelysium.rustyconnector.common.config.YAML;
import group.aelysium.rustyconnector.common.exception.NoOutputException;
import net.kyori.adventure.text.Component;
Expand All @@ -20,7 +20,7 @@ protected RootLanguageConfig(Path dataFolder) {
protected String language;
public String getLanguage() { return this.language; }

protected void generate(PluginLogger logger) throws Exception {
protected void generate(IPluginLogger logger) throws Exception {
logger.send(Component.text("Building "+this.configPointer.getName()+"...", NamedTextColor.DARK_GRAY));
try {
if (!this.configPointer.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ public JsonObject toJSON() {
return object;
}

protected static class NakedBuilder {
public static Builder New() {
return new Builder();
}

private static class NakedBuilder {
private Integer protocolVersion = Packet.protocolVersion();
private PacketIdentification id;
private Target sender;
Expand Down Expand Up @@ -139,33 +143,25 @@ public Packet build() {
public static class Builder implements IPacket.Builder {
private final NakedBuilder builder = new NakedBuilder();

public static class ReadyForSending implements IPacket.Builder.ReadyForSending {
protected Builder() {}

public static class PrepareForSending implements IPacket.Builder.PrepareForSending {
private final NakedBuilder builder;

protected ReadyForSending(NakedBuilder builder) {
protected PrepareForSending(NakedBuilder builder) {
this.builder = builder;
}

public ReadyForSending parameter(String key, String value) {
public PrepareForSending parameter(String key, String value) {
this.builder.parameter(key, new PacketParameter(value));
return this;
}

public ReadyForSending parameter(String key, PacketParameter value) {
public PrepareForSending parameter(String key, PacketParameter value) {
this.builder.parameter(key, value);
return this;
}

private IMagicLink fetchMagicLink() {
try {
return RC.P.MagicLink();
} catch (Exception ignore) {}
try {
return RC.M.MagicLink();
} catch (Exception ignore) {}
throw new RuntimeException("No available flames existed in order to send the packet!");
}

private void assignTargetAndSender(@NotNull Packet.Target target, Target sender) {
this.builder.target(target);

Expand All @@ -185,19 +181,38 @@ private void assignTargetAndSender(@NotNull Packet.Target target) {
assignTargetAndSender(target, null);
}

public void sendTo(Target target) {
public ReadyForSending addressedTo(Target target) {
assignTargetAndSender(target);

Packet packet = this.builder.build();

IMagicLink magicLinkService = fetchMagicLink();
((MagicLinkCore.Connection) magicLinkService.connection().orElseThrow()).publish(packet);
return new ReadyForSending(this.builder);
}

public void replyTo(IPacket targetPacket) {
public ReadyForSending addressedTo(IPacket targetPacket) {
assignTargetAndSender(targetPacket.target(), targetPacket.sender());
this.builder.response(ResponseTarget.respondTo(targetPacket.responseTarget().ownTarget()));

return new ReadyForSending(this.builder);
}
}
public static class ReadyForSending implements IPacket.Builder.ReadyForSending {
private final NakedBuilder builder;

protected ReadyForSending(NakedBuilder builder) {
this.builder = builder;
}

private IMagicLink fetchMagicLink() {
try {
return RC.P.MagicLink();
} catch (Exception ignore) {}
try {
return RC.M.MagicLink();
} catch (Exception ignore) {}
throw new RuntimeException("No available flames existed in order to send the packet!");
}

@Override
public void send() throws RuntimeException {
Packet packet = this.builder.build();

IMagicLink magicLinkService = fetchMagicLink();
Expand All @@ -209,8 +224,8 @@ public void replyTo(IPacket targetPacket) {
* The identification of this packet.
* Identification is what differentiates a "Server ping packet" from a "Teleport player packet"
*/
public ReadyForSending identification(PacketIdentification id) {
return new ReadyForSending(builder.identification(id));
public PrepareForSending identification(PacketIdentification id) {
return new PrepareForSending(builder.identification(id));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public FailService(int numberOfFails, LiquidTimestamp period) {
}

/**
* Triggers the fail service, telling it to register a new failure.
* Triggers the fail service, telling it to registerProxy a new failure.
* @param message The error message to throw if this trigger fails.
* @throws RuntimeException When the {@link FailService} has failed to many times and can't anymore.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ public interface ServerManager<S, F> {

/**
* Creates a new server which can be registered to the proxy.
* @param server The server to register to this manager.
* @param server The server to registerProxy to this manager.
*/
void add(S server);

/**
* Register a server to the network
* @param server The server to register
* @param server The server to registerProxy
*/
void registerServer(S server, F family);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
package group.aelysium.rustyconnector.common.packets;

import group.aelysium.rustyconnector.common.magic_link.Packet;
import group.aelysium.rustyconnector.toolkit.common.magic_link.packet.IPacket;

public interface MCLoader {
class Lock extends Packet.Wrapper {
public Lock(Packet packet) {
public Lock(IPacket packet) {
super(packet);
}

public static Packet build(MCLoaderFlame flame) {
return flame.services().packetBuilder().newBuilder()
.identification(BuiltInIdentifications.LOCK_SERVER)
.sendingToProxy()
.build();
}
}
class Unlock extends Packet.Wrapper {
public Unlock(Packet packet) {
public Unlock(IPacket packet) {
super(packet);
}

public static Packet build(MCLoaderFlame flame) {
return flame.services().packetBuilder().newBuilder()
.identification(BuiltInIdentifications.UNLOCK_SERVER)
.sendingToProxy()
.build();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package group.aelysium.rustyconnector.common.packets;

import group.aelysium.rustyconnector.common.magic_link.Packet;
import group.aelysium.rustyconnector.toolkit.common.magic_link.packet.IPacket;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -15,7 +16,7 @@ public UUID uuid() {
return UUID.fromString(this.parameters().get(Parameters.PLAYER_UUID).getAsString());
}

public SendPlayerPacket(Packet packet) {
public SendPlayerPacket(IPacket packet) {
super(packet);
}

Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 8aff31d

Please sign in to comment.