feat: hidden servers

This commit is contained in:
ChomeNS
2025-03-05 10:47:27 +07:00
parent 4e37021b50
commit bb766652f6
17 changed files with 58 additions and 50 deletions

View File

@@ -360,8 +360,11 @@ public class Bot {
session.connect(false);
}
public String getServerString () {
return host + ":" + port;
public String getServerString () { return getServerString(false); }
public String getServerString (boolean bypassHidden) {
return options.hidden && !bypassHidden ?
options.serverName :
host + ":" + port;
}
public void stop () {

View File

@@ -176,6 +176,7 @@ public class Configuration {
public String username;
public boolean creayun = false;
public String serverName;
public boolean hidden = false;
public boolean useCore = true;
public boolean useCorePlaceBlock = false;
public boolean useChat = false;

View File

@@ -197,7 +197,7 @@ public class Main {
for (Bot bot : copiedList) {
try {
if (discordEnabled) {
final String channelId = bot.discord.servers.get(bot.getServerString());
final String channelId = bot.discord.servers.get(bot.getServerString(true));
final MessageCreateAction messageAction = bot.discord.sendMessageInstantly(stoppingMessage, channelId, false);

View File

@@ -39,7 +39,7 @@ public class ConsoleCommand extends Command {
final List<String> servers = new ArrayList<>();
for (Bot eachBot : bot.bots) {
servers.add(eachBot.host + ":" + eachBot.port);
servers.add(bot.getServerString(true));
}
final String server = context.getString(true, true);

View File

@@ -29,25 +29,32 @@ public class NetMessageCommand extends Command {
final Bot bot = context.bot;
final List<Bot> bots = bot.bots;
final String originServer = bot.getServerString();
final String originServerName = bot.getServerString();
final String originServerAddress = bot.getServerString(false);
Component serverNameComponent = Component
.text(originServerName)
.color(NamedTextColor.GRAY);
if (!bot.options.hidden) serverNameComponent = serverNameComponent
.clickEvent(ClickEvent.copyToClipboard(originServerAddress))
.hoverEvent(
HoverEvent.showText(
Component.empty()
.append(Component.text(originServerAddress).color(NamedTextColor.GRAY))
.append(Component.newline())
.append(Component.text("Click here to copy the server host and port to your clipboard").color(NamedTextColor.GREEN))
)
);
final Component component = Component.translatable(
"[%s]%s%s%s %s",
Component
.text(originServer)
.color(NamedTextColor.GRAY)
.clickEvent(ClickEvent.copyToClipboard(originServer))
.hoverEvent(
HoverEvent.showText(
Component.empty()
.append(Component.text(originServer).color(NamedTextColor.GRAY))
.append(Component.newline())
.append(Component.text("Click here to copy the server host and port to your clipboard").color(NamedTextColor.GREEN))
)
),
Component.text(" "),
context.sender.displayName == null ? Component.text(context.sender.profile.getName()).color(NamedTextColor.GRAY) : context.sender.displayName.color(NamedTextColor.GRAY),
Component.text(" "),
serverNameComponent,
Component.space(),
context.sender.displayName == null ?
Component.text(context.sender.profile.getName()).color(NamedTextColor.GRAY) :
context.sender.displayName.color(NamedTextColor.GRAY),
Component.space(),
Component.text(context.getString(true, true)).color(NamedTextColor.GRAY)
).color(NamedTextColor.DARK_GRAY);

View File

@@ -52,7 +52,7 @@ public class SeenCommand extends Command {
Component.empty()
.append(Component.text(player))
.append(Component.text(" is currently online on "))
.append(Component.text(eachBot.host + ":" + eachBot.port))
.append(Component.text(eachBot.getServerString()))
.color(NamedTextColor.RED)
);
}

View File

@@ -16,7 +16,7 @@ public class AuthPlugin extends PlayersPlugin.Listener {
public AuthPlugin (Bot bot) {
this.bot = bot;
this.ownerIpForServer = bot.config.ownerAuthentication.ips.get(bot.getServerString());
this.ownerIpForServer = bot.config.ownerAuthentication.ips.get(bot.getServerString(true));
if (!bot.config.ownerAuthentication.enabled || ownerIpForServer == null) return;

View File

@@ -77,7 +77,7 @@ public class ConsolePlugin implements Completer {
if (line == null) return;
for (Bot bot : allBots) {
final String server = bot.getServerString();
final String server = bot.getServerString(true);
if (!server.equals(consoleServer) && !consoleServer.equals("all")) continue;

View File

@@ -79,7 +79,7 @@ public class DiscordPlugin {
jda.getPresence().setPresence(Activity.playing(config.discord.statusMessage), false);
for (Bot bot : Main.bots) {
final String channelId = servers.get(bot.getServerString());
final String channelId = servers.get(bot.getServerString(true));
totalConnects.put(channelId, 0); // is this necessary?
@@ -127,9 +127,8 @@ public class DiscordPlugin {
sendMessageInstantly(
String.format(
"Connecting to: `%s:%s`",
bot.host,
bot.port
"Connecting to: `%s`",
bot.getServerString()
),
channelId
);
@@ -141,9 +140,8 @@ public class DiscordPlugin {
sendMessageInstantly(
String.format(
"Successfully connected to: `%s:%s`",
bot.host,
bot.port
"Successfully connected to: `%s`",
bot.getServerString()
),
channelId
);

View File

@@ -88,7 +88,7 @@ public class GrepLogPlugin {
if (matches == 0) throw new CommandException(Component.text("No matches has been found"));
final String channelId = bot.discord.servers.get(bot.getServerString());
final String channelId = bot.discord.servers.get(bot.getServerString(true));
final TextChannel logChannel = bot.discord.jda.getTextChannelById(channelId);
if (logChannel == null) return;

View File

@@ -97,7 +97,7 @@ public class IRCPlugin extends ListenerAdapter {
for (Map.Entry<String, String> entry : servers.entrySet()) {
if (entry.getValue().equals(event.getChannel().getName())) {
serverBot = Main.bots.stream()
.filter(eachBot -> entry.getKey().equals(eachBot.host + ":" + eachBot.port))
.filter(eachBot -> entry.getKey().equals(eachBot.getServerString(true)))
.findFirst()
.orElse(null);
@@ -179,9 +179,8 @@ public class IRCPlugin extends ListenerAdapter {
sendMessage(
bot,
String.format(
"Successfully connected to: %s:%s",
bot.host,
bot.port
"Successfully connected to: %s",
bot.getServerString()
)
);
}
@@ -209,7 +208,7 @@ public class IRCPlugin extends ListenerAdapter {
}
private void addMessageToQueue (Bot bot, String message) {
final String channel = servers.get(bot.getServerString());
final String channel = servers.get(bot.getServerString(true));
addMessageToQueue(channel, message);
}
@@ -227,7 +226,7 @@ public class IRCPlugin extends ListenerAdapter {
}
public void sendMessage (Bot bot, String message) {
final String hostAndPort = bot.getServerString();
final String hostAndPort = bot.getServerString(true);
final String channel = servers.get(hostAndPort);

View File

@@ -38,9 +38,8 @@ public class LoggerPlugin extends ChatPlugin.Listener {
log(
String.format(
"Connecting to: %s:%s",
bot.host,
bot.port
"Connecting to: %s",
bot.getServerString(true)
)
);
}
@@ -49,9 +48,8 @@ public class LoggerPlugin extends ChatPlugin.Listener {
public void connected (ConnectedEvent event) {
log(
String.format(
"Successfully connected to: %s:%s",
bot.host,
bot.port
"Successfully connected to: %s",
bot.getServerString(true)
)
);
@@ -68,7 +66,7 @@ public class LoggerPlugin extends ChatPlugin.Listener {
final Component reason = event.getReason();
final String message = "Disconnected from " + bot.getServerString() + ", reason: ";
final String message = "Disconnected from " + bot.getServerString(true) + ", reason: ";
final String string = ComponentUtilities.stringify(reason);

View File

@@ -87,7 +87,7 @@ public class PlayersDatabasePlugin extends PlayersPlugin.Listener {
} else {
statement = bot.database.connection.prepareStatement(FIND_ALTS_SINGLE_SERVER);
statement.setString(1, bot.getServerString());
statement.setString(1, bot.getServerString(true));
statement.setString(2, ip);
}
@@ -141,7 +141,7 @@ public class PlayersDatabasePlugin extends PlayersPlugin.Listener {
updatePlayerStatement.setString(2, "$.ips");
final ObjectNode ipsObject = JsonNodeFactory.instance.objectNode();
ipsObject.put(bot.getServerString(), output);
ipsObject.put(bot.getServerString(true), output);
updatePlayerStatement.setString(3, objectMapper.writeValueAsString(ipsObject));
@@ -186,7 +186,7 @@ public class PlayersDatabasePlugin extends PlayersPlugin.Listener {
final ObjectNode object = JsonNodeFactory.instance.objectNode();
object.put("time", Instant.now().toEpochMilli());
object.put("server", bot.getServerString());
object.put("server", bot.getServerString(true));
return object;
}

View File

@@ -77,7 +77,7 @@ public class PlayersPlugin extends Bot.Listener {
if (ipsObject == null || ipsObject.isNull() || !ipsObject.isObject()) return null;
final JsonNode targetIP = ipsObject.get(bot.getServerString());
final JsonNode targetIP = ipsObject.get(bot.getServerString(true));
if (targetIP == null || targetIP.isNull() || !targetIP.isTextual()) return null;

View File

@@ -51,7 +51,7 @@ public class LoggerUtilities {
final String formattedMessage = bot == null ? "" :
String.format(
"[%s] %s",
bot.getServerString(),
bot.getServerString(true),
message
);