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

Rework entity visibility #6867

Merged
merged 27 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
99d8dad
init commit
Efnilite Jul 4, 2024
a062c45
fixes
Efnilite Jul 5, 2024
ef1f1b9
minor fixes
Efnilite Jul 5, 2024
872d4e6
oops
Efnilite Jul 5, 2024
f246a10
fixed formatting
Efnilite Jul 5, 2024
46204b0
replace player hiding with entity hiding
Efnilite Jul 5, 2024
4f1d87d
update hidden players
Efnilite Jul 5, 2024
13c9a81
fixed shane stuff
Efnilite Jul 5, 2024
671bb9d
oops
Efnilite Jul 5, 2024
f83885b
Apply suggestions from code review
Efnilite Jul 6, 2024
3dee858
fixed versions
Efnilite Jul 6, 2024
2e48789
fixed ParseResult import
Efnilite Jul 6, 2024
8f11231
added can see test
Efnilite Jul 6, 2024
8859cd6
fixed review stuff
Efnilite Jul 7, 2024
0b5a765
updated var, param names
Efnilite Jul 13, 2024
7a7f3e0
updated CondCanSeeTest
Efnilite Jul 18, 2024
e05fda2
fixed space
Efnilite Jul 19, 2024
80ce215
fixes
Efnilite Jul 21, 2024
66d29ec
Update src/main/java/ch/njol/skript/conditions/CondCanSee.java
Efnilite Aug 17, 2024
e08eaec
Merge branch 'dev/feature' into visibility
Efnilite Aug 24, 2024
a2f12d1
Merge branch 'dev/feature' into visibility
Moderocky Aug 30, 2024
34af419
Merge branch 'dev/feature' into visibility
Moderocky Aug 30, 2024
45d7790
Update src/test/java/org/skriptlang/skript/test/tests/syntaxes/effect…
Efnilite Sep 1, 2024
56794b8
Update src/test/java/org/skriptlang/skript/test/tests/syntaxes/condit…
Efnilite Sep 1, 2024
b48bb81
update invisibility tag
Efnilite Sep 1, 2024
8bda88c
Merge remote-tracking branch 'origin/visibility' into visibility
Efnilite Sep 1, 2024
59fe469
Merge branch 'dev/feature' into visibility
Efnilite Oct 13, 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
85 changes: 35 additions & 50 deletions src/main/java/ch/njol/skript/conditions/CondCanSee.java
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.eclipse.jdt.annotation.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.*;
sovdeeth marked this conversation as resolved.
Show resolved Hide resolved
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 \"&lt;light red&gt;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) [:in]visible for %players%",
"%players% can see %entities%",
"%entities% (is|are)(n't| not) [:in]visible 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;
Efnilite marked this conversation as resolved.
Show resolved Hide resolved

@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("in"));
Efnilite marked this conversation as resolved.
Show resolved Hide resolved
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 src/main/java/ch/njol/skript/effects/EffEntityVisibility.java
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.*;
Efnilite marked this conversation as resolved.
Show resolved Hide resolved
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();
sovdeeth marked this conversation as resolved.
Show resolved Hide resolved
} 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 src/main/java/ch/njol/skript/effects/EffPlayerVisibility.java

This file was deleted.

Loading