Search in sources :

Example 1 with ItemBuilder

use of com.voxelgameslib.voxelgameslib.utils.ItemBuilder in project VoxelGamesLibv2 by VoxelGamesLib.

the class EditMode method gui.

@Subcommand("gui")
@CommandPermission("%admin")
public void gui(@Nonnull User sender) {
    if (editMode.contains(sender.getUuid())) {
        // TODO implement paginated invs
        InventoryMenuBuilder builder = new InventoryMenuBuilder().withSize(9).withTitle(Lang.legacy(LangKey.INV_MARKER));
        for (int i = 0; i < mapHandler.getMarkerDefinitions().size(); i++) {
            MarkerDefinition markerDefinition = mapHandler.getMarkerDefinitions().get(i);
            ItemStack is = new ItemBuilder(Material.SKULL_ITEM).durability(3).name(markerDefinition.getPrefix()).meta((itemMeta -> {
                char prefix = markerDefinition.getPrefix().toUpperCase().charAt(0);
                Skin skin = textureHandler.getSkin(prefix + "").orElseThrow(() -> new VoxelGameLibException("Unknown skull " + prefix));
                ((SkullMeta) itemMeta).setPlayerProfile(textureHandler.getPlayerProfile(skin));
                ((SkullMeta) itemMeta).setOwner(markerDefinition.getPrefix());
            })).build();
            builder.withItem(i, is, (player, clickType, itemStack) -> sender.getPlayer().performCommand("editmode skull " + itemStack.getItemMeta().getDisplayName()), ClickType.LEFT);
        }
        builder.show(sender.getPlayer());
    } else {
        Lang.msg(sender, LangKey.EDITMODE_NOT_ENABLED);
    }
}
Also used : ItemBuilder(com.voxelgameslib.voxelgameslib.utils.ItemBuilder) InventoryMenuBuilder(org.inventivetalent.menubuilder.inventory.InventoryMenuBuilder) VoxelGameLibException(com.voxelgameslib.voxelgameslib.exception.VoxelGameLibException) Skin(org.mineskin.data.Skin) SkullMeta(org.bukkit.inventory.meta.SkullMeta) ItemStack(org.bukkit.inventory.ItemStack) MarkerDefinition(com.voxelgameslib.voxelgameslib.map.MarkerDefinition) Subcommand(co.aikar.commands.annotation.Subcommand) CommandPermission(co.aikar.commands.annotation.CommandPermission)

Example 2 with ItemBuilder

use of com.voxelgameslib.voxelgameslib.utils.ItemBuilder in project VoxelGamesLibv2 by VoxelGamesLib.

the class EditMode method skull.

@Subcommand("skull")
@CommandPermission("%admin")
@Syntax("<name> - the name of the skull")
public void skull(@Nonnull User sender, @Nonnull String name) {
    if (editMode.contains(sender.getUuid())) {
        ItemStack skull = new ItemBuilder(Material.SKULL_ITEM).durability(3).name(name).meta((itemMeta -> {
            char prefix = name.toUpperCase().charAt(0);
            Skin skin = textureHandler.getSkin(prefix + "").orElseThrow(() -> new VoxelGameLibException("Unknown skull " + prefix));
            ((SkullMeta) itemMeta).setPlayerProfile(textureHandler.getPlayerProfile(skin));
            ((SkullMeta) itemMeta).setOwner(name);
        })).build();
        sender.getPlayer().getInventory().setItemInMainHand(skull);
    } else {
        Lang.msg(sender, LangKey.EDITMODE_NOT_ENABLED);
    }
}
Also used : ItemBuilder(com.voxelgameslib.voxelgameslib.utils.ItemBuilder) VoxelGameLibException(com.voxelgameslib.voxelgameslib.exception.VoxelGameLibException) Skin(org.mineskin.data.Skin) SkullMeta(org.bukkit.inventory.meta.SkullMeta) ItemStack(org.bukkit.inventory.ItemStack) Subcommand(co.aikar.commands.annotation.Subcommand) Syntax(co.aikar.commands.annotation.Syntax) CommandPermission(co.aikar.commands.annotation.CommandPermission)

Example 3 with ItemBuilder

use of com.voxelgameslib.voxelgameslib.utils.ItemBuilder in project VoxelGamesLibv2 by VoxelGamesLib.

the class EditMode method chest.

