Fix "Cleaner reflection" breaking plugin.

Also add method to sort plots by modification date.
This commit is contained in:
Jesse Boyd 2016-03-19 17:32:05 +11:00
parent d30626d11f
commit 8074d041b8
3 changed files with 67 additions and 158 deletions

View File

@ -54,7 +54,7 @@ public final class Reflection {
return _loadedNMSClasses.get(className);
}
final String fullName = "net.minecraft.server." + getVersion() + className;
final String fullName = "net.minecraft.server." + getVersion() + "." + className;
Class<?> clazz;
try {
clazz = Class.forName(fullName);
@ -80,7 +80,7 @@ public final class Reflection {
return _loadedOBCClasses.get(className);
}
final String fullName = "org.bukkit.craftbukkit." + getVersion() + className;
final String fullName = "org.bukkit.craftbukkit." + getVersion() + "." + className;
Class<?> clazz;
try {
clazz = Class.forName(fullName);

View File

@ -923,6 +923,55 @@ public class PS {
return result;
}
@Deprecated
public ArrayList<Plot> sortPlotsByTimestamp(final Collection<Plot> plots) {
List<Plot> unknown = new ArrayList<>();
int hardmax = 256000;
int max = 0;
int overflowSize = 0;
for (final Plot plot : plots) {
final int hash = MathMan.getPositiveId(plot.hashCode());
if (hash > max) {
if (hash >= hardmax) {
overflowSize++;
} else {
max = hash;
}
}
}
hardmax = Math.min(hardmax, max);
final Plot[] cache = new Plot[hardmax + 1];
final List<Plot> overflow = new ArrayList<>(overflowSize);
final ArrayList<Plot> extra = new ArrayList<>();
for (final Plot plot : plots) {
final int hash = MathMan.getPositiveId(plot.hashCode());
if (hash < hardmax) {
if (hash >= 0) {
cache[hash] = plot;
} else {
extra.add(plot);
}
} else if ((Math.abs(plot.getId().x) > 15446) || (Math.abs(plot.getId().y) > 15446)) {
extra.add(plot);
} else {
overflow.add(plot);
}
}
final Plot[] overflowArray = overflow.toArray(new Plot[overflow.size()]);
sortPlotsByHash(overflowArray);
final ArrayList<Plot> result = new ArrayList<>(cache.length + overflowArray.length);
for (final Plot plot : cache) {
if (plot != null) {
result.add(plot);
}
}
Collections.addAll(result, overflowArray);
for (final Plot plot : extra) {
result.add(plot);
}
return result;
}
/**
* Sort plots by creation timestamp
* @param input
@ -930,167 +979,20 @@ public class PS {
* @return
*/
@Deprecated
public ArrayList<Plot> sortPlotsByTimestamp(final Collection<Plot> input) {
public List<Plot> sortPlotsByModified(final Collection<Plot> input) {
List<Plot> list;
if (input instanceof ArrayList<?>) {
if (input instanceof List) {
list = (List<Plot>) input;
} else {
list = new ArrayList<>(input);
}
long min = Integer.MAX_VALUE;
long max = 0;
final int size = list.size();
final int limit = Math.min(1048576, size * 2);
for (final Plot plot : list) {
final long time = plot.getTimestamp();
if (time < min) {
min = time;
}
if (time > max) {
max = time;
}
}
final long range = max - min;
try {
final ArrayList<Plot> overflow = new ArrayList<>();
Plot[] plots;
if ((range > limit) && (size > 1024)) {
plots = new Plot[limit];
final int factor = (int) ((range / limit));
for (Plot plot : list) {
int index = (int) (plot.getTimestamp() - min) / factor;
if (index < 0) {
index = 0;
}
if (index >= plots.length) {
overflow.add(plot);
continue;
}
Plot current = plots[index];
while (true) {
if (current == null) {
plots[index] = plot;
break;
}
if (current.getTimestamp() > plot.getTimestamp()) {
plots[index] = plot;
plot = current;
}
index++;
if (index >= plots.length) {
overflow.add(plot);
break;
}
current = plots[index];
}
}
} else if ((range < size) || (size < 1024)) {
final ArrayList<Plot> result = new ArrayList<>(list);
Collections.sort(result, new Comparator<Plot>() {
Collections.sort(list, new Comparator<Plot>() {
@Override
public int compare(final Plot a, final Plot b) {
if (a.getTimestamp() > b.getTimestamp()) {
return -1;
} else if (b.getTimestamp() > a.getTimestamp()) {
return 1;
}
return 0;
public int compare(Plot a, Plot b) {
return (int) Math.signum(ExpireManager.IMP.getTimestamp(a.owner) - ExpireManager.IMP.getTimestamp(b.owner));
}
});
return result;
} else if (min != 0) {
plots = new Plot[(int) range];
for (Plot plot : list) {
int index = (int) (plot.getTimestamp() - min);
if (index >= plots.length) {
overflow.add(plot);
continue;
}
Plot current = plots[index];
while (true) {
if (current == null) {
plots[index] = plot;
break;
}
if (current.getTimestamp() > plot.getTimestamp()) {
plots[index] = plot;
plot = current;
}
index++;
if (index >= plots.length) {
overflow.add(plot);
break;
}
current = plots[index];
}
}
} else {
plots = new Plot[(int) range];
for (Plot plot : list) {
int index = (int) (plot.getTimestamp());
if (index >= plots.length) {
overflow.add(plot);
continue;
}
Plot current = plots[index];
// Move everything along until a free spot is found
while (true) {
if (current == null) {
plots[index] = plot;
break;
}
if (current.getTimestamp() > plot.getTimestamp()) {
plots[index] = plot;
plot = current;
}
index++;
if (index >= plots.length) {
overflow.add(plot);
break;
}
current = plots[index];
}
}
}
final ArrayList<Plot> result = new ArrayList<>(size);
if (!overflow.isEmpty()) {
Collections.sort(overflow, new Comparator<Plot>() {
@Override
public int compare(final Plot a, final Plot b) {
if (a.getTimestamp() > b.getTimestamp()) {
return -1;
} else if (b.getTimestamp() > a.getTimestamp()) {
return 1;
}
return 0;
}
});
for (final Plot plot : overflow) {
result.add(plot);
}
}
for (int i = plots.length - 1; i >= 0; i--) {
if (plots[i] != null) {
result.add(plots[i]);
}
}
return result;
} catch (final Exception e) {
e.printStackTrace();
final ArrayList<Plot> result = new ArrayList<>(list);
Collections.sort(result, new Comparator<Plot>() {
@Override
public int compare(final Plot a, final Plot b) {
if (a.getTimestamp() > b.getTimestamp()) {
return -1;
} else if (b.getTimestamp() > a.getTimestamp()) {
return 1;
}
return 0;
}
});
return result;
}
return list;
}
/**
@ -1179,6 +1081,8 @@ public class PS {
case DISTANCE_FROM_ORIGIN:
toReturn.addAll(sortPlotsByHash(map.get(area)));
break;
case LAST_MODIFIED:
toReturn.addAll(sortPlotsByModified(map.get(area)));
default:
break;
}
@ -2562,6 +2466,6 @@ public class PS {
}
public enum SortType {
CREATION_DATE, CREATION_DATE_TIMESTAMP, DISTANCE_FROM_ORIGIN
CREATION_DATE, CREATION_DATE_TIMESTAMP, LAST_MODIFIED, DISTANCE_FROM_ORIGIN
}
}

View File

@ -46,6 +46,11 @@ public class ExpireManager {
}
}
public long getTimestamp(UUID uuid) {
Long value = dates_cache.get(uuid);
return value == null ? 0 : value;
}
public void confirmExpiry(final PlotPlayer pp) {
if (Settings.AUTO_CLEAR_CONFIRMATION && plotsToDelete != null && !plotsToDelete.isEmpty() && pp.hasPermission("plots.admin.command.autoclear")) {
final int num = plotsToDelete.size();