2015-01-24 01:00:57 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
|
|
|
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
|
|
|
// /
|
|
|
|
// This program is free software; you can redistribute it and/or modify /
|
|
|
|
// it under the terms of the GNU General Public License as published by /
|
|
|
|
// the Free Software Foundation; either version 3 of the License, or /
|
|
|
|
// (at your option) any later version. /
|
|
|
|
// /
|
|
|
|
// This program is distributed in the hope that it will be useful, /
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
|
|
|
// GNU General Public License for more details. /
|
|
|
|
// /
|
|
|
|
// You should have received a copy of the GNU General Public License /
|
|
|
|
// along with this program; if not, write to the Free Software Foundation, /
|
|
|
|
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
|
|
|
// /
|
|
|
|
// You can contact us via: support@intellectualsites.com /
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
package com.intellectualcrafters.plot.commands;
|
|
|
|
|
2015-07-05 17:44:10 +02:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.PrintWriter;
|
|
|
|
import java.sql.Timestamp;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
|
2015-07-03 14:15:20 +02:00
|
|
|
import com.intellectualcrafters.plot.PS;
|
2015-06-11 02:56:53 +02:00
|
|
|
import com.intellectualcrafters.plot.config.C;
|
2015-07-03 04:11:41 +02:00
|
|
|
import com.intellectualcrafters.plot.flag.Flag;
|
2015-06-24 22:33:43 +02:00
|
|
|
import com.intellectualcrafters.plot.flag.FlagManager;
|
2015-06-07 21:37:40 +02:00
|
|
|
import com.intellectualcrafters.plot.generator.BukkitHybridUtils;
|
|
|
|
import com.intellectualcrafters.plot.generator.HybridUtils;
|
2015-07-05 17:44:10 +02:00
|
|
|
import com.intellectualcrafters.plot.object.ChunkLoc;
|
|
|
|
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
|
|
|
|
import com.intellectualcrafters.plot.object.Plot;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotAnalysis;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
|
|
|
import com.intellectualcrafters.plot.object.RunnableVal;
|
2015-02-22 07:42:52 +01:00
|
|
|
import com.intellectualcrafters.plot.util.BlockManager;
|
2015-06-07 21:37:40 +02:00
|
|
|
import com.intellectualcrafters.plot.util.ChunkManager;
|
2015-01-24 01:00:57 +01:00
|
|
|
import com.intellectualcrafters.plot.util.ExpireManager;
|
2015-02-21 12:38:44 +01:00
|
|
|
import com.intellectualcrafters.plot.util.MainUtil;
|
2015-02-20 07:28:21 +01:00
|
|
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
2015-01-24 01:00:57 +01:00
|
|
|
|
|
|
|
public class DebugExec extends SubCommand {
|
|
|
|
public DebugExec() {
|
2015-02-20 07:34:19 +01:00
|
|
|
super("debugexec", "plots.admin", "Multi-purpose debug command", "debugexec", "exec", CommandCategory.DEBUG, false);
|
2015-01-24 01:00:57 +01:00
|
|
|
}
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2015-01-24 01:00:57 +01:00
|
|
|
@Override
|
2015-02-21 08:30:55 +01:00
|
|
|
public boolean execute(final PlotPlayer player, final String... args) {
|
2015-07-03 11:30:26 +02:00
|
|
|
final List<String> allowed_params = Arrays.asList("analyze", "reset-modified", "stop-expire", "start-expire", "show-expired", "update-expired", "seen", "trim-check");
|
2015-01-24 01:00:57 +01:00
|
|
|
if (args.length > 0) {
|
2015-02-20 07:34:19 +01:00
|
|
|
final String arg = args[0].toLowerCase();
|
|
|
|
switch (arg) {
|
2015-06-26 11:46:06 +02:00
|
|
|
case "analyze": {
|
2015-07-17 18:50:32 +02:00
|
|
|
PlotAnalysis.calcOptimalModifiers(new Runnable() {
|
2015-06-28 02:54:57 +02:00
|
|
|
@Override
|
|
|
|
public void run() {
|
2015-07-17 18:50:32 +02:00
|
|
|
PS.log("&cTHIS FUNCTION IS A WORK IN PROGRESS");
|
|
|
|
PS.log("&c - ");
|
2015-06-28 02:54:57 +02:00
|
|
|
}
|
|
|
|
});
|
2015-06-26 11:46:06 +02:00
|
|
|
return true;
|
|
|
|
}
|
2015-02-20 07:34:19 +01:00
|
|
|
case "stop-expire": {
|
|
|
|
if (ExpireManager.task != -1) {
|
|
|
|
Bukkit.getScheduler().cancelTask(ExpireManager.task);
|
|
|
|
} else {
|
2015-05-08 06:54:01 +02:00
|
|
|
return MainUtil.sendMessage(player, "Task already halted");
|
2015-02-20 07:34:19 +01:00
|
|
|
}
|
|
|
|
ExpireManager.task = -1;
|
2015-05-08 06:54:01 +02:00
|
|
|
return MainUtil.sendMessage(player, "Cancelled task.");
|
2015-02-20 07:34:19 +01:00
|
|
|
}
|
2015-06-29 21:30:36 +02:00
|
|
|
case "remove-flag": {
|
|
|
|
if (args.length != 2) {
|
2015-07-12 21:08:41 +02:00
|
|
|
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot debugexec remove-flag <flag>");
|
2015-06-29 21:30:36 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
String flag = args[1];
|
2015-07-03 14:15:20 +02:00
|
|
|
for (Plot plot : PS.get().getPlots()) {
|
2015-06-29 21:30:36 +02:00
|
|
|
if (FlagManager.getPlotFlag(plot, flag) != null) {
|
|
|
|
FlagManager.removePlotFlag(plot, flag);
|
2015-06-24 22:33:43 +02:00
|
|
|
}
|
|
|
|
}
|
2015-06-29 21:30:36 +02:00
|
|
|
return MainUtil.sendMessage(player, "Cleared flag: " + flag);
|
2015-06-24 22:33:43 +02:00
|
|
|
}
|
2015-06-07 21:37:40 +02:00
|
|
|
case "start-rgar": {
|
|
|
|
if (args.length != 2) {
|
2015-07-03 14:15:20 +02:00
|
|
|
PS.log("&cInvalid syntax: /plot debugexec start-rgar <world>");
|
2015-06-07 21:37:40 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
boolean result;
|
2015-07-03 14:15:20 +02:00
|
|
|
if (!PS.get().isPlotWorld(args[1])) {
|
2015-06-11 02:56:53 +02:00
|
|
|
MainUtil.sendMessage(player, C.NOT_VALID_PLOT_WORLD, args[1]);
|
|
|
|
return false;
|
|
|
|
}
|
2015-06-07 21:37:40 +02:00
|
|
|
if (BukkitHybridUtils.regions != null) {
|
2015-06-11 02:56:53 +02:00
|
|
|
result = ((BukkitHybridUtils)(HybridUtils.manager)).scheduleRoadUpdate(args[1], BukkitHybridUtils.regions, 0);
|
2015-06-07 21:37:40 +02:00
|
|
|
}
|
|
|
|
else {
|
2015-06-11 02:56:53 +02:00
|
|
|
result = HybridUtils.manager.scheduleRoadUpdate(args[1], 0);
|
2015-06-07 21:37:40 +02:00
|
|
|
}
|
|
|
|
if (!result) {
|
2015-07-03 14:15:20 +02:00
|
|
|
PS.log("&cCannot schedule mass schematic update! (Is one already in progress?)");
|
2015-06-07 21:37:40 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case "stop-rgar": {
|
|
|
|
if (((BukkitHybridUtils)(HybridUtils.manager)).task == 0) {
|
2015-07-03 14:15:20 +02:00
|
|
|
PS.log("&cTASK NOT RUNNING!");
|
2015-06-07 21:37:40 +02:00
|
|
|
return false;
|
|
|
|
}
|
2015-06-28 02:54:57 +02:00
|
|
|
((BukkitHybridUtils)(HybridUtils.manager)).task = 0;
|
2015-06-07 21:37:40 +02:00
|
|
|
Bukkit.getScheduler().cancelTask(((BukkitHybridUtils)(HybridUtils.manager)).task);
|
2015-07-03 14:15:20 +02:00
|
|
|
PS.log("&cCancelling task...");
|
2015-06-07 21:37:40 +02:00
|
|
|
while (BukkitHybridUtils.chunks.size() > 0) {
|
|
|
|
ChunkLoc chunk = BukkitHybridUtils.chunks.get(0);
|
|
|
|
BukkitHybridUtils.chunks.remove(0);
|
2015-07-03 11:30:26 +02:00
|
|
|
HybridUtils.manager.regenerateRoad(BukkitHybridUtils.world, chunk, 0);
|
2015-06-07 21:37:40 +02:00
|
|
|
ChunkManager.manager.unloadChunk(BukkitHybridUtils.world, chunk);
|
|
|
|
}
|
2015-07-03 14:15:20 +02:00
|
|
|
PS.log("&cCancelled!");
|
2015-06-07 21:37:40 +02:00
|
|
|
return true;
|
|
|
|
}
|
2015-02-20 07:34:19 +01:00
|
|
|
case "start-expire": {
|
|
|
|
if (ExpireManager.task == -1) {
|
|
|
|
ExpireManager.runTask();
|
|
|
|
} else {
|
2015-05-08 06:54:01 +02:00
|
|
|
return MainUtil.sendMessage(player, "Plot expiry task already started");
|
2015-02-20 07:34:19 +01:00
|
|
|
}
|
2015-05-08 06:54:01 +02:00
|
|
|
return MainUtil.sendMessage(player, "Started plot expiry task");
|
2015-02-20 07:34:19 +01:00
|
|
|
}
|
|
|
|
case "update-expired": {
|
|
|
|
if (args.length > 1) {
|
2015-02-22 07:42:52 +01:00
|
|
|
final String world = args[1];
|
|
|
|
if (!BlockManager.manager.isWorld(world)) {
|
2015-05-08 06:54:01 +02:00
|
|
|
return MainUtil.sendMessage(player, "Invalid world: " + args[1]);
|
2015-02-20 07:34:19 +01:00
|
|
|
}
|
2015-05-08 06:54:01 +02:00
|
|
|
MainUtil.sendMessage(player, "Updating expired plot list");
|
2015-02-20 07:34:19 +01:00
|
|
|
ExpireManager.updateExpired(args[1]);
|
|
|
|
return true;
|
|
|
|
}
|
2015-05-08 06:54:01 +02:00
|
|
|
return MainUtil.sendMessage(player, "Use /plot debugexec update-expired <world>");
|
2015-02-20 07:34:19 +01:00
|
|
|
}
|
|
|
|
case "show-expired": {
|
|
|
|
if (args.length > 1) {
|
2015-02-22 07:42:52 +01:00
|
|
|
final String world = args[1];
|
|
|
|
if (!BlockManager.manager.isWorld(world)) {
|
2015-05-08 06:54:01 +02:00
|
|
|
return MainUtil.sendMessage(player, "Invalid world: " + args[1]);
|
2015-02-20 07:34:19 +01:00
|
|
|
}
|
2015-02-22 07:42:52 +01:00
|
|
|
if (!ExpireManager.expiredPlots.containsKey(args[1])) {
|
2015-05-08 06:54:01 +02:00
|
|
|
return MainUtil.sendMessage(player, "No task for world: " + args[1]);
|
2015-02-22 07:42:52 +01:00
|
|
|
}
|
2015-05-08 06:54:01 +02:00
|
|
|
MainUtil.sendMessage(player, "Expired plots (" + ExpireManager.expiredPlots.get(args[1]).size() + "):");
|
2015-05-30 00:01:41 +02:00
|
|
|
for (final Plot plot : ExpireManager.expiredPlots.get(args[1])) {
|
|
|
|
MainUtil.sendMessage(player, " - " + plot.world + ";" + plot.id.x + ";" + plot.id.y + ";" + UUIDHandler.getName(plot.owner) + " : " + ExpireManager.dates.get(plot.owner));
|
2015-02-20 07:34:19 +01:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2015-05-08 06:54:01 +02:00
|
|
|
return MainUtil.sendMessage(player, "Use /plot debugexec show-expired <world>");
|
2015-02-20 07:34:19 +01:00
|
|
|
}
|
|
|
|
case "seen": {
|
|
|
|
if (args.length != 2) {
|
2015-05-08 06:54:01 +02:00
|
|
|
return MainUtil.sendMessage(player, "Use /plot debugexec seen <player>");
|
2015-02-20 07:34:19 +01:00
|
|
|
}
|
|
|
|
final UUID uuid = UUIDHandler.getUUID(args[1]);
|
|
|
|
if (uuid == null) {
|
2015-05-08 06:54:01 +02:00
|
|
|
return MainUtil.sendMessage(player, "player not found: " + args[1]);
|
2015-02-11 09:41:10 +01:00
|
|
|
}
|
2015-02-26 12:13:17 +01:00
|
|
|
final OfflinePlotPlayer op = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid);
|
2015-02-23 02:32:27 +01:00
|
|
|
if ((op == null) || (op.getLastPlayed() == 0)) {
|
2015-05-08 06:54:01 +02:00
|
|
|
return MainUtil.sendMessage(player, "player hasn't connected before: " + args[1]);
|
2015-02-20 07:34:19 +01:00
|
|
|
}
|
|
|
|
final Timestamp stamp = new Timestamp(op.getLastPlayed());
|
|
|
|
final Date date = new Date(stamp.getTime());
|
2015-05-08 06:54:01 +02:00
|
|
|
MainUtil.sendMessage(player, "PLAYER: " + args[1]);
|
|
|
|
MainUtil.sendMessage(player, "UUID: " + uuid);
|
|
|
|
MainUtil.sendMessage(player, "Object: " + date.toGMTString());
|
|
|
|
MainUtil.sendMessage(player, "GMT: " + date.toGMTString());
|
|
|
|
MainUtil.sendMessage(player, "Local: " + date.toLocaleString());
|
2015-02-20 07:34:19 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case "trim-check": {
|
|
|
|
if (args.length != 2) {
|
2015-05-08 06:54:01 +02:00
|
|
|
MainUtil.sendMessage(player, "Use /plot debugexec trim-check <world>");
|
|
|
|
MainUtil.sendMessage(player, "&7 - Generates a list of regions to trim");
|
|
|
|
return MainUtil.sendMessage(player, "&7 - Run after plot expiry has run");
|
2015-02-20 07:34:19 +01:00
|
|
|
}
|
2015-02-22 07:42:52 +01:00
|
|
|
final String world = args[1];
|
2015-07-03 14:15:20 +02:00
|
|
|
if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(args[1])) {
|
2015-05-08 06:54:01 +02:00
|
|
|
return MainUtil.sendMessage(player, "Invalid world: " + args[1]);
|
2015-02-20 07:34:19 +01:00
|
|
|
}
|
|
|
|
final ArrayList<ChunkLoc> empty = new ArrayList<>();
|
|
|
|
final boolean result = Trim.getTrimRegions(empty, world, new Runnable() {
|
2015-02-12 07:59:02 +01:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
Trim.sendMessage("Processing is complete! Here's how many chunks would be deleted:");
|
|
|
|
Trim.sendMessage(" - MCA #: " + empty.size());
|
2015-02-12 08:41:26 +01:00
|
|
|
Trim.sendMessage(" - CHUNKS: " + (empty.size() * 1024) + " (max)");
|
2015-02-12 07:59:02 +01:00
|
|
|
Trim.sendMessage("Exporting log for manual approval...");
|
2015-07-03 14:15:20 +02:00
|
|
|
final File file = new File(PS.get().IMP.getDirectory() + File.separator + "trim.txt");
|
2015-02-12 07:59:02 +01:00
|
|
|
PrintWriter writer;
|
|
|
|
try {
|
|
|
|
writer = new PrintWriter(file);
|
2015-02-20 07:34:19 +01:00
|
|
|
for (final ChunkLoc loc : empty) {
|
2015-02-22 07:42:52 +01:00
|
|
|
writer.println(world + "/region/r." + loc.x + "." + loc.z + ".mca");
|
2015-02-12 07:59:02 +01:00
|
|
|
}
|
|
|
|
writer.close();
|
2015-02-12 08:41:26 +01:00
|
|
|
Trim.sendMessage("File saved to 'plugins/PlotSquared/trim.txt'");
|
2015-02-20 07:34:19 +01:00
|
|
|
} catch (final FileNotFoundException e) {
|
2015-02-12 07:59:02 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
Trim.sendMessage("File failed to save! :(");
|
|
|
|
}
|
|
|
|
Trim.sendMessage("How to get the chunk coords from a region file:");
|
|
|
|
Trim.sendMessage(" - Locate the x,z values for the region file (the two numbers which are separated by a dot)");
|
|
|
|
Trim.sendMessage(" - Multiply each number by 32; this gives you the starting position");
|
|
|
|
Trim.sendMessage(" - Add 31 to each number to get the end position");
|
|
|
|
}
|
|
|
|
});
|
2015-02-20 07:34:19 +01:00
|
|
|
if (!result) {
|
2015-05-08 06:54:01 +02:00
|
|
|
MainUtil.sendMessage(player, "Trim task already started!");
|
2015-02-20 07:34:19 +01:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
2015-01-24 01:00:57 +01:00
|
|
|
}
|
2015-02-22 07:42:52 +01:00
|
|
|
MainUtil.sendMessage(player, "Possible sub commands: /plot debugexec <" + StringUtils.join(allowed_params, "|") + ">");
|
2015-01-24 01:00:57 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|