From b2bdd680696f679e1223e5f68e8c97201d6da161 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Tue, 13 Jan 2015 09:52:18 +0100 Subject: [PATCH] Make ModuloRepeatTask extend EngineAbstract. Add ARList. --- .../massivecore/ModuloRepeatTask.java | 36 +++------- .../massivecore/cmd/arg/ARList.java | 67 +++++++++++++++++++ 2 files changed, 76 insertions(+), 27 deletions(-) create mode 100644 src/main/java/com/massivecraft/massivecore/cmd/arg/ARList.java diff --git a/src/main/java/com/massivecraft/massivecore/ModuloRepeatTask.java b/src/main/java/com/massivecraft/massivecore/ModuloRepeatTask.java index 6d84fb7d..0d5bb644 100644 --- a/src/main/java/com/massivecraft/massivecore/ModuloRepeatTask.java +++ b/src/main/java/com/massivecraft/massivecore/ModuloRepeatTask.java @@ -1,13 +1,10 @@ package com.massivecraft.massivecore; -import org.bukkit.Bukkit; -import org.bukkit.plugin.Plugin; - /** * This class will allow you to create non-tps-dependent repeating tasks. * It makes use of the Bukkit scheduler internally. */ -public abstract class ModuloRepeatTask implements Runnable +public abstract class ModuloRepeatTask extends EngineAbstract { // -------------------------------------------- // // FIELDS: RAW @@ -23,7 +20,8 @@ public abstract class ModuloRepeatTask implements Runnable public long getPreviousMillis() { return this.previousMillis; } public void setPreviousMillis(long previousMillis) { this.previousMillis = previousMillis; } - private Integer taskId = null; + // TODO: Convertion Dust + // private Integer taskId = null; // -------------------------------------------- // // INVOCATION NUMBER CALCULATION @@ -58,6 +56,12 @@ public abstract class ModuloRepeatTask implements Runnable // OVERRIDE // -------------------------------------------- // + @Override + public Long getPeriod() + { + return 1L; + } + @Override public void run() { @@ -78,28 +82,6 @@ public abstract class ModuloRepeatTask implements Runnable this.setPreviousMillis(nowMillis); } - // -------------------------------------------- // - // EIGEN - // -------------------------------------------- // - - @Deprecated - public int schedule(Plugin plugin) - { - this.activate(plugin); - return this.taskId; - } - - public void activate(Plugin plugin) - { - this.taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, this, 1, 1); - } - - public void deactivate() - { - if (this.taskId == null) return; - Bukkit.getScheduler().cancelTask(this.taskId); - } - // -------------------------------------------- // // ABSTRACT // -------------------------------------------- // diff --git a/src/main/java/com/massivecraft/massivecore/cmd/arg/ARList.java b/src/main/java/com/massivecraft/massivecore/cmd/arg/ARList.java new file mode 100644 index 00000000..f3962b57 --- /dev/null +++ b/src/main/java/com/massivecraft/massivecore/cmd/arg/ARList.java @@ -0,0 +1,67 @@ +package com.massivecraft.massivecore.cmd.arg; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.command.CommandSender; + +public class ARList extends ArgReaderAbstract> +{ + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + protected ArgReader innerArgReader; + public ArgReader getInnerArgReader() { return this.innerArgReader; } + + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + public static ARList get(ArgReader innerArgReader) + { + return new ARList(innerArgReader); + } + + public ARList(ArgReader innerArgReader) + { + this.innerArgReader = innerArgReader; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + // NOTE: Must be used with argConcatFrom and setErrorOnTooManyArgs(false). + @Override + public ArgResult> read(String arg, CommandSender sender) + { + // Split into inner args + String[] innerArgs = arg.split("\\s+"); + + // Create Ret + ArgResult> ret = new ArgResult>(); + List result = new ArrayList(); + + // For Each + for (String innerArg : innerArgs) + { + ArgResult innerArgResult = this.getInnerArgReader().read(innerArg, sender); + + if (innerArgResult.hasErrors()) + { + ret.setErrors(innerArgResult.getErrors()); + return ret; + } + + result.add(innerArgResult.getResult()); + } + + // Set Result + ret.setResult(result); + + // Return Ret + return ret; + } + +}