wip: code cleanup
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package eu.mhsl.minecraft.pixelblocks;
|
||||
|
||||
import eu.mhsl.minecraft.pixelblocks.pixelblock.PixelBlock;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class PixelBlockItem {
|
||||
public static @NotNull ItemStack getBlockAsItem(@NotNull PixelBlock block) {
|
||||
ItemStack itemStack = ItemStack.of(Material.GRAY_STAINED_GLASS);
|
||||
String ownerName = Optional.ofNullable(Bukkit.getOfflinePlayer(block.ownerUUID).getName()).orElseGet(() -> block.ownerUUID.toString());
|
||||
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
meta.itemName(Component.text(block.blockUUID.toString()));
|
||||
meta.displayName(Component.text("Pixelblock von " + ownerName));
|
||||
meta.setEnchantmentGlintOverride(true);
|
||||
itemStack.setItemMeta(meta);
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public static @NotNull ItemStack getEmptyPixelBlock() {
|
||||
ItemStack item = ItemStack.of(Material.GRAY_STAINED_GLASS);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.displayName(Component.text("Leerer Pixelblock"));
|
||||
meta.setEnchantmentGlintOverride(true);
|
||||
meta.itemName(Component.text("Pixelblock"));
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static @NotNull Recipe getRecipe() {
|
||||
NamespacedKey key = new NamespacedKey(PixelBlocksPlugin.plugin, "pixelblock");
|
||||
ShapedRecipe recipe = new ShapedRecipe(key, getEmptyPixelBlock());
|
||||
recipe.shape("ABA", "BCB", "ABA");
|
||||
recipe.setIngredient('A', Material.DIAMOND_BLOCK);
|
||||
recipe.setIngredient('B', Material.EMERALD_BLOCK);
|
||||
recipe.setIngredient('C', Material.GRAY_STAINED_GLASS);
|
||||
return recipe;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user