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 velocity support #24

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
<groupId>com.rappytv.labyutils</groupId>
<artifactId>LabyUtils</artifactId>
<version>1.0.1</version>
<description>A simple plugin to utilize LabyMod's server API without coding knowledge.</description>
<url>https://github.com/RappyPlugins/LabyUtils#readme</url>
<packaging>jar</packaging>

<name>LabyUtils</name>

<properties>
<java.version>17</java.version>
<labymod.serverApiVersion>1.0.3</labymod.serverApiVersion>
<java.version>11</java.version>
<labymod.serverApiVersion>1.0.4</labymod.serverApiVersion>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand All @@ -25,8 +27,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>11</source>
<target>11</target>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -56,6 +58,10 @@
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
Expand Down Expand Up @@ -87,6 +93,12 @@
<version>1.12-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId>
<version>3.3.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.labymod.serverapi</groupId>
<artifactId>server-bukkit</artifactId>
Expand All @@ -97,10 +109,16 @@
<artifactId>server-bungeecord</artifactId>
<version>${labymod.serverApiVersion}</version>
</dependency>
<dependency>
<groupId>net.labymod.serverapi</groupId>
<artifactId>server-velocity</artifactId>
<version>${labymod.serverApiVersion}</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>24.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import com.rappytv.labyutils.bukkit.listeners.PlayerListener;
import com.rappytv.labyutils.common.ILabyUtilsPlugin;
import io.sentry.Sentry;
import net.labymod.serverapi.api.logger.ProtocolPlatformLogger;
import net.labymod.serverapi.server.bukkit.LabyModProtocolService;
import net.labymod.serverapi.server.common.JavaProtocolLogger;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginManager;
Expand All @@ -24,12 +26,14 @@ public final class LabyUtilsBukkit extends JavaPlugin implements ILabyUtilsPlugi
private Economy economy = null;
private boolean usingPapi = false;
private BukkitConfigManager configManager;
private ProtocolPlatformLogger logger;