@Subcommand("chest")
@CommandPermission("%admin")
@Syntax("<name> - the name of the chest")
public void chest(@Nonnull User sender, @Nonnull String name) {
    if (editMode.contains(sender.getUuid())) {
        ItemStack chest = new ItemBuilder(Material.CHEST).name(name).build();
        sender.getPlayer().getInventory().setItemInMainHand(chest);
    } else {
        Lang.msg(sender, LangKey.EDITMODE_NOT_ENABLED);
    }
}
Also used : ItemBuilder(com.voxelgameslib.voxelgameslib.utils.ItemBuilder) ItemStack(org.bukkit.inventory.ItemStack) Subcommand(co.aikar.commands.annotation.Subcommand) Syntax(co.aikar.commands.annotation.Syntax) CommandPermission(co.aikar.commands.annotation.CommandPermission)

Example 4 with ItemBuilder

use of com.voxelgameslib.voxelgameslib.utils.ItemBuilder in project VoxelGamesLibv2 by VoxelGamesLib.

the class KitHandler method enable.

@Override
public void enable() {
    if (!kitsDir.exists()) {
        log.info("Kits dir doesn't exist, creating....");
        kitsDir.mkdirs();
    }
    File[] files = kitsDir.listFiles();
    if (files != null) {
        for (File file : files) {
            if (file.getName().endsWith(".json")) {
                availableKits.add(file.getName().replace(".json", ""));
            }
        }
    }
    log.info("There are " + availableKits.size() + " kits available.");
    // test stuff
    Kit kit = new Kit("DefaultKit");
    kit.addItem(0, new ItemBuilder(Material.STONE).name("Test Stone").build());
    kit.addItem(1, new ItemBuilder(Material.DIAMOND_SWORD).enchantment(Enchantment.DAMAGE_ALL, 5).name(ChatColor.RED + "Cool sword").amount(2).build());
    kit.addItem(2, new ItemBuilder(Material.LEATHER_BOOTS).enchantment(Enchantment.PROTECTION_EXPLOSIONS, 2).enchantment(Enchantment.PROTECTION_FALL, 5).name("Cool bots").amount(3).color(Color.RED).durability(10).lore("test").lore("Lore").build());
    createKit(kit);
    kit = loadKit("DefaultKit", new File(kitsDir, kit.getName() + ".json"));
    System.out.println(kit);
}
Also used : ItemBuilder(com.voxelgameslib.voxelgameslib.utils.ItemBuilder) File(java.io.File)

Example 5 with ItemBuilder

use of com.voxelgameslib.voxelgameslib.utils.ItemBuilder in project VoxelGamesLibv2 by VoxelGamesLib.

the class VoteFeature method openVoteMenu.

@GameEvent
public void openVoteMenu(@Nonnull PlayerInteractEvent event, User user) {
    if ((event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) && openMenuItem.equals(event.getItem())) {
        InventoryMenuBuilder builder = new InventoryMenuBuilder().withSize(9).withTitle("Vote for a map");
        for (int id : availableMaps.keySet()) {
            MapInfo info = availableMaps.get(id);
            ItemStack item = new ItemBuilder(Material.PAPER).amount(id).name(info.getName()).lore(info.getAuthor()).build();
            builder.withItem(id - 1, item, (player, clickType, itemStack) -> confirmVote(user, id), ClickType.LEFT);
        }
        builder.show(user.getPlayer());
    }
}
Also used : ItemBuilder(com.voxelgameslib.voxelgameslib.utils.ItemBuilder) InventoryMenuBuilder(org.inventivetalent.menubuilder.inventory.InventoryMenuBuilder) MapInfo(com.voxelgameslib.voxelgameslib.map.MapInfo) ItemStack(org.bukkit.inventory.ItemStack) GameEvent(com.voxelgameslib.voxelgameslib.event.GameEvent)

Aggregations

ItemBuilder (com.voxelgameslib.voxelgameslib.utils.ItemBuilder)5 ItemStack (org.bukkit.inventory.ItemStack)4 CommandPermission (co.aikar.commands.annotation.CommandPermission)3 Subcommand (co.aikar.commands.annotation.Subcommand)3 Syntax (co.aikar.commands.annotation.Syntax)2 VoxelGameLibException (com.voxelgameslib.voxelgameslib.exception.VoxelGameLibException)2 SkullMeta (org.bukkit.inventory.meta.SkullMeta)2 InventoryMenuBuilder (org.inventivetalent.menubuilder.inventory.InventoryMenuBuilder)2 Skin (org.mineskin.data.Skin)2 GameEvent (com.voxelgameslib.voxelgameslib.event.GameEvent)1 MapInfo (com.voxelgameslib.voxelgameslib.map.MapInfo)1 MarkerDefinition (com.voxelgameslib.voxelgameslib.map.MarkerDefinition)1 File (java.io.File)1