Solved how to use variables

Discussion in 'Plugin Development' started by nBlacky, Nov 22, 2019.

  1. Offline

    nBlacky

    Hello. Im new to Coding and I made a little plugin function in German but its not working can somebody help me please? Source Code:

    [​IMG]
     
    Last edited: Nov 22, 2019
  2. Offline

    KarimAKL

    @nBlacky
    1. You can read a tutorial on java here: https://docs.oracle.com/javase/tutorial/ It's recommended to read that before diving into any APIs.
    2. That code looks fine, did you register the command in your onEnable method? Also, remember to add the command to your plugin.yml file.
     
  3. Offline

    nBlacky

  4. Offline

    CraftCreeper6

    @nBlacky
    Teleport needs to be a CommandExecutor, I.E. you need an instance of the teleport class, you do this by writing "new teleport()".

    That is of course provided that teleport is a class.

    EDIT: It could also be that teleport() is a method that returns a class, but I have no way of knowing.
     
  5. Offline

    Strahan

    Also remember in your command to check the args length rather than just assume one exists. Dunno if you did that before the bit you posted or not, figured I'd mention just in case. This is why it's better to post whole classes in code blocks or Pastebin rather than an image of a tiny portion of the code.

    I'd also argue that a switch would be cleaner, though that is just personal preference. Like:
    Code:
    if (args.length == 0) {
      p.sendMessage("Bitte ├╝bergeben Sie einen Unterbefehl!");
      return true;
    }
    
    switch (args[0].toLowerCase()) {
    case "youtube":
      p.sendMessage("Das ist der YT channel");
      break;
    
    case "discord":
      p.sendMessage("Das ist der Discord");
      break;
    
    default:
      p.sendMessage("Ung├╝ltiger Unterbefehl!");
      break;
    }
    Also if daten is the only command the teleport() class handles, then there is no need to check if the name matches as the code will only be ran when that command is the one in use.
     
  6. Offline

    nBlacky

    Thank you all it helped me a lot
     

Share This Page