Skip to content

Commit

Permalink
added center screen title like 2b2t
Browse files Browse the repository at this point in the history
  • Loading branch information
bierdosenhalter committed Sep 7, 2022
1 parent 9bcf386 commit ea70f5f
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 41 deletions.
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ A simple queue system for BungeeCord (and Velocity) in the style of the 2b2t que

### Config

| Value | Description |
|----------------------|----------------------------------------------------------|
| target | server name from bungee config |
| queue | server name from bungee config |
| maxPlayers | max players of target before players are queued |
| waitOnKick | seconds to wait after a kick before reconnect |
| messagePosition | player message, that shows his position in the queue |
| messageConnecting | player message, when connecting to the target server |
| messageFullOrOffline | player message, when the target is full or offline |
| serverName | target server name displayed to the player |
| kickPassthrough | if false, players will be enqueued again |
| kickOnRestart | if true, players will be kicked when the target restarts |
| kickOnBusy | if true, players will be kicked if the target is busy |
| bStats | if true, plugin metrics are enabled |

| Value | Description |
|----------------------|--------------------------------------------------------------|
| target | server name from bungee config |
| queue | server name from bungee config |
| maxPlayers | max players of target before players are queued |
| waitOnKick | seconds to wait after a kick before reconnect |
| messagePosition | player message, that shows his position in the queue |
| messageConnecting | player message, when connecting to the target server |
| messageFullOrOffline | player message, when the target is full or offline |
| serverName | target server name displayed to the player |
| kickPassthrough | if false, players will be enqueued again |
| kickOnRestart | if true, players will be kicked when the target restarts |
| kickOnBusy | if true, players will be kicked if the target is busy |
| bStats | if true, plugin metrics are enabled |
| senTitle | should the position be displayed in the center of the screen |
### Versions

