001/* 002 * PlotSquared, a land and world management plugin for Minecraft. 003 * Copyright (C) IntellectualSites <https://intellectualsites.com> 004 * Copyright (C) IntellectualSites team and contributors 005 * 006 * This program is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with this program. If not, see <https://www.gnu.org/licenses/>. 018 */ 019package com.plotsquared.core.command; 020 021import com.google.inject.Inject; 022import com.plotsquared.core.configuration.Settings; 023import com.plotsquared.core.configuration.caption.TranslatableCaption; 024import com.plotsquared.core.events.PlotFlagRemoveEvent; 025import com.plotsquared.core.events.Result; 026import com.plotsquared.core.permissions.Permission; 027import com.plotsquared.core.player.PlotPlayer; 028import com.plotsquared.core.plot.Plot; 029import com.plotsquared.core.plot.flag.PlotFlag; 030import com.plotsquared.core.plot.flag.implementations.DoneFlag; 031import com.plotsquared.core.util.EventDispatcher; 032import net.kyori.adventure.text.Component; 033import net.kyori.adventure.text.minimessage.tag.Tag; 034import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; 035import org.checkerframework.checker.nullness.qual.NonNull; 036 037@CommandDeclaration(command = "continue", 038 permission = "plots.continue", 039 category = CommandCategory.SETTINGS, 040 requiredType = RequiredType.PLAYER) 041public class Continue extends SubCommand { 042 043 private final EventDispatcher eventDispatcher; 044 045 @Inject 046 public Continue(final @NonNull EventDispatcher eventDispatcher) { 047 this.eventDispatcher = eventDispatcher; 048 } 049 050 @Override 051 public boolean onCommand(PlotPlayer<?> player, String[] args) { 052 Plot plot = player.getCurrentPlot(); 053 if ((plot == null) || !plot.hasOwner()) { 054 player.sendMessage(TranslatableCaption.of("errors.not_in_plot")); 055 return false; 056 } 057 if (!plot.isOwner(player.getUUID()) && !player.hasPermission(Permission.PERMISSION_ADMIN_COMMAND_CONTINUE)) { 058 player.sendMessage( 059 TranslatableCaption.of("permission.no_permission"), 060 TagResolver.resolver("node", Tag.inserting( 061 TranslatableCaption.of("permission.no_plot_perms").toComponent(player) 062 )) 063 ); 064 return false; 065 } 066 if (!DoneFlag.isDone(plot)) { 067 player.sendMessage(TranslatableCaption.of("done.done_not_done")); 068 return false; 069 } 070 int size = plot.getConnectedPlots().size(); 071 if (!Settings.Done.COUNTS_TOWARDS_LIMIT && (player.getAllowedPlots() 072 < player.getPlotCount() + size)) { 073 player.sendMessage( 074 TranslatableCaption.of("permission.cant_claim_more_plots"), 075 TagResolver.resolver("amount", Tag.inserting(Component.text(player.getAllowedPlots()))) 076 ); 077 return false; 078 } 079 if (plot.getRunning() > 0) { 080 player.sendMessage(TranslatableCaption.of("errors.wait_for_timer")); 081 return false; 082 } 083 PlotFlag<?, ?> plotFlag = plot.getFlagContainer().getFlag(DoneFlag.class); 084 PlotFlagRemoveEvent event = 085 this.eventDispatcher.callFlagRemove(plotFlag, plot); 086 if (event.getEventResult() == Result.DENY) { 087 player.sendMessage( 088 TranslatableCaption.of("events.event_denied"), 089 TagResolver.resolver("value", Tag.inserting(Component.text("Done flag removal"))) 090 ); 091 return true; 092 } 093 plot.removeFlag(event.getFlag()); 094 player.sendMessage(TranslatableCaption.of("done.done_removed")); 095 return true; 096 } 097 098}