Solved Getting a red line in Eclipse (error)

Discussion in 'Plugin Development' started by mrdude123, Jul 13, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    mrdude123

    Hi. here is the snippet of code preventing the plugin from functioning properly.

    if (!lore.isEmpty()) {
    List newLore = new ArrayList();
    for (String line : lore) {
    newLore.add(ChatColor.translateAlternateColorCodes('&', line));
    }

    The error has been highlighted red. What can I do to fix this?

    [16:43:46] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'ninjasandals' in plugin Test v1.0

    This is what I get in console telling me about the command. The plugin starts and everything, but the one command it has doesn't work. I get the "An internal error has occured while trying to execute this command" prompt.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  2. Offline

    schwabfl

    What does eclipse tell you when you hover over the red line?
    And what type is lore?
     
  3. Offline

    mrdude123

    Type mismatch: cannot convert from element type Object to String
     
  4. Offline

    schwabfl

    show me the entire method
     
  5. Offline

    mrdude123

    import java.util.ArrayList;
    import java.util.List;
    import java.util.logging.Logger;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.FileConfigurationOptions;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    import org.bukkit.inventory.ItemFactory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;

    public class NinjaSandals extends JavaPlugin
    implements Listener
    {
    private ItemStack sandalItem;

    public void onEnable()
    {
    saveDefaultConfig();
    getConfig().options().copyDefaults(false);
    saveConfig();

    reloadAll();

    Bukkit.getPluginManager().registerEvents(this, this);

    getLogger().info(String.format("NinjaSandals by TheCerealKill3r ENABLED.", new Object[] { getDescription().getVersion() }));
    }

    public void onDisable()
    {
    getLogger().info(String.format("NinjaSandals by TheCerealKill3r DISABLED.", new Object[] { getDescription().getVersion() }));
    }

    public void reloadAll() {
    reloadConfig();

    this.sandalItem = new ItemStack(Material.CHAINMAIL_BOOTS);

    ItemMeta meta = Bukkit.getItemFactory().getItemMeta(Material.CHAINMAIL_BOOTS);
    String dispName = getConfig().getString("Item.Display name");
    List lore = getConfig().getStringList("Item.Lore");
    if (dispName != null) {
    meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', dispName));
    }

    if (!lore.isEmpty()) {
    List newLore = new ArrayList();
    for (String line : lore) {
    newLore.add(ChatColor.translateAlternateColorCodes('&', line));
    }
    meta.setLore(newLore);
    }
    this.sandalItem.setItemMeta(meta);
    }

    public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
    {
    if (args.length > 0) {
    switch (args[0].toLowerCase()) {
    case "reload":
    if (!sender.hasPermission("ninjasandals.reload")) {
    sender.sendMessage(ChatColor.RED + "You do not have permission to use this command.");
    return true;
    }
    reloadAll();
    sender.sendMessage(ChatColor.GREEN + "Plugin configuration reloaded.");
    return true;
    }
    }

    if (!(sender instanceof Player)) {
    sender.sendMessage(ChatColor.RED + "You must be a player to use this command.");
    return true;
    }

    ItemStack item = ((Player)sender).getItemInHand();
    if ((item == null) || (item.getType() != Material.CHAINMAIL_BOOTS)) {
    sender.sendMessage(ChatColor.RED + "You must be holding chain boots!");
    return true;
    }

    if (isItemValid(item)) {
    sender.sendMessage(ChatColor.RED + "These chain boots are already Ninja Sandals.");
    return true;
    }

    item.setItemMeta(this.sandalItem.getItemMeta().clone());
    sender.sendMessage(ChatColor.GREEN + "Successfully received Ninja Sandals!");
    return true;
    }

    @EventHandler
    public void onEntityDamageByEntity(EntityDamageByEntityEvent e) {
    Entity entity = e.getEntity();
    if (!(entity instanceof Player)) return;

    ItemStack shoes = ((Player)entity).getInventory().getBoots();
    if ((!entity.isDead()) && (shoes != null) && (isItemValid(shoes)))
    ((Player)entity).addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 100, 1));
    }

    private boolean isItemValid(ItemStack item)
    {
    if (item.getType() != Material.CHAINMAIL_BOOTS) return false;
    if (item.hasItemMeta() != this.sandalItem.hasItemMeta()) return false;
    if ((item.hasItemMeta()) && (!item.getItemMeta().getDisplayName().equals(this.sandalItem.getItemMeta().getDisplayName()))) return false;
    return true;
    }
    }
     
  6. Offline

    schwabfl

    I said method, not class, had a lot of fun searching for the correct line, and use the [ code ] bb-code (without spaces) next time, or paste your code on http://pastebin.com
    Anyways,

    change this:
    "List lore = getConfig().getStringList("Item.Lore");"
    and this:
    "List newLore = new ArrayList();"

    to:
    "List<String> lore = getConfig().getStringList("Item.Lore");"
    and:
    "List<String> newLore = new ArrayList<String>();"
     
  7. Offline

    mrdude123

    Sorry. :(

    But thank you
     
Thread Status:
Not open for further replies.

Share This Page