This commit is contained in:
Jesse Boyd 2016-06-09 18:06:08 +10:00
commit 0d47e4599f
4 changed files with 102 additions and 105 deletions

View File

@ -4,6 +4,7 @@ import com.intellectualcrafters.configuration.MemorySection;
import com.intellectualcrafters.configuration.file.YamlConfiguration;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.util.StringMan;
import java.io.File;
import java.io.PrintWriter;
import java.lang.annotation.ElementType;
@ -98,80 +99,14 @@ public class Config {
file.createNewFile();
}
PrintWriter writer = new PrintWriter(file);
Class clazz = root;
Object instance = root.newInstance();
save(writer, clazz, instance, 0);
save(writer, root, instance, 0);
writer.close();
} catch (Throwable e) {
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
* @param clazz
@ -413,4 +348,69 @@ public class Config {
modifiersField.setAccessible(true);
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;
}
}
}

View File

@ -18,10 +18,11 @@ import com.intellectualcrafters.plot.object.RunnableVal3;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Objects;
@ -32,11 +33,13 @@ import java.util.concurrent.ConcurrentHashMap;
public class ExpireManager {
public static ExpireManager IMP;
private volatile HashSet<Plot> plotsToDelete;
private final ConcurrentHashMap<UUID, Long> dates_cache;
private volatile HashSet<Plot> plotsToDelete;
private ArrayDeque<ExpiryTask> tasks;
/**
* 0 = stopped, 1 = stopping, 2 = running
*/
private int running;
public ExpireManager() {
tasks = new ArrayDeque<>();
@ -48,12 +51,6 @@ public class ExpireManager {
this.tasks.add(task);
}
/**
* 0 = stopped, 1 = stopping, 2 = running
*/
private int running;
public void handleJoin(PlotPlayer pp) {
storeDate(pp.getUUID(), System.currentTimeMillis());
confirmExpiry(pp);
@ -154,21 +151,21 @@ public class ExpireManager {
}
// Run applicable non confirming tasks
for (int i = 0; i < applicable.size(); i++) {
ExpiryTask et = applicable.poll();
if (!et.needsAnalysis() || plot.getArea().TYPE != 0) {
if (!et.requiresConfirmation()) {
return Arrays.asList(et);
ExpiryTask expiryTask = applicable.poll();
if (!expiryTask.needsAnalysis() || plot.getArea().TYPE != 0) {
if (!expiryTask.requiresConfirmation()) {
return Collections.singletonList(expiryTask);
}
}
applicable.add(et);
applicable.add(expiryTask);
}
// Run applicable confirming tasks
for (int i = 0; i < applicable.size(); i++) {
ExpiryTask et = applicable.poll();
if (!et.needsAnalysis() || plot.getArea().TYPE != 0) {
return Arrays.asList(et);
ExpiryTask expiryTask = applicable.poll();
if (!expiryTask.needsAnalysis() || plot.getArea().TYPE != 0) {
return Collections.singletonList(expiryTask);
}
applicable.add(et);
applicable.add(expiryTask);
}
return applicable;
}
@ -231,9 +228,9 @@ public class ExpireManager {
if (expired.isEmpty()) {
continue;
}
for (ExpiryTask et : expired) {
if (!et.needsAnalysis()) {
expiredTask.run(plot, this, et.requiresConfirmation());
for (ExpiryTask expiryTask : expired) {
if (!expiryTask.needsAnalysis()) {
expiredTask.run(plot, this, expiryTask.requiresConfirmation());
}
}
final Runnable task = this;
@ -358,8 +355,7 @@ public class ExpireManager {
if (last == 0) {
return 0;
}
long compared = System.currentTimeMillis() - last;
return compared;
return System.currentTimeMillis() - last;
}
return 0;
}

View File

@ -9,6 +9,7 @@ import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.TaskManager;
import java.lang.reflect.Array;
import java.util.ArrayDeque;
import java.util.ArrayList;
@ -420,15 +421,13 @@ public class PlotAnalysis {
if (ranks.length == 0) {
return null;
}
int size = ranks[0].length;
int arrays = ranks.length;
int[] result = new int[size];
for (int j = 0; j < size; j++) {
int[] result = new int[ranks[0].length];
for (int j = 0; j < ranks[0].length; j++) {
int sum = 0;
for (int[] rank : ranks) {
sum += rank[j];
}
int mean = sum / arrays;
int mean = sum / ranks.length;
int sd = 0;
for (int[] rank : ranks) {
int value = rank[j];

View File

@ -11,6 +11,7 @@ import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.world.World;
import java.util.ArrayList;
import java.util.Collection;
@ -20,7 +21,7 @@ import java.util.Optional;
import java.util.UUID;
public class SpongeCommand implements CommandCallable {
@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
TaskManager.runTask(() -> {
@ -40,9 +41,10 @@ public class SpongeCommand implements CommandCallable {
});
return CommandResult.success();
}
@Override
public List<String> getSuggestions(CommandSource source, String arguments) throws CommandException {
public List<String> getSuggestions(CommandSource source, String arguments, org.spongepowered.api.world.Location<World> targetPosition)
throws CommandException {
if (!(source instanceof Player)) {
return null;
}
@ -60,26 +62,26 @@ public class SpongeCommand implements CommandCallable {
result.add(o.toString());
}
return result.isEmpty() ? null : result;
}
}
@Override
public boolean testPermission(CommandSource source) {
return true;
}
@Override
public Optional<Text> getShortDescription(CommandSource source) {
return Optional.of(Text.of("Shows plot help"));
}
@Override
public Optional<Text> getHelp(CommandSource source) {
return Optional.of(Text.of("/plot"));
}
@Override
public Text getUsage(CommandSource source) {
return Text.of("/plot <command>");
}
}