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

154 lines
8.4 KiB
Java
Raw Normal View History

2014-11-08 20:27:09 +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 /
////////////////////////////////////////////////////////////////////////////////////////////////////
2014-10-22 14:22:00 +02:00
package com.intellectualcrafters.plot.commands;
2015-07-05 17:44:10 +02:00
import java.util.ArrayList;
import java.util.UUID;
2015-01-13 17:38:15 +01:00
import com.google.common.collect.BiMap;
import com.intellectualcrafters.plot.PS;
2015-01-13 17:38:15 +01:00
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc;
2015-07-05 17:44:10 +02:00
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.StringWrapper;
2015-02-22 07:30:58 +01:00
import com.intellectualcrafters.plot.util.BlockManager;
2015-02-25 11:36:19 +01:00
import com.intellectualcrafters.plot.util.ChunkManager;
2015-02-23 06:29:45 +01:00
import com.intellectualcrafters.plot.util.EventUtil;
2015-02-20 12:23:48 +01:00
import com.intellectualcrafters.plot.util.MainUtil;
2015-07-27 09:26:50 +02:00
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualsites.commands.CommandDeclaration;
2015-07-27 06:30:50 +02:00
import com.intellectualsites.commands.CommandCaller;
2014-10-22 14:22:00 +02:00
@CommandDeclaration(
command = "debugclaimtest",
description = "If you accidentally delete your database, this command will attempt to restore all plots based on the data from plot sighs. Execution time may vary",
category = CommandCategory.DEBUG,
requiredType = PS.class,
permission = "plots.debugclaimtest"
)
2014-10-22 14:22:00 +02:00
public class DebugClaimTest extends SubCommand {
2015-02-23 02:32:27 +01:00
2015-02-22 07:30:58 +01:00
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport) {
2014-11-16 10:48:18 +01:00
return claimPlot(player, plot, teleport, "");
}
2015-02-23 02:32:27 +01:00
2015-02-22 07:37:44 +01:00
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport, final String schematic) {
2015-02-23 06:29:45 +01:00
final boolean result = EventUtil.manager.callClaim(player, plot, false);
if (result) {
2015-02-22 07:30:58 +01:00
MainUtil.createPlot(player.getUUID(), plot);
MainUtil.setSign(player.getName(), plot);
MainUtil.sendMessage(player, C.CLAIMED);
2014-11-16 10:48:18 +01:00
if (teleport) {
2015-02-21 15:13:34 +01:00
MainUtil.teleportPlayer(player, player.getLocation(), plot);
2014-11-16 10:48:18 +01:00
}
}
2015-02-23 06:29:45 +01:00
return !result;
2014-11-16 10:48:18 +01:00
}
2015-02-23 02:32:27 +01:00
2014-11-05 04:42:08 +01:00
@Override
public boolean onCommand(CommandCaller caller, String[] args) {
if (args.length < 3) {
return !MainUtil.sendMessage(null, "If you accidentally delete your database, this command will attempt to restore all plots based on the data from the plot signs. \n\n&cMissing world arg /plot debugclaimtest {world} {PlotId min} {PlotId max}");
}
final String world = args[0];
if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(world)) {
return !MainUtil.sendMessage(null, "&cInvalid plot world!");
}
PlotId min, max;
try {
final String[] split1 = args[1].split(";");
final String[] split2 = args[2].split(";");
min = new PlotId(Integer.parseInt(split1[0]), Integer.parseInt(split1[1]));
max = new PlotId(Integer.parseInt(split2[0]), Integer.parseInt(split2[1]));
} catch (final Exception e) {
return !MainUtil.sendMessage(null, "&cInvalid min/max values. &7The values are to Plot IDs in the format &cX;Y &7where X,Y are the plot coords\nThe conversion will only check the plots in the selected area.");
}
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Beginning sign to plot conversion. This may take a while...");
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: Found an excess of 250,000 chunks. Limiting search radius... (~3.8 min)");
final PlotManager manager = PS.get().getPlotManager(world);
final PlotWorld plotworld = PS.get().getPlotWorld(world);
final ArrayList<Plot> plots = new ArrayList<>();
for (final PlotId id : MainUtil.getPlotSelectionIds(min, max)) {
final Plot plot = MainUtil.getPlot(world, id);
final boolean contains = PS.get().getPlots(world).containsKey(plot.id);
if (contains) {
MainUtil.sendMessage(null, " - &cDB Already contains: " + plot.id);
continue;
2014-11-05 04:42:08 +01:00
}
final Location loc = manager.getSignLoc(plotworld, plot);
final ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4);
final boolean result = ChunkManager.manager.loadChunk(world, chunk);
if (!result) {
continue;
2014-11-05 04:42:08 +01:00
}
final String[] lines = BlockManager.manager.getSign(loc);
if (lines != null) {
String line = lines[2];
if ((line != null) && (line.length() > 2)) {
line = line.substring(2);
final BiMap<StringWrapper, UUID> map = UUIDHandler.getUuidMap();
UUID uuid = (map.get(new StringWrapper(line)));
if (uuid == null) {
for (final StringWrapper string : map.keySet()) {
if (string.value.toLowerCase().startsWith(line.toLowerCase())) {
uuid = map.get(string);
break;
2014-11-08 20:27:09 +01:00
}
2015-02-22 07:30:58 +01:00
}
}
if (uuid == null) {
2015-07-27 11:14:28 +02:00
uuid = UUIDHandler.getUUID(line, null);
}
if (uuid != null) {
MainUtil.sendMessage(null, " - &aFound plot: " + plot.id + " : " + line);
plot.owner = uuid;
plots.add(plot);
} else {
MainUtil.sendMessage(null, " - &cInvalid playername: " + plot.id + " : " + line);
2014-10-22 14:22:00 +02:00
}
}
2014-11-05 04:42:08 +01:00
}
}
if (plots.size() > 0) {
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Updating '" + plots.size() + "' plots!");
DBFunc.createPlotsAndData(plots, new Runnable() {
@Override
public void run() {
MainUtil.sendMessage(null, "&6Database update finished!");
2014-11-05 04:42:08 +01:00
}
});
for (final Plot plot : plots) {
PS.get().updatePlot(plot);
2014-11-05 04:42:08 +01:00
}
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Complete!");
2014-12-18 03:15:11 +01:00
} else {
MainUtil.sendMessage(null, "No plots were found for the given search.");
2014-11-05 04:42:08 +01:00
}
2014-10-22 14:22:00 +02:00
return true;
2014-11-05 04:42:08 +01:00
}
2014-10-22 14:22:00 +02:00
}