Solved my plugin would load on server

Discussion in 'Plugin Development' started by Mystic4phoenix, Mar 24, 2017.

Thread Status:
Not open for further replies.
  1. where did i go wrong?
    why will it not load?
    the .java code
    Code:
    package me.Mystic4phoenix.aurorafalls;
    
    import java.util.logging.Logger;
    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 aurorafalls extends JavaPlugin {
        public final Logger logger = Logger.getLogger("Minecraft");
        public static aurorafalls plugin;
     
        @Override
        public void onDisable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + "has failed!");
        }
        @Override
        public void onEnable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " loaded was successful");
        }
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            Player player = (Player) sender;
            if(commandLabel.equalsIgnoreCase("test")){
                player.sendMessage("test posative");
            }
            return false;
        }
    }
    the .yml code
    Code:
    name: aurora-falls
    main: me.Mystic4phoenix.aurorafalls
    version: 1.0 alpha
    description: >
                 RPG Plugin.
    commands:
        test:
          description: test plugin
     
  2. Offline

    timtower Administrator Administrator Moderator

    Moved to plugin development
    @Mystic4phoenix Add the main class name to the main in the plugin.yml
    Don't log your own plugins like that.
    Don't use the minecraft logger.
    Remove that static stuff.
    Please follow java naming conventions.
    You are casting the sender to player before checking if it is one.
     
  3. Offline

    Zombie_Striker

    @Mystic4phoenix
    1. Make sure your class name starts with an uppercase letter.
    2. Make sure your package is all lower case (make Mystic lower case)
    3. Don't use commandlabel. Instead, use cmd.getName().
    4. You do not need the plugin's instance in your class. You are not referencing any other classes, and even if you were, using static is not the way you should do it.
    5. The description should be on the same line.
     
  4. 1)I'm not following in new to this and how do I add my class to the plugin.yml
    2)The plugins for 1.11.2 server
    3)how do you change an package name in eclipse
    4)how do you change an class name in eclipse
    5)the cast is incomplete I'm working on that
    6)the statistic is not needed ? why?
     
    Last edited: Mar 24, 2017
  5. Offline

    Caderape2

    @Mystic4phoenix
    main: me.Mystic4phoenix.aurorafalls
    You are just specifing the package name, not the class to start with.
     
  6. Offline

    yPedx

    To change package name, right click it and select "refractor" then select "rename"
    You do the same for the class as for the package to rename.

    As @Zombie_Striker said;
    You have an invalid main in your plugin.yml. Set it to what I wrote
    If: me.Mystic4phoenix.aurorafalls; is your main, put that in the top of your plugin.yml like;
    main:
    me.mystic4phoenix.aurorafalls; // No upper cases
    If thats what you mean by putting your class in the plugin.yml?

    Also you don't need the;
    PluginDescriptionFile pdfFile = this.getDescription();
    this.logger.info(pdfFile.getName() + "has failed!");

    Isn't having onDisable() before onEnable() the wrong thing here maybe?
     
    Last edited: Mar 24, 2017
  7. how do you add the class to the plugin.yml
     
  8. Offline

    Zombie_Striker

    Add the class name to the path, so it should be

    me.mystic4phoenix.aurorafalls.Aurorafalls

    Note that I fixed the capitalization.
    Why should this matter? These changes should be done regardless of the server version.

    Right click the class or package in the explorerer, click refractor, click rename, and rename them.

    Static objects are single objects that belong to the Class, not the object. Because of that, there can be only be one instance of the object, which goes against what OOP should be. Not only that, but the garbage collector does not handle static objects well. Unless you make sure you clear the object on reloads, those objects will stay in memory even though they can no longer be accessed.

    Not only this, but static in general is useless in Java. Almost everything that can be done using static objects can be done better by just using getters and setters.
     
  9. and how do i do that

    package me.mystic4phoenix.aurorafalls;

    import java.util.logging.Logger;
    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 Aurorafalls extends JavaPlugin {
    public final Logger logger = Logger.getLogger("Minecraft");

    @Override
    public void onDisable() {
    PluginDescriptionFile pdfFile = this.getDescription();
    this.logger.info(pdfFile.getName() + "has failed!");
    }
    @Override
    public void onEnable() {
    PluginDescriptionFile pdfFile = this.getDescription();
    this.logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " loaded was successful");
    }
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    Player player = (Player) sender;
    if(commandLabel.equalsIgnoreCase("test")){
    player.sendMessage("test posative");
    }
    return false;
    }
    }
    like this?

    C:\Users\-------\Desktop\test server>java -Xmx2048M -Xms2048M -jar craftbukkit.1.11.2.jar
    Loading libraries, please wait...
    [17:27:58 INFO]: Starting minecraft server version 1.11.2
    [17:27:58 INFO]: Loading properties
    [17:27:58 INFO]: Default game type: SURVIVAL
    [17:27:58 INFO]: Generating keypair
    [17:27:58 INFO]: Starting Minecraft server on *:25565
    [17:27:58 INFO]: Using default channel type
    [17:27:59 INFO]: This server is running CraftBukkit version git-Bukkit-91c3152 (MC: 1.11.2) (Implementing API version 1.11.2-R0.1-SNAPSHOT)
    [17:27:59 ERROR]: Could not load 'plugins\Aurorafalls(pre-alpha).jar' in folder 'plugins'
    org.bukkit.plugin.InvalidDescriptionException: Invalid plugin.yml
    at org.bukkit.plugin.java.JavaPluginLoader.getPluginDescription(JavaPluginLoader.java:160) ~[craftbukkit.1.11.2.jar:git-Bukkit-91c3152]
    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:133) [craftbukkit.1.11.2.jar:git-Bukkit-91c3152]
    at org.bukkit.craftbukkit.v1_11_R1.CraftServer.loadPlugins(CraftServer.java:298) [craftbukkit.1.11.2.jar:git-Bukkit-91c3152]
    at org.bukkit.craftbukkit.v1_11_R1.CraftServer.<init>(CraftServer.java:260) [craftbukkit.1.11.2.jar:git-Bukkit-91c3152]
    at net.minecraft.server.v1_11_R1.PlayerList.<init>(PlayerList.java:73) [craftbukkit.1.11.2.jar:git-Bukkit-91c3152]
    at net.minecraft.server.v1_11_R1.DedicatedPlayerList.<init>(SourceFile:14) [craftbukkit.1.11.2.jar:git-Bukkit-91c3152]
    at net.minecraft.server.v1_11_R1.DedicatedServer.init(DedicatedServer.java:185) [craftbukkit.1.11.2.jar:git-Bukkit-91c3152]
    at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:521) [craftbukkit.1.11.2.jar:git-Bukkit-91c3152]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_121]
    Caused by: org.yaml.snakeyaml.scanner.ScannerException: while scanning a simple key
    in 'reader', line 4, column 1:
    description:> RPG Plugin.
    ^
    could not find expected ':'
    in 'reader', line 5, column 1:
    commands:
    ^

    at org.yaml.snakeyaml.scanner.ScannerImpl.stalePossibleSimpleKeys(ScannerImpl.java:465) ~[craftbukkit.1.11.2.jar:git-Bukkit-91c3152]
    at org.yaml.snakeyaml.scanner.ScannerImpl.needMoreTokens(ScannerImpl.java:280) ~[craftbukkit.1.11.2.jar:git-Bukkit-91c3152]
    at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:225) ~[craftbukkit.1.11.2.jar:git-Bukkit-91c3152]
    at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingKey.produce(ParserImpl.java:557) ~[craftbukkit.1.11.2.jar:git-Bukkit-91c3152]
    at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:157) ~[craftbukkit.1.11.2.jar:git-Bukkit-91c3152]
    at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:147) ~[craftbukkit.1.11.2.jar:git-Bukkit-91c3152]
    at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:224) ~[craftbukkit.1.11.2.jar:git-Bukkit-91c3152]
    at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:155) ~[craftbukkit.1.11.2.jar:git-Bukkit-91c3152]
    at org.yaml.snakeyaml.composer.Composer.composeDocument(Composer.java:122) ~[craftbukkit.1.11.2.jar:git-Bukkit-91c3152]
    at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:105) ~[craftbukkit.1.11.2.jar:git-Bukkit-91c3152]
    at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:120) ~[craftbukkit.1.11.2.jar:git-Bukkit-91c3152]
    at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:450) ~[craftbukkit.1.11.2.jar:git-Bukkit-91c3152]
    at org.yaml.snakeyaml.Yaml.load(Yaml.java:381) ~[craftbukkit.1.11.2.jar:git-Bukkit-91c3152]
    at org.bukkit.plugin.PluginDescriptionFile.<init>(PluginDescriptionFile.java:232) ~[craftbukkit.1.11.2.jar:git-Bukkit-91c3152]
    at org.bukkit.plugin.java.JavaPluginLoader.getPluginDescription(JavaPluginLoader.java:155) ~[craftbukkit.1.11.2.jar:git-Bukkit-91c3152]
    ... 8 more
    [17:27:59 INFO]: Preparing level "world"
    [17:27:59 INFO]: Preparing start region for level 0 (Seed: -1633073754192012120)
    [17:28:00 INFO]: Preparing spawn area: 29%
    [17:28:01 INFO]: Preparing start region for level 1 (Seed: -1633073754192012120)
    [17:28:02 INFO]: Preparing spawn area: 88%
    [17:28:02 INFO]: Preparing start region for level 2 (Seed: -1633073754192012120)
    [17:28:03 INFO]: Server permissions file permissions.yml is empty, ignoring it
    [17:28:03 INFO]: Done (4.007s)! For help, type "help" or "?"
    whats wrong with it?
     
    Last edited: Mar 24, 2017
  10. Offline

    yPedx

    Change this:
    Code:
    package me.mystic4phoenix.aurorafalls;
    
    import java.util.logging.Logger;
    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 Aurorafalls extends JavaPlugin {
        public final Logger logger = Logger.getLogger("Minecraft");
        @Override
        public void onDisable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + "has failed!");
        }
        @Override
        public void onEnable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " loaded was successful");
        }
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            Player player = (Player) sender;
            if(commandLabel.equalsIgnoreCase("test")){
                player.sendMessage("test posative");
            }
            return false;
        }
    }
    to this:
    Code:
    package me.mystic4phoenix.aurorafalls;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class aurorafalls extends JavaPlugin implements CommandExecutor{
        @Override
        public void onEnable() {
        }
     
        @Override
        public void onDisable() {
        }
        public boolean onCommand(CommandSender sender, Command cmd, String Label, String[] args){
            Player player = (Player) sender;
            if(cmd.getName().equalsIgnoreCase("test")) {
                player.sendMessage("test posative");
            }
            return false;
        }
    }
    And your plugin.yml to:
    Code:
    name: aurora-falls
    main: me.mystic4phoenix.aurorafalls.aurorafalls
    version: 1.0 alpha
    description: >
                 RPG Plugin.
    commands:
        test:
          description: test plugin
    This should fix your problem :) I tested it myself and it worked.
     
  11. i coped the code but it did [17:39:23 ERROR]: Could not load 'plugins\Aurorafalls(pre-alpha).jar' in folder 'plugins'
     
  12. Offline

    Zombie_Striker

    @Mystic4phoenix
    There should be more to that error. Can you post the full error log?

    @yPedx
    1. The onEnable and onDisable do nothing, so those methods could be removed
    2. You are still blindly casting sender to a player. What if a console sends the command? What if its a plugin or a command block? All those things are not players, so this would throw a ClassCastException. Do an instanceof check before creating player.
     
  13. how do you change it ?
     
  14. Offline

    yPedx

    You mean the Player player = (Player) sender; ?
     
  15. THANKS TO ALL OF YOU IT WORKS :D
     
  16. Offline

    Zombie_Striker

Thread Status:
Not open for further replies.

Share This Page