Initial commit
This commit is contained in:
parent
8e604aa324
commit
5bca29176b
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
.idea
|
||||||
|
out
|
||||||
|
Skooldown.iml
|
30
src/lt/govindas/skooldown/Skooldown.java
Normal file
30
src/lt/govindas/skooldown/Skooldown.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package lt.govindas.skooldown;
|
||||||
|
|
||||||
|
import ch.njol.skript.Skript;
|
||||||
|
import ch.njol.skript.lang.ExpressionType;
|
||||||
|
import ch.njol.skript.util.Timespan;
|
||||||
|
import lt.govindas.skooldown.conditions.CondCooldownOver;
|
||||||
|
import lt.govindas.skooldown.effects.EffStartCooldown;
|
||||||
|
import lt.govindas.skooldown.expressions.ExprCooldown;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public final class Skooldown extends JavaPlugin {
|
||||||
|
public static HashMap<String, Long> cooldowns = new HashMap<String, Long>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
Skript.registerEffect(EffStartCooldown.class, "(create|start) [a] cooldown %string% for %timespan%");
|
||||||
|
Skript.registerCondition(CondCooldownOver.class, "[the] cooldown %string% (is|has) (finished|over|done)", "[the] cooldown %string% is(n't| not) unfinished)", "[the] cooldown %string% is(n't| not) (finished|over|done)", "[the] cooldown %string% is unfinished");
|
||||||
|
Skript.registerExpression(ExprCooldown.class, Timespan.class, ExpressionType.PROPERTY, "cooldown %string%");
|
||||||
|
getLogger().info("[Skooldown] Plugin enabled!");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
getLogger().info("[Skooldown] Plugin disabled!");
|
||||||
|
}
|
||||||
|
}
|
46
src/lt/govindas/skooldown/conditions/CondCooldownOver.java
Normal file
46
src/lt/govindas/skooldown/conditions/CondCooldownOver.java
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package lt.govindas.skooldown.conditions;
|
||||||
|
|
||||||
|
import ch.njol.skript.lang.Condition;
|
||||||
|
import ch.njol.skript.lang.Expression;
|
||||||
|
import ch.njol.skript.lang.SkriptParser.ParseResult;
|
||||||
|
import ch.njol.util.Kleenean;
|
||||||
|
import lt.govindas.skooldown.Skooldown;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class CondCooldownOver extends Condition {
|
||||||
|
|
||||||
|
private Expression<String> name;
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
|
||||||
|
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean paramKleenean, ParseResult paramParseResult) {
|
||||||
|
name = (Expression<String>) expr[0];
|
||||||
|
System.out.println(matchedPattern);
|
||||||
|
setNegated(matchedPattern == 2 || matchedPattern == 3);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(@Nullable Event e, boolean debug) {
|
||||||
|
return "is cooldown over" + name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean check(Event e) {
|
||||||
|
Long cooldown = Skooldown.cooldowns.get(name.getSingle(e));
|
||||||
|
|
||||||
|
//if cooldown isn't created, will return that it is over
|
||||||
|
if (cooldown == null) return !isNegated();
|
||||||
|
|
||||||
|
if (cooldown < System.currentTimeMillis()) {
|
||||||
|
Skooldown.cooldowns.remove(name.getSingle(e));
|
||||||
|
//will return that cooldown is over
|
||||||
|
return !isNegated();
|
||||||
|
}
|
||||||
|
//will return that cooldown is not over
|
||||||
|
|
||||||
|
return isNegated();
|
||||||
|
}
|
||||||
|
}
|
36
src/lt/govindas/skooldown/effects/EffStartCooldown.java
Normal file
36
src/lt/govindas/skooldown/effects/EffStartCooldown.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package lt.govindas.skooldown.effects;
|
||||||
|
|
||||||
|
import ch.njol.skript.lang.Effect;
|
||||||
|
import ch.njol.skript.lang.Expression;
|
||||||
|
import ch.njol.skript.lang.SkriptParser.ParseResult;
|
||||||
|
import ch.njol.skript.util.Timespan;
|
||||||
|
import ch.njol.util.Kleenean;
|
||||||
|
import lt.govindas.skooldown.Skooldown;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class EffStartCooldown extends Effect {
|
||||||
|
|
||||||
|
private Expression<String> name;
|
||||||
|
private Expression<Timespan> time;
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean paramKleenean, ParseResult paramParseResult) {
|
||||||
|
name = (Expression<String>) expr[0];
|
||||||
|
time = (Expression<Timespan>) expr[1];
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(@Nullable Event e, boolean debug) {
|
||||||
|
return "start cooldown " + name.getSingle(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void execute(Event e) {
|
||||||
|
Skooldown.cooldowns.put(name.getSingle(e), System.currentTimeMillis() + time.getSingle(e).getMilliSeconds());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
package lt.govindas.skooldown.expressions;
|
||||||
|
|
||||||
|
public class ExprAllCooldowns {
|
||||||
|
}
|
98
src/lt/govindas/skooldown/expressions/ExprCooldown.java
Normal file
98
src/lt/govindas/skooldown/expressions/ExprCooldown.java
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
package lt.govindas.skooldown.expressions;
|
||||||
|
|
||||||
|
|
||||||
|
import ch.njol.skript.classes.Changer;
|
||||||
|
import ch.njol.skript.classes.Changer.ChangeMode;
|
||||||
|
import ch.njol.skript.lang.Expression;
|
||||||
|
import ch.njol.skript.lang.SkriptParser.ParseResult;
|
||||||
|
import ch.njol.skript.lang.util.SimpleExpression;
|
||||||
|
import ch.njol.skript.util.Timespan;
|
||||||
|
import ch.njol.util.Kleenean;
|
||||||
|
import ch.njol.util.coll.CollectionUtils;
|
||||||
|
import lt.govindas.skooldown.Skooldown;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
//TODO rename "delta" into something else, since I don't know what delta is
|
||||||
|
public class ExprCooldown extends SimpleExpression<Timespan> {
|
||||||
|
|
||||||
|
private Expression<String> name;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSingle() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<? extends Timespan> getReturnType() {
|
||||||
|
return Timespan.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean paramKleenean, ParseResult paramParseResult) {
|
||||||
|
name = (Expression<String>) expr[0];
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(@Nullable Event e, boolean debug) {
|
||||||
|
return "get cooldown " + name.getSingle(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Timespan[] get(Event e) {
|
||||||
|
Long cooldown = Skooldown.cooldowns.get(name.getSingle(e));
|
||||||
|
|
||||||
|
//if cooldown isn't created, will return that it is over
|
||||||
|
if (cooldown == null) return new Timespan[]{new Timespan(0)};
|
||||||
|
|
||||||
|
if (cooldown < System.currentTimeMillis()) {
|
||||||
|
Skooldown.cooldowns.remove(name.getSingle(e));
|
||||||
|
return new Timespan[]{new Timespan(0)};
|
||||||
|
}
|
||||||
|
return new Timespan[]{new Timespan(Skooldown.cooldowns.get(name.getSingle(e)) - System.currentTimeMillis())};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void change(Event e, Object[] delta, ChangeMode mode) {
|
||||||
|
switch (mode) {
|
||||||
|
case SET:
|
||||||
|
Skooldown.cooldowns.put(name.getSingle(e), System.currentTimeMillis() + ((Timespan) delta[0]).getMilliSeconds());
|
||||||
|
break;
|
||||||
|
case REMOVE_ALL:
|
||||||
|
case DELETE:
|
||||||
|
case RESET:
|
||||||
|
Skooldown.cooldowns.remove(name.getSingle(e));
|
||||||
|
break;
|
||||||
|
case ADD:
|
||||||
|
Long cooldown = Skooldown.cooldowns.get(name.getSingle(e));
|
||||||
|
if (cooldown == null) {
|
||||||
|
Skooldown.cooldowns.put(name.getSingle(e), System.currentTimeMillis() + ((Timespan) delta[0]).getMilliSeconds());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Skooldown.cooldowns.put(name.getSingle(e), cooldown + ((Timespan) delta[0]).getMilliSeconds());
|
||||||
|
break;
|
||||||
|
case REMOVE:
|
||||||
|
cooldown = Skooldown.cooldowns.get(name.getSingle(e));
|
||||||
|
//if removing from non-existent cooldown, do nothing
|
||||||
|
if (cooldown == null) return;
|
||||||
|
|
||||||
|
//remove cooldown from hashMap if it would expire with new value
|
||||||
|
|
||||||
|
if ((cooldown - ((Timespan) delta[0]).getMilliSeconds()) < System.currentTimeMillis()) {
|
||||||
|
Skooldown.cooldowns.remove(name.getSingle(e));
|
||||||
|
} else {
|
||||||
|
Skooldown.cooldowns.put(name.getSingle(e), cooldown - ((Timespan) delta[0]).getMilliSeconds());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalStateException("Unexpected value: " + mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<?>[] acceptChange(final Changer.ChangeMode mode) { return CollectionUtils.array(Timespan.class); }
|
||||||
|
}
|
||||||
|
|
4
src/plugin.yml
Normal file
4
src/plugin.yml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
name: Skooldown
|
||||||
|
main: lt.govindas.skooldown.Skooldown
|
||||||
|
version: 0.0.1
|
||||||
|
authors: [Govindas, Nashoba24]
|
Loading…
Reference in New Issue
Block a user