All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.plotsquared.core.command.Dislike Maven / Gradle / Ivy

There is a newer version: 7.4.1
Show newest version
/*
 * PlotSquared, a land and world management plugin for Minecraft.
 * Copyright (C) IntellectualSites 
 * Copyright (C) IntellectualSites team and contributors
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see .
 */
package com.plotsquared.core.command;

import com.google.inject.Inject;
import com.plotsquared.core.permissions.Permission;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.util.TabCompletions;
import org.checkerframework.checker.nullness.qual.NonNull;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

@CommandDeclaration(command = "dislike",
        permission = "plots.dislike",
        usage = "/plot dislike [next|purge]",
        category = CommandCategory.INFO,
        requiredType = RequiredType.PLAYER)
public class Dislike extends SubCommand {

    private final Like like;

    @Inject
    public Dislike(final @NonNull Like like) {
        this.like = like;
    }

    @Override
    public boolean onCommand(PlotPlayer player, String[] args) {
        return this.like.handleLike(player, args, false);
    }

    @Override
    public Collection tab(final PlotPlayer player, final String[] args, final boolean space) {
        if (args.length == 1) {
            final List completions = new LinkedList<>();
            if (player.hasPermission(Permission.PERMISSION_ADMIN_COMMAND_PURGE_RATINGS)) {
                completions.add("purge");
            }
            final List commands = completions.stream().filter(completion -> completion
                            .toLowerCase()
                            .startsWith(args[0].toLowerCase()))
                    .map(completion -> new Command(null, true, completion, "", RequiredType.PLAYER, CommandCategory.INFO) {
                    }).collect(Collectors.toCollection(LinkedList::new));
            if (player.hasPermission(Permission.PERMISSION_RATE) && args[0].length() > 0) {
                commands.addAll(TabCompletions.completePlayers(player, args[0], Collections.emptyList()));
            }
            return commands;
        }
        return TabCompletions.completePlayers(player, String.join(",", args).trim(), Collections.emptyList());
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy