mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-12-24 16:58:50 +01:00
Tweaks and small memory improvement.
This commit is contained in:
parent
880e084006
commit
12c01760a6
@ -4,6 +4,7 @@ import com.intellectualcrafters.configuration.MemorySection;
|
|||||||
import com.intellectualcrafters.configuration.file.YamlConfiguration;
|
import com.intellectualcrafters.configuration.file.YamlConfiguration;
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
import com.intellectualcrafters.plot.util.StringMan;
|
import com.intellectualcrafters.plot.util.StringMan;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
@ -98,80 +99,14 @@ public class Config {
|
|||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
}
|
}
|
||||||
PrintWriter writer = new PrintWriter(file);
|
PrintWriter writer = new PrintWriter(file);
|
||||||
Class clazz = root;
|
|
||||||
Object instance = root.newInstance();
|
Object instance = root.newInstance();
|
||||||
save(writer, clazz, instance, 0);
|
save(writer, root, instance, 0);
|
||||||
writer.close();
|
writer.close();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicates that a field should be instantiated / created
|
|
||||||
*/
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Target({ElementType.FIELD})
|
|
||||||
public @interface Create {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicates that a field cannot be modified
|
|
||||||
*/
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Target({ElementType.FIELD})
|
|
||||||
public @interface Final {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a comment
|
|
||||||
*/
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Target({ElementType.FIELD,ElementType.TYPE})
|
|
||||||
public @interface Comment {
|
|
||||||
String[] value();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The names of any default blocks
|
|
||||||
*/
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Target({ElementType.FIELD,ElementType.TYPE})
|
|
||||||
public @interface BlockName {
|
|
||||||
String[] value();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Any field or class with is not part of the config
|
|
||||||
*/
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Target({ElementType.FIELD,ElementType.TYPE})
|
|
||||||
public @interface Ignore {}
|
|
||||||
|
|
||||||
@Ignore // This is not part of the config
|
|
||||||
public static class ConfigBlock<T> {
|
|
||||||
|
|
||||||
private HashMap<String, T> INSTANCES = new HashMap<>();
|
|
||||||
|
|
||||||
public T get(String key) {
|
|
||||||
return INSTANCES.get(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void put(String key, T value) {
|
|
||||||
INSTANCES.put(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Collection<T> getInstances() {
|
|
||||||
return INSTANCES.values();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Collection<String> getSections() {
|
|
||||||
return INSTANCES.keySet();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<String, T> getRaw() {
|
|
||||||
return INSTANCES;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the static fields in a section
|
* Get the static fields in a section
|
||||||
* @param clazz
|
* @param clazz
|
||||||
@ -413,4 +348,69 @@ public class Config {
|
|||||||
modifiersField.setAccessible(true);
|
modifiersField.setAccessible(true);
|
||||||
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates that a field should be instantiated / created
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.FIELD})
|
||||||
|
public @interface Create {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates that a field cannot be modified
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.FIELD})
|
||||||
|
public @interface Final {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a comment
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.FIELD,ElementType.TYPE})
|
||||||
|
public @interface Comment {
|
||||||
|
String[] value();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The names of any default blocks
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.FIELD,ElementType.TYPE})
|
||||||
|
public @interface BlockName {
|
||||||
|
String[] value();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Any field or class with is not part of the config
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.FIELD,ElementType.TYPE})
|
||||||
|
public @interface Ignore {}
|
||||||
|
|
||||||
|
@Ignore // This is not part of the config
|
||||||
|
public static class ConfigBlock<T> {
|
||||||
|
|
||||||
|
private HashMap<String, T> INSTANCES = new HashMap<>();
|
||||||
|
|
||||||
|
public T get(String key) {
|
||||||
|
return INSTANCES.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void put(String key, T value) {
|
||||||
|
INSTANCES.put(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<T> getInstances() {
|
||||||
|
return INSTANCES.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<String> getSections() {
|
||||||
|
return INSTANCES.keySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, T> getRaw() {
|
||||||
|
return INSTANCES;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,11 @@ import com.intellectualcrafters.plot.object.RunnableVal3;
|
|||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
|
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -32,11 +33,13 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
public class ExpireManager {
|
public class ExpireManager {
|
||||||
|
|
||||||
public static ExpireManager IMP;
|
public static ExpireManager IMP;
|
||||||
|
|
||||||
private volatile HashSet<Plot> plotsToDelete;
|
|
||||||
private final ConcurrentHashMap<UUID, Long> dates_cache;
|
private final ConcurrentHashMap<UUID, Long> dates_cache;
|
||||||
|
private volatile HashSet<Plot> plotsToDelete;
|
||||||
private ArrayDeque<ExpiryTask> tasks;
|
private ArrayDeque<ExpiryTask> tasks;
|
||||||
|
/**
|
||||||
|
* 0 = stopped, 1 = stopping, 2 = running
|
||||||
|
*/
|
||||||
|
private int running;
|
||||||
|
|
||||||
public ExpireManager() {
|
public ExpireManager() {
|
||||||
tasks = new ArrayDeque<>();
|
tasks = new ArrayDeque<>();
|
||||||
@ -48,12 +51,6 @@ public class ExpireManager {
|
|||||||
this.tasks.add(task);
|
this.tasks.add(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 0 = stopped, 1 = stopping, 2 = running
|
|
||||||
*/
|
|
||||||
private int running;
|
|
||||||
|
|
||||||
public void handleJoin(PlotPlayer pp) {
|
public void handleJoin(PlotPlayer pp) {
|
||||||
storeDate(pp.getUUID(), System.currentTimeMillis());
|
storeDate(pp.getUUID(), System.currentTimeMillis());
|
||||||
confirmExpiry(pp);
|
confirmExpiry(pp);
|
||||||
@ -154,21 +151,21 @@ public class ExpireManager {
|
|||||||
}
|
}
|
||||||
// Run applicable non confirming tasks
|
// Run applicable non confirming tasks
|
||||||
for (int i = 0; i < applicable.size(); i++) {
|
for (int i = 0; i < applicable.size(); i++) {
|
||||||
ExpiryTask et = applicable.poll();
|
ExpiryTask expiryTask = applicable.poll();
|
||||||
if (!et.needsAnalysis() || plot.getArea().TYPE != 0) {
|
if (!expiryTask.needsAnalysis() || plot.getArea().TYPE != 0) {
|
||||||
if (!et.requiresConfirmation()) {
|
if (!expiryTask.requiresConfirmation()) {
|
||||||
return Arrays.asList(et);
|
return Collections.singletonList(expiryTask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
applicable.add(et);
|
applicable.add(expiryTask);
|
||||||
}
|
}
|
||||||
// Run applicable confirming tasks
|
// Run applicable confirming tasks
|
||||||
for (int i = 0; i < applicable.size(); i++) {
|
for (int i = 0; i < applicable.size(); i++) {
|
||||||
ExpiryTask et = applicable.poll();
|
ExpiryTask expiryTask = applicable.poll();
|
||||||
if (!et.needsAnalysis() || plot.getArea().TYPE != 0) {
|
if (!expiryTask.needsAnalysis() || plot.getArea().TYPE != 0) {
|
||||||
return Arrays.asList(et);
|
return Collections.singletonList(expiryTask);
|
||||||
}
|
}
|
||||||
applicable.add(et);
|
applicable.add(expiryTask);
|
||||||
}
|
}
|
||||||
return applicable;
|
return applicable;
|
||||||
}
|
}
|
||||||
@ -231,9 +228,9 @@ public class ExpireManager {
|
|||||||
if (expired.isEmpty()) {
|
if (expired.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (ExpiryTask et : expired) {
|
for (ExpiryTask expiryTask : expired) {
|
||||||
if (!et.needsAnalysis()) {
|
if (!expiryTask.needsAnalysis()) {
|
||||||
expiredTask.run(plot, this, et.requiresConfirmation());
|
expiredTask.run(plot, this, expiryTask.requiresConfirmation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final Runnable task = this;
|
final Runnable task = this;
|
||||||
@ -358,8 +355,7 @@ public class ExpireManager {
|
|||||||
if (last == 0) {
|
if (last == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
long compared = System.currentTimeMillis() - last;
|
return System.currentTimeMillis() - last;
|
||||||
return compared;
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import com.intellectualcrafters.plot.object.Plot;
|
|||||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||||
import com.intellectualcrafters.plot.util.MathMan;
|
import com.intellectualcrafters.plot.util.MathMan;
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
|
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -420,15 +421,13 @@ public class PlotAnalysis {
|
|||||||
if (ranks.length == 0) {
|
if (ranks.length == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
int size = ranks[0].length;
|
int[] result = new int[ranks[0].length];
|
||||||
int arrays = ranks.length;
|
for (int j = 0; j < ranks[0].length; j++) {
|
||||||
int[] result = new int[size];
|
|
||||||
for (int j = 0; j < size; j++) {
|
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
for (int[] rank : ranks) {
|
for (int[] rank : ranks) {
|
||||||
sum += rank[j];
|
sum += rank[j];
|
||||||
}
|
}
|
||||||
int mean = sum / arrays;
|
int mean = sum / ranks.length;
|
||||||
int sd = 0;
|
int sd = 0;
|
||||||
for (int[] rank : ranks) {
|
for (int[] rank : ranks) {
|
||||||
int value = rank[j];
|
int value = rank[j];
|
||||||
|
Loading…
Reference in New Issue
Block a user