Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Rusty Connector support #539

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@
/plugin/universal/test-environment/
gradle-app.setting
!gradle-wrapper.jar
.gradletasknamecache
.gradletasknamecache

# VS Code Gradle
bin
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ subprojects {
maven { url 'https://repo.onarandombox.com/content/groups/public' }
maven { url 'https://repo.codemc.org/repository/maven-public/' }
maven { url 'https://repo.alessiodp.com/releases/' }
maven { url "https://maven.mrnavastar.rocks/releases" }
}

shadowJar {
Expand Down
5 changes: 5 additions & 0 deletions plugin/common/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
apply plugin: "com.github.gmazzo.buildconfig"

repositories {
maven { url "https://maven.mrnavastar.rocks/releases" }
ajh123 marked this conversation as resolved.
Show resolved Hide resolved
}

dependencies {
/* PROVIDED */
compileOnly libs.multiverse
compileOnly libs.parties.api
compileOnly "group.aelysium:rustyconnector-toolkit:0.8.0"
ajh123 marked this conversation as resolved.
Show resolved Hide resolved

/* SHADED */
implementation 'org.screamingsandals.language.bedwars:BedWarsLanguage:' + (project.version =~ /^\d+.\d+/).findAll()?.first() + '-SNAPSHOT'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

package org.screamingsandals.bedwars;

import group.aelysium.rustyconnector.toolkit.RustyConnector;
import group.aelysium.rustyconnector.toolkit.mc_loader.central.IMCLoaderFlame;
import group.aelysium.rustyconnector.toolkit.mc_loader.central.IMCLoaderTinder;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.NotNull;
Expand All @@ -28,10 +31,7 @@
import org.screamingsandals.bedwars.config.RecordSave;
import org.screamingsandals.bedwars.database.DatabaseManager;
import org.screamingsandals.bedwars.entities.EntitiesManagerImpl;
import org.screamingsandals.bedwars.game.GameManagerImpl;
import org.screamingsandals.bedwars.game.GroupManagerImpl;
import org.screamingsandals.bedwars.game.ItemSpawnerTypeImpl;
import org.screamingsandals.bedwars.game.LocalGameLoaderImpl;
import org.screamingsandals.bedwars.game.*;
import org.screamingsandals.bedwars.holograms.LeaderboardHolograms;
import org.screamingsandals.bedwars.holograms.StatisticsHolograms;
import org.screamingsandals.bedwars.inventories.GamesInventory;
Expand Down Expand Up @@ -72,10 +72,7 @@

import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;

@Plugin(
Expand All @@ -95,7 +92,8 @@
"PerWorldInventory",
"SlimeWorldManager",
"My_Worlds",
"Parties"
"Parties",
"rustyconnector-paper"
})
@Init(
services = {
Expand Down Expand Up @@ -151,6 +149,8 @@ public class BedWarsPlugin implements BedwarsAPI {
@Getter
private final HashMap<String, ItemSpawnerTypeImpl> spawnerTypes = new HashMap<>();

private IMCLoaderFlame<?> flame;

public static BedWarsPlugin getInstance() {
return instance;
}
Expand Down Expand Up @@ -335,6 +335,19 @@ public void enable() {
Server.getConsoleSender().sendMessage(Component.text("https://www.patreon.com/screamingsandals", Color.WHITE));

HologramManager.setPreferDisplayEntities(MainConfig.getInstance().node("prefer-1-19-4-display-entities").getBoolean());

if (GameImpl.isRustyConnectorEnabled()) {
ajh123 marked this conversation as resolved.
Show resolved Hide resolved
Optional<IMCLoaderTinder> tinderHolder = RustyConnector.Toolkit.mcLoader();
if (tinderHolder.isPresent()) {
IMCLoaderTinder tinder = tinderHolder.get();
tinder.onStart(flame -> {
this.flame = flame;
Server.getConsoleSender().sendMessage(Component.text("Rusty Connector's Tinder found!", Color.GREEN));
});
} else {
Server.getConsoleSender().sendMessage(Component.text("Rusty Connector's Tinder not found!", Color.RED));
}
}
}

@OnDisable
Expand Down Expand Up @@ -414,4 +427,8 @@ public static boolean isDisabling() {
public void saveResource(@NotNull String resourcePath, boolean replace) {
PluginUtils.saveResource(pluginDescription, logger, resourcePath, replace);
}

public IMCLoaderFlame<?> getFlame() {
return flame;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ public void load() {
.key("rebuilding").defValue("%name%: Rebuilding...")
.key("disabled").defValue("%name%: Game is disabled")
.back()
.section("rustyConnector")
.key("enabled").defValue(false)
.key("family").defValue("hub")
.back()
.back()
.section("ignored-blocks")
.key("enabled").migrateOldAbsoluteKey("farmBlocks", "enable").defValue(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ public static boolean isBungeeEnabled() {
return MainConfig.getInstance().node("bungee", "enabled").getBoolean();
}

public static boolean isRustyConnectorEnabled() {
return MainConfig.getInstance().node("bungee", "rustyConnector", "enabled").getBoolean();
}

public void setWorld(World world) {
if (this.world == null) {
this.world = world;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@

package org.screamingsandals.bedwars.utils;

import group.aelysium.rustyconnector.toolkit.RustyConnector;
import group.aelysium.rustyconnector.toolkit.core.packet.Packet;
import group.aelysium.rustyconnector.toolkit.core.packet.PacketIdentification;
import group.aelysium.rustyconnector.toolkit.mc_loader.central.IMCLoaderTinder;
import lombok.experimental.UtilityClass;
import org.screamingsandals.bedwars.BedWarsPlugin;
import org.screamingsandals.bedwars.config.MainConfig;
import org.screamingsandals.bedwars.game.GameImpl;
import org.screamingsandals.bedwars.lib.debug.Debug;
import org.screamingsandals.lib.CustomPayload;
import org.screamingsandals.lib.Server;
import org.screamingsandals.lib.player.Player;
import org.screamingsandals.lib.spectator.Component;
import org.screamingsandals.lib.tasker.DefaultThreads;
Expand Down Expand Up @@ -63,24 +70,53 @@ public void sendPlayerBungeeMessage(Player player, String string) {

private void internalMove(Player player, boolean restart) {
var server = MainConfig.getInstance().node("bungee", "server").getString("hub");
var out = new ByteArrayOutputStream();
var dout = new DataOutputStream(out);
var rustySuccess = true;

try {
dout.writeUTF("Connect");
dout.writeUTF(server);
if (GameImpl.isRustyConnectorEnabled()) {
if (BedWarsPlugin.getInstance().getFlame() != null) {
var familyName = MainConfig.getInstance().node("bungee", "rustyConnector", "family").getString("hub");

CustomPayload.send(player, "BungeeCord", out.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
Debug.info("Player " + player.getName() + " has been moved to hub server.");
if (!restart && MainConfig.getInstance().node("bungee", "kick-when-proxy-too-slow").getBoolean(true)) {
Tasker.runDelayed(DefaultThreads.GLOBAL_THREAD, () -> {
if (player.isOnline()) {
player.kick(Component.text("BedWars can't properly transfer player through bungee network. Contact server admin."));
try {
Packet message = BedWarsPlugin.getInstance().getFlame().services().packetBuilder().newBuilder()
.identification(PacketIdentification.from("RC", "SP"))
.sendingToProxy()
.parameter("f", familyName)
.parameter("p", player.getUniqueId().toString())
.build();

BedWarsPlugin.getInstance().getFlame().services().magicLink().connection().orElseThrow().publish(message);
Debug.info("Player " + player.getName() + " has been moved to hub server.");
} catch (Exception e) {
rustySuccess = false;
Debug.warn("Rusty Connector transfer failed, falling back to Bungee.");
e.printStackTrace();
}
}, 20, TaskerTime.TICKS);
} else {
rustySuccess = false;
}
}

if (!rustySuccess) {

var out = new ByteArrayOutputStream();
var dout = new DataOutputStream(out);

try {
dout.writeUTF("Connect");
dout.writeUTF(server);

CustomPayload.send(player, "BungeeCord", out.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
Debug.info("Player " + player.getName() + " has been moved to hub server.");
if (!restart && MainConfig.getInstance().node("bungee", "kick-when-proxy-too-slow").getBoolean(true)) {
Tasker.runDelayed(DefaultThreads.GLOBAL_THREAD, () -> {
if (player.isOnline()) {
player.kick(Component.text("BedWars can't properly transfer player through bungee network. Contact server admin."));
}
}, 20, TaskerTime.TICKS);
}
}
}
}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pluginManagement {
maven {
url = "https://repo.screamingsandals.org/public/"
}

maven { url "https://maven.mrnavastar.rocks/releases" }
ajh123 marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down