- 1.* is for BungeeCord
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.zeroBzeroT</groupId>
<artifactId>AnarchyQueue</artifactId>
<version>1.5.6</version>
<version>1.5.7</version>
<packaging>jar</packaging>
<name>${project.artifactId}</name>

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/zeroBzeroT/anarchyqueue/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public class Config {
public static boolean kickPassthrough = true;
public static boolean kickOnRestart = false;
public static boolean kickOnBusy = false;
public static boolean bStats = false;
public static boolean bStats = true;

public static boolean sendTitle = true;

/**
* Loads a config file, and if it doesn't exist creates one
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/zeroBzeroT/anarchyqueue/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public void onEnable() {
log("config", "§3Pass main server kicks to client: §r" + Config.kickPassthrough);
log("config", "§3Kick on restart of the main server: §r" + Config.kickOnRestart);
log("config", "§3Kick when the main server is busy: §r" + Config.kickOnBusy);
log("config", "§3Send status as title: §r" + Config.sendTitle);

// Load Plugin Metrics
if (Config.bStats) {
Expand Down
77 changes: 54 additions & 23 deletions src/main/java/org/zeroBzeroT/anarchyqueue/Queue.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package org.zeroBzeroT.anarchyqueue;

import net.md_5.bungee.api.Callback;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.ServerPing;
import net.md_5.bungee.api.*;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.config.ServerInfo;
Expand Down Expand Up @@ -95,19 +92,24 @@ public void flushQueue() {
if (isNotConnected(player, targetServer)) {
Callback<Boolean> cb = (result, error) -> {
if (result) {
Main.log("queue", f" + finalPlayer.getName() + "§3 connected to server §b" + Config.target + "§3. Queue count is " + playerQueue.size() + ". Main count is " + (mainServerInfo.playerCount + 1) + " of " + Config.maxPlayers + ".");
Main.log("queue", "§f" + finalPlayer.getName() + "§3 connected to server §b" + Config.target + "§3. Queue count is " + playerQueue.size() + ". Main count is " + (mainServerInfo.playerCount + 1) + " of " + Config.maxPlayers + ".");
} else {
Main.log("queue", f" + finalPlayer.getName() + "s§c connection to server §b" + Config.target + "§c failed: " + error.getMessage());
Main.log("queue", "§f" + finalPlayer.getName() + "s§c connection to server §b" + Config.target + "§c failed: " + error.getMessage());
finalPlayer.sendMessage(TextComponent.fromLegacyText("§cConnection to " + Config.serverName + " failed!§r"));
playerQueue.add(finalPlayer);
}
};

// Clear the title
if (Config.sendTitle) {
sendTitle(player, " ", " ", 0, 0, 0);
}

player.sendMessage(TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', Config.messageConnecting) + "§r"));
player.connect(targetServer, cb);
} else {
player.disconnect(TextComponent.fromLegacyText("§cYou are already connected to " + Config.serverName + "!"));
Main.log("queue", f" + player.getName() + "§c was disconnected because there was already a connection for this account to the server.");
Main.log("queue", "§f" + player.getName() + "§c was disconnected because there was already a connection for this account to the server.");
}
}
} catch (InterruptedException e) {
Expand Down Expand Up @@ -137,6 +139,12 @@ public void sendUpdate() {

player.sendMessage(TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', Config.messagePosition.replaceAll("%position%", Integer.toString(i))) + "§r"));

// Title in the center of the screen
if (Config.sendTitle) {
// 10 Seconds + 1 s buffer
sendTitle(player, " ", ChatColor.translateAlternateColorCodes('&', Config.messagePosition.replaceAll("%position%", Integer.toString(i))) + "§r", 0, 20 * 11, 0);
}

i++;
}

Expand All @@ -146,7 +154,7 @@ public void sendUpdate() {
mutex.acquire();
playerQueue.remove(player);

Main.log("update", f" + player.getName() + "§3 was removed from the §dplayer queue§3 (wrong server or disconnected). Queue count is " + playerQueue.size() + ".");
Main.log("update", "§f" + player.getName() + "§3 was removed from the §dplayer queue§3 (wrong server or disconnected). Queue count is " + playerQueue.size() + ".");
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
Expand All @@ -169,7 +177,7 @@ public void onServerConnected(ServerConnectedEvent event) {
try {
mutex.acquire();
playerQueue.add(player);
Main.log("connect", f" + player.getName() + "§3 was added to the §dplayer queue§3. Queue count is " + playerQueue.size() + ".");
Main.log("connect", "§f" + player.getName() + "§3 was added to the §dplayer queue§3. Queue count is " + playerQueue.size() + ".");
} catch (InterruptedException e1) {
e1.printStackTrace();
} finally {
Expand All @@ -194,7 +202,7 @@ public void onServerDisconnect(ServerDisconnectEvent event) {
try {
mutex.acquire();
playerQueue.remove(player);
Main.log("disconnect", f" + player.getName() + "§3 was removed from the §dplayer queue§3. Queue count is " + playerQueue.size() + ".");
Main.log("disconnect", "§f" + player.getName() + "§3 was removed from the §dplayer queue§3. Queue count is " + playerQueue.size() + ".");
} catch (InterruptedException e1) {
e1.printStackTrace();
} finally {
Expand All @@ -216,16 +224,15 @@ public void onServerKick(ServerKickEvent event) {
String reason = BaseComponent.toLegacyText(event.getKickReasonComponent());
ProxiedPlayer player = event.getPlayer();

// cancel the event, if one of the following:
// - kicking is not enabled
// - target is restarting (and restart kicks are disabled)
// - target is busy with connecting players (and busy kicks are disabled)
if (!Config.kickPassthrough
|| (!Config.kickOnRestart && reason.toLowerCase().contains("server is restarting"))
|| (!Config.kickOnRestart && reason.toLowerCase().contains("went down"))
|| (!Config.kickOnBusy && reason.toLowerCase().contains("too many people logging in"))
|| (!Config.kickOnBusy && reason.toLowerCase().contains("too fast re-login"))) {
// cancel the event, if one of the following:
// - kicking is not enabled
// - target is restarting (and restart kicks are disabled)
// - target is busy with connecting players (and busy kicks are disabled)

// save the disconnection time
kickedPlayers.put(player, Instant.now().getEpochSecond());

Expand All @@ -235,13 +242,13 @@ public void onServerKick(ServerKickEvent event) {

// send message
player.sendMessage(TextComponent.fromLegacyText("§6You were sent back to the queue for: §c" + reason.replaceAll("\n", " ") + "§r"));
Main.log("kick", f" + player.getName() + "§3 was sent back to server §e" + Config.queue + "§3 after a disconnection (\"" + reason.replaceAll("\n", " ") + "§3\"). Kicked count is " + kickedPlayers.size() + ".");
Main.log("kick", "§f" + player.getName() + "§3 was sent back to server §e" + Config.queue + "§3 after a disconnection (\"" + reason.replaceAll("\n", " ") + "§3\"). Kicked count is " + kickedPlayers.size() + ".");

// the player did not leave the queue, therefore the connect event is not triggered and
// a manual (re)adding to the player queue is required
if (player.getServer() != null && player.getServer().getInfo() == ProxyServer.getInstance().getServerInfo(Config.queue)) {
playerQueue.add(player);
Main.log("kick", f" + player.getName() + "§3 was added to the §dplayer queue§3. Queue count is " + playerQueue.size() + ".");
Main.log("kick", "§f" + player.getName() + "§3 was added to the §dplayer queue§3. Queue count is " + playerQueue.size() + ".");
}
} else {
// set the disconnect reason from the target server (not the bungee message)
Expand All @@ -263,9 +270,10 @@ public void onServerKick(ServerKickEvent event) {
public void onServerConnect(ServerConnectEvent event) {
ProxiedPlayer player = event.getPlayer();

// check if it's a "fresh" connection
// check if it's a "fresh" connection - stop bungee from handling server switching
if (player.getServer() != null) {
if (player.getServer().getInfo().equals(event.getTarget()))
// cancel the event and stop player from accessing another server, since this is done by the plugin
event.setCancelled(true);

return;
Expand All @@ -279,18 +287,18 @@ public void onServerConnect(ServerConnectEvent event) {

if (kickedPlayers.containsKey(player)) {
// player was sent back to the queue after a kick on a fresh connection
Main.log("connect", f" + player.getName() + "§3 was sent to server §e" + Config.queue + "§3 after a kick from server §b" + Config.target + "§3.");
Main.log("connect", "§f" + player.getName() + "§3 was sent to server §e" + Config.queue + "§3 after a kick from server §b" + Config.target + "§3.");
} else if (mainServerInfo.isOnline && mainServerInfo.playerCount < Config.maxPlayers) {
// main server is online and player count is lower then max
ServerInfo targetServer = ProxyServer.getInstance().getServerInfo(Config.target);

if (isNotConnected(player, targetServer)) {
// direct connection
event.setTarget(targetServer);
Main.log("connect", f" + player.getName() + "§3 was directly connected to server §b" + Config.target + "§3. Main count is " + (mainServerInfo.playerCount + 1) + " of " + Config.maxPlayers + ".");
Main.log("connect", "§f" + player.getName() + "§3 was directly connected to server §b" + Config.target + "§3. Main count is " + (mainServerInfo.playerCount + 1) + " of " + Config.maxPlayers + ".");
} else {
player.disconnect(TextComponent.fromLegacyText("§cYou are already connected to " + Config.serverName + "!"));
Main.log("connect", f" + player.getName() + "§c was disconnected because there was already a connection for this account to the server.");
Main.log("connect", "§f" + player.getName() + "§c was disconnected because there was already a connection for this account to the server.");
}
} else {
// Send full message
Expand All @@ -311,7 +319,7 @@ public void onPlayerDisconnect(PlayerDisconnectEvent event) {
// Remove Player from queue
try {
mutex.acquire();
Main.log("disconnect", f" + player.getName() + "§3 was removed from the §dplayer queue§3. Queue count is " + playerQueue.size() + ".");
Main.log("disconnect", "§f" + player.getName() + "§3 was removed from the §dplayer queue§3. Queue count is " + playerQueue.size() + ".");
playerQueue.remove(player);
} catch (InterruptedException e1) {
e1.printStackTrace();
Expand All @@ -322,7 +330,30 @@ public void onPlayerDisconnect(PlayerDisconnectEvent event) {
}

/**
* Test a Server Connection
* Sends a title and a subtitle message to the player.
*
* @param title Title text
* @param subtitle Subtitle text
* @param fadeIn Time in ticks for titles to fade in. Defaults to 10.
* @param stay Time in ticks for titles to stay. Defaults to 70.
* @param fadeOut Time in ticks for titles to fade out. Defaults to 20.
*/
public void sendTitle(ProxiedPlayer player, String title, String subtitle, int fadeIn, int stay, int fadeOut) {
try {
Title bungeeTitle = Main.getInstance().getProxy().createTitle();
bungeeTitle.title(TextComponent.fromLegacyText(title));
bungeeTitle.subTitle(TextComponent.fromLegacyText(subtitle));
bungeeTitle.fadeIn(fadeIn);
bungeeTitle.stay(stay);
bungeeTitle.fadeOut(fadeOut);
player.sendTitle(bungeeTitle);
} catch (Exception e) {
Main.log("sendTitle", "§cCould not send title to §f" + player.getName() + "§c: " + e.getMessage());
}
}

/**
* Test a Server Connection and return the server ping info
*/
private static class ServerInfoGetter implements Callback<ServerPing> {
public boolean done = false;
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ serverName: "the server"
kickPassthrough: true
kickOnRestart: false
kickOnBusy: false
bStats: true
bStats: true
sendTitle: true

0 comments on commit ea70f5f

Please sign in to comment.