2019-01-19 16:52:04 +01:00
|
|
|
package world.bentobox.greenhouses.ui.user;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
|
|
|
import world.bentobox.bentobox.api.user.User;
|
2019-01-26 20:10:30 +01:00
|
|
|
import world.bentobox.greenhouses.Greenhouses;
|
2019-01-19 16:52:04 +01:00
|
|
|
|
|
|
|
/**
|
2019-01-26 20:10:30 +01:00
|
|
|
* Command to remove a greenhouse
|
2019-01-19 16:52:04 +01:00
|
|
|
* @author tastybento
|
|
|
|
*
|
|
|
|
*/
|
2019-01-26 17:38:13 +01:00
|
|
|
class RemoveCommand extends CompositeCommand {
|
2019-01-19 16:52:04 +01:00
|
|
|
|
|
|
|
/**
|
2019-01-26 17:38:13 +01:00
|
|
|
* @param parent - parent command
|
2019-01-19 16:52:04 +01:00
|
|
|
*/
|
|
|
|
public RemoveCommand(CompositeCommand parent) {
|
2019-01-26 20:10:30 +01:00
|
|
|
super(parent, "remove");
|
2019-01-19 16:52:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see world.bentobox.bentobox.api.commands.BentoBoxCommand#setup()
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void setup() {
|
2019-01-26 20:10:30 +01:00
|
|
|
this.setPermission("greenhouses.player");
|
|
|
|
this.setOnlyPlayer(true);
|
|
|
|
this.setDescription("greenhouses.commands.user.remove.description");
|
2019-01-19 16:52:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see world.bentobox.bentobox.api.commands.BentoBoxCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public boolean execute(User user, String label, List<String> args) {
|
2019-01-26 20:10:30 +01:00
|
|
|
// Check flag
|
|
|
|
if (!getIslands().getIslandAt(user.getLocation()).map(i -> i.isAllowed(user, Greenhouses.GREENHOUSES)).orElse(false)) {
|
|
|
|
user.sendMessage("greenhouses.errors.no-rank");
|
|
|
|
return false;
|
|
|
|
}
|
2021-08-01 08:10:07 +02:00
|
|
|
Greenhouses addon = this.getAddon();
|
2019-01-26 20:10:30 +01:00
|
|
|
// Remove greenhouse if it exists
|
|
|
|
if (!addon.getManager().getMap().getGreenhouse(user.getLocation()).map(gh -> {
|
|
|
|
user.sendMessage("general.success");
|
|
|
|
addon.getManager().removeGreenhouse(gh);
|
|
|
|
return true;
|
|
|
|
}).orElse(false)) {
|
|
|
|
user.sendMessage("greenhouses.errors.not-inside");
|
|
|
|
return false;
|
|
|
|
}
|
2019-01-19 16:52:04 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|