mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 05:06:44 +01:00
Merge branch 'v6' into feature/v6/pipeline-queue
# Conflicts: # Bukkit/src/main/java/com/plotsquared/bukkit/queue/GenChunk.java # Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java # Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java # Core/src/main/java/com/plotsquared/core/generator/SquarePlotManager.java # Core/src/main/java/com/plotsquared/core/plot/Plot.java # Core/src/main/java/com/plotsquared/core/plot/PlotArea.java # Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotManager.java # Core/src/main/java/com/plotsquared/core/util/SchematicHandler.java
This commit is contained in:
commit
d2443f6de8
@ -44,11 +44,11 @@ import com.plotsquared.bukkit.placeholder.PlaceholderFormatter;
|
||||
import com.plotsquared.bukkit.placeholder.Placeholders;
|
||||
import com.plotsquared.bukkit.player.BukkitPlayerManager;
|
||||
import com.plotsquared.bukkit.util.BukkitChatManager;
|
||||
import com.plotsquared.bukkit.util.task.BukkitTaskManager;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.bukkit.util.BukkitWorld;
|
||||
import com.plotsquared.bukkit.util.SetGenCB;
|
||||
import com.plotsquared.bukkit.util.UpdateUtility;
|
||||
import com.plotsquared.bukkit.util.task.BukkitTaskManager;
|
||||
import com.plotsquared.bukkit.util.task.PaperTimeConverter;
|
||||
import com.plotsquared.bukkit.util.task.SpigotTimeConverter;
|
||||
import com.plotsquared.bukkit.uuid.BungeePermsUUIDService;
|
||||
@ -67,6 +67,7 @@ import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.configuration.ChatFormatter;
|
||||
import com.plotsquared.core.configuration.ConfigurationNode;
|
||||
import com.plotsquared.core.configuration.ConfigurationSection;
|
||||
import com.plotsquared.core.configuration.ConfigurationUtil;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.configuration.file.YamlConfiguration;
|
||||
import com.plotsquared.core.database.DBFunc;
|
||||
@ -88,6 +89,7 @@ import com.plotsquared.core.plot.PlotAreaTerrainType;
|
||||
import com.plotsquared.core.plot.PlotAreaType;
|
||||
import com.plotsquared.core.plot.PlotId;
|
||||
import com.plotsquared.core.plot.comment.CommentManager;
|
||||
import com.plotsquared.core.plot.flag.implementations.ServerPlotFlag;
|
||||
import com.plotsquared.core.plot.message.PlainChatManager;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.plot.world.SinglePlotArea;
|
||||
@ -98,7 +100,7 @@ import com.plotsquared.core.util.ChatManager;
|
||||
import com.plotsquared.core.util.ConsoleColors;
|
||||
import com.plotsquared.core.util.EconHandler;
|
||||
import com.plotsquared.core.util.EventDispatcher;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.FileUtils;
|
||||
import com.plotsquared.core.util.PermHandler;
|
||||
import com.plotsquared.core.util.PlatformWorldManager;
|
||||
import com.plotsquared.core.util.PremiumVerification;
|
||||
@ -420,8 +422,8 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
||||
final SQLiteUUIDService sqLiteUUIDService = new SQLiteUUIDService("user_cache.db");
|
||||
|
||||
final SQLiteUUIDService legacyUUIDService;
|
||||
if (Settings.UUID.LEGACY_DATABASE_SUPPORT && MainUtil
|
||||
.getFile(PlotSquared.platform().getDirectory(), "usercache.db").exists()) {
|
||||
if (Settings.UUID.LEGACY_DATABASE_SUPPORT &&
|
||||
FileUtils.getFile(PlotSquared.platform().getDirectory(), "usercache.db").exists()) {
|
||||
legacyUUIDService = new SQLiteUUIDService("usercache.db");
|
||||
} else {
|
||||
legacyUUIDService = null;
|
||||
@ -584,7 +586,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
||||
}
|
||||
final Plot plot = area.getOwnedPlot(id);
|
||||
if (plot != null) {
|
||||
if (!MainUtil.isServerOwned(plot) || PlotPlayer.wrap(plot.getOwner()) == null) {
|
||||
if (!plot.getFlag(ServerPlotFlag.class) || PlotPlayer.wrap(plot.getOwner()) == null) {
|
||||
if (world.getKeepSpawnInMemory()) {
|
||||
world.setKeepSpawnInMemory(false);
|
||||
return;
|
||||
@ -1070,8 +1072,8 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
||||
String manager = worldConfig.getString("generator.plugin", getPluginName());
|
||||
PlotAreaBuilder builder = PlotAreaBuilder.newBuilder().plotManager(manager)
|
||||
.generatorName(worldConfig.getString("generator.init", manager))
|
||||
.plotAreaType(MainUtil.getType(worldConfig))
|
||||
.terrainType(MainUtil.getTerrain(worldConfig))
|
||||
.plotAreaType(ConfigurationUtil.getType(worldConfig))
|
||||
.terrainType(ConfigurationUtil.getTerrain(worldConfig))
|
||||
.settingsNodesWrapper(new SettingsNodesWrapper(new ConfigurationNode[0], null))
|
||||
.worldName(worldName);
|
||||
getInjector().getInstance(SetupUtils.class).setupWorld(builder);
|
||||
|
@ -36,7 +36,6 @@ import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.queue.ScopedQueueCoordinator;
|
||||
import com.plotsquared.core.util.ChunkManager;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.World;
|
||||
@ -74,7 +73,6 @@ public class BukkitPlotGenerator extends ChunkGenerator
|
||||
this.populators = new ArrayList<>();
|
||||
this.populators.add(new BlockStatePopulator(this.plotGenerator, this.plotAreaManager));
|
||||
this.full = true;
|
||||
MainUtil.initCache();
|
||||
}
|
||||
|
||||
public BukkitPlotGenerator(final String world, final ChunkGenerator cg, @Nonnull final PlotAreaManager plotAreaManager) {
|
||||
@ -87,7 +85,6 @@ public class BukkitPlotGenerator extends ChunkGenerator
|
||||
this.full = false;
|
||||
this.platformGenerator = cg;
|
||||
this.plotGenerator = new DelegatePlotGenerator(cg, world);
|
||||
MainUtil.initCache();
|
||||
}
|
||||
|
||||
@Override public void augment(PlotArea area) {
|
||||
|
@ -30,7 +30,7 @@ import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.flag.GlobalFlagContainer;
|
||||
import com.plotsquared.core.plot.flag.PlotFlag;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.PlayerManager;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -122,7 +122,7 @@ public class Placeholders extends PlaceholderExpansion {
|
||||
}
|
||||
|
||||
try {
|
||||
return MainUtil.getName(plotOwner, false);
|
||||
return PlayerManager.getName(plotOwner, false);
|
||||
} catch (final Exception ignored) {}
|
||||
|
||||
final String name = Bukkit.getOfflinePlayer(plotOwner).getName();
|
||||
|
@ -31,7 +31,7 @@ import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.core.location.ChunkWrapper;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.queue.ScopedQueueCoordinator;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.ChunkUtil;
|
||||
import com.plotsquared.core.util.PatternUtil;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
@ -158,12 +158,12 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
}
|
||||
|
||||
private void storeCache(final int x, final int y, final int z, final BlockState id) {
|
||||
int i = MainUtil.CACHE_I[y][x][z];
|
||||
int i = y >> 4;
|
||||
BlockState[] v = this.result[i];
|
||||
if (v == null) {
|
||||
this.result[i] = v = new BlockState[4096];
|
||||
}
|
||||
int j = MainUtil.CACHE_J[y][x][z];
|
||||
int j = ChunkUtil.getJ(x, y, z);
|
||||
v[j] = id;
|
||||
}
|
||||
|
||||
@ -178,7 +178,7 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
}
|
||||
|
||||
@Override public BlockState getBlock(int x, int y, int z) {
|
||||
int i = MainUtil.CACHE_I[y][x][z];
|
||||
int i = y >> 4;
|
||||
if (result == null) {
|
||||
return BukkitBlockUtil.get(chunkData.getType(x, y, z));
|
||||
}
|
||||
@ -186,7 +186,7 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
if (array == null) {
|
||||
return BlockTypes.AIR.getDefaultState();
|
||||
}
|
||||
int j = MainUtil.CACHE_J[y][x][z];
|
||||
int j = ChunkUtil.getJ(x, y, z);
|
||||
return array[j];
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,6 @@ import com.plotsquared.core.plot.PlotManager;
|
||||
import com.plotsquared.core.queue.QueueCoordinator;
|
||||
import com.plotsquared.core.queue.ScopedQueueCoordinator;
|
||||
import com.plotsquared.core.util.ChunkManager;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.RegionManager;
|
||||
import com.plotsquared.core.util.RegionUtil;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
|
@ -27,11 +27,11 @@ package com.plotsquared.bukkit.uuid;
|
||||
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.database.SQLite;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.FileUtils;
|
||||
import com.plotsquared.core.uuid.UUIDMapping;
|
||||
import com.plotsquared.core.uuid.UUIDService;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
@ -51,7 +51,7 @@ public class SQLiteUUIDService implements UUIDService, Consumer<List<UUIDMapping
|
||||
|
||||
public SQLiteUUIDService(final String fileName) {
|
||||
this.sqlite =
|
||||
new SQLite(MainUtil.getFile(PlotSquared.platform().getDirectory(), fileName));
|
||||
new SQLite(FileUtils.getFile(PlotSquared.platform().getDirectory(), fileName));
|
||||
try {
|
||||
this.sqlite.openConnection();
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
|
@ -59,8 +59,8 @@ import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.plot.world.SinglePlotArea;
|
||||
import com.plotsquared.core.plot.world.SinglePlotAreaManager;
|
||||
import com.plotsquared.core.util.EventDispatcher;
|
||||
import com.plotsquared.core.util.FileUtils;
|
||||
import com.plotsquared.core.util.LegacyConverter;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
import com.plotsquared.core.util.ReflectionUtils;
|
||||
import com.plotsquared.core.util.query.PlotQuery;
|
||||
@ -187,7 +187,7 @@ public class PlotSquared {
|
||||
return;
|
||||
}
|
||||
|
||||
this.translationFile = MainUtil.getFile(this.platform.getDirectory(),
|
||||
this.translationFile = FileUtils.getFile(this.platform.getDirectory(),
|
||||
Settings.Paths.TRANSLATIONS + File.separator + this.platform.getPluginName()
|
||||
+ ".use_THIS.yml");
|
||||
Captions.load(this.translationFile);
|
||||
@ -761,7 +761,7 @@ public class PlotSquared {
|
||||
ConfigurationSection worldSection = this.worldConfiguration.getConfigurationSection(path);
|
||||
PlotAreaType type;
|
||||
if (worldSection != null) {
|
||||
type = MainUtil.getType(worldSection);
|
||||
type = ConfigurationUtil.getType(worldSection);
|
||||
} else {
|
||||
type = PlotAreaType.NORMAL;
|
||||
}
|
||||
@ -1108,7 +1108,7 @@ public class PlotSquared {
|
||||
if (!output.exists()) {
|
||||
output.mkdirs();
|
||||
}
|
||||
File newFile = MainUtil.getFile(output, folder + File.separator + file);
|
||||
File newFile = FileUtils.getFile(output, folder + File.separator + file);
|
||||
if (newFile.exists()) {
|
||||
return;
|
||||
}
|
||||
@ -1225,7 +1225,7 @@ public class PlotSquared {
|
||||
database = new MySQL(Storage.MySQL.HOST, Storage.MySQL.PORT, Storage.MySQL.DATABASE,
|
||||
Storage.MySQL.USER, Storage.MySQL.PASSWORD);
|
||||
} else if (Storage.SQLite.USE) {
|
||||
File file = MainUtil.getFile(platform.getDirectory(), Storage.SQLite.DB + ".db");
|
||||
File file = FileUtils.getFile(platform.getDirectory(), Storage.SQLite.DB + ".db");
|
||||
database = new SQLite(file);
|
||||
} else {
|
||||
logger.error("[P2] No storage type is set. Disabling PlotSquared");
|
||||
@ -1361,7 +1361,7 @@ public class PlotSquared {
|
||||
}
|
||||
try {
|
||||
// TODO: REMOVE
|
||||
File styleFile = MainUtil.getFile(platform.getDirectory(),
|
||||
File styleFile = FileUtils.getFile(platform.getDirectory(),
|
||||
Settings.Paths.TRANSLATIONS + File.separator + "style.yml");
|
||||
if (!styleFile.exists()) {
|
||||
if (!styleFile.getParentFile().exists()) {
|
||||
|
@ -33,6 +33,7 @@ import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.util.EventDispatcher;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.PlayerManager;
|
||||
import com.plotsquared.core.util.TabCompletions;
|
||||
import com.plotsquared.core.util.task.RunnableVal2;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
@ -72,7 +73,7 @@ public class Add extends Command {
|
||||
checkTrue(args.length == 1, Captions.COMMAND_SYNTAX, getUsage());
|
||||
|
||||
final CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||
MainUtil.getUUIDsFromString(args[0], (uuids, throwable) -> {
|
||||
PlayerManager.getUUIDsFromString(args[0], (uuids, throwable) -> {
|
||||
if (throwable != null) {
|
||||
if (throwable instanceof TimeoutException) {
|
||||
Captions.FETCHING_PLAYERS_TIMEOUT.send(player);
|
||||
@ -91,17 +92,17 @@ public class Add extends Command {
|
||||
if (uuid == DBFunc.EVERYONE && !(
|
||||
Permissions.hasPermission(player, Captions.PERMISSION_TRUST_EVERYONE) || Permissions
|
||||
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_TRUST))) {
|
||||
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, MainUtil.getName(uuid));
|
||||
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, PlayerManager.getName(uuid));
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
if (plot.isOwner(uuid)) {
|
||||
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid));
|
||||
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, PlayerManager.getName(uuid));
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
if (plot.getMembers().contains(uuid)) {
|
||||
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid));
|
||||
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, PlayerManager.getName(uuid));
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
|
@ -47,6 +47,7 @@ import com.plotsquared.core.plot.PlotId;
|
||||
import com.plotsquared.core.plot.message.PlotMessage;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.setup.PlotAreaBuilder;
|
||||
import com.plotsquared.core.util.FileUtils;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
@ -186,7 +187,7 @@ public class Area extends SubCommand {
|
||||
hybridPlotWorld.PLOT_HEIGHT = hybridPlotWorld.ROAD_HEIGHT = hybridPlotWorld.WALL_HEIGHT = playerSelectionMin.getBlockY();
|
||||
// No sign plz
|
||||
hybridPlotWorld.setAllowSigns(false);
|
||||
final File parentFile = MainUtil.getFile(PlotSquared.platform().getDirectory(), "schematics" + File.separator +
|
||||
final File parentFile = FileUtils.getFile(PlotSquared.platform().getDirectory(), "schematics" + File.separator +
|
||||
"GEN_ROAD_SCHEMATIC" + File.separator + hybridPlotWorld.getWorldName() + File.separator +
|
||||
hybridPlotWorld.getId());
|
||||
if (!parentFile.exists() && !parentFile.mkdirs()) {
|
||||
|
@ -25,6 +25,7 @@
|
||||
*/
|
||||
package com.plotsquared.core.command;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
@ -50,10 +51,10 @@ import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.task.AutoClaimFinishTask;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@CommandDeclaration(command = "auto",
|
||||
@ -307,7 +308,8 @@ public class Auto extends SubCommand {
|
||||
plot.claim(player, plotId.equals(end), null);
|
||||
}
|
||||
|
||||
ArrayList<PlotId> plotIds = MainUtil.getPlotSelectionIds(start, end);
|
||||
final List<PlotId> plotIds = Lists.newArrayList((Iterable<? extends PlotId>)
|
||||
PlotId.PlotRangeIterator.range(start, end));
|
||||
final PlotId pos1 = plotIds.get(0);
|
||||
final PlotAutoMergeEvent mergeEvent = this.eventDispatcher
|
||||
.callAutoMerge(plotarea.getPlotAbs(pos1), plotIds);
|
||||
|
@ -36,12 +36,11 @@ import com.plotsquared.core.plot.flag.PlotFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.PriceFlag;
|
||||
import com.plotsquared.core.util.EconHandler;
|
||||
import com.plotsquared.core.util.EventDispatcher;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.task.RunnableVal2;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@ -72,7 +71,7 @@ public class Buy extends Command {
|
||||
final Plot plot;
|
||||
if (args.length != 0) {
|
||||
checkTrue(args.length == 1, Captions.COMMAND_SYNTAX, getUsage());
|
||||
plot = check(MainUtil.getPlotFromString(player, args[0], true), null);
|
||||
plot = check(Plot.getPlotFromString(player, args[0], true), null);
|
||||
} else {
|
||||
plot = check(player.getCurrentPlot(), Captions.NOT_IN_PLOT);
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ public class Comment extends SubCommand {
|
||||
// Attempt to extract a plot out of the first argument
|
||||
Plot plot = null;
|
||||
if (!CommentManager.inboxes.containsKey(args[0].toLowerCase(Locale.ENGLISH))) {
|
||||
plot = MainUtil.getPlotFromString(player, args[0], false);
|
||||
plot = Plot.getPlotFromString(player, args[0], false);
|
||||
}
|
||||
|
||||
int index;
|
||||
|
@ -56,7 +56,7 @@ public class Copy extends SubCommand {
|
||||
Captions.COMMAND_SYNTAX.send(player, getUsage());
|
||||
return false;
|
||||
}
|
||||
Plot plot2 = MainUtil.getPlotFromString(player, args[0], true);
|
||||
Plot plot2 = Plot.getPlotFromString(player, args[0], true);
|
||||
if (plot2 == null) {
|
||||
return false;
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ import com.plotsquared.core.plot.PlotId;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.plot.world.SinglePlotArea;
|
||||
import com.plotsquared.core.util.EventDispatcher;
|
||||
import com.plotsquared.core.util.FileUtils;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.query.PlotQuery;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
@ -125,7 +126,7 @@ public class DatabaseCommand extends SubCommand {
|
||||
.sendMessage(player, "/plot database import <sqlite file> [prefix]");
|
||||
return false;
|
||||
}
|
||||
File file = MainUtil.getFile(PlotSquared.platform().getDirectory(),
|
||||
File file = FileUtils.getFile(PlotSquared.platform().getDirectory(),
|
||||
args[1].endsWith(".db") ? args[1] : args[1] + ".db");
|
||||
if (!file.exists()) {
|
||||
MainUtil.sendMessage(player, "&6Database does not exist: " + file);
|
||||
@ -200,7 +201,7 @@ public class DatabaseCommand extends SubCommand {
|
||||
return MainUtil.sendMessage(player, "/plot database sqlite [file]");
|
||||
}
|
||||
File sqliteFile =
|
||||
MainUtil.getFile(PlotSquared.platform().getDirectory(), args[1] + ".db");
|
||||
FileUtils.getFile(PlotSquared.platform().getDirectory(), args[1] + ".db");
|
||||
implementation = new SQLite(sqliteFile);
|
||||
break;
|
||||
default:
|
||||
|
@ -50,6 +50,7 @@ import com.plotsquared.core.queue.GlobalBlockQueue;
|
||||
import com.plotsquared.core.util.ChunkManager;
|
||||
import com.plotsquared.core.util.EconHandler;
|
||||
import com.plotsquared.core.util.EventDispatcher;
|
||||
import com.plotsquared.core.util.FileUtils;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
import com.plotsquared.core.util.SchematicHandler;
|
||||
@ -63,11 +64,11 @@ import com.plotsquared.core.util.task.RunnableVal3;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.script.Bindings;
|
||||
import javax.script.ScriptContext;
|
||||
import javax.script.ScriptEngine;
|
||||
@ -327,7 +328,7 @@ public class DebugExec extends SubCommand {
|
||||
return false;
|
||||
case "addcmd":
|
||||
try {
|
||||
final String cmd = StringMan.join(Files.readLines(MainUtil.getFile(new File(
|
||||
final String cmd = StringMan.join(Files.readLines(FileUtils.getFile(new File(
|
||||
PlotSquared.platform().getDirectory() + File.separator
|
||||
+ Settings.Paths.SCRIPTS), args[1]), StandardCharsets.UTF_8),
|
||||
System.getProperty("line.separator"));
|
||||
@ -359,7 +360,7 @@ public class DebugExec extends SubCommand {
|
||||
async = true;
|
||||
case "run":
|
||||
try {
|
||||
script = StringMan.join(Files.readLines(MainUtil.getFile(new File(
|
||||
script = StringMan.join(Files.readLines(FileUtils.getFile(new File(
|
||||
PlotSquared.platform().getDirectory() + File.separator
|
||||
+ Settings.Paths.SCRIPTS), args[1]), StandardCharsets.UTF_8),
|
||||
System.getProperty("line.separator"));
|
||||
|
@ -36,6 +36,7 @@ import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.util.EventDispatcher;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.PlayerManager;
|
||||
import com.plotsquared.core.util.TabCompletions;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
import com.sk89q.worldedit.world.gamemode.GameModes;
|
||||
@ -84,7 +85,7 @@ public class Deny extends SubCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
MainUtil.getUUIDsFromString(args[0], (uuids, throwable) -> {
|
||||
PlayerManager.getUUIDsFromString(args[0], (uuids, throwable) -> {
|
||||
if (throwable instanceof TimeoutException) {
|
||||
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
|
||||
} else if (throwable != null || uuids.isEmpty()) {
|
||||
@ -94,12 +95,12 @@ public class Deny extends SubCommand {
|
||||
if (uuid == DBFunc.EVERYONE && !(
|
||||
Permissions.hasPermission(player, Captions.PERMISSION_DENY_EVERYONE) || Permissions
|
||||
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_DENY))) {
|
||||
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, MainUtil.getName(uuid));
|
||||
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, PlayerManager.getName(uuid));
|
||||
} else if (plot.isOwner(uuid)) {
|
||||
MainUtil.sendMessage(player, Captions.CANT_REMOVE_OWNER, MainUtil.getName(uuid));
|
||||
MainUtil.sendMessage(player, Captions.CANT_REMOVE_OWNER, PlayerManager.getName(uuid));
|
||||
return;
|
||||
} else if (plot.getDenied().contains(uuid)) {
|
||||
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid));
|
||||
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, PlayerManager.getName(uuid));
|
||||
return;
|
||||
} else {
|
||||
if (uuid != DBFunc.EVERYONE) {
|
||||
|
@ -33,13 +33,16 @@ import com.plotsquared.core.database.DBFunc;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.PlayerManager;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
import com.plotsquared.core.util.task.RunnableVal2;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@CommandDeclaration(command = "grant",
|
||||
category = CommandCategory.CLAIMING,
|
||||
@ -70,16 +73,14 @@ public class Grant extends Command {
|
||||
if (args.length > 2) {
|
||||
break;
|
||||
}
|
||||
MainUtil.getUUIDsFromString(args[1], (uuids, throwable) -> {
|
||||
PlayerManager.getUUIDsFromString(args[1], (uuids, throwable) -> {
|
||||
if (throwable instanceof TimeoutException) {
|
||||
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
|
||||
} else if (throwable != null || uuids.size() != 1) {
|
||||
MainUtil.sendMessage(player, Captions.INVALID_PLAYER);
|
||||
} else {
|
||||
final UUID uuid = uuids.toArray(new UUID[0])[0];
|
||||
MainUtil.getPersistentMeta(uuid,
|
||||
"grantedPlots", new RunnableVal<byte[]>() {
|
||||
@Override public void run(byte[] array) {
|
||||
final Consumer<byte[]> result = array -> {
|
||||
if (arg0.equals("check")) { // check
|
||||
int granted;
|
||||
if (array == null) {
|
||||
@ -106,9 +107,18 @@ public class Grant extends Command {
|
||||
DBFunc.addPersistentMeta(uuid, key, rawData, replace);
|
||||
}
|
||||
}
|
||||
};
|
||||
PlotPlayer<?> pp = PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuid);
|
||||
if (pp != null) {
|
||||
result.accept(player.getPersistentMeta("grantedPlots"));
|
||||
} else {
|
||||
DBFunc.getPersistentMeta(uuid, new RunnableVal<Map<String, byte[]>>() {
|
||||
@Override public void run(Map<String, byte[]> value) {
|
||||
result.accept(value.get("grantedPlots"));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
return CompletableFuture.completedFuture(true);
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ public class HomeCommand extends Command {
|
||||
break;
|
||||
}
|
||||
// either plot id or alias
|
||||
Plot fromId = MainUtil.getPlotFromString(player, identifier, false);
|
||||
Plot fromId = Plot.getPlotFromString(player, identifier, false);
|
||||
if (fromId != null && fromId.isOwner(player.getUUID())) {
|
||||
// it was a valid plot id
|
||||
basePlotOnly = false;
|
||||
|
@ -32,7 +32,6 @@ import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.flag.implementations.HideInfoFlag;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
|
||||
@CommandDeclaration(command = "info",
|
||||
aliases = "i",
|
||||
@ -60,10 +59,10 @@ public class Info extends SubCommand {
|
||||
case "owner":
|
||||
case "rating":
|
||||
case "likes":
|
||||
plot = MainUtil.getPlotFromString(player, null, false);
|
||||
plot = Plot.getPlotFromString(player, null, false);
|
||||
break;
|
||||
default:
|
||||
plot = MainUtil.getPlotFromString(player, arg, false);
|
||||
plot = Plot.getPlotFromString(player, arg, false);
|
||||
if (args.length == 2) {
|
||||
arg = args[1];
|
||||
} else {
|
||||
@ -141,13 +140,9 @@ public class Info extends SubCommand {
|
||||
} else {
|
||||
full = false;
|
||||
}
|
||||
MainUtil.format(info, plot, player, full, new RunnableVal<String>() {
|
||||
@Override public void run(String value) {
|
||||
MainUtil.sendMessage(player,
|
||||
Captions.PLOT_INFO_HEADER.getTranslated() + '\n' + value + '\n'
|
||||
+ Captions.PLOT_INFO_FOOTER.getTranslated(), false);
|
||||
}
|
||||
});
|
||||
plot.format(info, player, full).thenAcceptAsync(value ->
|
||||
player.sendMessage(Captions.PLOT_INFO_HEADER.getTranslated() + '\n' + value + '\n'
|
||||
+ Captions.PLOT_INFO_FOOTER.getTranslated()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,7 @@ import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.PlayerManager;
|
||||
import com.plotsquared.core.util.TabCompletions;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
import javax.annotation.Nonnull;
|
||||
@ -77,7 +78,7 @@ public class Kick extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
|
||||
MainUtil.getUUIDsFromString(args[0], (uuids, throwable) -> {
|
||||
PlayerManager.getUUIDsFromString(args[0], (uuids, throwable) -> {
|
||||
if (throwable instanceof TimeoutException) {
|
||||
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
|
||||
} else if (throwable != null || uuids.isEmpty()) {
|
||||
|
@ -42,6 +42,7 @@ import com.plotsquared.core.util.EconHandler;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.PlayerManager;
|
||||
import com.plotsquared.core.util.StringComparison;
|
||||
import com.plotsquared.core.util.StringMan;
|
||||
import com.plotsquared.core.util.TabCompletions;
|
||||
@ -378,11 +379,11 @@ public class ListCmd extends SubCommand {
|
||||
}
|
||||
PlotMessage trusted = new PlotMessage().text(Captions.color(
|
||||
Captions.PLOT_INFO_TRUSTED.getTranslated()
|
||||
.replaceAll("%trusted%", MainUtil.getPlayerList(plot.getTrusted()))))
|
||||
.replaceAll("%trusted%", PlayerManager.getPlayerList(plot.getTrusted()))))
|
||||
.color("$1");
|
||||
PlotMessage members = new PlotMessage().text(Captions.color(
|
||||
Captions.PLOT_INFO_MEMBERS.getTranslated()
|
||||
.replaceAll("%members%", MainUtil.getPlayerList(plot.getMembers()))))
|
||||
.replaceAll("%members%", PlayerManager.getPlayerList(plot.getMembers()))))
|
||||
.color("$1");
|
||||
message.text("[").color("$3").text(i + "")
|
||||
.command("/plot visit " + plot.getArea() + ";" + plot.getId())
|
||||
|
@ -81,7 +81,7 @@ public class Move extends SubCommand {
|
||||
PlotArea area = this.plotAreaManager.getPlotAreaByString(args[0]);
|
||||
Plot plot2;
|
||||
if (area == null) {
|
||||
plot2 = MainUtil.getPlotFromString(player, args[0], true);
|
||||
plot2 = Plot.getPlotFromString(player, args[0], true);
|
||||
if (plot2 == null) {
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.util.EventDispatcher;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.PlayerManager;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@ -102,9 +103,9 @@ public class Owner extends SetCommand {
|
||||
MainUtil.sendMessage(player, Captions.SET_OWNER);
|
||||
return;
|
||||
}
|
||||
final PlotPlayer other = PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuid);
|
||||
final PlotPlayer<?> other = PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuid);
|
||||
if (plot.isOwner(uuid)) {
|
||||
Captions.ALREADY_OWNER.send(player, MainUtil.getName(uuid));
|
||||
Captions.ALREADY_OWNER.send(player, PlayerManager.getName(uuid));
|
||||
return;
|
||||
}
|
||||
if (!force && !Permissions
|
||||
|
@ -34,6 +34,7 @@ import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.util.EventDispatcher;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.PlayerManager;
|
||||
import com.plotsquared.core.util.TabCompletions;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@ -74,7 +75,7 @@ public class Remove extends SubCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
MainUtil.getUUIDsFromString(args[0], (uuids, throwable) -> {
|
||||
PlayerManager.getUUIDsFromString(args[0], (uuids, throwable) -> {
|
||||
int count = 0;
|
||||
if (throwable instanceof TimeoutException) {
|
||||
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
|
||||
|
@ -63,7 +63,7 @@ public class Swap extends SubCommand {
|
||||
Captions.COMMAND_SYNTAX.send(player, getUsage());
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
Plot plot2 = MainUtil.getPlotFromString(player, args[0], true);
|
||||
Plot plot2 = Plot.getPlotFromString(player, args[0], true);
|
||||
if (plot2 == null) {
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ public class Target extends SubCommand {
|
||||
MainUtil.sendMessage(player, Captions.FOUND_NO_PLOTS);
|
||||
return false;
|
||||
}
|
||||
} else if ((target = MainUtil.getPlotFromString(player, args[0], true)) == null) {
|
||||
} else if ((target = Plot.getPlotFromString(player, args[0], true)) == null) {
|
||||
return false;
|
||||
}
|
||||
target.getCenter(player::setCompassTarget);
|
||||
|
@ -27,6 +27,7 @@ package com.plotsquared.core.command;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.ConfigurationUtil;
|
||||
import com.plotsquared.core.inject.annotations.WorldConfig;
|
||||
import com.plotsquared.core.inject.annotations.WorldFile;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
@ -44,6 +45,7 @@ import com.plotsquared.core.queue.GlobalBlockQueue;
|
||||
import com.plotsquared.core.setup.PlotAreaBuilder;
|
||||
import com.plotsquared.core.setup.SettingsNodesWrapper;
|
||||
import com.plotsquared.core.util.FileBytes;
|
||||
import com.plotsquared.core.util.FileUtils;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.SetupUtils;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
@ -87,7 +89,7 @@ public class Template extends SubCommand {
|
||||
public static boolean extractAllFiles(String world, String template) {
|
||||
try {
|
||||
File folder =
|
||||
MainUtil.getFile(PlotSquared.platform().getDirectory(), Settings.Paths.TEMPLATES);
|
||||
FileUtils.getFile(PlotSquared.platform().getDirectory(), Settings.Paths.TEMPLATES);
|
||||
if (!folder.exists()) {
|
||||
return false;
|
||||
}
|
||||
@ -141,8 +143,7 @@ public class Template extends SubCommand {
|
||||
}
|
||||
|
||||
public static void zipAll(String world, Set<FileBytes> files) throws IOException {
|
||||
File output =
|
||||
MainUtil.getFile(PlotSquared.platform().getDirectory(), Settings.Paths.TEMPLATES);
|
||||
File output = FileUtils.getFile(PlotSquared.platform().getDirectory(), Settings.Paths.TEMPLATES);
|
||||
output.mkdirs();
|
||||
try (FileOutputStream fos = new FileOutputStream(
|
||||
output + File.separator + world + ".template");
|
||||
@ -191,7 +192,7 @@ public class Template extends SubCommand {
|
||||
.sendMessage(player, "&cInvalid template file: " + args[2] + ".template");
|
||||
return false;
|
||||
}
|
||||
File worldFile = MainUtil.getFile(PlotSquared.platform().getDirectory(),
|
||||
File worldFile = FileUtils.getFile(PlotSquared.platform().getDirectory(),
|
||||
Settings.Paths.TEMPLATES + File.separator + "tmp-data.yml");
|
||||
YamlConfiguration worldConfig = YamlConfiguration.loadConfiguration(worldFile);
|
||||
this.worldConfiguration.set("worlds." + world, worldConfig.get(""));
|
||||
@ -205,8 +206,8 @@ public class Template extends SubCommand {
|
||||
worldConfig.getString("generator.plugin", PlotSquared.platform().getPluginName());
|
||||
String generator = worldConfig.getString("generator.init", manager);
|
||||
PlotAreaBuilder builder = PlotAreaBuilder.newBuilder()
|
||||
.plotAreaType(MainUtil.getType(worldConfig))
|
||||
.terrainType(MainUtil.getTerrain(worldConfig))
|
||||
.plotAreaType(ConfigurationUtil.getType(worldConfig))
|
||||
.terrainType(ConfigurationUtil.getTerrain(worldConfig))
|
||||
.plotManager(manager)
|
||||
.generatorName(generator)
|
||||
.settingsNodesWrapper(new SettingsNodesWrapper(new ConfigurationNode[0], null))
|
||||
|
@ -33,6 +33,7 @@ import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.util.EventDispatcher;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.PlayerManager;
|
||||
import com.plotsquared.core.util.TabCompletions;
|
||||
import com.plotsquared.core.util.task.RunnableVal2;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
@ -75,7 +76,7 @@ public class Trust extends Command {
|
||||
checkTrue(args.length == 1, Captions.COMMAND_SYNTAX, getUsage());
|
||||
|
||||
final CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||
MainUtil.getUUIDsFromString(args[0], (uuids, throwable) -> {
|
||||
PlayerManager.getUUIDsFromString(args[0], (uuids, throwable) -> {
|
||||
if (throwable != null) {
|
||||
if (throwable instanceof TimeoutException) {
|
||||
Captions.FETCHING_PLAYERS_TIMEOUT.send(player);
|
||||
@ -93,17 +94,17 @@ public class Trust extends Command {
|
||||
if (uuid == DBFunc.EVERYONE && !(
|
||||
Permissions.hasPermission(player, Captions.PERMISSION_TRUST_EVERYONE) || Permissions
|
||||
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_TRUST))) {
|
||||
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, MainUtil.getName(uuid));
|
||||
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, PlayerManager.getName(uuid));
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
if (currentPlot.isOwner(uuid)) {
|
||||
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid));
|
||||
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, PlayerManager.getName(uuid));
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
if (currentPlot.getTrusted().contains(uuid)) {
|
||||
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid));
|
||||
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, PlayerManager.getName(uuid));
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.PlayerManager;
|
||||
import com.plotsquared.core.util.TabCompletions;
|
||||
import com.plotsquared.core.util.query.PlotQuery;
|
||||
import com.plotsquared.core.util.query.SortingStrategy;
|
||||
@ -178,7 +179,7 @@ public class Visit extends Command {
|
||||
|
||||
final PlotArea finalSortByArea = sortByArea;
|
||||
int finalPage1 = page;
|
||||
MainUtil.getUUIDsFromString(args[0], (uuids, throwable) -> {
|
||||
PlayerManager.getUUIDsFromString(args[0], (uuids, throwable) -> {
|
||||
if (throwable instanceof TimeoutException) {
|
||||
Captions.FETCHING_PLAYERS_TIMEOUT.send(player);
|
||||
} else if (throwable != null || uuids.size() != 1) {
|
||||
@ -219,7 +220,7 @@ public class Visit extends Command {
|
||||
});
|
||||
} else {
|
||||
// Try to parse a plot
|
||||
final Plot plot = MainUtil.getPlotFromString(player, finalArgs[0], true);
|
||||
final Plot plot = Plot.getPlotFromString(player, finalArgs[0], true);
|
||||
if (plot != null) {
|
||||
this.visit(player, PlotQuery.newQuery().withPlot(plot), null, confirm, whenDone, 1);
|
||||
}
|
||||
|
@ -26,6 +26,9 @@
|
||||
package com.plotsquared.core.configuration;
|
||||
|
||||
import com.plotsquared.core.plot.BlockBucket;
|
||||
import com.plotsquared.core.plot.PlotAreaTerrainType;
|
||||
import com.plotsquared.core.plot.PlotAreaType;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
||||
@ -33,6 +36,10 @@ import com.sk89q.worldedit.world.block.BlockState;
|
||||
import lombok.Getter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.IntFunction;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
||||
/**
|
||||
@ -101,6 +108,29 @@ public class ConfigurationUtil {
|
||||
}
|
||||
};
|
||||
|
||||
private static <T> T getValueFromConfig(ConfigurationSection config, String path,
|
||||
IntFunction<Optional<T>> intParser, Function<String, Optional<T>> textualParser,
|
||||
Supplier<T> defaultValue) {
|
||||
String value = config.getString(path);
|
||||
if (value == null) {
|
||||
return defaultValue.get();
|
||||
}
|
||||
if (MathMan.isInteger(value)) {
|
||||
return intParser.apply(Integer.parseInt(value)).orElseGet(defaultValue);
|
||||
}
|
||||
return textualParser.apply(value).orElseGet(defaultValue);
|
||||
}
|
||||
|
||||
public static PlotAreaType getType(ConfigurationSection config) {
|
||||
return getValueFromConfig(config, "generator.type", PlotAreaType::fromLegacyInt,
|
||||
PlotAreaType::fromString, () -> PlotAreaType.NORMAL);
|
||||
}
|
||||
|
||||
public static PlotAreaTerrainType getTerrain(ConfigurationSection config) {
|
||||
return getValueFromConfig(config, "generator.terrain", PlotAreaTerrainType::fromLegacyInt,
|
||||
PlotAreaTerrainType::fromString, () -> PlotAreaTerrainType.NONE);
|
||||
}
|
||||
|
||||
|
||||
public static final class UnknownBlockException extends IllegalArgumentException {
|
||||
|
||||
|
@ -47,6 +47,7 @@ import com.plotsquared.core.plot.flag.GlobalFlagContainer;
|
||||
import com.plotsquared.core.plot.flag.PlotFlag;
|
||||
import com.plotsquared.core.plot.flag.types.BlockTypeListFlag;
|
||||
import com.plotsquared.core.util.EventDispatcher;
|
||||
import com.plotsquared.core.util.HashUtil;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.StringMan;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
@ -934,7 +935,7 @@ public class SQLManager implements AbstractDB {
|
||||
preparedStatement.setString(7, legacySettings.settings.getAlias());
|
||||
}
|
||||
boolean[] merged = legacySettings.settings.getMerged();
|
||||
int hash = MainUtil.hash(merged);
|
||||
int hash = HashUtil.hash(merged);
|
||||
preparedStatement.setInt(8, hash);
|
||||
BlockLoc loc = legacySettings.settings.getPosition();
|
||||
String position;
|
||||
@ -2049,7 +2050,7 @@ public class SQLManager implements AbstractDB {
|
||||
plot.getSettings().setMerged(merged);
|
||||
addPlotTask(plot, new UniqueStatement("setMerged") {
|
||||
@Override public void set(PreparedStatement statement) throws SQLException {
|
||||
int hash = MainUtil.hash(merged);
|
||||
int hash = HashUtil.hash(merged);
|
||||
statement.setInt(1, hash);
|
||||
statement.setInt(2, getId(plot));
|
||||
}
|
||||
|
@ -37,9 +37,10 @@ import com.plotsquared.core.plot.PlotId;
|
||||
import com.plotsquared.core.queue.QueueCoordinator;
|
||||
import com.plotsquared.core.util.ChunkManager;
|
||||
import com.plotsquared.core.util.FileBytes;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.FileUtils;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
import com.plotsquared.core.util.RegionManager;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
@ -53,6 +54,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
|
||||
public class HybridPlotManager extends ClassicPlotManager {
|
||||
|
||||
@ -77,20 +79,21 @@ public class HybridPlotManager extends ClassicPlotManager {
|
||||
.getWorldName() + File.separator;
|
||||
try {
|
||||
File sideRoad =
|
||||
MainUtil.getFile(PlotSquared.platform().getDirectory(), dir + "sideroad.schem");
|
||||
FileUtils.getFile(PlotSquared.platform().getDirectory(), dir + "sideroad.schem");
|
||||
String newDir = "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator
|
||||
+ "__TEMP_DIR__" + File.separator;
|
||||
if (sideRoad.exists()) {
|
||||
files.add(new FileBytes(newDir + "sideroad.schem",
|
||||
Files.readAllBytes(sideRoad.toPath())));
|
||||
}
|
||||
File intersection =
|
||||
MainUtil.getFile(PlotSquared.platform().getDirectory(), dir + "intersection.schem");
|
||||
File intersection = FileUtils
|
||||
.getFile(PlotSquared.platform().getDirectory(), dir + "intersection.schem");
|
||||
if (intersection.exists()) {
|
||||
files.add(new FileBytes(newDir + "intersection.schem",
|
||||
Files.readAllBytes(intersection.toPath())));
|
||||
}
|
||||
File plot = MainUtil.getFile(PlotSquared.platform().getDirectory(), dir + "plot.schem");
|
||||
File plot =
|
||||
FileUtils.getFile(PlotSquared.platform().getDirectory(), dir + "plot.schem");
|
||||
if (plot.exists()) {
|
||||
files.add(new FileBytes(newDir + "plot.schem", Files.readAllBytes(plot.toPath())));
|
||||
}
|
||||
@ -111,7 +114,7 @@ public class HybridPlotManager extends ClassicPlotManager {
|
||||
Location pos2 = Location
|
||||
.at(hybridPlotWorld.getWorldName(), bot.getX(), Math.min(getWorldHeight(), 255),
|
||||
top.getZ() + 1);
|
||||
MainUtil.resetBiome(hybridPlotWorld, pos1, pos2);
|
||||
this.resetBiome(hybridPlotWorld, pos1, pos2);
|
||||
if (!hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
|
||||
return true;
|
||||
}
|
||||
@ -121,6 +124,18 @@ public class HybridPlotManager extends ClassicPlotManager {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void resetBiome(@Nonnull final HybridPlotWorld hybridPlotWorld,
|
||||
@Nonnull final Location pos1, @Nonnull final Location pos2) {
|
||||
BiomeType biome = hybridPlotWorld.getPlotBiome();
|
||||
if (!Objects.equals(PlotSquared.platform().getWorldUtil()
|
||||
.getBiomeSynchronous(hybridPlotWorld.getWorldName(), (pos1.getX() + pos2.getX()) / 2,
|
||||
(pos1.getZ() + pos2.getZ()) / 2), biome)) {
|
||||
WorldUtil
|
||||
.setBiome(hybridPlotWorld.getWorldName(), pos1.getX(), pos1.getZ(), pos2.getX(),
|
||||
pos2.getZ(), biome);
|
||||
}
|
||||
}
|
||||
|
||||
private void createSchemAbs(QueueCoordinator queue, Location pos1, Location pos2,
|
||||
boolean isRoad) {
|
||||
int size = hybridPlotWorld.SIZE;
|
||||
@ -174,7 +189,7 @@ public class HybridPlotManager extends ClassicPlotManager {
|
||||
Location pos2 = Location
|
||||
.at(hybridPlotWorld.getWorldName(), top.getX() + 1, Math.min(getWorldHeight(), 255),
|
||||
bot.getZ());
|
||||
MainUtil.resetBiome(hybridPlotWorld, pos1, pos2);
|
||||
this.resetBiome(hybridPlotWorld, pos1, pos2);
|
||||
if (!hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
|
||||
return true;
|
||||
}
|
||||
@ -242,7 +257,7 @@ public class HybridPlotManager extends ClassicPlotManager {
|
||||
}
|
||||
/* Otherwise we need to set each component, as we don't want to regenerate the road or other plots that share the same chunk.*/
|
||||
// Set the biome
|
||||
MainUtil.setBiome(world, value[2], value[3], value[4], value[5], biome);
|
||||
WorldUtil.setBiome(world, value[2], value[3], value[4], value[5], biome);
|
||||
// These two locations are for each component (e.g. bedrock, main block, floor, air)
|
||||
Location bot = Location.at(world, value[2], 0, value[3]);
|
||||
Location top = Location.at(world, value[4], 1, value[5]);
|
||||
|
@ -39,7 +39,7 @@ import com.plotsquared.core.plot.PlotManager;
|
||||
import com.plotsquared.core.plot.schematic.Schematic;
|
||||
import com.plotsquared.core.queue.GlobalBlockQueue;
|
||||
import com.plotsquared.core.util.EconHandler;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.FileUtils;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
import com.plotsquared.core.util.RegionManager;
|
||||
import com.plotsquared.core.util.SchematicHandler;
|
||||
@ -56,11 +56,11 @@ import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import lombok.Getter;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
@ -219,9 +219,9 @@ public class HybridPlotWorld extends ClassicPlotWorld {
|
||||
|
||||
// Try to determine root. This means that plot areas can have separate schematic
|
||||
// directories
|
||||
if (!(root = MainUtil.getFile(PlotSquared.platform().getDirectory(), "schematics/GEN_ROAD_SCHEMATIC/" +
|
||||
if (!(root = FileUtils.getFile(PlotSquared.platform().getDirectory(), "schematics/GEN_ROAD_SCHEMATIC/" +
|
||||
this.getWorldName() + "/" + this.getId())).exists()) {
|
||||
root = MainUtil.getFile(PlotSquared.platform().getDirectory(),
|
||||
root = FileUtils.getFile(PlotSquared.platform().getDirectory(),
|
||||
"schematics/GEN_ROAD_SCHEMATIC/" + this.getWorldName());
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,6 @@ import com.plotsquared.core.queue.ChunkQueueCoordinator;
|
||||
import com.plotsquared.core.queue.GlobalBlockQueue;
|
||||
import com.plotsquared.core.queue.QueueCoordinator;
|
||||
import com.plotsquared.core.util.ChunkManager;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
import com.plotsquared.core.util.RegionManager;
|
||||
import com.plotsquared.core.util.RegionUtil;
|
||||
@ -141,7 +140,6 @@ public class HybridUtils {
|
||||
final int cbz = bz >> 4;
|
||||
final int ctx = tx >> 4;
|
||||
final int ctz = tz >> 4;
|
||||
MainUtil.initCache();
|
||||
final int width = tx - bx + 1;
|
||||
final int length = tz - bz + 1;
|
||||
|
||||
@ -251,7 +249,6 @@ public class HybridUtils {
|
||||
whenDone.run();
|
||||
});
|
||||
System.gc();
|
||||
MainUtil.initCache();
|
||||
Location botLoc = Location.at(world, bot.getX(), bot.getY(), bot.getZ());
|
||||
Location topLoc = Location.at(world, top.getX(), top.getY(), top.getZ());
|
||||
ChunkManager.chunkTask(botLoc, topLoc, new RunnableVal<int[]>() {
|
||||
|
@ -31,7 +31,7 @@ import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.PlotId;
|
||||
import com.plotsquared.core.queue.QueueCoordinator;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.HashUtil;
|
||||
import com.plotsquared.core.util.RegionManager;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import org.slf4j.Logger;
|
||||
@ -198,7 +198,7 @@ public abstract class SquarePlotManager extends GridPlotManager {
|
||||
PlotId id = PlotId.of(dx, dz);
|
||||
boolean[] merged =
|
||||
new boolean[] {rz <= pathWidthLower, rx > end, rz > end, rx <= pathWidthLower};
|
||||
int hash = MainUtil.hash(merged);
|
||||
int hash = HashUtil.hash(merged);
|
||||
// Not merged, and no need to check if it is
|
||||
if (hash == 0) {
|
||||
return id;
|
||||
|
@ -58,16 +58,16 @@ import com.plotsquared.core.plot.flag.types.TimedFlag;
|
||||
import com.plotsquared.core.util.EventDispatcher;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.PlayerManager;
|
||||
import com.plotsquared.core.util.StringMan;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.plotsquared.core.util.task.TaskTime;
|
||||
import com.sk89q.worldedit.world.gamemode.GameMode;
|
||||
import com.sk89q.worldedit.world.gamemode.GameModes;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
import com.sk89q.worldedit.world.item.ItemTypes;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
@ -155,12 +155,8 @@ public class PlotListener {
|
||||
|
||||
final String greeting = plot.getFlag(GreetingFlag.class);
|
||||
if (!greeting.isEmpty()) {
|
||||
MainUtil.format(Captions.PREFIX_GREETING.getTranslated() + greeting, plot, player,
|
||||
false, new RunnableVal<String>() {
|
||||
@Override public void run(String value) {
|
||||
MainUtil.sendMessage(player, value);
|
||||
}
|
||||
});
|
||||
plot.format(Captions.PREFIX_GREETING.getTranslated() + greeting, player, false)
|
||||
.thenAcceptAsync(player::sendMessage);
|
||||
}
|
||||
|
||||
if (plot.getFlag(NotifyEnterFlag.class)) {
|
||||
@ -271,7 +267,7 @@ public class PlotListener {
|
||||
replacements.put("%world%", plot.getArea().toString());
|
||||
replacements.put("%greeting%", greeting);
|
||||
replacements.put("%alias", plot.toString());
|
||||
replacements.put("%s", MainUtil.getName(plot.getOwner()));
|
||||
replacements.put("%s", PlayerManager.getName(plot.getOwner()));
|
||||
String main = StringMan
|
||||
.replaceFromMap(Captions.TITLE_ENTERED_PLOT.getTranslated(),
|
||||
replacements);
|
||||
@ -331,12 +327,8 @@ public class PlotListener {
|
||||
|
||||
final String farewell = plot.getFlag(FarewellFlag.class);
|
||||
if (!farewell.isEmpty()) {
|
||||
MainUtil.format(Captions.PREFIX_FAREWELL.getTranslated() + farewell, plot, player,
|
||||
false, new RunnableVal<String>() {
|
||||
@Override public void run(String value) {
|
||||
MainUtil.sendMessage(player, value);
|
||||
}
|
||||
});
|
||||
plot.format(Captions.PREFIX_FAREWELL.getTranslated() + farewell, player, false)
|
||||
.thenAcceptAsync(player::sendMessage);
|
||||
}
|
||||
|
||||
if (plot.getFlag(NotifyLeaveFlag.class)) {
|
||||
|
@ -26,9 +26,12 @@
|
||||
package com.plotsquared.core.plot;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.command.Like;
|
||||
import com.plotsquared.core.configuration.CaptionUtility;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.configuration.ConfigurationUtil;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
@ -45,6 +48,7 @@ import com.plotsquared.core.location.BlockLoc;
|
||||
import com.plotsquared.core.location.Direction;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.location.PlotLoc;
|
||||
import com.plotsquared.core.player.ConsolePlayer;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.comment.PlotComment;
|
||||
import com.plotsquared.core.plot.expiration.ExpireManager;
|
||||
@ -53,7 +57,10 @@ import com.plotsquared.core.plot.flag.FlagContainer;
|
||||
import com.plotsquared.core.plot.flag.GlobalFlagContainer;
|
||||
import com.plotsquared.core.plot.flag.InternalFlag;
|
||||
import com.plotsquared.core.plot.flag.PlotFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.DescriptionFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.KeepFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.ServerPlotFlag;
|
||||
import com.plotsquared.core.plot.flag.types.DoubleFlag;
|
||||
import com.plotsquared.core.plot.schematic.Schematic;
|
||||
import com.plotsquared.core.queue.GlobalBlockQueue;
|
||||
import com.plotsquared.core.queue.QueueCoordinator;
|
||||
@ -61,9 +68,13 @@ import com.plotsquared.core.util.EventDispatcher;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.PlayerManager;
|
||||
import com.plotsquared.core.util.RegionManager;
|
||||
import com.plotsquared.core.util.RegionUtil;
|
||||
import com.plotsquared.core.util.SchematicHandler;
|
||||
import com.plotsquared.core.util.TimeUtil;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
import com.plotsquared.core.util.query.PlotQuery;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.plotsquared.core.util.task.TaskTime;
|
||||
@ -86,6 +97,7 @@ import java.awt.geom.PathIterator;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -125,22 +137,17 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE;
|
||||
public class Plot {
|
||||
|
||||
public static final int MAX_HEIGHT = 256;
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger("P2/" + Plot.class.getSimpleName());
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger("P2/" + Plot.class.getSimpleName());
|
||||
private static final DecimalFormat FLAG_DECIMAL_FORMAT = new DecimalFormat("0");
|
||||
|
||||
static {
|
||||
FLAG_DECIMAL_FORMAT.setMaximumFractionDigits(340);
|
||||
}
|
||||
|
||||
private static Set<Plot> connected_cache;
|
||||
private static Set<CuboidRegion> regions_cache;
|
||||
|
||||
@Nonnull private PlotId id;
|
||||
|
||||
// These will be injected
|
||||
@Inject private EventDispatcher eventDispatcher;
|
||||
@Inject private PlotListener plotListener;
|
||||
@Inject private RegionManager regionManager;
|
||||
@Inject private GlobalBlockQueue blockQueue;
|
||||
@Inject private WorldUtil worldUtil;
|
||||
@Inject private SchematicHandler schematicHandler;
|
||||
@Inject @ImpromptuPipeline private UUIDPipeline impromptuPipeline;
|
||||
|
||||
/**
|
||||
* Plot flag container
|
||||
*/
|
||||
@ -157,6 +164,15 @@ public class Plot {
|
||||
* @deprecated magical
|
||||
*/
|
||||
@Deprecated public int temp;
|
||||
@Nonnull private PlotId id;
|
||||
// These will be injected
|
||||
@Inject private EventDispatcher eventDispatcher;
|
||||
@Inject private PlotListener plotListener;
|
||||
@Inject private RegionManager regionManager;
|
||||
@Inject private GlobalBlockQueue blockQueue;
|
||||
@Inject private WorldUtil worldUtil;
|
||||
@Inject private SchematicHandler schematicHandler;
|
||||
@Inject @ImpromptuPipeline private UUIDPipeline impromptuPipeline;
|
||||
/**
|
||||
* plot owner
|
||||
* (Merged plots can have multiple owners)
|
||||
@ -282,6 +298,72 @@ public class Plot {
|
||||
PlotSquared.platform().getInjector().injectMembers(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plot from a string.
|
||||
*
|
||||
* @param player Provides a context for what world to search in. Prefixing the term with 'world_name;' will override this context.
|
||||
* @param arg The search term
|
||||
* @param message If a message should be sent to the player if a plot cannot be found
|
||||
* @return The plot if only 1 result is found, or null
|
||||
*/
|
||||
@Nullable public static Plot getPlotFromString(PlotPlayer<?> player, String arg,
|
||||
boolean message) {
|
||||
if (arg == null) {
|
||||
if (player == null) {
|
||||
if (message) {
|
||||
logger.info("[P2] No plot area string was supplied");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return player.getCurrentPlot();
|
||||
}
|
||||
PlotArea area;
|
||||
if (player != null) {
|
||||
area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(arg);
|
||||
if (area == null) {
|
||||
area = player.getApplicablePlotArea();
|
||||
}
|
||||
} else {
|
||||
area = ConsolePlayer.getConsole().getApplicablePlotArea();
|
||||
}
|
||||
String[] split = arg.split(";|,");
|
||||
PlotId id;
|
||||
if (split.length == 4) {
|
||||
area = PlotSquared.get().getPlotAreaManager()
|
||||
.getPlotAreaByString(split[0] + ';' + split[1]);
|
||||
id = PlotId.fromString(split[2] + ';' + split[3]);
|
||||
} else if (split.length == 3) {
|
||||
area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(split[0]);
|
||||
id = PlotId.fromString(split[1] + ';' + split[2]);
|
||||
} else if (split.length == 2) {
|
||||
id = PlotId.fromString(arg);
|
||||
} else {
|
||||
Collection<Plot> plots;
|
||||
if (area == null) {
|
||||
plots = PlotQuery.newQuery().allPlots().asList();
|
||||
} else {
|
||||
plots = area.getPlots();
|
||||
}
|
||||
for (Plot p : plots) {
|
||||
String name = p.getAlias();
|
||||
if (!name.isEmpty() && name.equalsIgnoreCase(arg)) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
if (message) {
|
||||
MainUtil.sendMessage(player, Captions.NOT_VALID_PLOT_ID);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (area == null) {
|
||||
if (message) {
|
||||
MainUtil.sendMessage(player, Captions.NOT_VALID_PLOT_WORLD);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return area.getPlotAbs(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a plot from a string e.g. [area];[id]
|
||||
*
|
||||
@ -327,6 +409,13 @@ public class Plot {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nonnull private static Location[] getCorners(@Nonnull final String world,
|
||||
@Nonnull final CuboidRegion region) {
|
||||
final BlockVector3 min = region.getMinimumPoint();
|
||||
final BlockVector3 max = region.getMaximumPoint();
|
||||
return new Location[] {Location.at(world, min), Location.at(world, max)};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the owner of this exact plot, as it is
|
||||
* stored in the database.
|
||||
@ -469,7 +558,7 @@ public class Plot {
|
||||
* @see #getOwnerAbs() getOwnerAbs() to get the owner as stored in the database
|
||||
*/
|
||||
public UUID getOwner() {
|
||||
if (MainUtil.isServerOwned(this)) {
|
||||
if (this.getFlag(ServerPlotFlag.class)) {
|
||||
return DBFunc.SERVER;
|
||||
}
|
||||
return this.getOwnerAbs();
|
||||
@ -576,6 +665,15 @@ public class Plot {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the plot ID
|
||||
*
|
||||
* @param id new plot ID
|
||||
*/
|
||||
public void setId(@Nonnull final PlotId id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plot world object for this plot<br>
|
||||
* - The generic PlotArea object can be casted to its respective class for more control (e.g. HybridPlotWorld)
|
||||
@ -958,7 +1056,7 @@ public class Plot {
|
||||
if (queue.isEmpty()) {
|
||||
Runnable run = () -> {
|
||||
for (CuboidRegion region : regions) {
|
||||
Location[] corners = MainUtil.getCorners(getWorldName(), region);
|
||||
Location[] corners = getCorners(getWorldName(), region);
|
||||
regionManager.clearAllEntities(corners[0], corners[1]);
|
||||
}
|
||||
TaskManager.runTask(whenDone);
|
||||
@ -1070,7 +1168,7 @@ public class Plot {
|
||||
if (createSign) {
|
||||
queue.setCompleteTask(() -> TaskManager.runTaskAsync(() -> {
|
||||
for (Plot current : plots) {
|
||||
current.setSign(MainUtil.getName(current.getOwnerAbs()));
|
||||
current.setSign(PlayerManager.getName(current.getOwnerAbs()));
|
||||
}
|
||||
}));
|
||||
}
|
||||
@ -1867,6 +1965,8 @@ public class Plot {
|
||||
return this.setComponent(component, parsed.toPattern(), queue);
|
||||
}
|
||||
|
||||
//TODO Better documentation needed.
|
||||
|
||||
/**
|
||||
* Retrieve the biome of the plot.
|
||||
*/
|
||||
@ -1875,6 +1975,8 @@ public class Plot {
|
||||
.getBiome(location.getWorldName(), location.getX(), location.getZ(), result));
|
||||
}
|
||||
|
||||
//TODO Better documentation needed.
|
||||
|
||||
/**
|
||||
* @deprecated May cause synchronous chunk loads
|
||||
*/
|
||||
@ -1884,8 +1986,6 @@ public class Plot {
|
||||
.getBiomeSynchronous(location.getWorldName(), location.getX(), location.getZ());
|
||||
}
|
||||
|
||||
//TODO Better documentation needed.
|
||||
|
||||
/**
|
||||
* Returns the top location for the plot.
|
||||
*/
|
||||
@ -1893,8 +1993,6 @@ public class Plot {
|
||||
return this.getManager().getPlotTopLocAbs(this.id).withWorld(this.getWorldName());
|
||||
}
|
||||
|
||||
//TODO Better documentation needed.
|
||||
|
||||
/**
|
||||
* Returns the bottom location for the plot.
|
||||
*/
|
||||
@ -2009,7 +2107,7 @@ public class Plot {
|
||||
if (!this.isMerged()) {
|
||||
return new Location[] {this.getBottomAbs(), this.getTopAbs()};
|
||||
}
|
||||
return MainUtil.getCorners(this.getWorldName(), this.getRegions());
|
||||
return RegionUtil.getCorners(this.getWorldName(), this.getRegions());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2086,7 +2184,6 @@ public class Plot {
|
||||
return this.area + ";" + this.id.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove a denied player (use DBFunc as well)<br>
|
||||
* Using the * uuid will remove all users
|
||||
@ -2187,8 +2284,8 @@ public class Plot {
|
||||
}
|
||||
} else {
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
String name = Plot.this.id + "," + Plot.this.area + ',' + MainUtil
|
||||
.getName(Plot.this.getOwnerAbs());
|
||||
String name = Plot.this.id + "," + Plot.this.area + ',' +
|
||||
PlayerManager.getName(Plot.this.getOwnerAbs());
|
||||
boolean result = schematicHandler.save(value,
|
||||
Settings.Paths.SCHEMATICS + File.separator + name + ".schem");
|
||||
if (whenDone != null) {
|
||||
@ -2762,8 +2859,9 @@ public class Plot {
|
||||
PlotId top = PlotId.of(current.getId().getX(), current.getId().getY());
|
||||
while (merge) {
|
||||
merge = false;
|
||||
ArrayList<PlotId> ids = MainUtil.getPlotSelectionIds(PlotId.of(bot.getX(), bot.getY() - 1),
|
||||
PlotId.of(top.getX(), bot.getY() - 1));
|
||||
List<PlotId> ids = Lists.newArrayList((Iterable<? extends PlotId>)
|
||||
PlotId.PlotRangeIterator.range(PlotId.of(bot.getX(), bot.getY() - 1),
|
||||
PlotId.of(top.getX(), bot.getY() - 1)));
|
||||
boolean tmp = true;
|
||||
for (PlotId id : ids) {
|
||||
Plot plot = this.area.getPlotAbs(id);
|
||||
@ -2776,8 +2874,9 @@ public class Plot {
|
||||
merge = true;
|
||||
bot = PlotId.of(bot.getX(), bot.getY() - 1);
|
||||
}
|
||||
ids = MainUtil.getPlotSelectionIds(PlotId.of(top.getX() + 1, bot.getY()),
|
||||
PlotId.of(top.getX() + 1, top.getY()));
|
||||
ids = Lists.newArrayList((Iterable<? extends PlotId>)
|
||||
PlotId.PlotRangeIterator.range(PlotId.of(top.getX() + 1, bot.getY()),
|
||||
PlotId.of(top.getX() + 1, top.getY())));
|
||||
tmp = true;
|
||||
for (PlotId id : ids) {
|
||||
Plot plot = this.area.getPlotAbs(id);
|
||||
@ -2790,8 +2889,9 @@ public class Plot {
|
||||
merge = true;
|
||||
top = PlotId.of(top.getX() + 1, top.getY());
|
||||
}
|
||||
ids = MainUtil.getPlotSelectionIds(PlotId.of(bot.getX(), top.getY() + 1),
|
||||
PlotId.of(top.getX(), top.getY() + 1));
|
||||
ids = Lists.newArrayList((Iterable<? extends PlotId>)
|
||||
PlotId.PlotRangeIterator.range(PlotId.of(bot.getX(), top.getY() + 1),
|
||||
PlotId.of(top.getX(), top.getY() + 1)));
|
||||
tmp = true;
|
||||
for (PlotId id : ids) {
|
||||
Plot plot = this.area.getPlotAbs(id);
|
||||
@ -2804,8 +2904,9 @@ public class Plot {
|
||||
merge = true;
|
||||
top = PlotId.of(top.getX(), top.getY() + 1);
|
||||
}
|
||||
ids = MainUtil.getPlotSelectionIds(PlotId.of(bot.getX() - 1, bot.getY()),
|
||||
PlotId.of(bot.getX() - 1, top.getY()));
|
||||
ids = Lists.newArrayList((Iterable<? extends PlotId>)
|
||||
PlotId.PlotRangeIterator.range(PlotId.of(bot.getX() - 1, bot.getY()),
|
||||
PlotId.of(bot.getX() - 1, top.getY())));
|
||||
tmp = true;
|
||||
for (PlotId id : ids) {
|
||||
Plot plot = this.area.getPlotAbs(id);
|
||||
@ -2821,7 +2922,8 @@ public class Plot {
|
||||
}
|
||||
Location gtopabs = this.area.getPlotAbs(top).getTopAbs();
|
||||
Location gbotabs = this.area.getPlotAbs(bot).getBottomAbs();
|
||||
visited.addAll(MainUtil.getPlotSelectionIds(bot, top));
|
||||
visited.addAll(Lists.newArrayList((Iterable<? extends PlotId>)
|
||||
PlotId.PlotRangeIterator.range(bot, top)));
|
||||
for (int x = bot.getX(); x <= top.getX(); x++) {
|
||||
Plot plot = this.area.getPlotAbs(PlotId.of(x, top.getY()));
|
||||
if (plot.getMerged(Direction.SOUTH)) {
|
||||
@ -3205,7 +3307,7 @@ public class Plot {
|
||||
TaskManager.runTask(whenDone);
|
||||
} else {
|
||||
CuboidRegion region = regions.poll();
|
||||
Location[] corners = MainUtil.getCorners(getWorldName(), region);
|
||||
Location[] corners = getCorners(getWorldName(), region);
|
||||
Location pos1 = corners[0];
|
||||
Location pos2 = corners[1];
|
||||
Location pos3 =
|
||||
@ -3239,7 +3341,7 @@ public class Plot {
|
||||
}
|
||||
final Runnable task = this;
|
||||
CuboidRegion region = regions.poll();
|
||||
Location[] corners = MainUtil.getCorners(getWorldName(), region);
|
||||
Location[] corners = getCorners(getWorldName(), region);
|
||||
final Location pos1 = corners[0];
|
||||
final Location pos2 = corners[1];
|
||||
Location newPos =
|
||||
@ -3334,7 +3436,7 @@ public class Plot {
|
||||
return;
|
||||
}
|
||||
CuboidRegion region = regions.poll();
|
||||
Location[] corners = MainUtil.getCorners(getWorldName(), region);
|
||||
Location[] corners = getCorners(getWorldName(), region);
|
||||
Location pos1 = corners[0];
|
||||
Location pos2 = corners[1];
|
||||
Location newPos =
|
||||
@ -3396,13 +3498,158 @@ public class Plot {
|
||||
return FlagContainer.<T, V>castUnsafe(flagInstance).getValue();
|
||||
}
|
||||
|
||||
public CompletableFuture<String> format(final String iInfo, PlotPlayer<?> player, final boolean full) {
|
||||
final CompletableFuture<String> future = new CompletableFuture<>();
|
||||
int num = this.getConnectedPlots().size();
|
||||
String alias = !this.getAlias().isEmpty() ? this.getAlias() : Captions.NONE.getTranslated();
|
||||
Location bot = this.getCorners()[0];
|
||||
PlotSquared.platform().getWorldUtil()
|
||||
.getBiome(this.getWorldName(), bot.getX(), bot.getZ(), biome -> {
|
||||
String info = iInfo;
|
||||
String trusted = PlayerManager.getPlayerList(this.getTrusted());
|
||||
String members = PlayerManager.getPlayerList(this.getMembers());
|
||||
String denied = PlayerManager.getPlayerList(this.getDenied());
|
||||
String seen;
|
||||
if (Settings.Enabled_Components.PLOT_EXPIRY && ExpireManager.IMP != null) {
|
||||
if (this.isOnline()) {
|
||||
seen = Captions.NOW.getTranslated();
|
||||
} else {
|
||||
int time = (int) (ExpireManager.IMP.getAge(this) / 1000);
|
||||
if (time != 0) {
|
||||
seen = TimeUtil.secToTime(time);
|
||||
} else {
|
||||
seen = Captions.UNKNOWN.getTranslated();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
seen = Captions.NEVER.getTranslated();
|
||||
}
|
||||
|
||||
String description = this.getFlag(DescriptionFlag.class);
|
||||
if (description.isEmpty()) {
|
||||
description = Captions.PLOT_NO_DESCRIPTION.getTranslated();
|
||||
}
|
||||
|
||||
StringBuilder flags = new StringBuilder();
|
||||
Collection<PlotFlag<?, ?>> flagCollection = this.getApplicableFlags(true);
|
||||
if (flagCollection.isEmpty()) {
|
||||
flags.append(Captions.NONE.getTranslated());
|
||||
} else {
|
||||
String prefix = " ";
|
||||
for (final PlotFlag<?, ?> flag : flagCollection) {
|
||||
Object value;
|
||||
if (flag instanceof DoubleFlag && !Settings.General.SCIENTIFIC) {
|
||||
value = FLAG_DECIMAL_FORMAT.format(flag.getValue());
|
||||
} else {
|
||||
value = flag.toString();
|
||||
}
|
||||
flags.append(prefix).append(CaptionUtility
|
||||
.format(player, Captions.PLOT_FLAG_LIST.getTranslated(), flag.getName(),
|
||||
CaptionUtility.formatRaw(player, value.toString(), "")));
|
||||
prefix = ", ";
|
||||
}
|
||||
}
|
||||
boolean build = this.isAdded(player.getUUID());
|
||||
String owner = this.getOwners().isEmpty() ? "unowned" : PlayerManager.getPlayerList(this.getOwners());
|
||||
if (this.getArea() != null) {
|
||||
info = info.replace("%area%",
|
||||
this.getArea().getWorldName() + (this.getArea().getId() == null ?
|
||||
"" :
|
||||
"(" + this.getArea().getId() + ")"));
|
||||
} else {
|
||||
info = info.replace("%area%", Captions.NONE.getTranslated());
|
||||
}
|
||||
info = info.replace("%id%", this.getId().toString());
|
||||
info = info.replace("%alias%", alias);
|
||||
info = info.replace("%num%", String.valueOf(num));
|
||||
info = info.replace("%desc%", description);
|
||||
info = info.replace("%biome%", biome.toString().toLowerCase());
|
||||
info = info.replace("%owner%", owner);
|
||||
info = info.replace("%members%", members);
|
||||
info = info.replace("%player%", player.getName());
|
||||
info = info.replace("%trusted%", trusted);
|
||||
info = info.replace("%helpers%", members);
|
||||
info = info.replace("%denied%", denied);
|
||||
info = info.replace("%seen%", seen);
|
||||
info = info.replace("%flags%", flags);
|
||||
info = info.replace("%build%", String.valueOf(build));
|
||||
if (info.contains("%rating%")) {
|
||||
final String newInfo = info;
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
String info1;
|
||||
if (Settings.Ratings.USE_LIKES) {
|
||||
info1 = newInfo.replaceAll("%rating%",
|
||||
String.format("%.0f%%", Like.getLikesPercentage(this) * 100D));
|
||||
} else {
|
||||
int max = 10;
|
||||
if (Settings.Ratings.CATEGORIES != null && !Settings.Ratings.CATEGORIES
|
||||
.isEmpty()) {
|
||||
max = 8;
|
||||
}
|
||||
if (full && Settings.Ratings.CATEGORIES != null
|
||||
&& Settings.Ratings.CATEGORIES.size() > 1) {
|
||||
double[] ratings = this.getAverageRatings();
|
||||
String rating = "";
|
||||
String prefix = "";
|
||||
for (int i = 0; i < ratings.length; i++) {
|
||||
rating +=
|
||||
prefix + Settings.Ratings.CATEGORIES.get(i) + '=' + String
|
||||
.format("%.1f", ratings[i]);
|
||||
prefix = ",";
|
||||
}
|
||||
info1 = newInfo.replaceAll("%rating%", rating);
|
||||
} else {
|
||||
info1 = newInfo.replaceAll("%rating%",
|
||||
String.format("%.1f", this.getAverageRating()) + '/' + max);
|
||||
}
|
||||
}
|
||||
future.complete(info1);
|
||||
});
|
||||
return;
|
||||
}
|
||||
future.complete(info);
|
||||
});
|
||||
return future;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the plot ID
|
||||
* If rating categories are enabled, get the average rating by category.<br>
|
||||
* - The index corresponds to the index of the category in the config
|
||||
*
|
||||
* @param id new plot ID
|
||||
* @return Average ratings in each category
|
||||
*/
|
||||
public void setId(@Nonnull final PlotId id) {
|
||||
this.id = id;
|
||||
public double[] getAverageRatings() {
|
||||
Map<UUID, Integer> rating;
|
||||
if (this.getSettings().getRatings() != null) {
|
||||
rating = this.getSettings().getRatings();
|
||||
} else if (Settings.Enabled_Components.RATING_CACHE) {
|
||||
rating = new HashMap<>();
|
||||
} else {
|
||||
rating = DBFunc.getRatings(this);
|
||||
}
|
||||
int size = 1;
|
||||
if (!Settings.Ratings.CATEGORIES.isEmpty()) {
|
||||
size = Math.max(1, Settings.Ratings.CATEGORIES.size());
|
||||
}
|
||||
double[] ratings = new double[size];
|
||||
if (rating == null || rating.isEmpty()) {
|
||||
return ratings;
|
||||
}
|
||||
for (Entry<UUID, Integer> entry : rating.entrySet()) {
|
||||
int current = entry.getValue();
|
||||
if (Settings.Ratings.CATEGORIES.isEmpty()) {
|
||||
ratings[0] += current;
|
||||
} else {
|
||||
for (int i = 0; i < Settings.Ratings.CATEGORIES.size(); i++) {
|
||||
ratings[i] += current % 10 - 1;
|
||||
current /= 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < size; i++) {
|
||||
ratings[i] /= rating.size();
|
||||
}
|
||||
return ratings;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ package com.plotsquared.core.plot;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.plotsquared.core.collection.QuadMap;
|
||||
import com.plotsquared.core.configuration.CaptionUtility;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
@ -52,7 +53,6 @@ import com.plotsquared.core.queue.GlobalBlockQueue;
|
||||
import com.plotsquared.core.queue.QueueCoordinator;
|
||||
import com.plotsquared.core.util.EconHandler;
|
||||
import com.plotsquared.core.util.Expression;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
import com.plotsquared.core.util.RegionUtil;
|
||||
import com.plotsquared.core.util.StringMan;
|
||||
@ -272,8 +272,8 @@ public abstract class PlotArea {
|
||||
throw new IllegalArgumentException("Must extend GridPlotWorld to provide");
|
||||
}
|
||||
if (config.contains("generator.terrain")) {
|
||||
this.terrain = MainUtil.getTerrain(config);
|
||||
this.type = MainUtil.getType(config);
|
||||
this.terrain = ConfigurationUtil.getTerrain(config);
|
||||
this.type = ConfigurationUtil.getType(config);
|
||||
}
|
||||
this.mobSpawning = config.getBoolean("natural_mob_spawning");
|
||||
this.miscSpawnUnowned = config.getBoolean("misc_spawn_unowned");
|
||||
@ -994,7 +994,8 @@ public abstract class PlotArea {
|
||||
final int size = (1 + pos2.getX() - pos1.getX()) * (1 + pos2.getY() - pos1.getY());
|
||||
final Set<Plot> result = new HashSet<>();
|
||||
if (size < 16 || size < getPlotCount()) {
|
||||
for (final PlotId pid : MainUtil.getPlotSelectionIds(pos1, pos2)) {
|
||||
for (final PlotId pid : Lists.newArrayList((Iterable<? extends PlotId>)
|
||||
PlotId.PlotRangeIterator.range(pos1, pos2))) {
|
||||
final Plot plot = getPlotAbs(pid);
|
||||
if (plot.hasOwner()) {
|
||||
if (plot.getId().getX() > pos1.getX() || plot.getId().getY() > pos1.getY()
|
||||
|
@ -25,15 +25,15 @@
|
||||
*/
|
||||
package com.plotsquared.core.plot;
|
||||
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.database.DBFunc;
|
||||
import com.plotsquared.core.location.BlockLoc;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.RegionUtil;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
@ -156,10 +156,13 @@ public class PlotCluster {
|
||||
public void getHome(@Nonnull final Consumer<Location> result) {
|
||||
final BlockLoc home = this.settings.getPosition();
|
||||
Consumer<Location> locationConsumer = toReturn ->
|
||||
MainUtil.getHighestBlock(this.area.getWorldName(), toReturn.getX(), toReturn.getZ(),
|
||||
max -> {
|
||||
if (max > toReturn.getY()) {
|
||||
result.accept(toReturn.withY(1 + max));
|
||||
PlotSquared.platform().getWorldUtil().getHighestBlock(this.area.getWorldName(), toReturn.getX(), toReturn.getZ(),
|
||||
highest -> {
|
||||
if (highest == 0) {
|
||||
highest = 63;
|
||||
}
|
||||
if (highest > toReturn.getY()) {
|
||||
result.accept(toReturn.withY(1 + highest));
|
||||
} else {
|
||||
result.accept(toReturn);
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ import com.plotsquared.core.plot.flag.GlobalFlagContainer;
|
||||
import com.plotsquared.core.plot.flag.PlotFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.AnalysisFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.KeepFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.ServerPlotFlag;
|
||||
import com.plotsquared.core.plot.message.PlotMessage;
|
||||
import com.plotsquared.core.util.EventDispatcher;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
@ -215,7 +216,7 @@ public class ExpireManager {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
if (MainUtil.isServerOwned(plot)) {
|
||||
if (plot.getFlag(ServerPlotFlag.class)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
|
@ -28,8 +28,9 @@ package com.plotsquared.core.plot.flag.implementations;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.plot.flag.FlagParseException;
|
||||
import com.plotsquared.core.plot.flag.PlotFlag;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
import com.plotsquared.core.util.TimeUtil;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class KeepFlag extends PlotFlag<Object, KeepFlag> {
|
||||
@ -60,7 +61,7 @@ public class KeepFlag extends PlotFlag<Object, KeepFlag> {
|
||||
case "false":
|
||||
return flagOf(false);
|
||||
default:
|
||||
return flagOf(MainUtil.timeToSec(input) * 1000 + System.currentTimeMillis());
|
||||
return flagOf(TimeUtil.timeToSec(input) * 1000 + System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.PlotId;
|
||||
import com.plotsquared.core.plot.PlotManager;
|
||||
import com.plotsquared.core.queue.QueueCoordinator;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.FileUtils;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
|
||||
@ -69,7 +69,7 @@ public class SinglePlotManager extends PlotManager {
|
||||
final File worldFolder =
|
||||
new File(PlotSquared.platform().getWorldContainer(), plot.getWorldName());
|
||||
TaskManager.getPlatformImplementation().taskAsync(() -> {
|
||||
MainUtil.deleteDirectory(worldFolder);
|
||||
FileUtils.deleteDirectory(worldFolder);
|
||||
if (whenDone != null) {
|
||||
whenDone.run();
|
||||
}
|
||||
|
93
Core/src/main/java/com/plotsquared/core/util/ChunkUtil.java
Normal file
93
Core/src/main/java/com/plotsquared/core/util/ChunkUtil.java
Normal file
@ -0,0 +1,93 @@
|
||||
package com.plotsquared.core.util;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
/**
|
||||
* This cache is used for world generation and just saves a bit of calculation time when checking if something is in the plot area.
|
||||
*/
|
||||
@UtilityClass
|
||||
public class ChunkUtil {
|
||||
|
||||
|
||||
/**
|
||||
* Cache of mapping x,y,z coordinates to the chunk array<br>
|
||||
* - Used for efficient world generation<br>
|
||||
*/
|
||||
private static short[] x_loc;
|
||||
private static short[][] y_loc;
|
||||
private static short[] z_loc;
|
||||
private static short[][][] CACHE_J = null;
|
||||
|
||||
static {
|
||||
x_loc = new short[4096];
|
||||
y_loc = new short[16][4096];
|
||||
z_loc = new short[4096];
|
||||
for (int i = 0; i < 16; i++) {
|
||||
int i4 = i << 4;
|
||||
for (int j = 0; j < 4096; j++) {
|
||||
int y = i4 + (j >> 8);
|
||||
int a = j - ((y & 0xF) << 8);
|
||||
int z1 = a >> 4;
|
||||
int x1 = a - (z1 << 4);
|
||||
x_loc[j] = (short) x1;
|
||||
y_loc[i][j] = (short) y;
|
||||
z_loc[j] = (short) z1;
|
||||
}
|
||||
}
|
||||
CACHE_J = new short[256][16][16];
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
for (int y = 0; y < 256; y++) {
|
||||
short j = (short) ((y & 0xF) << 8 | z << 4 | x);
|
||||
CACHE_J[y][x][z] = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the J value for Chunk block storage from the chunk xyz coordinates.
|
||||
* J is in the range 0 to 4095 where it represents a position in an array of 16x16x16 xyz (ChunkSection Array[4096]).
|
||||
*
|
||||
* @param x Relative x coordinate
|
||||
* @param y Relative y coordinate
|
||||
* @param z Relative z coordinate
|
||||
* @return J value for xyz position in Array[4096].
|
||||
*/
|
||||
public static int getJ(@Range(from = 0, to = 15) int x, @Range(from = 0, to = 255) int y,
|
||||
@Range(from = 0, to = 15) int z) {
|
||||
return CACHE_J[y][x][z];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the x coordinate for a specific J value for a ChunkSection 16x16x16 xyz Array[4096].
|
||||
*
|
||||
* @param j Position in the xyz Array[4096].
|
||||
* @return x coordinate within the chunk
|
||||
*/
|
||||
public static int getX(@Range(from = 0, to = 4095) int j) {
|
||||
return x_loc[j];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the y coordinate for specific I and J values for a Chunk 16x16x16x16 layerxyz Array[16][4096].
|
||||
*
|
||||
* @param i Relative layer of the position in the layerxyz Array[16][4096].
|
||||
* @param j Position in the xyz Array[4096].
|
||||
* @return x coordinate within the chunk
|
||||
*/
|
||||
public static int getY(@Range(from = 0, to = 15) int i, @Range(from = 0, to = 4095) int j) {
|
||||
return y_loc[i][j];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the z coordinate for a specific J value for a ChunkSection 16x16x16 xyz Array[4096].
|
||||
*
|
||||
* @param j Position in the xyz Array[4096].
|
||||
* @return z coordinate within the chunk
|
||||
*/
|
||||
public static int getZ(@Range(from = 0, to = 4095) int j) {
|
||||
return z_loc[j];
|
||||
}
|
||||
}
|
@ -25,30 +25,43 @@
|
||||
*/
|
||||
package com.plotsquared.core.util;
|
||||
|
||||
public class PseudoRandom {
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.File;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public static final PseudoRandom random = new PseudoRandom();
|
||||
public final class FileUtils {
|
||||
|
||||
public long state = System.nanoTime();
|
||||
|
||||
public long nextLong() {
|
||||
long a = this.state;
|
||||
this.state = xorShift64(a);
|
||||
return a;
|
||||
private FileUtils() {
|
||||
}
|
||||
|
||||
public long xorShift64(long a) {
|
||||
a ^= a << 21;
|
||||
a ^= a >>> 35;
|
||||
a ^= a << 4;
|
||||
return a;
|
||||
/**
|
||||
* Attempt to (recursively) delete a directory
|
||||
*
|
||||
* @param directory Directory to delete
|
||||
* @throws RuntimeException If the deletion fails
|
||||
*/
|
||||
public static void deleteDirectory(@Nonnull final File directory) {
|
||||
if (directory.exists()) {
|
||||
final File[] files = directory.listFiles();
|
||||
if (null != files) {
|
||||
for (final File file : files) {
|
||||
if (file.isDirectory()) {
|
||||
deleteDirectory(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!directory.delete()) {
|
||||
throw new RuntimeException(
|
||||
String.format("Failed to delete directory %s", directory.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
public int random(int n) {
|
||||
if (n == 1) {
|
||||
return 0;
|
||||
@Nonnull public static File getFile(@Nonnull final File base, @Nonnull final String path) {
|
||||
if (Paths.get(path).isAbsolute()) {
|
||||
return new File(path);
|
||||
}
|
||||
long r = ((nextLong() >>> 32) * n) >> 32;
|
||||
return (int) r;
|
||||
return new File(base, path);
|
||||
}
|
||||
|
||||
}
|
@ -25,20 +25,33 @@
|
||||
*/
|
||||
package com.plotsquared.core.util;
|
||||
|
||||
public abstract class LazyResult<T> {
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
private T result;
|
||||
public final class HashUtil {
|
||||
|
||||
public T get() {
|
||||
return this.result;
|
||||
private HashUtil() {
|
||||
}
|
||||
|
||||
public T getOrCreate() {
|
||||
if (this.result == null) {
|
||||
return this.result = create();
|
||||
/**
|
||||
* Hashcode of a boolean array.<br>
|
||||
* - Used for traversing mega plots quickly.
|
||||
*
|
||||
* @param array Booleans to hash
|
||||
* @return hashcode
|
||||
*/
|
||||
public static int hash(@Nonnull final boolean[] array) {
|
||||
if (array.length == 4) {
|
||||
if (!array[0] && !array[1] && !array[2] && !array[3]) {
|
||||
return 0;
|
||||
}
|
||||
return this.result;
|
||||
return ((array[0] ? 1 : 0) << 3) + ((array[1] ? 1 : 0) << 2) + ((array[2] ? 1 : 0) << 1)
|
||||
+ (array[3] ? 1 : 0);
|
||||
}
|
||||
int n = 0;
|
||||
for (boolean anArray : array) {
|
||||
n = (n << 1) + (anArray ? 1 : 0);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
public abstract T create();
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2020 IntellectualSites
|
||||
*
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.core.util;
|
||||
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
|
||||
public abstract class LazyBlock {
|
||||
|
||||
public abstract BlockState getBlockState();
|
||||
|
||||
public String getId() {
|
||||
return getBlockState().toString();
|
||||
}
|
||||
}
|
@ -25,610 +25,24 @@
|
||||
*/
|
||||
package com.plotsquared.core.util;
|
||||
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.command.Like;
|
||||
import com.plotsquared.core.configuration.Caption;
|
||||
import com.plotsquared.core.configuration.CaptionUtility;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.configuration.ConfigurationSection;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.database.DBFunc;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.player.ConsolePlayer;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.PlotAreaTerrainType;
|
||||
import com.plotsquared.core.plot.PlotAreaType;
|
||||
import com.plotsquared.core.plot.PlotId;
|
||||
import com.plotsquared.core.plot.expiration.ExpireManager;
|
||||
import com.plotsquared.core.plot.flag.PlotFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.DescriptionFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.ServerPlotFlag;
|
||||
import com.plotsquared.core.plot.flag.types.DoubleFlag;
|
||||
import com.plotsquared.core.util.net.AbstractDelegateOutputStream;
|
||||
import com.plotsquared.core.util.query.PlotQuery;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.plotsquared.core.uuid.UUIDMapping;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Paths;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Scanner;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.IntConsumer;
|
||||
import java.util.function.IntFunction;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
/**
|
||||
* plot functions
|
||||
* @deprecated Do not use
|
||||
*/
|
||||
public class MainUtil {
|
||||
@Deprecated public class MainUtil {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger("P2/" + MainUtil.class.getSimpleName());
|
||||
private static final DecimalFormat FLAG_DECIMAL_FORMAT = new DecimalFormat("0");
|
||||
|
||||
static {
|
||||
FLAG_DECIMAL_FORMAT.setMaximumFractionDigits(340);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache of mapping x,y,z coordinates to the chunk array<br>
|
||||
* - Used for efficient world generation<br>
|
||||
*/
|
||||
public static short[][] x_loc;
|
||||
public static short[][] y_loc;
|
||||
public static short[][] z_loc;
|
||||
public static short[][][] CACHE_I = null;
|
||||
public static short[][][] CACHE_J = null;
|
||||
|
||||
/**
|
||||
* This cache is used for world generation and just saves a bit of calculation time when checking if something is in the plot area.
|
||||
*/
|
||||
public static void initCache() {
|
||||
if (x_loc == null) {
|
||||
x_loc = new short[16][4096];
|
||||
y_loc = new short[16][4096];
|
||||
z_loc = new short[16][4096];
|
||||
for (int i = 0; i < 16; i++) {
|
||||
int i4 = i << 4;
|
||||
for (int j = 0; j < 4096; j++) {
|
||||
int y = i4 + (j >> 8);
|
||||
int a = j - ((y & 0xF) << 8);
|
||||
int z1 = a >> 4;
|
||||
int x1 = a - (z1 << 4);
|
||||
x_loc[i][j] = (short) x1;
|
||||
y_loc[i][j] = (short) y;
|
||||
z_loc[i][j] = (short) z1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CACHE_I == null) {
|
||||
CACHE_I = new short[256][16][16];
|
||||
CACHE_J = new short[256][16][16];
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
for (int y = 0; y < 256; y++) {
|
||||
short i = (short) (y >> 4);
|
||||
short j = (short) ((y & 0xF) << 8 | z << 4 | x);
|
||||
CACHE_I[y][x][z] = i;
|
||||
CACHE_J[y][x][z] = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void upload(@Nullable UUID uuid, @Nullable final String file,
|
||||
@Nonnull final String extension, @Nullable final RunnableVal<OutputStream> writeTask,
|
||||
@Nonnull final RunnableVal<URL> whenDone) {
|
||||
if (writeTask == null) {
|
||||
TaskManager.runTask(whenDone);
|
||||
return;
|
||||
}
|
||||
final String filename;
|
||||
final String website;
|
||||
if (uuid == null) {
|
||||
uuid = UUID.randomUUID();
|
||||
website = Settings.Web.URL + "upload.php?" + uuid;
|
||||
filename = "plot." + extension;
|
||||
} else {
|
||||
website = Settings.Web.URL + "save.php?" + uuid;
|
||||
filename = file + '.' + extension;
|
||||
}
|
||||
final URL url;
|
||||
try {
|
||||
url = new URL(Settings.Web.URL + "?key=" + uuid + "&type=" + extension);
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
whenDone.run();
|
||||
return;
|
||||
}
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
try {
|
||||
String boundary = Long.toHexString(System.currentTimeMillis());
|
||||
URLConnection con = new URL(website).openConnection();
|
||||
con.setDoOutput(true);
|
||||
con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
|
||||
try (OutputStream output = con.getOutputStream();
|
||||
PrintWriter writer = new PrintWriter(
|
||||
new OutputStreamWriter(output, StandardCharsets.UTF_8), true)) {
|
||||
String CRLF = "\r\n";
|
||||
writer.append("--" + boundary).append(CRLF);
|
||||
writer.append("Content-Disposition: form-data; name=\"param\"").append(CRLF);
|
||||
writer.append(
|
||||
"Content-Type: text/plain; charset=" + StandardCharsets.UTF_8.displayName())
|
||||
.append(CRLF);
|
||||
String param = "value";
|
||||
writer.append(CRLF).append(param).append(CRLF).flush();
|
||||
writer.append("--" + boundary).append(CRLF);
|
||||
writer.append(
|
||||
"Content-Disposition: form-data; name=\"schematicFile\"; filename=\""
|
||||
+ filename + '"').append(CRLF);
|
||||
writer
|
||||
.append("Content-Type: " + URLConnection.guessContentTypeFromName(filename))
|
||||
.append(CRLF);
|
||||
writer.append("Content-Transfer-Encoding: binary").append(CRLF);
|
||||
writer.append(CRLF).flush();
|
||||
writeTask.value = new AbstractDelegateOutputStream(output) {
|
||||
@Override public void close() {
|
||||
} // Don't close
|
||||
};
|
||||
writeTask.run();
|
||||
output.flush();
|
||||
writer.append(CRLF).flush();
|
||||
writer.append("--" + boundary + "--").append(CRLF).flush();
|
||||
}
|
||||
String content;
|
||||
try (Scanner scanner = new Scanner(con.getInputStream()).useDelimiter("\\A")) {
|
||||
content = scanner.next().trim();
|
||||
}
|
||||
if (!content.startsWith("<")) {
|
||||
}
|
||||
int responseCode = ((HttpURLConnection) con).getResponseCode();
|
||||
if (responseCode == 200) {
|
||||
whenDone.value = url;
|
||||
}
|
||||
TaskManager.runTask(whenDone);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
TaskManager.runTask(whenDone);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the biome if it was modified
|
||||
*
|
||||
* @param area
|
||||
* @param pos1
|
||||
* @param pos2
|
||||
* @return true if any changes were made
|
||||
*/
|
||||
public static boolean resetBiome(PlotArea area, Location pos1, Location pos2) {
|
||||
BiomeType biome = area.getPlotBiome();
|
||||
if (!Objects.equals(PlotSquared.platform().getWorldUtil().getBiomeSynchronous(area.getWorldName(), (pos1.getX() + pos2.getX()) / 2,
|
||||
(pos1.getZ() + pos2.getZ()) / 2), biome)) {
|
||||
MainUtil
|
||||
.setBiome(area.getWorldName(), pos1.getX(), pos1.getZ(), pos2.getX(), pos2.getZ(),
|
||||
biome);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String secToTime(long time) {
|
||||
StringBuilder toreturn = new StringBuilder();
|
||||
if (time >= 33868800) {
|
||||
int years = (int) (time / 33868800);
|
||||
time -= years * 33868800;
|
||||
toreturn.append(years + "y ");
|
||||
}
|
||||
if (time >= 604800) {
|
||||
int weeks = (int) (time / 604800);
|
||||
time -= weeks * 604800;
|
||||
toreturn.append(weeks + "w ");
|
||||
}
|
||||
if (time >= 86400) {
|
||||
int days = (int) (time / 86400);
|
||||
time -= days * 86400;
|
||||
toreturn.append(days + "d ");
|
||||
}
|
||||
if (time >= 3600) {
|
||||
int hours = (int) (time / 3600);
|
||||
time -= hours * 3600;
|
||||
toreturn.append(hours + "h ");
|
||||
}
|
||||
if (time >= 60) {
|
||||
int minutes = (int) (time / 60);
|
||||
time -= minutes * 60;
|
||||
toreturn.append(minutes + "m ");
|
||||
}
|
||||
if (toreturn.equals("") || time > 0) {
|
||||
toreturn.append((time) + "s ");
|
||||
}
|
||||
return toreturn.toString().trim();
|
||||
}
|
||||
|
||||
public static long timeToSec(String string) {
|
||||
if (MathMan.isInteger(string)) {
|
||||
return Long.parseLong(string);
|
||||
}
|
||||
string = string.toLowerCase().trim().toLowerCase();
|
||||
if (string.equalsIgnoreCase("false")) {
|
||||
return 0;
|
||||
}
|
||||
String[] split = string.split(" ");
|
||||
long time = 0;
|
||||
for (String value : split) {
|
||||
int nums = Integer.parseInt(value.replaceAll("[^\\d]", ""));
|
||||
String letters = value.replaceAll("[^a-z]", "");
|
||||
switch (letters) {
|
||||
case "week":
|
||||
case "weeks":
|
||||
case "wks":
|
||||
case "w":
|
||||
|
||||
time += 604800 * nums;
|
||||
case "days":
|
||||
case "day":
|
||||
case "d":
|
||||
time += 86400 * nums;
|
||||
case "hour":
|
||||
case "hr":
|
||||
case "hrs":
|
||||
case "hours":
|
||||
case "h":
|
||||
time += 3600 * nums;
|
||||
case "minutes":
|
||||
case "minute":
|
||||
case "mins":
|
||||
case "min":
|
||||
case "m":
|
||||
time += 60 * nums;
|
||||
case "seconds":
|
||||
case "second":
|
||||
case "secs":
|
||||
case "sec":
|
||||
case "s":
|
||||
time += nums;
|
||||
}
|
||||
}
|
||||
return time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hashcode of a boolean array.<br>
|
||||
* - Used for traversing mega plots quickly.
|
||||
*
|
||||
* @param array
|
||||
* @return hashcode
|
||||
*/
|
||||
public static int hash(boolean[] array) {
|
||||
if (array.length == 4) {
|
||||
if (!array[0] && !array[1] && !array[2] && !array[3]) {
|
||||
return 0;
|
||||
}
|
||||
return ((array[0] ? 1 : 0) << 3) + ((array[1] ? 1 : 0) << 2) + ((array[2] ? 1 : 0) << 1)
|
||||
+ (array[3] ? 1 : 0);
|
||||
}
|
||||
int n = 0;
|
||||
for (boolean anArray : array) {
|
||||
n = (n << 1) + (anArray ? 1 : 0);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of plot ids within a selection.
|
||||
*
|
||||
* @param pos1
|
||||
* @param pos2
|
||||
* @return
|
||||
*/
|
||||
public static ArrayList<PlotId> getPlotSelectionIds(PlotId pos1, PlotId pos2) {
|
||||
ArrayList<PlotId> myPlots = new ArrayList<>();
|
||||
for (int x = pos1.getX(); x <= pos2.getX(); x++) {
|
||||
for (int y = pos1.getY(); y <= pos2.getY(); y++) {
|
||||
myPlots.add(PlotId.of(x, y));
|
||||
}
|
||||
}
|
||||
return myPlots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name from a UUID.
|
||||
*
|
||||
* @param owner Owner UUID
|
||||
* @return The player's name, None, Everyone or Unknown
|
||||
*/
|
||||
@Nonnull public static String getName(@Nullable UUID owner) {
|
||||
return getName(owner, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name from a UUID.
|
||||
*
|
||||
* @param owner Owner UUID
|
||||
* @param blocking Whether or not the operation can be blocking
|
||||
* @return The player's name, None, Everyone or Unknown
|
||||
*/
|
||||
@Nonnull public static String getName(@Nullable final UUID owner, final boolean blocking) {
|
||||
if (owner == null) {
|
||||
return Captions.NONE.getTranslated();
|
||||
}
|
||||
if (owner.equals(DBFunc.EVERYONE)) {
|
||||
return Captions.EVERYONE.getTranslated();
|
||||
}
|
||||
if (owner.equals(DBFunc.SERVER)) {
|
||||
return Captions.SERVER.getTranslated();
|
||||
}
|
||||
final String name;
|
||||
if (blocking) {
|
||||
name = PlotSquared.get().getImpromptuUUIDPipeline().getSingle(owner, Settings.UUID.BLOCKING_TIMEOUT);
|
||||
} else {
|
||||
final UUIDMapping uuidMapping = PlotSquared.get().getImpromptuUUIDPipeline().getImmediately(owner);
|
||||
if (uuidMapping != null) {
|
||||
name = uuidMapping.getUsername();
|
||||
} else {
|
||||
name = null;
|
||||
}
|
||||
}
|
||||
if (name == null) {
|
||||
return Captions.UNKNOWN.getTranslated();
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
public static boolean isServerOwned(Plot plot) {
|
||||
return plot.getFlag(ServerPlotFlag.class);
|
||||
}
|
||||
|
||||
@Nonnull public static Location[] getCorners(@Nonnull final String world, @Nonnull final CuboidRegion region) {
|
||||
final BlockVector3 min = region.getMinimumPoint();
|
||||
final BlockVector3 max = region.getMaximumPoint();
|
||||
return new Location[] {Location.at(world, min), Location.at(world, max)};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the corner locations for a list of regions.
|
||||
*
|
||||
* @param world
|
||||
* @param regions
|
||||
* @return
|
||||
* @see Plot#getCorners()
|
||||
*/
|
||||
@Nonnull public static Location[] getCorners(String world, Collection<CuboidRegion> regions) {
|
||||
Location min = null;
|
||||
Location max = null;
|
||||
for (CuboidRegion region : regions) {
|
||||
Location[] corners = getCorners(world, region);
|
||||
if (min == null) {
|
||||
min = corners[0];
|
||||
max = corners[1];
|
||||
continue;
|
||||
}
|
||||
Location pos1 = corners[0];
|
||||
Location pos2 = corners[1];
|
||||
if (pos2.getX() > max.getX()) {
|
||||
max = max.withX(pos2.getX());
|
||||
}
|
||||
if (pos1.getX() < min.getX()) {
|
||||
min = min.withX(pos1.getX());
|
||||
}
|
||||
if (pos2.getZ() > max.getZ()) {
|
||||
max = max.withZ(pos2.getZ());
|
||||
}
|
||||
if (pos1.getZ() < min.getZ()) {
|
||||
min = min.withZ(pos1.getZ());
|
||||
}
|
||||
}
|
||||
return new Location[] {min, max};
|
||||
}
|
||||
|
||||
/**
|
||||
* Fuzzy plot search with spaces separating terms.
|
||||
* - Terms: type, alias, world, owner, trusted, member
|
||||
*
|
||||
* @param search
|
||||
* @return
|
||||
*/
|
||||
public static List<Plot> getPlotsBySearch(String search) {
|
||||
String[] split = search.split(" ");
|
||||
int size = split.length * 2;
|
||||
|
||||
List<UUID> uuids = new ArrayList<>();
|
||||
PlotId id = null;
|
||||
|
||||
for (String term : split) {
|
||||
try {
|
||||
UUID uuid = PlotSquared.get().getImpromptuUUIDPipeline().getSingle(term, Settings.UUID.BLOCKING_TIMEOUT);
|
||||
if (uuid == null) {
|
||||
uuid = UUID.fromString(term);
|
||||
}
|
||||
uuids.add(uuid);
|
||||
} catch (Exception ignored) {
|
||||
id = PlotId.fromString(term);
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList<ArrayList<Plot>> plotList =
|
||||
IntStream.range(0, size).mapToObj(i -> new ArrayList<Plot>())
|
||||
.collect(Collectors.toCollection(() -> new ArrayList<>(size)));
|
||||
|
||||
PlotArea area = null;
|
||||
String alias = null;
|
||||
for (Plot plot : PlotQuery.newQuery().allPlots()) {
|
||||
int count = 0;
|
||||
if (!uuids.isEmpty()) {
|
||||
for (UUID uuid : uuids) {
|
||||
if (plot.isOwner(uuid)) {
|
||||
count += 2;
|
||||
} else if (plot.isAdded(uuid)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (id != null) {
|
||||
if (plot.getId().equals(id)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (area != null && plot.getArea().equals(area)) {
|
||||
count++;
|
||||
}
|
||||
if (alias != null && alias.equals(plot.getAlias())) {
|
||||
count += 2;
|
||||
}
|
||||
if (count != 0) {
|
||||
plotList.get(count - 1).add(plot);
|
||||
}
|
||||
}
|
||||
|
||||
List<Plot> plots = new ArrayList<>();
|
||||
for (int i = plotList.size() - 1; i >= 0; i--) {
|
||||
if (!plotList.get(i).isEmpty()) {
|
||||
plots.addAll(plotList.get(i));
|
||||
}
|
||||
}
|
||||
return plots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plot from a string.
|
||||
*
|
||||
* @param player Provides a context for what world to search in. Prefixing the term with 'world_name;' will override this context.
|
||||
* @param arg The search term
|
||||
* @param message If a message should be sent to the player if a plot cannot be found
|
||||
* @return The plot if only 1 result is found, or null
|
||||
*/
|
||||
@Nullable public static Plot getPlotFromString(PlotPlayer<?> player, String arg, boolean message) {
|
||||
if (arg == null) {
|
||||
if (player == null) {
|
||||
if (message) {
|
||||
logger.info("[P2] No plot area string was supplied");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return player.getCurrentPlot();
|
||||
}
|
||||
PlotArea area;
|
||||
if (player != null) {
|
||||
area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(arg);
|
||||
if (area == null) {
|
||||
area = player.getApplicablePlotArea();
|
||||
}
|
||||
} else {
|
||||
area = ConsolePlayer.getConsole().getApplicablePlotArea();
|
||||
}
|
||||
String[] split = arg.split(";|,");
|
||||
PlotId id;
|
||||
if (split.length == 4) {
|
||||
area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(split[0] + ';' + split[1]);
|
||||
id = PlotId.fromString(split[2] + ';' + split[3]);
|
||||
} else if (split.length == 3) {
|
||||
area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(split[0]);
|
||||
id = PlotId.fromString(split[1] + ';' + split[2]);
|
||||
} else if (split.length == 2) {
|
||||
id = PlotId.fromString(arg);
|
||||
} else {
|
||||
Collection<Plot> plots;
|
||||
if (area == null) {
|
||||
plots = PlotQuery.newQuery().allPlots().asList();
|
||||
} else {
|
||||
plots = area.getPlots();
|
||||
}
|
||||
for (Plot p : plots) {
|
||||
String name = p.getAlias();
|
||||
if (!name.isEmpty() && name.equalsIgnoreCase(arg)) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
if (message) {
|
||||
MainUtil.sendMessage(player, Captions.NOT_VALID_PLOT_ID);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (area == null) {
|
||||
if (message) {
|
||||
MainUtil.sendMessage(player, Captions.NOT_VALID_PLOT_WORLD);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return area.getPlotAbs(id);
|
||||
}
|
||||
|
||||
public static File getFile(File base, String path) {
|
||||
if (Paths.get(path).isAbsolute()) {
|
||||
return new File(path);
|
||||
}
|
||||
return new File(base, path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronously set the biome in a selection.
|
||||
*
|
||||
* @param world
|
||||
* @param p1x
|
||||
* @param p1z
|
||||
* @param p2x
|
||||
* @param p2z
|
||||
* @param biome
|
||||
*/
|
||||
public static void setBiome(String world, int p1x, int p1z, int p2x, int p2z, BiomeType biome) {
|
||||
BlockVector3 pos1 = BlockVector2.at(p1x, p1z).toBlockVector3();
|
||||
BlockVector3 pos2 = BlockVector2.at(p2x, p2z).toBlockVector3(Plot.MAX_HEIGHT - 1);
|
||||
CuboidRegion region = new CuboidRegion(pos1, pos2);
|
||||
PlotSquared.platform().getWorldUtil().setBiomes(world, region, biome);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the highest block at a location.
|
||||
*/
|
||||
public static void getHighestBlock(String world, int x, int z, IntConsumer result) {
|
||||
PlotSquared.platform().getWorldUtil().getHighestBlock(world, x, z, highest -> {
|
||||
if (highest == 0) {
|
||||
result.accept(63);
|
||||
} else {
|
||||
result.accept(highest);
|
||||
}
|
||||
});
|
||||
}
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger("P2/" + MainUtil.class.getSimpleName());
|
||||
|
||||
/**
|
||||
* Send a message to the player.
|
||||
@ -637,7 +51,7 @@ public class MainUtil {
|
||||
* @param message Message to send
|
||||
* @return true Can be used in things such as commands (return PlayerFunctions.sendMessage(...))
|
||||
*/
|
||||
public static boolean sendMessage(PlotPlayer player, String message) {
|
||||
@Deprecated public static boolean sendMessage(PlotPlayer<?> player, String message) {
|
||||
return sendMessage(player, message, true);
|
||||
}
|
||||
|
||||
@ -647,7 +61,7 @@ public class MainUtil {
|
||||
* @param caption
|
||||
* @param args
|
||||
*/
|
||||
public static void sendConsoleMessage(Captions caption, String... args) {
|
||||
@Deprecated public static void sendConsoleMessage(Captions caption, String... args) {
|
||||
sendMessage(null, caption, args);
|
||||
}
|
||||
|
||||
@ -659,7 +73,7 @@ public class MainUtil {
|
||||
* @param prefix If the message should be prefixed with the configured prefix
|
||||
* @return
|
||||
*/
|
||||
public static boolean sendMessage(PlotPlayer player, @Nonnull String msg, boolean prefix) {
|
||||
@Deprecated public static boolean sendMessage(PlotPlayer<?> player, @Nonnull String msg, boolean prefix) {
|
||||
if (!msg.isEmpty()) {
|
||||
if (player == null) {
|
||||
String message = CaptionUtility
|
||||
@ -680,7 +94,7 @@ public class MainUtil {
|
||||
* @param caption the message to send
|
||||
* @return boolean success
|
||||
*/
|
||||
public static boolean sendMessage(PlotPlayer player, Caption caption, String... args) {
|
||||
@Deprecated public static boolean sendMessage(PlotPlayer<?> player, Caption caption, String... args) {
|
||||
return sendMessage(player, caption, (Object[]) args);
|
||||
}
|
||||
|
||||
@ -691,7 +105,7 @@ public class MainUtil {
|
||||
* @param caption the message to send
|
||||
* @return boolean success
|
||||
*/
|
||||
public static boolean sendMessage(final PlotPlayer player, final Caption caption,
|
||||
@Deprecated public static boolean sendMessage(final PlotPlayer<?> player, final Caption caption,
|
||||
final Object... args) {
|
||||
if (caption.getTranslated().isEmpty()) {
|
||||
return true;
|
||||
@ -707,319 +121,4 @@ public class MainUtil {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* If rating categories are enabled, get the average rating by category.<br>
|
||||
* - The index corresponds to the index of the category in the config
|
||||
*
|
||||
* @param plot
|
||||
* @return
|
||||
*/
|
||||
public static double[] getAverageRatings(Plot plot) {
|
||||
Map<UUID, Integer> rating;
|
||||
if (plot.getSettings().getRatings() != null) {
|
||||
rating = plot.getSettings().getRatings();
|
||||
} else if (Settings.Enabled_Components.RATING_CACHE) {
|
||||
rating = new HashMap<>();
|
||||
} else {
|
||||
rating = DBFunc.getRatings(plot);
|
||||
}
|
||||
int size = 1;
|
||||
if (!Settings.Ratings.CATEGORIES.isEmpty()) {
|
||||
size = Math.max(1, Settings.Ratings.CATEGORIES.size());
|
||||
}
|
||||
double[] ratings = new double[size];
|
||||
if (rating == null || rating.isEmpty()) {
|
||||
return ratings;
|
||||
}
|
||||
for (Entry<UUID, Integer> entry : rating.entrySet()) {
|
||||
int current = entry.getValue();
|
||||
if (Settings.Ratings.CATEGORIES.isEmpty()) {
|
||||
ratings[0] += current;
|
||||
} else {
|
||||
for (int i = 0; i < Settings.Ratings.CATEGORIES.size(); i++) {
|
||||
ratings[i] += current % 10 - 1;
|
||||
current /= 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < size; i++) {
|
||||
ratings[i] /= rating.size();
|
||||
}
|
||||
return ratings;
|
||||
}
|
||||
|
||||
public static void getUUIDsFromString(final String list, final BiConsumer<Collection<UUID>, Throwable> consumer) {
|
||||
String[] split = list.split(",");
|
||||
|
||||
final Set<UUID> result = new HashSet<>();
|
||||
final List<String> request = new LinkedList<>();
|
||||
|
||||
for (final String name : split) {
|
||||
if (name.isEmpty()) {
|
||||
consumer.accept(Collections.emptySet(), null);
|
||||
return;
|
||||
} else if ("*".equals(name)) {
|
||||
result.add(DBFunc.EVERYONE);
|
||||
} else if (name.length() > 16) {
|
||||
try {
|
||||
result.add(UUID.fromString(name));
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
consumer.accept(Collections.emptySet(), null);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
request.add(name);
|
||||
}
|
||||
}
|
||||
|
||||
if (request.isEmpty()) {
|
||||
consumer.accept(result, null);
|
||||
} else {
|
||||
PlotSquared.get().getImpromptuUUIDPipeline().getUUIDs(request, Settings.UUID.NON_BLOCKING_TIMEOUT)
|
||||
.whenComplete((uuids, throwable) -> {
|
||||
if (throwable != null) {
|
||||
consumer.accept(null, throwable);
|
||||
} else {
|
||||
for (final UUIDMapping uuid : uuids) {
|
||||
result.add(uuid.getUuid());
|
||||
}
|
||||
consumer.accept(result, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a string with plot information.
|
||||
*
|
||||
* @param iInfo
|
||||
* @param plot
|
||||
* @param player
|
||||
* @param full
|
||||
* @param whenDone
|
||||
*/
|
||||
public static void format(final String iInfo, final Plot plot, PlotPlayer player,
|
||||
final boolean full, final RunnableVal<String> whenDone) {
|
||||
int num = plot.getConnectedPlots().size();
|
||||
String alias = !plot.getAlias().isEmpty() ? plot.getAlias() : Captions.NONE.getTranslated();
|
||||
Location bot = plot.getCorners()[0];
|
||||
PlotSquared.platform().getWorldUtil().getBiome(plot.getWorldName(), bot.getX(), bot.getZ(), biome -> {
|
||||
String info = iInfo;
|
||||
String trusted = getPlayerList(plot.getTrusted());
|
||||
String members = getPlayerList(plot.getMembers());
|
||||
String denied = getPlayerList(plot.getDenied());
|
||||
String seen;
|
||||
if (Settings.Enabled_Components.PLOT_EXPIRY && ExpireManager.IMP != null) {
|
||||
if (plot.isOnline()) {
|
||||
seen = Captions.NOW.getTranslated();
|
||||
} else {
|
||||
int time = (int) (ExpireManager.IMP.getAge(plot) / 1000);
|
||||
if (time != 0) {
|
||||
seen = MainUtil.secToTime(time);
|
||||
} else {
|
||||
seen = Captions.UNKNOWN.getTranslated();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
seen = Captions.NEVER.getTranslated();
|
||||
}
|
||||
|
||||
String description = plot.getFlag(DescriptionFlag.class);
|
||||
if (description.isEmpty()) {
|
||||
description = Captions.PLOT_NO_DESCRIPTION.getTranslated();
|
||||
}
|
||||
|
||||
StringBuilder flags = new StringBuilder();
|
||||
Collection<PlotFlag<?, ?>> flagCollection = plot.getApplicableFlags(true);
|
||||
if (flagCollection.isEmpty()) {
|
||||
flags.append(Captions.NONE.getTranslated());
|
||||
} else {
|
||||
String prefix = " ";
|
||||
for (final PlotFlag<?, ?> flag : flagCollection) {
|
||||
Object value;
|
||||
if (flag instanceof DoubleFlag && !Settings.General.SCIENTIFIC) {
|
||||
value = FLAG_DECIMAL_FORMAT.format(flag.getValue());
|
||||
} else {
|
||||
value = flag.toString();
|
||||
}
|
||||
flags.append(prefix).append(CaptionUtility
|
||||
.format(player, Captions.PLOT_FLAG_LIST.getTranslated(), flag.getName(),
|
||||
CaptionUtility.formatRaw(player, value.toString(), "")));
|
||||
prefix = ", ";
|
||||
}
|
||||
}
|
||||
boolean build = plot.isAdded(player.getUUID());
|
||||
String owner = plot.getOwners().isEmpty() ? "unowned" : getPlayerList(plot.getOwners());
|
||||
if (plot.getArea() != null) {
|
||||
info = info.replace("%area%",
|
||||
plot.getArea().getWorldName() + (plot.getArea().getId() == null ?
|
||||
"" :
|
||||
"(" + plot.getArea().getId() + ")"));
|
||||
} else {
|
||||
info = info.replace("%area%", Captions.NONE.getTranslated());
|
||||
}
|
||||
info = info.replace("%id%", plot.getId().toString());
|
||||
info = info.replace("%alias%", alias);
|
||||
info = info.replace("%num%", String.valueOf(num));
|
||||
info = info.replace("%desc%", description);
|
||||
info = info.replace("%biome%", biome.toString().toLowerCase());
|
||||
info = info.replace("%owner%", owner);
|
||||
info = info.replace("%members%", members);
|
||||
info = info.replace("%player%", player.getName());
|
||||
info = info.replace("%trusted%", trusted);
|
||||
info = info.replace("%helpers%", members);
|
||||
info = info.replace("%denied%", denied);
|
||||
info = info.replace("%seen%", seen);
|
||||
info = info.replace("%flags%", flags);
|
||||
info = info.replace("%build%", String.valueOf(build));
|
||||
if (info.contains("%rating%")) {
|
||||
final String newInfo = info;
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
String info1;
|
||||
if (Settings.Ratings.USE_LIKES) {
|
||||
info1 = newInfo.replaceAll("%rating%",
|
||||
String.format("%.0f%%", Like.getLikesPercentage(plot) * 100D));
|
||||
} else {
|
||||
int max = 10;
|
||||
if (Settings.Ratings.CATEGORIES != null && !Settings.Ratings.CATEGORIES
|
||||
.isEmpty()) {
|
||||
max = 8;
|
||||
}
|
||||
if (full && Settings.Ratings.CATEGORIES != null
|
||||
&& Settings.Ratings.CATEGORIES.size() > 1) {
|
||||
double[] ratings = MainUtil.getAverageRatings(plot);
|
||||
String rating = "";
|
||||
String prefix = "";
|
||||
for (int i = 0; i < ratings.length; i++) {
|
||||
rating += prefix + Settings.Ratings.CATEGORIES.get(i) + '=' + String
|
||||
.format("%.1f", ratings[i]);
|
||||
prefix = ",";
|
||||
}
|
||||
info1 = newInfo.replaceAll("%rating%", rating);
|
||||
} else {
|
||||
info1 = newInfo.replaceAll("%rating%",
|
||||
String.format("%.1f", plot.getAverageRating()) + '/' + max);
|
||||
}
|
||||
}
|
||||
whenDone.run(info1);
|
||||
});
|
||||
return;
|
||||
}
|
||||
whenDone.run(info);
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean deleteDirectory(File directory) {
|
||||
if (directory.exists()) {
|
||||
File[] files = directory.listFiles();
|
||||
if (null != files) {
|
||||
for (File file : files) {
|
||||
if (file.isDirectory()) {
|
||||
deleteDirectory(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return (directory.delete());
|
||||
}
|
||||
|
||||
/*
|
||||
@Nonnull public static String getName(UUID owner) {
|
||||
if (owner == null) {
|
||||
return Captions.NONE.getTranslated();
|
||||
}
|
||||
if (owner.equals(DBFunc.EVERYONE)) {
|
||||
return Captions.EVERYONE.getTranslated();
|
||||
}
|
||||
if (owner.equals(DBFunc.SERVER)) {
|
||||
return Captions.SERVER.getTranslated();
|
||||
}
|
||||
String name = PlotSquared.get().getImpromptuUUIDPipeline().getSingle(owner, Settings.UUID.BLOCKING_TIMEOUT);
|
||||
if (name == null) {
|
||||
return Captions.UNKNOWN.getTranslated();
|
||||
}
|
||||
return name;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get a list of names given a list of UUIDs.
|
||||
* - Uses the format {@link Captions#PLOT_USER_LIST} for the returned string
|
||||
*/
|
||||
public static String getPlayerList(final Collection<UUID> uuids) {
|
||||
if (uuids.size() < 1) {
|
||||
return Captions.NONE.getTranslated();
|
||||
}
|
||||
|
||||
final List<UUID> players = new LinkedList<>();
|
||||
final List<String> users = new LinkedList<>();
|
||||
for (final UUID uuid : uuids) {
|
||||
if (uuid == null) {
|
||||
users.add(Captions.NONE.getTranslated());
|
||||
} else if (DBFunc.EVERYONE.equals(uuid)) {
|
||||
users.add(Captions.EVERYONE.getTranslated());
|
||||
} else if (DBFunc.SERVER.equals(uuid)) {
|
||||
users.add(Captions.SERVER.getTranslated());
|
||||
} else {
|
||||
players.add(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
for (final UUIDMapping mapping : PlotSquared.get().getImpromptuUUIDPipeline().getNames(players).get(Settings.UUID.BLOCKING_TIMEOUT,
|
||||
TimeUnit.MILLISECONDS)) {
|
||||
users.add(mapping.getUsername());
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
String c = Captions.PLOT_USER_LIST.getTranslated();
|
||||
StringBuilder list = new StringBuilder();
|
||||
for (int x = 0; x < users.size(); x++) {
|
||||
if (x + 1 == uuids.size()) {
|
||||
list.append(c.replace("%user%", users.get(x)).replace(",", ""));
|
||||
} else {
|
||||
list.append(c.replace("%user%", users.get(x)));
|
||||
}
|
||||
}
|
||||
return list.toString();
|
||||
}
|
||||
|
||||
public static void getPersistentMeta(UUID uuid, final String key,
|
||||
final RunnableVal<byte[]> result) {
|
||||
PlotPlayer player = PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuid);
|
||||
if (player != null) {
|
||||
result.run(player.getPersistentMeta(key));
|
||||
} else {
|
||||
DBFunc.getPersistentMeta(uuid, new RunnableVal<Map<String, byte[]>>() {
|
||||
@Override public void run(Map<String, byte[]> value) {
|
||||
result.run(value.get(key));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> T getValueFromConfig(ConfigurationSection config, String path,
|
||||
IntFunction<Optional<T>> intParser, Function<String, Optional<T>> textualParser,
|
||||
Supplier<T> defaultValue) {
|
||||
String value = config.getString(path);
|
||||
if (value == null) {
|
||||
return defaultValue.get();
|
||||
}
|
||||
if (MathMan.isInteger(value)) {
|
||||
return intParser.apply(Integer.parseInt(value)).orElseGet(defaultValue);
|
||||
}
|
||||
return textualParser.apply(value).orElseGet(defaultValue);
|
||||
}
|
||||
|
||||
public static PlotAreaType getType(ConfigurationSection config) {
|
||||
return getValueFromConfig(config, "generator.type", PlotAreaType::fromLegacyInt,
|
||||
PlotAreaType::fromString, () -> PlotAreaType.NORMAL);
|
||||
}
|
||||
|
||||
public static PlotAreaTerrainType getTerrain(ConfigurationSection config) {
|
||||
return getValueFromConfig(config, "generator.terrain", PlotAreaTerrainType::fromLegacyInt,
|
||||
PlotAreaTerrainType::fromString, () -> PlotAreaTerrainType.NONE);
|
||||
}
|
||||
}
|
||||
|
@ -1,141 +0,0 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2020 IntellectualSites
|
||||
*
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.core.util;
|
||||
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.google.common.util.concurrent.ListeningExecutorService;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.extension.platform.Platform;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class OperationUtil {
|
||||
private static final boolean ASYNC;
|
||||
|
||||
static {
|
||||
boolean hasFawe = true;
|
||||
try {
|
||||
Class.forName("com.boydti.fawe.Fawe");
|
||||
} catch (ClassNotFoundException ignore) {
|
||||
hasFawe = false;
|
||||
}
|
||||
ASYNC = hasFawe;
|
||||
}
|
||||
|
||||
private static World getWorld(String worldName) {
|
||||
Platform platform =
|
||||
WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING);
|
||||
List<? extends World> worlds = platform.getWorlds();
|
||||
for (World current : worlds) {
|
||||
if (current.getName().equals(worldName)) {
|
||||
return current;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static World getWorld(PlotPlayer plotPlayer, Actor actor) {
|
||||
World weWorld;
|
||||
if (actor instanceof Player) {
|
||||
weWorld = ((Player) actor).getWorld();
|
||||
} else {
|
||||
@Nonnull Location loc = plotPlayer.getLocation();
|
||||
String world = loc.getWorldName();
|
||||
weWorld = getWorld(world);
|
||||
}
|
||||
return weWorld;
|
||||
}
|
||||
|
||||
private static EditSession createEditSession(PlotPlayer plotPlayer) {
|
||||
Actor actor = plotPlayer.toActor();
|
||||
World weWorld = getWorld(plotPlayer, actor);
|
||||
return createEditSession(weWorld, actor);
|
||||
}
|
||||
|
||||
private static LocalSession getSession(Actor actor) {
|
||||
return WorldEdit.getInstance().getSessionManager().get(actor);
|
||||
}
|
||||
|
||||
private static EditSession createEditSession(World world, Actor actor) {
|
||||
return createEditSession(world, actor, getSession(actor));
|
||||
}
|
||||
|
||||
private static EditSession createEditSession(World world, Actor actor, LocalSession session) {
|
||||
EditSession editSession;
|
||||
Player player = actor.isPlayer() ? (Player) actor : null;
|
||||
editSession =
|
||||
WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1, null, player);
|
||||
|
||||
editSession.setFastMode(!actor.isPlayer());
|
||||
editSession.setReorderMode(EditSession.ReorderMode.FAST);
|
||||
return editSession;
|
||||
}
|
||||
|
||||
public Future<?> withEditSession(@Nonnull PlotPlayer plotPlayer,
|
||||
@Nonnull Consumer<EditSession> consumer, @Nullable Consumer<Throwable> exceptionHandler) {
|
||||
if (ASYNC) {
|
||||
ListeningExecutorService exec = WorldEdit.getInstance().getExecutorService();
|
||||
return exec
|
||||
.submit(() -> withEditSessionOnThread(plotPlayer, consumer, exceptionHandler));
|
||||
} else {
|
||||
withEditSessionOnThread(plotPlayer, consumer, exceptionHandler);
|
||||
}
|
||||
return Futures.immediateFuture(true);
|
||||
}
|
||||
|
||||
private void withEditSessionOnThread(PlotPlayer plotPlayer, Consumer<EditSession> consumer,
|
||||
Consumer<Throwable> exceptionHandler) {
|
||||
Actor actor = plotPlayer.toActor();
|
||||
World weWorld = getWorld(plotPlayer, actor);
|
||||
LocalSession session = getSession(actor);
|
||||
try (EditSession ess = createEditSession(weWorld, actor, session)) {
|
||||
try {
|
||||
consumer.accept(ess);
|
||||
} finally {
|
||||
ess.close();
|
||||
session.remember(ess);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
if (exceptionHandler != null) {
|
||||
exceptionHandler.accept(e);
|
||||
} else {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -25,8 +25,14 @@
|
||||
*/
|
||||
package com.plotsquared.core.util;
|
||||
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.database.DBFunc;
|
||||
import com.plotsquared.core.player.OfflinePlotPlayer;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.uuid.UUIDMapping;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@ -34,8 +40,14 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
/**
|
||||
* Manages player instances
|
||||
@ -45,6 +57,142 @@ public abstract class PlayerManager<P extends PlotPlayer<? extends T>, T> {
|
||||
private final Map<UUID, P> playerMap = new HashMap<>();
|
||||
private final Object playerLock = new Object();
|
||||
|
||||
public static void getUUIDsFromString(@Nonnull final String list,
|
||||
@Nonnull final BiConsumer<Collection<UUID>, Throwable> consumer) {
|
||||
String[] split = list.split(",");
|
||||
|
||||
final Set<UUID> result = new HashSet<>();
|
||||
final List<String> request = new LinkedList<>();
|
||||
|
||||
for (final String name : split) {
|
||||
if (name.isEmpty()) {
|
||||
consumer.accept(Collections.emptySet(), null);
|
||||
return;
|
||||
} else if ("*".equals(name)) {
|
||||
result.add(DBFunc.EVERYONE);
|
||||
} else if (name.length() > 16) {
|
||||
try {
|
||||
result.add(UUID.fromString(name));
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
consumer.accept(Collections.emptySet(), null);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
request.add(name);
|
||||
}
|
||||
}
|
||||
|
||||
if (request.isEmpty()) {
|
||||
consumer.accept(result, null);
|
||||
} else {
|
||||
PlotSquared.get().getImpromptuUUIDPipeline()
|
||||
.getUUIDs(request, Settings.UUID.NON_BLOCKING_TIMEOUT)
|
||||
.whenComplete((uuids, throwable) -> {
|
||||
if (throwable != null) {
|
||||
consumer.accept(null, throwable);
|
||||
} else {
|
||||
for (final UUIDMapping uuid : uuids) {
|
||||
result.add(uuid.getUuid());
|
||||
}
|
||||
consumer.accept(result, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of names given a list of UUIDs.
|
||||
* - Uses the format {@link Captions#PLOT_USER_LIST} for the returned string
|
||||
*
|
||||
* @param uuids UUIDs
|
||||
* @return Name list
|
||||
*/
|
||||
@Nonnull public static String getPlayerList(@Nonnull final Collection<UUID> uuids) {
|
||||
if (uuids.size() < 1) {
|
||||
return Captions.NONE.getTranslated();
|
||||
}
|
||||
|
||||
final List<UUID> players = new LinkedList<>();
|
||||
final List<String> users = new LinkedList<>();
|
||||
for (final UUID uuid : uuids) {
|
||||
if (uuid == null) {
|
||||
users.add(Captions.NONE.getTranslated());
|
||||
} else if (DBFunc.EVERYONE.equals(uuid)) {
|
||||
users.add(Captions.EVERYONE.getTranslated());
|
||||
} else if (DBFunc.SERVER.equals(uuid)) {
|
||||
users.add(Captions.SERVER.getTranslated());
|
||||
} else {
|
||||
players.add(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
for (final UUIDMapping mapping : PlotSquared.get().getImpromptuUUIDPipeline()
|
||||
.getNames(players).get(Settings.UUID.BLOCKING_TIMEOUT, TimeUnit.MILLISECONDS)) {
|
||||
users.add(mapping.getUsername());
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
String c = Captions.PLOT_USER_LIST.getTranslated();
|
||||
StringBuilder list = new StringBuilder();
|
||||
for (int x = 0; x < users.size(); x++) {
|
||||
if (x + 1 == uuids.size()) {
|
||||
list.append(c.replace("%user%", users.get(x)).replace(",", ""));
|
||||
} else {
|
||||
list.append(c.replace("%user%", users.get(x)));
|
||||
}
|
||||
}
|
||||
return list.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name from a UUID.
|
||||
*
|
||||
* @param owner Owner UUID
|
||||
* @return The player's name, None, Everyone or Unknown
|
||||
*/
|
||||
@Nonnull public static String getName(@Nullable final UUID owner) {
|
||||
return getName(owner, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name from a UUID.
|
||||
*
|
||||
* @param owner Owner UUID
|
||||
* @param blocking Whether or not the operation can be blocking
|
||||
* @return The player's name, None, Everyone or Unknown
|
||||
*/
|
||||
@Nonnull public static String getName(@Nullable final UUID owner, final boolean blocking) {
|
||||
if (owner == null) {
|
||||
return Captions.NONE.getTranslated();
|
||||
}
|
||||
if (owner.equals(DBFunc.EVERYONE)) {
|
||||
return Captions.EVERYONE.getTranslated();
|
||||
}
|
||||
if (owner.equals(DBFunc.SERVER)) {
|
||||
return Captions.SERVER.getTranslated();
|
||||
}
|
||||
final String name;
|
||||
if (blocking) {
|
||||
name = PlotSquared.get().getImpromptuUUIDPipeline()
|
||||
.getSingle(owner, Settings.UUID.BLOCKING_TIMEOUT);
|
||||
} else {
|
||||
final UUIDMapping uuidMapping =
|
||||
PlotSquared.get().getImpromptuUUIDPipeline().getImmediately(owner);
|
||||
if (uuidMapping != null) {
|
||||
name = uuidMapping.getUsername();
|
||||
} else {
|
||||
name = null;
|
||||
}
|
||||
}
|
||||
if (name == null) {
|
||||
return Captions.UNKNOWN.getTranslated();
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a player from the player map
|
||||
*
|
||||
|
@ -25,6 +25,7 @@
|
||||
*/
|
||||
package com.plotsquared.core.util;
|
||||
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
@ -32,8 +33,45 @@ import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.util.Collection;
|
||||
|
||||
public class RegionUtil {
|
||||
|
||||
@Nonnull public static Location[] getCorners(@Nonnull final String world,
|
||||
@Nonnull final CuboidRegion region) {
|
||||
final BlockVector3 min = region.getMinimumPoint();
|
||||
final BlockVector3 max = region.getMaximumPoint();
|
||||
return new Location[] {Location.at(world, min), Location.at(world, max)};
|
||||
}
|
||||
|
||||
@Nonnull public static Location[] getCorners(String world, Collection<CuboidRegion> regions) {
|
||||
Location min = null;
|
||||
Location max = null;
|
||||
for (CuboidRegion region : regions) {
|
||||
Location[] corners = getCorners(world, region);
|
||||
if (min == null) {
|
||||
min = corners[0];
|
||||
max = corners[1];
|
||||
continue;
|
||||
}
|
||||
Location pos1 = corners[0];
|
||||
Location pos2 = corners[1];
|
||||
if (pos2.getX() > max.getX()) {
|
||||
max = max.withX(pos2.getX());
|
||||
}
|
||||
if (pos1.getX() < min.getX()) {
|
||||
min = min.withX(pos1.getX());
|
||||
}
|
||||
if (pos2.getZ() > max.getZ()) {
|
||||
max = max.withZ(pos2.getZ());
|
||||
}
|
||||
if (pos1.getZ() < min.getZ()) {
|
||||
min = min.withZ(pos1.getZ());
|
||||
}
|
||||
}
|
||||
return new Location[] {min, max};
|
||||
}
|
||||
|
||||
public static CuboidRegion createRegion(int pos1x, int pos2x, int pos1z, int pos2z) {
|
||||
return createRegion(pos1x, pos2x, 0, Plot.MAX_HEIGHT - 1, pos1z, pos2z);
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.schematic.Schematic;
|
||||
import com.plotsquared.core.queue.QueueCoordinator;
|
||||
import com.plotsquared.core.util.net.AbstractDelegateOutputStream;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.plotsquared.core.util.task.TaskTime;
|
||||
@ -65,6 +66,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
@ -75,10 +77,15 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -88,6 +95,7 @@ import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
@ -107,6 +115,84 @@ public abstract class SchematicHandler {
|
||||
this.worldUtil = worldUtil;
|
||||
}
|
||||
|
||||
public static void upload(@Nullable UUID uuid, @Nullable final String file,
|
||||
@Nonnull final String extension, @Nullable final RunnableVal<OutputStream> writeTask,
|
||||
@Nonnull final RunnableVal<URL> whenDone) {
|
||||
if (writeTask == null) {
|
||||
TaskManager.runTask(whenDone);
|
||||
return;
|
||||
}
|
||||
final String filename;
|
||||
final String website;
|
||||
if (uuid == null) {
|
||||
uuid = UUID.randomUUID();
|
||||
website = Settings.Web.URL + "upload.php?" + uuid;
|
||||
filename = "plot." + extension;
|
||||
} else {
|
||||
website = Settings.Web.URL + "save.php?" + uuid;
|
||||
filename = file + '.' + extension;
|
||||
}
|
||||
final URL url;
|
||||
try {
|
||||
url = new URL(Settings.Web.URL + "?key=" + uuid + "&type=" + extension);
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
whenDone.run();
|
||||
return;
|
||||
}
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
try {
|
||||
String boundary = Long.toHexString(System.currentTimeMillis());
|
||||
URLConnection con = new URL(website).openConnection();
|
||||
con.setDoOutput(true);
|
||||
con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
|
||||
try (OutputStream output = con.getOutputStream();
|
||||
PrintWriter writer = new PrintWriter(
|
||||
new OutputStreamWriter(output, StandardCharsets.UTF_8), true)) {
|
||||
String CRLF = "\r\n";
|
||||
writer.append("--" + boundary).append(CRLF);
|
||||
writer.append("Content-Disposition: form-data; name=\"param\"").append(CRLF);
|
||||
writer.append(
|
||||
"Content-Type: text/plain; charset=" + StandardCharsets.UTF_8.displayName())
|
||||
.append(CRLF);
|
||||
String param = "value";
|
||||
writer.append(CRLF).append(param).append(CRLF).flush();
|
||||
writer.append("--" + boundary).append(CRLF);
|
||||
writer.append(
|
||||
"Content-Disposition: form-data; name=\"schematicFile\"; filename=\""
|
||||
+ filename + '"').append(CRLF);
|
||||
writer
|
||||
.append("Content-Type: " + URLConnection.guessContentTypeFromName(filename))
|
||||
.append(CRLF);
|
||||
writer.append("Content-Transfer-Encoding: binary").append(CRLF);
|
||||
writer.append(CRLF).flush();
|
||||
writeTask.value = new AbstractDelegateOutputStream(output) {
|
||||
@Override public void close() {
|
||||
} // Don't close
|
||||
};
|
||||
writeTask.run();
|
||||
output.flush();
|
||||
writer.append(CRLF).flush();
|
||||
writer.append("--" + boundary + "--").append(CRLF).flush();
|
||||
}
|
||||
String content;
|
||||
try (Scanner scanner = new Scanner(con.getInputStream()).useDelimiter("\\A")) {
|
||||
content = scanner.next().trim();
|
||||
}
|
||||
if (!content.startsWith("<")) {
|
||||
}
|
||||
int responseCode = ((HttpURLConnection) con).getResponseCode();
|
||||
if (responseCode == 200) {
|
||||
whenDone.value = url;
|
||||
}
|
||||
TaskManager.runTask(whenDone);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
TaskManager.runTask(whenDone);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean exportAll(Collection<Plot> collection, final File outputDir,
|
||||
final String namingScheme, final Runnable ifSuccess) {
|
||||
if (this.exportAll) {
|
||||
@ -313,7 +399,7 @@ public abstract class SchematicHandler {
|
||||
*/
|
||||
public Schematic getSchematic(String name) throws UnsupportedFormatException {
|
||||
File parent =
|
||||
MainUtil.getFile(PlotSquared.platform().getDirectory(), Settings.Paths.SCHEMATICS);
|
||||
FileUtils.getFile(PlotSquared.platform().getDirectory(), Settings.Paths.SCHEMATICS);
|
||||
if (!parent.exists()) {
|
||||
if (!parent.mkdir()) {
|
||||
throw new RuntimeException("Could not create schematic parent directory");
|
||||
@ -322,10 +408,10 @@ public abstract class SchematicHandler {
|
||||
if (!name.endsWith(".schem") && !name.endsWith(".schematic")) {
|
||||
name = name + ".schem";
|
||||
}
|
||||
File file = MainUtil.getFile(PlotSquared.platform().getDirectory(),
|
||||
File file = FileUtils.getFile(PlotSquared.platform().getDirectory(),
|
||||
Settings.Paths.SCHEMATICS + File.separator + name);
|
||||
if (!file.exists()) {
|
||||
file = MainUtil.getFile(PlotSquared.platform().getDirectory(),
|
||||
file = FileUtils.getFile(PlotSquared.platform().getDirectory(),
|
||||
Settings.Paths.SCHEMATICS + File.separator + name);
|
||||
}
|
||||
return getSchematic(file);
|
||||
@ -338,7 +424,7 @@ public abstract class SchematicHandler {
|
||||
*/
|
||||
public Collection<String> getSchematicNames() {
|
||||
final File parent =
|
||||
MainUtil.getFile(PlotSquared.platform().getDirectory(), Settings.Paths.SCHEMATICS);
|
||||
FileUtils.getFile(PlotSquared.platform().getDirectory(), Settings.Paths.SCHEMATICS);
|
||||
final List<String> names = new ArrayList<>();
|
||||
if (parent.exists()) {
|
||||
final String[] rawNames =
|
||||
@ -437,7 +523,7 @@ public abstract class SchematicHandler {
|
||||
TaskManager.runTask(whenDone);
|
||||
return;
|
||||
}
|
||||
MainUtil.upload(uuid, file, "schem", new RunnableVal<OutputStream>() {
|
||||
upload(uuid, file, "schem", new RunnableVal<OutputStream>() {
|
||||
@Override public void run(OutputStream output) {
|
||||
try (NBTOutputStream nos = new NBTOutputStream(
|
||||
new GZIPOutputStream(output, true))) {
|
||||
@ -461,7 +547,7 @@ public abstract class SchematicHandler {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
File tmp = MainUtil.getFile(PlotSquared.platform().getDirectory(), path);
|
||||
File tmp = FileUtils.getFile(PlotSquared.platform().getDirectory(), path);
|
||||
tmp.getParentFile().mkdirs();
|
||||
try (NBTOutputStream nbtStream = new NBTOutputStream(
|
||||
new GZIPOutputStream(new FileOutputStream(tmp)))) {
|
||||
@ -481,7 +567,7 @@ public abstract class SchematicHandler {
|
||||
// async
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
// Main positions
|
||||
Location[] corners = MainUtil.getCorners(world, regions);
|
||||
Location[] corners = RegionUtil.getCorners(world, regions);
|
||||
final Location bot = corners[0];
|
||||
final Location top = corners[1];
|
||||
|
||||
|
@ -1,97 +0,0 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2020 IntellectualSites
|
||||
*
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.core.util;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class StringWrapper {
|
||||
|
||||
public final String value;
|
||||
private int hash;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param value to wrap
|
||||
*/
|
||||
public StringWrapper(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a wrapped string equals another one
|
||||
*
|
||||
* @param obj to compare
|
||||
* @return true if obj equals the stored value
|
||||
*/
|
||||
@Override public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
if (obj.getClass() == String.class) {
|
||||
return obj.toString().equalsIgnoreCase(this.value);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (obj.hashCode() != hashCode()) {
|
||||
return false;
|
||||
}
|
||||
StringWrapper other = (StringWrapper) obj;
|
||||
if ((other.value == null) || (this.value == null)) {
|
||||
return false;
|
||||
}
|
||||
return other.value.equalsIgnoreCase(this.value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the string value.
|
||||
*
|
||||
* @return string value
|
||||
*/
|
||||
@Override public String toString() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the hash value.
|
||||
*
|
||||
* @return has value
|
||||
*/
|
||||
@Override public int hashCode() {
|
||||
if (this.value == null) {
|
||||
return 0;
|
||||
}
|
||||
if (this.hash == 0) {
|
||||
this.hash = this.value.toLowerCase().hashCode();
|
||||
}
|
||||
return this.hash;
|
||||
}
|
||||
}
|
129
Core/src/main/java/com/plotsquared/core/util/TimeUtil.java
Normal file
129
Core/src/main/java/com/plotsquared/core/util/TimeUtil.java
Normal file
@ -0,0 +1,129 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2020 IntellectualSites
|
||||
*
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.core.util;
|
||||
|
||||
import javax.annotation.Nonnegative;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public final class TimeUtil {
|
||||
|
||||
private TimeUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Format seconds into a string with the format
|
||||
* #y #w #d #h #s
|
||||
*
|
||||
* @param time Time to format
|
||||
* @return Formatted string
|
||||
*/
|
||||
@Nonnull public static String secToTime(@Nonnegative long time) {
|
||||
StringBuilder toReturn = new StringBuilder();
|
||||
if (time >= 33868800) {
|
||||
int years = (int) (time / 33868800);
|
||||
time -= years * 33868800;
|
||||
toReturn.append(years).append("y ");
|
||||
}
|
||||
if (time >= 604800) {
|
||||
int weeks = (int) (time / 604800);
|
||||
time -= weeks * 604800;
|
||||
toReturn.append(weeks).append("w ");
|
||||
}
|
||||
if (time >= 86400) {
|
||||
int days = (int) (time / 86400);
|
||||
time -= days * 86400;
|
||||
toReturn.append(days).append("d ");
|
||||
}
|
||||
if (time >= 3600) {
|
||||
int hours = (int) (time / 3600);
|
||||
time -= hours * 3600;
|
||||
toReturn.append(hours).append("h ");
|
||||
}
|
||||
if (time >= 60) {
|
||||
int minutes = (int) (time / 60);
|
||||
time -= minutes * 60;
|
||||
toReturn.append(minutes).append("m ");
|
||||
}
|
||||
if (toReturn.length() == 0 || time > 0) {
|
||||
toReturn.append(time).append("s ");
|
||||
}
|
||||
return toReturn.toString().trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a time string back into time
|
||||
*
|
||||
* @param string String to parse
|
||||
* @return Parsed time
|
||||
*/
|
||||
@Nonnegative public static long timeToSec(@Nonnull String string) {
|
||||
if (MathMan.isInteger(string)) {
|
||||
return Long.parseLong(string);
|
||||
}
|
||||
string = string.toLowerCase().trim().toLowerCase();
|
||||
if (string.equalsIgnoreCase("false")) {
|
||||
return 0;
|
||||
}
|
||||
final String[] split = string.split(" ");
|
||||
long time = 0;
|
||||
for (final String value : split) {
|
||||
final int numbers = Integer.parseInt(value.replaceAll("[^\\d]", ""));
|
||||
String letters = value.replaceAll("[^a-z]", "");
|
||||
switch (letters) {
|
||||
case "week":
|
||||
case "weeks":
|
||||
case "wks":
|
||||
case "w":
|
||||
|
||||
time += 604800 * numbers;
|
||||
case "days":
|
||||
case "day":
|
||||
case "d":
|
||||
time += 86400 * numbers;
|
||||
case "hour":
|
||||
case "hr":
|
||||
case "hrs":
|
||||
case "hours":
|
||||
case "h":
|
||||
time += 3600 * numbers;
|
||||
case "minutes":
|
||||
case "minute":
|
||||
case "mins":
|
||||
case "min":
|
||||
case "m":
|
||||
time += 60 * numbers;
|
||||
case "seconds":
|
||||
case "second":
|
||||
case "secs":
|
||||
case "sec":
|
||||
case "s":
|
||||
time += numbers;
|
||||
}
|
||||
}
|
||||
return time;
|
||||
}
|
||||
|
||||
}
|
@ -36,6 +36,7 @@ import com.sk89q.jnbt.NBTInputStream;
|
||||
import com.sk89q.jnbt.NBTOutputStream;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
@ -70,6 +71,23 @@ public abstract class WorldUtil {
|
||||
this.regionManager = regionManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the biome in a region
|
||||
*
|
||||
* @param world World name
|
||||
* @param p1x Min X
|
||||
* @param p1z Min Z
|
||||
* @param p2x Max X
|
||||
* @param p2z Max Z
|
||||
* @param biome Biome
|
||||
*/
|
||||
public static void setBiome(String world, int p1x, int p1z, int p2x, int p2z, BiomeType biome) {
|
||||
BlockVector3 pos1 = BlockVector2.at(p1x, p1z).toBlockVector3();
|
||||
BlockVector3 pos2 = BlockVector2.at(p2x, p2z).toBlockVector3(Plot.MAX_HEIGHT - 1);
|
||||
CuboidRegion region = new CuboidRegion(pos1, pos2);
|
||||
PlotSquared.platform().getWorldUtil().setBiomes(world, region, biome);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a given world name corresponds to a real world
|
||||
*
|
||||
@ -222,7 +240,7 @@ public abstract class WorldUtil {
|
||||
|
||||
public void upload(@Nonnull final Plot plot, @Nullable final UUID uuid,
|
||||
@Nullable final String file, @Nonnull final RunnableVal<URL> whenDone) {
|
||||
plot.getHome(home -> MainUtil.upload(uuid, file, "zip", new RunnableVal<OutputStream>() {
|
||||
plot.getHome(home -> SchematicHandler.upload(uuid, file, "zip", new RunnableVal<OutputStream>() {
|
||||
@Override public void run(OutputStream output) {
|
||||
try (final ZipOutputStream zos = new ZipOutputStream(output)) {
|
||||
File dat = getDat(plot.getWorldName());
|
||||
|
@ -25,11 +25,19 @@
|
||||
*/
|
||||
package com.plotsquared.core.util.query;
|
||||
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import javax.annotation.Nonnull;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.PlotId;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
class SearchPlotProvider implements PlotProvider {
|
||||
|
||||
@ -40,7 +48,76 @@ class SearchPlotProvider implements PlotProvider {
|
||||
}
|
||||
|
||||
@Override public Collection<Plot> getPlots() {
|
||||
return MainUtil.getPlotsBySearch(this.searchTerm);
|
||||
return getPlotsBySearch(this.searchTerm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fuzzy plot search with spaces separating terms.
|
||||
* - Terms: type, alias, world, owner, trusted, member
|
||||
*
|
||||
* @param search Search string
|
||||
* @return Search results
|
||||
*/
|
||||
@Nonnull private static List<Plot> getPlotsBySearch(@Nonnull final String search) {
|
||||
String[] split = search.split(" ");
|
||||
int size = split.length * 2;
|
||||
|
||||
List<UUID> uuids = new ArrayList<>();
|
||||
PlotId id = null;
|
||||
|
||||
for (String term : split) {
|
||||
try {
|
||||
UUID uuid = PlotSquared.get().getImpromptuUUIDPipeline()
|
||||
.getSingle(term, Settings.UUID.BLOCKING_TIMEOUT);
|
||||
if (uuid == null) {
|
||||
uuid = UUID.fromString(term);
|
||||
}
|
||||
uuids.add(uuid);
|
||||
} catch (Exception ignored) {
|
||||
id = PlotId.fromString(term);
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList<ArrayList<Plot>> plotList =
|
||||
IntStream.range(0, size).mapToObj(i -> new ArrayList<Plot>())
|
||||
.collect(Collectors.toCollection(() -> new ArrayList<>(size)));
|
||||
|
||||
PlotArea area = null;
|
||||
String alias = null;
|
||||
for (Plot plot : PlotQuery.newQuery().allPlots()) {
|
||||
int count = 0;
|
||||
if (!uuids.isEmpty()) {
|
||||
for (UUID uuid : uuids) {
|
||||
if (plot.isOwner(uuid)) {
|
||||
count += 2;
|
||||
} else if (plot.isAdded(uuid)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (id != null) {
|
||||
if (plot.getId().equals(id)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (area != null && plot.getArea().equals(area)) {
|
||||
count++;
|
||||
}
|
||||
if (alias != null && alias.equals(plot.getAlias())) {
|
||||
count += 2;
|
||||
}
|
||||
if (count != 0) {
|
||||
plotList.get(count - 1).add(plot);
|
||||
}
|
||||
}
|
||||
|
||||
List<Plot> plots = new ArrayList<>();
|
||||
for (int i = plotList.size() - 1; i >= 0; i--) {
|
||||
if (!plotList.get(i).isEmpty()) {
|
||||
plots.addAll(plotList.get(i));
|
||||
}
|
||||
}
|
||||
return plots;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user