fix(velocity): Implement ignoreSignedPlayer configuration

Workaround for #48
This commit is contained in:
Adrian3d04 2022-08-13 21:47:26 +00:00
parent 97b9bcd87a
commit 0d8630452f
2 changed files with 44 additions and 13 deletions

View File

@ -47,8 +47,7 @@ public class ProxyConfiguration {
Selection Mode of the player's initial server
TO_FIRST | Send to the first valid server configured
TO_EMPTIEST_SERVER | Send to the server with the lowest number of players
RANDOM | Send to a random server
""")
RANDOM | Send to a random server""")
private SendMode sendMode = SendMode.RANDOM;
public SendMode sendMode() {
return this.sendMode;
@ -65,8 +64,7 @@ public class ProxyConfiguration {
@Comment("""
List of servers to send
One of these servers will be chosen at random
""")
One of these servers will be chosen at random""")
private List<String> teleportServers = List.of("lobby1", "lobby2");
public List<String> teleportServers() {
return this.teleportServers;
@ -76,8 +74,7 @@ public class ProxyConfiguration {
Selection Mode of the server to which the player will be sent
TO_FIRST | Send to the first valid server configured
TO_EMPTIEST_SERVER | Send to the server with the lowest number of players
RANDOM | Send to a random server
""")
RANDOM | Send to a random server""")
private SendMode sendMode = SendMode.RANDOM;
public SendMode sendMode() {
return this.sendMode;
@ -94,8 +91,7 @@ public class ProxyConfiguration {
@Comment("""
Sets the message to send in case a non-logged-in player executes an unauthorized command
To deactivate the message, leave it empty
""")
To deactivate the message, leave it empty""")
private String blockedMessage = "<red>You cannot execute commands if you are not logged in yet";
public String blockedCommandMessage() {
return this.blockedMessage;
@ -115,6 +111,16 @@ public class ProxyConfiguration {
public int randomAttempts() {
return this.randomAttempts;
}
@Comment("""
Ignore blocking of commands and chat messages to 1.19.1 clients with a valid signed key
When trying to block these executions, the proxy will kick the player out.
This option allows you to prevent the plugin from trying to block these executions,
avoiding the player to be kicked out""")
private boolean ignoreSignedPlayers = false;
public boolean ignoreSignedPlayers() {
return this.ignoreSignedPlayers;
}
}

View File

@ -10,6 +10,7 @@ import com.velocitypowered.api.event.command.CommandExecuteEvent;
import com.velocitypowered.api.event.connection.DisconnectEvent;
import com.velocitypowered.api.event.player.PlayerChatEvent;
import com.velocitypowered.api.event.player.TabCompleteEvent;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.proxy.Player;
import net.kyori.adventure.text.minimessage.MiniMessage;
@ -35,7 +36,13 @@ public final class ProxyListener {
}
if (plugin.isLogged(player)) {
plugin.logDebug("CommandExecuteEvent | Player is not logged");
plugin.logDebug("CommandExecuteEvent | Player is already logged");
continuation.resume();
return;
}
if (canBeIgnored(player)) {
plugin.logDebug("CommandexecuteEvent | Ignored signed player");
continuation.resume();
return;
}
@ -57,11 +64,23 @@ public final class ProxyListener {
}
@Subscribe(order = PostOrder.FIRST)
public void onPlayerChat(final PlayerChatEvent event) {
if (plugin.isNotLogged(event.getPlayer())) {
plugin.logDebug("PlayerChatEvent | Player is not logged");
event.setResult(PlayerChatEvent.ChatResult.denied());
public void onPlayerChat(final PlayerChatEvent event, Continuation continuation) {
if (plugin.isLogged(event.getPlayer())) {
plugin.logDebug("PlayerChatEvent | Player is already logged");
continuation.resume();
return;
}
plugin.logDebug("PlayerChatEvent | Player is not logged");
if (canBeIgnored(event.getPlayer())) {
plugin.logDebug("PlayerChatEvent | Ignored signed player");
continuation.resume();
return;
}
event.setResult(PlayerChatEvent.ChatResult.denied());
continuation.resume();
}
@Subscribe(order = PostOrder.FIRST)
@ -88,5 +107,11 @@ public final class ProxyListener {
player.sendMessage(MiniMessage.miniMessage().deserialize(blockedMessage));
}
}
boolean canBeIgnored(Player player) {
return player.getIdentifiedKey() != null
&& player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19_1) >= 0
&& plugin.config().get().advanced().ignoreSignedPlayers();
}
}