Merge bedrock packet checks into a single function

Floodgate and Geyser specific checks can now be modified without
changing JoinManagement.
Added the ability to resume Java specific checks for Bedrock players.
This will be neccessary for Geyser `auth-type=online` players
This commit is contained in:
Smart123s
2021-10-24 16:23:07 +02:00
committed by games647
parent af0bc34255
commit 2ac638f3f9
4 changed files with 20 additions and 9 deletions

View File

@ -48,6 +48,15 @@ public abstract class BedrockService<B> {
this.allowConflict = core.getConfig().get("allowFloodgateNameConflict").toString().toLowerCase();
}
/**
* Perfrom every packet level check needed on a Bedrock player.
*
* @param username the name of the player
* @param source an instance of LoginSource
* @return true if Java specific checks can be skipped
*/
public abstract boolean performChecks(String username, LoginSource source);
/**
* Check if the player's name conflicts an existing Java player's name, and kick
* them if it does
@ -55,7 +64,7 @@ public abstract class BedrockService<B> {
* @param username the name of the player
* @param source an instance of LoginSource
*/
public void checkNameConflict(String username, LoginSource source) {
protected void checkNameConflict(String username, LoginSource source) {
// check for conflicting Premium Java name
Optional<Profile> premiumUUID = Optional.empty();
try {
@ -81,7 +90,6 @@ public abstract class BedrockService<B> {
core.getPlugin().getLog().error("Could not kick Player {}", username, ex);
}
}
}
/**

View File

@ -76,7 +76,7 @@ public class FloodgateService extends BedrockService<FloodgatePlayer> {
}
@Override
public void checkNameConflict(String username, LoginSource source) {
public boolean performChecks(String username, LoginSource source) {
// check if the Bedrock player is linked to a Java account
FloodgatePlayer floodgatePlayer = getBedrockPlayer(username);
boolean isLinked = floodgatePlayer.getLinkedPlayer() != null;
@ -87,6 +87,9 @@ public class FloodgateService extends BedrockService<FloodgatePlayer> {
} else {
core.getPlugin().getLog().info("Skipping name conflict checking for player {}", username);
}
//Floodgate users don't need Java specific checks
return true;
}
/**

View File

@ -45,13 +45,14 @@ public class GeyserService extends BedrockService<GeyserSession> {
}
@Override
public void checkNameConflict(String username, LoginSource source) {
//TODO: Replace stub with Geyser specific code
public boolean performChecks(String username, LoginSource source) {
//TODO: Replace stub with Geyser specific code
if ("false".equals(allowConflict)) {
super.checkNameConflict(username, source);
} else {
core.getPlugin().getLog().info("Skipping name conflict checking for player {}", username);
}
return true;
}
@Override

View File

@ -56,10 +56,9 @@ public abstract class JoinManagement<P extends C, C, S extends LoginSource> {
}
//check if the player is connecting through Bedrock Edition
if (bedrockService != null) {
if (bedrockService.isBedrockConnection(username)) {
bedrockService.checkNameConflict(username, source);
// skip flow for any Bedrock player
if (bedrockService != null && bedrockService.isBedrockConnection(username)) {
//perform Bedrock specific checks and skip Java checks, if they are not needed
if (bedrockService.performChecks(username, source)) {
return;
}
}