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

Add player visibility stuff #1302

Merged
merged 14 commits into from
Jul 17, 2018
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ repositories {
}

dependencies {
implementation 'com.destroystokyo.paper:paper-api:1.12.1-R0.1-SNAPSHOT'
implementation 'com.destroystokyo.paper:paper-api:1.12.2-R0.1-SNAPSHOT'
implementation 'org.eclipse.jdt:org.eclipse.jdt.annotation:1.1.0'
implementation 'com.google.code.findbugs:findbugs:2.0.3'
implementation 'com.sk89q:worldguard:6.1.1-SNAPSHOT'
Expand Down
88 changes: 88 additions & 0 deletions src/main/java/ch/njol/skript/conditions/CondCanSee.java
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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import order

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 src/main/java/ch/njol/skript/effects/EffPlayerVisibility.java
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 src/main/java/ch/njol/skript/expressions/ExprHiddenPlayers.java
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);
}

}
7 changes: 6 additions & 1 deletion src/main/java/ch/njol/skript/util/BlockStateBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,12 @@ public BlockFace getFace(final Block block) {
public BlockState getState() {
return state;
}


@Override
public BlockState getState(boolean useSnapshot) {
return state;
}

@Override
public Biome getBiome() {
return state.getBlock().getBiome();
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/ch/njol/skript/util/DelayedChangeBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ public BlockFace getFace(final Block block) {
@Override
public BlockState getState() {
return b.getState();
}

@Override
public BlockState getState(boolean useSnapshot) {
return b.getState(useSnapshot);
}

@Override
Expand Down