-
-
Notifications
You must be signed in to change notification settings - Fork 443
Adds ExprPlayerListOrder #8600
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
AnOwlBe
wants to merge
20
commits into
SkriptLang:dev/feature
Choose a base branch
from
AnOwlBe:ExprPlayerListOrder
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.
+92
−0
Open
Adds ExprPlayerListOrder #8600
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
0401164
Adds ExprPlayerListOrder
AnOwlBe ac008c8
Stuff
AnOwlBe 715c9c5
Changes `order` to `priority`
AnOwlBe 69fb531
Added more detail to the description
AnOwlBe 3c1da9e
Update src/main/java/org/skriptlang/skript/bukkit/entity/player/eleme…
AnOwlBe 23584db
Update src/main/java/org/skriptlang/skript/bukkit/entity/player/eleme…
AnOwlBe e7b247d
Adds `remove` & small change for `set`
AnOwlBe 937b42b
Adds `remove` & small change for `set`
AnOwlBe 527b60c
Adds `remove` & small change for `set`
AnOwlBe 1b4e06c
Merge remote-tracking branch 'origin/ExprPlayerListOrder' into ExprPl…
AnOwlBe dbfbdad
Update src/main/java/org/skriptlang/skript/bukkit/entity/player/eleme…
AnOwlBe 716bb28
Small changes
AnOwlBe 468a838
Merge remote-tracking branch 'origin/ExprPlayerListOrder' into ExprPl…
AnOwlBe 1ce3b5b
Small changes
AnOwlBe 1d1b471
Merge branch 'dev/feature' into ExprPlayerListOrder
AnOwlBe 67fddcc
Adds clamping for ADD to prevent integer overflow
AnOwlBe b90d06d
Update src/main/java/org/skriptlang/skript/bukkit/entity/player/eleme…
AnOwlBe 0e2b360
Merge branch 'dev/feature' into ExprPlayerListOrder
AnOwlBe 11ccbaa
Stuff
AnOwlBe 5e4c762
Merge remote-tracking branch 'origin/ExprPlayerListOrder' into ExprPl…
AnOwlBe 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 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
91 changes: 91 additions & 0 deletions
91
...g/skriptlang/skript/bukkit/entity/player/elements/expressions/ExprPlayerListPriority.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,91 @@ | ||
| package org.skriptlang.skript.bukkit.entity.player.elements.expressions; | ||
|
|
||
| import ch.njol.skript.classes.Changer.ChangeMode; | ||
| import ch.njol.skript.doc.Description; | ||
| import ch.njol.skript.doc.Example; | ||
| import ch.njol.skript.doc.Keywords; | ||
| import ch.njol.skript.doc.Name; | ||
| import ch.njol.skript.doc.Since; | ||
| import ch.njol.skript.expressions.base.SimplePropertyExpression; | ||
| import ch.njol.util.Math2; | ||
| import ch.njol.util.coll.CollectionUtils; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.event.Event; | ||
| import org.jetbrains.annotations.Nullable; | ||
| import org.skriptlang.skript.registration.SyntaxRegistry; | ||
|
|
||
| @Name("Player List Priority") | ||
| @Description(""" | ||
| The priority of the player in the player list in the tab menu. | ||
| Used to sort players on the tab list. Lowest priority is at the bottom of tab and highest priority is at the top. | ||
| If 2 players have same priority then they will be sorted A-Z (but still be above those with lower priority). | ||
| """) | ||
| @Example(""" | ||
| on join: | ||
| player has permission "group.mod" | ||
| set the player's tab list priority to 5 | ||
| """) | ||
| @Since("INSERT VERSION") | ||
| @Keywords({"tablist", "tab list"}) | ||
| public class ExprPlayerListPriority extends SimplePropertyExpression<Player, Integer> { | ||
|
|
||
| public static void register(SyntaxRegistry syntaxRegistry) { | ||
| syntaxRegistry.register(SyntaxRegistry.EXPRESSION, infoBuilder(ExprPlayerListPriority.class, Integer.class, | ||
| "(player|tab)[ ]list priority", "players", false) | ||
| .supplier(ExprPlayerListPriority::new) | ||
| .build()); | ||
| } | ||
|
|
||
| @Override | ||
| public Integer convert(Player player) { | ||
| return player.getPlayerListOrder(); | ||
| } | ||
|
|
||
| @Override | ||
| public Class<?> @Nullable [] acceptChange(ChangeMode mode) { | ||
| return switch (mode) { | ||
| case ADD, REMOVE, SET, RESET -> CollectionUtils.array(Integer.class); | ||
| default -> null; | ||
| }; | ||
| } | ||
|
|
||
| @Override | ||
| public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { | ||
| if (delta == null && mode != ChangeMode.RESET) return; | ||
| Integer amount = mode == ChangeMode.RESET ? 0 : (Integer) delta[0]; | ||
| switch (mode) { | ||
| case ADD -> { | ||
| for (Player player : getExpr().getArray(event)) { | ||
| player.setPlayerListOrder((int) Math.max(0, Math2.addClamped(player.getPlayerListOrder(), amount))); | ||
| } | ||
| } | ||
| case REMOVE -> { | ||
| for (Player player : getExpr().getArray(event)) { | ||
| player.setPlayerListOrder(Math.max(0,player.getPlayerListOrder() - amount)); | ||
| } | ||
| } | ||
| case SET -> { | ||
| amount = Math.max(0, amount); | ||
| for (Player player : getExpr().getArray(event)) { | ||
| player.setPlayerListOrder(amount); | ||
| } | ||
| } | ||
| case RESET -> { | ||
| for (Player player : getExpr().getArray(event)) { | ||
| player.setPlayerListOrder(0); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public Class<Integer> getReturnType() { | ||
| return Integer.class; | ||
| } | ||
|
|
||
| @Override | ||
| protected String getPropertyName() { | ||
| return "player list priority"; | ||
| } | ||
|
|
||
| } | ||
|
AnOwlBe marked this conversation as resolved.
|
||
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.