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.minimessage.Template; 033import org.checkerframework.checker.nullness.qual.NonNull; 034 035@CommandDeclaration(command = "continue", 036 permission = "plots.continue", 037 category = CommandCategory.SETTINGS, 038 requiredType = RequiredType.PLAYER) 039public class Continue extends SubCommand { 040 041 private final EventDispatcher eventDispatcher; 042 043 @Inject 044 public Continue(final @NonNull EventDispatcher eventDispatcher) { 045 this.eventDispatcher = eventDispatcher; 046 } 047 048 @Override 049 public boolean onCommand(PlotPlayer<?> player, String[] args) { 050 Plot plot = player.getCurrentPlot(); 051 if ((plot == null) || !plot.hasOwner()) { 052 player.sendMessage(TranslatableCaption.of("errors.not_in_plot")); 053 return false; 054 } 055 if (!plot.isOwner(player.getUUID()) && !player.hasPermission(Permission.PERMISSION_ADMIN_COMMAND_CONTINUE)) { 056 player.sendMessage( 057 TranslatableCaption.of("permission.no_permission"), 058 Template.of("node", TranslatableCaption.of("permission.no_plot_perms").getComponent(player)) 059 ); 060 return false; 061 } 062 if (!DoneFlag.isDone(plot)) { 063 player.sendMessage(TranslatableCaption.of("done.done_not_done")); 064 return false; 065 } 066 int size = plot.getConnectedPlots().size(); 067 if (!Settings.Done.COUNTS_TOWARDS_LIMIT && (player.getAllowedPlots() 068 < player.getPlotCount() + size)) { 069 player.sendMessage( 070 TranslatableCaption.of("permission.cant_claim_more_plots"), 071 Template.of("amount", String.valueOf(player.getAllowedPlots())) 072 ); 073 return false; 074 } 075 if (plot.getRunning() > 0) { 076 player.sendMessage(TranslatableCaption.of("errors.wait_for_timer")); 077 return false; 078 } 079 PlotFlag<?, ?> plotFlag = plot.getFlagContainer().getFlag(DoneFlag.class); 080 PlotFlagRemoveEvent event = 081 this.eventDispatcher.callFlagRemove(plotFlag, plot); 082 if (event.getEventResult() == Result.DENY) { 083 player.sendMessage( 084 TranslatableCaption.of("events.event_denied"), 085 Template.of("value", "Done flag removal") 086 ); 087 return true; 088 } 089 plot.removeFlag(event.getFlag()); 090 player.sendMessage(TranslatableCaption.of("done.done_removed")); 091 return true; 092 } 093 094}