Where is the mistake? Please help me.

Discussion in 'Plugin Development' started by cxlp2006, Aug 20, 2019.

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

    cxlp2006

    Wheres the mistake.

    The command usally is /ds add team 1 <Player Name>
    In the Minecraft Chat
    An Internal Error occured...

    I want to develope a Plugin which puts Players in a Team(1/2)

    Code:
    } else if (args[0].equalsIgnoreCase("add")) {
    
    if (args[1].equalsIgnoreCase("team")) {
    
    if (args[2].equalsIgnoreCase("1")) {
    
    Player target1 = Bukkit.getServer().getPlayer(args[3]);
    
    target1.setHealth(1);
    p.sendMessage(target1.getName() + " was added to Team 1!");
    
    }
    }
    }
     
  2. Offline

    robertlit

    @cxlp2006 First of all you should check if the player is online, otherwise you may get a NullPointerException (the internal error that you were talking about), and also do: Bukkit.getPlayer(Player p) instead of Bukkit.getServer().getPlayer(Player p) it also might return a null. Check if that works, if it doesn't please post the whole class, the main class, the error from console.

    Also what does the player's health have to do with its team??
     
    Last edited: Aug 20, 2019
  3. Offline

    cxlp2006

    The health thing was just a test.
    I tried it before with "if(target == null) {".
    The Error is here: https://pastebin.com/HrGDQkcA
     
  4. Offline

    tlm920

    Can you please post stacktrace?
     
  5. I think that should work for you:
    Code:
    @Override
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            if(args[0].equalsIgnoreCase("add") && args[1].equalsIgnoreCase("team") && args[2].equalsIgnoreCase("1") && Bukkit.getPlayer(args[3]) != null) {
                Bukkit.getScoreboardManager().getMainScoreboard().getTeam("1").addEntry(Bukkit.getPlayer(args[3]).getName());
                sender.sendMessage(Bukkit.getPlayer(args[3]).getName() + " was added to Team 1!");
            } else {
                sender.sendMessage("ExampleError");
            }
            return true;
        }
    You can check if the player exists:
    Code:
    if(Bukkit.getPlayer(args[3]) != null) {
    }
     
  6. Offline

    robertlit

    @cxlp2006 what is line 33 in de.cxl.commands.SetTeam.SetTeamCore?
     
  7. Offline

    Strahan

    You should never perform operations against arguments without first checking if there are arguments and you shouldn't add to a scoreboard's team without verifying said team actually exists.
     
Thread Status:
Not open for further replies.

Share This Page