Skip to content

Commit

Permalink
Add Geyser extension
Browse files Browse the repository at this point in the history
Co-authored-by: rtm516 <[email protected]>
  • Loading branch information
2 people authored and lucko committed Oct 20, 2024
1 parent 5ee638e commit 5f96ffa
Show file tree
Hide file tree
Showing 8 changed files with 430 additions and 3 deletions.
7 changes: 4 additions & 3 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ plugins {

rootProject.name = 'spark'
include (
'spark-velocity4',
'spark-sponge7',
'spark-geyser',
'spark-minestom',
'spark-nukkit',
'spark-sponge7',
'spark-velocity4',
'spark-waterdog',
'spark-minestom',
)
55 changes: 55 additions & 0 deletions spark-geyser/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
plugins {
id 'com.gradleup.shadow' version '8.3.0'
}

tasks.withType(JavaCompile) {
// override, compile targeting J17
options.release = 17
}

dependencies {
implementation "me.lucko:spark-common:${project.baseVersion}-SNAPSHOT"

implementation 'net.kyori:adventure-text-serializer-legacy:4.14.0'
compileOnly 'org.geysermc.geyser:api:2.4.2-SNAPSHOT'
compileOnly 'com.google.guava:guava:29.0-jre'
compileOnly('org.geysermc.geyser:core:2.4.2-SNAPSHOT') {
transitive(false)
}
}

repositories {
maven { url 'https://repo.opencollab.dev/main/' }
}

processResources {
from(sourceSets.main.resources.srcDirs) {
expand (
'pluginVersion': project.pluginVersion,
'pluginDescription': project.pluginDescription
)
include 'extension.yml'
}
}

shadowJar {
archiveFileName = "spark-${project.pluginVersion}-geyser.jar"

relocate 'net.kyori.adventure', 'me.lucko.spark.lib.adventure'
relocate 'net.kyori.examination', 'me.lucko.spark.lib.adventure.examination'
relocate 'net.bytebuddy', 'me.lucko.spark.lib.bytebuddy'
relocate 'com.google.protobuf', 'me.lucko.spark.lib.protobuf'
relocate 'org.objectweb.asm', 'me.lucko.spark.lib.asm'
relocate 'one.profiler', 'me.lucko.spark.lib.asyncprofiler'
relocate 'me.lucko.bytesocks.client', 'me.lucko.spark.lib.bytesocks'
relocate 'org.java_websocket', 'me.lucko.spark.lib.bytesocks.ws'

exclude 'module-info.class'
exclude 'META-INF/maven/**'
exclude 'META-INF/proguard/**'
}

artifacts {
archives shadowJar
shadow shadowJar
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* This file is part of spark.
*
* Copyright (c) lucko (Luck) <[email protected]>
* Copyright (c) contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package me.lucko.spark.geyser;

import me.lucko.spark.common.sampler.source.ClassSourceLookup;

import org.geysermc.geyser.extension.GeyserExtensionClassLoader;

import java.io.IOException;
import java.net.URISyntaxException;

public class GeyserClassSourceLookup extends ClassSourceLookup.ByFirstUrlSource {

@Override
public String identify(ClassLoader loader) throws IOException, URISyntaxException {
if (loader instanceof GeyserExtensionClassLoader) {
return super.identify(loader);
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* This file is part of spark.
*
* Copyright (c) lucko (Luck) <[email protected]>
* Copyright (c) contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package me.lucko.spark.geyser;

import me.lucko.spark.common.command.sender.AbstractCommandSender;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;

import org.geysermc.geyser.api.command.CommandSource;

import java.util.UUID;

public class GeyserCommandSender extends AbstractCommandSender<CommandSource> {

public GeyserCommandSender(CommandSource delegate) {
super(delegate);
}

@Override
public String getName() {
return this.delegate.name();
}

@Override
public UUID getUniqueId() {
return this.delegate.playerUuid();
}

@Override
public void sendMessage(Component message) {
this.delegate.sendMessage(LegacyComponentSerializer.legacySection().serialize(message));
}

@Override
public boolean hasPermission(String permission) {
return this.delegate.hasPermission(permission);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* This file is part of spark.
*
* Copyright (c) lucko (Luck) <[email protected]>
* Copyright (c) contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package me.lucko.spark.geyser;

import me.lucko.spark.common.platform.PlatformInfo;

import org.geysermc.api.util.ApiVersion;
import org.geysermc.geyser.api.GeyserApi;

public class GeyserPlatformInfo implements PlatformInfo {
private final GeyserApi geyserApi;

public GeyserPlatformInfo(GeyserApi geyserApi) {
this.geyserApi = geyserApi;
}

@Override
public Type getType() {
return Type.SERVER;
}

@Override
public String getName() {
return "Geyser";
}

@Override
public String getBrand() {
return "Geyser";
}

@Override
public String getVersion() {
ApiVersion version = this.geyserApi.geyserApiVersion();
return version.human() + "." + version.major() + "." + version.minor();
}

@Override
public String getMinecraftVersion() {
return this.geyserApi.supportedJavaVersion().versionString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* This file is part of spark.
*
* Copyright (c) lucko (Luck) <[email protected]>
* Copyright (c) contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package me.lucko.spark.geyser;

import com.google.common.collect.ImmutableMap;

import me.lucko.spark.common.monitor.ping.PlayerPingProvider;

import org.geysermc.geyser.api.GeyserApi;
import org.geysermc.geyser.api.connection.GeyserConnection;

import java.util.Map;

public class GeyserPlayerPingProvider implements PlayerPingProvider {
private final GeyserApi server;

public GeyserPlayerPingProvider(GeyserApi server) {
this.server = server;
}

@Override
public Map<String, Integer> poll() {
ImmutableMap.Builder<String, Integer> builder = ImmutableMap.builder();
for (GeyserConnection player : this.server.onlineConnections()) {
builder.put(player.name(), player.ping());
}
return builder.build();
}
}
Loading

0 comments on commit 5f96ffa

Please sign in to comment.