PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Download.java

72 lines
3.1 KiB
Java
Raw Normal View History

package com.intellectualcrafters.plot.commands;
2015-07-30 16:25:16 +02:00
import java.net.URL;
import com.intellectualcrafters.jnbt.CompoundTag;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
2015-08-28 01:50:44 +02:00
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.MainUtil;
2015-07-24 19:37:39 +02:00
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.TaskManager;
2015-07-27 19:50:04 +02:00
import com.plotsquared.general.commands.CommandDeclaration;
2015-09-13 06:04:31 +02:00
@CommandDeclaration(command = "download", aliases = { "dl" }, category = CommandCategory.ACTIONS, requiredType = RequiredType.NONE, description = "Download your plot", permission = "plots.download")
public class Download extends SubCommand {
@Override
2015-09-13 06:04:31 +02:00
public boolean onCommand(final PlotPlayer plr, final String[] args) {
if (!Settings.METRICS) {
MainUtil.sendMessage(plr, "&cPlease enable metrics in order to use this command.\n&7 - Or host it yourself if you don't like the free service");
return false;
}
final String world = plr.getLocation().getWorld();
2015-09-13 06:04:31 +02:00
if (!PS.get().isPlotWorld(world)) {
return !sendMessage(plr, C.NOT_IN_PLOT_WORLD);
}
2015-09-22 15:23:28 +02:00
final Plot plot = MainUtil.getPlotAbs(plr.getLocation());
2015-09-13 06:04:31 +02:00
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if (!plot.hasOwner()) {
2015-07-24 19:37:39 +02:00
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
return false;
}
2015-09-13 06:04:31 +02:00
if ((!plot.isOwner(plr.getUUID()) || (Settings.DOWNLOAD_REQUIRES_DONE && (FlagManager.getPlotFlag(plot, "done") != null))) && !Permissions.hasPermission(plr, "plots.admin.command.download")) {
2015-07-24 19:37:39 +02:00
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
2015-09-22 15:23:28 +02:00
if (plot.getRunning() > 0) {
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false;
}
MainUtil.runners.put(plot, 1);
MainUtil.sendMessage(plr, C.GENERATING_LINK);
2015-09-13 06:04:31 +02:00
SchematicHandler.manager.getCompoundTag(plot.world, plot.id, new RunnableVal<CompoundTag>() {
@Override
2015-09-13 06:04:31 +02:00
public void run() {
TaskManager.runTaskAsync(new Runnable() {
@Override
2015-09-13 06:04:31 +02:00
public void run() {
2015-09-11 12:09:22 +02:00
final URL url = SchematicHandler.manager.upload(value, null, null);
2015-09-13 06:04:31 +02:00
if (url == null) {
MainUtil.sendMessage(plr, C.GENERATING_LINK_FAILED);
MainUtil.runners.remove(plot);
return;
}
MainUtil.sendMessage(plr, url.toString());
MainUtil.runners.remove(plot);
}
});
}
});
return true;
}
}