Plugin Help Help

Discussion in 'Plugin Help/Development/Requests' started by Lukas12137, Feb 10, 2015.

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

    Lukas12137

    So im new to coding and i mad a simple plugin and i don't know what its wrong with it can any one assist?

    Read at the end for more information.

    package me.lukas.staffsay1;

    import java.util.logging.Logger;

    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;

    public class staffsay1 extends JavaPlugin {

    public final Logger logger = Logger.getLogger("Minecraft");
    public static staffsay1 plugin;

    @Override
    public void onDisable() {
    PluginDescriptionFile pdfFile = this.getDescription();
    this.logger.info(pdfFile.getName() + " Has Been Disabled");

    }

    @Override
    public void onEnable() {

    PluginDescriptionFile pdfFile = this.getDescription();
    this.logger.info(pdfFile.getName() + " Has Been Enable");
    }

    public boolean onCommand(CommandSender sender, Command cmd, String commandLable, String[] args){
    Player player = (Player) sender;
    if(commandLable.equalsIgnoreCase("lukas")){
    player.sendMessage(ChatColor.DARK_GREEN + "Im The Server Owner");
    }
    return false;

    }
    }


    The YML is:

    name: staffsay1
    description: tells a lukas
    version: 1.0
    main: mc.lukas.staffsay1.staffsay1
    commands:
    Lukas:
    description: tells a lukas


    It jest does not seem to load at all im using a host for a server so do i need to change a build or something? i jest need like a guide on how to upload it, is there any thing else i can do?

    Bukkit version im using as a build path is: bukkit-1.7.10-R0.1-20140817.175650-8

    and for the uploading one i use my standard host one which is craftbukkit 1.7.10
     
  2. Offline

    pie_flavor

    @Lukas12137 Actually, a few things I can immediately find wrong with your code. First of all, not sure if you directly pasted or not, but if the YML is pasted, your indentation is wrong. Either you don't have it, or you're using tab breaks instead of spaces (you need to use spaces).
    With that in mind, there's a couple more things:
    You should use command.getName() instead of commandLable because the command.getName() will always return Lukas, but commandLable will actually return the alias used for the command (e.g. /gm is an alias for /gamemode in Essentials).
    You don't actually need to muck about with PluginDescriptionFiles. It says in the console already when it's enabled or disabled.
    You don't actually need to cast to player, it might be run from the console and will generate an error. Just do sender.sendMessage() instead of player.sendMessage().
    In this case, if you're not adding any more commands, you don't even need an if/then check for command.getName() or commandLable because your plugin will always be using only the one command.
    You can delete basically all your infrastructure regarding Loggers, because it's unnecessary and sometimes will not even work, resulting in the plugin not being loaded (is that your problem?). getLogger() gets the logger.
     
  3. Offline

    Lukas12137

    @pie_flavor So i changed the code to what i understood of you saying and it has a problem the - command.getName is underlined red and i don't know why? could you assist. I try running this code but taking logger off and it still does not want to load on the console and i don't get a error is jest like the plugin docent exist code:

    package me.lukas.staffsay1;


    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;

    public class staffsay1 extends JavaPlugin {

    @Override
    public void onDisable() {


    }

    @Override
    public void onEnable() {

    }

    public boolean onCommand(CommandSender sender, Command cmd, String commandLable, String[] args){
    if(command.getName("lukas")){
    sender.sendMessage("Im The Server Owner");
    }
    return true;

    }
    }
     
  4. Offline

    pie_flavor

    @Lukas12137 Don't just copy-paste what I write, understand why I write it. You have named the Command object cmd, so you should use cmd instead of command.
     
  5. Offline

    Lukas12137

    If i do cmd.getName it tells me to remove the string in ( ) brakets
     
  6. Offline

    timtower Administrator Administrator Moderator

    @Lukas12137 That is because there is no getName method with parameters. You probably want to use cmd.getName().equals("lukas")
     
  7. Offline

    Lukas12137

  8. Offline

    pie_flavor

    @Lukas12137 That's not how it works. You don't put it in onEnable(). You don't even need onEnable or onDisable. onCommand is a method, like onEnable(). Your original post was right at least in that regard.
    Have you worked with Java before?
     
  9. Offline

    Lukas12137

    I'm new to java and I'm trying to learn it. Your suppor is really good thank you.

    So if I get you right I need to delete onenable() and onDisable () with all the code behind it or if you could can you post a code how it should look like so I know?
     
  10. Offline

    pie_flavor

    @Lukas12137 Crucial word in your earlier post:
    You don't need it per se, but it will simplify the code for you. Here's the entire class as simple as it gets.
    Code:java
    1. package me.lukas.staffsay1;
    2.  
    3. import org.bukkit.command.Command;
    4. import org.bukkit.command.CommandSender;
    5. import org.bukkit.plugin.java.JavaPlugin;
    6.  
    7. public class staffsay1 extends JavaPlugin {
    8. @Override
    9. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    10. sender.sendMessage("I'm the Server Owner");
    11. return true;
    12. }
    13. }

    By the way, if you want to know how to type like that it's [syntax][/syntax].

    Also, a cool new feature in Java 8:
    If you have multiple commands and you don't want to put them all in the same onCommand but you also want the commands to all be in the main class, you can put separate methods with random names such as staffsay(CommandSender sender, Command cmd, String label, String[] args)
    and then in onCommand, you say getCommand("lukas").setExecutor(this::staffsay);

    So a class that looks like that would be
    Code:java
    1. package me.lukas.staffsay1.staffsay1;
    2.  
    3. import org.bukkit.command.Command;
    4. import org.bukkit.command.CommandSender;
    5. import org.bukkit.plugin.java.JavaPlugin;
    6.  
    7. public class staffsay1 extends JavaPlugin {
    8. public boolean lukas(CommandSender sender, Command cmd, String label, String[] args) {
    9. sender.sendMessage("I'm the Server Owner");
    10. return true;
    11. }
    12. public void onEnable() {
    13. getCommand("lukas").setExecutor(this::lukas);
    14. }
    15. }

    Remember though, only in Java 8.
     
    Last edited: Feb 13, 2015
  11. Offline

    Lukas12137

    Close this threat it got answers
     
  12. Offline

    timtower Administrator Administrator Moderator

    Locked on request
     
Thread Status:
Not open for further replies.

Share This Page