Plugin Java Help!

Discussion in 'Bukkit Help' started by Groganer, Jul 10, 2011.

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

    Groganer

    Ok, so my friend and I have been spending a lot of time making a plugin, fixing bugs etc, and now when we try running the server with the plugin, we get no notifications for errors or notifications that it has started the plugin.

    Our main class:

    package me.groganers.ultimaterpg;

    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.logging.Logger;

    import org.bukkit.block.Block;
    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 UltimateRPG extends JavaPlugin {
    public final Logger logger = Logger.getLogger("Minecraft");
    public final HashMap<Player, ArrayList<Block>> basicUsers = new HashMap<Player, ArrayList<Block>>();
    //The HashMap
    private final HashMap<Player, Boolean> debugees = new HashMap<Player, Boolean>();
    //The HashMap Debugee

    public void onDisabled() {
    this.logger.info("UltimateRPG Disabled");
    }

    public void onEnabled() {
    getServer().getPluginManager();
    PluginDescriptionFile pdfFile = this.getDescription();
    this.logger.info( pdfFile.getName() + " version " + pdfFile.getVersion() + "is enabled!" );
    }

    public boolean onCommand1(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    if (commandLabel.equalsIgnoreCase("URPG Help"))
    toggleVision((Player) sender);
    return false;
    }

    public boolean isDebugging(final Player player) {
    if (debugees.containsKey(player)) {
    return debugees.get(player);
    } else {
    return false;
    }
    }

    public void setDebugging(final Player player, final boolean value) {
    debugees.put(player, value);
    }

    public boolean enabled(Player player) {
    return this.basicUsers.containsKey(player);
    }
    public void toggleVision(Player player) {
    if (enabled(player)) {
    } else {
    this.basicUsers.put(player, null);
    player.sendMessage("The factions are:" +
    "/Silverblade" +
    "/Silverpalm"); }
    }
    public boolean onCommand2(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    if (commandLabel.equalsIgnoreCase("Silverblade"))
    toggleVision2((Player) sender);
    return false;
    }
    public void toggleVision2(Player player) {
    if (enabled(player)) {
    } else {
    this.basicUsers.put(player, null);
    player.sendMessage("The races are:" +
    "/Human" +
    "/Troll" +
    "/Merm" +
    "/Dwarf" +
    "/Elf"); }
    }
    public boolean onCommand3(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    if (commandLabel.equalsIgnoreCase("Silverpalm"))
    toggleVision3((Player) sender);
    return false;
    }
    public void toggleVision3(Player player) {
    if (enabled(player)) {
    } else {
    this.basicUsers.put(player, null);
    player.sendMessage("The races are:" +
    "/Twisted Human" +
    "/Orc" +
    "/Amphuman" +
    "/Demon" +
    "/Goblin"); }
    }
    public boolean onCommand4(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    if (commandLabel.equalsIgnoreCase("Human"))
    toggleVision4((Player) sender);
    return false;
    }
    public void toggleVision4(Player player) {
    if (enabled(player)) {
    } else {
    this.basicUsers.put(player, null);
    player.sendMessage("The classes for Humans are:" +
    "/Knight" +
    "/Assassin" +
    "/Wizard" +
    "/Survivor"); }
    }
    public boolean onCommand5(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    if (commandLabel.equalsIgnoreCase("Troll"))
    toggleVision5((Player) sender);
    return false;
    }
    public void toggleVision5(Player player) {
    if (enabled(player)) {
    } else {
    this.basicUsers.put(player, null);
    player.sendMessage("The classes for Trolls are:" +
    "/Assassin" +
    "/Voodoo" +
    "/Brute"); }
    }
    public boolean onCommand6(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    if (commandLabel.equalsIgnoreCase("Merm"))
    toggleVision6((Player) sender);
    return false;
    }
    public void toggleVision6(Player player) {
    if (enabled(player)) {
    } else {
    this.basicUsers.put(player, null);
    player.sendMessage("The classes for Merms are:" +
    "/Runner" +
    "/Assassin" +
    "/Survivor" +
    "/Voodoo"); }
    }
    public boolean onCommand7(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    if (commandLabel.equalsIgnoreCase("Dwarf"))
    toggleVision7((Player) sender);
    return false;
    }
    public void toggleVision7(Player player) {
    if (enabled(player)) {
    } else {
    this.basicUsers.put(player, null);
    player.sendMessage("The classes for Dwarves are:" +
    "/Brute" +
    "/Survivor" +
    "/Knight"); }
    }
    public boolean onCommand8(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    if (commandLabel.equalsIgnoreCase("Elf"))
    toggleVision8((Player) sender);
    return false;
    }
    public void toggleVision8(Player player) {
    if (enabled(player)) {
    } else {
    this.basicUsers.put(player, null);
    player.sendMessage("The classes for Elves are:" +
    "/Knight" +
    "/Assassin" +
    "/Voodoo" +
    "/Runner"); }
    }
    public boolean onCommand9(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    if (commandLabel.equalsIgnoreCase("Orc"))
    toggleVision9((Player) sender);
    return false;
    }
    public void toggleVision9(Player player) {
    if (enabled(player)) {
    } else {
    this.basicUsers.put(player, null);
    player.sendMessage("The classes for Orcs are:" +
    "/Brute" +
    "/Voodoo" +
    "/Survivor"); }
    }
    public boolean onCommand10(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    if (commandLabel.equalsIgnoreCase("Twisted Human"))
    toggleVision10((Player) sender);
    return false;
    }
    public void toggleVision10(Player player) {
    if (enabled(player)) {
    } else {
    this.basicUsers.put(player, null);
    player.sendMessage("The classes for Twisted Humans are:" +
    "/Knight" +
    "/Wizard" +
    "/Voodoo" +
    "/Survivor"); }
    }
    public boolean onCommand11(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    if (commandLabel.equalsIgnoreCase("Amphuman"))
    toggleVision11((Player) sender);
    return false;
    }
    public void toggleVision11(Player player) {
    if (enabled(player)) {
    } else {
    this.basicUsers.put(player, null);
    player.sendMessage("The classes for Amphumans are:" +
    "/Assassin" +
    "/Voodoo" +
    "/Runner" +
    "/Survivor"); }
    }
    public boolean onCommand12(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    if (commandLabel.equalsIgnoreCase("Demon"))
    toggleVision12((Player) sender);
    return false;
    }
    public void toggleVision12(Player player) {
    if (enabled(player)) {
    } else {
    this.basicUsers.put(player, null);
    player.sendMessage("The classes for Demons are:" +
    "/Voodoo" +
    "/Assassin" +
    "/Runner"); }
    }
    public boolean onCommand13(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    if (commandLabel.equalsIgnoreCase("Goblin"))
    toggleVision13((Player) sender);
    return false;
    }
    public void toggleVision13(Player player) {
    if (enabled(player)) {
    } else {
    this.basicUsers.put(player, null);
    player.sendMessage("The classes for Goblins are:" +
    "/Voodoo" +
    "/Assassin" +
    "/Runner" +
    "/Survivor"); }
    }


    @Override
    public void onDisable() {
    // TODO Auto-generated method stub
    }

    @Override
    public void onEnable() {
    // TODO Auto-generated method stub
    }
    }

    Our plugin.yml:

    name: UltimateRPG
    main: me.groganers.ultimaterpg.UltimateRPG
    version: 0.3.1
    author: Groganer

    commands:
    URPG Help:
    description: Shows the Races list.
    usage: /URPG Help
    Silverblade:
    description: The good faction.
    usage: /Silverblade
    Human:
    description: The human race.
    usage: /Human
    Knight:
    description: A knight class.
    usage: /Knight
    Assassin:
    description: An assassin class.
    usage: /Assassin
    Wizard:
    description: A wizard class.
    usage: /Wizard
    Survivor:
    description: A survivor class.
    usage: /Survivor
    Troll:
    description: A troll race.
    usage: /Troll
    Assassin:
    description: An assassin class.
    usage: /Assassin
    Voodoo:
    description: A voodoo class.
    usage: /Voodoo
    Brute:
    description: A brute class.
    usage: /Brute
    Merm:
    description: A merm race.
    usage: /Merm
    Runner:
    description: A runner class.
    usage: /Runner
    Assassin:
    description: An assassin class.
    usage: /Assassin
    Survivor:
    description: A survivor class.
    usage: /Survivor
    Voodoo:
    description: A voodoo class.
    usage: /Voodoo
    Dwarf:
    description: A dwarf race.
    usage: /Dwarf
    Brute:
    description: A brute class.
    usage: /Brute
    Survivor:
    description: A survivor class.
    usage: /Survivor
    Knight:
    description: A knight class.
    usage: /Knight
    Elf:
    description: An elf race.
    usage: /Elf
    Knight:
    description: A knight class.
    usage: /Knight
    Assassin:
    description: An assassin class.
    usage: /Assassin
    Voodoo:
    description: A voodoo class.
    usage: /Voodoo
    Runner:
    description: A runner class.
    usage: /Runner
    Silverpalm:
    description: The evil faction.
    usage: /Silverpalm
    Orc:
    description: An orc race.
    usage: /Orc
    Brute:
    description: A brute class.
    usage: /Brute
    Voodoo:
    description: A voodoo class.
    usage: /Voodoo
    Survivor:
    description: A survivor class.
    usage: /Survivor
    Twisted Human:
    description: A Twisted Human race.
    usage: /Twisted Human
    Knight:
    description: A knight class.
    usage: /Knight
    Wizard:
    description: A wizard class.
    usage: /Wizard
    Voodoo:
    description: A voodoo class.
    usage: /Voodoo
    Survivor:
    description: A survivor class.
    usage: /Survivor
    Amphuman:
    description: An amphuman race.
    usage: /Amphuman
    Assassin:
    description: An assassin class.
    usage: /Assassin
    Voodoo:
    description: A voodoo class.
    usage: /Voodoo
    Runner:
    description: A runner class.
    usage: /Runner
    Survivor:
    description: A survivor class.
    usage: /Survivor
    Demon:
    description: A demon race.
    usage: /Demon
    Voodoo:
    description: A voodoo class.
    usage: /Voodoo
    Assassin:
    description: An assassin class.
    usage: /Assassin
    Runner:
    description: A runner class.
    usage: /Runner
    Goblin:
    description: A Goblin race.
    usage: /Goblin
    Voodoo:
    description: A voodoo class.
    usage: /Voodoo
    Assassin:
    description: An assassin class.
    usage: /Assassin
    Runner:
    description: A runner class.
    usage: /Runner
    Survivor:
    description: A survivor class.
    usage: /Survivor

    Please help, we really want this plugin to work.
     
  2. Offline

    TheTrixsta

    well do you have 2 classes??

    you have 2 onEnable and onDisables in one class

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 17, 2016
  3. Offline

    Groganer

    Where did that come from?! What do?
     
  4. Offline

    bassfader

    Code:
    TODO Auto-generated method stub
    That comment tells me you are using Eclipse or some similar IDE and it generated these method's automatically for you after you added "extends JavaPlugin" and chose to correct a error which would be highlighting you're Main Class's definition red.

    What to do? Delete the 2 empty onEnable and onDisable methods and you should be good to go ;) (Haven't checked the rest of the code though, just scanned it quickly ^^)
     
  5. Offline

    Groganer

    Ok, I've gotten rid of the last onEnable and onDisable sections. The only problem now is that "public class UltimateRPG extends JavaPlugin {" on line 14, UltimateRPG is highlighted red with the error:
    The type UltimateRPG must implement the inherited abstract method Plugin.onEnable()
     
  6. Offline

    bassfader

    Yes you have to rename you're methods: Its not
    public void onEnabled()
    but its
    public void onEnable()

    (The same for your onDisabled() method)
     
  7. Offline

    Groganer

    Ok it says enabled! :D
     
  8. It works but it doesn't say what it's meant to but says the command and /URPG Help doesn't work
     
  9. Offline

    Groganer

    Basically, type /Silverblade
    We get "/Silverblade" Pop up in chat.
     
  10. It's worked but it does'nt say what it is meant to to the player it just repeats the command said and /URPG Help doesn't work, can you help bassfader?
     
  11. Offline

    bassfader

    I'll try my best :) But (if you have got any more questions and the following suggestion doesnt help) could you please post you're code in a {PHP} {/PHP} Tag (replace the {} with []) or upload it anywhere to download, this would make reading the code much much easier ;) Its pretty much a pain in the a... currently to pick out some errors in the code ^^

    Okay well... that's going to be a long post xD Here's what I noticed so far:
    • You did not register the commands
    • You haven't got a CommandHandler class (which would make things much more organized) but have all Command Handling in you're main class
    • You have multiple onCommandX() methods (where X is a number), but you need only one onCommand() method which handles all the commands

    I know it's a bit of work, but I'd suggest you to do the following:



    1. Create a CommandHandler Class
    It should look something like the following but be aware of this:
    • replace the xyz in front of the class name to urpg or something like that (not neccessary but would be "cleaner")
    • replace "commandA" etc.. with you're commands and put all command processing stuff here, or call a function in you're main plugin's class that handles the command stuff (one method for each command)
    PHP:
    public class xyzCommandHandler implements CommandExecutor {
        private final 
    UltimateRPG  plugin;
        
        public 
    xyzCommandHandler(UltimateRPG  instance)
        {
            
    this.plugin instance;
        }
        
        public 
    boolean onCommand(CommandSender senderCommand cmdString commandLabelString[] args)
        {
            if (
    cmd.getName().equalsIgnoreCase("commandA")) 
            {
                    
    // Do something with you're command
                    
    return true;
            }

            
            if (
    cmd.getName().equalsIgnoreCase("commandB")) 
             {
                    
    // Do something with you're command
                    
    return true;
            }

            
            ....

            return 
    false;
        }



    2. Register you're commands in you're main Class's onEnable() method
    Copy the following function into you're main class, but be aware of the following:
    • replace"xyzCommandHandler" with you're CommandHandler Class's Name you created in step 1
    PHP:
        private void registerCommand(String command)
        {
            try
            {
                
    getCommand(command).setExecutor(new xyzCommandHandler(this));

            } catch (
    Exception ex)
            {
                
    log.warning(getNameBrackets() + "Failed to register command '" command "'! Is it allready used by some other Plugin?");
            }
        }
    Then register you're commands like the following in the onEnable() method:
    PHP:
    ....
    registerCommand("URPG");
    registerCommand("Silverblade");
    registerCommand("Human");
    ....


    That should make the command handling work ;) Also I'd highly recommend you reading the following tutorial which covers pretty much any aspect of Plugin Coding for Bukkit:
    http://wiki.bukkit.org/HUGE_Plugin_Tutorial
     
  12. I dont have the files but Groganer will upload at 8:00, 9:00 your time.

    Thats if your in Germany

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 17, 2016
  13. Offline

    bassfader

    Yeah I am from Germany and also currently in Germany so it's good. But do you mean tomorrow in the morning? I am not up that early (I am on vecation at the moment) so it might be 12am or something like that till I take a look into this forums ;)
     
  14. Offline

    Groganer

    Ok, gonna look at it now :L
     
Thread Status:
Not open for further replies.

Share This Page