Exception?

Discussion in 'Spigot Plugin Development' started by ryguybuddy, Mar 5, 2015.

  1. I have tried to rewrite my plugin http://www.spigotmc.org/resources/telegrams.4593/ and I kept getting this error:
    http://pastebin.com/FiHbx2Je
    My classes are as follows:
    Main.java:
    Code (Text):

    import java.util.HashMap;
    import java.util.UUID;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin implements Listener{
    public void onEnable(){  
        this.getCommand("receive").setExecutor(new Recover());
        Bukkit.getServer().getPluginManager().registerEvents(this, this);
    }
    static HashMap<Player, String[]> map = new HashMap<Player, String[]>();
    public static void saveForOfflinePlayer(Player p, String[] args)
    {
        map.put(p, args);
    }
    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if (cmd.getName().equalsIgnoreCase("telegram")) {
            Player player = Bukkit.getServer().getPlayer(args[0]);
                    SendTelegram.Send(player, args, args[0]);              
        return true;
        }
        return false;
        }

    public void onPlayerJoin(PlayerJoinEvent e)
    {
        Player p = e.getPlayer();
        Recover.recover(p);
    }
    }


     
    Recover.java:
    Code (Text):
    package com.outlook.rcottone;

    import java.util.HashMap;

    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;

    public class Recover implements CommandExecutor{
        static HashMap<Player, String[]> map = Main.map;
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label,
                String[] args) {      
            if (cmd.getName().equalsIgnoreCase("receive")) {
                Player p = (Player) sender;
                recover(p);
            }
            return false;
        }
        public void sendOffline(Player p, String[] args)
        {
           
        }
        public static void recover(Player p) {
            String[] Message = map.get(p);
            if (Message != null)
            {
            SendTelegram.Send(p, Message, "Unknown");
            }
           
        }

    }
    And my SendTelegram.java:
    Code (Text):
    package com.outlook.rcottone;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;

    public class SendTelegram {
    public static void  Send(Player args2, String[] args, String string)
    {
        Player senda = Bukkit.getServer().getPlayer(string);
        if (args.length > 1 || !(args.length > 4))
        {
            args2 = Bukkit.getServer().getPlayer(args[0]);
            if (args2.isOnline())
            {                  
            args2.sendMessage(ChatColor.BLACK + "=========================");
            args2.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "Incoming Telegram!");
            args2.sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "Sender: " + senda.getName());
            args2.sendMessage(ChatColor.BLUE + "" + ChatColor.BOLD + args[1] + args[2] + args[3] + args[4]);
            args2.sendMessage(ChatColor.BLACK + "=========================");
            senda.sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "Telegram Sent.");
            }
            else
            {
                Main.saveForOfflinePlayer(args2, args);
            }  
        }
        else
        {
            senda.sendMessage("A Telegram must be 4 words or less!");
        }
    }
    }
     
    Plugin.yml:
    Code (Text):
    name: DonorScoreboard
    main: com.outlook.rcottone.Main
    version: 0.0.3
    commands:
       telegram:
          description: This is a demo command.
          usage: /<command> [player]
          permission: pluginname.basic
          permission-message: You don't have <permission>
       receive:
          description: Receive telegrams sent to you when you were offline!
          usage: /receive
          permission: telegrams.receive
          permission-message: No permission.
    Please help me ASAP if you can.
     
  2. Check if args[0] exists before using it.