mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-07-01 13:14:43 +02:00
Fix for sponge
This commit is contained in:
@ -1,15 +1,17 @@
|
||||
package com.intellectualcrafters.plot.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotLoc;
|
||||
import com.intellectualcrafters.plot.object.RegionWrapper;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
@ -103,17 +105,72 @@ public abstract class ChunkManager {
|
||||
|
||||
public abstract void unloadChunk(final String world, final ChunkLoc loc, final boolean save, final boolean safe);
|
||||
|
||||
public abstract Set<ChunkLoc> getChunkChunks(final String world);
|
||||
public Set<ChunkLoc> getChunkChunks(final String world) {
|
||||
final String directory = PS.get().IMP.getWorldContainer() + File.separator + world + File.separator + "region";
|
||||
final File folder = new File(directory);
|
||||
final File[] regionFiles = folder.listFiles();
|
||||
final HashSet<ChunkLoc> chunks = new HashSet<>();
|
||||
if (regionFiles == null) {
|
||||
throw new RuntimeException("Could not find worlds folder.");
|
||||
}
|
||||
for (final File file : regionFiles) {
|
||||
final String name = file.getName();
|
||||
if (name.endsWith("mca")) {
|
||||
final String[] split = name.split("\\.");
|
||||
try {
|
||||
final int x = Integer.parseInt(split[1]);
|
||||
final int z = Integer.parseInt(split[2]);
|
||||
final ChunkLoc loc = new ChunkLoc(x, z);
|
||||
chunks.add(loc);
|
||||
} catch (final Exception e) {}
|
||||
}
|
||||
}
|
||||
return chunks;
|
||||
}
|
||||
|
||||
public abstract void regenerateChunk(final String world, final ChunkLoc loc);
|
||||
|
||||
public abstract void deleteRegionFile(final String world, final ChunkLoc loc);
|
||||
public void deleteRegionFiles(String world, List<ChunkLoc> chunks) {
|
||||
deleteRegionFiles(world, chunks, null);
|
||||
}
|
||||
|
||||
public abstract void deleteRegionFiles(final String world, final List<ChunkLoc> chunks);
|
||||
public void deleteRegionFiles(final String world, final List<ChunkLoc> chunks, final Runnable whenDone) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (final ChunkLoc loc : chunks) {
|
||||
final String directory = world + File.separator + "region" + File.separator + "r." + loc.x + "." + loc.z + ".mca";
|
||||
final File file = new File(PS.get().IMP.getWorldContainer(), directory);
|
||||
PS.log("&6 - Deleting file: " + file.getName() + " (max 1024 chunks)");
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
if (whenDone != null) {
|
||||
whenDone.run();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public abstract void deleteRegionFiles(final String world, final List<ChunkLoc> chunks, final Runnable whenDone);
|
||||
|
||||
public abstract Plot hasPlot(String world, ChunkLoc chunk);
|
||||
public Plot hasPlot(String world, ChunkLoc chunk) {
|
||||
final int x1 = chunk.x << 4;
|
||||
final int z1 = chunk.z << 4;
|
||||
final int x2 = x1 + 15;
|
||||
final int z2 = z1 + 15;
|
||||
final Location bot = new Location(world, x1, 0, z1);
|
||||
Plot plot;
|
||||
plot = MainUtil.getPlotAbs(bot);
|
||||
if ((plot != null) && (plot.owner != null)) {
|
||||
return plot;
|
||||
}
|
||||
final Location top = new Location(world, x2, 0, z2);
|
||||
plot = MainUtil.getPlotAbs(top);
|
||||
if ((plot != null) && (plot.owner != null)) {
|
||||
return plot;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy a region to a new location (in the same world)
|
||||
|
@ -86,14 +86,14 @@ public abstract class EventUtil {
|
||||
if (!plot.hasOwner()) {
|
||||
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms);
|
||||
}
|
||||
final Flag use = FlagManager.getPlotFlag(plot, "use");
|
||||
final Flag use = FlagManager.getPlotFlagRaw(plot, "use");
|
||||
if (use != null) {
|
||||
final HashSet<PlotBlock> value = (HashSet<PlotBlock>) use.getValue();
|
||||
if (value.contains(PlotBlock.EVERYTHING) || value.contains(block.getPlotBlock())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
final Flag destroy = FlagManager.getPlotFlag(plot, "break");
|
||||
final Flag destroy = FlagManager.getPlotFlagRaw(plot, "break");
|
||||
if (destroy != null) {
|
||||
final HashSet<PlotBlock> value = (HashSet<PlotBlock>) destroy.getValue();
|
||||
if (value.contains(PlotBlock.EVERYTHING) || value.contains(block.getPlotBlock())) {
|
||||
@ -142,7 +142,7 @@ public abstract class EventUtil {
|
||||
if (!plot.hasOwner()) {
|
||||
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms);
|
||||
}
|
||||
final Flag flag = FlagManager.getPlotFlag(plot, "use");
|
||||
final Flag flag = FlagManager.getPlotFlagRaw(plot, "use");
|
||||
final HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue();
|
||||
if ((value == null) || (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock()))) {
|
||||
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms);
|
||||
@ -156,7 +156,7 @@ public abstract class EventUtil {
|
||||
if (!plot.hasOwner()) {
|
||||
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED.s(), notifyPerms);
|
||||
}
|
||||
final Flag flag = FlagManager.getPlotFlag(plot, "place");
|
||||
final Flag flag = FlagManager.getPlotFlagRaw(plot, "place");
|
||||
final HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue();
|
||||
if ((value == null) || (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock()))) {
|
||||
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER.s(), notifyPerms);
|
||||
@ -173,7 +173,7 @@ public abstract class EventUtil {
|
||||
if (FlagManager.isPlotFlagTrue(plot, "device-interact")) {
|
||||
return true;
|
||||
}
|
||||
final Flag flag = FlagManager.getPlotFlag(plot, "use");
|
||||
final Flag flag = FlagManager.getPlotFlagRaw(plot, "use");
|
||||
final HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue();
|
||||
if ((value == null) || (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock()))) {
|
||||
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms);
|
||||
@ -190,7 +190,7 @@ public abstract class EventUtil {
|
||||
if (FlagManager.isPlotFlagTrue(plot, "hanging-interact")) {
|
||||
return true;
|
||||
}
|
||||
final Flag flag = FlagManager.getPlotFlag(plot, "use");
|
||||
final Flag flag = FlagManager.getPlotFlagRaw(plot, "use");
|
||||
final HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue();
|
||||
if ((value == null) || (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock()))) {
|
||||
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms);
|
||||
@ -207,7 +207,7 @@ public abstract class EventUtil {
|
||||
if (FlagManager.isPlotFlagTrue(plot, "misc-interact")) {
|
||||
return true;
|
||||
}
|
||||
final Flag flag = FlagManager.getPlotFlag(plot, "use");
|
||||
final Flag flag = FlagManager.getPlotFlagRaw(plot, "use");
|
||||
final HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue();
|
||||
if ((value == null) || (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock()))) {
|
||||
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms);
|
||||
@ -224,7 +224,7 @@ public abstract class EventUtil {
|
||||
if (FlagManager.isPlotFlagTrue(plot, "vehicle-use")) {
|
||||
return true;
|
||||
}
|
||||
final Flag flag = FlagManager.getPlotFlag(plot, "use");
|
||||
final Flag flag = FlagManager.getPlotFlagRaw(plot, "use");
|
||||
final HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue();
|
||||
if ((value == null) || (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock()))) {
|
||||
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms);
|
||||
@ -242,7 +242,7 @@ public abstract class EventUtil {
|
||||
if (FlagManager.isPlotFlagTrue(plot, "mob-place")) {
|
||||
return true;
|
||||
}
|
||||
final Flag flag = FlagManager.getPlotFlag(plot, "place");
|
||||
final Flag flag = FlagManager.getPlotFlagRaw(plot, "place");
|
||||
final HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue();
|
||||
if ((value == null) || (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock()))) {
|
||||
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms);
|
||||
@ -278,7 +278,7 @@ public abstract class EventUtil {
|
||||
if (FlagManager.isPlotFlagTrue(plot, "misc-place")) {
|
||||
return true;
|
||||
}
|
||||
final Flag flag = FlagManager.getPlotFlag(plot, "place");
|
||||
final Flag flag = FlagManager.getPlotFlagRaw(plot, "place");
|
||||
final HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue();
|
||||
if ((value == null) || (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock()))) {
|
||||
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms);
|
||||
@ -296,7 +296,7 @@ public abstract class EventUtil {
|
||||
if (FlagManager.isPlotFlagTrue(plot, "vehicle-place")) {
|
||||
return true;
|
||||
}
|
||||
final Flag flag = FlagManager.getPlotFlag(plot, "place");
|
||||
final Flag flag = FlagManager.getPlotFlagRaw(plot, "place");
|
||||
final HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue();
|
||||
if ((value == null) || (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock()))) {
|
||||
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms);
|
||||
|
@ -223,7 +223,7 @@ public class ExpireManager {
|
||||
final Iterator<Plot> iter = plots.iterator();
|
||||
while (iter.hasNext()) {
|
||||
final Plot plot = iter.next();
|
||||
final Flag keepFlag = FlagManager.getPlotFlag(plot, "keep");
|
||||
final Flag keepFlag = FlagManager.getPlotFlagRaw(plot, "keep");
|
||||
if ((keepFlag != null) && (Boolean) keepFlag.getValue()) {
|
||||
continue;
|
||||
}
|
||||
|
@ -34,12 +34,14 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.object.BlockLoc;
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
@ -269,6 +271,8 @@ public class MainUtil {
|
||||
|
||||
public static String getName(final UUID owner) {
|
||||
if (owner == null) {
|
||||
return C.NONE.s();
|
||||
} else if (owner.equals(DBFunc.everyone)) {
|
||||
return C.EVERYONE.s();
|
||||
}
|
||||
final String name = UUIDHandler.getName(owner);
|
||||
@ -518,10 +522,14 @@ public class MainUtil {
|
||||
final boolean result = EventUtil.manager.callUnlink(plot.world, ids);
|
||||
if (!result) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (createSign) {
|
||||
plot.removeSign();
|
||||
}
|
||||
final PlotManager manager = PS.get().getPlotManager(plot.world);
|
||||
final PlotWorld plotworld = PS.get().getPlotWorld(plot.world);
|
||||
final PlotWorld plotworld = PS.get().getPlotWorld(plot.world);
|
||||
if (createRoad) {
|
||||
manager.startPlotUnlink(plotworld, ids);
|
||||
}
|
||||
if ((plotworld.TERRAIN != 3) && createRoad) {
|
||||
for (Plot current : plots) {
|
||||
@ -545,7 +553,9 @@ public class MainUtil {
|
||||
if (createSign) {
|
||||
MainUtil.setSign(getName(current.owner), current);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (createRoad) {
|
||||
manager.finishPlotUnlink(plotworld, ids);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -2157,8 +2167,13 @@ public class MainUtil {
|
||||
tmp = getPlotAbs(plot.world, getPlotIdRelative(plot.id, 0));
|
||||
if (!tmp.getMerged(2)) {
|
||||
// invalid merge
|
||||
PS.debug("Fixing invalid merge: " + plot);
|
||||
tmp.getSettings().setMerged(2, true);
|
||||
PS.debug("Fixing invalid merge: " + plot);
|
||||
if (tmp.hasOwner()) {
|
||||
tmp.getSettings().setMerged(2, true);
|
||||
DBFunc.setMerged(tmp, tmp.settings.getMerged());
|
||||
} else {
|
||||
plot.getSettings().setMerged(0, false);
|
||||
DBFunc.setMerged(plot, plot.settings.getMerged());
|
||||
}
|
||||
}
|
||||
queuecache.add(tmp);
|
||||
@ -2168,8 +2183,13 @@ public class MainUtil {
|
||||
tmp = getPlotAbs(plot.world, getPlotIdRelative(plot.id, 1));
|
||||
if (!tmp.getMerged(3)) {
|
||||
// invalid merge
|
||||
PS.debug("Fixing invalid merge: " + plot);
|
||||
tmp.getSettings().setMerged(3, true);
|
||||
PS.debug("Fixing invalid merge: " + plot);
|
||||
if (tmp.hasOwner()) {
|
||||
tmp.getSettings().setMerged(3, true);
|
||||
DBFunc.setMerged(tmp, tmp.settings.getMerged());
|
||||
} else {
|
||||
plot.getSettings().setMerged(1, false);
|
||||
DBFunc.setMerged(plot, plot.settings.getMerged());
|
||||
}
|
||||
}
|
||||
queuecache.add(tmp);
|
||||
@ -2179,8 +2199,13 @@ public class MainUtil {
|
||||
tmp = getPlotAbs(plot.world, getPlotIdRelative(plot.id, 2));
|
||||
if (!tmp.getMerged(0)) {
|
||||
// invalid merge
|
||||
PS.debug("Fixing invalid merge: " + plot);
|
||||
tmp.getSettings().setMerged(0, true);
|
||||
PS.debug("Fixing invalid merge: " + plot);
|
||||
if (tmp.hasOwner()) {
|
||||
tmp.getSettings().setMerged(0, true);
|
||||
DBFunc.setMerged(tmp, tmp.settings.getMerged());
|
||||
} else {
|
||||
plot.getSettings().setMerged(2, false);
|
||||
DBFunc.setMerged(plot, plot.settings.getMerged());
|
||||
}
|
||||
}
|
||||
queuecache.add(tmp);
|
||||
@ -2190,8 +2215,13 @@ public class MainUtil {
|
||||
tmp = getPlotAbs(plot.world, getPlotIdRelative(plot.id, 3));
|
||||
if (!tmp.getMerged(1)) {
|
||||
// invalid merge
|
||||
PS.debug("Fixing invalid merge: " + plot);
|
||||
tmp.getSettings().setMerged(1, true);
|
||||
PS.debug("Fixing invalid merge: " + plot);
|
||||
if (tmp.hasOwner()) {
|
||||
tmp.getSettings().setMerged(1, true);
|
||||
DBFunc.setMerged(tmp, tmp.settings.getMerged());
|
||||
} else {
|
||||
plot.getSettings().setMerged(3, false);
|
||||
DBFunc.setMerged(plot, plot.settings.getMerged());
|
||||
}
|
||||
}
|
||||
queuecache.add(tmp);
|
||||
@ -2381,4 +2411,84 @@ public class MainUtil {
|
||||
|
||||
public static boolean setComponent(final Plot plot, final String component, final PlotBlock[] blocks) {
|
||||
return PS.get().getPlotManager(plot.world).setComponent(PS.get().getPlotWorld(plot.world), plot.id, component, blocks);
|
||||
}
|
||||
|
||||
public static void format(String info, final Plot plot, final PlotPlayer player, final boolean full, final RunnableVal<String> whenDone) {
|
||||
final int num = MainUtil.getConnectedPlots(plot).size();
|
||||
final String alias = plot.getAlias().length() > 0 ? plot.getAlias() : C.NONE.s();
|
||||
final Location bot = plot.getBottom();
|
||||
final String biome = BlockManager.manager.getBiome(plot.world, bot.getX(), bot.getZ());
|
||||
final String trusted = getPlayerList(plot.getTrusted());
|
||||
final String members = getPlayerList(plot.getMembers());
|
||||
final String denied = getPlayerList(plot.getDenied());
|
||||
|
||||
final Flag descriptionFlag = FlagManager.getPlotFlagRaw(plot, "description");
|
||||
final String description = descriptionFlag == null ? C.NONE.s() : descriptionFlag.getValueString();
|
||||
|
||||
final String flags = StringMan.replaceFromMap(
|
||||
"$2"
|
||||
+ (StringMan.join(FlagManager.getPlotFlags(plot.world, plot.getSettings(), true).values(), "").length() > 0 ? StringMan.join(FlagManager.getPlotFlags(plot.world, plot.getSettings(), true)
|
||||
.values(), "$1, $2") : C.NONE.s()), C.replacements);
|
||||
final boolean build = plot.isAdded(player.getUUID());
|
||||
|
||||
final String owner = plot.owner == null ? "unowned" : getPlayerList(plot.getOwners());
|
||||
|
||||
info = info.replaceAll("%id%", plot.id.toString());
|
||||
info = info.replaceAll("%alias%", alias);
|
||||
info = info.replaceAll("%num%", num + "");
|
||||
info = info.replaceAll("%desc%", description);
|
||||
info = info.replaceAll("%biome%", biome);
|
||||
info = info.replaceAll("%owner%", owner);
|
||||
info = info.replaceAll("%members%", members);
|
||||
info = info.replaceAll("%trusted%", trusted);
|
||||
info = info.replaceAll("%helpers%", members);
|
||||
info = info.replaceAll("%denied%", denied);
|
||||
info = info.replaceAll("%flags%", Matcher.quoteReplacement(flags));
|
||||
info = info.replaceAll("%build%", build + "");
|
||||
info = info.replaceAll("%desc%", "No description set.");
|
||||
if (info.contains("%rating%")) {
|
||||
final String newInfo = info;
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int max = 10;
|
||||
if ((Settings.RATING_CATEGORIES != null) && (Settings.RATING_CATEGORIES.size() > 0)) {
|
||||
max = 8;
|
||||
}
|
||||
String info;
|
||||
if (full && (Settings.RATING_CATEGORIES != null) && (Settings.RATING_CATEGORIES.size() > 1)) {
|
||||
String rating = "";
|
||||
String prefix = "";
|
||||
final double[] ratings = MainUtil.getAverageRatings(plot);
|
||||
for (int i = 0; i < ratings.length; i++) {
|
||||
rating += prefix + Settings.RATING_CATEGORIES.get(i) + "=" + String.format("%.1f", ratings[i]);
|
||||
prefix = ",";
|
||||
}
|
||||
info = newInfo.replaceAll("%rating%", rating);
|
||||
} else {
|
||||
info = newInfo.replaceAll("%rating%", String.format("%.1f", MainUtil.getAverageRating(plot)) + "/" + max);
|
||||
}
|
||||
whenDone.run(info);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
whenDone.run(info);
|
||||
}
|
||||
|
||||
public static String getPlayerList(final Collection<UUID> uuids) {
|
||||
final ArrayList<UUID> l = new ArrayList<>(uuids);
|
||||
if ((l == null) || (l.size() < 1)) {
|
||||
return C.NONE.s();
|
||||
}
|
||||
final String c = C.PLOT_USER_LIST.s();
|
||||
final StringBuilder list = new StringBuilder();
|
||||
for (int x = 0; x < l.size(); x++) {
|
||||
if ((x + 1) == l.size()) {
|
||||
list.append(c.replace("%user%", getName(l.get(x))).replace(",", ""));
|
||||
} else {
|
||||
list.append(c.replace("%user%", getName(l.get(x))));
|
||||
}
|
||||
}
|
||||
return list.toString();
|
||||
}
|
||||
|
Reference in New Issue
Block a user