Optimizations and a purge fix

This commit is contained in:
MattBDev
2016-04-02 01:30:26 -04:00
parent 8243e0118a
commit 4ebd778c62
33 changed files with 765 additions and 835 deletions

View File

@ -537,16 +537,16 @@ public class MemorySection implements ConfigurationSection {
@Override
public List<String> getStringList(String path) {
final List<?> list = getList(path);
List<?> list = getList(path);
if (list == null) {
return new ArrayList<>(0);
}
final List<String> result = new ArrayList<>();
List<String> result = new ArrayList<>();
for (final Object object : list) {
if ((object instanceof String) || (isPrimitiveWrapper(object))) {
for (Object object : list) {
if ((object instanceof String) || isPrimitiveWrapper(object)) {
result.add(String.valueOf(object));
}
}

View File

@ -67,8 +67,14 @@ public class Inbox extends SubCommand {
@Override
public boolean onCommand(final PlotPlayer player, String[] args) {
final Plot plot = player.getCurrentPlot();
if (plot == null) {
sendMessage(player, C.NOT_IN_PLOT);
return false;
} else if (!plot.hasOwner()) {
sendMessage(player, C.PLOT_UNOWNED);
return false;
}
if (args.length == 0) {
sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox [inbox] [delete <index>|clear|page]");
for (final CommentInbox inbox : CommentManager.inboxes.values()) {
@ -183,11 +189,7 @@ public class Inbox extends SubCommand {
displayComments(player, value, page);
}
})) {
if (plot == null) {
sendMessage(player, C.NOT_IN_PLOT);
} else {
sendMessage(player, C.PLOT_UNOWNED);
}
sendMessage(player, C.PLOT_UNOWNED);
return false;
}
return true;

View File

@ -11,6 +11,7 @@ import com.intellectualcrafters.plot.util.CmdConfirm;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
import com.plotsquared.listener.PlotListener;
import java.util.HashMap;
import java.util.HashSet;
@ -150,9 +151,10 @@ public class Purge extends SubCommand {
if (plot.temp != Integer.MAX_VALUE) {
ids.add(plot.temp);
plot.getArea().removePlot(plot.getId());
for (PlotPlayer plotPlayer : plot.getPlayersInPlot()) {
plotPlayer.deleteMeta("lastplot");
for (PlotPlayer pp : plot.getPlayersInPlot()) {
PlotListener.plotEntry(pp, plot);
}
plot.removeSign();
}
}
DBFunc.purgeIds(ids);

View File

@ -290,7 +290,7 @@ public class DBFunc {
* @param comment
*/
public static void removeComment(Plot plot, PlotComment comment) {
if (plot != null && plot.temp == -1) {
if (plot.temp == -1) {
return;
}
DBFunc.dbManager.removeComment(plot, comment);

View File

@ -3147,7 +3147,7 @@ public class SQLManager implements AbstractDB {
public abstract class UniqueStatement {
public String method;
public final String method;
public UniqueStatement(String method) {
this.method = method;

View File

@ -214,7 +214,7 @@ public class HybridPlotWorld extends ClassicPlotWorld {
}
}
HashMap<BlockLoc, CompoundTag> items = schematic3.getTiles();
if (items.size() > 0) {
if (!items.isEmpty()) {
this.G_SCH_STATE = new HashMap<>();
for (Map.Entry<BlockLoc, CompoundTag> entry : items.entrySet()) {
BlockLoc loc = entry.getKey();

View File

@ -20,6 +20,7 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.util.WorldUtil;
import com.plotsquared.listener.PlotListener;
import java.awt.Rectangle;
import java.awt.geom.Area;
import java.awt.geom.PathIterator;
@ -765,8 +766,8 @@ public class Plot {
@Override
public void run() {
if (queue.isEmpty()) {
final AtomicInteger finished = new AtomicInteger(0);
final Runnable run = new Runnable() {
AtomicInteger finished = new AtomicInteger(0);
Runnable run = new Runnable() {
@Override
public void run() {
for (RegionWrapper region : regions) {
@ -794,11 +795,11 @@ public class Plot {
manager.clearPlot(Plot.this.area, current, this);
}
};
if (!isMerged() && area.getRegion().equals(getLargestRegion())) {
ChunkManager.largeRegionTask(area.worldname, area.getRegion(), new RunnableVal<ChunkLoc>() {
if (!isMerged() && this.area.getRegion().equals(getLargestRegion())) {
ChunkManager.largeRegionTask(this.area.worldname, this.area.getRegion(), new RunnableVal<ChunkLoc>() {
@Override
public void run(ChunkLoc value) {
ChunkManager.manager.regenerateChunk(area.worldname, value);
ChunkManager.manager.regenerateChunk(Plot.this.area.worldname, value);
}
}, whenDone);
} else {
@ -1773,7 +1774,7 @@ public class Plot {
* Upload this plot as a world file<br>
* - The mca files are each 512x512, so depending on the plot size it may also download adjacent plots<br>
* - Works best when (plot width + road width) % 512 == 0<br>
* @see com.intellectualcrafters.plot.util.WorldUtil
* @see WorldUtil
* @param whenDone
*/
public void uploadWorld(RunnableVal<URL> whenDone) {
@ -1784,7 +1785,7 @@ public class Plot {
* Upload this plot as a BO3<br>
* - May not work on non default generator<br>
* - BO3 includes flags/ignores plot main/floor block<br>
* @see com.intellectualcrafters.plot.util.BO3Handler
* @see BO3Handler
* @param whenDone
*/
public void uploadBO3(RunnableVal<URL> whenDone) {
@ -1991,8 +1992,6 @@ public class Plot {
int index = caption.indexOf("%plr%");
if (index == -1) {
continue;
} else if (index < -1) {
PS.debug("This should NEVER happen. Seriously, it's impossible.");
}
String line = lines[i - 1];
if (line.length() <= index) {
@ -2487,7 +2486,7 @@ public class Plot {
RegionWrapper max = null;
double area = Double.NEGATIVE_INFINITY;
for (RegionWrapper region : regions) {
double current = ((region.maxX - (double) region.minX + 1)) * (region.maxZ - (double) region.minZ + 1);
double current = (region.maxX - (double) region.minX + 1) * (region.maxZ - (double) region.minZ + 1);
if (current > area) {
max = region;
area = current;

View File

@ -19,7 +19,7 @@ import java.util.concurrent.atomic.AtomicInteger;
public class PlotAnalysis {
public static PlotAnalysis MODIFIERS = new PlotAnalysis();
public static final PlotAnalysis MODIFIERS = new PlotAnalysis();
public static boolean running = false;
public int changes;
public int faces;

View File

@ -3,28 +3,28 @@ package com.intellectualcrafters.plot.object;
public class PlotLoc {
public int x;
public int z;
public PlotLoc(final int x, final int z) {
public PlotLoc(int x, int z) {
this.x = x;
this.z = z;
}
@Override
public int hashCode() {
final int prime = 31;
int prime = 31;
int result = 1;
result = (prime * result) + x;
result = (prime * result) + z;
result = (prime * result) + this.x;
result = (prime * result) + this.z;
return result;
}
@Override
public String toString() {
return x + "," + z;
return this.x + "," + this.z;
}
@Override
public boolean equals(final Object obj) {
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
@ -34,7 +34,7 @@ public class PlotLoc {
if (getClass() != obj.getClass()) {
return false;
}
final PlotLoc other = (PlotLoc) obj;
return ((x == other.x) && (z == other.z));
PlotLoc other = (PlotLoc) obj;
return (this.x == other.x) && (this.z == other.z);
}
}

View File

@ -10,50 +10,50 @@ public class PlotMessage {
public PlotMessage() {
reset(ChatManager.manager);
}
public <T> T $(final ChatManager<T> manager) {
return (T) builder;
}
public PlotMessage(final String text) {
public PlotMessage(String text) {
this();
text(text);
}
public <T> T reset(ChatManager<T> manager) {
return (T) (builder = manager.builder());
public <T> T $(ChatManager<T> manager) {
return (T) this.builder;
}
public PlotMessage text(final String text) {
public <T> T reset(ChatManager<T> manager) {
return (T) (this.builder = manager.builder());
}
public PlotMessage text(String text) {
ChatManager.manager.text(this, text);
return this;
}
public PlotMessage tooltip(final PlotMessage... tooltip) {
public PlotMessage tooltip(PlotMessage... tooltip) {
ChatManager.manager.tooltip(this, tooltip);
return this;
}
public PlotMessage tooltip(final String tooltip) {
public PlotMessage tooltip(String tooltip) {
return tooltip(new PlotMessage(tooltip));
}
public PlotMessage command(final String command) {
public PlotMessage command(String command) {
ChatManager.manager.command(this, command);
return this;
}
public PlotMessage suggest(final String command) {
public PlotMessage suggest(String command) {
ChatManager.manager.suggest(this, command);
return this;
}
public PlotMessage color(final String color) {
public PlotMessage color(String color) {
ChatManager.manager.color(this, C.color(color));
return this;
}
public void send(final PlotPlayer player) {
public void send(PlotPlayer player) {
ChatManager.manager.send(this, player);
}
}

View File

@ -1,5 +1,6 @@
package com.intellectualcrafters.plot.object.comment;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
@ -18,7 +19,7 @@ public abstract class CommentInbox {
public abstract boolean canModify(Plot plot, PlotPlayer player);
/**
* The plot may be null if the user is not standing in a plot. Return false if this is not a plot-less inbox.
*
* <br>
* The `whenDone` parameter should be executed when it's done fetching the comments.
* The value should be set to List of comments
@ -31,7 +32,11 @@ public abstract class CommentInbox {
public abstract boolean addComment(Plot plot, PlotComment comment);
public abstract boolean removeComment(Plot plot, PlotComment comment);
public void removeComment(Plot plot, PlotComment comment) {
DBFunc.removeComment(plot, comment);
}
public abstract boolean clearInbox(Plot plot);
public void clearInbox(Plot plot) {
DBFunc.clearInbox(plot, toString());
}
}

View File

@ -12,45 +12,38 @@ import java.util.ArrayList;
import java.util.List;
public class InboxOwner extends CommentInbox {
@Override
public boolean canRead(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.read." + toString());
if (Permissions.hasPermission(player, "plots.inbox.read." + toString())) {
if (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.read." + toString() + ".other")) {
return true;
}
}
return Permissions.hasPermission(player, "plots.inbox.read." + toString()) && (plot.isOwner(player.getUUID()) || Permissions
.hasPermission(player, "plots.inbox.read."
+ toString()
+ ".other"));
return false;
}
@Override
public boolean canWrite(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.write." + toString());
}
return Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (plot.isOwner(player.getUUID()) || Permissions
.hasPermission(player, "plots.inbox.write."
+ toString()
+ ".other"));
.hasPermission(player, "plots.inbox.write." + toString() + ".other"));
}
@Override
public boolean canModify(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.modify." + toString());
if (Permissions.hasPermission(player, "plots.inbox.modify." + toString())) {
if (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify." + toString() + ".other")) {
return true;
}
}
return Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (plot.isOwner(player.getUUID()) || Permissions
.hasPermission(player, "plots.inbox.modify."
+ toString()
+ ".other"));
return false;
}
@Override
public boolean getComments(final Plot plot, final RunnableVal<List<PlotComment>> whenDone) {
if ((plot == null) || (plot.owner == null)) {
return false;
}
Optional<ArrayList<PlotComment>> comments = plot.getSettings().getComments(toString());
if (comments.isPresent()) {
whenDone.value = comments.get();
@ -73,7 +66,7 @@ public class InboxOwner extends CommentInbox {
});
return true;
}
@Override
public boolean addComment(Plot plot, PlotComment comment) {
if (plot.owner == null) {
@ -83,27 +76,10 @@ public class InboxOwner extends CommentInbox {
DBFunc.setComment(plot, comment);
return true;
}
@Override
public String toString() {
return "owner";
}
@Override
public boolean removeComment(Plot plot, PlotComment comment) {
if ((plot == null) || (plot.owner == null)) {
return false;
}
DBFunc.removeComment(plot, comment);
return false;
}
@Override
public boolean clearInbox(Plot plot) {
if (plot == null || plot.owner == null) {
return false;
}
DBFunc.clearInbox(plot, this.toString());
return false;
}
}

View File

@ -15,13 +15,12 @@ public class InboxPublic extends CommentInbox {
@Override
public boolean canRead(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.read." + toString());
if (Permissions.hasPermission(player, "plots.inbox.read." + toString())) {
if (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.read." + toString() + ".other")) {
return true;
}
}
return Permissions.hasPermission(player, "plots.inbox.read." + toString()) && (plot.isOwner(player.getUUID()) || Permissions
.hasPermission(player, "plots.inbox.read."
+ toString()
+ ".other"));
return false;
}
@Override
@ -35,18 +34,16 @@ public class InboxPublic extends CommentInbox {
@Override
public boolean canModify(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.modify." + toString());
if (Permissions.hasPermission(player, "plots.inbox.modify." + toString())) {
if (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify." + toString() + ".other")) {
return true;
}
}
return Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (plot.isOwner(player.getUUID()) || Permissions
.hasPermission(player, "plots.inbox.modify." + toString() + ".other"));
return false;
}
@Override
public boolean getComments(final Plot plot, final RunnableVal<List<PlotComment>> whenDone) {
if (plot.owner == null) {
return false;
}
Optional<ArrayList<PlotComment>> comments = plot.getSettings().getComments(toString());
if (comments.isPresent()) {
whenDone.value = comments.get();
@ -70,9 +67,6 @@ public class InboxPublic extends CommentInbox {
@Override
public boolean addComment(Plot plot, PlotComment comment) {
if (plot.owner == null) {
return false;
}
plot.getSettings().addComment(comment);
DBFunc.setComment(plot, comment);
return true;
@ -82,22 +76,6 @@ public class InboxPublic extends CommentInbox {
public String toString() {
return "public";
}
@Override
public boolean removeComment(Plot plot, PlotComment comment) {
if ((plot == null) || (plot.owner == null)) {
return false;
}
DBFunc.removeComment(plot, comment);
return false;
}
@Override
public boolean clearInbox(Plot plot) {
if (plot == null || plot.owner == null) {
return false;
}
DBFunc.clearInbox(plot, this.toString());
return false;
}
}

View File

@ -13,11 +13,13 @@ public class InboxReport extends CommentInbox {
@Override
public boolean canRead(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.read." + toString());
if (Permissions.hasPermission(player, "plots.inbox.read." + toString())) {
if (plot.isOwner(player.getUUID()) || Permissions
.hasPermission(player, "plots.inbox.read." + toString() + ".other")) {
return true;
}
}
return Permissions.hasPermission(player, "plots.inbox.read." + toString()) && (plot.isOwner(player.getUUID()) || Permissions
.hasPermission(player, "plots.inbox.read." + toString() + ".other"));
return false;
}
@Override
@ -31,11 +33,12 @@ public class InboxReport extends CommentInbox {
@Override
public boolean canModify(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.modify." + toString());
if (Permissions.hasPermission(player, "plots.inbox.modify." + toString())) {
if (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify." + toString() + ".other")) {
return true;
}
}
return Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (plot.isOwner(player.getUUID()) || Permissions
.hasPermission(player, "plots.inbox.modify." + toString() + ".other"));
return false;
}
@Override
@ -64,21 +67,4 @@ public class InboxReport extends CommentInbox {
return "report";
}
@Override
public boolean removeComment(Plot plot, PlotComment comment) {
if (plot.owner == null) {
return false;
}
DBFunc.removeComment(plot, comment);
return false;
}
@Override
public boolean clearInbox(Plot plot) {
if (plot == null || plot.owner == null) {
return false;
}
DBFunc.clearInbox(plot, this.toString());
return false;
}
}

View File

@ -1,12 +1,13 @@
package com.intellectualcrafters.plot.object.schematic;
public class PlotItem {
public int x;
public int y;
public int z;
public short[] id;
public byte[] data;
public byte[] amount;
public final int x;
public final int y;
public final int z;
public final short[] id;
public final byte[] data;
public final byte[] amount;
public PlotItem(short x, short y, short z, short[] id, byte[] data, byte[] amount) {
this.x = x;

View File

@ -111,7 +111,7 @@ public abstract class ChunkManager {
Runnable smallTask = new Runnable() {
@Override
public void run() {
if (regions.size() == 0) {
if (regions.isEmpty()) {
TaskManager.runTask(whenDone);
return;
}

View File

@ -18,7 +18,7 @@ import java.util.concurrent.atomic.AtomicInteger;
public class CommentManager {
public static HashMap<String, CommentInbox> inboxes = new HashMap<>();
public static final HashMap<String, CommentInbox> inboxes = new HashMap<>();
public static void sendTitle(final PlotPlayer player, final Plot plot) {
if (!Settings.COMMENT_NOTIFICATIONS || !plot.isOwner(player.getUUID())) {

View File

@ -24,8 +24,8 @@ import java.util.concurrent.ConcurrentHashMap;
public abstract class UUIDHandlerImplementation {
public final ConcurrentHashMap<String, PlotPlayer> players;
public final HashSet<UUID> unknown = new HashSet<>();
public UUIDWrapper uuidWrapper = null;
public HashSet<UUID> unknown = new HashSet<>();
private boolean cached = false;
private BiMap<StringWrapper, UUID> uuidMap = HashBiMap.create(new HashMap<StringWrapper, UUID>());

View File

@ -459,13 +459,13 @@ public abstract class Command {
}
public String getUsage() {
if (this.usage != null && this.usage.length() != 0) {
if (this.usage != null && !this.usage.isEmpty()) {
if (this.usage.startsWith("/")) {
return this.usage;
}
return getCommandString() + " " + this.usage;
}
if (this.allCommands.size() == 0) {
if (this.allCommands.isEmpty()) {
return getCommandString();
}
StringBuilder args = new StringBuilder("[");
@ -511,7 +511,7 @@ public abstract class Command {
@Override
public String toString() {
return this.aliases.size() > 0 ? this.aliases.get(0) : this.id;
return !this.aliases.isEmpty() ? this.aliases.get(0) : this.id;
}
@Override