Make ModuloRepeatTask extend EngineAbstract. Add ARList.

This commit is contained in:
Olof Larsson 2015-01-13 09:52:18 +01:00
parent 7d0eba1665
commit b2bdd68069
2 changed files with 76 additions and 27 deletions

View File

@ -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
// -------------------------------------------- //

View File

@ -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<T> extends ArgReaderAbstract<List<T>>
{
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
protected ArgReader<T> innerArgReader;
public ArgReader<T> getInnerArgReader() { return this.innerArgReader; }
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
public static <T> ARList<T> get(ArgReader<T> innerArgReader)
{
return new ARList<T>(innerArgReader);
}
public ARList(ArgReader<T> innerArgReader)
{
this.innerArgReader = innerArgReader;
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
// NOTE: Must be used with argConcatFrom and setErrorOnTooManyArgs(false).
@Override
public ArgResult<List<T>> read(String arg, CommandSender sender)
{
// Split into inner args
String[] innerArgs = arg.split("\\s+");
// Create Ret
ArgResult<List<T>> ret = new ArgResult<List<T>>();
List<T> result = new ArrayList<T>();
// For Each
for (String innerArg : innerArgs)
{
ArgResult<T> 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;
}
}