mirror of
https://github.com/TotalFreedomMC/TF-PlotSquared.git
synced 2025-08-06 04:23:26 +00:00
cleanup
This commit is contained in:
parent
37a8861fa0
commit
c386f33df8
380 changed files with 43490 additions and 33913 deletions
|
@ -23,7 +23,6 @@ package com.intellectualcrafters.plot.commands;
|
|||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
|
@ -32,7 +31,6 @@ import com.intellectualcrafters.plot.config.Settings;
|
|||
import com.intellectualcrafters.plot.object.ConsolePlayer;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
@ -45,93 +43,107 @@ import com.plotsquared.general.commands.CommandDeclaration;
|
|||
// TODO Add sub-subcommands
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "schematic",
|
||||
permission = "plots.schematic",
|
||||
description = "Schematic command",
|
||||
aliases = {"sch"},
|
||||
category = CommandCategory.ACTIONS,
|
||||
usage = "/plot schematic <arg...>"
|
||||
)
|
||||
public class SchematicCmd extends SubCommand {
|
||||
command = "schematic",
|
||||
permission = "plots.schematic",
|
||||
description = "Schematic command",
|
||||
aliases = { "sch" },
|
||||
category = CommandCategory.ACTIONS,
|
||||
usage = "/plot schematic <arg...>")
|
||||
public class SchematicCmd extends SubCommand
|
||||
{
|
||||
|
||||
private int counter = 0;
|
||||
private boolean running = false;
|
||||
private int task;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer plr, final String ... args) {
|
||||
if (args.length < 1) {
|
||||
public boolean onCommand(final PlotPlayer plr, final String... args)
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
|
||||
return true;
|
||||
}
|
||||
final String arg = args[0].toLowerCase();
|
||||
final String file;
|
||||
final Schematic schematic;
|
||||
switch (arg) {
|
||||
case "paste": {
|
||||
if (!Permissions.hasPermission(plr, "plots.schematic.paste")) {
|
||||
switch (arg)
|
||||
{
|
||||
case "paste":
|
||||
{
|
||||
if (!Permissions.hasPermission(plr, "plots.schematic.paste"))
|
||||
{
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.paste");
|
||||
return false;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
if (args.length < 2)
|
||||
{
|
||||
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
|
||||
break;
|
||||
}
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
if (!plot.hasOwner()) {
|
||||
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
|
||||
if (!plot.hasOwner())
|
||||
{
|
||||
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.schematic.paste")) {
|
||||
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.schematic.paste"))
|
||||
{
|
||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
return false;
|
||||
}
|
||||
if (this.running) {
|
||||
if (running)
|
||||
{
|
||||
MainUtil.sendMessage(plr, "&cTask is already running.");
|
||||
return false;
|
||||
}
|
||||
final String location = args[1];
|
||||
this.running = true;
|
||||
this.counter = 0;
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
running = true;
|
||||
TaskManager.runTaskAsync(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run() {
|
||||
public void run()
|
||||
{
|
||||
Schematic schematic;
|
||||
if (location.startsWith("url:")) {
|
||||
try {
|
||||
UUID uuid = UUID.fromString(location.substring(4));
|
||||
URL base = new URL(Settings.WEB_URL);
|
||||
URL url = new URL(base, "uploads/" + uuid + ".schematic");
|
||||
if (location.startsWith("url:"))
|
||||
{
|
||||
try
|
||||
{
|
||||
final UUID uuid = UUID.fromString(location.substring(4));
|
||||
final URL base = new URL(Settings.WEB_URL);
|
||||
final URL url = new URL(base, "uploads/" + uuid + ".schematic");
|
||||
schematic = SchematicHandler.manager.getSchematic(url);
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (final Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent url: " + location);
|
||||
SchematicCmd.this.running = false;
|
||||
running = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
schematic = SchematicHandler.manager.getSchematic(location);
|
||||
}
|
||||
if (schematic == null) {
|
||||
SchematicCmd.this.running = false;
|
||||
if (schematic == null)
|
||||
{
|
||||
running = false;
|
||||
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent or not in gzip format");
|
||||
return;
|
||||
}
|
||||
SchematicHandler.manager.paste(schematic, plot, 0, 0, new RunnableVal<Boolean>() {
|
||||
SchematicHandler.manager.paste(schematic, plot, 0, 0, new RunnableVal<Boolean>()
|
||||
{
|
||||
@Override
|
||||
public void run() {
|
||||
SchematicCmd.this.running = false;
|
||||
if (this.value) {
|
||||
public void run()
|
||||
{
|
||||
running = false;
|
||||
if (value)
|
||||
{
|
||||
sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
sendMessage(plr, C.SCHEMATIC_PASTE_FAILED);
|
||||
}
|
||||
}
|
||||
|
@ -140,31 +152,37 @@ public class SchematicCmd extends SubCommand {
|
|||
});
|
||||
break;
|
||||
}
|
||||
case "test": {
|
||||
if (!Permissions.hasPermission(plr, "plots.schematic.test")) {
|
||||
case "test":
|
||||
{
|
||||
if (!Permissions.hasPermission(plr, "plots.schematic.test"))
|
||||
{
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.test");
|
||||
return false;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
if (args.length < 2)
|
||||
{
|
||||
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
|
||||
return false;
|
||||
}
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
if (plot == null)
|
||||
{
|
||||
sendMessage(plr, C.NOT_IN_PLOT);
|
||||
return false;
|
||||
}
|
||||
file = args[1];
|
||||
schematic = SchematicHandler.manager.getSchematic(file);
|
||||
if (schematic == null) {
|
||||
if (schematic == null)
|
||||
{
|
||||
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent");
|
||||
return false;
|
||||
}
|
||||
final int l1 = schematic.getSchematicDimension().getX();
|
||||
final int l2 = schematic.getSchematicDimension().getZ();
|
||||
final int length = MainUtil.getPlotWidth(loc.getWorld(), plot.id);
|
||||
if ((l1 < length) || (l2 < length)) {
|
||||
if ((l1 < length) || (l2 < length))
|
||||
{
|
||||
sendMessage(plr, C.SCHEMATIC_INVALID, String.format("Wrong size (x: %s, z: %d) vs %d ", l1, l2, length));
|
||||
break;
|
||||
}
|
||||
|
@ -172,82 +190,97 @@ public class SchematicCmd extends SubCommand {
|
|||
break;
|
||||
}
|
||||
case "saveall":
|
||||
case "exportall": {
|
||||
if (!ConsolePlayer.isConsole(plr)) {
|
||||
case "exportall":
|
||||
{
|
||||
if (!ConsolePlayer.isConsole(plr))
|
||||
{
|
||||
MainUtil.sendMessage(plr, C.NOT_CONSOLE);
|
||||
return false;
|
||||
}
|
||||
if (args.length != 2) {
|
||||
if (args.length != 2)
|
||||
{
|
||||
MainUtil.sendMessage(null, "&cNeed world arg. Use &7/plots sch exportall <world>");
|
||||
return false;
|
||||
}
|
||||
Collection<Plot> plots = PS.get().getPlotsInWorld(args[1]);
|
||||
if ((plots.size() == 0)) {
|
||||
final Collection<Plot> plots = PS.get().getPlotsInWorld(args[1]);
|
||||
if ((plots.size() == 0))
|
||||
{
|
||||
MainUtil.sendMessage(plr, "&cInvalid world. Use &7/plots sch exportall <world>");
|
||||
return false;
|
||||
}
|
||||
boolean result = SchematicHandler.manager.exportAll(plots, null, null, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.sendMessage(plr, "&aFinished mass export");
|
||||
}
|
||||
});
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(plr, "&cTask is already running.");
|
||||
final boolean result = SchematicHandler.manager.exportAll(plots, null, null, new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
MainUtil.sendMessage(plr, "&aFinished mass export");
|
||||
}
|
||||
});
|
||||
if (!result)
|
||||
{
|
||||
MainUtil.sendMessage(plr, "&cTask is already running.");
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
MainUtil.sendMessage(plr, "&3PlotSquared&8->&3Schemaitc&8: &7Mass export has started. This may take a while.");
|
||||
MainUtil.sendMessage(plr, "&3PlotSquared&8->&3Schemaitc&8: &7Found &c" + plots.size() + "&7 plots...");
|
||||
else
|
||||
{
|
||||
MainUtil.sendMessage(plr, "&3PlotSquared&8->&3Schemaitc&8: &7Mass export has started. This may take a while.");
|
||||
MainUtil.sendMessage(plr, "&3PlotSquared&8->&3Schemaitc&8: &7Found &c" + plots.size() + "&7 plots...");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "export":
|
||||
case "save": {
|
||||
if (!Permissions.hasPermission(plr, "plots.schematic.save")) {
|
||||
case "save":
|
||||
{
|
||||
if (!Permissions.hasPermission(plr, "plots.schematic.save"))
|
||||
{
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.save");
|
||||
return false;
|
||||
}
|
||||
if (this.running) {
|
||||
if (running)
|
||||
{
|
||||
MainUtil.sendMessage(plr, "&cTask is already running.");
|
||||
return false;
|
||||
}
|
||||
final String world;
|
||||
final Plot p2;
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
if (!plot.hasOwner()) {
|
||||
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
|
||||
if (!plot.hasOwner())
|
||||
{
|
||||
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.schematic.save")) {
|
||||
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.schematic.save"))
|
||||
{
|
||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
return false;
|
||||
}
|
||||
p2 = plot;
|
||||
world = loc.getWorld();
|
||||
Collection<Plot> plots = new ArrayList<Plot>();
|
||||
loc.getWorld();
|
||||
final Collection<Plot> plots = new ArrayList<Plot>();
|
||||
plots.add(p2);
|
||||
boolean result = SchematicHandler.manager.exportAll(plots, null, null, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.sendMessage(plr, "&aFinished export");
|
||||
SchematicCmd.this.running = false;
|
||||
}
|
||||
});
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(plr, "&cTask is already running.");
|
||||
final boolean result = SchematicHandler.manager.exportAll(plots, null, null, new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
MainUtil.sendMessage(plr, "&aFinished export");
|
||||
running = false;
|
||||
}
|
||||
});
|
||||
if (!result)
|
||||
{
|
||||
MainUtil.sendMessage(plr, "&cTask is already running.");
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
MainUtil.sendMessage(plr, "&7Starting export...");
|
||||
else
|
||||
{
|
||||
MainUtil.sendMessage(plr, "&7Starting export...");
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
default:
|
||||
{
|
||||
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue