Fix DebugClaimTest (#2667)

* Fix DebugClaimTest

* Remove code causing 3 database updates per plot + errors when using MySQL
This commit is contained in:
Hannes Greule 2020-01-31 18:12:06 +01:00 committed by GitHub
parent 30f37e1e8b
commit d0b6badf09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,7 +3,6 @@ package com.github.intellectualsites.plotsquared.plot.commands;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea; import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
@ -21,6 +20,7 @@ import com.sk89q.worldedit.math.BlockVector2;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@CommandDeclaration(command = "debugclaimtest", description = @CommandDeclaration(command = "debugclaimtest", description =
"If you accidentally delete your database, this command will attempt to restore all plots based on the data from plot signs. " "If you accidentally delete your database, this command will attempt to restore all plots based on the data from plot signs. "
@ -54,8 +54,10 @@ public class DebugClaimTest extends SubCommand {
MainUtil.sendMessage(player, MainUtil.sendMessage(player,
"&3Sign Block&8->&3Plot&8: Found an excess of 250,000 chunks. Limiting search radius... (~3.8 min)"); "&3Sign Block&8->&3Plot&8: Found an excess of 250,000 chunks. Limiting search radius... (~3.8 min)");
PlotManager manager = area.getPlotManager(); PlotManager manager = area.getPlotManager();
ArrayList<Plot> plots = new ArrayList<>(); CompletableFuture.runAsync(() -> {
for (PlotId id : MainUtil.getPlotSelectionIds(min, max)) { ArrayList<PlotId> ids = MainUtil.getPlotSelectionIds(min, max);
MainUtil.sendMessage(player, "&3Sign Block&8->&3Plot&8: " + ids.size() + " plot ids to check!");
for (PlotId id : ids) {
Plot plot = area.getPlotAbs(id); Plot plot = area.getPlotAbs(id);
if (plot.hasOwner()) { if (plot.hasOwner()) {
MainUtil.sendMessage(player, " - &cDB Already contains: " + plot.getId()); MainUtil.sendMessage(player, " - &cDB Already contains: " + plot.getId());
@ -72,8 +74,7 @@ public class DebugClaimTest extends SubCommand {
BiMap<StringWrapper, UUID> map = UUIDHandler.getUuidMap(); BiMap<StringWrapper, UUID> map = UUIDHandler.getUuidMap();
UUID uuid = map.get(new StringWrapper(line)); UUID uuid = map.get(new StringWrapper(line));
if (uuid == null) { if (uuid == null) {
for (Map.Entry<StringWrapper, UUID> stringWrapperUUIDEntry : map for (Map.Entry<StringWrapper, UUID> stringWrapperUUIDEntry : map.entrySet()) {
.entrySet()) {
if (stringWrapperUUIDEntry.getKey().value.toLowerCase() if (stringWrapperUUIDEntry.getKey().value.toLowerCase()
.startsWith(line.toLowerCase())) { .startsWith(line.toLowerCase())) {
uuid = stringWrapperUUIDEntry.getValue(); uuid = stringWrapperUUIDEntry.getValue();
@ -85,32 +86,17 @@ public class DebugClaimTest extends SubCommand {
uuid = UUIDHandler.getUUID(line, null); uuid = UUIDHandler.getUUID(line, null);
} }
if (uuid != null) { if (uuid != null) {
MainUtil.sendMessage(player, MainUtil.sendMessage(player, " - &aFound plot: " + plot.getId() + " : " + line);
" - &aFound plot: " + plot.getId() + " : " + line);
plot.setOwner(uuid); plot.setOwner(uuid);
plots.add(plot); MainUtil.sendMessage(player, " - &8Updated plot: " + plot.getId());
} else { } else {
MainUtil.sendMessage(player, MainUtil.sendMessage(player, " - &cInvalid PlayerName: " + plot.getId() + " : " + line);
" - &cInvalid PlayerName: " + plot.getId() + " : " + line);
} }
} }
} }
}).thenRun(() -> { }).join();
if (!plots.isEmpty()) {
MainUtil.sendMessage(player,
"&3Sign Block&8->&3Plot&8: &7Updating '" + plots.size() + "' plots!");
DBFunc.createPlotsAndData(plots,
() -> MainUtil.sendMessage(player, "&6Database update finished!"));
for (Plot plot1 : plots) {
plot.create();
}
MainUtil.sendMessage(player, "&3Sign Block&8->&3Plot&8: &7Complete!");
} else {
MainUtil.sendMessage(player, "No plots were found for the given search.");
}
});
return true;
} }
}).thenRun(() -> MainUtil.sendMessage(player, "&3Sign Block&8->&3Plot&8: Finished scan."));
return true; return true;
} }
} }