Server Join/leave Messages
This commit is contained in:
parent
be9d8f4ab3
commit
ec2377a837
|
|
@ -204,4 +204,31 @@ 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 SERVERSWTICHMESSAGETO = "&7* {player} leaves to {to_server}...";
|
||||||
|
public static String SERVERJOINMESSAGE = "&a* {player} appears from thin air...";
|
||||||
|
public static String SERVERLEAVEMESSAGE = "&c* {player} vanishes in the mist...";
|
||||||
|
private static void JoinLeaveMessages() {
|
||||||
|
SERVERSWTICHMESSAGEFROM = getString("messages.switch-server-from", SERVERSWTICHMESSAGEFROM);
|
||||||
|
SERVERSWTICHMESSAGETO = getString("messages.switch-server-to", SERVERSWTICHMESSAGETO);
|
||||||
|
SERVERJOINMESSAGE = getString("messages.join-server", SERVERJOINMESSAGE);
|
||||||
|
SERVERLEAVEMESSAGE = getString("messages.leave-server", SERVERLEAVEMESSAGE);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String DRIVER = "databasedriver";
|
||||||
|
public static String IP = "0.0.0.0";
|
||||||
|
public static String PORT = "3306";
|
||||||
|
public static String DATABASE = "database";
|
||||||
|
public static String USERNAME = "root";
|
||||||
|
public static String PASSWORD = "root";
|
||||||
|
private static void database() {
|
||||||
|
DRIVER = getString("database.driver" , DRIVER);
|
||||||
|
IP = getString("database.ip", IP);
|
||||||
|
PORT = getString("database.port", PORT);
|
||||||
|
DATABASE = getString("database.name", DATABASE);
|
||||||
|
USERNAME = getString("database.username", USERNAME);
|
||||||
|
PASSWORD = getString("database.password", PASSWORD);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package com.alttd.chat.database;
|
package com.alttd.chat.database;
|
||||||
|
|
||||||
|
|
||||||
|
import com.alttd.chat.config.Config;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
@ -16,14 +18,12 @@ public class DatabaseConnection {
|
||||||
*/
|
*/
|
||||||
public DatabaseConnection() {
|
public DatabaseConnection() {
|
||||||
|
|
||||||
/*this.drivers = Config.drivers;
|
this.drivers = Config.DRIVER;
|
||||||
this.ip = Config.ip;
|
this.ip = Config.IP;
|
||||||
this.port = Config.port;
|
this.port = Config.PORT;
|
||||||
this.database = Config.database;
|
this.database = Config.DATABASE;
|
||||||
this.username = Config.username;
|
this.username = Config.USERNAME;
|
||||||
this.password = Config.password;*/
|
this.password = Config.PASSWORD;
|
||||||
// temp to make compile, remove when config is added
|
|
||||||
this.drivers = this.ip = this.port = this.database = this.username = this.password = "";
|
|
||||||
instance = this;
|
instance = this;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,20 @@
|
||||||
package com.alttd.chat.listeners;
|
package com.alttd.chat.listeners;
|
||||||
|
|
||||||
import com.alttd.chat.VelocityChat;
|
import com.alttd.chat.VelocityChat;
|
||||||
|
import com.alttd.chat.config.Config;
|
||||||
import com.alttd.chat.objects.ChatPlayer;
|
import com.alttd.chat.objects.ChatPlayer;
|
||||||
import com.velocitypowered.api.event.PostOrder;
|
import com.velocitypowered.api.event.PostOrder;
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
||||||
import com.velocitypowered.api.event.connection.LoginEvent;
|
import com.velocitypowered.api.event.connection.LoginEvent;
|
||||||
|
import com.velocitypowered.api.event.player.ServerConnectedEvent;
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.kyori.adventure.text.minimessage.Template;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class PlayerListener {
|
public class PlayerListener {
|
||||||
|
|
||||||
|
|
@ -18,4 +27,46 @@ public class PlayerListener {
|
||||||
public void quitEvent(DisconnectEvent event) {
|
public void quitEvent(DisconnectEvent event) {
|
||||||
VelocityChat.getPlugin().getChatHandler().removePlayer(event.getPlayer().getUniqueId());
|
VelocityChat.getPlugin().getChatHandler().removePlayer(event.getPlayer().getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Server Join and Leave messages
|
||||||
|
@Subscribe
|
||||||
|
public void serverConnected(ServerConnectedEvent event) {
|
||||||
|
MiniMessage miniMessage = MiniMessage.get();
|
||||||
|
// todo optional setting to ignore this for servers?
|
||||||
|
if (event.getPreviousServer().isPresent()) {
|
||||||
|
RegisteredServer previousServer = event.getPreviousServer().get();
|
||||||
|
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
List<Template> templates = new ArrayList<>(List.of(
|
||||||
|
Template.of("player", player.getUsername()),
|
||||||
|
Template.of("from_server", previousServer.getServerInfo().getName()),
|
||||||
|
Template.of("to_server", event.getServer().getServerInfo().getName())));
|
||||||
|
|
||||||
|
previousServer.sendMessage(miniMessage.parse(Config.SERVERSWTICHMESSAGETO, templates));
|
||||||
|
event.getServer().sendMessage(miniMessage.parse(Config.SERVERSWTICHMESSAGEFROM, templates));
|
||||||
|
} else {
|
||||||
|
List<Template> templates = new ArrayList<>(List.of(
|
||||||
|
Template.of("player", event.getPlayer().getUsername())
|
||||||
|
));
|
||||||
|
event.getServer().sendMessage(miniMessage.parse(Config.SERVERJOINMESSAGE, templates));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void serverDisconnected(DisconnectEvent event) {
|
||||||
|
if (event.getLoginStatus().equals(DisconnectEvent.LoginStatus.SUCCESSFUL_LOGIN) && event.getPlayer().getCurrentServer().isPresent()) {
|
||||||
|
RegisteredServer registeredServer = event.getPlayer().getCurrentServer().get().getServer();
|
||||||
|
|
||||||
|
MiniMessage miniMessage = MiniMessage.get();
|
||||||
|
|
||||||
|
List<Template> templates = new ArrayList<>(List.of(
|
||||||
|
Template.of("player", event.getPlayer().getUsername()),
|
||||||
|
Template.of("from_server", registeredServer.getServerInfo().getName())));
|
||||||
|
|
||||||
|
registeredServer.sendMessage(miniMessage.parse(Config.SERVERLEAVEMESSAGE, templates));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user