mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 17:17:37 +00:00
Adds a connection listener to proxy module
This commit is contained in:
parent
fd50589331
commit
6c4903c3fe
@ -10,17 +10,16 @@ import dev.plex.config.TomlConfig;
|
|||||||
import dev.plex.handlers.ListenerHandler;
|
import dev.plex.handlers.ListenerHandler;
|
||||||
import dev.plex.settings.ServerSettings;
|
import dev.plex.settings.ServerSettings;
|
||||||
import dev.plex.util.PlexLog;
|
import dev.plex.util.PlexLog;
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Credits for TOML library go to https://github.com/mwanji/toml4j
|
* Credits for TOML library go to https://github.com/mwanji/toml4j
|
||||||
* I was unable to add it back to the package without it glitching, so
|
* I was unable to add it back to the package without it glitching, so
|
||||||
* I kept it in a separate package.
|
* I kept it in a separate package.
|
||||||
*
|
* <p>
|
||||||
* Modifications: Properly indent arrays in TOML as well as only append
|
* Modifications: Properly indent arrays in TOML as well as only append
|
||||||
* missing object fields into the file
|
* missing object fields into the file
|
||||||
*/
|
*/
|
||||||
@ -38,7 +37,7 @@ public class Plex
|
|||||||
{
|
{
|
||||||
private static Plex plugin;
|
private static Plex plugin;
|
||||||
|
|
||||||
private final ProxyServer server;
|
public final ProxyServer server;
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
private final File dataFolder;
|
private final File dataFolder;
|
||||||
|
|
||||||
|
@ -0,0 +1,45 @@
|
|||||||
|
package dev.plex.listener.impl;
|
||||||
|
|
||||||
|
import com.velocitypowered.api.event.PostOrder;
|
||||||
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
|
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
||||||
|
import com.velocitypowered.api.event.player.ServerConnectedEvent;
|
||||||
|
import dev.plex.Plex;
|
||||||
|
import dev.plex.listener.PlexListener;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
|
||||||
|
public class ConnectionListener extends PlexListener
|
||||||
|
{
|
||||||
|
@Subscribe(order = PostOrder.FIRST)
|
||||||
|
public void onPlayerJoin(ServerConnectedEvent event)
|
||||||
|
{
|
||||||
|
if (event.getPreviousServer().isPresent())
|
||||||
|
{
|
||||||
|
Plex.get().server.sendMessage(miniMessage("<dark_gray>[<#ffbf00>o<dark_gray>] <yellow>"
|
||||||
|
+ event.getPlayer().getUsername() + " switched from " + event.getPreviousServer().get().getServerInfo().getName()
|
||||||
|
+ " to " + event.getServer().getServerInfo().getName()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Plex.get().server.sendMessage(miniMessage("<dark_gray>[<green>+<dark_gray>] <yellow>"
|
||||||
|
+ event.getPlayer().getUsername() + " joined server " + event.getServer().getServerInfo().getName()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe(order = PostOrder.FIRST)
|
||||||
|
public void onPlayerLeave(DisconnectEvent event)
|
||||||
|
{
|
||||||
|
if (event.getPlayer().getCurrentServer().isPresent())
|
||||||
|
{
|
||||||
|
Plex.get().server.sendMessage(miniMessage("<dark_gray>[<red>-<dark_gray>] <yellow>"
|
||||||
|
+ event.getPlayer().getUsername() + " left server " +
|
||||||
|
event.getPlayer().getCurrentServer().get().getServerInfo().getName()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Component miniMessage(String message)
|
||||||
|
{
|
||||||
|
return MiniMessage.miniMessage().deserialize(message);
|
||||||
|
}
|
||||||
|
}
|
@ -4,20 +4,16 @@ import com.velocitypowered.api.event.PostOrder;
|
|||||||
import com.velocitypowered.api.event.Subscribe;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
import com.velocitypowered.api.event.proxy.ProxyPingEvent;
|
import com.velocitypowered.api.event.proxy.ProxyPingEvent;
|
||||||
import com.velocitypowered.api.proxy.server.ServerPing;
|
import com.velocitypowered.api.proxy.server.ServerPing;
|
||||||
import dev.plex.Plex;
|
|
||||||
import dev.plex.listener.PlexListener;
|
import dev.plex.listener.PlexListener;
|
||||||
import dev.plex.settings.ServerSettings;
|
import dev.plex.settings.ServerSettings;
|
||||||
import dev.plex.util.PlexLog;
|
|
||||||
import dev.plex.util.RandomUtil;
|
import dev.plex.util.RandomUtil;
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
|
||||||
public class ServerListener extends PlexListener
|
public class ServerListener extends PlexListener
|
||||||
{
|
{
|
||||||
@ -41,7 +37,9 @@ public class ServerListener extends PlexListener
|
|||||||
motd.set(motd.get().append(Component.space()));
|
motd.set(motd.get().append(Component.space()));
|
||||||
}
|
}
|
||||||
builder.description(motd.get());
|
builder.description(motd.get());
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
builder.description(MiniMessage.miniMessage().deserialize(baseMotd));
|
builder.description(MiniMessage.miniMessage().deserialize(baseMotd));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,5 +59,4 @@ public class ServerListener extends PlexListener
|
|||||||
Matcher matcher = Pattern.compile("[&][0-9a-fk-or]{1}").matcher(code);
|
Matcher matcher = Pattern.compile("[&][0-9a-fk-or]{1}").matcher(code);
|
||||||
return matcher.replaceAll(matchResult -> "§" + matcher.group().substring(1));
|
return matcher.replaceAll(matchResult -> "§" + matcher.group().substring(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user