general code tweaks and fixes

This commit is contained in:
J.T. McQuigg 2022-07-03 01:44:31 -04:00
parent a64fa24dcc
commit b661dd958c
7 changed files with 25 additions and 27 deletions

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@ -13,17 +13,17 @@ import com.velocitypowered.api.proxy.server.RegisteredServer;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.adde0109.ambassador.Forge.ForgeConnection;
import org.adde0109.ambassador.Forge.ForgeHandshakeHandler;
import org.adde0109.ambassador.Forge.ForgeHandshakeUtils;
import org.adde0109.ambassador.Forge.ForgeServerConnection;
import org.adde0109.ambassador.forge.ForgeConnection;
import org.adde0109.ambassador.forge.ForgeHandshakeHandler;
import org.adde0109.ambassador.forge.ForgeHandshakeUtils;
import org.adde0109.ambassador.forge.ForgeServerConnection;
import org.bstats.velocity.Metrics;
import org.slf4j.Logger;
import java.nio.file.Path;
import java.util.*;
@Plugin(id = "ambassador", name = "Ambassador", version = "0.2.0-SNAPSHOT", url = "", description = "", authors = {"adde0109"})
@Plugin(id = "ambassador", name = "Ambassador", version = "0.2.0-SNAPSHOT", authors = {"adde0109"})
public class Ambassador {
private final ProxyServer server;
@ -47,7 +47,7 @@ public class Ambassador {
@Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) {
Metrics metrics = metricsFactory.make(this, 15655);
metricsFactory.make(this, 15655);
config = AmbassadorConfig.readOrCreateConfig(dataDirectory,server,logger);
if(config != null) {

View File

@ -55,7 +55,7 @@ public class AmbassadorConfig {
}
catch (IOException e) {
logger.error("Config related error: " + e.toString());
logger.error("Config related error: " + e);
return null;
}
@ -78,7 +78,7 @@ public class AmbassadorConfig {
return ambassadorConfig;
}
catch (Exception e) {
logger.error("Config related error: " + e.toString());
logger.error("Config related error: " + e);
return null;
}
}
@ -115,7 +115,7 @@ public class AmbassadorConfig {
if (config != null) {
String serverName = config.getOrElse("forge-server", "");
if (!Objects.equals(serverName, ""))
handshakeServer = server.getServer(serverName)
handshakeServer = server.getServer(serverName)
.orElseThrow(() -> new Exception(serverName + "is not a registered server!"));
this.forced = config.getOrElse("forced",forced);
}

View File

@ -1,4 +1,4 @@
package org.adde0109.ambassador.Forge;
package org.adde0109.ambassador.forge;
import com.velocitypowered.api.event.Continuation;
import com.velocitypowered.api.proxy.LoginPhaseConnection;
@ -22,7 +22,7 @@ public class ForgeConnection {
public static CompletableFuture<ForgeConnection> sync(LoginPhaseConnection connection, ForgeServerConnection forgeServerConnection, Continuation continuation) {
CompletableFuture<ForgeConnection> future = new CompletableFuture<ForgeConnection>();
CompletableFuture<ForgeConnection> future = new CompletableFuture<>();
ForgeConnection forgeConnection = new ForgeConnection(connection);
forgeServerConnection.getHandshake().whenComplete((msg,ex) -> {
if (ex != null) {
@ -53,7 +53,7 @@ public class ForgeConnection {
}
public CompletableFuture<byte[]> sendModlist(byte[] modListPacket) {
CompletableFuture<byte[]> future = new CompletableFuture<byte[]>();
CompletableFuture<byte[]> future = new CompletableFuture<>();
connection.sendLoginPluginMessage(MinecraftChannelIdentifier.create("fml","loginwrapper"), modListPacket,
responseBody -> {
recivedClientModlist = responseBody;
@ -63,7 +63,7 @@ public class ForgeConnection {
}
CompletableFuture<byte[]> sendOther(List<byte[]> otherPackets) {
CompletableFuture<byte[]> future = new CompletableFuture<byte[]>();
CompletableFuture<byte[]> future = new CompletableFuture<>();
for (int i = 0;i<otherPackets.size();i++) {
connection.sendLoginPluginMessage(MinecraftChannelIdentifier.create("fml","loginwrapper"), otherPackets.get(i),
(i<(otherPackets.size()-1)) ? responseBody -> {} : responseBody -> {

View File

@ -1,4 +1,4 @@
package org.adde0109.ambassador.Forge;
package org.adde0109.ambassador.forge;
import com.velocitypowered.api.event.Continuation;
import com.velocitypowered.api.event.Subscribe;
@ -21,9 +21,9 @@ public class ForgeHandshakeHandler {
private final ProxyServer server;
private final Logger logger;
private Map<RegisteredServer, ForgeServerConnection>
forgeServerConnectionMap = new HashMap<RegisteredServer,ForgeServerConnection>();
private Map<InetSocketAddress,ForgeConnection> incomingForgeConnections = new HashMap<InetSocketAddress,ForgeConnection>();
private final Map<RegisteredServer, ForgeServerConnection>
forgeServerConnectionMap = new HashMap<>();
private final Map<InetSocketAddress,ForgeConnection> incomingForgeConnections = new HashMap<>();
public ForgeHandshakeHandler(AmbassadorConfig config, ProxyServer server, Logger logger) {

View File

@ -1,4 +1,4 @@
package org.adde0109.ambassador.Forge;
package org.adde0109.ambassador.forge;
import com.google.common.io.ByteArrayDataInput;
import com.velocitypowered.api.proxy.server.RegisteredServer;
@ -60,7 +60,7 @@ public class ForgeHandshakeUtils {
public static CompletableFuture<CachedServerHandshake> downloadHandshake(RegisteredServer forgeServer) {
CompletableFuture<CachedServerHandshake> future = new CompletableFuture<CachedServerHandshake>();
CompletableFuture<CachedServerHandshake> future = new CompletableFuture<>();
forgeServer.ping().whenComplete((msg,ex) -> {
if (ex != null) {
future.completeExceptionally(ex);
@ -78,7 +78,7 @@ public class ForgeHandshakeUtils {
}
public static CompletableFuture<CachedServerHandshake> downloadHandshake(RegisteredServer forgeServer, CachedServerHandshake oldHandshake) {
CompletableFuture<CachedServerHandshake> future = new CompletableFuture<CachedServerHandshake>();
CompletableFuture<CachedServerHandshake> future = new CompletableFuture<>();
forgeServer.ping().whenComplete((msg,ex) -> {
if (ex != null) {
future.completeExceptionally(ex);
@ -127,7 +127,7 @@ public class ForgeHandshakeUtils {
int recivedPartNr = Integer.parseInt((pair.getVersion().split(":")[0].split("-"))[0]);
placePartInArray(pair.getId().getBytes(StandardCharsets.ISO_8859_1), recivedPartNr - 1);
logger.info("Downloaded part " + String.valueOf(numberOfRecivedParts) + " out of " + String.valueOf(numberOfParts));
logger.info("Downloaded part " + numberOfRecivedParts + " out of " + numberOfParts);
}
@ -164,7 +164,7 @@ public class ForgeHandshakeUtils {
}
public static class CachedServerHandshake {
private long fingerprint;
private final long fingerprint;
public byte[] modListPacket;
public List<byte[]> otherPackets;

View File

@ -1,4 +1,4 @@
package org.adde0109.ambassador.Forge;
package org.adde0109.ambassador.forge;
import com.google.common.io.ByteArrayDataInput;
import com.velocitypowered.api.event.Continuation;
@ -34,9 +34,7 @@ public class ForgeServerConnection {
} else {
future = ForgeHandshakeUtils.HandshakeReceiver.downloadHandshake(handshakeServer,handshake);
}
future.thenAccept(p -> {
handshake = p;
});
future.thenAccept(p -> handshake = p);
return future;
}