-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from liquip/feat/features
Add new feature to set texture of skulls
- Loading branch information
Showing
3 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
44 changes: 44 additions & 0 deletions
44
...src/main/java/io/github/liquip/paper/core/item/feature/minecraft/SkullTextureFeature.java
This file contains 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,44 @@ | ||
package io.github.liquip.paper.core.item.feature.minecraft; | ||
|
||
import com.destroystokyo.paper.profile.PlayerProfile; | ||
import com.destroystokyo.paper.profile.ProfileProperty; | ||
import io.github.liquip.api.config.ConfigElement; | ||
import io.github.liquip.api.item.Item; | ||
import io.github.liquip.api.item.TaggedFeature; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.NamespacedKey; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.inventory.meta.SkullMeta; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.UUID; | ||
|
||
public class SkullTextureFeature implements TaggedFeature<String> { | ||
private final NamespacedKey key = new NamespacedKey("minecraft", "skull_texture"); | ||
|
||
@Override | ||
public @NotNull NamespacedKey getKey() { | ||
return this.key; | ||
} | ||
|
||
@Override | ||
public @Nullable String initialize(@NonNull Item item, @NonNull ConfigElement element) { | ||
if (!element.isString()) { | ||
return null; | ||
} | ||
return element.asString(); | ||
} | ||
|
||
@Override | ||
public void apply(@NonNull Item item, @NonNull ItemStack itemStack, @NonNull String object) { | ||
itemStack.editMeta(it -> { | ||
if (it instanceof SkullMeta meta) { | ||
final PlayerProfile profile = Bukkit.createProfile(UUID.randomUUID()); | ||
profile.setProperty(new ProfileProperty("textures", object)); | ||
meta.setPlayerProfile(profile); | ||
} | ||
}); | ||
} | ||
} |
This file contains 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