Search in sources :

Example 1 with WhitelistEntry

use of net.minecraft.server.WhitelistEntry in project KahzerxMod by otakucraft.

the class ServerConfigMixin method onWhitelistAdd.

@Inject(method = "add", at = @At("RETURN"))
public void onWhitelistAdd(V entry, CallbackInfo ci) {
    if (OpOnWhitelistExtension.isExtensionEnabled && OpOnWhitelistExtension.server != null && entry instanceof WhitelistEntry) {
        try {
            JSONParser parser = new JSONParser();
            JSONObject obj = (JSONObject) parser.parse(new Gson().toJson(entry));
            Optional<GameProfile> profile = OpOnWhitelistExtension.server.getUserCache().getByUuid(UUID.fromString((String) ((JSONObject) obj.get("key")).get("id")));
            if (profile.isEmpty()) {
                return;
            }
            GameProfile gameProfile = profile.get();
            if (!OpOnWhitelistExtension.server.getPlayerManager().isOperator(gameProfile)) {
                OpOnWhitelistExtension.server.getPlayerManager().addToOperators(gameProfile);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : WhitelistEntry(net.minecraft.server.WhitelistEntry) JSONObject(org.json.simple.JSONObject) GameProfile(com.mojang.authlib.GameProfile) Gson(com.google.gson.Gson) JSONParser(org.json.simple.parser.JSONParser) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with WhitelistEntry

use of net.minecraft.server.WhitelistEntry in project KahzerxMod by otakucraft.

the class ExremoveCommand method execute.

@Override
public void execute(MessageReceivedEvent event, MinecraftServer server, String serverPrefix, DiscordWhitelistExtension extension) {
    boolean feedback = extension.getDiscordExtension().extensionSettings().isShouldFeedback();
    String[] req = event.getMessage().getContentRaw().split(" ");
    String playerName = req[1];
    if (req.length != 2) {
        event.getMessage().delete().queueAfter(2, TimeUnit.SECONDS);
        this.sendHelpCommand(serverPrefix, event.getChannel(), feedback);
        return;
    }
    Optional<GameProfile> profile = server.getUserCache().findByName(playerName);
    if (profile.isEmpty()) {
        EmbedBuilder embed = DiscordChatUtils.generateEmbed(new String[] { "**Not premium.**" }, serverPrefix, true, Color.RED, true, feedback);
        if (embed != null) {
            event.getChannel().sendMessageEmbeds(embed.build()).queue();
        }
        return;
    }
    if (!extension.canRemove(69420L, profile.get().getId().toString())) {
        EmbedBuilder embed = DiscordChatUtils.generateEmbed(new String[] { "**You can't remove " + profile.get().getName() + ".**" }, serverPrefix, true, Color.RED, true, feedback);
        if (embed != null) {
            event.getChannel().sendMessageEmbeds(embed.build()).queue();
        }
        return;
    }
    Whitelist whitelist = server.getPlayerManager().getWhitelist();
    if (!whitelist.isAllowed(profile.get())) {
        EmbedBuilder embed = DiscordChatUtils.generateEmbed(new String[] { "**" + playerName + " is not whitelisted.**" }, serverPrefix, true, Color.YELLOW, true, feedback);
        if (embed != null) {
            event.getChannel().sendMessageEmbeds(embed.build()).queue();
        }
        return;
    }
    WhitelistEntry whitelistEntry = new WhitelistEntry(profile.get());
    extension.deletePlayer(69420L, profile.get().getId().toString());
    whitelist.remove(whitelistEntry);
    ServerPlayerEntity player = server.getPlayerManager().getPlayer(profile.get().getId());
    if (player != null) {
        player.networkHandler.disconnect(new LiteralText("Byee~"));
    }
    EmbedBuilder embed = DiscordChatUtils.generateEmbed(new String[] { "**" + profile.get().getName() + " removed D:**" }, serverPrefix, true, Color.GREEN, true, feedback);
    if (embed != null) {
        event.getChannel().sendMessageEmbeds(embed.build()).queue();
    }
}
Also used : WhitelistEntry(net.minecraft.server.WhitelistEntry) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) GameProfile(com.mojang.authlib.GameProfile) Whitelist(net.minecraft.server.Whitelist) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) LiteralText(net.minecraft.text.LiteralText)

Example 3 with WhitelistEntry

use of net.minecraft.server.WhitelistEntry in project KahzerxMod by otakucraft.

the class ExaddCommand method execute.

@Override
public void execute(MessageReceivedEvent event, MinecraftServer server, String serverPrefix, DiscordWhitelistExtension extension) {
    boolean feedback = extension.getDiscordExtension().extensionSettings().isShouldFeedback();
    String[] req = event.getMessage().getContentRaw().split(" ");
    String playerName = req[1];
    if (req.length != 2) {
        event.getMessage().delete().queueAfter(2, TimeUnit.SECONDS);
        this.sendHelpCommand(serverPrefix, event.getChannel(), feedback);
        return;
    }
    Optional<GameProfile> profile = server.getUserCache().findByName(playerName);
    if (profile.isEmpty()) {
        EmbedBuilder embed = DiscordChatUtils.generateEmbed(new String[] { "**Not premium.**" }, serverPrefix, true, Color.RED, true, feedback);
        if (embed != null) {
            event.getChannel().sendMessageEmbeds(embed.build()).queue();
        }
        return;
    }
    Whitelist whitelist = server.getPlayerManager().getWhitelist();
    if (whitelist.isAllowed(profile.get())) {
        EmbedBuilder embed = DiscordChatUtils.generateEmbed(new String[] { "**" + playerName + " already whitelisted.**" }, serverPrefix, true, Color.YELLOW, true, feedback);
        if (embed != null) {
            event.getChannel().sendMessageEmbeds(embed.build()).queue();
        }
        return;
    }
    WhitelistEntry whitelistEntry = new WhitelistEntry(profile.get());
    if (extension.isPlayerBanned(profile.get().getId().toString())) {
        EmbedBuilder embed = DiscordChatUtils.generateEmbed(new String[] { "**Looks like that player is banned.**" }, serverPrefix, true, Color.RED, true, feedback);
        if (embed != null) {
            event.getChannel().sendMessageEmbeds(embed.build()).queue();
        }
        return;
    }
    if (extension.alreadyAddedBySomeone(profile.get().getId().toString())) {
        EmbedBuilder embed = DiscordChatUtils.generateEmbed(new String[] { "**Already whitelisted by someone else.**" }, serverPrefix, true, Color.RED, true, feedback);
        if (embed != null) {
            event.getChannel().sendMessageEmbeds(embed.build()).queue();
        }
        return;
    }
    extension.addPlayer(69420L, profile.get().getId().toString(), profile.get().getName());
    whitelist.add(whitelistEntry);
    EmbedBuilder embed = DiscordChatUtils.generateEmbed(new String[] { "**" + profile.get().getName() + " added :D**" }, serverPrefix, true, Color.GREEN, true, feedback);
    if (embed != null) {
        event.getChannel().sendMessageEmbeds(embed.build()).queue();
    }
}
Also used : WhitelistEntry(net.minecraft.server.WhitelistEntry) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) GameProfile(com.mojang.authlib.GameProfile) Whitelist(net.minecraft.server.Whitelist)

Example 4 with WhitelistEntry

use of net.minecraft.server.WhitelistEntry in project mc-discord-bridge by Selicre.

the class DiscordBotImpl method handleNormalDiscordCommand.

private boolean handleNormalDiscordCommand(Message message) {
    if (message.getMember() != null && message.getContentRaw().startsWith("!mcname")) {
        String[] args = message.getContentRaw().split(" ");
        if (args.length == 2) {
            Optional<GameProfile> lookupResult = server.getUserCache().findByName(args[1]);
            if (lookupResult.isEmpty()) {
                message.reply("I couldn't find a Minecraft user called `" + args[1] + "` - are you sure that it's correct?").queue();
            } else {
                GameProfile profile = lookupResult.get();
                UUID old = playerLookup.updatePlayerProfile(message.getMember(), profile);
                server.getPlayerManager().getWhitelist().add(new WhitelistEntry(profile));
                if (old == null) {
                    message.reply("Welcome, " + profile.getName() + "! You're all set up and have been added to the whitelist.").queue();
                } else if (old.equals(profile.getId())) {
                    message.reply("I already know who you are <3").queue();
                } else {
                    message.reply("I will remember that your new player profile is " + profile.getName() + ", but your old account has been forgotten.").queue();
                    server.getPlayerManager().getWhitelist().remove(new GameProfile(old, null));
                }
                try {
                    server.getPlayerManager().getWhitelist().save();
                } catch (IOException ex) {
                    LOGGER.warn("Couldn't save whitelist", ex);
                }
            }
        } else {
            message.reply("Usage: !mcname MyMinecraftUsername").queue();
        }
        return true;
    }
    return false;
}
Also used : WhitelistEntry(net.minecraft.server.WhitelistEntry) GameProfile(com.mojang.authlib.GameProfile) IOException(java.io.IOException) UUID(java.util.UUID)

Example 5 with WhitelistEntry

use of net.minecraft.server.WhitelistEntry in project MC-Server-Protection by GStefanowich.

the class ClaimCommand method invitedList.

private static int invitedList(@NotNull ServerCommandSource source, @NotNull GameProfile player) throws CommandSyntaxException {
    // Get information about the server
    MinecraftServer server = source.getServer();
    ClaimCache claimCache = ((ClaimsAccessor) server).getClaimManager();
    UserCache cache = server.getUserCache();
    Whitelist whitelist = server.getPlayerManager().getWhitelist();
    // Store information about invites
    GameProfile invitedBy = null;
    List<WhitelistEntry> invited = new ArrayList<>();
    ClaimantPlayer claim = claimCache.getPlayerClaim(player.getId());
    // Loop the whitelist
    for (WhitelistEntry entry : whitelist.values()) {
        if (entry == null)
            continue;
        UUID invitedById = ((WhitelistedPlayer) entry).getInvitedBy();
        if (invitedById != null) {
            if (player.getId().equals(((WhitelistedPlayer) entry).getUUID()))
                invitedBy = cache.getByUuid(invitedById).orElse(null);
            else if (player.getId().equals(invitedById))
                invited.add(entry);
        }
    }
    Entity entity = source.getEntity();
    boolean isPlayer = (entity instanceof PlayerEntity && player.getId().equals(entity.getUuid()));
    // Output as text
    MutableText out = null;
    if (invitedBy != null)
        out = new LiteralText("").append(new LiteralText(isPlayer ? "You" : player.getName()).formatted(Formatting.GRAY)).append(" " + (isPlayer ? "were" : "was") + " invited to the server by ").formatted(Formatting.WHITE).append(ClaimCommand.inviteeFormattedName(source, claim, invitedBy.getName(), invitedBy.getId()));
    MutableText inv = new LiteralText("").formatted(Formatting.WHITE).append(new LiteralText(isPlayer ? "You" : player.getName()).formatted(Formatting.GRAY)).append(" invited the following players [").append(MessageUtils.formatNumber(invited.size())).append("]: ").append(MessageUtils.listToTextComponent(invited, (entry) -> ClaimCommand.inviteeFormattedName(source, claim, ((WhitelistedPlayer) entry).getName(), ((WhitelistedPlayer) entry).getUUID())));
    if (out == null)
        out = inv;
    else
        out.append("\n").append(inv);
    source.sendFeedback(out, false);
    return Command.SINGLE_SUCCESS;
}
Also used : MutableText(net.minecraft.text.MutableText) MySQLStatement(net.TheElm.project.MySQL.MySQLStatement) LiteralText(net.minecraft.text.LiteralText) LiteralCommandNode(com.mojang.brigadier.tree.LiteralCommandNode) Arrays(java.util.Arrays) CommandDispatcher(com.mojang.brigadier.CommandDispatcher) FormattingUtils(net.TheElm.project.utilities.FormattingUtils) ClaimantPlayer(net.TheElm.project.protections.claiming.ClaimantPlayer) GameProfile(com.mojang.authlib.GameProfile) TranslatableText(net.minecraft.text.TranslatableText) IClaimedChunk(net.TheElm.project.interfaces.IClaimedChunk) MoneyUtils(net.TheElm.project.utilities.MoneyUtils) ClaimantTown(net.TheElm.project.protections.claiming.ClaimantTown) BlockRange(net.TheElm.project.protections.BlockRange) MinecraftServer(net.minecraft.server.MinecraftServer) EnumArgumentType(net.TheElm.project.commands.ArgumentTypes.EnumArgumentType) SoundEvents(net.minecraft.sound.SoundEvents) TranslatableServerSide(net.TheElm.project.utilities.TranslatableServerSide) ClaimsAccessor(net.TheElm.project.interfaces.ClaimsAccessor) SuggestionsBuilder(com.mojang.brigadier.suggestion.SuggestionsBuilder) Suggestions(com.mojang.brigadier.suggestion.Suggestions) EffectUtils(net.TheElm.project.utilities.EffectUtils) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ChunkOwnerUpdate(net.TheElm.project.objects.ticking.ChunkOwnerUpdate) ClaimCache(net.TheElm.project.objects.ticking.ClaimCache) Collection(java.util.Collection) Set(java.util.Set) UUID(java.util.UUID) EntityArgumentType(net.minecraft.command.argument.EntityArgumentType) Collectors(java.util.stream.Collectors) ClaimPermissions(net.TheElm.project.enums.ClaimPermissions) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) Formatting(net.minecraft.util.Formatting) List(java.util.List) Whitelist(net.minecraft.server.Whitelist) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) LogicalWorld(net.TheElm.project.interfaces.LogicalWorld) ExceptionTranslatableServerSide(net.TheElm.project.exceptions.ExceptionTranslatableServerSide) Text(net.minecraft.text.Text) NotNull(org.jetbrains.annotations.NotNull) IntegerArgumentType(com.mojang.brigadier.arguments.IntegerArgumentType) Claimant(net.TheElm.project.protections.claiming.Claimant) TextUtils(net.TheElm.project.utilities.text.TextUtils) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) PlayerData(net.TheElm.project.interfaces.PlayerData) Command(com.mojang.brigadier.Command) ClaimRanks(net.TheElm.project.enums.ClaimRanks) MessageType(net.minecraft.network.MessageType) ServerWorld(net.minecraft.server.world.ServerWorld) PlayerManager(net.minecraft.server.PlayerManager) VillagerTownie(net.TheElm.project.interfaces.VillagerTownie) CompletableFuture(java.util.concurrent.CompletableFuture) SimpleCommandExceptionType(com.mojang.brigadier.exceptions.SimpleCommandExceptionType) CoreMod(net.TheElm.project.CoreMod) NotEnoughMoneyException(net.TheElm.project.exceptions.NotEnoughMoneyException) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) BoolArgumentType(com.mojang.brigadier.arguments.BoolArgumentType) StringArgumentType(com.mojang.brigadier.arguments.StringArgumentType) SQLException(java.sql.SQLException) ParticleTypes(net.minecraft.particle.ParticleTypes) WarpUtils(net.TheElm.project.utilities.WarpUtils) ClickEvent(net.minecraft.text.ClickEvent) MutableText(net.minecraft.text.MutableText) OpLevels(net.TheElm.project.enums.OpLevels) Path(net.minecraft.entity.ai.pathing.Path) WhitelistEntry(net.minecraft.server.WhitelistEntry) Chunk(net.minecraft.world.chunk.Chunk) BlockPosArgumentType(net.minecraft.command.argument.BlockPosArgumentType) SoundCategory(net.minecraft.sound.SoundCategory) WhitelistedPlayer(net.TheElm.project.interfaces.WhitelistedPlayer) MessageUtils(net.TheElm.project.utilities.text.MessageUtils) ClaimSettings(net.TheElm.project.enums.ClaimSettings) Entity(net.minecraft.entity.Entity) CommandUtils(net.TheElm.project.utilities.CommandUtils) Iterator(java.util.Iterator) CommandContext(com.mojang.brigadier.context.CommandContext) World(net.minecraft.world.World) VillagerEntity(net.minecraft.entity.passive.VillagerEntity) PlayerMovement(net.TheElm.project.interfaces.PlayerMovement) CommandPredicate(net.TheElm.project.interfaces.CommandPredicate) UserCache(net.minecraft.util.UserCache) BlockPos(net.minecraft.util.math.BlockPos) CommandManager(net.minecraft.server.command.CommandManager) Texts(net.minecraft.text.Texts) WorldChunk(net.minecraft.world.chunk.WorldChunk) CommandSource(net.minecraft.command.CommandSource) SewConfig(net.TheElm.project.config.SewConfig) GameProfileArgumentType(net.minecraft.command.argument.GameProfileArgumentType) CasingUtils(net.TheElm.project.utilities.CasingUtils) ChunkUtils(net.TheElm.project.utilities.ChunkUtils) ServerCore(net.TheElm.project.ServerCore) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) WhitelistEntry(net.minecraft.server.WhitelistEntry) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) Entity(net.minecraft.entity.Entity) VillagerEntity(net.minecraft.entity.passive.VillagerEntity) ClaimsAccessor(net.TheElm.project.interfaces.ClaimsAccessor) ArrayList(java.util.ArrayList) UserCache(net.minecraft.util.UserCache) MinecraftServer(net.minecraft.server.MinecraftServer) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ClaimCache(net.TheElm.project.objects.ticking.ClaimCache) WhitelistedPlayer(net.TheElm.project.interfaces.WhitelistedPlayer) GameProfile(com.mojang.authlib.GameProfile) ClaimantPlayer(net.TheElm.project.protections.claiming.ClaimantPlayer) Whitelist(net.minecraft.server.Whitelist) UUID(java.util.UUID) LiteralText(net.minecraft.text.LiteralText)

Aggregations

GameProfile (com.mojang.authlib.GameProfile)10 WhitelistEntry (net.minecraft.server.WhitelistEntry)10 Whitelist (net.minecraft.server.Whitelist)7 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)4 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)4 LiteralText (net.minecraft.text.LiteralText)3 Gson (com.google.gson.Gson)2 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 Guild (net.dv8tion.jda.api.entities.Guild)2 Member (net.dv8tion.jda.api.entities.Member)2 Role (net.dv8tion.jda.api.entities.Role)2 HierarchyException (net.dv8tion.jda.api.exceptions.HierarchyException)2 Command (com.mojang.brigadier.Command)1 CommandDispatcher (com.mojang.brigadier.CommandDispatcher)1 BoolArgumentType (com.mojang.brigadier.arguments.BoolArgumentType)1 IntegerArgumentType (com.mojang.brigadier.arguments.IntegerArgumentType)1 StringArgumentType (com.mojang.brigadier.arguments.StringArgumentType)1 CommandContext (com.mojang.brigadier.context.CommandContext)1 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)1