sendMessage error

Discussion in 'Spigot Plugin Development' started by Pointless2Play, Apr 24, 2017.

  1. Hi, I'm creating a Wand Plugin and in my main class I get this error:
    package me.kingdom.wand;

    import java.util.ArrayList;
    import java.util.List;

    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin implements Listener{

    public Main plugin;
    public List<String> spells = new ArrayList<String>();
    public getTargets getTargets = new getTargets();

    @Override
    public void onEnable() {
    plugin = this;

    }

    @Override
    public boolean onCommand (CommandSender sender, Command command,
    String label, String[] args) {
    if(label.equalsIgnoreCase("wand"))
    if((sender instanceof Player)) {
    sender.sendMessage(ChatColor.RED + "Je moet een in-game speler zijn om dat te doen!");
    } else {
    if(sender.hasPermission("wand.wand")) {
    Player p = (Player)sender;
    ItemStack stack = new ItemStack(Material.BLAZE_ROD);
    ItemMeta stackMeta = stack.getItemMeta();
    stackMeta.setDisplayName(ChatColor.BLACK + "Tandi" + ChatColor.DARK_BLUE + "cium " + ChatColor.BLACK + "Wand");
    stack.setItemMeta(stackMeta);
    ChatUtitlities.sendMessage(p, "Je hebt nu de Tandicium Wand ontvangen!");
    p.getInventory().addItem(stack);
    }else{
    sender.sendMessage(ChatColor.RED + "Je hebt geen permissie om dit te doen!");
    }
    }
    return false;
    }

    }
    @Override
    public boolean onCommand (CommandSender sender, Command command,
    String label, String[] args) {
    if(label.equalsIgnoreCase("wand"))
    if((sender instanceof Player)) {
    sender.sendMessage(ChatColor.RED + "Je moet een in-game speler zijn om dat te doen!");
    } else {
    if(sender.hasPermission("wand.wand")) {
    Player p = (Player)sender;
    ItemStack stack = new ItemStack(Material.BLAZE_ROD);
    ItemMeta stackMeta = stack.getItemMeta();
    stackMeta.setDisplayName(ChatColor.BLACK + "Tandi" + ChatColor.DARK_BLUE + "cium " + ChatColor.BLACK + "Wand");
    stack.setItemMeta(stackMeta);
    ChatUtitlities.sendMessage(p, "Je hebt nu de Tandicium Wand ontvangen!");
    p.getInventory().addItem(stack);
    }else{
    sender.sendMessage(ChatColor.RED + "Je hebt geen permissie om dit te doen!");

    It's about the ChatUtitlities.sendMessage part. (The messages are Dutch by the way)

    Thanks,

    Pointless2Play
     
    • Winner Winner x 1
  2. What is the exact error? Whole thing


    Sent from my iPhone using Tapatalk
     
  3. No, it's just 'The method sendMessage(Player, String) is undefined for the type ChatUtitlities' that's the error for ChatUtitlities, the rest show no error.
     
  4. Show us the ChatUtilities class
     
  5. Where is the chat utilities class?


    Sent from my iPhone using Tapatalk
     
  6. package me.kingdom.wand;

    import org.bukkit.entity.Player;
    import static org.bukkit.ChatColor.*;

    public class ChatUtitlities {

    public static void sendMessage(Player p, String msg) {
    p.sendMessage(starter() + msg);

    }

    public static String starter() {
    return GOLD + "[" + GRAY + "X" + GOLD + "] " + WHITE;
    }

    }
     
  7. ChatUtilities*

    Is the method underlined with red? What is the error message saying?
     
  8. Gotta use
    Code (Java):
            return ChatColor.GOLD + "[" + ChatColor.GRAY + "X" + ChatColor.GOLD + "] " + ChatColor.WHITE;
     
  9. Hmm that looks ok, did you import ChatUtilities in the class where the error is appearing? And if so is it the one from your plugin and not one from another library?


    Sent from my iPhone using Tapatalk
     
  10. I think they have a static import on ChatColor which allow them to not do so i believe. Not sure though.
     
  11. Could be wrong, but Unless you're extending a class, you need to access the class' static fields with <ClassName>.<FieldName>

    Edit: hadnt seen the static import.

    Remove the static import and use the full name. see if it works.
     
  12. Basically forgot the ChatColor, that was it. Sorry, I'm new to coding. It's fixed now, thanks for the help.
     
  13. Look up how enums work. Like rn.
     
  14. You should, too.
     
  15. [​IMG]
    https://gyazo.com/09a6e2ea0e4b165f321b88fe550f9653

    Result:
    Code (Text):
    §cStatic§9 import§3 is§a a§0 thing
    They had the .*, meaning they originally thought it was a static import. They forgot the static tag, but the star is required for the static import to work.

    Smart guy :rolleyes:
     
  16. Did I say it was need for it? You are the only yelling at me for not knowing "how enums work", when I perfectly know how. This guy clearly had no idea.

    EDIT:
    This fixed it:
    They also forgot the static tag if they wanted to go for the static import. Guess they changed it.