Search in sources :

Example 1 with ItemBuilder

use of com.voxelgameslib.voxelgameslib.util.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.PLAYER_HEAD).name(markerDefinition.getPrefix()).meta(itemMeta -> {
                char prefix = markerDefinition.getPrefix().toUpperCase().charAt(0);
                Skin skin = textureHandler.getSkin(prefix + "").orElseThrow(() -> new VoxelGameLibException("Unknown skull " + prefix));
                SkullMeta meta = ((SkullMeta) itemMeta);
                meta.setPlayerProfile(textureHandler.getPlayerProfile(skin));
                Objects.requireNonNull(meta.getPlayerProfile()).setName(markerDefinition.getPrefix());
                meta.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 : ClickType(org.bukkit.event.inventory.ClickType) User(com.voxelgameslib.voxelgameslib.components.user.User) PlayerProfile(com.destroystokyo.paper.profile.PlayerProfile) CommandAlias(co.aikar.commands.annotation.CommandAlias) MapHandler(com.voxelgameslib.voxelgameslib.components.map.MapHandler) Singleton(javax.inject.Singleton) VoxelGameLibException(com.voxelgameslib.voxelgameslib.api.exception.VoxelGameLibException) TextureHandler(com.voxelgameslib.voxelgameslib.internal.texture.TextureHandler) SkullMeta(org.bukkit.inventory.meta.SkullMeta) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) InventoryMenuBuilder(org.inventivetalent.menubuilder.inventory.InventoryMenuBuilder) MarkerDefinition(com.voxelgameslib.voxelgameslib.components.map.MarkerDefinition) CommandPermission(co.aikar.commands.annotation.CommandPermission) Nonnull(javax.annotation.Nonnull) Material(org.bukkit.Material) Subcommand(co.aikar.commands.annotation.Subcommand) BaseCommand(co.aikar.commands.BaseCommand) Skin(org.mineskin.data.Skin) UUID(java.util.UUID) Logger(java.util.logging.Logger) Lang(com.voxelgameslib.voxelgameslib.internal.lang.Lang) ItemStack(org.bukkit.inventory.ItemStack) Objects(java.util.Objects) List(java.util.List) ItemBuilder(com.voxelgameslib.voxelgameslib.util.utils.ItemBuilder) Syntax(co.aikar.commands.annotation.Syntax) Optional(java.util.Optional) LangKey(com.voxelgameslib.voxelgameslib.internal.lang.LangKey) Default(co.aikar.commands.annotation.Default) ItemBuilder(com.voxelgameslib.voxelgameslib.util.utils.ItemBuilder) InventoryMenuBuilder(org.inventivetalent.menubuilder.inventory.InventoryMenuBuilder) VoxelGameLibException(com.voxelgameslib.voxelgameslib.api.exception.VoxelGameLibException) Skin(org.mineskin.data.Skin) SkullMeta(org.bukkit.inventory.meta.SkullMeta) ItemStack(org.bukkit.inventory.ItemStack) MarkerDefinition(com.voxelgameslib.voxelgameslib.components.map.MarkerDefinition) Subcommand(co.aikar.commands.annotation.Subcommand) CommandPermission(co.aikar.commands.annotation.CommandPermission)

Example 2 with ItemBuilder

use of com.voxelgameslib.voxelgameslib.util.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.util.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 3 with ItemBuilder

use of com.voxelgameslib.voxelgameslib.util.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, @co.aikar.commands.annotation.Optional @Default(value = "true") boolean usePrefix) {
    if (editMode.contains(sender.getUuid())) {
        ItemStack skull = new ItemBuilder(Material.PLAYER_HEAD).name(name).meta((itemMeta -> {
            SkullMeta skullMeta = (SkullMeta) itemMeta;
            if (usePrefix) {
                char prefix = name.toUpperCase().charAt(0);
                Optional<Skin> skin = textureHandler.getSkin(prefix + "");
                if (!skin.isPresent()) {
                    log.warning("Could not find skull for char " + prefix + "!");
                    skullMeta.setPlayerProfile(textureHandler.getErrorProfile());
                } else {
                    skullMeta.setPlayerProfile(textureHandler.getPlayerProfile(skin.get()));
                }
            } else {
                PlayerProfile playerProfile = textureHandler.getPlayerProfile(name);
                if (playerProfile == null) {
                    log.warning("Could not find skull for name " + name + "!");
                    skullMeta.setPlayerProfile(textureHandler.getErrorProfile());
                } else {
                    skullMeta.setPlayerProfile(playerProfile);
                }
            }
            if (skullMeta.getPlayerProfile() != null) {
                skullMeta.getPlayerProfile().setName(name);
            }
        })).build();
        sender.getPlayer().getInventory().setItemInMainHand(skull);
    } else {
        Lang.msg(sender, LangKey.EDITMODE_NOT_ENABLED);
    }
}
Also used : ItemBuilder(com.voxelgameslib.voxelgameslib.util.utils.ItemBuilder) PlayerProfile(com.destroystokyo.paper.profile.PlayerProfile) SkullMeta(org.bukkit.inventory.meta.SkullMeta) Skin(org.mineskin.data.Skin) 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.util.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.util.utils.ItemBuilder) File(java.io.File)

Example 5 with ItemBuilder

use of com.voxelgameslib.voxelgameslib.util.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.getDisplayName()).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.util.utils.ItemBuilder) InventoryMenuBuilder(org.inventivetalent.menubuilder.inventory.InventoryMenuBuilder) MapInfo(com.voxelgameslib.voxelgameslib.components.map.MapInfo) ItemStack(org.bukkit.inventory.ItemStack) GameEvent(com.voxelgameslib.voxelgameslib.api.event.GameEvent)

Aggregations

ItemBuilder (com.voxelgameslib.voxelgameslib.util.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)3 PlayerProfile (com.destroystokyo.paper.profile.PlayerProfile)2 SkullMeta (org.bukkit.inventory.meta.SkullMeta)2 InventoryMenuBuilder (org.inventivetalent.menubuilder.inventory.InventoryMenuBuilder)2 Skin (org.mineskin.data.Skin)2 BaseCommand (co.aikar.commands.BaseCommand)1 CommandAlias (co.aikar.commands.annotation.CommandAlias)1 Default (co.aikar.commands.annotation.Default)1 GameEvent (com.voxelgameslib.voxelgameslib.api.event.GameEvent)1 VoxelGameLibException (com.voxelgameslib.voxelgameslib.api.exception.VoxelGameLibException)1 MapHandler (com.voxelgameslib.voxelgameslib.components.map.MapHandler)1 MapInfo (com.voxelgameslib.voxelgameslib.components.map.MapInfo)1 MarkerDefinition (com.voxelgameslib.voxelgameslib.components.map.MarkerDefinition)1 User (com.voxelgameslib.voxelgameslib.components.user.User)1 Lang (com.voxelgameslib.voxelgameslib.internal.lang.Lang)1 LangKey (com.voxelgameslib.voxelgameslib.internal.lang.LangKey)1