Solved Bukkit Plugin

Discussion in 'Plugin Development' started by hemran, Nov 23, 2014.

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

    hemran

    Hey there,

    at the moment im programming a bukkit Plugin.

    Code:
    Code:java
    1. if(cmd.getName().equalsIgnoreCase("tele")){
    2. if(p != null){
    3. if(p.hasPermission("test.tele")){
    4. if(args.length != 2){
    5. return false;
    6. }
    7. Player p2 = this.getServer().getPlayer(args[0]);
    8. Player target = this.getServer().getPlayer(args[1]);
    9. String targetname = target.getDisplayName();
    10. String pname= p2.getDisplayName();
    11.  
    12.  
    13. if(target.isOnline() && p2.isOnline()){
    14.  
    15. Location s = target.getLocation();
    16. p2.teleport(s);
    17.  
    18. p.sendMessage(ChatColor.RED + pname + ChatColor.GREEN + " wurde erfolgrecih zu" + targetname + " teleportiert!");
    19.  
    20. }else{
    21. p.sendMessage("Not online");
    22.  
    23. }
    24.  
    25.  
    26. }
    27. }else{
    28. sender.sendMessage("[Test] Sie sind kein Spieler!");
    29. return true;
    30. }
    31.  
    32. }


    this is one of the commands. this is a teleport command. Now when i teleport player who are online, it works but if i type a random name, it wont show the message "Not Online". Instead it shows an error in the console of bukkit... maybe there is 1 return too much?

    Thank you!
     
  2. Offline

    mrCookieSlime

    hemran
    The Variables targetname and pname should be inside of the if-statement. Because they won't have a name if they aren't even online. Also always post any errors you get using Pastebin. Errors are helpful.
     
  3. Online

    timtower Administrator Administrator Moderator

    Moved to plugin development.
     
  4. Offline

    Jaaakee224

    hemran
    Check if the player is null before teleporting.

    if (p2 == null) {
    p.sendMessage("Player not found);
    } else {
    // teleport
     
  5. Offline

    hemran

    Thank you guys its works now... with the null statement
     
Thread Status:
Not open for further replies.

Share This Page