I dont know whats wrong in the code :(

Discussion in 'Plugin Development' started by LucarioMCDario, Apr 10, 2016.

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


    package BugPlugin;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    public class BugPlugin extends JavaPlugin {
        public void onEnable() {
            System.out.println("TEST Plugin BugPlugin Version 1.0 geladen.");
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            Player player = null;
            if(sender instanceof Player)
                player = (Player) sender;
            //Kommando "test"
             if(command.getName() .equalsIgnoreCase("test")){
                if(player == null){
                     sender.sendMessage("Yeah es hat funktioniert");
                     return true;
                 } else {
                     player.sendMessage(ChatColor.BOLD + "Nice, " + player.getDisplayName());
                     player.sendMessage(ChatColor.YELLOW + "[BugPlug]" + ChatColor.BLUE + "Yeah es hat funktioniert");
                     return true;
            return false;
    i dont know whats wrong everytime player is underlined like its false :( bukkit forum.JPG

    sry my english is bad
  2. Offline

    timtower Ninja on the waves Moderator

    Moved to plugin development.
    @LucarioMCDario Hover your mouse over it. It should tell what the issue is.
  3. Offline


    To simplify finding a player if it is running a command, try
     (cmd.getName().equalsIgnoreCase("test") && sender instanceof Player){ [/code
  4. Offline


    Fix your brackets :p
  5. Offline


  6. Offline


    It's a really bad idea to name the class after the package or vise-versa, and it is a bad practice not to follow namming conventions.
    onEnable in JavaPlugin does nothing, so there is no point to call it.
    Use the Logger by invoking getLogger() instead of the default printstream.

    Well ive seen this a lot being used in an inapropriate way such as:
    if(command is X and sender is a player){}
    if(command is N and sender is a player){}
    which isn't wrong nessesarily but it would be much better to do:
    if SENDER is Player then:
          if COMMAND equals 'a_command' then:
           //do whatever
          else if COMMAND equals 'another_command' then:
           //do whatever
          end if
    end if
  7. Offline


    sry its my first plugin :(

    yeah i know but thats not the problem :(

    nice thx

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Apr 11, 2016
  8. Offline


    If solved mark this as solved.
Thread Status:
Not open for further replies.

Share This Page