package net.knarcraft.blockhunt.command; import net.knarcraft.blockhunt.BlockHunt; import net.knarcraft.blockhunt.MemoryStorage; import net.knarcraft.blockhunt.config.ConfigKey; import net.knarcraft.blockhunt.config.MessageKey; import net.knarcraft.blockhunt.util.MessageHelper; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.logging.Level; public class WandCommand extends DefaultCommand { @Override public boolean execute(Player player, String[] args) { if (player != null) { Material material = Material.getMaterial((String) MemoryStorage.config.get(ConfigKey.WAND_ID_NAME)); if (material == null) { BlockHunt.plugin.getLogger().log(Level.SEVERE, "Invalid wand material specified in the config file!"); return true; } ItemStack wand = new ItemStack(material); ItemMeta itemMeta = wand.getItemMeta(); Objects.requireNonNull(itemMeta).setDisplayName(MessageHelper.replaceAll( (String) MemoryStorage.config.get(ConfigKey.WAND_NAME))); MemoryStorage.config.load(); List loreLines = MemoryStorage.config.getFileConfiguration().getStringList( ConfigKey.WAND_DESCRIPTION.getPath()); List loreLines2 = new ArrayList<>(); for (String lore : loreLines) { loreLines2.add(MessageHelper.replaceAll(lore)); } itemMeta.setLore(loreLines2); wand.setItemMeta(itemMeta); player.getInventory().addItem(wand); player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 5, 0); MessageHelper.sendMessage(player, MessageKey.NORMAL_WAND_GAVE_WAND, "type-" + wand.getType().toString().replaceAll("_", " ").toLowerCase()); } else { MessageHelper.sendMessage(null, MessageKey.ERROR_ONLY_IN_GAME); } return true; } }