mirror of
https://github.com/GeyserMC/Floodgate.git
synced 2025-12-19 14:59:20 +00:00
Simplified plugin message channel logic
This commit is contained in:
@@ -53,21 +53,6 @@ public final class BungeePluginMessageUtils extends PluginMessageUtils implement
|
||||
return;
|
||||
}
|
||||
|
||||
UUID targetUuid = null;
|
||||
String targetUsername = null;
|
||||
Identity targetIdentity = Identity.UNKNOWN;
|
||||
|
||||
Connection target = event.getReceiver();
|
||||
if (target instanceof ProxiedPlayer) {
|
||||
ProxiedPlayer player = (ProxiedPlayer) target;
|
||||
targetUuid = player.getUniqueId();
|
||||
targetUsername = player.getName();
|
||||
targetIdentity = Identity.PLAYER;
|
||||
|
||||
} else if (target instanceof ServerConnection) {
|
||||
targetIdentity = Identity.SERVER;
|
||||
}
|
||||
|
||||
UUID sourceUuid = null;
|
||||
String sourceUsername = null;
|
||||
Identity sourceIdentity = Identity.UNKNOWN;
|
||||
@@ -83,8 +68,9 @@ public final class BungeePluginMessageUtils extends PluginMessageUtils implement
|
||||
sourceIdentity = Identity.SERVER;
|
||||
}
|
||||
|
||||
Result result = channel.handleProxyCall(event.getData(), targetUuid, targetUsername,
|
||||
targetIdentity, sourceUuid, sourceUsername, sourceIdentity);
|
||||
Result result = channel.handleProxyCall(
|
||||
event.getData(), sourceUuid, sourceUsername, sourceIdentity
|
||||
);
|
||||
|
||||
event.setCancelled(!result.isAllowed());
|
||||
|
||||
|
||||
@@ -36,14 +36,12 @@ public interface PluginMessageChannel {
|
||||
|
||||
Result handleProxyCall(
|
||||
byte[] data,
|
||||
UUID targetUuid,
|
||||
String targetUsername,
|
||||
Identity targetIdentity,
|
||||
UUID sourceUuid,
|
||||
String sourceUsername,
|
||||
Identity sourceIdentity);
|
||||
Identity sourceIdentity
|
||||
);
|
||||
|
||||
Result handleServerCall(byte[] data, UUID targetUuid, String targetUsername);
|
||||
Result handleServerCall(byte[] data, UUID playerUuid, String playerUsername);
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
|
||||
@@ -56,13 +56,10 @@ public class FormChannel implements PluginMessageChannel {
|
||||
@Override
|
||||
public Result handleProxyCall(
|
||||
byte[] data,
|
||||
UUID targetUuid,
|
||||
String targetUsername,
|
||||
Identity targetIdentity,
|
||||
UUID sourceUuid,
|
||||
String sourceUsername,
|
||||
Identity sourceIdentity) {
|
||||
|
||||
Identity sourceIdentity
|
||||
) {
|
||||
if (sourceIdentity == Identity.SERVER) {
|
||||
// send it to the client
|
||||
return Result.forward();
|
||||
@@ -89,7 +86,7 @@ public class FormChannel implements PluginMessageChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result handleServerCall(byte[] data, UUID targetUuid, String targetUsername) {
|
||||
public Result handleServerCall(byte[] data, UUID playerUuid, String playerUsername) {
|
||||
callResponseConsumer(data);
|
||||
return Result.handled();
|
||||
}
|
||||
|
||||
@@ -40,23 +40,26 @@ public final class PacketChannel implements PluginMessageChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result handleProxyCall(byte[] data, UUID targetUuid, String targetUsername,
|
||||
Identity targetIdentity, UUID sourceUuid, String sourceUsername,
|
||||
Identity sourceIdentity) {
|
||||
public Result handleProxyCall(
|
||||
byte[] data,
|
||||
UUID sourceUuid,
|
||||
String sourceUsername,
|
||||
Identity sourceIdentity
|
||||
) {
|
||||
if (sourceIdentity == Identity.SERVER) {
|
||||
// send it to the client
|
||||
return Result.forward();
|
||||
}
|
||||
|
||||
if (sourceIdentity == Identity.PLAYER) {
|
||||
return handleServerCall(data, targetUuid, targetUsername);
|
||||
return handleServerCall(data, sourceUuid, sourceUsername);
|
||||
}
|
||||
|
||||
return Result.handled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result handleServerCall(byte[] data, UUID targetUuid, String targetUsername) {
|
||||
public Result handleServerCall(byte[] data, UUID playerUuid, String playerUsername) {
|
||||
return Result.kick("Cannot send packets from Geyser/Floodgate to Floodgate");
|
||||
}
|
||||
|
||||
|
||||
@@ -51,16 +51,13 @@ public class SkinChannel implements PluginMessageChannel {
|
||||
@Override
|
||||
public Result handleProxyCall(
|
||||
byte[] data,
|
||||
UUID targetUuid,
|
||||
String targetUsername,
|
||||
Identity targetIdentity,
|
||||
UUID sourceUuid,
|
||||
String sourceUsername,
|
||||
Identity sourceIdentity) {
|
||||
|
||||
Identity sourceIdentity
|
||||
) {
|
||||
// we can only get skins from Geyser (client)
|
||||
if (sourceIdentity == Identity.PLAYER) {
|
||||
Result result = handleServerCall(data, targetUuid, targetUsername);
|
||||
Result result = handleServerCall(data, sourceUuid, sourceUsername);
|
||||
// aka translate 'handled' into 'forward' when send-floodgate-data is enabled
|
||||
if (!result.isAllowed() && result.getReason() == null) {
|
||||
if (config.isProxy() && ((ProxyFloodgateConfig) config).isSendFloodgateData()) {
|
||||
@@ -78,8 +75,8 @@ public class SkinChannel implements PluginMessageChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result handleServerCall(byte[] data, UUID targetUuid, String targetUsername) {
|
||||
FloodgatePlayer floodgatePlayer = api.getPlayer(targetUuid);
|
||||
public Result handleServerCall(byte[] data, UUID playerUuid, String playerUsername) {
|
||||
FloodgatePlayer floodgatePlayer = api.getPlayer(playerUuid);
|
||||
if (floodgatePlayer == null) {
|
||||
return Result.kick("Player sent skins data for a non-Floodgate player");
|
||||
}
|
||||
|
||||
@@ -42,27 +42,24 @@ public class TransferChannel implements PluginMessageChannel {
|
||||
@Override
|
||||
public Result handleProxyCall(
|
||||
byte[] data,
|
||||
UUID targetUuid,
|
||||
String targetUsername,
|
||||
Identity targetIdentity,
|
||||
UUID sourceUuid,
|
||||
String sourceUsername,
|
||||
Identity sourceIdentity) {
|
||||
|
||||
Identity sourceIdentity
|
||||
) {
|
||||
if (sourceIdentity == Identity.SERVER) {
|
||||
// send it to the client
|
||||
return Result.forward();
|
||||
}
|
||||
|
||||
if (sourceIdentity == Identity.PLAYER) {
|
||||
handleServerCall(data, targetUuid, targetUsername);
|
||||
handleServerCall(data, sourceUuid, sourceUsername);
|
||||
}
|
||||
|
||||
return Result.handled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result handleServerCall(byte[] data, UUID targetUuid, String targetUsername) {
|
||||
public Result handleServerCall(byte[] data, UUID playerUuid, String playerUsername) {
|
||||
return Result.kick("I'm sorry, I'm unable to transfer a server :(");
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@ import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||
import com.velocitypowered.api.proxy.messages.ChannelMessageSink;
|
||||
import com.velocitypowered.api.proxy.messages.ChannelMessageSource;
|
||||
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||
import java.util.UUID;
|
||||
@@ -64,21 +63,6 @@ public class VelocityPluginMessageUtils extends PluginMessageUtils {
|
||||
return;
|
||||
}
|
||||
|
||||
UUID targetUuid = null;
|
||||
String targetUsername = null;
|
||||
Identity targetIdentity = Identity.UNKNOWN;
|
||||
|
||||
ChannelMessageSink target = event.getTarget();
|
||||
if (target instanceof Player) {
|
||||
Player player = (Player) target;
|
||||
targetUuid = player.getUniqueId();
|
||||
targetUsername = player.getUsername();
|
||||
targetIdentity = Identity.PLAYER;
|
||||
|
||||
} else if (target instanceof ServerConnection) {
|
||||
targetIdentity = Identity.SERVER;
|
||||
}
|
||||
|
||||
UUID sourceUuid = null;
|
||||
String sourceUsername = null;
|
||||
Identity sourceIdentity = Identity.UNKNOWN;
|
||||
@@ -94,8 +78,9 @@ public class VelocityPluginMessageUtils extends PluginMessageUtils {
|
||||
sourceIdentity = Identity.SERVER;
|
||||
}
|
||||
|
||||
Result result = channel.handleProxyCall(event.getData(), targetUuid, targetUsername,
|
||||
targetIdentity, sourceUuid, sourceUsername, sourceIdentity);
|
||||
Result result = channel.handleProxyCall(
|
||||
event.getData(), sourceUuid, sourceUsername, sourceIdentity
|
||||
);
|
||||
|
||||
event.setResult(result.isAllowed() ? ForwardResult.forward() : ForwardResult.handled());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user