-
-
Notifications
You must be signed in to change notification settings - Fork 443
Expression for Skull Texture #8500
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
8
commits into
SkriptLang:dev/feature
Choose a base branch
from
AnOwlBe:feature/ExprSkullTexture
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.
+120
−1
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e8290d8
E
AnOwlBe ca23a0c
Some Code Convention fixes
AnOwlBe e1d2166
Merge branch 'dev/feature' into feature/ExprSkullTexture
AnOwlBe d6cd790
Fixed some things changed to use 2.15's syntaxRegistry
AnOwlBe 0a64ffd
Small changes
AnOwlBe 0f3b83f
Fixes
AnOwlBe 971e50a
Small changes
AnOwlBe 8e41b0a
Adds tests
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
112 changes: 112 additions & 0 deletions
112
src/main/java/org/skriptlang/skript/bukkit/misc/elements/expressions/ExprSkullTexture.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,112 @@ | ||
| package org.skriptlang.skript.bukkit.misc.elements.expressions; | ||
|
|
||
| import ch.njol.skript.aliases.ItemType; | ||
| import ch.njol.skript.classes.Changer.ChangeMode; | ||
| import ch.njol.skript.doc.Description; | ||
| import ch.njol.skript.doc.Example; | ||
| import ch.njol.skript.doc.Name; | ||
| import ch.njol.skript.doc.Since; | ||
| import ch.njol.skript.expressions.base.SimplePropertyExpression; | ||
| import ch.njol.util.coll.CollectionUtils; | ||
|
|
||
| import com.destroystokyo.paper.profile.ProfileProperty; | ||
| import org.bukkit.Bukkit; | ||
| import org.bukkit.Material; | ||
| import org.bukkit.event.Event; | ||
| import org.bukkit.inventory.meta.SkullMeta; | ||
| import com.destroystokyo.paper.profile.PlayerProfile; | ||
| import org.jetbrains.annotations.Nullable; | ||
| import org.skriptlang.skript.registration.SyntaxInfo; | ||
| import org.skriptlang.skript.registration.SyntaxRegistry; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| @Name("Skull Texture") | ||
| @Description(""" | ||
| The skull texture of a player head. | ||
| Allows you to give a skull a custom texture (e.g. instead of it being a Steve head, it's Notch's head). | ||
| For the %string% you input a base64 string (think of it like the ID/texture so Minecraft knows what the head should look like). | ||
| (The most common place to get a base64 string is https://minecraft-heads.com) | ||
| Resetting the texture of a skull will make it look like a Steve/Alex head. | ||
| """) | ||
| @Example("set the skull texture of {_i} to \"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNTM4NmRmZDc0Y2JhZmJkMWRiZTQ3OWY1ZTAzNzRjMDliZjJlYjRlMzg2NjExZmM0ZmM2OTlmMDJlY2E0ZGQyYyJ9fX0=\"") | ||
| @Since("INSERT VERSION") | ||
| public class ExprSkullTexture extends SimplePropertyExpression<ItemType, String> { | ||
|
|
||
| public static void register(SyntaxRegistry syntaxRegistry) { | ||
| syntaxRegistry.register(SyntaxRegistry.EXPRESSION, | ||
| infoBuilder(ExprSkullTexture.class, String.class, "skull texture", "itemtypes", false) | ||
| .supplier(ExprSkullTexture::new) | ||
| .priority(SyntaxInfo.SIMPLE) | ||
| .addPattern("[the] (skull|head) texture [of] %itemtypes%") | ||
| .build()); | ||
| } | ||
|
|
||
| @Override | ||
| public Class<?> @Nullable [] acceptChange(ChangeMode mode) { | ||
| return switch (mode) { | ||
| case SET -> CollectionUtils.array(String.class); | ||
| case DELETE, RESET -> CollectionUtils.array(); | ||
| default -> null; | ||
| }; | ||
| } | ||
|
|
||
| @Override | ||
|
AnOwlBe marked this conversation as resolved.
|
||
| public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { | ||
| String value = delta == null ? null : (String) delta[0]; | ||
| switch (mode) { | ||
| case DELETE, RESET: | ||
|
AnOwlBe marked this conversation as resolved.
|
||
| for (ItemType item : getExpr().getArray(event)) { | ||
| if (item.getMaterial() != Material.PLAYER_HEAD) { | ||
| continue; | ||
| } | ||
| SkullMeta meta = (SkullMeta) item.getItemMeta(); | ||
| meta.setPlayerProfile(null); | ||
| item.setItemMeta(meta); | ||
| } | ||
| break; | ||
| case SET: | ||
| for (ItemType item : getExpr().getArray(event)) { | ||
| if (item.getMaterial() != Material.PLAYER_HEAD) { | ||
| continue; | ||
| } | ||
| SkullMeta meta = (SkullMeta) item.getItemMeta(); | ||
| PlayerProfile playerProfile = Bukkit.createProfile(UUID.randomUUID()); | ||
| playerProfile.setProperty(new ProfileProperty("textures", value)); | ||
| meta.setPlayerProfile(playerProfile); | ||
| item.setItemMeta(meta); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public @Nullable String convert(ItemType item) { | ||
| if (item.getMaterial() != Material.PLAYER_HEAD) { | ||
| return null; | ||
| } | ||
| SkullMeta meta = (SkullMeta) item.getItemMeta(); | ||
| PlayerProfile profile = meta.getPlayerProfile(); | ||
| if (profile == null) { | ||
| return null; | ||
| } | ||
| ProfileProperty texture = profile.getProperties().stream() | ||
| .filter(property -> property.getName().equals("textures")) | ||
| .findFirst() | ||
| .orElse(null); | ||
| if (!(texture == null)) { | ||
| return texture.getValue(); | ||
|
sovdeeth marked this conversation as resolved.
|
||
| } else { | ||
| return null; | ||
| } | ||
|
AnOwlBe marked this conversation as resolved.
|
||
| } | ||
|
|
||
| @Override | ||
| public Class<? extends String> getReturnType() { | ||
| return String.class; | ||
| } | ||
|
|
||
| @Override | ||
| protected String getPropertyName() { | ||
| return "skull texture"; | ||
| } | ||
| } | ||
6 changes: 6 additions & 0 deletions
6
src/test/skript/tests/syntaxes/expressions/ExprSkullTexture.sk
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,6 @@ | ||
| test "skull texture": | ||
| set {_head} to player head | ||
| set skull texture of {_head} to "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNTM4NmRmZDc0Y2JhZmJkMWRiZTQ3OWY1ZTAzNzRjMDliZjJlYjRlMzg2NjExZmM0ZmM2OTlmMDJlY2E0ZGQyYyJ9fX0=" | ||
| assert skull texture of {_head} is "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNTM4NmRmZDc0Y2JhZmJkMWRiZTQ3OWY1ZTAzNzRjMDliZjJlYjRlMzg2NjExZmM0ZmM2OTlmMDJlY2E0ZGQyYyJ9fX0=" with "skull texture should be set" | ||
| reset skull texture of {_head} | ||
| assert skull texture of {_head} is not set with "skull texture should be reset" |
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.