@Override
public void onEnable() {
instance = this;
saveDefaultConfig();
configManager = new BukkitConfigManager(this);
logger = new JavaProtocolLogger(getLogger());
if(configManager.isSentryEnabled()) {
getLogger().info("Thanks for enabling Sentry! Loading...");
initializeSentry(getDescription().getVersion());
Expand Down Expand Up @@ -97,4 +101,9 @@ private boolean loadPlaceholderAPI() {
usingPapi = getServer().getPluginManager().getPlugin("PlaceholderAPI") != null;
return usingPapi;
}

@Override
public ProtocolPlatformLogger logger() {
return logger;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@
import com.rappytv.labyutils.bungee.commands.ReloadCommand;
import com.rappytv.labyutils.bungee.listener.PlayerListener;
import com.rappytv.labyutils.common.ILabyUtilsPlugin;
import net.labymod.serverapi.api.logger.ProtocolPlatformLogger;
import net.labymod.serverapi.server.bungeecord.LabyModProtocolService;
import net.labymod.serverapi.server.common.JavaProtocolLogger;
import net.md_5.bungee.api.plugin.Plugin;

public final class LabyUtilsBungee extends Plugin implements ILabyUtilsPlugin {

private static LabyUtilsBungee instance;
private BungeeConfigManager configManager;
private ProtocolPlatformLogger platformLogger;

@Override
public void onEnable() {
instance = this;
configManager = new BungeeConfigManager(new LabyUtilsConfig(this));
platformLogger = new JavaProtocolLogger(getLogger());
try {
LabyModProtocolService.initialize(this);
getLogger().info("LabyMod protocol service initialized.");
Expand All @@ -38,4 +42,9 @@ public static String getPrefix() {
public BungeeConfigManager getConfigManager() {
return configManager;
}

@Override
public ProtocolPlatformLogger logger() {
return platformLogger;
}
}
10 changes: 5 additions & 5 deletions src/main/java/com/rappytv/labyutils/common/ILabyUtilsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import io.sentry.Sentry;
import net.labymod.serverapi.api.logger.ProtocolPlatformLogger;
import net.labymod.serverapi.core.model.display.TabListFlag;
import org.jetbrains.annotations.Nullable;

Expand All @@ -19,21 +20,20 @@
import java.util.Map;
import java.util.UUID;
import java.util.function.Consumer;
import java.util.logging.Logger;

public interface ILabyUtilsPlugin {

Map<UUID, TabListFlag.TabListFlagCountryCode> cachedFlags = new HashMap<>();
Gson gson = new Gson();
HttpClient client = HttpClient.newHttpClient();
Logger getLogger();
ProtocolPlatformLogger logger();

default void initializeSentry(String version) {
Sentry.init(options -> {
options.setDsn("https://[email protected]/4");
options.setTracesSampleRate(1.0);
options.setRelease(version);
getLogger().info("Sentry loaded!");
logger().info("Sentry loaded!");
});
}

Expand Down Expand Up @@ -70,13 +70,13 @@ default void getCountryCode(UUID uuid, InetSocketAddress address, Consumer<TabLi
consumer.accept(cachedFlags.get(uuid));
}).exceptionally(throwable -> {
Sentry.captureException(throwable);
getLogger().warning("Failed to get country code of " + host);
logger().warn("Failed to get country code of " + host);
consumer.accept(null);
return null;
});
} catch (Exception e) {
Sentry.captureException(e);
getLogger().warning("Failed to get country code of " + host);
logger().warn("Failed to get country code of " + host);
consumer.accept(null);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.rappytv.labyutils.velocity;

import com.rappytv.labyutils.common.ILabyUtilsPlugin;
import com.rappytv.labyutils.velocity.commands.LabyInfoCommand;
import com.rappytv.labyutils.velocity.commands.ReloadCommand;
import com.rappytv.labyutils.velocity.listener.PlayerListener;
import com.velocitypowered.api.command.BrigadierCommand;
import com.velocitypowered.api.command.CommandManager;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.plugin.PluginContainer;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.labymod.serverapi.api.logger.ProtocolPlatformLogger;
import net.labymod.serverapi.server.velocity.LabyModProtocolService;
import net.labymod.serverapi.server.velocity.Slf4jPlatformLogger;
import org.slf4j.Logger;

import javax.inject.Inject;
import java.nio.file.Path;
import java.util.Optional;

public final class LabyUtilsVelocity implements ILabyUtilsPlugin {

private static LabyUtilsVelocity instance;
private VelocityConfigManager configManager;
private final ProxyServer server;
private final ProtocolPlatformLogger logger;
private final Logger serverLogger;
private final Path dataDirectory;

@Inject
public LabyUtilsVelocity(ProxyServer server, Logger logger, @DataDirectory Path dataDirectory) {
this.server = server;
this.serverLogger = logger;
this.logger = new Slf4jPlatformLogger(logger);
this.dataDirectory = dataDirectory;
}

@Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) {
instance = this;
configManager = new VelocityConfigManager(/*new VelocityConfig(this)*/);
try {
LabyModProtocolService.initialize(this, server, serverLogger);
logger.info("LabyMod protocol service initialized.");
} catch (IllegalStateException e) {
logger.info("LabyMod protocol service already initialized.");
}
if(configManager.isSentryEnabled()) {
String version = "?";
Optional<PluginContainer> plugin = server.getPluginManager().getPlugin("labyutils");
if(plugin.isPresent() && plugin.get().getDescription().getVersion().isPresent()) {
version = plugin.get().getDescription().getVersion().get();
}
logger.info("Thanks for enabling Sentry! Loading...");
initializeSentry(version);
}
CommandManager manager = server.getCommandManager();
BrigadierCommand infoCommand = LabyInfoCommand.createBrigadierCommand(this);
BrigadierCommand reloadCommand = ReloadCommand.createBrigadierCommand(this);
manager.register(manager.metaBuilder(infoCommand).build(), infoCommand);
manager.register(manager.metaBuilder(reloadCommand).build(), reloadCommand);
server.getEventManager().register(this, new PlayerListener(this));
}

@Override
public ProtocolPlatformLogger logger() {
return logger;
}

public static TextComponent getPrefix() {
return LegacyComponentSerializer.legacyAmpersand().deserialize(instance.getConfigManager().getPrefix());
}

public VelocityConfigManager getConfigManager() {
return configManager;
}

public ProxyServer getServer() {
return server;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.rappytv.labyutils.velocity;

public class VelocityConfig { // TODO: Implement config
}
Loading