Skip to content

Commit

Permalink
tidy up commands
Browse files Browse the repository at this point in the history
  • Loading branch information
onebeastchris committed Jan 9, 2025
1 parent a45ff2a commit 3128689
Show file tree
Hide file tree
Showing 20 changed files with 398 additions and 218 deletions.
20 changes: 1 addition & 19 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

- uses: actions/setup-java@v3
with:
java-version: 17
java-version: 21
distribution: temurin

- name: Build
Expand All @@ -27,24 +27,6 @@ jobs:
arguments: build
cache-read-only: ${{ github.ref_name != 'master' && github.ref_name != 'development' }}

- name: Build image
if: ${{ github.repository == 'GeyserMC/GlobalLinkServer' && github.ref_name == 'master' }}
run: docker build . -t $IMAGE_NAME --label "run-number=${GITHUB_RUN_ID}"
- name: Registry login
if: ${{ github.repository == 'GeyserMC/GlobalLinkServer' && github.ref_name == 'master' }}
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Push image
if: ${{ github.repository == 'GeyserMC/GlobalLinkServer' && github.ref_name == 'master' }}
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
- name: Notify Discord
if: ${{ (success() || failure()) && github.repository == 'GeyserMC/GlobalLinkServer' }}
uses: Tim203/actions-git-discord-webhook@main
Expand Down
6 changes: 0 additions & 6 deletions Dockerfile

This file was deleted.

28 changes: 21 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
plugins {
alias(libs.plugins.indra)
alias(libs.plugins.indra.licenser.spotless)
alias(libs.plugins.paperweight)
alias(libs.plugins.runpaper)
}

group = "org.geysermc.globallinkserver"

dependencies {
implementation(libs.gson) // newer version required for record support
paperweight.paperDevBundle("1.21.4-R0.1-SNAPSHOT")

implementation(libs.gson) // newer version required for record support
implementation(libs.bundles.fastutil)

compileOnly(libs.spigot.api)
compileOnly(libs.geyser.api)

compileOnly(libs.floodgate.api)
implementation(libs.mariadb.client)

compileOnly(libs.checker.qual)
}

Expand All @@ -28,7 +27,7 @@ indra {
mitLicense()

javaVersions {
target(17)
target(21)
}

spotless {
Expand All @@ -40,6 +39,21 @@ indra {
}
}

repositories {
mavenLocal()

maven("https://repo.opencollab.dev/main")
maven("https://repo.papermc.io/repository/maven-public/")

mavenCentral()

maven("https://jitpack.io") {
content { includeGroupByRegex("com\\.github\\..*") }
}
}

paperweight.reobfArtifactConfiguration = io.papermc.paperweight.userdev.ReobfArtifactConfiguration.MOJANG_PRODUCTION

tasks.jar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) })
Expand Down
10 changes: 5 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
[versions]
gson = "2.10.1"
fastutil = "8.5.2"
adventure-text = "4.15.0-20231207.074016-23" # Match version to MCPL
mariadb-client = "2.7.3"
checker-qual = "3.21.1"
indra = "3.1.2"

spigot-api = "1.16.5-R0.1-SNAPSHOT"
paperweight = "2.0.0-beta.12"
runpaper = "2.3.1"

[libraries]
spigot-api = { group = "org.spigotmc", name = "spigot-api", version.ref = "spigot-api" }
geyser-api = { group = "org.geysermc.geyser", name = "api", version = "2.6.0-SNAPSHOT" }
floodgate-api = { group = "org.geysermc.floodgate", name = "api", version = "2.2.3-SNAPSHOT" }

gson = { module = "com.google.code.gson:gson", version.ref = "gson" }

