Solved /reply its keep going say you have nobody to reply to

Discussion in 'Spigot Plugin Development' started by AnnoyingMan, May 29, 2016.

  1. Can you help me with it:
    package me.speedypvp.commands;

    import java.util.HashMap;
    import java.util.Map;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Sound;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;

    public class PrivateMessages implements CommandExecutor, Listener {

    public Map<Player, Player> reply = new HashMap<Player, Player>();

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    {
    if(cmd.getName().equalsIgnoreCase("msg")) {
    if(!(sender instanceof Player)) {
    sender.sendMessage("no");
    return true;
    }
    Player p = (Player) sender;

    if (args.length == 0)
    {
    p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&b&lSpeedy&c&lPvP &8» &6Please use &b/msg (player) (message)"));
    return true;
    }
    if (args.length == 1)
    {
    p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&b&lSpeedy&c&lPvP &8» &6Please use &b/msg (player) (message)"));
    return true;
    }

    else if(args.length >= 2) {
    StringBuilder str = new StringBuilder();
    for(int i = 1; i < args.length; i++) {
    str.append(args + " ");
    }
    Player target = Bukkit.getServer().getPlayer(args[0]);

    if (target == null)
    {
    p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&b&lSpeedy&c&lPvP &8» &6That player is not online!"));
    return true;
    }

    sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&e[&bSpeedyPvP&e] &eMe &c» &b" + target.getName() + "&e]&b " + str.toString().trim()));
    target.sendMessage(ChatColor.translateAlternateColorCodes('&', "&e[&bSpeedyPvP&e] &b" + sender.getName() + " &eMe &c»&b " + str.toString().trim()));
    target.playSound(target.getLocation(), Sound.LEVEL_UP, 1, 1);
    return true;
    }


    }
    if(cmd.getName().equalsIgnoreCase("reply")) {
    if(!(sender instanceof Player)) {
    sender.sendMessage("no");
    return true;
    }

    if(args.length == 0) {
    sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&b&lSpeedy&c&lPvP &8» &6Please use &b/r (messages)"));
    return true;
    }

    if(args.length >= 1) {
    StringBuilder str = new StringBuilder();
    for(int i = 1; i < args.length; i++) {
    str.append(args + " ");
    }


    Player r = (Player) reply.get(sender);
    if(r == null) {
    sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&b&lSpeedy&c&lPvP &8» &6You have nobody to reply to"));
    return true;
    }
    Player target = Bukkit.getServer().getPlayer(args[0]);
    r.sendMessage(ChatColor.translateAlternateColorCodes('&', "&e[&bSpeedyPvP&e] &eMe &c» &b" + r.getName() + "&e]&b " + str.toString().trim()));
    target.sendMessage(ChatColor.translateAlternateColorCodes('&', "&e[&bSpeedyPvP&e] &b" + sender.getName() + " &eMe &c»&b " + str.toString().trim()));
    return true;

    }

    }

    return true;
    }

    }
     
    #1 AnnoyingMan, May 29, 2016
    Last edited: May 30, 2016
  2. Where you add the two players to the HashMap? That's the reason why it sends you that message. The plugin cannot find "sender" in the HashMap
     
    • Like Like x 1
  3. you mean?
     
  4. You have to add both players into the HashMap with reply.put(p, target);
     
    • Like Like x 1
  5. yea i just fixing it and works thx
     
    • Like Like x 1