API 정리

2025. 4. 14. 23:23마인크래프트

Inventory에 Item 넣기

    public void giveMonsterBlock(Player player, String mobName) {
        ItemStack block = new ItemStack(Material.IRON_BLOCK);
        ItemMeta meta = block.getItemMeta();
        if (meta != null) {
            meta.setDisplayName(ChatColor.GREEN + mobName);
            meta.setLore(Collections.singletonList(ChatColor.GRAY + "Place to summon a " + mobName));
            meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
            block.setItemMeta(meta);
        }
        player.getInventory().addItem(block);
    }

Item 만들기 추가

	private void registerGuardianBlockRecipe() {
	    // ✅ Zombie Guardian Recipe
	    ItemStack zombieBlock = new ItemStack(Material.IRON_BLOCK);
	    ItemMeta zMeta = zombieBlock.getItemMeta();
	    if (zMeta != null) {
	        zMeta.setDisplayName(ChatColor.GREEN + "Zombie");
	        zMeta.setLore(Collections.singletonList(ChatColor.GRAY + "Place to summon a Zombie guardian"));
	        zombieBlock.setItemMeta(zMeta);
	    }

	    NamespacedKey zKey = new NamespacedKey(this, "zombie_guardian_block");
	    ShapedRecipe zRecipe = new ShapedRecipe(zKey, zombieBlock);
	    zRecipe.shape("RRR", "RDR", "RRR");
	    zRecipe.setIngredient('R', Material.ROTTEN_FLESH);
	    zRecipe.setIngredient('D', Material.DIAMOND);
	    Bukkit.addRecipe(zRecipe);
}

명령어 추가

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (label.equalsIgnoreCase("hello")) {
            sender.sendMessage("Hello, world!");
            return true;
        }
        
        if (label.equalsIgnoreCase("mobblock") && sender instanceof Player player) {
            if (args.length == 1) {
                giveMonsterBlock(player, args[0]);
                player.sendMessage(ChatColor.YELLOW + "You received a " + args[0] + " block.");
            } else {
                player.sendMessage(ChatColor.RED + "Usage: /mobblock <mob>");
            }
            return true;
        }
        return false;
    }

'마인크래프트' 카테고리의 다른 글

NMS 추가  (1) 2025.05.04
Plugin 동적으로 적용하기  (0) 2025.05.03
Minecraft OST  (0) 2025.03.29
몹의 공격 데미지가 0이되게 하기  (0) 2025.03.28
좀비 소환  (0) 2025.03.27