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

154 lines
8.6 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-01-13 17:38:15 +01:00
import java.util.ArrayList;
import java.util.UUID;
2014-12-28 14:47:35 +01:00
2015-01-13 17:38:15 +01:00
import com.google.common.collect.BiMap;
2015-02-19 09:51:10 +01:00
import com.intellectualcrafters.plot.PlotSquared;
2015-01-13 17:38:15 +01:00
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc;
2015-02-22 07:30:58 +01:00
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.Location;
2015-01-13 17:38:15 +01:00
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager;
2015-02-21 12:38:44 +01:00
import com.intellectualcrafters.plot.object.PlotPlayer;
2015-01-13 17:38:15 +01:00
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.AChunkManager;
import com.intellectualcrafters.plot.util.BlockManager;
2015-02-20 12:23:48 +01:00
import com.intellectualcrafters.plot.util.MainUtil;
2015-02-20 07:28:21 +01:00
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
2014-10-22 14:22:00 +02:00
/**
* @author Citymonstret
*/
public class DebugClaimTest extends SubCommand {
2014-11-05 04:42:08 +01:00
public DebugClaimTest() {
2014-11-10 11:54:36 +01:00
super(Command.DEBUGCLAIMTEST, "If you accidentally delete your database, this command will attempt to restore all plots based on the data from the plot signs. Execution time may vary", "debugclaimtest", CommandCategory.DEBUG, false);
2014-11-05 04:42:08 +01:00
}
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-22 07:30:58 +01:00
// FIXME call claim event
// boolean result = event result
2015-02-23 02:32:27 +01:00
final boolean result = true;
2015-02-22 07:30:58 +01:00
if (!result) {
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-22 07:30:58 +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
2015-02-21 08:30:55 +01:00
public boolean execute(final PlotPlayer plr, final String... args) {
2014-11-05 04:42:08 +01:00
if (plr == null) {
if (args.length < 3) {
2015-02-21 12:24:46 +01:00
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}");
2014-11-05 04:42:08 +01:00
}
2015-02-23 02:32:27 +01:00
final String world = args[0];
2015-02-22 07:30:58 +01:00
if (!BlockManager.manager.isWorld(world) || !PlotSquared.isPlotWorld(world)) {
2015-02-21 12:24:46 +01:00
return !MainUtil.sendMessage(null, "&cInvalid plot world!");
2014-11-05 04:42:08 +01:00
}
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]));
2014-12-18 03:15:11 +01:00
} catch (final Exception e) {
2015-02-21 12:24:46 +01:00
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.");
2014-11-05 04:42:08 +01:00
}
2015-02-21 12:24:46 +01:00
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)");
2015-02-19 09:51:10 +01:00
final PlotManager manager = PlotSquared.getPlotManager(world);
2015-02-20 09:55:04 +01:00
final PlotWorld plotworld = PlotSquared.getPlotWorld(world);
2014-11-08 20:27:09 +01:00
final ArrayList<Plot> plots = new ArrayList<>();
2015-02-21 13:52:50 +01:00
for (final PlotId id : MainUtil.getPlotSelectionIds(min, max)) {
2015-02-20 12:23:48 +01:00
final Plot plot = MainUtil.getPlot(world, id);
2015-02-19 09:51:10 +01:00
final boolean contains = PlotSquared.getPlots(world).containsKey(plot.id);
2014-10-22 14:22:00 +02:00
if (contains) {
2015-02-21 12:24:46 +01:00
MainUtil.sendMessage(null, " - &cDB Already contains: " + plot.id);
2014-10-22 14:22:00 +02:00
continue;
}
2015-02-22 07:30:58 +01:00
final Location loc = manager.getSignLoc(plotworld, plot);
2015-02-23 02:32:27 +01:00
final ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4);
final boolean result = AChunkManager.manager.loadChunk(world, chunk);
2015-02-22 07:30:58 +01:00
if (!result) {
continue;
2014-10-22 14:22:00 +02:00
}
2015-02-23 02:32:27 +01:00
final String[] lines = BlockManager.manager.getSign(loc);
2015-02-22 07:30:58 +01:00
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-10-22 14:22:00 +02:00
}
2014-11-08 20:27:09 +01:00
}
2015-02-22 07:30:58 +01:00
}
if (uuid == null) {
uuid = UUIDHandler.getUUID(line);
}
if (uuid != null) {
MainUtil.sendMessage(null, " - &aFound plot: " + plot.id + " : " + line);
plot.owner = uuid;
plot.hasChanged = true;
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) {
2015-02-21 12:24:46 +01:00
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Updating '" + plots.size() + "' plots!");
2014-11-05 04:42:08 +01:00
DBFunc.createPlots(plots);
DBFunc.createAllSettingsAndHelpers(plots);
for (final Plot plot : plots) {
2015-02-19 09:51:10 +01:00
PlotSquared.updatePlot(plot);
2014-11-05 04:42:08 +01:00
}
2015-02-21 12:24:46 +01:00
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Complete!");
2014-12-18 03:15:11 +01:00
} else {
2015-02-21 12:24:46 +01:00
MainUtil.sendMessage(null, "No plots were found for the given search.");
2014-11-05 04:42:08 +01:00
}
2014-12-18 03:15:11 +01:00
} else {
2015-02-21 12:24:46 +01:00
MainUtil.sendMessage(plr, "&6This command can only be executed by console as it has been deemed unsafe if abused.");
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
}