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

Introduces toggle effect & expression #4154

Open
wants to merge 104 commits into
base: dev/feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
ddb40a8
feat(changemode): introduces toggle mode
Olyno Jul 3, 2021
7c6dfb5
merge: master
Olyno Jul 3, 2021
f5d6762
fix(unreachable): remove unecessary statement
Olyno Jul 3, 2021
9f53cc5
fix(unreachable): remove unecessary statement
Olyno Jul 3, 2021
7c799fe
fix(condition): missing pipe sign
Olyno Jul 3, 2021
62af771
revert(ExprWhitelist): reset mode affected
Olyno Jul 3, 2021
717cb84
fix(ExprGlowing): missing toggle mode in acceptChange
Olyno Jul 3, 2021
c9c87be
Merge branch 'feature/toggleChanger' of github.com:Olyno/Skript into …
Olyno Jul 3, 2021
59f8e68
Merge branch 'master' into feature/toggleChanger
Olyno Jul 3, 2021
e6ddeea
Merge branch 'master' into feature/toggleChanger
Olyno Sep 1, 2021
d6cd4d6
fix(conflict): merge master
Olyno Nov 23, 2021
759e1f0
chore(toggle): replaces ChangeMode.TOGGLE with ChangeMode.SET
Olyno Nov 23, 2021
a95f19e
docs(toggle): add missing version update
Olyno Nov 23, 2021
37408c7
chore(toggle): remove syntax conflict & unwanted changes
Olyno Nov 23, 2021
dd8c9d0
chore(toggle): remove unwanted changes
Olyno Nov 23, 2021
fb3af6f
chore(toggle): remove unwanted changes
Olyno Nov 23, 2021
2ade451
chore(toggle): remove missing unwanted changes
Olyno Nov 23, 2021
c4fb185
fix: tests
Olyno Nov 23, 2021
cb93dd8
chore(toggle): move toggle booleans to EffToggle
Olyno Nov 23, 2021
63e0ff7
fix(toggle): check parsing type
Olyno Nov 23, 2021
7ac2de5
fix(toggle): make tests work
Olyno Nov 23, 2021
f6438c8
fix(typo): description of toggle effect
Olyno Nov 24, 2021
6f88032
fix(toggle): make init check work
Olyno Nov 24, 2021
8070373
fix(toggle): make requiered changes
Olyno Nov 24, 2021
7f3cef9
chore: merge changes
Olyno Nov 24, 2021
8ae20b5
chore(toggle): remove unwanted stuff
Olyno Nov 25, 2021
dbc20e6
Merge branch 'master' into feature/toggleChanger
Olyno Feb 11, 2022
3075255
Merge branch 'master' of github.com:SkriptLang/Skript into feature/to…
Olyno Feb 23, 2022
8397e24
fix: indentation
Olyno Feb 23, 2022
912f0d8
docs(ExprToggled): precise we toggle a boolean value
Olyno Feb 23, 2022
d3b07a5
fix(ExprToggled): wrong annotation indentation
Olyno Feb 23, 2022
0da3b69
fix(EffToggle): remove boilerplate and unecessary code
Olyno Feb 23, 2022
4565ff4
fix(EffToggle): boolean value check
Olyno Feb 23, 2022
026a132
fix: conflict
Olyno Feb 23, 2022
9cc2f23
fix(EffToggle): apply change to lists
Olyno Feb 23, 2022
ef85caf
fix(ExprToggled): issue with Expression#stream method
Olyno Feb 25, 2022
f6667d7
Merge branch 'master' into feature/toggleChanger
Olyno Feb 25, 2022
94dd2b0
Merge branch 'master' into feature/toggleChanger
Olyno Mar 14, 2022
d8b81c6
fix: toggle condition
Olyno Mar 18, 2022
2ffed85
feat: optimize toggle operation
Olyno Mar 18, 2022
338f097
fix: typing
Olyno Mar 18, 2022
1fd0cdc
fix: returning only boolean
Olyno Mar 24, 2022
29b1496
test: add block test
Olyno Mar 24, 2022
a41d1c4
Merge branch 'master' into feature/toggleChanger
Olyno Jul 9, 2022
533ecaa
More readable patterns
Olyno Jul 9, 2022
0ca5809
Remove comment
Olyno Jul 9, 2022
6d33a9c
Improve code quality
Olyno Jul 9, 2022
fa349dc
revert: asked
Olyno Oct 5, 2022
c51a1ea
chore: remove empty line
Olyno Oct 5, 2022
7d2b381
chore: change pattern of ExprToggle
Olyno Oct 5, 2022
63df787
Merge branch 'feature/toggleChanger' of github.com:Olyno/Skript into …
Olyno Oct 5, 2022
f1c249f
merge: master
Olyno Oct 5, 2022
9ca79a9
revert: add missing new line for test
Olyno Oct 5, 2022
1611bb3
chore: rename ExprToggled to ExprInverse
Olyno Oct 5, 2022
6cd8135
fix: toggle test
Olyno Oct 5, 2022
702206d
fix(typo): apply review
Olyno Oct 6, 2022
876933a
Merge branch 'master' of github.com:SkriptLang/Skript into feature/to…
Olyno Oct 26, 2022
3af8951
revert: unecessary change
Olyno Oct 26, 2022
c60cd74
ups
Olyno Oct 26, 2022
0c02931
chore: remove unused imports
Olyno Oct 26, 2022
bb053c0
docs: remove comment
Olyno Nov 17, 2022
eab9c59
docs: update description
Olyno Dec 26, 2022
3bfb357
chore: short code
Olyno Dec 26, 2022
83e461a
Merge branch 'master' into feature/toggleChanger
Olyno Dec 26, 2022
964c998
Merge branch 'master' into feature/toggleChanger
Olyno Dec 30, 2022
b3884c0
chore: adds check before toggle
Olyno Jan 18, 2023
596644c
Merge branch 'master' into feature/toggleChanger
Olyno Jan 18, 2023
ab8b35f
chore: add missing closures
Olyno Jan 18, 2023
2fb4096
chore: remove finals
Olyno Jan 18, 2023
b813df0
chore: simplify workflow
Olyno Jan 18, 2023
e397038
fix: toggle wasn't working correctly
Olyno Feb 11, 2023
23d711a
Merge branch 'master' into feature/toggleChanger
Olyno Apr 25, 2023
832374d
fix: missing value when boolean toggle
Olyno Apr 30, 2023
07601b3
merge: master
Olyno Apr 30, 2023
08397f5
Merge branch 'master' into feature/toggleChanger
Olyno Apr 30, 2023
27b9169
fix: incompatibility Java version method
Olyno May 1, 2023
54fbcca
Merge branch 'feature/toggleChanger' of github.com:Olyno/Skript into …
Olyno May 1, 2023
6a3f2a2
fix: block wasn't added to the list
Olyno May 1, 2023
0cfa688
Merge branch 'master' into feature/toggleChanger
Olyno May 1, 2023
e3f1622
test: rename test name
Olyno May 1, 2023
68fead4
chore: remove unecessary part
Olyno May 1, 2023
439639c
chore: update code with review
Olyno May 1, 2023
9121b2a
Merge branch 'master' into feature/toggleChanger
Olyno May 2, 2023
64bd9c3
Merge branch 'master' into feature/toggleChanger
Olyno May 9, 2023
75d999e
Merge branch 'dev/feature' into feature/toggleChanger
Moderocky Oct 14, 2023
c20f01f
Merge branch 'dev/feature' into feature/toggleChanger
Moderocky Apr 3, 2024
14cc4e0
Merge branch 'dev/feature' into feature/toggleChanger
Olyno Apr 8, 2024
fa7d13c
Merge branch 'dev/feature' into feature/toggleChanger
sovdeeth May 6, 2024
fc6840c
Merge branch 'dev/feature' into feature/toggleChanger
Moderocky May 8, 2024
6cde78c
Merge branch 'dev/feature' into feature/toggleChanger
Olyno May 9, 2024
5d5cb4a
chore(formatting): fix formatting
Olyno Jun 3, 2024
9bb3ed5
chore(formatting): fix formatting
Olyno Jun 3, 2024
ae5960f
chore(formatting): fix formatting
Olyno Jun 3, 2024
8ee2c1b
chore(formatting): fix formatting
Olyno Jun 3, 2024
1315872
chore: collect as array directly
Olyno Jun 3, 2024
bbabd72
Merge branch 'dev/feature' into feature/toggleChanger
Olyno Jun 3, 2024
b5dd7b5
chore: rename 'toggledExpr' to 'togglables'
Olyno Jun 15, 2024
41a45fe
fix(toggle): try to fix unexpected behavior
Olyno Jun 15, 2024
15a8bf2
Merge branch 'dev/feature' into feature/toggleChanger
Olyno Jun 15, 2024
7259c54
Merge branch 'dev/feature' into feature/toggleChanger
sovdeeth Aug 16, 2024
565fe7d
Merge branch 'dev/feature' into feature/toggleChanger
Olyno Nov 15, 2024
ab9b399
chore(EffToggle): check if accepts more than single value
Olyno Nov 15, 2024
8bc1de4
fix(EffToggle): avoid index reset when possible
Olyno Nov 15, 2024
adf2438
fix(test): rephrase error
Olyno Nov 15, 2024
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
2 changes: 1 addition & 1 deletion src/main/java/ch/njol/skript/classes/Changer.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
public interface Changer<T> {

public static enum ChangeMode {
ADD, SET, REMOVE, REMOVE_ALL, DELETE, RESET;
ADD, SET, REMOVE, REMOVE_ALL, DELETE, RESET, TOGGLE;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,9 @@ public Class<? extends Object>[] acceptChange(final ChangeMode mode) {
return CollectionUtils.array(PotionEffectType[].class, ItemType[].class, Inventory.class);
case REMOVE_ALL:
return CollectionUtils.array(PotionEffectType[].class, ItemType[].class);
case SET:
case RESET: // REMIND reset entity? (unshear, remove held item, reset weapon/armour, ...)
default: // REMIND reset entity? (unshear, remove held item, reset weapon/armour, ...)
return null;
}
assert false;
return null;
}

@Override
Expand Down Expand Up @@ -268,7 +265,7 @@ public void change(final Inventory[] invis, final @Nullable Object[] delta, fina
}
}
break;
case RESET:
default:
assert false;
}
InventoryHolder holder = invi.getHolder();
Expand Down Expand Up @@ -343,7 +340,7 @@ public void change(final Block[] blocks, final @Nullable Object[] delta, final C
}
state.update();
break;
case RESET:
default:
assert false;
}
}
Expand Down
23 changes: 19 additions & 4 deletions src/main/java/ch/njol/skript/effects/EffChange.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package ch.njol.skript.effects;

