mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2024-11-22 02:25:49 +01:00
feat: proxy tag (#451)
This commit is contained in:
parent
5bc1dc3218
commit
dd72123d4b
@ -1,65 +0,0 @@
|
|||||||
let versionRegex = /(\nversion:\s)([0-9.-]+)/;
|
|
||||||
let velocityVersionRegex = /(\sversion\s=\s")([0-9.-]+)("\))/;
|
|
||||||
|
|
||||||
|
|
||||||
const ymlUpdater = {
|
|
||||||
updater: {
|
|
||||||
'readVersion': (contents) => {
|
|
||||||
return versionRegex.exec(contents)[2];
|
|
||||||
},
|
|
||||||
'writeVersion': (contents, version) => {
|
|
||||||
return contents.replace(versionRegex, `$1${version}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const bungee = {
|
|
||||||
filename: 'src/main/resources/bungee.yml',
|
|
||||||
...ymlUpdater,
|
|
||||||
}
|
|
||||||
|
|
||||||
const spigotPlugin = {
|
|
||||||
filename: 'spigot/src/main/resources/plugin.yml',
|
|
||||||
...ymlUpdater,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const gradleTracker = {
|
|
||||||
filename: 'gradle.properties',
|
|
||||||
updater: {
|
|
||||||
'readVersion': (contents) => {
|
|
||||||
return versionRegex.exec(contents)[2];
|
|
||||||
},
|
|
||||||
'writeVersion': (contents, version) => {
|
|
||||||
return contents.replace(versionRegex, `$1${version}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const velocity_plugin = {
|
|
||||||
filename: 'src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsPlugin.java',
|
|
||||||
updater: {
|
|
||||||
'readVersion': (contents) => {
|
|
||||||
return velocityVersionRegex.exec(contents)[2];
|
|
||||||
},
|
|
||||||
'writeVersion': (contents, version) => {
|
|
||||||
return contents.replace(velocityVersionRegex, `$1${version}$3`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const files = [gradleTracker] // spigotPlugin, velocity_plugin, bungee
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
bumpFiles: files,
|
|
||||||
packageFiles: files,
|
|
||||||
// In case you need to force a version change (mostly due to change of scope of the update e.g. major now instead of patch)
|
|
||||||
//releaseAs: '1.0.0',
|
|
||||||
header:"# Changelog\n" +
|
|
||||||
"\n" +
|
|
||||||
"All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.\n" +
|
|
||||||
"\n" +
|
|
||||||
"For the release changelogs see [CHANGELOG.md](CHANGELOG.md) \n" +
|
|
||||||
"For the snapshot changelogs see [SNAPSHOT_CHANGELOG.md](SNAPSHOT_CHANGELOG.md)\n",
|
|
||||||
}
|
|
@ -67,10 +67,12 @@ buildscript {
|
|||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id 'dev.s7a.gradle.minecraft.server' version '1.1.0'
|
id 'dev.s7a.gradle.minecraft.server' version '1.1.0'
|
||||||
|
id 'org.jetbrains.gradle.plugin.idea-ext' version '1.1.7'
|
||||||
}
|
}
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
|
apply plugin: 'idea'
|
||||||
|
|
||||||
tasks.withType(JavaCompile).configureEach {
|
tasks.withType(JavaCompile).configureEach {
|
||||||
options.encoding = 'UTF-8'
|
options.encoding = 'UTF-8'
|
||||||
|
@ -17,17 +17,12 @@ repositories {
|
|||||||
|
|
||||||
// includeLibs just says to include the library in the final jar
|
// includeLibs just says to include the library in the final jar
|
||||||
dependencies {
|
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
|
// For bungee api
|
||||||
implementation "net.md-5:bungeecord-api:1.15-SNAPSHOT"
|
implementation "net.md-5:bungeecord-api:1.15-SNAPSHOT"
|
||||||
|
|
||||||
|
implementation project(":proxycore")
|
||||||
|
implementation project(":core")
|
||||||
}
|
}
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -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()));
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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
bungee/src/main/resources/bungee.yml
Normal file
4
bungee/src/main/resources/bungee.yml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
main: com.sekwah.advancedportals.bungee.AdvancedPortalsBungeePlugin
|
||||||
|
name: AdvancedPortals
|
||||||
|
version: ${pluginVersion}
|
||||||
|
author: sekwah41
|
@ -1,6 +1,9 @@
|
|||||||
apply plugin: 'maven-publish'
|
|
||||||
apply plugin: 'idea'
|
plugins {
|
||||||
apply plugin: 'eclipse'
|
id 'maven-publish'
|
||||||
|
id 'idea'
|
||||||
|
id 'eclipse'
|
||||||
|
}
|
||||||
|
|
||||||
configurations {
|
configurations {
|
||||||
// configuration that holds jars to copy into lib
|
// configuration that holds jars to copy into lib
|
||||||
@ -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
|
def templateSource = file('src/main/templates')
|
||||||
// DIReallyKnowWhatIAmDoingISwear is to remove the stupid pause spigot has at the start
|
def templateDest = layout.buildDirectory.dir('generated/sources/templates')
|
||||||
tasks.register('runJar') {
|
|
||||||
doLast {
|
def generateTemplates = tasks.register('generateTemplates', Copy) { task ->
|
||||||
javaexec {
|
def props = [
|
||||||
main "-jar"
|
'version': project.version
|
||||||
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"]
|
task.inputs.properties props
|
||||||
workingDir "${System.env.MC_SERVER_LOC}"
|
|
||||||
}
|
task.from templateSource
|
||||||
}
|
task.into templateDest
|
||||||
|
task.expand props
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sourceSets.main.java.srcDir(generateTemplates.map { it.outputs })
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ package com.sekwah.advancedportals.core;
|
|||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.spi.Message;
|
|
||||||
import com.sekwah.advancedportals.core.commands.CommandWithSubCommands;
|
import com.sekwah.advancedportals.core.commands.CommandWithSubCommands;
|
||||||
import com.sekwah.advancedportals.core.commands.SubCommand;
|
import com.sekwah.advancedportals.core.commands.SubCommand;
|
||||||
import com.sekwah.advancedportals.core.commands.subcommands.desti.*;
|
import com.sekwah.advancedportals.core.commands.subcommands.desti.*;
|
||||||
@ -12,7 +11,6 @@ import com.sekwah.advancedportals.core.connector.containers.ServerContainer;
|
|||||||
import com.sekwah.advancedportals.core.module.AdvancedPortalsModule;
|
import com.sekwah.advancedportals.core.module.AdvancedPortalsModule;
|
||||||
import com.sekwah.advancedportals.core.registry.TagRegistry;
|
import com.sekwah.advancedportals.core.registry.TagRegistry;
|
||||||
import com.sekwah.advancedportals.core.repository.ConfigRepository;
|
import com.sekwah.advancedportals.core.repository.ConfigRepository;
|
||||||
import com.sekwah.advancedportals.core.repository.IPlayerDataRepository;
|
|
||||||
import com.sekwah.advancedportals.core.serializeddata.DataStorage;
|
import com.sekwah.advancedportals.core.serializeddata.DataStorage;
|
||||||
import com.sekwah.advancedportals.core.services.DestinationServices;
|
import com.sekwah.advancedportals.core.services.DestinationServices;
|
||||||
import com.sekwah.advancedportals.core.services.PlayerDataServices;
|
import com.sekwah.advancedportals.core.services.PlayerDataServices;
|
||||||
@ -66,10 +64,6 @@ public class AdvancedPortalsCore {
|
|||||||
@Inject
|
@Inject
|
||||||
private GameScheduler gameScheduler;
|
private GameScheduler gameScheduler;
|
||||||
|
|
||||||
// TEMP REMOVE THIS THIS IS JUST FOR DEV
|
|
||||||
@Inject
|
|
||||||
private IPlayerDataRepository tempDataRepository;
|
|
||||||
|
|
||||||
public AdvancedPortalsCore(String mcVersion, File dataStorageLoc,
|
public AdvancedPortalsCore(String mcVersion, File dataStorageLoc,
|
||||||
InfoLogger infoLogger,
|
InfoLogger infoLogger,
|
||||||
ServerContainer serverContainer) {
|
ServerContainer serverContainer) {
|
||||||
@ -126,6 +120,10 @@ public class AdvancedPortalsCore {
|
|||||||
|
|
||||||
private void registerChannels() {
|
private void registerChannels() {
|
||||||
this.serverContainer.registerOutgoingChannel(BungeeTag.PACKET_CHANNEL);
|
this.serverContainer.registerOutgoingChannel(BungeeTag.PACKET_CHANNEL);
|
||||||
|
if(this.configRepository.getEnableProxySupport()) {
|
||||||
|
this.serverContainer.registerOutgoingChannel(ProxyMessages.CHANNEL_NAME);
|
||||||
|
this.serverContainer.registerIncomingChannel(ProxyMessages.CHANNEL_NAME);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerTags() {
|
private void registerTags() {
|
||||||
@ -138,6 +136,7 @@ public class AdvancedPortalsCore {
|
|||||||
this.tagRegistry.registerTag(new PortalEventTag());
|
this.tagRegistry.registerTag(new PortalEventTag());
|
||||||
this.tagRegistry.registerTag(new MessageTag());
|
this.tagRegistry.registerTag(new MessageTag());
|
||||||
this.tagRegistry.registerTag(new BungeeTag());
|
this.tagRegistry.registerTag(new BungeeTag());
|
||||||
|
this.tagRegistry.registerTag(new ProxyTag());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,15 +1,18 @@
|
|||||||
package com.sekwah.advancedportals.core;
|
package com.sekwah.advancedportals.core;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.sekwah.advancedportals.core.connector.containers.EntityContainer;
|
import com.sekwah.advancedportals.core.connector.containers.EntityContainer;
|
||||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||||
import com.sekwah.advancedportals.core.connector.containers.WorldContainer;
|
import com.sekwah.advancedportals.core.connector.containers.WorldContainer;
|
||||||
import com.sekwah.advancedportals.core.data.BlockAxis;
|
import com.sekwah.advancedportals.core.data.BlockAxis;
|
||||||
import com.sekwah.advancedportals.core.data.Direction;
|
import com.sekwah.advancedportals.core.data.Direction;
|
||||||
|
import com.sekwah.advancedportals.core.network.ServerDestiPacket;
|
||||||
import com.sekwah.advancedportals.core.permissions.PortalPermissions;
|
import com.sekwah.advancedportals.core.permissions.PortalPermissions;
|
||||||
import com.sekwah.advancedportals.core.repository.ConfigRepository;
|
import com.sekwah.advancedportals.core.repository.ConfigRepository;
|
||||||
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
|
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
|
||||||
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
|
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
|
||||||
|
import com.sekwah.advancedportals.core.services.DestinationServices;
|
||||||
import com.sekwah.advancedportals.core.services.PlayerDataServices;
|
import com.sekwah.advancedportals.core.services.PlayerDataServices;
|
||||||
import com.sekwah.advancedportals.core.services.PortalServices;
|
import com.sekwah.advancedportals.core.services.PortalServices;
|
||||||
import com.sekwah.advancedportals.core.util.GameScheduler;
|
import com.sekwah.advancedportals.core.util.GameScheduler;
|
||||||
@ -25,6 +28,9 @@ public class CoreListeners {
|
|||||||
@Inject
|
@Inject
|
||||||
private PortalServices portalServices;
|
private PortalServices portalServices;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private DestinationServices destinationServices;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ConfigRepository configRepository;
|
private ConfigRepository configRepository;
|
||||||
|
|
||||||
@ -56,7 +62,16 @@ public class CoreListeners {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void incomingMessage(PlayerContainer player, String channel, byte[] message) {
|
public void incomingMessage(PlayerContainer player, String channel, byte[] message) {
|
||||||
// TODO implement proxy handling
|
var buffer = ByteStreams.newDataInput(message);
|
||||||
|
var messageType = buffer.readUTF();
|
||||||
|
|
||||||
|
switch (messageType) {
|
||||||
|
case ProxyMessages.SERVER_DESTI -> {
|
||||||
|
var serverDestiPacket = ServerDestiPacket.decode(buffer);
|
||||||
|
this.destinationServices.teleportToDestination(serverDestiPacket.getDestination(), player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void tick() {
|
public void tick() {
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.sekwah.advancedportals.core;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* messages going to the proxy will start with proxy: messages going to the server will start with server:
|
||||||
|
*/
|
||||||
|
public class ProxyMessages {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Could split by channel messages we will handle it ourselves
|
||||||
|
*/
|
||||||
|
public static final String CHANNEL_NAME = "advancedportals:message";
|
||||||
|
|
||||||
|
public static final String PROXY_TRANSFER_DESTI = "proxy:transfer_desti";
|
||||||
|
public static final String PROXY_TRANSFER = "proxy:transfer";
|
||||||
|
public static final String PROXY_COMMAND = "proxy:command";
|
||||||
|
|
||||||
|
public static final String SERVER_DESTI = "server:destination";
|
||||||
|
}
|
@ -25,7 +25,7 @@ import java.util.Objects;
|
|||||||
*/
|
*/
|
||||||
public class ShowPortalSubCommand
|
public class ShowPortalSubCommand
|
||||||
implements SubCommand, SubCommand.SubCommandOnInit {
|
implements SubCommand, SubCommand.SubCommandOnInit {
|
||||||
static final int SHOW_TICKS = 1010;
|
static final int SHOW_TICKS = 1050;
|
||||||
|
|
||||||
boolean alternate_show_trigger = true;
|
boolean alternate_show_trigger = true;
|
||||||
|
|
||||||
@ -116,8 +116,14 @@ public class ShowPortalSubCommand
|
|||||||
player.getWorldName())
|
player.getWorldName())
|
||||||
&& tempData.getPos2().getWorldName().equals(
|
&& tempData.getPos2().getWorldName().equals(
|
||||||
player.getWorldName())) {
|
player.getWorldName())) {
|
||||||
debugVisuals(player, tempData.getPos1(), tempData.getPos2(),
|
int widthX = Math.abs(tempData.getPos1().getPosX()
|
||||||
SELECTION_COLOR, SHOW_TICKS);
|
- tempData.getPos2().getPosX());
|
||||||
|
int widthY = Math.abs(tempData.getPos1().getPosY() - tempData.getPos2().getPosY());
|
||||||
|
int widthZ = Math.abs(tempData.getPos1().getPosZ() - tempData.getPos2().getPosZ());
|
||||||
|
int totalBlocks = widthX * widthY * widthZ;
|
||||||
|
if (totalBlocks <= config.getMaxTriggerVisualisationSize())
|
||||||
|
debugVisuals(player, tempData.getPos1(), tempData.getPos2(),
|
||||||
|
SELECTION_COLOR, SHOW_TICKS);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tempData.getPos1() != null
|
if (tempData.getPos1() != null
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
package com.sekwah.advancedportals.core.network;
|
||||||
|
|
||||||
|
public interface Packet {
|
||||||
|
byte[] encode();
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package com.sekwah.advancedportals.core.network;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import com.sekwah.advancedportals.core.ProxyMessages;
|
||||||
|
|
||||||
|
public class ProxyCommandPacket implements Packet {
|
||||||
|
|
||||||
|
private final String command;
|
||||||
|
|
||||||
|
public ProxyCommandPacket(String command) {
|
||||||
|
this.command = command;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] encode() {
|
||||||
|
ByteArrayDataOutput buffer = ByteStreams.newDataOutput();
|
||||||
|
buffer.writeUTF(ProxyMessages.PROXY_COMMAND);
|
||||||
|
buffer.writeUTF(this.command);
|
||||||
|
return buffer.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ProxyCommandPacket decode(ByteArrayDataInput buffer) {
|
||||||
|
return new ProxyCommandPacket(buffer.readUTF());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCommand() {
|
||||||
|
return command;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
package com.sekwah.advancedportals.core.network;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import com.sekwah.advancedportals.core.ProxyMessages;
|
||||||
|
|
||||||
|
public class ProxyTransferDestiPacket implements Packet {
|
||||||
|
|
||||||
|
private final String serverName;
|
||||||
|
private final String destination;
|
||||||
|
|
||||||
|
public ProxyTransferDestiPacket(String serverName, String destination) {
|
||||||
|
this.serverName = serverName;
|
||||||
|
this.destination = destination;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] encode() {
|
||||||
|
ByteArrayDataOutput buffer = ByteStreams.newDataOutput();
|
||||||
|
buffer.writeUTF(ProxyMessages.PROXY_TRANSFER_DESTI);
|
||||||
|
buffer.writeUTF(this.serverName);
|
||||||
|
buffer.writeUTF(this.destination);
|
||||||
|
return buffer.toByteArray();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ProxyTransferDestiPacket decode(ByteArrayDataInput buffer) {
|
||||||
|
return new ProxyTransferDestiPacket(buffer.readUTF(), buffer.readUTF());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getServerName() {
|
||||||
|
return serverName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDestination() {
|
||||||
|
return destination;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package com.sekwah.advancedportals.core.network;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import com.sekwah.advancedportals.core.ProxyMessages;
|
||||||
|
|
||||||
|
public class ProxyTransferPacket implements Packet {
|
||||||
|
|
||||||
|
private final String serverName;
|
||||||
|
|
||||||
|
public ProxyTransferPacket(String serverName) {
|
||||||
|
this.serverName = serverName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] encode() {
|
||||||
|
ByteArrayDataOutput buffer = ByteStreams.newDataOutput();
|
||||||
|
buffer.writeUTF(ProxyMessages.PROXY_TRANSFER);
|
||||||
|
buffer.writeUTF(this.serverName);
|
||||||
|
return buffer.toByteArray();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ProxyTransferPacket decode(ByteArrayDataInput buffer) {
|
||||||
|
return new ProxyTransferPacket(buffer.readUTF());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getServerName() {
|
||||||
|
return serverName;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package com.sekwah.advancedportals.core.network;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import com.sekwah.advancedportals.core.ProxyMessages;
|
||||||
|
|
||||||
|
public class ServerDestiPacket implements Packet {
|
||||||
|
|
||||||
|
private final String destination;
|
||||||
|
|
||||||
|
public ServerDestiPacket(String destination) {
|
||||||
|
this.destination = destination;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] encode() {
|
||||||
|
ByteArrayDataOutput buffer = ByteStreams.newDataOutput();
|
||||||
|
buffer.writeUTF(ProxyMessages.SERVER_DESTI);
|
||||||
|
buffer.writeUTF(this.destination);
|
||||||
|
return buffer.toByteArray();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ServerDestiPacket decode(ByteArrayDataInput buffer) {
|
||||||
|
return new ServerDestiPacket(buffer.readUTF());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDestination() {
|
||||||
|
return destination;
|
||||||
|
}
|
||||||
|
}
|
@ -45,4 +45,6 @@ public interface ConfigRepository {
|
|||||||
boolean warpMessageInChat();
|
boolean warpMessageInChat();
|
||||||
|
|
||||||
String getWarpParticles();
|
String getWarpParticles();
|
||||||
|
|
||||||
|
boolean getEnableProxySupport();
|
||||||
}
|
}
|
||||||
|
@ -95,6 +95,11 @@ public class ConfigRepositoryImpl implements ConfigRepository {
|
|||||||
return this.config.warpParticles;
|
return this.config.warpParticles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getEnableProxySupport() {
|
||||||
|
return this.config.enableProxySupport;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadConfig(DataStorage dataStorage) {
|
public void loadConfig(DataStorage dataStorage) {
|
||||||
this.dataStorage = dataStorage;
|
this.dataStorage = dataStorage;
|
||||||
|
@ -65,6 +65,14 @@ public class PortalRepositoryImpl implements IPortalRepository {
|
|||||||
for (String fileName : allFiles) {
|
for (String fileName : allFiles) {
|
||||||
AdvancedPortal portal = dataStorage.loadFile(
|
AdvancedPortal portal = dataStorage.loadFile(
|
||||||
AdvancedPortal.class, fileLocation + fileName);
|
AdvancedPortal.class, fileLocation + fileName);
|
||||||
|
|
||||||
|
if (portal != null) {
|
||||||
|
AdvancedPortalsCore.getInstance()
|
||||||
|
.getModule()
|
||||||
|
.getInjector()
|
||||||
|
.injectMembers(portal);
|
||||||
|
}
|
||||||
|
|
||||||
// Forces the name tag to be up-to-date on load
|
// Forces the name tag to be up-to-date on load
|
||||||
String[] name = portal.getArgValues(NameTag.TAG_NAME);
|
String[] name = portal.getArgValues(NameTag.TAG_NAME);
|
||||||
if (name != null && name.length > 0) {
|
if (name != null && name.length > 0) {
|
||||||
|
@ -4,5 +4,6 @@ public class CommandPortalConfig {
|
|||||||
public boolean op = true;
|
public boolean op = true;
|
||||||
public boolean console = true;
|
public boolean console = true;
|
||||||
public boolean permsWildcard = true;
|
public boolean permsWildcard = true;
|
||||||
|
public boolean proxy = true;
|
||||||
public boolean enabled = true;
|
public boolean enabled = true;
|
||||||
}
|
}
|
||||||
|
@ -39,4 +39,6 @@ public class Config {
|
|||||||
public boolean warpMessageInChat = false;
|
public boolean warpMessageInChat = false;
|
||||||
|
|
||||||
public CommandPortalConfig commandPortals = new CommandPortalConfig();
|
public CommandPortalConfig commandPortals = new CommandPortalConfig();
|
||||||
|
|
||||||
|
public boolean enableProxySupport = false;
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,8 @@ package com.sekwah.advancedportals.core.tags;
|
|||||||
|
|
||||||
import com.google.common.io.ByteArrayDataOutput;
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import com.google.inject.Inject;
|
|
||||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||||
import com.sekwah.advancedportals.core.registry.TagTarget;
|
import com.sekwah.advancedportals.core.registry.TagTarget;
|
||||||
import com.sekwah.advancedportals.core.repository.ConfigRepository;
|
|
||||||
import com.sekwah.advancedportals.core.util.FriendlyDataOutput;
|
|
||||||
import com.sekwah.advancedportals.core.util.Lang;
|
import com.sekwah.advancedportals.core.util.Lang;
|
||||||
import com.sekwah.advancedportals.core.warphandler.ActivationData;
|
import com.sekwah.advancedportals.core.warphandler.ActivationData;
|
||||||
import com.sekwah.advancedportals.core.warphandler.Tag;
|
import com.sekwah.advancedportals.core.warphandler.Tag;
|
||||||
@ -16,8 +13,6 @@ import java.util.Random;
|
|||||||
public class BungeeTag implements Tag.Activation {
|
public class BungeeTag implements Tag.Activation {
|
||||||
|
|
||||||
public static final String PACKET_CHANNEL = "BungeeCord";
|
public static final String PACKET_CHANNEL = "BungeeCord";
|
||||||
@Inject
|
|
||||||
ConfigRepository configRepository;
|
|
||||||
|
|
||||||
public static String TAG_NAME = "bungee";
|
public static String TAG_NAME = "bungee";
|
||||||
|
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package com.sekwah.advancedportals.core.tags;
|
package com.sekwah.advancedportals.core.tags;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
import com.sekwah.advancedportals.core.ProxyMessages;
|
||||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||||
|
import com.sekwah.advancedportals.core.network.ProxyCommandPacket;
|
||||||
|
import com.sekwah.advancedportals.core.network.ProxyTransferPacket;
|
||||||
import com.sekwah.advancedportals.core.registry.TagTarget;
|
import com.sekwah.advancedportals.core.registry.TagTarget;
|
||||||
import com.sekwah.advancedportals.core.repository.ConfigRepository;
|
import com.sekwah.advancedportals.core.repository.ConfigRepository;
|
||||||
import com.sekwah.advancedportals.core.util.Lang;
|
import com.sekwah.advancedportals.core.util.Lang;
|
||||||
@ -84,6 +87,14 @@ public class CommandTag implements Tag.Activation, Tag.Split, Tag.Creation {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case '%':
|
||||||
|
if (!commandPortals.proxy || !configRepository.getEnableProxySupport()) {
|
||||||
|
player.sendMessage(
|
||||||
|
Lang.getNegativePrefix()
|
||||||
|
+ Lang.translate("tag.command.proxy.disabled"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -116,6 +127,10 @@ public class CommandTag implements Tag.Activation, Tag.Split, Tag.Creation {
|
|||||||
player.getUUID(), formattedCommand.substring(1),
|
player.getUUID(), formattedCommand.substring(1),
|
||||||
CommandLevel.PERMISSION_WILDCARD);
|
CommandLevel.PERMISSION_WILDCARD);
|
||||||
break;
|
break;
|
||||||
|
case '%':
|
||||||
|
var packet = new ProxyCommandPacket(formattedCommand.substring(1));
|
||||||
|
player.sendPacket(ProxyMessages.CHANNEL_NAME, packet.encode());
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
player.getServer().dispatchCommand(player.getUUID(),
|
player.getServer().dispatchCommand(player.getUUID(),
|
||||||
formattedCommand,
|
formattedCommand,
|
||||||
|
@ -67,6 +67,10 @@ public class DestiTag implements Tag.Activation, Tag.AutoComplete, Tag.Split {
|
|||||||
|
|
||||||
activeData.setMetadata(TAG_NAME, selectedArg);
|
activeData.setMetadata(TAG_NAME, selectedArg);
|
||||||
|
|
||||||
|
if(activeData.getMetadata(ProxyTag.TAG_NAME) != null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if(destinationServices.getDestination(selectedArg) == null) {
|
if(destinationServices.getDestination(selectedArg) == null) {
|
||||||
player.sendMessage(Lang.getNegativePrefix() + Lang.translateInsertVariables("desti.error.notfound", selectedArg));
|
player.sendMessage(Lang.getNegativePrefix() + Lang.translateInsertVariables("desti.error.notfound", selectedArg));
|
||||||
return false;
|
return false;
|
||||||
@ -92,6 +96,10 @@ public class DestiTag implements Tag.Activation, Tag.AutoComplete, Tag.Split {
|
|||||||
@Override
|
@Override
|
||||||
public void postActivated(TagTarget target, PlayerContainer player,
|
public void postActivated(TagTarget target, PlayerContainer player,
|
||||||
ActivationData activationData, String[] argData) {
|
ActivationData activationData, String[] argData) {
|
||||||
|
if(activationData.getMetadata(ProxyTag.TAG_NAME) != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var selectedArg = activationData.getMetadata(TAG_NAME);
|
var selectedArg = activationData.getMetadata(TAG_NAME);
|
||||||
Destination destination = destinationServices.getDestination(selectedArg);
|
Destination destination = destinationServices.getDestination(selectedArg);
|
||||||
if (destination != null) {
|
if (destination != null) {
|
||||||
@ -112,6 +120,10 @@ public class DestiTag implements Tag.Activation, Tag.AutoComplete, Tag.Split {
|
|||||||
@Override
|
@Override
|
||||||
public boolean activated(TagTarget target, PlayerContainer player,
|
public boolean activated(TagTarget target, PlayerContainer player,
|
||||||
ActivationData activationData, String[] argData) {
|
ActivationData activationData, String[] argData) {
|
||||||
|
if(activationData.getMetadata(ProxyTag.TAG_NAME) != null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
var selectedArg = activationData.getMetadata(TAG_NAME);
|
var selectedArg = activationData.getMetadata(TAG_NAME);
|
||||||
Destination destination =
|
Destination destination =
|
||||||
destinationServices.getDestination(selectedArg);
|
destinationServices.getDestination(selectedArg);
|
||||||
@ -149,10 +161,4 @@ public class DestiTag implements Tag.Activation, Tag.AutoComplete, Tag.Split {
|
|||||||
public List<String> autoComplete(String argData) {
|
public List<String> autoComplete(String argData) {
|
||||||
return destinationServices.getDestinationNames();
|
return destinationServices.getDestinationNames();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public String splitString() {
|
|
||||||
return ",";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -48,12 +48,6 @@ public class NameTag implements Tag.AutoComplete, Tag.Creation {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public String splitString() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean created(TagTarget target, PlayerContainer player,
|
public boolean created(TagTarget target, PlayerContainer player,
|
||||||
String[] argData) {
|
String[] argData) {
|
||||||
|
@ -80,12 +80,6 @@ public class PortalEventTag implements Tag.Activation, Tag.AutoComplete, Tag.Den
|
|||||||
return List.of("true", "false");
|
return List.of("true", "false");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public String splitString() {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Behaviour getDenyBehavior() {
|
public Behaviour getDenyBehavior() {
|
||||||
return Behaviour.SILENT;
|
return Behaviour.SILENT;
|
||||||
|
@ -0,0 +1,85 @@
|
|||||||
|
package com.sekwah.advancedportals.core.tags;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.sekwah.advancedportals.core.ProxyMessages;
|
||||||
|
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||||
|
import com.sekwah.advancedportals.core.network.ProxyTransferDestiPacket;
|
||||||
|
import com.sekwah.advancedportals.core.network.ProxyTransferPacket;
|
||||||
|
import com.sekwah.advancedportals.core.registry.TagTarget;
|
||||||
|
import com.sekwah.advancedportals.core.repository.ConfigRepository;
|
||||||
|
import com.sekwah.advancedportals.core.util.Lang;
|
||||||
|
import com.sekwah.advancedportals.core.warphandler.ActivationData;
|
||||||
|
import com.sekwah.advancedportals.core.warphandler.Tag;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class ProxyTag implements Tag.Activation, Tag.OrderPriority, Tag.Split {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ConfigRepository configRepository;
|
||||||
|
|
||||||
|
public static String TAG_NAME = "proxy";
|
||||||
|
|
||||||
|
private final TagType[] tagTypes =
|
||||||
|
new TagType[] {TagType.PORTAL};
|
||||||
|
|
||||||
|
private final Random random = new Random();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TagType[] getTagTypes() {
|
||||||
|
return tagTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return TAG_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getAliases() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String description() {
|
||||||
|
return Lang.translate("tag.proxy.description");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean preActivated(TagTarget target, PlayerContainer player, ActivationData activeData, String[] argData) {
|
||||||
|
String selectedArg = argData[random.nextInt(argData.length)];
|
||||||
|
activeData.setMetadata(TAG_NAME, selectedArg);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postActivated(TagTarget target, PlayerContainer player, ActivationData activationData, String[] argData) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean activated(TagTarget target, PlayerContainer player, ActivationData activeData, String[] argData) {
|
||||||
|
|
||||||
|
if(!this.configRepository.getEnableProxySupport()) {
|
||||||
|
player.sendMessage(Lang.getNegativePrefix() + Lang.translate("tag.proxy.notenabled"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String selectedArg = argData[random.nextInt(argData.length)];
|
||||||
|
|
||||||
|
var desti = activeData.getMetadata(DestiTag.TAG_NAME);
|
||||||
|
|
||||||
|
var packet = desti == null ? new ProxyTransferPacket(selectedArg) : new ProxyTransferDestiPacket(selectedArg, desti);
|
||||||
|
player.sendPacket(ProxyMessages.CHANNEL_NAME, packet.encode());
|
||||||
|
activeData.setWarpStatus(ActivationData.WarpedStatus.WARPED);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Priority getPriority() {
|
||||||
|
return Priority.HIGHEST;
|
||||||
|
}
|
||||||
|
}
|
@ -29,7 +29,7 @@ public interface Tag {
|
|||||||
*/
|
*/
|
||||||
enum TagType { PORTAL, DESTINATION }
|
enum TagType { PORTAL, DESTINATION }
|
||||||
|
|
||||||
enum Priority { LOWEST, LOW, NORMAL, HIGH, HIGHEST }
|
enum Priority { HIGHEST, HIGH, NORMAL, LOW, LOWEST }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to flag where the auto complete should show more or less info.
|
* Used to flag where the auto complete should show more or less info.
|
||||||
@ -65,9 +65,6 @@ public interface Tag {
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
List<String> autoComplete(String argData);
|
List<String> autoComplete(String argData);
|
||||||
|
|
||||||
@Nullable
|
|
||||||
String splitString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Split extends Tag {
|
interface Split extends Tag {
|
||||||
@ -78,7 +75,9 @@ public interface Tag {
|
|||||||
* @return null if the tag does not support splitting
|
* @return null if the tag does not support splitting
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
String splitString();
|
default String splitString() {
|
||||||
|
return ",";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
package com.sekwah.advancedportals.core;
|
||||||
|
|
||||||
|
public class BuildConstants {
|
||||||
|
public static final String VERSION = "${version}";
|
||||||
|
}
|
@ -56,7 +56,7 @@ command.help.invalidhelp= &e%1$s&c ist keine gültige Seitennummer oder Sub-Comm
|
|||||||
|
|
||||||
command.reload.help=Ladet die Portal-Dateien neu
|
command.reload.help=Ladet die Portal-Dateien neu
|
||||||
command.reload.detailedhelp=Lade alle Portal-Dateien von den Dateien im Dateiordner neu.
|
command.reload.detailedhelp=Lade alle Portal-Dateien von den Dateien im Dateiordner neu.
|
||||||
command.reload.reloaded= Alle Advanced Portals Dateien wurden neugeladet
|
command.reload.reloaded= Alle Advanced Portals-Daten wurden neu geladen. Einige Konfigurationswerte erfordern möglicherweise einen vollständigen Serverneustart oder ein Plugin-Reload, um wirksam zu werden.
|
||||||
|
|
||||||
command.create.help=Erstellt Portale
|
command.create.help=Erstellt Portale
|
||||||
command.create.error= Beim Portal erstellen ist ein Fehler aufgetreten:
|
command.create.error= Beim Portal erstellen ist ein Fehler aufgetreten:
|
||||||
|
@ -54,7 +54,7 @@ command.help.invalidhelp= Sorry but &e%1$s&c is not a valid page number or sub c
|
|||||||
|
|
||||||
command.reload.help=Reloads portal data
|
command.reload.help=Reloads portal data
|
||||||
command.reload.detailedhelp=Reloads all portal data from files in the data folder
|
command.reload.detailedhelp=Reloads all portal data from files in the data folder
|
||||||
command.reload.reloaded= All Advanced Portals data reloaded
|
command.reload.reloaded= All Advanced Portals data reloaded. Some config values may need a full server restart or a plugin reload to take effect.
|
||||||
|
|
||||||
command.create.help=Creates portals
|
command.create.help=Creates portals
|
||||||
command.create.error= There was a problem making the portal.
|
command.create.error= There was a problem making the portal.
|
||||||
@ -192,3 +192,7 @@ tag.command.disabled= Command portals are &edisabled &con this server. Please co
|
|||||||
tag.command.op.disabled= Op command portals are &edisabled &con this server. Please contact a server admin if this is an issue.
|
tag.command.op.disabled= Op command portals are &edisabled &con this server. Please contact a server admin if this is an issue.
|
||||||
tag.command.console.disabled= Console command portals are &edisabled &con this server. Please contact a server admin if this is an issue.
|
tag.command.console.disabled= Console command portals are &edisabled &con this server. Please contact a server admin if this is an issue.
|
||||||
tag.command.permswildcard.disabled= Wildcard &e*&c permission command portals are &edisabled &con this server. Please contact a server admin if this is an issue.
|
tag.command.permswildcard.disabled= Wildcard &e*&c permission command portals are &edisabled &con this server. Please contact a server admin if this is an issue.
|
||||||
|
tag.command.proxy.disabled= Proxy command portals are &edisabled &con this server. Please contact a server admin if this is an issue.
|
||||||
|
|
||||||
|
tag.proxy.notenabled= Proxy portals are currently &edisabled &con this server. Please contact a server admin to enable them.
|
||||||
|
tag.proxy.description= Sets the server destination of the portal.
|
@ -37,7 +37,7 @@ translatedata.translationsoutdated=Certaines des traductions du fichier de tradu
|
|||||||
translatedata.replacecommand= Utilisez &e/portal transupdate&c pour copier un nouveau fichier par défaut de traduction &een_GB&c.
|
translatedata.replacecommand= Utilisez &e/portal transupdate&c pour copier un nouveau fichier par défaut de traduction &een_GB&c.
|
||||||
translatedata.replaced= Un nouveau fichier &een_GB&a a bien été enregistré.
|
translatedata.replaced= Un nouveau fichier &een_GB&a a bien été enregistré.
|
||||||
|
|
||||||
messageprefix.positive=&c[&7AdvancedPortals&c]
|
messageprefix.positive=&a[&7AdvancedPortals&a]
|
||||||
messageprefix.negative=&c[&7AdvancedPortals&c]
|
messageprefix.negative=&c[&7AdvancedPortals&c]
|
||||||
|
|
||||||
logger.pluginenable=Advanced portals have been enabled!
|
logger.pluginenable=Advanced portals have been enabled!
|
||||||
@ -53,7 +53,7 @@ command.help.invalidhelp= Désolé mais &e%1$s&c n'est pas une page ou sous comm
|
|||||||
|
|
||||||
command.reload.help=Recharge les fichiers
|
command.reload.help=Recharge les fichiers
|
||||||
command.reload.detailedhelp=Recharge toutes les données du portail à partir des fichiers du dossier de données.
|
command.reload.detailedhelp=Recharge toutes les données du portail à partir des fichiers du dossier de données.
|
||||||
command.reload.reloaded= Tous les fichiers ont bien été rechargés.
|
command.reload.reloaded= Toutes les données d'Advanced Portals ont été rechargées. Certaines valeurs de configuration peuvent nécessiter un redémarrage complet du serveur ou un rechargement du plugin pour prendre effet.
|
||||||
|
|
||||||
command.create.help=Crée un portail
|
command.create.help=Crée un portail
|
||||||
command.create.error= Une erreur est survenue en créant le portail:
|
command.create.error= Une erreur est survenue en créant le portail:
|
||||||
|
@ -53,7 +53,7 @@ command.help.invalidhelp= Sajnálom, de &e%1$s&c nem érvényes oldalszám vagy
|
|||||||
|
|
||||||
command.reload.help=Portál adat újratöltése
|
command.reload.help=Portál adat újratöltése
|
||||||
command.reload.detailedhelp=Újratölt minden portáladatot az adatmappában található fájlokból
|
command.reload.detailedhelp=Újratölt minden portáladatot az adatmappában található fájlokból
|
||||||
command.reload.reloaded= Minden Advanced Portals adat újratöltve
|
command.reload.reloaded= Minden Advanced Portals adat újratöltve. Egyes konfigurációs értékek teljes szerverújraindítást vagy a plugin újratöltését igényelhetik a hatályba lépéshez.
|
||||||
|
|
||||||
command.create.help=Portál létrehozása
|
command.create.help=Portál létrehozása
|
||||||
command.create.error= Hiba történt a portál létrehozásában:
|
command.create.error= Hiba történt a portál létrehozásában:
|
||||||
|
29
proxycore/build.gradle
Normal file
29
proxycore/build.gradle
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
apply plugin: 'maven-publish'
|
||||||
|
apply plugin: 'idea'
|
||||||
|
apply plugin: 'eclipse'
|
||||||
|
|
||||||
|
configurations {
|
||||||
|
// configuration that holds jars to copy into lib
|
||||||
|
includeLibs
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
|
||||||
|
maven { url "https://repo.maven.apache.org/maven2" }
|
||||||
|
maven { url "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" }
|
||||||
|
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
|
||||||
|
}
|
||||||
|
|
||||||
|
// includeLibs just says to include the library in the final jar
|
||||||
|
dependencies {
|
||||||
|
// This is here just for referencing the proxy message strings
|
||||||
|
implementation project(":core")
|
||||||
|
implementation group: 'com.google.guava', name: 'guava', version: '33.2.0-jre'
|
||||||
|
}
|
||||||
|
|
||||||
|
jar {
|
||||||
|
from configurations.includeLibs.collect {
|
||||||
|
it.isDirectory() ? it : zipTree(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,85 @@
|
|||||||
|
package com.sekwah.advancedportals.proxycore;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import com.sekwah.advancedportals.core.ProxyMessages;
|
||||||
|
import com.sekwah.advancedportals.core.network.ProxyCommandPacket;
|
||||||
|
import com.sekwah.advancedportals.core.network.ProxyTransferDestiPacket;
|
||||||
|
import com.sekwah.advancedportals.core.network.ProxyTransferPacket;
|
||||||
|
import com.sekwah.advancedportals.core.network.ServerDestiPacket;
|
||||||
|
import com.sekwah.advancedportals.core.util.InfoLogger;
|
||||||
|
import com.sekwah.advancedportals.core.util.Lang;
|
||||||
|
import com.sekwah.advancedportals.proxycore.connector.container.ProxyContainer;
|
||||||
|
import com.sekwah.advancedportals.proxycore.connector.container.ProxyJoinData;
|
||||||
|
import com.sekwah.advancedportals.proxycore.connector.container.ProxyPlayerContainer;
|
||||||
|
import com.sekwah.advancedportals.proxycore.connector.container.ProxyServerContainer;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class AdvancedPortalsProxyCore {
|
||||||
|
|
||||||
|
private final InfoLogger logger;
|
||||||
|
private final ProxyContainer proxyContainer;
|
||||||
|
|
||||||
|
public HashMap<String, ProxyJoinData> playerJoinMap = new HashMap<>();
|
||||||
|
|
||||||
|
public AdvancedPortalsProxyCore(InfoLogger logger, ProxyContainer proxyContainer) {
|
||||||
|
this.logger = logger;
|
||||||
|
this.proxyContainer = proxyContainer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onEnable() {
|
||||||
|
this.logger.info(Lang.convertColors("&aSuccessfully enabled!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onDisable() {
|
||||||
|
this.logger.info(Lang.convertColors("&cDisabling plugin!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onServerConnect(ProxyServerContainer server, ProxyPlayerContainer player) {
|
||||||
|
if(this.playerJoinMap.containsKey(player.getUUID())) {
|
||||||
|
var joinData = this.playerJoinMap.get(player.getUUID());
|
||||||
|
if(joinData.isExpired()) return;
|
||||||
|
player.sendServerPluginMessage(new ServerDestiPacket(joinData.destination).encode());
|
||||||
|
this.playerJoinMap.remove(player.getUUID());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPlayerDisconnect(ProxyPlayerContainer player) {
|
||||||
|
this.playerJoinMap.remove(player.getUUID());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Messages coming on the ProxyMessages.CHANNEL_NAME from the server, others will be filtered out before now.
|
||||||
|
* @param player
|
||||||
|
* @param message
|
||||||
|
*/
|
||||||
|
public void incomingMessage(ProxyPlayerContainer player, byte[] message) {
|
||||||
|
|
||||||
|
var buffer = ByteStreams.newDataInput(message);
|
||||||
|
var messageType = buffer.readUTF();
|
||||||
|
|
||||||
|
// Might be a bit overboard for some as they'll only have one value, but try to keep the decode behavior with
|
||||||
|
// the encode behavior in the packets
|
||||||
|
switch (messageType) {
|
||||||
|
case ProxyMessages.PROXY_TRANSFER -> {
|
||||||
|
var transferPacket = ProxyTransferPacket.decode(buffer);
|
||||||
|
this.logger.info("Transfer request for " + player.getName() + " to " + transferPacket.getServerName());
|
||||||
|
this.proxyContainer.transferPlayer(player, transferPacket.getServerName());
|
||||||
|
}
|
||||||
|
case ProxyMessages.PROXY_COMMAND -> {
|
||||||
|
var commandPacket = ProxyCommandPacket.decode(buffer);
|
||||||
|
this.logger.info("Command request for " + player.getName() + " to run /" + commandPacket.getCommand());
|
||||||
|
this.proxyContainer.invokeCommand(player, commandPacket.getCommand());
|
||||||
|
}
|
||||||
|
case ProxyMessages.PROXY_TRANSFER_DESTI -> {
|
||||||
|
var transferDestiPacket = ProxyTransferDestiPacket.decode(buffer);
|
||||||
|
this.proxyContainer.transferPlayer(player, transferDestiPacket.getServerName());
|
||||||
|
this.playerJoinMap.put(player.getUUID(), new ProxyJoinData(transferDestiPacket.getDestination(), transferDestiPacket.getServerName()));
|
||||||
|
}
|
||||||
|
default -> {
|
||||||
|
this.logger.info("Unknown message type: " + messageType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package com.sekwah.advancedportals.proxycore.connector.container;
|
||||||
|
|
||||||
|
public interface ProxyContainer {
|
||||||
|
void invokeCommand(ProxyPlayerContainer proxyPlayer, String command);
|
||||||
|
|
||||||
|
void transferPlayer(ProxyPlayerContainer proxyPlayer, String serverName);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.sekwah.advancedportals.proxycore.connector.container;
|
||||||
|
|
||||||
|
public class ProxyJoinData {
|
||||||
|
|
||||||
|
public final String destination;
|
||||||
|
public final String serverName;
|
||||||
|
public final long joinTime;
|
||||||
|
|
||||||
|
public ProxyJoinData(String destination, String serverName) {
|
||||||
|
this.destination = destination;
|
||||||
|
this.serverName = serverName;
|
||||||
|
this.joinTime = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isExpired() {
|
||||||
|
return System.currentTimeMillis() - this.joinTime > 1000 * 15; // 15 seconds
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package com.sekwah.advancedportals.proxycore.connector.container;
|
||||||
|
|
||||||
|
public interface ProxyPlayerContainer {
|
||||||
|
String getUUID();
|
||||||
|
String getName();
|
||||||
|
void sendServerPluginMessage(byte[] data);
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
package com.sekwah.advancedportals.proxycore.connector.container;
|
||||||
|
|
||||||
|
public interface ProxyServerContainer {
|
||||||
|
String getServerName();
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
rootProject.name = "Advanced-Portals"
|
rootProject.name = "Advanced-Portals"
|
||||||
// Core modules
|
// Core modules
|
||||||
include 'core'
|
include 'core'
|
||||||
|
include 'proxycore'
|
||||||
include 'lang'
|
include 'lang'
|
||||||
|
|
||||||
// Implementations
|
// Implementations
|
||||||
|
@ -7,12 +7,15 @@ configurations {
|
|||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven { url "https://repo.maven.apache.org/maven2" }
|
maven { url "https://repo.maven.apache.org/maven2" }
|
||||||
maven { url 'https://papermc.io/repo/repository/maven-public/' }
|
maven {
|
||||||
maven { url "https://nexus.velocitypowered.com/repository/maven-public/" }
|
name 'papermc'
|
||||||
|
url 'https://repo.papermc.io/repository/maven-public/'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// includeLibs just says to include the library in the final jar
|
// includeLibs just says to include the library in the final jar
|
||||||
dependencies {
|
dependencies {
|
||||||
|
implementation project(":proxycore")
|
||||||
implementation project(":core")
|
implementation project(":core")
|
||||||
|
|
||||||
implementation("com.velocitypowered:velocity-api:3.1.0")
|
implementation("com.velocitypowered:velocity-api:3.1.0")
|
||||||
|
@ -0,0 +1,72 @@
|
|||||||
|
package com.sekwah.advancedportals.velocity;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.sekwah.advancedportals.core.BuildConstants;
|
||||||
|
import com.sekwah.advancedportals.core.ProxyMessages;
|
||||||
|
import com.sekwah.advancedportals.proxycore.AdvancedPortalsProxyCore;
|
||||||
|
import com.sekwah.advancedportals.velocity.connector.container.VelocityProxyContainer;
|
||||||
|
import com.sekwah.advancedportals.velocity.connector.container.VelocityProxyPlayerContainer;
|
||||||
|
import com.sekwah.advancedportals.velocity.connector.container.VelocityProxyServerContainer;
|
||||||
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
|
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
||||||
|
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
||||||
|
import com.velocitypowered.api.event.player.ServerPostConnectEvent;
|
||||||
|
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||||
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
|
import com.velocitypowered.api.plugin.Plugin;
|
||||||
|
import com.velocitypowered.api.proxy.ServerConnection;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier;
|
||||||
|
|
||||||
|
@Plugin(authors = {"sekwah41"} ,id = "advancedportals", name = "Advanced Portals",
|
||||||
|
url = "https://www.spigotmc.org/resources/advanced-portals.14356/",
|
||||||
|
version = BuildConstants.VERSION)
|
||||||
|
public class AdvancedPortalsVelocityPlugin {
|
||||||
|
|
||||||
|
private AdvancedPortalsProxyCore proxyCore;
|
||||||
|
|
||||||
|
private final Logger logger;
|
||||||
|
private final ProxyServer proxy;
|
||||||
|
|
||||||
|
private LegacyChannelIdentifier AP_CHANNEL;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public AdvancedPortalsVelocityPlugin(ProxyServer proxy, Logger logger) {
|
||||||
|
this.proxy = proxy;
|
||||||
|
this.logger = logger;
|
||||||
|
this.proxyCore = new AdvancedPortalsProxyCore(new VelocityInfoLogger(this.logger, this.proxy), new VelocityProxyContainer(this.proxy));
|
||||||
|
this.proxyCore.onEnable();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onProxyInitialize(ProxyInitializeEvent event) {
|
||||||
|
AP_CHANNEL = new LegacyChannelIdentifier(ProxyMessages.CHANNEL_NAME);
|
||||||
|
|
||||||
|
proxy.getChannelRegistrar().register(AP_CHANNEL);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onPluginMessage(PluginMessageEvent event) {
|
||||||
|
if (event.getIdentifier().equals(AP_CHANNEL)) {
|
||||||
|
if(event.getSource() instanceof ServerConnection serverConnection) {
|
||||||
|
this.proxyCore.incomingMessage(new VelocityProxyPlayerContainer(serverConnection.getPlayer(), AP_CHANNEL), event.getData());
|
||||||
|
}
|
||||||
|
// So that client packets don't make it through to the servers, always trigger on this channel.
|
||||||
|
event.setResult(PluginMessageEvent.ForwardResult.handled());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void postJoinEvent(ServerPostConnectEvent event) {
|
||||||
|
event.getPlayer().getCurrentServer().ifPresent(serverConnection -> {
|
||||||
|
this.proxyCore.onServerConnect(new VelocityProxyServerContainer(serverConnection.getServer()), new VelocityProxyPlayerContainer(event.getPlayer(), AP_CHANNEL));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onDisconnect(DisconnectEvent event) {
|
||||||
|
this.proxyCore.onPlayerDisconnect(new VelocityProxyPlayerContainer(event.getPlayer(), AP_CHANNEL));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
package com.sekwah.advancedportals.velocity;
|
||||||
|
import com.sekwah.advancedportals.core.util.InfoLogger;
|
||||||
|
import com.sekwah.advancedportals.velocity.connector.MinecraftToAnsi;
|
||||||
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
public class VelocityInfoLogger extends InfoLogger {
|
||||||
|
|
||||||
|
private final Logger logger;
|
||||||
|
private final ProxyServer proxy;
|
||||||
|
private final LegacyComponentSerializer serializer = LegacyComponentSerializer.builder().character('&').hexCharacter('#').hexColors().build();
|
||||||
|
|
||||||
|
public VelocityInfoLogger(Logger logger, ProxyServer proxy) {
|
||||||
|
this.logger = logger;
|
||||||
|
this.proxy = proxy;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void warning(String s) {
|
||||||
|
logger.warn(MinecraftToAnsi.convert(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void info(String s) {
|
||||||
|
logger.info(MinecraftToAnsi.convert(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void error(Exception e) {
|
||||||
|
logger.error(MinecraftToAnsi.convert("\u00A7c" + e.getMessage()), e);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
package com.sekwah.advancedportals.velocity.connector;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* I believe later versions of velocity have some component handlers for this, and I could just send it to the server as components
|
||||||
|
* but ive decided to throw this in for now just to use the plugin logger. Also, to try to clone the bungee behavior as close as possible.
|
||||||
|
*/
|
||||||
|
public class MinecraftToAnsi {
|
||||||
|
|
||||||
|
private static final Map<Character, String> minecraftToAnsiMap = new HashMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
minecraftToAnsiMap.put('0', "\u001B[30m"); // Black
|
||||||
|
minecraftToAnsiMap.put('1', "\u001B[34m"); // Dark Blue
|
||||||
|
minecraftToAnsiMap.put('2', "\u001B[32m"); // Dark Green
|
||||||
|
minecraftToAnsiMap.put('3', "\u001B[36m"); // Dark Aqua
|
||||||
|
minecraftToAnsiMap.put('4', "\u001B[31m"); // Dark Red
|
||||||
|
minecraftToAnsiMap.put('5', "\u001B[35m"); // Dark Purple
|
||||||
|
minecraftToAnsiMap.put('6', "\u001B[33m"); // Gold
|
||||||
|
minecraftToAnsiMap.put('7', "\u001B[37m"); // Gray
|
||||||
|
minecraftToAnsiMap.put('8', "\u001B[90m"); // Dark Gray
|
||||||
|
minecraftToAnsiMap.put('9', "\u001B[94m"); // Blue
|
||||||
|
minecraftToAnsiMap.put('a', "\u001B[92m"); // Green
|
||||||
|
minecraftToAnsiMap.put('b', "\u001B[96m"); // Aqua
|
||||||
|
minecraftToAnsiMap.put('c', "\u001B[91m"); // Red
|
||||||
|
minecraftToAnsiMap.put('d', "\u001B[95m"); // Light Purple
|
||||||
|
minecraftToAnsiMap.put('e', "\u001B[93m"); // Yellow
|
||||||
|
minecraftToAnsiMap.put('f', "\u001B[97m"); // White
|
||||||
|
minecraftToAnsiMap.put('k', "\u001B[5m"); // Obfuscated (Blinking)
|
||||||
|
minecraftToAnsiMap.put('l', "\u001B[1m"); // Bold
|
||||||
|
minecraftToAnsiMap.put('m', "\u001B[9m"); // Strikethrough
|
||||||
|
minecraftToAnsiMap.put('n', "\u001B[4m"); // Underline
|
||||||
|
minecraftToAnsiMap.put('o', "\u001B[3m"); // Italic
|
||||||
|
minecraftToAnsiMap.put('r', "\u001B[0m"); // Reset
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String convert(String text) {
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
for (int i = 0; i < text.length(); i++) {
|
||||||
|
if (text.charAt(i) == '\u00A7' && i + 1 < text.length()) {
|
||||||
|
char code = Character.toLowerCase(text.charAt(i + 1));
|
||||||
|
String ansiCode = minecraftToAnsiMap.getOrDefault(code, "");
|
||||||
|
result.append(ansiCode);
|
||||||
|
i++;
|
||||||
|
} else {
|
||||||
|
result.append(text.charAt(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result.append("\u001B[0m");
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
package com.sekwah.advancedportals.velocity.connector.container;
|
||||||
|
|
||||||
|
import com.sekwah.advancedportals.proxycore.connector.container.ProxyContainer;
|
||||||
|
import com.sekwah.advancedportals.proxycore.connector.container.ProxyPlayerContainer;
|
||||||
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
|
||||||
|
public class VelocityProxyContainer implements ProxyContainer {
|
||||||
|
private final ProxyServer proxy;
|
||||||
|
|
||||||
|
public VelocityProxyContainer(ProxyServer proxy) {
|
||||||
|
this.proxy = proxy;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void invokeCommand(ProxyPlayerContainer proxyPlayer, String command) {
|
||||||
|
if(proxyPlayer instanceof VelocityProxyPlayerContainer playerContainer) {
|
||||||
|
this.proxy.getCommandManager().executeAsync(playerContainer.getPlayer(), command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void transferPlayer(ProxyPlayerContainer proxyPlayer, String serverName) {
|
||||||
|
if(proxyPlayer instanceof VelocityProxyPlayerContainer playerContainer) {
|
||||||
|
this.proxy.getServer(serverName).ifPresentOrElse(
|
||||||
|
server -> {
|
||||||
|
playerContainer.getPlayer().createConnectionRequest(server).fireAndForget();
|
||||||
|
},
|
||||||
|
() -> playerContainer.getPlayer().sendMessage(Component.text("Could not find server: " + serverName))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package com.sekwah.advancedportals.velocity.connector.container;
|
||||||
|
|
||||||
|
import com.sekwah.advancedportals.proxycore.connector.container.ProxyPlayerContainer;
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
|
||||||
|
public class VelocityProxyPlayerContainer implements ProxyPlayerContainer {
|
||||||
|
|
||||||
|
private final Player player;
|
||||||
|
private final LegacyChannelIdentifier channel;
|
||||||
|
|
||||||
|
public VelocityProxyPlayerContainer(Player player, LegacyChannelIdentifier channel) {
|
||||||
|
this.player = player;
|
||||||
|
this.channel = channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUUID() {
|
||||||
|
return player.getUniqueId().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return player.getUsername();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendServerPluginMessage(byte[] data) {
|
||||||
|
player.getCurrentServer().ifPresent(serverConnection -> serverConnection.sendPluginMessage(channel, data));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
return this.player;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.sekwah.advancedportals.velocity.connector.container;
|
||||||
|
|
||||||
|
import com.sekwah.advancedportals.proxycore.connector.container.ProxyServerContainer;
|
||||||
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
|
|
||||||
|
public class VelocityProxyServerContainer implements ProxyServerContainer {
|
||||||
|
private final RegisteredServer server;
|
||||||
|
|
||||||
|
public VelocityProxyServerContainer(RegisteredServer server) {
|
||||||
|
this.server = server;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getServerName() {
|
||||||
|
return this.server.getServerInfo().getName();
|
||||||
|
}
|
||||||
|
}
|
@ -1 +1 @@
|
|||||||
0.9.2
|
1.0.0
|
||||||
|
Loading…
Reference in New Issue
Block a user