Expand All @@ -26,6 +24,8 @@ checker-qual = { module = "org.checkerframework:checker-qual", version.ref = "ch
indra = { id = "net.kyori.indra", version.ref = "indra" }
indra-publishing = { id = "net.kyori.indra.publishing", version.ref = "indra" }
indra-licenser-spotless = { id = "net.kyori.indra.licenser.spotless", version.ref = "indra" }
paperweight = { id = "io.papermc.paperweight.userdev", version.ref = "paperweight" }
runpaper = { id = "xyz.jpenilla.run-paper", version.ref = "runpaper" }

[bundles]
fastutil = [ "fastutil-int-int-maps", "fastutil-int-object-maps", "fastutil-object-int-maps", "fastutil-object-object-maps" ]
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
22 changes: 13 additions & 9 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -83,7 +85,9 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -144,15 +148,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -201,11 +205,11 @@ fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
22 changes: 12 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down Expand Up @@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
14 changes: 3 additions & 11 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
@file:Suppress("UnstableApiUsage")

dependencyResolutionManagement {
repositoriesMode = RepositoriesMode.FAIL_ON_PROJECT_REPOS
pluginManagement {
repositories {
mavenLocal()

maven("https://repo.opencollab.dev/main")

mavenCentral()

maven("https://jitpack.io") {
content { includeGroupByRegex("com\\.github\\..*") }
}
gradlePluginPortal()
maven("https://repo.papermc.io/repository/maven-public/")
}
}

Expand Down
100 changes: 77 additions & 23 deletions src/main/java/org/geysermc/globallinkserver/GlobalLinkServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,106 @@
*/
package org.geysermc.globallinkserver;

import java.util.Timer;
import java.util.TimerTask;
import java.util.List;
import java.util.logging.Logger;

import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager;
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.globallinkserver.config.Config;
import org.geysermc.globallinkserver.config.ConfigReader;
import org.geysermc.globallinkserver.link.LinkManager;
import org.geysermc.globallinkserver.util.CommandUtils;
import org.geysermc.globallinkserver.util.Utils;

public class GlobalLinkServer extends JavaPlugin {
private static final Timer TIMER = new Timer();
@SuppressWarnings("UnstableApiUsage")
public class GlobalLinkServer extends JavaPlugin implements Listener {
public static Logger LOGGER;
public static LinkManager linkManager;

public final static Component LINK_INSTRUCTIONS = Component.text("Run the ").color(NamedTextColor.AQUA)
.append(Component.text("`/link`", NamedTextColor.GREEN))
.append(Component.text(" command to link your accounts.", NamedTextColor.AQUA));

private LinkManager linkManager;
public final static Component UNLINK_INSTRUCTIONS = Component.text("To unlink, use ").color(NamedTextColor.AQUA)
.append(Component.text("`/unlink`", NamedTextColor.RED))
.append(Component.text("."));

@Override
public void onEnable() {
LOGGER = getLogger();

Config config = ConfigReader.readConfig();
Config config = ConfigReader.readConfig(this);

linkManager = new LinkManager(config);
CommandUtils commandUtils = new CommandUtils(linkManager);

Bukkit.getScheduler().scheduleSyncRepeatingTask(this, linkManager::cleanupTempLinks, 0, 0);
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, linkManager::cleanupTempLinks, 0, 1);
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> {
Bukkit.getOnlinePlayers().forEach(player -> {
if (Utils.isLinked(player)) {
player.sendActionBar(UNLINK_INSTRUCTIONS);
} else {
player.sendActionBar(LINK_INSTRUCTIONS);
}
});
}, 10, 15);
getServer().getPluginManager().registerEvents(this, this);

TimerTask task = new TimerTask() {
@Override
public void run() {
linkManager.cleanupTempLinks();
}
};
TIMER.scheduleAtFixedRate(task, 0L, 60_000L);
LifecycleEventManager<@NonNull Plugin> manager = this.getLifecycleManager();
manager.registerEventHandler(LifecycleEvents.COMMANDS, event -> {
final Commands commands = event.registrar();
commands.register(
Commands.literal("link")
.requires(ctx -> ctx.getSender() instanceof Player)
.executes(commandUtils::startLink)
.then(Commands.argument("code", ArgumentTypes.integerRange())
.executes(commandUtils::linkWithCode)
)
.build(),
"Use this command to link your Java and Bedrock account.",
List.of("linkaccount")
);
commands.register(
Commands.literal("unlink")
.requires(ctx -> ctx.getSender() instanceof Player)
.executes(commandUtils::unlink)
.build(),
"Use this command to unlink your Java and Bedrock account.",
List.of("unlinkaccount")
);
commands.register(
Commands.literal("linkinfo")
.requires(ctx -> ctx.getSender() instanceof Player)
.executes(commandUtils::info)
.build(),
"Use this command to show information whether you are currently linked.",
List.of("info")
);
});

LOGGER.info("Started Global Linking Server plugin!");
}

@Override
public boolean onCommand(
@NonNull CommandSender sender, @NonNull Command command, @NonNull String label, @NonNull String[] args) {
if (sender instanceof Player player) {
CommandUtils.handleCommand(linkManager, player, command.getName() + " " + String.join(" ", args));
}
return true;
@EventHandler
public void onPlayerLoad(PlayerJoinEvent event) {
Utils.processJoin(event.getPlayer());
}

@EventHandler
public void onPlayerLeave(PlayerQuitEvent event) {
Utils.processLeave(event.getPlayer());
}
}
Loading

0 comments on commit 3128689

Please sign in to comment.