Skip to content

Commit

Permalink
feat: proxy tag (#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 authored Nov 13, 2024
1 parent 94ae654 commit 6f3099f
Show file tree
Hide file tree
Showing 52 changed files with 978 additions and 133 deletions.
65 changes: 0 additions & 65 deletions .versionrc.js

This file was deleted.

26 changes: 26 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ buildscript {

plugins {
id 'dev.s7a.gradle.minecraft.server' version '1.1.0'
id 'org.jetbrains.gradle.plugin.idea-ext' version '1.1.7'
}

allprojects {
apply plugin: 'java'
apply plugin: 'idea'

tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
Expand Down Expand Up @@ -158,3 +160,27 @@ tasks.register('copyPlugin') {
}
}
}

// Set SPIGOT_LOC to the location of your server and SPIGOT_JAR as the name of the jar file in the server you want to run
// DIReallyKnowWhatIAmDoingISwear is to remove the stupid pause spigot has at the start
tasks.register('runJar') {
doLast {
javaexec {
main "-jar"
args "${System.env.MC_SERVER_LOC}\\${System.env.MC_SERVER_JAR}.jar"
jvmArgs = ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005", "-DIReallyKnowWhatIAmDoingISwear=true"]
workingDir "${System.env.MC_SERVER_LOC}"
}
}
}


idea {
project {
settings {
taskTriggers {
afterSync(project(':core').tasks.named('generateTemplates'))
}
}
}
}
11 changes: 3 additions & 8 deletions bungee/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,12 @@ repositories {

// includeLibs just says to include the library in the final jar
dependencies {
//includeLibs group: 'com.google.code.gson', name: 'gson', version:'2.8.2'
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.9'
//includeLibs group: 'com.google.inject', name: 'guice', version:'4.0'
implementation group: 'com.google.inject', name: 'guice', version:'4.0'
implementation group: 'com.google.guava', name: 'guava', version: '33.2.0-jre'

// For spigot api
implementation "org.spigotmc:spigot-api:1.16.1-R0.1-SNAPSHOT"

// For bungee api
implementation "net.md-5:bungeecord-api:1.15-SNAPSHOT"

implementation project(":proxycore")
implementation project(":core")
}

jar {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.sekwah.advancedportals.bungee;

import com.sekwah.advancedportals.bungee.connector.container.BungeeProxyContainer;
import com.sekwah.advancedportals.core.ProxyMessages;
import com.sekwah.advancedportals.proxycore.AdvancedPortalsProxyCore;
import net.md_5.bungee.api.plugin.Plugin;

public class AdvancedPortalsBungeePlugin extends Plugin {
private AdvancedPortalsProxyCore proxyCore;

@Override
public void onEnable() {
this.proxyCore = new AdvancedPortalsProxyCore(new BungeeInfoLogger(this), new BungeeProxyContainer(this));
this.proxyCore.onEnable();

getProxy().registerChannel(ProxyMessages.CHANNEL_NAME);

getProxy().getPluginManager().registerListener(this, new EventListener(this, this.proxyCore));
}

@Override
public void onDisable() {
this.proxyCore.onDisable();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.sekwah.advancedportals.bungee;

import com.sekwah.advancedportals.core.util.InfoLogger;

import java.util.logging.Level;

public class BungeeInfoLogger extends InfoLogger {
private final AdvancedPortalsBungeePlugin plugin;

public BungeeInfoLogger(AdvancedPortalsBungeePlugin plugin) {
this.plugin = plugin;
}

@Override
public void warning(String s) {
plugin.getLogger().warning(s);
}

@Override
public void info(String s) {
plugin.getLogger().info(s);
}

@Override
public void error(Exception e) {
plugin.getLogger().log(Level.SEVERE, e.getMessage(), e);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.sekwah.advancedportals.bungee;

import com.sekwah.advancedportals.bungee.connector.container.BungeeProxyPlayerContainer;
import com.sekwah.advancedportals.bungee.connector.container.BungeeProxyServerContainer;
import com.sekwah.advancedportals.core.ProxyMessages;
import com.sekwah.advancedportals.proxycore.AdvancedPortalsProxyCore;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.connection.Server;
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
import net.md_5.bungee.api.event.PluginMessageEvent;
import net.md_5.bungee.api.event.ServerConnectedEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;

public class EventListener implements Listener {


private final AdvancedPortalsBungeePlugin plugin;
private final AdvancedPortalsProxyCore proxyCore;

public EventListener(AdvancedPortalsBungeePlugin plugin, AdvancedPortalsProxyCore proxyCore) {
this.plugin = plugin;
this.proxyCore = proxyCore;
}

@EventHandler
public void onMessageReceived(PluginMessageEvent event) {
if(!event.getTag().equalsIgnoreCase(ProxyMessages.CHANNEL_NAME)) return;
event.setCancelled(true);

if(!(event.getSender() instanceof Server)) return;

if(event.getReceiver() instanceof ProxiedPlayer player) {
this.proxyCore.incomingMessage(new BungeeProxyPlayerContainer(player), event.getData());
}
}

@EventHandler
public void onServerConnected(ServerConnectedEvent event) {
this.proxyCore.onServerConnect(new BungeeProxyServerContainer(event.getServer()), new BungeeProxyPlayerContainer(event.getPlayer()));
}

@EventHandler
public void onDisconnect(PlayerDisconnectEvent event) {
this.proxyCore.onPlayerDisconnect(new BungeeProxyPlayerContainer(event.getPlayer()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.sekwah.advancedportals.bungee.connector.container;

import com.sekwah.advancedportals.bungee.AdvancedPortalsBungeePlugin;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.proxycore.connector.container.ProxyContainer;
import com.sekwah.advancedportals.proxycore.connector.container.ProxyPlayerContainer;
import net.md_5.bungee.api.chat.TextComponent;

public class BungeeProxyContainer implements ProxyContainer {

private final AdvancedPortalsBungeePlugin plugin;

public BungeeProxyContainer(AdvancedPortalsBungeePlugin plugin) {
this.plugin = plugin;
}

@Override
public void invokeCommand(ProxyPlayerContainer proxyPlayer, String command) {
// Should never not be true but just to be safe
if(proxyPlayer instanceof BungeeProxyPlayerContainer playerContainer) {
plugin.getProxy().getPluginManager().dispatchCommand(playerContainer.getPlayer(), command);
}
}

@Override
public void transferPlayer(ProxyPlayerContainer proxyPlayer, String serverName) {
// Should never not be true but just to be safe
if(proxyPlayer instanceof BungeeProxyPlayerContainer playerContainer) {
var serverInfo = plugin.getProxy().getServerInfo(serverName);
var player = playerContainer.getPlayer();
if(serverInfo == null) {
player.sendMessage(new TextComponent(Lang.convertColors("&cCould not find server: &e") + serverName));
return;
}
player.connect(serverInfo);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.sekwah.advancedportals.bungee.connector.container;

import com.sekwah.advancedportals.core.ProxyMessages;
import com.sekwah.advancedportals.proxycore.connector.container.ProxyPlayerContainer;
import net.md_5.bungee.api.connection.ProxiedPlayer;

public class BungeeProxyPlayerContainer implements ProxyPlayerContainer {

private final ProxiedPlayer player;

public BungeeProxyPlayerContainer(ProxiedPlayer player) {
this.player = player;
}

public ProxiedPlayer getPlayer() {
return this.player;
}

@Override
public String getUUID() {
return this.player.getUniqueId().toString();
}

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

public void sendServerPluginMessage(byte[] data) {
this.player.getServer().sendData(ProxyMessages.CHANNEL_NAME, data);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.sekwah.advancedportals.bungee.connector.container;

import com.sekwah.advancedportals.proxycore.connector.container.ProxyServerContainer;
import net.md_5.bungee.api.connection.Server;

public class BungeeProxyServerContainer implements ProxyServerContainer {
private final Server server;

public BungeeProxyServerContainer(Server server) {
this.server = server;
}

@Override
public String getServerName() {
return this.server.getInfo().getName();
}
}
4 changes: 4 additions & 0 deletions bungee/src/main/resources/bungee.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
main: com.sekwah.advancedportals.bungee.AdvancedPortalsBungeePlugin
name: AdvancedPortals
version: ${pluginVersion}
author: sekwah41
35 changes: 21 additions & 14 deletions core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
apply plugin: 'maven-publish'
apply plugin: 'idea'
apply plugin: 'eclipse'

plugins {
id 'maven-publish'
id 'idea'
id 'eclipse'
}

configurations {
// configuration that holds jars to copy into lib
Expand Down Expand Up @@ -32,15 +35,19 @@ jar {
}
}

// Set SPIGOT_LOC to the location of your server and SPIGOT_JAR as the name of the jar file in the server you want to run
// DIReallyKnowWhatIAmDoingISwear is to remove the stupid pause spigot has at the start
tasks.register('runJar') {
doLast {
javaexec {
main "-jar"
args "${System.env.MC_SERVER_LOC}\\${System.env.MC_SERVER_JAR}.jar"
jvmArgs = ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005", "-DIReallyKnowWhatIAmDoingISwear=true"]
workingDir "${System.env.MC_SERVER_LOC}"
}
}
def templateSource = file('src/main/templates')
def templateDest = layout.buildDirectory.dir('generated/sources/templates')

def generateTemplates = tasks.register('generateTemplates', Copy) { task ->
def props = [
'version': project.version
]
task.inputs.properties props

task.from templateSource
task.into templateDest
task.expand props
}

sourceSets.main.java.srcDir(generateTemplates.map { it.outputs })

Loading

0 comments on commit 6f3099f

Please sign in to comment.