Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to implement tempbanning. #2694

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/main/java/ch/njol/skript/effects/EffBan.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand All @@ -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<String> reason;

@Nullable
private Expression<Timespan> duration;
Jayderp marked this conversation as resolved.
Show resolved Hide resolved

private boolean ban;
private boolean ipBan;

Expand All @@ -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<String>) exprs[1] : null;
duration = exprs.length > 2 ? (Expression<Timespan>) exprs[2] : null;
ban = matchedPattern % 2 == 0;
ipBan = matchedPattern >= 2;
return true;
Expand All @@ -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) {
Expand Down Expand Up @@ -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.