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

180 lines
9.5 KiB
Java
Raw Normal View History

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;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.sql.Timestamp;
2015-02-11 09:41:10 +01:00
import java.util.ArrayList;
2015-01-24 01:00:57 +01:00
import java.util.Arrays;
import java.util.Date;
2015-01-24 01:00:57 +01:00
import java.util.List;
import java.util.Map.Entry;
import java.util.UUID;
2015-01-24 01:00:57 +01:00
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
2015-01-24 01:00:57 +01:00
import org.bukkit.World;
import org.bukkit.entity.Player;
2015-02-19 09:51:10 +01:00
import com.intellectualcrafters.plot.PlotSquared;
2015-02-11 09:41:10 +01:00
import com.intellectualcrafters.plot.object.ChunkLoc;
2015-01-24 01:00:57 +01:00
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.util.ExpireManager;
import com.intellectualcrafters.plot.util.PlayerFunctions;
import com.intellectualcrafters.plot.util.UUIDHandler;
public class DebugExec extends SubCommand {
2015-02-11 10:25:04 +01:00
private ArrayList<ChunkLoc> chunks = null;
private World world;
2015-01-24 01:00:57 +01:00
public DebugExec() {
super("debugexec", "plots.admin", "Multi-purpose debug command", "debugexec", "exec", CommandCategory.DEBUG, false);
}
@Override
public boolean execute(final Player player, final String... args) {
2015-02-12 08:41:26 +01:00
List<String> allowed_params = Arrays.asList(new String[]{"stop-expire","start-expire", "show-expired", "update-expired", "seen", "trim-check"});
2015-01-24 01:00:57 +01:00
if (args.length > 0) {
String arg = args[0].toLowerCase();
switch (arg) {
2015-02-11 09:41:10 +01:00
case "stop-expire": {
2015-01-24 01:00:57 +01:00
if (ExpireManager.task != -1) {
Bukkit.getScheduler().cancelTask(ExpireManager.task);
}
else {
return PlayerFunctions.sendMessage(null, "Task already halted");
}
ExpireManager.task = -1;
return PlayerFunctions.sendMessage(null, "Cancelled task.");
2015-02-11 09:41:10 +01:00
}
case "start-expire": {
2015-01-24 01:00:57 +01:00
if (ExpireManager.task == -1) {
ExpireManager.runTask();
}
else {
return PlayerFunctions.sendMessage(null, "Plot expiry task already started");
}
return PlayerFunctions.sendMessage(null, "Started plot expiry task");
2015-02-11 09:41:10 +01:00
}
case "update-expired": {
2015-01-24 01:00:57 +01:00
if (args.length > 1) {
World world = Bukkit.getWorld(args[1]);
if (world == null) {
return PlayerFunctions.sendMessage(null, "Invalid world: "+args[1]);
}
2015-02-05 10:24:07 +01:00
PlayerFunctions.sendMessage(null, "Updating expired plot list");
2015-01-24 01:00:57 +01:00
ExpireManager.updateExpired(args[1]);
2015-02-05 10:24:07 +01:00
return true;
2015-01-24 01:00:57 +01:00
}
return PlayerFunctions.sendMessage(null, "Use /plot debugexec update-expired <world>");
2015-02-11 09:41:10 +01:00
}
case "show-expired": {
2015-01-24 01:00:57 +01:00
if (args.length > 1) {
World world = Bukkit.getWorld(args[1]);
if (world == null || !ExpireManager.expiredPlots.containsKey(args[1])) {
return PlayerFunctions.sendMessage(null, "Invalid world: "+args[1]);
}
PlayerFunctions.sendMessage(null, "Expired plots (" + ExpireManager.expiredPlots.get(args[1]).size() + "):");
for (Entry<Plot, Long> entry : ExpireManager.expiredPlots.get(args[1]).entrySet()) {
Plot plot = entry.getKey();
Long stamp = entry.getValue();
PlayerFunctions.sendMessage(null, " - " + plot.world + ";" + plot.id.x + ";" + plot.id.y + ";" + UUIDHandler.getName(plot.owner) +" : " + stamp);
2015-01-24 01:00:57 +01:00
}
return true;
}
return PlayerFunctions.sendMessage(null, "Use /plot debugexec show-expired <world>");
2015-02-11 09:41:10 +01:00
}
case "seen": {
2015-02-04 05:42:27 +01:00
if (args.length != 2) {
return PlayerFunctions.sendMessage(null, "Use /plot debugexec seen <player>");
}
UUID uuid = UUIDHandler.getUUID(args[1]);
if (uuid == null) {
return PlayerFunctions.sendMessage(null, "player not found: " + args[1]);
}
OfflinePlayer op = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid);
if (op == null || !op.hasPlayedBefore()) {
return PlayerFunctions.sendMessage(null, "player hasn't connected before: " + args[1]);
}
Timestamp stamp = new Timestamp(op.getLastPlayed());
Date date = new Date(stamp.getTime());
PlayerFunctions.sendMessage(null, "PLAYER: " + args[1]);
PlayerFunctions.sendMessage(null, "UUID: " + uuid);
PlayerFunctions.sendMessage(null, "Object: " + date.toGMTString());
PlayerFunctions.sendMessage(null, "GMT: " + date.toGMTString());
PlayerFunctions.sendMessage(null, "Local: " + date.toLocaleString());
return true;
2015-02-11 09:41:10 +01:00
}
case "trim-check": {
2015-02-11 09:41:10 +01:00
if (args.length != 2) {
2015-02-12 08:41:26 +01:00
PlayerFunctions.sendMessage(null, "Use /plot debugexec trim-check <world>");
2015-02-11 09:41:10 +01:00
PlayerFunctions.sendMessage(null, "&7 - Generates a list of regions to trim");
return PlayerFunctions.sendMessage(null, "&7 - Run after plot expiry has run");
}
final World world = Bukkit.getWorld(args[1]);
2015-02-19 09:51:10 +01:00
if (world == null || !PlotSquared.isPlotWorld(args[1])) {
2015-02-11 09:41:10 +01:00
return PlayerFunctions.sendMessage(null, "Invalid world: "+args[1]);
}
final ArrayList<ChunkLoc> empty = new ArrayList<>();
2015-02-12 08:41:26 +01:00
boolean result = Trim.getTrimRegions(empty, world, new Runnable() {
@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)");
Trim.sendMessage("Exporting log for manual approval...");
2015-02-19 12:06:27 +01:00
final File file = new File(PlotSquared.IMP.getDirectory() + File.separator + "trim.txt");
PrintWriter writer;
try {
writer = new PrintWriter(file);
String worldname = world.getName();
for (ChunkLoc loc : empty) {
writer.println(worldname +"/region/r." + loc.x + "." + loc.z +".mca" );
}
writer.close();
2015-02-12 08:41:26 +01:00
Trim.sendMessage("File saved to 'plugins/PlotSquared/trim.txt'");
} catch (FileNotFoundException e) {
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-12 08:41:26 +01:00
if (!result) {
PlayerFunctions.sendMessage(null, "Trim task already started!");
}
return result;
2015-02-11 10:25:04 +01:00
}
2015-01-24 01:00:57 +01:00
}
}
PlayerFunctions.sendMessage(player, "Possible sub commands: /plot debugexec <" + StringUtils.join(allowed_params, "|") + ">");
return true;
}
}