mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-07-01 13:14:43 +02:00
@ -20,6 +20,7 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.util;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -36,6 +37,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
@ -56,6 +58,7 @@ import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.object.PseudoRandom;
|
||||
import com.intellectualcrafters.plot.object.RegionWrapper;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
||||
import com.plotsquared.listener.PlotListener;
|
||||
|
||||
/**
|
||||
@ -1427,7 +1430,9 @@ public class MainUtil {
|
||||
}
|
||||
final HashSet<RegionWrapper> regions = getRegions(plot);
|
||||
final HashSet<Plot> plots = getConnectedPlots(plot);
|
||||
final ArrayDeque<Plot> queue = new ArrayDeque<>(plots);
|
||||
final ArrayDeque<Plot> queue = new ArrayDeque<>(plots);
|
||||
if (isDelete) {
|
||||
removeSign(plot);
|
||||
}
|
||||
MainUtil.unlinkPlot(plot, true, !isDelete);
|
||||
final PlotManager manager = PS.get().getPlotManager(plot.world);
|
||||
@ -1724,6 +1729,12 @@ public class MainUtil {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a plot can be claimed
|
||||
* @param player
|
||||
* @param plot
|
||||
* @return
|
||||
*/
|
||||
public static boolean canClaim(final PlotPlayer player, final Plot plot) {
|
||||
if (plot == null) {
|
||||
@ -1736,7 +1747,63 @@ public class MainUtil {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return guessOwner(plot) == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to guess who the plot owner is:
|
||||
* - Checks cache
|
||||
* - Checks sign text
|
||||
* @param plot
|
||||
* @return
|
||||
*/
|
||||
public static UUID guessOwner(Plot plot) {
|
||||
if (plot.owner != null) {
|
||||
return plot.owner;
|
||||
}
|
||||
PlotWorld pw = plot.getWorld();
|
||||
if (!pw.ALLOW_SIGNS) {
|
||||
return null;
|
||||
}
|
||||
Location loc = plot.getManager().getSignLoc(pw, plot);
|
||||
ChunkManager.manager.loadChunk(loc.getWorld(), loc.getChunkLoc(), false);
|
||||
String[] lines = BlockManager.manager.getSign(loc);
|
||||
if (lines == null) {
|
||||
return null;
|
||||
}
|
||||
loop:
|
||||
for (int i = 4; i > 0; i--) {
|
||||
String caption = C.valueOf("OWNER_SIGN_LINE_" + i).s();
|
||||
int index = caption.indexOf("%plr%");
|
||||
if (index == -1) {
|
||||
continue;
|
||||
}
|
||||
String name = lines[i - 1].substring(index);
|
||||
if (name.length() == 0) {
|
||||
return null;
|
||||
}
|
||||
UUID owner = UUIDHandler.getUUID(name, null);
|
||||
if (owner != null) {
|
||||
plot.owner = owner;
|
||||
break;
|
||||
}
|
||||
if (lines[i - 1].length() == 15) {
|
||||
BiMap<StringWrapper, UUID> map = UUIDHandler.getUuidMap();
|
||||
for (Entry<StringWrapper, UUID> entry : map.entrySet()) {
|
||||
String key = entry.getKey().value;
|
||||
if (key.length() > name.length() && key.startsWith(name)) {
|
||||
plot.owner = entry.getValue();
|
||||
break loop;
|
||||
}
|
||||
}
|
||||
}
|
||||
plot.owner = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(StandardCharsets.UTF_8));
|
||||
break;
|
||||
}
|
||||
if (plot.owner != null) {
|
||||
plot.create();
|
||||
}
|
||||
return plot.owner;
|
||||
}
|
||||
|
||||
|
@ -132,17 +132,21 @@ public abstract class UUIDHandlerImplementation {
|
||||
}
|
||||
try {
|
||||
final UUID offline = uuidMap.put(name, uuid);
|
||||
if ((offline != null) && !offline.equals(uuid)) {
|
||||
final Set<Plot> plots = PS.get().getPlots(offline);
|
||||
if (plots.size() > 0) {
|
||||
for (final Plot plot : PS.get().getPlots(offline)) {
|
||||
plot.owner = uuid;
|
||||
if (offline != null) {
|
||||
if (!offline.equals(uuid)) {
|
||||
final Set<Plot> plots = PS.get().getPlots(offline);
|
||||
if (plots.size() > 0) {
|
||||
for (final Plot plot : PS.get().getPlots(offline)) {
|
||||
plot.owner = uuid;
|
||||
}
|
||||
DBFunc.replaceUUID(offline, uuid);
|
||||
PS.debug("&cDetected invalid UUID stored for (1): " + name.value);
|
||||
PS.debug("&7 - Did you recently switch to online-mode storage without running `uuidconvert`?");
|
||||
PS.debug("&6PlotSquared will update incorrect entries when the user logs in, or you can reconstruct your database.");
|
||||
}
|
||||
DBFunc.replaceUUID(offline, uuid);
|
||||
PS.debug("&cDetected invalid UUID stored for (1): " + name.value);
|
||||
PS.debug("&7 - Did you recently switch to online-mode storage without running `uuidconvert`?");
|
||||
PS.debug("&6PlotSquared will update incorrect entries when the user logs in, or you can reconstruct your database.");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
final BiMap<UUID, StringWrapper> inverse = uuidMap.inverse();
|
||||
|
Reference in New Issue
Block a user