Skip to content

Commit

Permalink
Start implementing whitelist checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Erdragh committed Nov 30, 2023
1 parent 9a91b7d commit 1729132
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,24 @@

import com.mojang.authlib.GameProfile;
import dev.erdragh.astralbot.handlers.WhitelistHandler;
import net.minecraft.network.chat.Component;
import net.minecraft.server.players.PlayerList;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.net.SocketAddress;

@Mixin(PlayerList.class)
public class PlayerListMixin {
@Inject(method = "isWhiteListed", at = @At("RETURN"), cancellable = true)
private void astralbot$isWhiteListed(GameProfile profile, CallbackInfoReturnable<Boolean> cir) {
// comparing a Boolean object in a normal boolean statement may produce a NullPointerException if said Object is null
void astralbot$isWhiteListed(GameProfile profile, CallbackInfoReturnable<Boolean> cir) {
cir.setReturnValue(Boolean.TRUE.equals(cir.getReturnValue()) || WhitelistHandler.INSTANCE.checkWhitelist(profile.getId()) != null);
}

@Inject(method = "canPlayerLogin", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/chat/Component;translatable(Ljava/lang/String;)Lnet/minecraft/network/chat/MutableComponent;"), cancellable = true)
private void astralbot$returnWhiteListMessage(SocketAddress socketAddress, GameProfile gameProfile, CallbackInfoReturnable<Component> cir) {
cir.setReturnValue(Component.literal("Whitelist yourself using /link"));
}
}

0 comments on commit 1729132

Please sign in to comment.