-
-
Notifications
You must be signed in to change notification settings - Fork 405
Feature/players listed #8101
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
Open
TheLimeGlass
wants to merge
13
commits into
SkriptLang:dev/feature
Choose a base branch
from
TheLimeGlass:feature/players-listed
base: dev/feature
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feature/players listed #8101
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2a93632
Adds tablisted view players
TheLimeGlass 87ed44e
Add the to the syntax because of 2.12 conflictions
TheLimeGlass 344f49c
requested changes
TheLimeGlass beaf294
Add keywords
TheLimeGlass aed2ce5
requested changes
TheLimeGlass 09ec8b7
requested changes
TheLimeGlass 46e22b5
Remove 1.19.4 method checks
TheLimeGlass 60d11de
Remove 1.19.4 method checks
TheLimeGlass 4e1388b
Update src/main/java/ch/njol/skript/expressions/ExprTablistedPlayers.…
TheLimeGlass 4ef525c
Merge branch 'dev/feature' into feature/players-listed
Absolutionism 6f18134
Update src/main/java/ch/njol/skript/expressions/ExprTablistedPlayers.…
TheLimeGlass 6fa987e
Update src/main/java/ch/njol/skript/expressions/ExprTablistedPlayers.…
TheLimeGlass 5331716
Update src/main/java/ch/njol/skript/expressions/ExprTablistedPlayers.…
TheLimeGlass 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
125 changes: 125 additions & 0 deletions
125
src/main/java/ch/njol/skript/expressions/ExprListedPlayers.java
This file contains hidden or 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,125 @@ | ||
package ch.njol.skript.expressions; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.Event; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.classes.Changer.ChangeMode; | ||
import ch.njol.skript.doc.Description; | ||
import ch.njol.skript.doc.Examples; | ||
import ch.njol.skript.doc.Keywords; | ||
import ch.njol.skript.doc.Name; | ||
import ch.njol.skript.doc.RequiredPlugins; | ||
import ch.njol.skript.doc.Since; | ||
import ch.njol.skript.expressions.base.PropertyExpression; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
import ch.njol.util.Kleenean; | ||
import ch.njol.util.coll.CollectionUtils; | ||
|
||
@Name("Tablisted Players") | ||
@Description({ | ||
"The displayed players in the tablist for selected players.", | ||
"Delete changer will remove all the online players.", | ||
"Reset changer will reset the tablist to a default state viewing all the players again." | ||
}) | ||
@Examples("tablist players of player") | ||
@RequiredPlugins("Paper 1.20.1+") | ||
@Since("INSERT VERSION") | ||
@Keywords("tablist") | ||
public class ExprListedPlayers extends PropertyExpression<Player, Player> { | ||
|
||
static { | ||
if (Skript.methodExists(Player.class, "isListed", Player.class)) { | ||
registerDefault(ExprListedPlayers.class, Player.class, "[the] (tablist[ed]|listed) players", "players"); | ||
} | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||
setExpr((Expression<Player>) expressions[0]); | ||
return true; | ||
} | ||
|
||
@Override | ||
protected Player[] get(Event event, Player[] source) { | ||
return Arrays.stream(source) | ||
.flatMap(viewer -> Bukkit.getOnlinePlayers().stream().filter(viewer::isListed)) | ||
.toArray(Player[]::new); | ||
} | ||
|
||
@Override | ||
public Class<?>[] acceptChange(ChangeMode mode) { | ||
return CollectionUtils.array(Player[].class); | ||
} | ||
|
||
@Override | ||
public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { | ||
Player[] recipients = (Player[]) delta; | ||
Player[] viewers = getExpr().getArray(event); | ||
switch (mode) { | ||
case DELETE: | ||
recipients = Bukkit.getOnlinePlayers().toArray(Player[]::new); | ||
// $fallthrough | ||
case REMOVE: | ||
for (Player viewer : viewers) { | ||
for (Player player : recipients) { | ||
viewer.unlistPlayer(player); | ||
} | ||
} | ||
break; | ||
case SET: | ||
for (Player viewer : viewers) { | ||
for (Player player : Bukkit.getOnlinePlayers()) { | ||
if (Arrays.stream(recipients).noneMatch(recipient -> recipient.equals(player))) { | ||
// If the player is not in the recipients, unlist them | ||
viewer.unlistPlayer(player); | ||
} | ||
} | ||
} | ||
// $fallthrough | ||
case ADD: | ||
assert recipients != null; | ||
for (Player viewer : viewers) { | ||
for (Player player : recipients) { | ||
if (viewer.canSee(player)) { | ||
viewer.listPlayer(player); | ||
} | ||
} | ||
} | ||
break; | ||
case RESET: | ||
for (Player viewer : viewers) { | ||
for (Player player : Bukkit.getOnlinePlayers()) { | ||
if (!viewer.isListed(player) && viewer.canSee(player)) { | ||
viewer.listPlayer(player); | ||
} | ||
} | ||
} | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isSingle() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Class<? extends Player> getReturnType() { | ||
return Player.class; | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event event, boolean debug) { | ||
return "tablisted players of " + getExpr().toString(event, debug); | ||
} | ||
|
||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.