Solved Variable not coming into effect

Discussion in 'Spigot Plugin Development' started by DecisionsYT, May 15, 2016.

Thread Status:
Not open for further replies.
  1. Hey!

    In my Command Spy class, when seeing the players name and command they typed in game, the {player} variable works but the {command} variable isn't. Any suggestions?

    CODE:

    Code (Text):
    package ChatFilter;

    import java.util.ArrayList;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerCommandPreprocessEvent;

    import me.DecisionsYT.Main;

    public class CmdSpy implements Listener, CommandExecutor {
       
    Main plugin;
       
        public CmdSpy(Main passedPlugin) {
            this.plugin = passedPlugin;
        }

        public static ArrayList<String> spy = new ArrayList<String>();
       
        @EventHandler
        public void PlayerCommand(PlayerCommandPreprocessEvent e) {
            Player player = e.getPlayer();
            for (Player p : Bukkit.getOnlinePlayers())
                if (CmdSpy.spy.contains(p.getName()))
                  player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("CmdSpy-Format").replace("{player}", player.getName()).replace("{display_name}", player.getDisplayName().replace("{command}", e.getMessage()))));
                 
        }

      public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
       
          if (!(sender instanceof Player)) {
                sender.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Non-Player")));
                return true;
            }
           
            Player player = (Player) sender;
         
            if (args.length == 0) {
                if (sender.hasPermission("ChatX.CmdSpy")) {
                sender.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("CmdSpy-Usage").replace("{player}", player.getName()).replace("{display_name}", player.getDisplayName())));
                return true;
                }
           }
           
           
             else if (args.length == 1) {
                 if (sender.hasPermission("ChatX.CmdSpy")) {
                     if (args[0].equalsIgnoreCase("On")) {
                         sender.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("CmdSpy-Enabled").replace("{player}", player.getName()).replace("{display_name}", player.getDisplayName())));
                         CmdSpy.spy.add(sender.getName());
                         return true;
                     }
                     else if (args[0].equalsIgnoreCase("Off")) {
                         sender.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("CmdSpy-Disabled").replace("{player}", player.getName()).replace("{display_name}", player.getDisplayName())));
                         CmdSpy.spy.remove(sender.getName());
                         return true;
                     }
                 }
             }
           
           
            if (!sender.hasPermission("ChatX.CmdSpy")) {
                sender.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("No-Perm-Message").replace("{player}", player.getName()).replace("{display_name}", player.getDisplayName())));
                return true;
            }
       
       
       
        return true;
            }
          }
     
  2. Learn Java and notice that you're replacing {command} in the displayname.

    This is literally one of the easiest 'issues' that you could have.
     
  3. it's not associated with the player.getDisplayName at all
     
    • Optimistic Optimistic x 1
  4. That's what I already said. Just open your eyes and look at this part closely.
    Code (Text):
    player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("CmdSpy-Format").replace("{player}", player.getName()).replace("{display_name}", player.getDisplayName().replace("{command}", e.getMessage()))));
     
Thread Status:
Not open for further replies.