Skip to content

Commit

Permalink
Merge pull request #31 from liquip/feat/features
Browse files Browse the repository at this point in the history
Add new feature to set texture of skulls
  • Loading branch information
sqyyy-jar authored Jan 3, 2023
2 parents 6773d03 + 1f7579e commit 756e158
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
allprojects {
group = "io.github.liquip"
version = "2.0.2-beta"
version = "2.1.0-beta"

repositories {
mavenCentral()
Expand Down
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);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.github.liquip.paper.core.item.feature.minecraft.HidePotionEffectsFeature;
import io.github.liquip.paper.core.item.feature.minecraft.HideUnbreakableFeature;
import io.github.liquip.paper.core.item.feature.minecraft.LeatherDyeFeature;
import io.github.liquip.paper.core.item.feature.minecraft.SkullTextureFeature;
import io.github.liquip.paper.core.item.feature.minecraft.UnbreakableFeature;
import io.github.liquip.paper.core.listener.BlockEventListener;
import io.github.liquip.paper.core.listener.EntityEventListener;
Expand Down Expand Up @@ -302,6 +303,8 @@ private void registerMinecraftFeatures() {
this.taggedFeatureRegistry.register(customModelDataFeature.getKey(), customModelDataFeature);
final LeatherDyeFeature leatherDyeFeature = new LeatherDyeFeature();
this.taggedFeatureRegistry.register(leatherDyeFeature.getKey(), leatherDyeFeature);
final SkullTextureFeature skullTextureFeature = new SkullTextureFeature();
this.taggedFeatureRegistry.register(skullTextureFeature.getKey(), skullTextureFeature);
}

private void registerBukkitEnchantments() {
Expand Down

0 comments on commit 756e158

Please sign in to comment.