Modified internal configuration classes, Updated Mojang UUID fetcher, other various method and documentation tweaks

This commit is contained in:
MattBDev 2019-09-01 16:54:43 -04:00
parent a0d666ae14
commit 5e8909883d
14 changed files with 110 additions and 148 deletions

View File

@ -31,13 +31,13 @@ import java.util.ArrayDeque;
import java.util.Collections;
import java.util.HashMap;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
public class SQLUUIDHandler extends UUIDHandlerImplementation {
final int MAX_REQUESTS = 500;
private final String PROFILE_URL =
"https://sessionserver.mojang.com/session/minecraft/profile/";
private final int INTERVAL = 12000;
private final JSONParser jsonParser = new JSONParser();
private final SQLite sqlite;
@ -133,7 +133,10 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
"Invalid response from Mojang: Some UUIDs will be cached later. (`unknown` until then or player joins)");
}
try {
Thread.sleep(INTERVAL * 50);
//Mojang allows requests every 10 minutes according to https://wiki.vg/Mojang_API
//15 Minutes is chosen here since system timers are not always precise
//and it should provide enough time where Mojang won't block requests.
TimeUnit.MINUTES.sleep(15);
} catch (InterruptedException e) {
e.printStackTrace();
break;
@ -142,7 +145,6 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
if (whenDone != null) {
whenDone.run();
}
return;
});
});
} catch (SQLException e) {

View File

@ -6,7 +6,6 @@ package com.github.intellectualsites.plotsquared.configuration;
*/
class ConfigurationOptions {
private final Configuration configuration;
private char pathSeparator = '.';
private boolean copyDefaults = false;
protected ConfigurationOptions(Configuration configuration) {
@ -26,28 +25,12 @@ class ConfigurationOptions {
* Gets the char that will be used to separate {@link
* ConfigurationSection}s.
*
* <p>This value does not affect how the {@link Configuration} is stored,
* only in how you access the data. The default value is '.'.
* <p> This value is always '.'.
*
* @return Path separator
*/
public char pathSeparator() {
return pathSeparator;
}
/**
* Sets the char that will be used to separate {@link
* ConfigurationSection}s.
*
* <p>This value does not affect how the {@link Configuration} is stored,
* only in how you access the data. The default value is '.'.
*
* @param value Path separator
* @return This object, for chaining
*/
public ConfigurationOptions pathSeparator(char value) {
pathSeparator = value;
return this;
char pathSeparator() {
return '.';
}
/**

View File

@ -18,8 +18,4 @@ public class MemoryConfigurationOptions extends ConfigurationOptions {
return this;
}
@Override public MemoryConfigurationOptions pathSeparator(char value) {
super.pathSeparator(value);
return this;
}
}

View File

@ -25,11 +25,6 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions {
return this;
}
@Override public FileConfigurationOptions pathSeparator(char value) {
super.pathSeparator(value);
return this;
}
/**
* Gets the header that will be applied to the top of the saved output.
*

View File

@ -5,7 +5,6 @@ package com.github.intellectualsites.plotsquared.configuration.file;
* YamlConfiguration}.
*/
public class YamlConfigurationOptions extends FileConfigurationOptions {
private int indent = 2;
YamlConfigurationOptions(YamlConfiguration configuration) {
super(configuration);
@ -20,11 +19,6 @@ public class YamlConfigurationOptions extends FileConfigurationOptions {
return this;
}
@Override public YamlConfigurationOptions pathSeparator(char value) {
super.pathSeparator(value);
return this;
}
@Override public YamlConfigurationOptions header(String value) {
super.header(value);
return this;
@ -42,27 +36,8 @@ public class YamlConfigurationOptions extends FileConfigurationOptions {
*
* @return How much to indent by
*/
public int indent() {
return indent;
int indent() {
return 2;
}
/**
* Sets how much spaces should be used to indent each line.
*
* <p>The minimum value this may be is 2, and the maximum is 9.
*
* @param value New indent
* @return This object, for chaining
*/
public YamlConfigurationOptions indent(int value) {
if (value < 2) {
throw new IllegalArgumentException("Indent must be at least 2 characters");
}
if (value > 9) {
throw new IllegalArgumentException("Indent cannot be greater than 9 characters");
}
indent = value;
return this;
}
}

View File

@ -24,10 +24,9 @@ import com.github.intellectualsites.plotsquared.plot.util.StringMan;
import java.util.*;
@CommandDeclaration(command = "setflag", aliases = {"f", "flag", "setf", "setflag"},
usage = "/plot flag <set|remove|add|list|info> <flag> <value>", description = "Set plot flags",
category = CommandCategory.SETTINGS, requiredType = RequiredType.NONE,
permission = "plots.flag") public class FlagCmd extends SubCommand {
@CommandDeclaration(command = "setflag", aliases = {"f", "flag",
"setflag"}, usage = "/plot flag <set|remove|add|list|info> <flag> <value>", description = "Set plot flags", category = CommandCategory.SETTINGS, requiredType = RequiredType.NONE, permission = "plots.flag")
public class FlagCmd extends SubCommand {
private boolean checkPermValue(PlotPlayer player, Flag flag, String key, String value) {
key = key.toLowerCase();

View File

@ -149,8 +149,14 @@ import java.util.List;
}
PlotComment comment = value.get(index - 1);
inbox.removeComment(plot, comment);
plot.removeComment(comment);
MainUtil.sendMessage(player, Captions.COMMENT_REMOVED, comment.comment);
boolean success = plot.removeComment(comment);
//noinspection StatementWithEmptyBody
if (success) {
MainUtil
.sendMessage(player, Captions.COMMENT_REMOVED, comment.comment);
} else {
//TODO Comment removal failure message
}
}
})) {
sendMessage(player, Captions.NOT_IN_PLOT);

View File

@ -1,12 +1,19 @@
package com.github.intellectualsites.plotsquared.plot.database;
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
import com.github.intellectualsites.plotsquared.plot.object.*;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
import com.github.intellectualsites.plotsquared.plot.object.PlotCluster;
import com.github.intellectualsites.plotsquared.plot.object.PlotId;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal;
import com.github.intellectualsites.plotsquared.plot.object.comment.PlotComment;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull;
import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
public interface AbstractDB {
@ -298,7 +305,7 @@ public interface AbstractDB {
void setComment(Plot plot, PlotComment comment);
/**
* Gets Plot Comments.
* Gets Plot comments.
*
* @param plot The Plot to get comments from
*/

View File

@ -1,13 +1,21 @@
package com.github.intellectualsites.plotsquared.plot.database;
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
import com.github.intellectualsites.plotsquared.plot.object.*;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
import com.github.intellectualsites.plotsquared.plot.object.PlotCluster;
import com.github.intellectualsites.plotsquared.plot.object.PlotId;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal;
import com.github.intellectualsites.plotsquared.plot.object.comment.PlotComment;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
/**
* Database Functions
@ -74,6 +82,8 @@ public class DBFunc {
DBFunc.dbManager.validateAllPlots(plots);
}
//TODO Consider Removal
/**
* Check if a {@link ResultSet} contains a column.
*
@ -81,7 +91,7 @@ public class DBFunc {
* @param name
* @return
*/
public static boolean hasColumn(ResultSet resultSet, String name) {
@Deprecated public static boolean hasColumn(ResultSet resultSet, String name) {
try {
ResultSetMetaData meta = resultSet.getMetaData();
int count = meta.getColumnCount();

View File

@ -24,29 +24,21 @@ public class ClassicPlotManager extends SquarePlotManager {
BlockBucket blocks) {
switch (component) {
case "floor":
setFloor(plotId, blocks);
return true;
return setFloor(plotId, blocks);
case "wall":
setWallFilling(plotId, blocks);
return true;
return setWallFilling(plotId, blocks);
case "all":
setAll(plotId, blocks);
return true;
return setAll(plotId, blocks);
case "air":
setAir(plotId, blocks);
return true;
return setAir(plotId, blocks);
case "main":
setMain(plotId, blocks);
return true;
return setMain(plotId, blocks);
case "middle":
setMiddle(plotId, blocks);
return true;
return setMiddle(plotId, blocks);
case "outline":
setOutline(plotId, blocks);
return true;
return setOutline(plotId, blocks);
case "border":
setWall(plotId, blocks);
return true;
return setWall(plotId, blocks);
}
return false;
}
@ -54,8 +46,7 @@ public class ClassicPlotManager extends SquarePlotManager {
@Override public boolean unClaimPlot(Plot plot, Runnable whenDone) {
setWallFilling(plot.getId(), classicPlotWorld.WALL_FILLING);
setWall(plot.getId(), classicPlotWorld.WALL_BLOCK);
GlobalBlockQueue.IMP.addTask(whenDone);
return true;
return GlobalBlockQueue.IMP.addTask(whenDone);
}
public boolean setFloor(PlotId plotId, BlockBucket blocks) {
@ -70,8 +61,7 @@ public class ClassicPlotManager extends SquarePlotManager {
queue.setCuboid(pos1, pos2, blocks);
}
}
queue.enqueue();
return true;
return queue.enqueue();
}
public boolean setAll(PlotId plotId, BlockBucket blocks) {
@ -86,8 +76,7 @@ public class ClassicPlotManager extends SquarePlotManager {
Location pos2 = new Location(classicPlotWorld.worldname, region.maxX, maxY, region.maxZ);
queue.setCuboid(pos1, pos2, blocks);
}
queue.enqueue();
return true;
return queue.enqueue();
}
public boolean setAir(PlotId plotId, BlockBucket blocks) {
@ -103,8 +92,7 @@ public class ClassicPlotManager extends SquarePlotManager {
Location pos2 = new Location(classicPlotWorld.worldname, region.maxX, maxY, region.maxZ);
queue.setCuboid(pos1, pos2, blocks);
}
queue.enqueue();
return true;
return queue.enqueue();
}
public boolean setMain(PlotId plotId, BlockBucket blocks) {
@ -119,8 +107,7 @@ public class ClassicPlotManager extends SquarePlotManager {
new Location(classicPlotWorld.worldname, region.maxX, classicPlotWorld.PLOT_HEIGHT - 1, region.maxZ);
queue.setCuboid(pos1, pos2, blocks);
}
queue.enqueue();
return true;
return queue.enqueue();
}
public boolean setMiddle(PlotId plotId, BlockBucket blocks) {
@ -134,8 +121,7 @@ public class ClassicPlotManager extends SquarePlotManager {
int x = MathMan.average(corners[0].getX(), corners[1].getX());
int z = MathMan.average(corners[0].getZ(), corners[1].getZ());
queue.setBlock(x, classicPlotWorld.PLOT_HEIGHT, z, blocks.getBlock());
queue.enqueue();
return true;
return queue.enqueue();
}
public boolean setOutline(PlotId plotId, BlockBucket blocks) {
@ -187,8 +173,7 @@ public class ClassicPlotManager extends SquarePlotManager {
queue.setCuboid(pos1, pos2, blocks);
}
}
queue.enqueue();
return true;
return queue.enqueue();
}
public boolean setWallFilling(PlotId plotId, BlockBucket blocks) {
@ -235,8 +220,7 @@ public class ClassicPlotManager extends SquarePlotManager {
}
}
}
queue.enqueue();
return true;
return queue.enqueue();
}
public boolean setWall(PlotId plotId, BlockBucket blocks) {
@ -276,8 +260,7 @@ public class ClassicPlotManager extends SquarePlotManager {
queue.setBlock(x, y, z, blocks.getBlock());
}
}
queue.enqueue();
return true;
return queue.enqueue();
}
/**
@ -308,8 +291,7 @@ public class ClassicPlotManager extends SquarePlotManager {
new Location(classicPlotWorld.worldname, ex, classicPlotWorld.WALL_HEIGHT + 1, ez - 1), classicPlotWorld.WALL_BLOCK);
queue.setCuboid(new Location(classicPlotWorld.worldname, sx + 1, 1, sz + 1),
new Location(classicPlotWorld.worldname, ex - 1, classicPlotWorld.ROAD_HEIGHT, ez - 1), classicPlotWorld.ROAD_BLOCK);
queue.enqueue();
return true;
return queue.enqueue();
}
@Override public boolean createRoadSouth(Plot plot) {
@ -337,8 +319,7 @@ public class ClassicPlotManager extends SquarePlotManager {
new Location(classicPlotWorld.worldname, ex - 1, classicPlotWorld.WALL_HEIGHT + 1, ez), classicPlotWorld.WALL_BLOCK);
queue.setCuboid(new Location(classicPlotWorld.worldname, sx + 1, 1, sz + 1),
new Location(classicPlotWorld.worldname, ex - 1, classicPlotWorld.ROAD_HEIGHT, ez - 1), classicPlotWorld.ROAD_BLOCK);
queue.enqueue();
return true;
return queue.enqueue();
}
@Override public boolean createRoadSouthEast(Plot plot) {
@ -356,8 +337,7 @@ public class ClassicPlotManager extends SquarePlotManager {
PlotBlock.get((short) 7, (byte) 0));
queue.setCuboid(new Location(classicPlotWorld.worldname, sx + 1, 1, sz + 1),
new Location(classicPlotWorld.worldname, ex - 1, classicPlotWorld.ROAD_HEIGHT, ez - 1), classicPlotWorld.ROAD_BLOCK);
queue.enqueue();
return true;
return queue.enqueue();
}
@Override public boolean removeRoadEast(Plot plot) {
@ -377,8 +357,7 @@ public class ClassicPlotManager extends SquarePlotManager {
new Location(classicPlotWorld.worldname, ex, classicPlotWorld.PLOT_HEIGHT - 1, ez - 1), classicPlotWorld.MAIN_BLOCK);
queue.setCuboid(new Location(classicPlotWorld.worldname, sx, classicPlotWorld.PLOT_HEIGHT, sz + 1),
new Location(classicPlotWorld.worldname, ex, classicPlotWorld.PLOT_HEIGHT, ez - 1), classicPlotWorld.TOP_BLOCK);
queue.enqueue();
return true;
return queue.enqueue();
}
@Override public boolean removeRoadSouth(Plot plot) {
@ -398,8 +377,7 @@ public class ClassicPlotManager extends SquarePlotManager {
new Location(classicPlotWorld.worldname, ex - 1, classicPlotWorld.PLOT_HEIGHT - 1, ez), classicPlotWorld.MAIN_BLOCK);
queue.setCuboid(new Location(classicPlotWorld.worldname, sx + 1, classicPlotWorld.PLOT_HEIGHT, sz),
new Location(classicPlotWorld.worldname, ex - 1, classicPlotWorld.PLOT_HEIGHT, ez), classicPlotWorld.TOP_BLOCK);
queue.enqueue();
return true;
return queue.enqueue();
}
@Override public boolean removeRoadSouthEast(Plot plot) {
@ -416,14 +394,14 @@ public class ClassicPlotManager extends SquarePlotManager {
new Location(classicPlotWorld.worldname, ex, classicPlotWorld.ROAD_HEIGHT - 1, ez), classicPlotWorld.MAIN_BLOCK);
queue.setCuboid(new Location(classicPlotWorld.worldname, sx, classicPlotWorld.ROAD_HEIGHT, sz),
new Location(classicPlotWorld.worldname, ex, classicPlotWorld.ROAD_HEIGHT, ez), classicPlotWorld.TOP_BLOCK);
queue.enqueue();
return true;
return queue.enqueue();
}
/**
* Finishing off plot merging by adding in the walls surrounding the plot (OPTIONAL)(UNFINISHED).
*/
@Override public boolean finishPlotMerge(List<PlotId> plotIds) {
//TODO This method shouldn't always return true
final BlockBucket block = classicPlotWorld.CLAIMED_WALL_BLOCK;
plotIds.forEach(id -> setWall(id, block));
if (Settings.General.MERGE_REPLACE_WALL) {
@ -434,12 +412,14 @@ public class ClassicPlotManager extends SquarePlotManager {
}
@Override public boolean finishPlotUnlink(List<PlotId> plotIds) {
//TODO This method shouldn't always return true
final BlockBucket block = classicPlotWorld.CLAIMED_WALL_BLOCK;
plotIds.forEach(id -> setWall(id, block));
return true;
}
@Override public boolean regenerateAllPlotWalls() {
//TODO This method shouldn't always return true
for (Plot plot : classicPlotWorld.getPlots()) {
if (plot.hasOwner()) {
setWall(plot.getId(), classicPlotWorld.CLAIMED_WALL_BLOCK);
@ -460,8 +440,7 @@ public class ClassicPlotManager extends SquarePlotManager {
@Override public boolean claimPlot(Plot plot) {
final BlockBucket claim = classicPlotWorld.CLAIMED_WALL_BLOCK;
setWall(plot.getId(), claim);
return true;
return setWall(plot.getId(), claim);
}
@Override public String[] getPlotComponents(PlotId plotId) {

View File

@ -2418,20 +2418,16 @@ public class Plot {
* @param direction
* @return
*/
public Plot getRelative(int direction) {
@Deprecated public Plot getRelative(int direction) {
return this.area.getPlotAbs(this.id.getRelative(direction));
}
/**
* Gets the plot in a relative direction<br>
* 0 = north<br>
* 1 = east<br>
* 2 = south<br>
* 3 = west<br>
* Gets the plot in a relative direction
* Note: May be null if the partial plot area does not include the relative location
*
* @param direction
* @return
* @return the plot relative to this one
*/
public Plot getRelative(Direction direction) {
return this.area.getPlotAbs(this.id.getRelative(direction));
@ -2441,7 +2437,7 @@ public class Plot {
* Gets a set of plots connected (and including) this plot<br>
* - This result is cached globally
*
* @return
* @return a Set of Plots connected to this Plot
*/
public Set<Plot> getConnectedPlots() {
if (this.settings == null) {
@ -2802,6 +2798,11 @@ public class Plot {
return false;
}
/**
* Checks if the owner of this Plot is online.
*
* @return true if the owner of the Plot is online
*/
public boolean isOnline() {
if (this.owner == null) {
return false;
@ -3098,23 +3099,23 @@ public class Plot {
return getFlags().containsKey(flag);
}
@SuppressWarnings("deprecation") public boolean removeComment(PlotComment comment) {
public boolean removeComment(PlotComment comment) {
return getSettings().removeComment(comment);
}
@SuppressWarnings("deprecation") public void removeComments(List<PlotComment> comments) {
public void removeComments(List<PlotComment> comments) {
getSettings().removeComments(comments);
}
@SuppressWarnings("deprecation") public List<PlotComment> getComments(String inbox) {
public List<PlotComment> getComments(String inbox) {
return getSettings().getComments(inbox);
}
@SuppressWarnings("deprecation") public void addComment(PlotComment comment) {
public void addComment(PlotComment comment) {
getSettings().addComment(comment);
}
@SuppressWarnings("deprecation") public void setComments(List<PlotComment> list) {
public void setComments(List<PlotComment> list) {
getSettings().setComments(list);
}

View File

@ -102,9 +102,10 @@ public class DelegateLocalBlockQueue extends LocalBlockQueue {
}
}
@Override public void enqueue() {
@Override public boolean enqueue() {
if (parent != null) {
parent.enqueue();
return parent.enqueue();
}
return false;
}
}

View File

@ -45,10 +45,10 @@ public class GlobalBlockQueue {
public GlobalBlockQueue(QueueProvider provider, int threads) {
this.provider = provider;
activeQueues = new ConcurrentLinkedDeque<>();
inactiveQueues = new ConcurrentLinkedDeque<>();
runnables = new ConcurrentLinkedDeque<>();
running = new AtomicBoolean();
this.activeQueues = new ConcurrentLinkedDeque<>();
this.inactiveQueues = new ConcurrentLinkedDeque<>();
this.runnables = new ConcurrentLinkedDeque<>();
this.running = new AtomicBoolean();
this.PARALLEL_THREADS = threads;
}
@ -151,12 +151,20 @@ public class GlobalBlockQueue {
return false;
}
public void enqueue(LocalBlockQueue queue) {
inactiveQueues.remove(queue);
/**
* TODO Documentation needed.
*
* @param queue todo
* @return true if added to queue, false otherwise
*/
public boolean enqueue(LocalBlockQueue queue) {
boolean success = false;
success = inactiveQueues.remove(queue);
if (queue.size() > 0 && !activeQueues.contains(queue)) {
queue.optimize();
activeQueues.add(queue);
success = activeQueues.add(queue);
}
return success;
}
public void dequeue(LocalBlockQueue queue) {

View File

@ -96,8 +96,8 @@ public abstract class LocalBlockQueue {
}
}
public void enqueue() {
GlobalBlockQueue.IMP.enqueue(this);
public boolean enqueue() {
return GlobalBlockQueue.IMP.enqueue(this);
}
public void setCuboid(Location pos1, Location pos2, PlotBlock block) {