diff --git a/src/main/java/ch/njol/skript/effects/EffBan.java b/src/main/java/ch/njol/skript/effects/EffBan.java index cc0376172cd..20c60699dce 100644 --- a/src/main/java/ch/njol/skript/effects/EffBan.java +++ b/src/main/java/ch/njol/skript/effects/EffBan.java @@ -30,6 +30,7 @@ import org.bukkit.event.Event; import org.eclipse.jdt.annotation.Nullable; + import ch.njol.skript.Skript; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Examples; @@ -38,6 +39,7 @@ 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; /** @@ -55,16 +57,20 @@ public class EffBan extends Effect { static { Skript.registerEffect(EffBan.class, - "ban %strings/offlineplayers% [(by reason of|because [of]|on account of|due to) %-string%]", "unban %strings/offlineplayers%", - "ban %players% by IP [(by reason of|because [of]|on account of|due to) %-string%]", "unban %players% by IP", - "IP(-| )ban %players% [(by reason of|because [of]|on account of|due to) %-string%]", "(IP(-| )unban|un[-]IP[-]ban) %players%"); + "ban %strings/offlineplayers% [(by reason of|because [of]|on account of|due to) %-string%] [for %timespan%]", "unban %strings/offlineplayers%", + "ban %players% by IP [(by reason of|because [of]|on account of|due to) %-string%] [for %timespan%]", "unban %players% by IP", + "IP(-| )ban %players% [(by reason of|because [of]|on account of|due to) %-string%] [for %timespan%]", "(IP(-| )unban|un[-]IP[-]ban) %players%"); } @SuppressWarnings("null") private Expression players; + @Nullable private Expression reason; + @Nullable + private Expression duration; + private boolean ban; private boolean ipBan; @@ -73,6 +79,7 @@ public class EffBan extends Effect { public boolean init(final Expression[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) { players = exprs[0]; reason = exprs.length > 1 ? (Expression) exprs[1] : null; + duration = exprs.length > 2 ? (Expression) exprs[2] : null; ban = matchedPattern % 2 == 0; ipBan = matchedPattern >= 2; return true; @@ -81,7 +88,7 @@ public boolean init(final Expression[] exprs, final int matchedPattern, final @Override protected void execute(final Event e) { final String reason = this.reason != null ? this.reason.getSingle(e) : null; // don't check for null, just ignore an invalid reason - final Date expires = null; + final Date expires = this.duration != null ? new Date(System.currentTimeMillis() + this.duration.getSingle(e).getMilliSeconds()) : null; final String source = "Skript ban effect"; for (final Object o : players.getArray(e)) { if (o instanceof Player) { @@ -126,6 +133,7 @@ protected void execute(final Event e) { @Override public String toString(final @Nullable Event e, final boolean debug) { return (ipBan ? "IP-" : "") + (ban ? "" : "un") + "ban " + players.toString(e, debug) + (reason != null ? " on account of " + reason.toString(e, debug) : ""); - } - + } } + +// Imagine you had 1 cookie for every friend you had. Despite what you think, you'd have quite a lot of cookies.