-
-
Notifications
You must be signed in to change notification settings - Fork 368
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
Add player visibility stuff #1302
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6b2641b
Add player visibility stuff
Blueyescat f6110ef
Remove an unnecessary blank line and fix syntax description
Blueyescat 9fe1019
Fixes
Blueyescat a5c9ae7
Merge branch 'visibility-stuff' of https://github.com/Blueyescat/Skri…
Blueyescat 5a69499
Reviews
Blueyescat 0de3bfd
Remove show effect
Blueyescat cd09204
Remove an unnecessary import
Blueyescat 3af27b3
Fix copyrights
Blueyescat 60dc909
Revert "Fix copyrights"
Blueyescat a6dd956
Remove unnecessary imports
Blueyescat c8dcb26
Resolve conflicts with build.gradle
Blueyescat a841686
Merge branch 'master' into visibility-stuff
Blueyescat b867227
Fix import orders
Blueyescat c10dfdc
Fix import order
Blueyescat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,88 @@ | ||
/** | ||
* 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 2011-2017 Peter Güttinger and contributors | ||
*/ | ||
package ch.njol.skript.conditions; | ||
|
||
import ch.njol.skript.Skript; | ||
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.lang.Condition; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.SkriptParser; | ||
import ch.njol.util.Checker; | ||
import ch.njol.util.Kleenean; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.Bukkit; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
|
||
@Name("Can See") | ||
@Description("Checks whether the given players can see another players.") | ||
@Examples({"if the player can't see the player-argument:", | ||
" message \"<light red>The player %player-argument% is not online!\""}) | ||
@Since("INSERT VERSION") | ||
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%"); | ||
} | ||
|
||
@SuppressWarnings("null") | ||
private Expression<Player> players, targetPlayers; | ||
|
||
@Override | ||
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { | ||
setNegated(matchedPattern > 1 ^ parseResult.mark == 1); | ||
if (matchedPattern == 1 || matchedPattern == 3) { | ||
players = (Expression<Player>) exprs[0]; | ||
targetPlayers = (Expression<Player>) exprs[1]; | ||
} else { | ||
players = (Expression<Player>) exprs[1]; | ||
targetPlayers = (Expression<Player>) exprs[0]; | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean check(Event e) { | ||
return players.check(e, new Checker<Player>() { | ||
@Override | ||
public boolean check(final Player player) { | ||
return targetPlayers.check(e, new Checker<Player>() { | ||
@Override | ||
public boolean check(final Player targetPlayer) { | ||
return player.canSee(targetPlayer); | ||
} | ||
}, isNegated()); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event e, boolean debug) { | ||
return players.toString(e, debug) + (isNegated() ? " can't see " : " can see ") + targetPlayers.toString(e, debug); | ||
} | ||
|
||
} |
102 changes: 102 additions & 0 deletions
102
src/main/java/ch/njol/skript/effects/EffPlayerVisibility.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,102 @@ | ||
/** | ||
* 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 2011-2017 Peter Güttinger and contributors | ||
*/ | ||
package ch.njol.skript.effects; | ||
|
||
import ch.njol.skript.Skript; | ||
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.lang.Effect; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.SkriptParser; | ||
import ch.njol.skript.lang.util.SimpleLiteral; | ||
import ch.njol.skript.expressions.ExprHiddenPlayers; | ||
import ch.njol.util.Kleenean; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.plugin.Plugin; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.Event; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
|
||
@Name("Player Visibility") | ||
@Description({"Change visibility of a player for the given 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: if a player was hidden and relogs, this player will be visible again."}) | ||
@Examples({"on join:", | ||
" if {vanished::%player's uuid%} is true:", | ||
" hide the player from all players", | ||
"", | ||
"reveal hidden players of {_player}"}) | ||
@Since("INSERT VERSION") | ||
public class EffPlayerVisibility extends Effect { | ||
|
||
private static final boolean USE_DEPRECATED_METHOD = !Skript.methodExists(Player.class, "hidePlayer", Plugin.class, Player.class); | ||
|
||
static { | ||
Skript.registerEffect(EffPlayerVisibility.class, | ||
"hide %players% [(from|for) %-players%]", | ||
"reveal %players% [(to|for|from) %-players%]"); | ||
} | ||
|
||
@SuppressWarnings("null") | ||
private Expression<Player> players, targetPlayers; | ||
private boolean reveal; | ||
|
||
@SuppressWarnings({"unchecked", "null"}) | ||
@Override | ||
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { | ||
reveal = matchedPattern == 1; | ||
players = (Expression<Player>) exprs[0]; | ||
if (reveal && players instanceof ExprHiddenPlayers) | ||
targetPlayers = exprs.length > 1 ? (Expression<Player>) exprs[1] : ((ExprHiddenPlayers) players).getPlayers(); | ||
else | ||
targetPlayers = exprs.length > 1 ? (Expression<Player>) exprs[1] : null; | ||
return true; | ||
} | ||
|
||
@Override | ||
protected void execute(Event e) { | ||
Player[] targets = targetPlayers == null ? Bukkit.getOnlinePlayers().toArray(new Player[0]) : targetPlayers.getArray(e); | ||
for (Player targetPlayer : targets) { | ||
for (Player player : players.getArray(e)) { | ||
if (reveal) { | ||
if (USE_DEPRECATED_METHOD) | ||
targetPlayer.showPlayer(player); | ||
else | ||
targetPlayer.showPlayer(Skript.getInstance(), player); | ||
} else { | ||
if (USE_DEPRECATED_METHOD) | ||
targetPlayer.hidePlayer(player); | ||
else | ||
targetPlayer.hidePlayer(Skript.getInstance(), player); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event e, boolean debug) { | ||
return (reveal ? "show " : "hide ") + players.toString(e, debug) + (reveal ? " to " : " from ") + targetPlayers.toString(e, debug); | ||
} | ||
|
||
} |
91 changes: 91 additions & 0 deletions
91
src/main/java/ch/njol/skript/expressions/ExprHiddenPlayers.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,91 @@ | ||
/** | ||
* 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 2011-2017 Peter Güttinger and contributors | ||
*/ | ||
package ch.njol.skript.expressions; | ||
|
||
import java.util.List; | ||
import java.util.ArrayList; | ||
import ch.njol.skript.Skript; | ||
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.lang.SkriptParser; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.ExpressionType; | ||
import ch.njol.skript.lang.util.SimpleExpression; | ||
import ch.njol.util.Kleenean; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.Event; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
|
||
@Name("Hidden Players") | ||
@Description({"The players hidden from a player that hidden using the <a href='effects.html#EffPlayerVisibility'>player visibility</a> effect."}) | ||
@Examples({"message \"<light red>You are currently hiding: <light gray>%hidden players of the player%\""}) | ||
@Since("INSERT VERSION") | ||
public class ExprHiddenPlayers extends SimpleExpression<Player> { | ||
|
||
static { | ||
Skript.registerExpression(ExprHiddenPlayers.class, Player.class, ExpressionType.PROPERTY, | ||
"[(all [[of] the]|the)] hidden players (of|for) %players%", | ||
"[(all [[of] the]|the)] players hidden (from|for|by) %players%"); | ||
} | ||
|
||
@SuppressWarnings("null") | ||
private Expression<Player> players; | ||
|
||
@SuppressWarnings({"unchecked", "null"}) | ||
@Override | ||
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { | ||
players = (Expression<Player>) exprs[0]; | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isSingle() { | ||
return false; | ||
} | ||
|
||
@Override | ||
@Nullable | ||
public Player[] get(Event e) { | ||
List<Player> list = new ArrayList<>(); | ||
for (Player player : players.getArray(e)) { | ||
list.addAll(player.spigot().getHiddenPlayers()); | ||
} | ||
return list.toArray(new Player[list.size()]); | ||
} | ||
|
||
@Nullable | ||
public Expression<Player> getPlayers() { | ||
return players; | ||
} | ||
|
||
@Override | ||
public Class<? extends Player> getReturnType() { | ||
return Player.class; | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event e, boolean debug) { | ||
return "hidden players for " + players.toString(e, debug); | ||
} | ||
|
||
} |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import order