changed pixelblock item and added item to recipe book
This commit is contained in:
parent
2ad3f135c3
commit
e35145f8ed
@ -18,7 +18,7 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly "io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT"
|
||||
compileOnly "io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT"
|
||||
}
|
||||
|
||||
def targetJavaVersion = 21
|
||||
@ -47,3 +47,10 @@ processResources {
|
||||
expand props
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register('copyJarToTestServer', Exec) {
|
||||
dependsOn jar
|
||||
mustRunAfter jar
|
||||
|
||||
commandLine 'cp', 'build/libs/PixelBlocks-1.0-SNAPSHOT.jar', '/home/elias/Dokumente/mcTestServer/plugins/pixelblocks.jar'
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package eu.mhsl.minecraft.pixelblocks;
|
||||
|
||||
import eu.mhsl.minecraft.pixelblocks.pixelblock.PixelBlock;
|
||||
import eu.mhsl.minecraft.pixelblocks.utils.HeadUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -18,14 +19,13 @@ import java.util.UUID;
|
||||
|
||||
public class PixelBlockItem {
|
||||
public static UUID unusedBlockID = UUID.fromString("98fdf0ae-c3ab-4ef7-ae25-efd518d600de");
|
||||
public static final String itemTexture = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzE5NGU5ZTc3NTdkMDZkNmY1ZTViZTg0NTQ4YTdjYjUyMTczZDY4Y2NmODAyZDIxMTI3NWQzMWNkYmEwYTA2ZSJ9fX0=";
|
||||
public static final NamespacedKey recipeKey = new NamespacedKey(PixelBlocksPlugin.plugin, "pixelblock");
|
||||
|
||||
public static @NotNull ItemStack getBlockAsItem(@NotNull PixelBlock block) {
|
||||
return PixelBlockItem.updateBlockAsItem(block, ItemStack.of(Material.GRAY_STAINED_GLASS));
|
||||
}
|
||||
|
||||
public static @NotNull ItemStack updateBlockAsItem(@NotNull PixelBlock block, @NotNull ItemStack itemStack) {
|
||||
String ownerName = Optional.ofNullable(Bukkit.getOfflinePlayer(block.ownerUUID).getName()).orElseGet(() -> block.ownerUUID.toString());
|
||||
|
||||
ItemStack itemStack = HeadUtil.getCustomTextureHead(itemTexture);
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
meta.itemName(Component.text(block.blockUUID.toString()));
|
||||
meta.displayName(Component.text("Pixelblock von " + ownerName));
|
||||
@ -41,11 +41,11 @@ public class PixelBlockItem {
|
||||
}
|
||||
|
||||
public static @NotNull ItemStack getEmptyPixelBlock() {
|
||||
ItemStack item = ItemStack.of(Material.GRAY_STAINED_GLASS);
|
||||
ItemStack item = HeadUtil.getCustomTextureHead(itemTexture);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.displayName(Component.text("Leerer Pixelblock"));
|
||||
meta.lore(List.of(
|
||||
Component.text("Der erste Spieler, welcher den Block platziert wird der Besitzer des Blocks."),
|
||||
Component.text("Der erste Spieler, der den Block platziert wird zum Besitzer des Blocks."),
|
||||
Component.text("Klicke auf den gesetzten Block, um diesen zu bearbeiten!")
|
||||
));
|
||||
meta.setEnchantmentGlintOverride(true);
|
||||
@ -55,12 +55,13 @@ public class PixelBlockItem {
|
||||
}
|
||||
|
||||
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);
|
||||
ShapedRecipe recipe = new ShapedRecipe(recipeKey, getEmptyPixelBlock());
|
||||
recipe.shape("AEA", "BCB", "DDD");
|
||||
recipe.setIngredient('A', Material.GLASS);
|
||||
recipe.setIngredient('B', Material.DIAMOND_BLOCK);
|
||||
recipe.setIngredient('C', Material.HEART_OF_THE_SEA);
|
||||
recipe.setIngredient('D', Material.GRASS_BLOCK);
|
||||
recipe.setIngredient('E', Material.GLOW_BERRIES);
|
||||
return recipe;
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +59,8 @@ public final class PixelBlocksPlugin extends JavaPlugin {
|
||||
new PreventHopperActionsListener(),
|
||||
new PreventLiquidsFlowListener(),
|
||||
new PreventPistonsListener(),
|
||||
new PreventEntityPlacementListener()
|
||||
new PreventEntityPlacementListener(),
|
||||
new DiscoverRecipesListener()
|
||||
};
|
||||
|
||||
for (Listener listener : listeners) {
|
||||
|
@ -0,0 +1,26 @@
|
||||
package eu.mhsl.minecraft.pixelblocks.listeners;
|
||||
|
||||
import eu.mhsl.minecraft.pixelblocks.PixelBlockItem;
|
||||
import eu.mhsl.minecraft.pixelblocks.PixelBlocksPlugin;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.*;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class DiscoverRecipesListener implements Listener {
|
||||
@EventHandler
|
||||
public void shouldDiscover(InventoryClickEvent event) {
|
||||
ItemStack clickedItem = event.getCurrentItem();
|
||||
if(clickedItem == null) return;
|
||||
if(!List.of(Material.HEART_OF_THE_SEA, Material.GLOW_BERRIES).contains(clickedItem.getType())) return;
|
||||
if(!(event.getWhoClicked() instanceof Player player)) return;
|
||||
if(player.hasDiscoveredRecipe(PixelBlockItem.recipeKey)) return;
|
||||
PixelBlocksPlugin.plugin.getLogger().log(Level.INFO, String.format("%s unlocked tne PixelBlock recipe!", player.getName()));
|
||||
player.discoverRecipe(PixelBlockItem.recipeKey);
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package eu.mhsl.minecraft.pixelblocks.utils;
|
||||
|
||||
import com.destroystokyo.paper.profile.PlayerProfile;
|
||||
import com.destroystokyo.paper.profile.ProfileProperty;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class HeadUtil {
|
||||
public static ItemStack getCustomTextureHead(String base64) {
|
||||
ItemStack head = new ItemStack(Material.PLAYER_HEAD);
|
||||
SkullMeta meta = (SkullMeta) head.getItemMeta();
|
||||
PlayerProfile profile = Bukkit.createProfile(UUID.randomUUID(), "");
|
||||
profile.setProperty(new ProfileProperty("textures", base64));
|
||||
meta.setPlayerProfile(profile);
|
||||
head.setItemMeta(meta);
|
||||
return head;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user