2015-07-10 16:08:07 +02:00
|
|
|
package com.intellectualcrafters.plot.commands;
|
|
|
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
|
|
|
import com.intellectualcrafters.jnbt.CompoundTag;
|
|
|
|
import com.intellectualcrafters.plot.PS;
|
|
|
|
import com.intellectualcrafters.plot.config.C;
|
2015-07-12 21:08:41 +02:00
|
|
|
import com.intellectualcrafters.plot.config.Settings;
|
2015-07-10 16:08:07 +02:00
|
|
|
import com.intellectualcrafters.plot.object.Plot;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
2015-07-19 15:12:48 +02:00
|
|
|
import com.intellectualcrafters.plot.object.RunnableVal;
|
2015-07-10 16:08:07 +02:00
|
|
|
import com.intellectualcrafters.plot.util.MainUtil;
|
2015-07-24 19:37:39 +02:00
|
|
|
import com.intellectualcrafters.plot.util.Permissions;
|
2015-07-10 16:08:07 +02:00
|
|
|
import com.intellectualcrafters.plot.util.SchematicHandler;
|
|
|
|
import com.intellectualcrafters.plot.util.TaskManager;
|
2015-07-26 20:50:54 +02:00
|
|
|
import com.intellectualsites.commands.CommandDeclaration;
|
2015-07-27 06:30:50 +02:00
|
|
|
import com.intellectualsites.commands.CommandCaller;
|
2015-07-10 16:08:07 +02:00
|
|
|
|
2015-07-26 20:50:54 +02:00
|
|
|
@CommandDeclaration(
|
|
|
|
command = "download",
|
|
|
|
aliases = {"dl"},
|
|
|
|
category = CommandCategory.ACTIONS,
|
|
|
|
requiredType = PlotPlayer.class,
|
|
|
|
description = "Download your plot",
|
|
|
|
permission = "plots.download"
|
|
|
|
)
|
2015-07-10 16:08:07 +02:00
|
|
|
public class Download extends SubCommand {
|
|
|
|
|
|
|
|
@Override
|
2015-07-26 20:50:54 +02:00
|
|
|
public boolean onCommand(final CommandCaller caller, final String[] args) {
|
|
|
|
final PlotPlayer plr = (PlotPlayer) caller.getSuperCaller();
|
2015-07-12 21:08:41 +02:00
|
|
|
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;
|
|
|
|
}
|
2015-07-10 16:08:07 +02:00
|
|
|
final String world = plr.getLocation().getWorld();
|
|
|
|
if (!PS.get().isPlotWorld(world)) {
|
|
|
|
return !sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
|
|
|
}
|
|
|
|
final Plot plot = MainUtil.getPlot(plr.getLocation());
|
|
|
|
if (plot == null) {
|
|
|
|
return !sendMessage(plr, C.NOT_IN_PLOT);
|
|
|
|
}
|
2015-07-24 19:37:39 +02:00
|
|
|
if (!plot.hasOwner()) {
|
|
|
|
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.download")) {
|
|
|
|
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
|
|
|
return false;
|
|
|
|
}
|
2015-07-10 16:08:07 +02:00
|
|
|
if (MainUtil.runners.containsKey(plot)) {
|
|
|
|
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
MainUtil.runners.put(plot, 1);
|
|
|
|
MainUtil.sendMessage(plr, C.GENERATING_LINK);
|
2015-07-19 15:12:48 +02:00
|
|
|
SchematicHandler.manager.getCompoundTag(plot.world, plot.id, new RunnableVal<CompoundTag>() {
|
2015-07-10 16:08:07 +02:00
|
|
|
@Override
|
|
|
|
public void run() {
|
2015-07-19 15:12:48 +02:00
|
|
|
TaskManager.runTaskAsync(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2015-07-24 19:37:39 +02:00
|
|
|
URL url = SchematicHandler.manager.upload(value, null, null);
|
2015-07-19 15:12:48 +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);
|
|
|
|
}
|
|
|
|
});
|
2015-07-10 16:08:07 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|