@EventHandler public void onClick(PlayerInteractEvent e) { if (e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK) { if (checkName(e.getPlayer().getItemInHand(), this.name())) { ItemStack i = e.getPlayer().getItemInHand(); List<String> l = i.getItemMeta().getLore(); String s = l.get(0).replace(ChatColor.GRAY + "", ""); if (Zephyrus.spellMap.containsKey(s)) { Spell spell = Zephyrus.spellMap.get(s); Player player = e.getPlayer(); FileConfiguration cfg = PlayerConfigHandler.getConfig(plugin, player); if (!cfg.getStringList("learned").contains(spell.name())) { PlayerLearnSpellEvent event = new PlayerLearnSpellEvent(player, spell); Bukkit.getServer().getPluginManager().callEvent(event); if (!event.isCancelled()) { List<String> learned = PlayerConfigHandler.getConfig(plugin, player).getStringList("learned"); learned.add(spell.name()); cfg.set("learned", learned); e.getPlayer() .sendMessage("You have successfully learned " + ChatColor.GOLD + spell.name()); e.getPlayer().setItemInHand(null); PlayerConfigHandler.saveConfig(plugin, player, cfg); } } else { e.getPlayer().sendMessage("You already know that spell!"); return; } } else { e.getPlayer().sendMessage("Spell not found..."); } } } }
public static ItemStack getSpelltome(Spell spell) { ItemStack i = new ItemStack(Material.BOOK); BookMeta m = (BookMeta) i.getItemMeta(); List<String> l = new ArrayList<String>(); l.add(ChatColor.GRAY + "" + spell); m.setLore(l); m.setTitle(spell.name()); m.addPage( spell.bookText() + "\n\n" + ChatColor.getByChar("0") + "Cast the spell with:\n" + ChatColor.getByChar("9") + "/cast " + spell + "\n\n" + ChatColor.getByChar("0") + "Learn this spell by left clicking this book!"); i.setItemMeta(m); i.addEnchantment(Zephyrus.getInstance().glow, 1); return i; }