Finalize join and leave messages

This commit is contained in:
len 2021-05-15 13:26:31 +02:00
parent 904fc3faad
commit c1db6c1e39
9 changed files with 20 additions and 36 deletions

View File

@ -28,7 +28,7 @@ public final class Config {
static int version; static int version;
static boolean verbose; static boolean verbose;
public static void init() { public static void init() { // todo setup share for the config
CONFIG_FILE = new File(new File(System.getProperty("user.home")), "config.yml");; CONFIG_FILE = new File(new File(System.getProperty("user.home")), "config.yml");;
configLoader = YAMLConfigurationLoader.builder() configLoader = YAMLConfigurationLoader.builder()
.setFile(CONFIG_FILE) .setFile(CONFIG_FILE)
@ -204,10 +204,10 @@ public final class Config {
REGEXNODE = getNode("regex-settings"); REGEXNODE = getNode("regex-settings");
} }
public static String SERVERSWTICHMESSAGEFROM = "&7* {player} comes from {from_server}..."; // TODO CONVERT THESE TO MINIMESSAGE public static String SERVERSWTICHMESSAGEFROM = "<gray>* <player> comes from <from_server>..."; // Confirm these are the correct ones @destro
public static String SERVERSWTICHMESSAGETO = "&7* {player} leaves to {to_server}..."; public static String SERVERSWTICHMESSAGETO = "<gray>* <player> leaves to <to_server>...";
public static String SERVERJOINMESSAGE = "&a* {player} appears from thin air..."; public static String SERVERJOINMESSAGE = "<green>* <player> appears from thin air...";
public static String SERVERLEAVEMESSAGE = "&c* {player} vanishes in the mist..."; public static String SERVERLEAVEMESSAGE = "<red>* <player> vanishes in the mist...";
private static void JoinLeaveMessages() { private static void JoinLeaveMessages() {
SERVERSWTICHMESSAGEFROM = getString("messages.switch-server-from", SERVERSWTICHMESSAGEFROM); SERVERSWTICHMESSAGEFROM = getString("messages.switch-server-from", SERVERSWTICHMESSAGEFROM);
SERVERSWTICHMESSAGETO = getString("messages.switch-server-to", SERVERSWTICHMESSAGETO); SERVERSWTICHMESSAGETO = getString("messages.switch-server-to", SERVERSWTICHMESSAGETO);
@ -216,7 +216,7 @@ public final class Config {
} }
public static String DRIVER = "databasedriver"; public static String DRIVER = "mysql";
public static String IP = "0.0.0.0"; public static String IP = "0.0.0.0";
public static String PORT = "3306"; public static String PORT = "3306";
public static String DATABASE = "database"; public static String DATABASE = "database";

View File

@ -10,7 +10,7 @@ public final class RegexConfig {
private final String regexName; private final String regexName;
private final String configPath; private final String configPath;
// TODO move this into regex.yml?
public RegexConfig(String regexName) { public RegexConfig(String regexName) {
this.regexName = regexName; this.regexName = regexName;
this.configPath = "regex-settings." + this.regexName + "."; this.configPath = "regex-settings." + this.regexName + ".";

View File

@ -61,12 +61,6 @@
<version>1.16.5-R0.1-SNAPSHOT</version> <version>1.16.5-R0.1-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-minimessage</artifactId>
<version>4.1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
<properties> <properties>
<maven.compiler.target>11</maven.compiler.target> <maven.compiler.target>11</maven.compiler.target>

View File

@ -91,7 +91,6 @@
<groupId>net.kyori</groupId> <groupId>net.kyori</groupId>
<artifactId>adventure-text-minimessage</artifactId> <artifactId>adventure-text-minimessage</artifactId>
<version>4.1.0-SNAPSHOT</version> <version>4.1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -71,12 +71,6 @@
<version>4.1.0</version> <version>4.1.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-minimessage</artifactId>
<version>4.1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
<properties> <properties>
<maven.compiler.target>11</maven.compiler.target> <maven.compiler.target>11</maven.compiler.target>

View File

@ -102,7 +102,6 @@
<groupId>net.kyori</groupId> <groupId>net.kyori</groupId>
<artifactId>adventure-text-minimessage</artifactId> <artifactId>adventure-text-minimessage</artifactId>
<version>4.1.0-SNAPSHOT</version> <version>4.1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -6,6 +6,7 @@ import com.alttd.chat.config.Config;
import com.alttd.chat.handlers.ChatHandler; import com.alttd.chat.handlers.ChatHandler;
import com.alttd.chat.handlers.ServerHandler; import com.alttd.chat.handlers.ServerHandler;
import com.alttd.chat.listeners.ChatListener; import com.alttd.chat.listeners.ChatListener;
import com.alttd.chat.listeners.ProxyPlayerListener;
import com.alttd.chat.listeners.PluginMessageListener; import com.alttd.chat.listeners.PluginMessageListener;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.Subscribe;
@ -54,6 +55,7 @@ public class VelocityChat {
serverHandler = new ServerHandler(); serverHandler = new ServerHandler();
chatHandler = new ChatHandler(); chatHandler = new ChatHandler();
server.getEventManager().register(this, new ChatListener()); server.getEventManager().register(this, new ChatListener());
server.getEventManager().register(this, new ProxyPlayerListener());
String[] channels = Config.MESSAGECHANNEL.split(":");// todo add a check for this? String[] channels = Config.MESSAGECHANNEL.split(":");// todo add a check for this?
channelIdentifier = MinecraftChannelIdentifier.create(channels[0], channels[1]); channelIdentifier = MinecraftChannelIdentifier.create(channels[0], channels[1]);
server.getChannelRegistrar().register(channelIdentifier); server.getChannelRegistrar().register(channelIdentifier);

View File

@ -46,7 +46,7 @@ public class ServerHandler {
} }
public ServerWrapper getWrapper(String serverName) { public ServerWrapper getWrapper(String serverName) {
for(ServerWrapper wrapper : getServers()) { for(ServerWrapper wrapper : servers) {
if(wrapper.serverName().equalsIgnoreCase(serverName)) { if(wrapper.serverName().equalsIgnoreCase(serverName)) {
return wrapper; return wrapper;
} }

View File

@ -18,15 +18,7 @@ import net.kyori.adventure.text.minimessage.Template;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class PlayerListener { public class ProxyPlayerListener {
private final ServerHandler serverHandler;
private final MiniMessage miniMessage;
public PlayerListener() {
serverHandler = VelocityChat.getPlugin().getServerHandler();
miniMessage = MiniMessage.get();
}
@Subscribe(order = PostOrder.FIRST) @Subscribe(order = PostOrder.FIRST)
public void onPlayerLogin(LoginEvent event) { public void onPlayerLogin(LoginEvent event) {
@ -41,6 +33,8 @@ public class PlayerListener {
// Server Join and Leave messages // Server Join and Leave messages
@Subscribe @Subscribe
public void serverConnected(ServerConnectedEvent event) { public void serverConnected(ServerConnectedEvent event) {
ServerHandler serverHandler = VelocityChat.getPlugin().getServerHandler();
MiniMessage miniMessage = MiniMessage.get();
if (event.getPreviousServer().isPresent()) { if (event.getPreviousServer().isPresent()) {
RegisteredServer previousServer = event.getPreviousServer().get(); RegisteredServer previousServer = event.getPreviousServer().get();
@ -51,11 +45,11 @@ public class PlayerListener {
Template.of("from_server", previousServer.getServerInfo().getName()), Template.of("from_server", previousServer.getServerInfo().getName()),
Template.of("to_server", event.getServer().getServerInfo().getName()))); Template.of("to_server", event.getServer().getServerInfo().getName())));
// todo Code clean up @Destro // todo Code clean up @Destro
ServerWrapper wrapper = serverHandler.getWrapper(previousServer.getServerInfo().toString()); ServerWrapper wrapper = serverHandler.getWrapper(previousServer.getServerInfo().getName());
if(wrapper != null) { if(wrapper != null) {
wrapper.sendJoinLeaveMessage(miniMessage.parse(Config.SERVERSWTICHMESSAGETO, templates)); wrapper.sendJoinLeaveMessage(miniMessage.parse(Config.SERVERSWTICHMESSAGETO, templates));
} }
wrapper = serverHandler.getWrapper(event.getServer().getServerInfo().toString()); wrapper = serverHandler.getWrapper(event.getServer().getServerInfo().getName());
if(wrapper != null) { if(wrapper != null) {
wrapper.sendJoinLeaveMessage(miniMessage.parse(Config.SERVERSWTICHMESSAGEFROM, templates)); wrapper.sendJoinLeaveMessage(miniMessage.parse(Config.SERVERSWTICHMESSAGEFROM, templates));
} }
@ -63,7 +57,7 @@ public class PlayerListener {
List<Template> templates = new ArrayList<>(List.of( List<Template> templates = new ArrayList<>(List.of(
Template.of("player", event.getPlayer().getUsername()) Template.of("player", event.getPlayer().getUsername())
)); ));
ServerWrapper wrapper = serverHandler.getWrapper(event.getServer().getServerInfo().toString()); ServerWrapper wrapper = serverHandler.getWrapper(event.getServer().getServerInfo().getName());
if(wrapper != null) { if(wrapper != null) {
wrapper.sendJoinLeaveMessage(miniMessage.parse(Config.SERVERJOINMESSAGE, templates)); wrapper.sendJoinLeaveMessage(miniMessage.parse(Config.SERVERJOINMESSAGE, templates));
} }
@ -72,6 +66,8 @@ public class PlayerListener {
@Subscribe @Subscribe
public void serverDisconnected(DisconnectEvent event) { public void serverDisconnected(DisconnectEvent event) {
ServerHandler serverHandler = VelocityChat.getPlugin().getServerHandler();
MiniMessage miniMessage = MiniMessage.get();
if (event.getLoginStatus().equals(DisconnectEvent.LoginStatus.SUCCESSFUL_LOGIN) && event.getPlayer().getCurrentServer().isPresent()) { if (event.getLoginStatus().equals(DisconnectEvent.LoginStatus.SUCCESSFUL_LOGIN) && event.getPlayer().getCurrentServer().isPresent()) {
RegisteredServer registeredServer = event.getPlayer().getCurrentServer().get().getServer(); RegisteredServer registeredServer = event.getPlayer().getCurrentServer().get().getServer();
@ -79,9 +75,9 @@ public class PlayerListener {
Template.of("player", event.getPlayer().getUsername()), Template.of("player", event.getPlayer().getUsername()),
Template.of("from_server", registeredServer.getServerInfo().getName()))); Template.of("from_server", registeredServer.getServerInfo().getName())));
ServerWrapper wrapper = serverHandler.getWrapper(registeredServer.getServerInfo().toString()); ServerWrapper wrapper = serverHandler.getWrapper(registeredServer.getServerInfo().getName());
if(wrapper != null) { if(wrapper != null) {
wrapper.sendJoinLeaveMessage(miniMessage.parse(Config.SERVERJOINMESSAGE, templates)); wrapper.sendJoinLeaveMessage(miniMessage.parse(Config.SERVERLEAVEMESSAGE, templates));
} }
} }
} }