Search in sources :

Example 1 with ItemBuilder

use of xyz.derkades.derkutils.bukkit.ItemBuilder in project Ublisk by Derkades.

the class TestNPC method talk.

@Override
public void talk(UPlayer player) {
    final QuestParticipant qp = player.getQuestParticipant(Quest.UNKNOWN, this);
    /*ClickAction action = new ClickAction(){

			@Override
			public void click(ClickedOption option) {
				qp.sendMessage("TEST!");
			}
			
		};*/
    // Option option1 = new Option(10, Material.STONE, "Some random option", "Some lore!", "Line 2");
    // Option option2 = new Option(11, Material.WOOD, "Option without lore");
    // qp.openMenu(new NPCMenu("Test Menu", action, option1, option2));
    new NPCMenu("Test Menu", 3 * 9, qp) {

        @Override
        public void open() {
            items.put(10, new ItemBuilder(Material.STONE).name("Some random option").lore("Some lore!", "Lines 2").create());
            items.put(11, new ItemBuilder(Material.WOOD).name("Option without lore").create());
            super.open();
        }

        @Override
        public boolean onOptionClick(OptionClickEvent event) {
            qp.sendMessage("TEST!");
            return false;
        }
    }.open();
}
Also used : QuestParticipant(xyz.derkades.ublisk.quest.QuestParticipant) ItemBuilder(xyz.derkades.derkutils.bukkit.ItemBuilder) NPCMenu(xyz.derkades.ublisk.quest.npcmenu.NPCMenu)

Example 2 with ItemBuilder

use of xyz.derkades.derkutils.bukkit.ItemBuilder in project ServerSelectorX by ServerSelectorX.

the class OnJoinListener method onJoin.

@EventHandler(priority = EventPriority.MONITOR)
public void onJoin(PlayerJoinEvent event) {
    for (FileConfiguration config : Main.getConfigurationManager().getAll()) {
        boolean putItemInInventory = config.getBoolean("on-join");
        if (!putItemInInventory)
            continue;
        Player player = event.getPlayer();
        if (Main.getPlugin().getConfig().getBoolean("permissions-enabled")) {
            if (!player.hasPermission("ssx.join." + config.getName().replace(".yml", ""))) {
                continue;
            }
        }
        String itemName = config.getString("item");
        if (itemName.equalsIgnoreCase("none")) {
            continue;
        }
        Material material = Material.getMaterial(itemName);
        if (material == null) {
            material = Material.STONE;
        }
        ItemBuilder builder = new ItemBuilder(material).data(config.getInt("data", 0)).coloredName(config.getString("item-name", "error"));
        List<String> lore = config.getStringList("item-lore");
        // Don't add lore if it's null or if the first line is equal to 'none'
        if (!(lore == null || lore.isEmpty() || lore.get(0).equalsIgnoreCase("none"))) {
            builder.coloredLore(lore);
        }
        int slot = config.getInt("inv-slot", 0);
        PlayerInventory inv = player.getInventory();
        if (slot < 0) {
            if (!inv.containsAtLeast(builder.create(), 1)) {
                inv.addItem(builder.create());
            }
        } else {
            inv.setItem(slot, builder.create());
        }
    }
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) Player(org.bukkit.entity.Player) ItemBuilder(xyz.derkades.derkutils.bukkit.ItemBuilder) Material(org.bukkit.Material) PlayerInventory(org.bukkit.inventory.PlayerInventory) EventHandler(org.bukkit.event.EventHandler)

Aggregations

ItemBuilder (xyz.derkades.derkutils.bukkit.ItemBuilder)2 Material (org.bukkit.Material)1 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1 PlayerInventory (org.bukkit.inventory.PlayerInventory)1 QuestParticipant (xyz.derkades.ublisk.quest.QuestParticipant)1 NPCMenu (xyz.derkades.ublisk.quest.npcmenu.NPCMenu)1