-
-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev/feature' into remove-test-delay
- Loading branch information
Showing
6 changed files
with
301 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,70 @@ | ||
/** | ||
* This file is part of Skript. | ||
* | ||
* Skript is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Skript is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Skript. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* Copyright Peter Güttinger, SkriptLang team and contributors | ||
*/ | ||
package ch.njol.skript.conditions; | ||
|
||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.Event; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.conditions.base.PropertyCondition; | ||
import ch.njol.skript.conditions.base.PropertyCondition.PropertyType; | ||
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.doc.*; | ||
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 org.bukkit.entity.Entity; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.Event; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
@Name("Can See") | ||
@Description("Checks whether the given players can see another players.") | ||
@Examples({"if the player can't see the player-argument:", | ||
"\tmessage \"<light red>The player %player-argument% is not online!\""}) | ||
@Since("2.3") | ||
@Description("Checks whether the given players can see the provided entities.") | ||
@Examples({ | ||
"if sender can't see the player-argument:", | ||
"\tmessage \"who dat?\"", | ||
"", | ||
"if the player can see the last spawned entity:", | ||
"\tmessage \"hello there!\"" | ||
}) | ||
@Since("2.3, INSERT VERSION (entities)") | ||
@RequiredPlugins("Minecraft 1.19+ (entities)") | ||
public class CondCanSee extends Condition { | ||
|
||
static { | ||
Skript.registerCondition(CondCanSee.class, | ||
"%players% (is|are) [(1¦in)]visible for %players%", | ||
"%players% can see %players%", | ||
"%players% (is|are)(n't| not) [(1¦in)]visible for %players%", | ||
"%players% can('t| not) see %players%"); | ||
"%entities% (is|are) [visible|:invisible] for %players%", | ||
"%players% can see %entities%", | ||
"%entities% (is|are)(n't| not) [visible|:invisible] for %players%", | ||
"%players% can('t| not) see %entities%"); | ||
} | ||
|
||
@SuppressWarnings("null") | ||
private Expression<Player> players; | ||
private Expression<Player> viewers; | ||
@SuppressWarnings("null") | ||
private Expression<Player> targetPlayers; | ||
private Expression<Entity> entities; | ||
|
||
@SuppressWarnings({"unchecked", "null"}) | ||
@Override | ||
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||
@SuppressWarnings("unchecked") | ||
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult result) { | ||
if (matchedPattern == 1 || matchedPattern == 3) { | ||
players = (Expression<Player>) exprs[0]; | ||
targetPlayers = (Expression<Player>) exprs[1]; | ||
viewers = (Expression<Player>) exprs[0]; | ||
entities = (Expression<Entity>) exprs[1]; | ||
} else { | ||
players = (Expression<Player>) exprs[1]; | ||
targetPlayers = (Expression<Player>) exprs[0]; | ||
entities = (Expression<Entity>) exprs[0]; | ||
viewers = (Expression<Player>) exprs[1]; | ||
} | ||
setNegated(matchedPattern > 1 ^ parseResult.mark == 1); | ||
setNegated(matchedPattern > 1 ^ result.hasTag("invisible")); | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean check(Event e) { | ||
return players.check(e, | ||
player -> targetPlayers.check(e, | ||
public boolean check(Event event) { | ||
return viewers.check(event, | ||
player -> entities.check(event, | ||
player::canSee | ||
), isNegated()); | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event e, boolean debug) { | ||
return PropertyCondition.toString(this, PropertyType.CAN, e, debug, players, | ||
"see" + targetPlayers.toString(e, debug)); | ||
public String toString(@Nullable Event event, boolean debug) { | ||
return PropertyCondition.toString(this, PropertyType.CAN, event, debug, viewers, | ||
"see " + entities.toString(event, debug)); | ||
} | ||
|
||
} |
95 changes: 95 additions & 0 deletions
95
src/main/java/ch/njol/skript/effects/EffEntityVisibility.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package ch.njol.skript.effects; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.doc.*; | ||
import ch.njol.skript.expressions.ExprHiddenPlayers; | ||
import ch.njol.skript.lang.Effect; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
import ch.njol.util.Kleenean; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.Event; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.jetbrains.annotations.UnknownNullability; | ||
|
||
@Name("Entity Visibility") | ||
@Description({ | ||
"Change visibility of the given entities for the given players.", | ||
"If no players are given, will hide the entities from all online players.", | ||
"", | ||
"When reveal is used in combination of the <a href='expressions.html#ExprHiddenPlayers'>hidden players</a> " + | ||
"expression and the viewers are not specified, " + | ||
"this will default it to the given player in the hidden players expression.", | ||
"", | ||
"Note: all previously hidden entities (including players) will be visible when a player leaves and rejoins.", | ||
}) | ||
@Examples({ | ||
"on spawn:", | ||
"\tif event-entity is a chicken:", | ||
"\t\thide event-entity", | ||
"", | ||
"reveal hidden players of players" | ||
}) | ||
@Since("2.3, INSERT VERSION (entities)") | ||
@RequiredPlugins("Minecraft 1.19+ (entities)") | ||
public class EffEntityVisibility extends Effect { | ||
|
||
static { | ||
Skript.registerEffect(EffEntityVisibility.class, | ||
"hide %entities% [(from|for) %-players%]", | ||
"reveal %entities% [(to|for|from) %-players%]"); | ||
} | ||
|
||
private boolean reveal; | ||
|
||
@UnknownNullability | ||
private Expression<Entity> hidden; | ||
@UnknownNullability | ||
private Expression<Player> viewers; | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult result) { | ||
reveal = matchedPattern == 1; | ||
hidden = (Expression<Entity>) exprs[0]; | ||
|
||
if (reveal && exprs[0] instanceof ExprHiddenPlayers && exprs.length == 1) { | ||
viewers = ((ExprHiddenPlayers) exprs[0]).getViewers(); | ||
} else { | ||
viewers = (Expression<Player>) exprs[1]; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
protected void execute(Event event) { | ||
Player[] updated = viewers != null ? viewers.getArray(event) : Bukkit.getOnlinePlayers().toArray(new Player[0]); | ||
|
||
Skript instance = Skript.getInstance(); | ||
if (reveal) { | ||
for (Player player : updated) { | ||
for (Entity entity : hidden.getArray(event)) { | ||
player.showEntity(instance, entity); | ||
} | ||
} | ||
} else { | ||
for (Player player : updated) { | ||
for (Entity entity : hidden.getArray(event)) { | ||
player.hideEntity(instance, entity); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event event, boolean debug) { | ||
return (reveal ? "reveal " : "hide ") + "entities " + | ||
hidden.toString(event, debug) + | ||
(reveal ? " to " : " from ") + | ||
viewers.toString(event, debug); | ||
} | ||
|
||
} |
106 changes: 0 additions & 106 deletions
106
src/main/java/ch/njol/skript/effects/EffPlayerVisibility.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.