import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;

import org.bukkit.event.Event;
Expand Down Expand Up @@ -73,7 +74,10 @@
"delete {variable}",
"# reset:",
"reset walk speed of player",
"reset chunk at the targeted block"})
"reset chunk at the targeted block",
"# toggle:",
Olyno marked this conversation as resolved.
Show resolved Hide resolved
Olyno marked this conversation as resolved.
Show resolved Hide resolved
"toggle player's flight mode",
"toggle player's gravity"})
@Since("1.0 (set, add, remove, delete), 2.0 (remove all)")
public class EffChange extends Effect {
private static Patterns<ChangeMode> patterns = new Patterns<>(new Object[][] {
Expand All @@ -90,7 +94,9 @@ public class EffChange extends Effect {

{"(delete|clear) %~objects%", ChangeMode.DELETE},

{"reset %~objects%", ChangeMode.RESET}
{"reset %~objects%", ChangeMode.RESET},

{"toggle %~objects%", ChangeMode.TOGGLE}
});

static {
Expand Down Expand Up @@ -146,6 +152,10 @@ public boolean init(final Expression<?>[] exprs, final int matchedPattern, final
break;
case RESET:
changed = exprs[0];
break;
case TOGGLE:
changed = exprs[0];
break;
}

CountingLogHandler h = new CountingLogHandler(Level.SEVERE).start();
Expand Down Expand Up @@ -187,6 +197,9 @@ public boolean init(final Expression<?>[] exprs, final int matchedPattern, final
Skript.error(what + " can't be reset. It can however be deleted which might result in the desired effect.", ErrorQuality.SEMANTIC_ERROR);
else
Skript.error(what + " can't be reset", ErrorQuality.SEMANTIC_ERROR);
break;
case TOGGLE:
Skript.error(what + " can't be toggled", ErrorQuality.SEMANTIC_ERROR);
}
return false;
}
Expand Down Expand Up @@ -272,9 +285,9 @@ else if (mode == ChangeMode.SET)
protected void execute(Event e) {
Expression<?> changer = this.changer;
Object[] delta = changer == null ? null : changer.getArray(e);
List<ChangeMode> modes = List.of(ChangeMode.DELETE, ChangeMode.RESET, ChangeMode.TOGGLE);
Olyno marked this conversation as resolved.
Show resolved Hide resolved
delta = changer == null ? delta : changer.beforeChange(changed, delta);

if ((delta == null || delta.length == 0) && (mode != ChangeMode.DELETE && mode != ChangeMode.RESET)) {
if ((delta == null || delta.length == 0) && (!modes.contains(mode))) {
if (changed.acceptChange(ChangeMode.DELETE) != null)
changed.change(e, null, ChangeMode.DELETE);
return;
Expand Down Expand Up @@ -302,6 +315,8 @@ public String toString(final @Nullable Event e, final boolean debug) {
return "delete/clear " + changed.toString(e, debug);
case RESET:
return "reset " + changed.toString(e, debug);
case TOGGLE:
return "toggle " + changed.toString(e, debug);
}
assert false;
return "";
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/ch/njol/skript/expressions/ExprAI.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
@Name("Entity AI")
@Description("Returns whether an entity has AI.")
@Examples("set artificial intelligence of target entity to false")
@Since("2.5")
@Since("2.5, INSERT VERSION (toggle support)")
public class ExprAI extends SimplePropertyExpression<LivingEntity, Boolean> {

static {
Expand All @@ -49,12 +49,23 @@ public Boolean convert(LivingEntity entity) {
@Nullable
@Override
public Class<?>[] acceptChange(Changer.ChangeMode mode) {
return mode == Changer.ChangeMode.SET ? CollectionUtils.array(Boolean.class) : null;
switch (mode) {
case SET:
case TOGGLE:
return CollectionUtils.array(Boolean.class);
default:
return null;
}
}

@Override
public void change(Event event, @Nullable Object[] delta, Changer.ChangeMode mode) {
if (delta == null || delta[0] == null) {
if (mode == Changer.ChangeMode.TOGGLE) {
for (LivingEntity entity : getExpr().getArray(event)) {
entity.setAI(!entity.hasAI());
}
}
return;
}
boolean value = (Boolean) delta[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,11 @@ public Class<?>[] acceptChange(final ChangeMode mode) {
Skript.error("Can't cancel the event anymore after it has already passed");
return null;
}
if (mode == ChangeMode.SET || mode == ChangeMode.DELETE)
if (mode == ChangeMode.SET || mode == ChangeMode.DELETE | mode == ChangeMode.TOGGLE)
Olyno marked this conversation as resolved.
Show resolved Hide resolved
return CollectionUtils.array(Boolean.class);
return null;
}

@SuppressWarnings("incomplete-switch")
@Override
public void change(final Event e, final @Nullable Object[] delta, final ChangeMode mode) {
if (!(e instanceof Cancellable))
Expand All @@ -99,6 +98,11 @@ public void change(final Event e, final @Nullable Object[] delta, final ChangeMo
case SET:
assert delta != null;
((Cancellable) e).setCancelled((Boolean) delta[0]);
break;
case TOGGLE:
Cancellable cancellable = (Cancellable) e;
cancellable.setCancelled(!cancellable.isCancelled());
break;
}
}

Expand Down
17 changes: 11 additions & 6 deletions src/main/java/ch/njol/skript/expressions/ExprFlightMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,22 @@
*/
package ch.njol.skript.expressions;

import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.eclipse.jdt.annotation.Nullable;

Olyno marked this conversation as resolved.
Show resolved Hide resolved
import ch.njol.skript.classes.Changer;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.expressions.base.SimplePropertyExpression;
import ch.njol.util.coll.CollectionUtils;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.eclipse.jdt.annotation.Nullable;

@Name("Flight Mode")
@Description("Whether the player(s) are allowed to fly. Use <a href=effects.html#EffMakeFly>Make Fly</a> effect to force player(s) to fly.")
@Examples({"set flight mode of player to true", "send \"%flying state of all players%\""})
@Since("2.2-dev34")
@Since("2.2-dev34, INSERT VERSION (toggle support)")
public class ExprFlightMode extends SimplePropertyExpression<Player, Boolean> {

static {
Expand All @@ -47,7 +48,7 @@ public Boolean convert(final Player player) {
@Override
@Nullable
public Class<?>[] acceptChange(Changer.ChangeMode mode) {
if (mode == Changer.ChangeMode.SET || mode == Changer.ChangeMode.RESET) {
if (mode == Changer.ChangeMode.SET || mode == Changer.ChangeMode.RESET || mode == Changer.ChangeMode.TOGGLE) {
return CollectionUtils.array(Boolean.class);
}
return null;
Expand All @@ -57,7 +58,11 @@ public Class<?>[] acceptChange(Changer.ChangeMode mode) {
public void change(Event event, @Nullable Object[] delta, Changer.ChangeMode mode) {
boolean state = mode != Changer.ChangeMode.RESET && delta != null && (boolean) delta[0];
for (Player player : getExpr().getArray(event)) {
player.setAllowFlight(state);
if (mode == Changer.ChangeMode.TOGGLE) {
player.setAllowFlight(!player.getAllowFlight());
} else {
player.setAllowFlight(state);
}
}
}

Expand Down
13 changes: 9 additions & 4 deletions src/main/java/ch/njol/skript/expressions/ExprGlidingState.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
@Name("Gliding State")
@Description("Sets of gets gliding state of player. It allows you to set gliding state of entity even if they do not have an <a href=\"https://minecraft.gamepedia.com/Elytra\">Elytra</a> equipped.")
@Examples({"set gliding of player to off"})
@Since("2.2-dev21")
@Since("2.2-dev21, INSERT VERSION (toggle support)")
public class ExprGlidingState extends SimplePropertyExpression<LivingEntity, Boolean> {

static {
Expand All @@ -59,14 +59,19 @@ public Class<Boolean> getReturnType() {
@Override
@Nullable
public Class<?>[] acceptChange(final ChangeMode mode) {
if (mode == ChangeMode.SET || mode == ChangeMode.RESET)
if (mode == ChangeMode.SET || mode == ChangeMode.RESET || mode == ChangeMode.TOGGLE)
return new Class[] {Boolean.class};
return null;
}

@Override
public void change(final Event e, final @Nullable Object[] delta, final ChangeMode mode) throws UnsupportedOperationException {
for (final LivingEntity entity : getExpr().getArray(e))
entity.setGliding(delta == null ? false : (Boolean) delta[0]);
for (final LivingEntity entity : getExpr().getArray(e)) {
if (mode == ChangeMode.TOGGLE) {
entity.setGliding(!entity.isGliding());
} else {
entity.setGliding(delta == null ? false : (Boolean) delta[0]);
}
}
}
}
11 changes: 8 additions & 3 deletions src/main/java/ch/njol/skript/expressions/ExprGlowing.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
@Name("Glowing")
@Description("Indicates if targeted entity is glowing (new 1.9 effect) or not. Glowing entities can be seen through walls.")
@Examples({"set glowing of player to true"})
@Since("2.2-dev18")
@Since("2.2-dev18, INSERT VERSION (toggle support)")
public class ExprGlowing extends SimplePropertyExpression<Entity, Boolean> {
Olyno marked this conversation as resolved.
Show resolved Hide resolved

static {
Expand Down Expand Up @@ -64,7 +64,12 @@ public Class<?>[] acceptChange(final ChangeMode mode) {

@Override
public void change(final Event e, final @Nullable Object[] delta, final ChangeMode mode) throws UnsupportedOperationException {
for (final Entity entity : getExpr().getArray(e))
entity.setGlowing(delta == null ? false : (Boolean) delta[0]);
for (final Entity entity : getExpr().getArray(e)) {
if (mode == ChangeMode.TOGGLE) {
entity.setGlowing(!entity.isGlowing());
} else {
entity.setGlowing(delta == null ? false : (Boolean) delta[0]);
}
}
}
}
14 changes: 10 additions & 4 deletions src/main/java/ch/njol/skript/expressions/ExprGravity.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
@Name("Gravity")
@Description("If entity is affected by gravity or not, i.e. if it has Minecraft 1.10+ NoGravity flag.")
@Examples({"set gravity of player off"})
@Since("2.2-dev21")
@Since("2.2-dev21, INSERT VERSION (toggle support)")
public class ExprGravity extends SimplePropertyExpression<Entity, Boolean> {

static {
Expand All @@ -59,14 +59,20 @@ public Class<Boolean> getReturnType() {
@Override
@Nullable
public Class<?>[] acceptChange(final ChangeMode mode) {
if (mode == ChangeMode.SET || mode == ChangeMode.RESET)
if (mode == ChangeMode.SET || mode == ChangeMode.RESET || mode == ChangeMode.TOGGLE)
return new Class[] {Boolean.class};
return null;
}

@Override
public void change(final Event e, final @Nullable Object[] delta, final ChangeMode mode) throws UnsupportedOperationException {
for (final Entity entity : getExpr().getArray(e))
entity.setGravity(delta == null ? true : (Boolean) delta[0]);
for (final Entity entity : getExpr().getArray(e)) {
if (mode == ChangeMode.TOGGLE) {
entity.setGravity(!entity.hasGravity());
} else {
entity.setGravity(delta == null ? true : (Boolean) delta[0]);
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public T[] get(Event e) {
@Override
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
if (mode == ChangeMode.RESET)
if (mode == ChangeMode.RESET || mode == ChangeMode.TOGGLE)
return null;
for (Expression<?> expr : variables.getExpressions()) {
if (!((Variable<?>) expr).isList()) { // It's a single variable
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/ch/njol/skript/expressions/ExprSaturation.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
@Name("Saturation")
@Description("The saturation of a player. If used in a player event, it can be omitted and will default to event-player.")
@Examples("set saturation of player to 20")
@Since("2.2-Fixes-v10, 2.2-dev35 (fully modifiable)")
@Since("2.2-Fixes-v10, 2.2-dev35 (fully modifiable), INSERT VERSION (toggle support)")
public class ExprSaturation extends PropertyExpression<Player, Number> {
Olyno marked this conversation as resolved.
Show resolved Hide resolved

static {
Expand Down Expand Up @@ -98,6 +98,10 @@ public void change(Event e, @Nullable Object[] delta, Changer.ChangeMode mode) {
for (Player player : getExpr().getArray(e))
player.setSaturation(0);
break;
case TOGGLE:
for (Player player : getExpr().getArray(e))
player.setSaturation(player.getSaturation() == 100 ? 0 : 100);
break;
}
}

Expand Down
26 changes: 14 additions & 12 deletions src/main/java/ch/njol/skript/expressions/ExprWhitelist.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
@Examples({"set whitelist to false",
"add all players to whitelist",
"reset the whitelist"})
@Since("2.5.2")
@Since("2.5.2, INSERT VERSION (toggle support)")
public class ExprWhitelist extends SimpleExpression<OfflinePlayer> {

static {
Expand All @@ -68,35 +68,37 @@ protected OfflinePlayer[] get(Event e) {
public Class<?>[] acceptChange(ChangeMode mode) {
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE)
return CollectionUtils.array(OfflinePlayer[].class);
else if (mode == ChangeMode.SET || mode == ChangeMode.RESET)
else if (mode == ChangeMode.SET || mode == ChangeMode.RESET || mode == ChangeMode.TOGGLE)
return CollectionUtils.array(Boolean.class);
else
return null;
}

@Override
public void change(Event e, @Nullable Object[] delta, ChangeMode mode) {
if (delta == null) return;
Olyno marked this conversation as resolved.
Show resolved Hide resolved
switch (mode) {
case SET:
if (delta != null)
Bukkit.setWhitelist((Boolean) delta[0]);
Bukkit.setWhitelist((Boolean) delta[0]);
break;
case ADD:
if (delta != null) {
for (Object p : delta)
((OfflinePlayer) p).setWhitelisted(true);
}
for (Object p : delta)
((OfflinePlayer) p).setWhitelisted(true);
break;
case REMOVE:
if (delta != null) {
for (Object p : delta)
((OfflinePlayer) p).setWhitelisted(false);
}
for (Object p : delta)
((OfflinePlayer) p).setWhitelisted(false);
break;
case RESET:
for (OfflinePlayer p : Bukkit.getWhitelistedPlayers())
p.setWhitelisted(false);
break;
case TOGGLE:
for (Object p : delta) {
OfflinePlayer player = (OfflinePlayer) p;
player.setWhitelisted(!player.isWhitelisted());
}
break;
default:
assert false;
}
Expand Down