PlotSquared/Core/src/main/java/com/plotsquared/core/command/Kick.java

160 lines
6.7 KiB
Java
Raw Normal View History

/*
* PlotSquared, a land and world management plugin for Minecraft.
* Copyright (C) IntellectualSites <https://intellectualsites.com>
* 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 <https://www.gnu.org/licenses/>.
*/
2020-04-15 21:26:54 +02:00
package com.plotsquared.core.command;
2014-09-30 13:17:55 +02:00
2020-07-11 17:19:19 +02:00
import com.google.inject.Inject;
2020-04-15 21:26:54 +02:00
import com.plotsquared.core.PlotSquared;
2020-07-18 15:06:51 +02:00
import com.plotsquared.core.configuration.caption.TranslatableCaption;
2020-04-15 21:26:54 +02:00
import com.plotsquared.core.database.DBFunc;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.permissions.Permission;
2020-04-15 21:26:54 +02:00
import com.plotsquared.core.player.PlotPlayer;
2020-04-30 12:33:59 +02:00
import com.plotsquared.core.plot.Plot;
2020-07-10 17:32:07 +02:00
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.PlayerManager;
import com.plotsquared.core.util.TabCompletions;
2020-04-15 21:26:54 +02:00
import com.plotsquared.core.util.WorldUtil;
import net.kyori.adventure.text.minimessage.Template;
import org.checkerframework.checker.nullness.qual.NonNull;
2016-06-24 05:19:02 +02:00
import java.util.Collection;
import java.util.Collections;
2016-05-19 10:53:07 +02:00
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
2020-05-19 23:05:36 +02:00
import java.util.concurrent.TimeoutException;
2014-12-30 14:09:11 +01:00
Pull/2693 (#2694) * Commit WIP flag work. * More ported flag types, and additions to the flag API. * Make PlotFlag more generic to allow generic flag creation * Pull Captions methods into a Caption interface. * Port MusicFlag * Port flight flag * Port UntrustedVisitFlag * Port DenyExitFlag * Remove paper suggestion * Make ListFlag lists immutable * Update Flag containers. Add javadocs. Add missing methods. * Port description flag * Port greeting and farewell flags * Port weather flag * Move getExample implementation to BooleanFlag * Port reserved flags * Port all boolean flags. * Remove unused flag types * Invert liquid-flow flag * Find the real (legacy) flag name * Change NOITFY -> NOTIFY in Captions * Make IntegerFlag extendable * Port integer flags * Update Flag command to current API state * Begin remaking flag command * Create DoubleFlag + extract common parsing stuff * Supply arguments in flag parse exceptions * Implement missing flag subcommands * Update Flag command to current API state * Implement PriceFlag * Port deny-teleport * Port gamemode flags * Port BreakFlag * Port PlaceFlag * Port UseFlag * Remove old unused flag constants * Port blocked-cmds flag * Fix entity util * Port TimeFlag * Use CaptionUtility for formatting * Port keep flag * Fix imports * Reformat code * Remove unused classes * Fix MainUtil.java * Remove FlagCmd * Add flag info header and footer * Comment out flag related stuff in SchematicHandler * Remove FlagManager * Finalize Plot.java * Finalize PlotArea.java * Finalize PlotListener * Fix API issues * Fix a bunch of compile errors * Fix `/plot flag remove` * Fix initialization of GlobalFlagContainer * Apply API changes to events * Update SQLManager to new API * Invert default value for DenyExitFlag * Replace flag.getValue().toString() with flag.toString() * Make FlagContainer instance in Plot final * Fix various command issues * Clean up PlotSettings * Don't show internal flags in flag list * Fix `/plot flag add` * Remove the info inventory as it's 100% broken * Add plot info entries and fix up the default format * Fix default flag state in Captions * 781c200 part 2 * Fix odd grammar in captions * Fix odd grammar in captions v2 * Add create table statements for plot_flags * Remove old flag references in SQLManager * Use the new plot_flags table * Add tab completion to `/plot flag` * Improve parse error handling * Make flag permission check recognize parse exceptions * Initial progress towards flag conversion * Fix minor issues * Don't validate flags during flag conversion * Allow unrecognized flags to be parsed * Filter out internal flags from command sugguestions * Use the wrong caption when there's no plot description set * Limit command suggestions for boolean flags * Make blocktypelistflags accept blockcategories * Require categories to be prefixed with '#' and fix some minor display issues * Fix plot database conversion * Update PlotFlagEvent.java Updated return description * Fix command annotation wrapping * Add FLAG_UPDATE event for FlagContainer listeners * Make getParentContainer nullable * Document castUnsafe in FlagContainer * Document FlagContainer constructors * Add missing documentation to FlagContainer * Document FlagParseException * Fix wording in FlagContainer javadoc * Document InternalFlag * Document PlotFlag * Minor changes * Remove revisit comments Co-authored-by: Hannes Greule <SirYwell@users.noreply.github.com> Co-authored-by: NotMyFault <mc.cache@web.de> Co-authored-by: Matt <4009945+MattBDev@users.noreply.github.com>
2020-02-24 18:42:02 +01:00
@CommandDeclaration(command = "kick",
aliases = "k",
permission = "plots.kick",
usage = "/plot kick <player | *>",
category = CommandCategory.TELEPORT,
requiredType = RequiredType.PLAYER)
Pull/2693 (#2694) * Commit WIP flag work. * More ported flag types, and additions to the flag API. * Make PlotFlag more generic to allow generic flag creation * Pull Captions methods into a Caption interface. * Port MusicFlag * Port flight flag * Port UntrustedVisitFlag * Port DenyExitFlag * Remove paper suggestion * Make ListFlag lists immutable * Update Flag containers. Add javadocs. Add missing methods. * Port description flag * Port greeting and farewell flags * Port weather flag * Move getExample implementation to BooleanFlag * Port reserved flags * Port all boolean flags. * Remove unused flag types * Invert liquid-flow flag * Find the real (legacy) flag name * Change NOITFY -> NOTIFY in Captions * Make IntegerFlag extendable * Port integer flags * Update Flag command to current API state * Begin remaking flag command * Create DoubleFlag + extract common parsing stuff * Supply arguments in flag parse exceptions * Implement missing flag subcommands * Update Flag command to current API state * Implement PriceFlag * Port deny-teleport * Port gamemode flags * Port BreakFlag * Port PlaceFlag * Port UseFlag * Remove old unused flag constants * Port blocked-cmds flag * Fix entity util * Port TimeFlag * Use CaptionUtility for formatting * Port keep flag * Fix imports * Reformat code * Remove unused classes * Fix MainUtil.java * Remove FlagCmd * Add flag info header and footer * Comment out flag related stuff in SchematicHandler * Remove FlagManager * Finalize Plot.java * Finalize PlotArea.java * Finalize PlotListener * Fix API issues * Fix a bunch of compile errors * Fix `/plot flag remove` * Fix initialization of GlobalFlagContainer * Apply API changes to events * Update SQLManager to new API * Invert default value for DenyExitFlag * Replace flag.getValue().toString() with flag.toString() * Make FlagContainer instance in Plot final * Fix various command issues * Clean up PlotSettings * Don't show internal flags in flag list * Fix `/plot flag add` * Remove the info inventory as it's 100% broken * Add plot info entries and fix up the default format * Fix default flag state in Captions * 781c200 part 2 * Fix odd grammar in captions * Fix odd grammar in captions v2 * Add create table statements for plot_flags * Remove old flag references in SQLManager * Use the new plot_flags table * Add tab completion to `/plot flag` * Improve parse error handling * Make flag permission check recognize parse exceptions * Initial progress towards flag conversion * Fix minor issues * Don't validate flags during flag conversion * Allow unrecognized flags to be parsed * Filter out internal flags from command sugguestions * Use the wrong caption when there's no plot description set * Limit command suggestions for boolean flags * Make blocktypelistflags accept blockcategories * Require categories to be prefixed with '#' and fix some minor display issues * Fix plot database conversion * Update PlotFlagEvent.java Updated return description * Fix command annotation wrapping * Add FLAG_UPDATE event for FlagContainer listeners * Make getParentContainer nullable * Document castUnsafe in FlagContainer * Document FlagContainer constructors * Add missing documentation to FlagContainer * Document FlagParseException * Fix wording in FlagContainer javadoc * Document InternalFlag * Document PlotFlag * Minor changes * Remove revisit comments Co-authored-by: Hannes Greule <SirYwell@users.noreply.github.com> Co-authored-by: NotMyFault <mc.cache@web.de> Co-authored-by: Matt <4009945+MattBDev@users.noreply.github.com>
2020-02-24 18:42:02 +01:00
public class Kick extends SubCommand {
2016-03-22 18:53:17 +01:00
2020-07-10 17:32:07 +02:00
private final PlotAreaManager plotAreaManager;
2020-07-11 17:19:19 +02:00
private final WorldUtil worldUtil;
2020-07-10 17:32:07 +02:00
@Inject
public Kick(
final @NonNull PlotAreaManager plotAreaManager,
final @NonNull WorldUtil worldUtil
) {
2016-03-28 23:31:40 +02:00
super(Argument.PlayerName);
2020-07-10 17:32:07 +02:00
this.plotAreaManager = plotAreaManager;
2020-07-11 17:19:19 +02:00
this.worldUtil = worldUtil;
2016-03-28 23:31:40 +02:00
}
@Override
public boolean onCommand(PlotPlayer<?> player, String[] args) {
2016-06-02 17:38:47 +02:00
Location location = player.getLocation();
Plot plot = location.getPlot();
2015-09-13 06:04:31 +02:00
if (plot == null) {
2020-07-18 15:06:51 +02:00
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
return false;
2015-09-13 06:04:31 +02:00
}
if ((!plot.hasOwner() || !plot.isOwner(player.getUUID())) && !player.hasPermission(Permission.PERMISSION_ADMIN_COMMAND_KICK)) {
player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
2014-11-05 04:42:08 +01:00
return false;
}
2020-05-19 23:05:36 +02:00
PlayerManager.getUUIDsFromString(args[0], (uuids, throwable) -> {
2020-05-19 23:05:36 +02:00
if (throwable instanceof TimeoutException) {
player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout"));
2020-05-19 23:05:36 +02:00
} else if (throwable != null || uuids.isEmpty()) {
player.sendMessage(
TranslatableCaption.of("errors.invalid_player"),
Template.of("value", args[0])
);
2020-05-19 23:05:36 +02:00
} else {
Set<PlotPlayer<?>> players = new HashSet<>();
2020-05-19 23:05:36 +02:00
for (UUID uuid : uuids) {
if (uuid == DBFunc.EVERYONE) {
for (PlotPlayer<?> pp : plot.getPlayersInPlot()) {
if (pp == player || pp.hasPermission(Permission.PERMISSION_ADMIN_ENTRY_DENIED)) {
2020-05-19 23:05:36 +02:00
continue;
}
players.add(pp);
}
2016-06-22 20:07:57 +02:00
continue;
}
PlotPlayer<?> pp = PlotSquared.platform().playerManager().getPlayerIfExists(uuid);
2020-05-19 23:05:36 +02:00
if (pp != null) {
players.add(pp);
}
2016-06-22 20:07:57 +02:00
}
2020-05-19 23:05:36 +02:00
players.remove(player); // Don't ever kick the calling player
if (players.isEmpty()) {
player.sendMessage(
TranslatableCaption.of("errors.invalid_player"),
Template.of("value", args[0])
);
2020-05-19 23:05:36 +02:00
return;
}
for (PlotPlayer<?> player2 : players) {
2020-05-19 23:05:36 +02:00
if (!plot.equals(player2.getCurrentPlot())) {
player.sendMessage(
TranslatableCaption.of("errors.invalid_player"),
Template.of("value", args[0])
);
2020-05-19 23:05:36 +02:00
return;
}
if (player2.hasPermission(Permission.PERMISSION_ADMIN_ENTRY_DENIED)) {
player.sendMessage(
TranslatableCaption.of("cluster.cannot_kick_player"),
Template.of("name", player2.getName())
);
2020-05-19 23:05:36 +02:00
return;
}
2020-07-11 17:19:19 +02:00
Location spawn = this.worldUtil.getSpawn(location.getWorldName());
player2.sendMessage(TranslatableCaption.of("kick.you_got_kicked"));
2020-05-19 23:05:36 +02:00
if (plot.equals(spawn.getPlot())) {
2020-07-11 17:19:19 +02:00
Location newSpawn = this.worldUtil.getSpawn(this.plotAreaManager.getAllWorlds()[0]);
2020-05-19 23:05:36 +02:00
if (plot.equals(newSpawn.getPlot())) {
// Kick from server if you can't be teleported to spawn
// Use string based message here for legacy uses
player2.kick("You got kicked from the plot! This server did not set up a loaded spawn, so you got " +
"kicked from the server.");
2020-05-19 23:05:36 +02:00
} else {
player2.plotkick(newSpawn);
}
} else {
player2.plotkick(spawn);
}
2016-05-19 10:53:07 +02:00
}
}
2020-05-19 23:05:36 +02:00
});
2014-11-05 04:42:08 +01:00
return true;
}
@Override
2021-05-01 18:33:02 +02:00
public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
Location location = player.getLocation();
Plot plot = location.getPlotAbs();
if (plot == null) {
return Collections.emptyList();
}
return TabCompletions.completePlayersInPlot(plot, String.join(",", args).trim(),
Collections.singletonList(player.getName())
);
}
2014-09-30 13:17:55 +02:00
}