NEED HELP WITH ERROR WHEN LOADING PLUGIN ON SERVER

Discussion in 'WIP and Development Status' started by lionking23, Jul 19, 2011.

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

    lionking23

    Hey, I was trying to make a simple UnlimitedHealth plugin, when it said the "main is not defined." Could someone please tell me what's wrong? I also have a feeling I might be missing something big in the code... just letting you know, I'm sort of a Java noob. :p
    PLEASE HELP!

    Code:
    18:11:45 [SEVERE] Could not load 'plugins/UnlimitedHealth1.0.jar' in folder 'plugins': main is not defined
    org.bukkit.plugin.InvalidDescriptionException: main is not defined
        at org.bukkit.plugin.PluginDescriptionFile.loadMap(PluginDescriptionFile.java:168)
        at org.bukkit.plugin.PluginDescriptionFile.<init>(PluginDescriptionFile.java:31)
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:69)
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:199)
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:122)
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:118)
        at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:89)
        at net.minecraft.server.ServerConfigurationManager.<init>(ServerConfigurationManager.java:51)
        at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:132)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:335)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:422)
    
     
  2. Offline

    loganwm

    What does your plugin.yml file look like?
     
  3. Offline

    lionking23

    Here :p
    Code:
    name: UnlimitedHealth
    package: me.lionking23.UnlimitedHealth.UnlimitedHealth
    version: 1.0
    Is there more I have to add?
     
  4. Offline

    loganwm

    You need to add a line defining the plugin class to load. Here's the line you need to add (although, it points to a different startup class than the one I specified for you)

    Code:
    main: me.loganwm.ApocalypseCraft.ApocalypseCraftPlugin
     
  5. Offline

    lionking23

    Cool, but now it doesn't show anything in the console on startup, anyways, i think i might be able to figure that out on my own :) thanks! by the way, I saw ur ApocalypseCraft plugin you're working on, really great! can't wait till it's done!
     
  6. Offline

    loganwm

    I appreciate the interest, and if you need any more help getting started, feel free to ask. I'm almost always willing and able to help.
     
  7. Offline

    lionking23

    thanks, will do!

    Hey, for my plugin, do you know what code I could use to make a command to initialize the inviniciblity? I looked around but a lot of different source codes had a lot of different stuff and i got confused.

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

    loganwm

    I
    I haven't yet coded invincibility in anything that I've worked on, but my best guess would be to hook into the onEntityDamage or onPlayerDamage event, then cancel it if the circumstances are correct (meaning that the target of the damage is a player who should be invincible.)
     
  9. Offline

    lionking23

    Yeah, so a public boolean onCommand() method should work for that?
     
  10. Offline

    loganwm

    What you would do is define some sort of variable to determine whether a player is invincible or not, and have the variable changeable using a command.

    Then, based on the value of the player-invincibility variable, you would decide in the onEntityDamage listener whether to cancel the event (and by extension, the damage) or to allow the damage.
     
  11. Offline

    lionking23

    okay, thanks!

    This is the code i put in for the commands, hopefully it is correct?
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            if(cmd.getName().equalsIgnoreCase("god")){ // If the player typed /god then do the following...
                    if(event.getEntity() instanceof Player){
                        event.setCancelled(true); // This cancels the damage to player.
                    return true;
                    }return false;
            }if(cmd.getName().equalsIgnoreCase("ungod")){ // If the player typed /ungod then do the following...
                if(event.getEntity() instanceof Player){
                    event.setCancelled(false); //This doesn't cancel damage to player.
                    return true;
                }
            }return false;
    
        }
    Here is what i have in my plugin.yml:

    Code:
    name: UnlimitedHealth
    package: me.lionking23.UnlimitedHealth.UnlimitedHealth
    main: me.lionking23.UnlimitedHealth.UnlimitedHealth
    version: 1.1
    commands:
        god:
            Description: Unlimited health! WOOT!
            Usage: |
                /god
        ungod:
            Description: No unlimited health... :(
            Usage: |
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 17, 2016
  12. Offline

    loganwm

    You can't cancel the entity damage event from inside the onCommand event. You're going to need to create an entity listener. Do you know how to do that or do you need me to guide you through it?
     
  13. Offline

    lionking23

    I don't entirely understand :confused:

    Ooo wait.. sorry if you already started on a reply, but i didn't show all my code in that class:

    Code:
    package me.lionking23.UnlimitedHealth;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.entity.EntityDamageEvent;
    import org.bukkit.event.entity.EntityListener;
    
    public class UnlimitedHealthEntityListener extends EntityListener {
    
        public static UnlimitedHealth plugin;
        public EntityDamageEvent event;
         
        public UnlimitedHealthEntityListener(UnlimitedHealth instance) {
            plugin = instance;
        }
      
        public void onEntityDamage(EntityDamageEvent event){
    
            if(event.getEntity() instanceof Player){
                event.setCancelled(true);
     
            }
        }
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            if(cmd.getName().equalsIgnoreCase("god")){ // If the player typed /god then do the following...
                    if(event.getEntity() instanceof Player){
                        event.setCancelled(true);
                    return true;
                    }return false;
            }if(cmd.getName().equalsIgnoreCase("ungod")){ // If the player typed /ungod then do the following...
                if(event.getEntity() instanceof Player){
                    event.setCancelled(false);
                    return true;
                }
            }return false;
    
        }
      
    }
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 17, 2016
  14. Offline

    loganwm

    Your command shouldn't actually be executed at all to the best of my knowledge. The onCommand event must exist in a class that extends CommandExecutor and it must be set as an executor for a command.

    Have you ever used commands in Bukkit programming before?
     
  15. Offline

    DrBowe

    Actually, (to my knowledge) it can be executed just about anywhere. Most people prefer placing it in a CommandExecutor, to keep their main class neat, but nothing's wrong with placing onCommand inside your main class.
     
  16. Offline

    loganwm

    I'm still relatively new to the way Bukkit does things (though I've been programming for years). I wasn't aware of that, but that's interesting indeed.
     
  17. Offline

    lionking23

    I tried to launch my plugin when another error occurred which I think is a problem with my plugin.yml?

    the error:
    Code:
    17:47:44 [SEVERE] Could not load 'plugins/UnlimitedHealth1.1.jar' in folder 'plugins':
    while scanning for the next token
    found character     '\t' that cannot start any token
     in "<reader>", line 6, column 1:
            god:
        ^
    
        at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:360)
        at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:183)
        at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingValue.produce(ParserImpl.java:592)
        at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:163)
        at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:148)
        at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:132)
        at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:230)
        at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:160)
        at org.yaml.snakeyaml.composer.Composer.composeDocument(Composer.java:122)
        at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:105)
        at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:124)
        at org.yaml.snakeyaml.Yaml.load(Yaml.java:264)
        at org.yaml.snakeyaml.Yaml.load(Yaml.java:250)
        at org.bukkit.plugin.PluginDescriptionFile.<init>(PluginDescriptionFile.java:31)
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:69)
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:199)
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:122)
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:118)
        at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:89)
        at net.minecraft.server.ServerConfigurationManager.<init>(ServerConfigurationManager.java:51)
        at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:132)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:335)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:422)

    my plugin.yml
    Code:
    name: UnlimitedHealth
    package: me.lionking23.UnlimitedHealth.UnlimitedHealth
    main: me.lionking23.UnlimitedHealth.UnlimitedHealth
    version: 1.1
    commands:
        god:
            Description: Unlimited health! WOOT!
            Usage: |
                /god
        ungod:
            Description: No unlimited health... :(
            Usage: |
               /ungod
    
     
  18. Offline

    loganwm

    Use spaces when editing yaml. Don't use tabs. Yaml hates tabs.
     
  19. Offline

    lionking23

    does the onCommand method have to be in the main class if not in a class with CommandExecutor?
     
  20. Offline

    DrBowe

    It doesn't have to be, but that's generally where you'd put it (if not in a separate CommandExecutor)
     
  21. Offline

    lionking23

    I actually put it in my EntityListener class and when I try to run it on my server and type /god in the console, it doesn't work, i replaced the tabs in my plugin.yml with spaces too.
     
Thread Status:
Not open for further replies.

Share This Page