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

183 lines
9.3 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.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;
2015-02-11 10:25:04 +01:00
import org.bukkit.Chunk;
import org.bukkit.OfflinePlayer;
2015-01-24 01:00:57 +01:00
import org.bukkit.World;
import org.bukkit.entity.Player;
2015-02-11 09:41:10 +01:00
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.object.ChunkLoc;
2015-01-24 01:00:57 +01:00
import com.intellectualcrafters.plot.object.Plot;
2015-02-11 10:25:04 +01:00
import com.intellectualcrafters.plot.util.ChunkManager;
2015-01-24 01:00:57 +01:00
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-11 10:25:04 +01:00
List<String> allowed_params = Arrays.asList(new String[]{"stop-expire","start-expire", "show-expired", "update-expired", "seen", "trim-check-chunks", "trim-get-chunks"});
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-get-chunks": {
if (args.length != 2) {
PlayerFunctions.sendMessage(null, "Use /plot debugexec trim-get-chunks <world>");
PlayerFunctions.sendMessage(null, "&7 - Generates a list of regions to trim");
return PlayerFunctions.sendMessage(null, "&7 - Run after plot expiry has run");
}
World world = Bukkit.getWorld(args[1]);
if (world == null || !PlotMain.isPlotWorld(args[1])) {
return PlayerFunctions.sendMessage(null, "Invalid world: "+args[1]);
}
ArrayList<ChunkLoc> chunks0 = Trim.getTrimChunks(world);
PlayerFunctions.sendMessage(null, "BULK MCR: " + chunks0.size());
ArrayList<ChunkLoc> chunks = Trim.getTrimPlots(world);
chunks.addAll(chunks0);
2015-02-11 10:25:04 +01:00
this.chunks = chunks;
this.world = world;
2015-02-11 09:41:10 +01:00
PlayerFunctions.sendMessage(null, "MCR: " + chunks.size());
PlayerFunctions.sendMessage(null, "CHUNKS: " + chunks.size() * 256);
PlayerFunctions.sendMessage(null, "Calculating size on disk...");
PlayerFunctions.sendMessage(null, "SIZE (bytes): " + Trim.calculateSizeOnDisk(world, chunks));
2015-02-11 10:25:04 +01:00
return true;
}
case "trim-check-chunks": {
if (this.chunks == null) {
return PlayerFunctions.sendMessage(null, "Please run the 'trim-get-chunks' command first");
}
PlayerFunctions.sendMessage(null, "Checking MCR files for existing plots:");
int count = 0;
for (ChunkLoc loc : chunks) {
int sx = loc.x << 4;
int sz = loc.z << 4;
loop:
for (int x = sx; x < sx + 16; x++) {
for (int z = sz; z < sz + 16; z++) {
Chunk chunk = world.getChunkAt(x, z);
Plot plot = ChunkManager.hasPlot(world, chunk);
if (plot != null) {
PlayerFunctions.sendMessage(null, " - " + plot);
count++;
break loop;
}
}
}
}
PlayerFunctions.sendMessage(null, "Found " + count + "plots.");
2015-02-11 09:41:10 +01:00
}
2015-01-24 01:00:57 +01:00
}
}
PlayerFunctions.sendMessage(player, "Possible sub commands: /plot debugexec <" + StringUtils.join(allowed_params, "|") + ">");
return true;
}
}