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);
}
}
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);
}
}
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);
}
}
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);
}
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());
}
}
Aggregations