Merge branch 'v6' into feature/v6/json

This commit is contained in:
Alexander Söderberg
2020-07-14 16:52:40 +02:00
committed by GitHub
18 changed files with 207 additions and 183 deletions

View File

@ -155,11 +155,9 @@ public class PlotSquared {
public WorldEdit worldedit;
public File configFile;
public File worldsFile;
public File commandsFile;
public File translationFile;
public YamlConfiguration worlds;
public YamlConfiguration storage;
public YamlConfiguration commands;
// Temporary hold the plots/clusters before the worlds load
public HashMap<String, Set<PlotCluster>> clusters_tmp;
public HashMap<String, HashMap<PlotId, Plot>> plots_tmp;
@ -269,6 +267,7 @@ public class PlotSquared {
if (Settings.Enabled_Components.CHUNK_PROCESSOR) {
this.IMP.registerChunkProcessor();
}
startExpiryTasks();
// Create Event utility class
eventDispatcher = new EventDispatcher();
// create Hybrid utility class
@ -1786,22 +1785,6 @@ public class PlotSquared {
} catch (IOException ignored) {
PlotSquared.log("Failed to save storage.yml");
}
try {
this.commandsFile = new File(folder, "commands.yml");
if (!this.commandsFile.exists() && !this.commandsFile.createNewFile()) {
PlotSquared.log(
"Could not the storage settings file, please create \"commands.yml\" manually.");
}
this.commands = YamlConfiguration.loadConfiguration(this.commandsFile);
} catch (IOException ignored) {
PlotSquared.log("Failed to save commands.yml");
}
try {
this.commands.save(this.commandsFile);
} catch (IOException e) {
PlotSquared.log("Configuration file saving failed");
e.printStackTrace();
}
return true;
}

View File

@ -43,7 +43,6 @@ import lombok.SneakyThrows;
import net.kyori.adventure.text.minimessage.Template;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
@ -193,36 +192,16 @@ public abstract class Command {
this.permission = declaration.permission();
this.required = declaration.requiredType();
this.category = declaration.category();
List<String> aliasOptions = new ArrayList<>();
aliasOptions.add(this.id);
aliasOptions.addAll(Arrays.asList(declaration.aliases()));
HashMap<String, Object> options = new HashMap<>();
options.put("aliases", aliasOptions);
options.put("description", declaration.description());
options.put("usage", declaration.usage());
options.put("confirmation", declaration.confirmation());
boolean set = false;
YamlConfiguration commands =
PlotSquared.get() == null ? new YamlConfiguration() : PlotSquared.get().commands;
for (Map.Entry<String, Object> entry : options.entrySet()) {
String key = this.getFullId() + "." + entry.getKey();
if (!commands.contains(key)) {
commands.set(key, entry.getValue());
set = true;
}
}
if (set && PlotSquared.get() != null) {
try {
commands.save(PlotSquared.get().commandsFile);
} catch (IOException e) {
e.printStackTrace();
}
}
this.aliases = commands.getStringList(this.getFullId() + ".aliases");
this.description = commands.getString(this.getFullId() + ".description");
this.usage = commands.getString(this.getFullId() + ".usage");
this.confirmation = commands.getBoolean(this.getFullId() + ".confirmation");
this.aliases = aliasOptions;
this.description = declaration.description();
this.usage = declaration.usage();
this.confirmation = declaration.confirmation();
if (this.parent != null) {
this.parent.register(this);
}

View File

@ -84,7 +84,7 @@ public class HomeCommand extends Command {
@NotNull private PlotQuery query(@NotNull final PlotPlayer<?> player) {
// everything plots need to have in common here
return PlotQuery.newQuery().ownedBy(player).whereBasePlot();
return PlotQuery.newQuery().ownedBy(player);
}
@Override public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
@ -107,6 +107,7 @@ public class HomeCommand extends Command {
PlotQuery query = query(player);
int page = 1; // page = index + 1
String identifier;
boolean basePlotOnly = true;
switch (args.length) {
case 1:
identifier = args[0];
@ -124,6 +125,7 @@ public class HomeCommand extends Command {
Plot fromId = MainUtil.getPlotFromString(player, identifier, false);
if (fromId != null && fromId.isOwner(player.getUUID())) {
// it was a valid plot id
basePlotOnly = false;
query.withPlot(fromId);
break;
}
@ -165,12 +167,16 @@ public class HomeCommand extends Command {
break;
}
// as the query already filters by owner, this is fine
basePlotOnly = false;
query.withPlot(plot);
break;
case 0:
query.withSortingStrategy(SortingStrategy.SORT_BY_CREATION);
break;
}
if (basePlotOnly) {
query.whereBasePlot();
}
home(player, query, page, confirm, whenDone);
return CompletableFuture.completedFuture(true);
}

View File

@ -388,6 +388,9 @@ public class Settings extends Config {
@Comment(
"Whether schematic based generation should paste schematic on top of plots, or from Y=1")
public static boolean PASTE_ON_TOP = true;
@Comment(
"Whether schematic based road generation should paste schematic on top of roads, or from Y=1")
public static boolean PASTE_ROAD_ON_TOP = true;
}

View File

@ -47,7 +47,8 @@ public class HybridGen extends IndependentPlotGenerator {
private void placeSchem(HybridPlotWorld world, ScopedLocalBlockQueue result, short relativeX,
short relativeZ, int x, int z, boolean isRoad) {
int minY; // Math.min(world.PLOT_HEIGHT, world.ROAD_HEIGHT);
if (isRoad || Settings.Schematics.PASTE_ON_TOP) {
if ((isRoad && Settings.Schematics.PASTE_ROAD_ON_TOP) || (!isRoad
&& Settings.Schematics.PASTE_ON_TOP)) {
minY = world.SCHEM_Y;
} else {
minY = 1;

View File

@ -112,15 +112,17 @@ public class HybridPlotManager extends ClassicPlotManager {
return true;
}
LocalBlockQueue queue = hybridPlotWorld.getQueue(false);
createSchemAbs(queue, pos1, pos2);
createSchemAbs(queue, pos1, pos2, true);
queue.enqueue();
return true;
}
private void createSchemAbs(LocalBlockQueue queue, Location pos1, Location pos2) {
private void createSchemAbs(LocalBlockQueue queue, Location pos1, Location pos2,
boolean isRoad) {
int size = hybridPlotWorld.SIZE;
int minY;
if (Settings.Schematics.PASTE_ON_TOP) {
if ((isRoad && Settings.Schematics.PASTE_ROAD_ON_TOP) || (!isRoad
&& Settings.Schematics.PASTE_ON_TOP)) {
minY = hybridPlotWorld.SCHEM_Y;
} else {
minY = 1;
@ -172,7 +174,7 @@ public class HybridPlotManager extends ClassicPlotManager {
return true;
}
LocalBlockQueue queue = hybridPlotWorld.getQueue(false);
createSchemAbs(queue, pos1, pos2);
createSchemAbs(queue, pos1, pos2, true);
queue.enqueue();
return true;
}
@ -186,9 +188,9 @@ public class HybridPlotManager extends ClassicPlotManager {
pos1.setY(0);
pos2.setY(Math.min(getWorldHeight(), 255));
LocalBlockQueue queue = hybridPlotWorld.getQueue(false);
createSchemAbs(queue, pos1, pos2);
createSchemAbs(queue, pos1, pos2, true);
if (hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
createSchemAbs(queue, pos1, pos2);
createSchemAbs(queue, pos1, pos2, true);
}
return queue.enqueue();
}
@ -267,7 +269,7 @@ public class HybridPlotManager extends ClassicPlotManager {
if (!hybridPlotWorld.PLOT_SCHEMATIC) {
return;
}
createSchemAbs(queue, bottom, top);
createSchemAbs(queue, bottom, top, false);
}
/**

View File

@ -83,6 +83,11 @@ public abstract class HybridUtils {
public static PlotArea area;
public static boolean UPDATE = false;
public static boolean regeneratePlotWalls(final PlotArea area) {
PlotManager plotManager = area.getPlotManager();
return plotManager.regenerateAllPlotWalls();
}
public void analyzeRegion(final String world, final CuboidRegion region,
final RunnableVal<PlotAnalysis> whenDone) {
// int diff, int variety, int vertices, int rotation, int height_sd
@ -501,7 +506,7 @@ public abstract class HybridUtils {
PlotManager plotManager = plotworld.getPlotManager();
int sx = bot.getX() - plotworld.ROAD_WIDTH + 1;
int sz = bot.getZ() + 1;
int sy = plotworld.ROAD_HEIGHT;
int sy = Settings.Schematics.PASTE_ROAD_ON_TOP ? plotworld.ROAD_HEIGHT : 1;
int ex = bot.getX();
int ez = top.getZ();
int ey = get_ey(plotManager, queue, sx, ex, sz, ez, sy);
@ -621,10 +626,7 @@ public abstract class HybridUtils {
}
if (condition) {
BaseBlock[] blocks = plotWorld.G_SCH.get(MathMan.pair(absX, absZ));
int minY = plotWorld.SCHEM_Y;
if (!Settings.Schematics.PASTE_ON_TOP) {
minY = 1;
}
int minY = Settings.Schematics.PASTE_ROAD_ON_TOP ? plotWorld.SCHEM_Y : 1;
int maxY = Math.max(extend, blocks.length);
for (int y = 0; y < maxY; y++) {
if (y > blocks.length - 1) {
@ -659,9 +661,4 @@ public abstract class HybridUtils {
}
return false;
}
public static boolean regeneratePlotWalls(final PlotArea area) {
PlotManager plotManager = area.getPlotManager();
return plotManager.regenerateAllPlotWalls();
}
}

View File

@ -34,6 +34,7 @@ import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;
import org.khelekore.prtree.MBR;
import org.khelekore.prtree.SimpleMBR;
@ -103,6 +104,16 @@ public class Location implements Cloneable, Comparable<Location> {
}
}
/**
* Return a copy of the location. This will pass {@link #equals(Object)}
* but will have a different identity.
*
* @return Copy of the location
*/
@NotNull public Location copy() {
return new Location(this.world, this.x, this.y, this.z, this.yaw, this.pitch);
}
public PlotArea getPlotArea() {
return PlotSquared.get().getPlotAreaAbs(this);
}
@ -179,6 +190,7 @@ public class Location implements Cloneable, Comparable<Location> {
this.x += x;
this.y += y;
this.z += z;
this.blockVector3 = BlockVector3.at(this.x, this.y, this.z);
return this;
}
@ -220,6 +232,7 @@ public class Location implements Cloneable, Comparable<Location> {
this.x -= x;
this.y -= y;
this.z -= z;
this.blockVector3 = BlockVector3.at(this.x, this.y, this.z);
return this;
}

View File

@ -387,7 +387,7 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer,
@NotNull public Location getLocation() {
Location location = getMeta("location");
if (location != null) {
return location;
return location.copy(); // Always return a copy of the location
}
return getLocationFull();
}

View File

@ -3010,11 +3010,9 @@ public class Plot {
final String name = player.getName();
TaskManager.TELEPORT_QUEUE.add(name);
TaskManager.runTaskLater(() -> {
if (!TaskManager.TELEPORT_QUEUE.contains(name)) {
MainUtil.sendMessage(player, Captions.TELEPORT_FAILED);
if (!TaskManager.TELEPORT_QUEUE.remove(name)) {
return;
}
TaskManager.TELEPORT_QUEUE.remove(name);
if (player.isOnline()) {
MainUtil.sendMessage(player, Captions.TELEPORTED_TO_PLOT);
player.teleport(location, cause);

View File

@ -372,10 +372,21 @@ public class MainUtil {
/**
* Get the name from a UUID.
*
* @param owner
* @param owner Owner UUID
* @return The player's name, None, Everyone or Unknown
*/
@NotNull public static String getName(UUID owner) {
@NotNull 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
*/
@NotNull public static String getName(@Nullable final UUID owner, final boolean blocking) {
if (owner == null) {
return Captions.NONE.getTranslated();
}
@ -385,7 +396,17 @@ public class MainUtil {
if (owner.equals(DBFunc.SERVER)) {
return Captions.SERVER.getTranslated();
}
String name = PlotSquared.get().getImpromptuUUIDPipeline().getSingle(owner, Settings.UUID.BLOCKING_TIMEOUT);
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();
}