Development Assistance Console Error -Solved-

Discussion in 'Plugin Help/Development/Requests' started by SkyLarkPvP, Dec 10, 2014.

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

    SkyLarkPvP

    Hey, so i made a plugin that clears the custom name of an item, it's working fine but i'm getting an error on the console.

    Core.java
    Code:
    package me.Jacksparrow3007.sExtras.core;
    
    import java.util.logging.Logger;
    
    import me.Jacksparrow3007.sExtras.commands.Commands;
    import me.Jacksparrow3007.sExtras.listeners.Listeners;
    
    import org.bukkit.permissions.Permission;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Core extends JavaPlugin{
        public final Logger logger = Logger.getLogger("Minecraft");
        public static Core plugin;
        private PluginManager pm;
        public Permission clearname = new Permission("clearname.use");
      
        @Override
        public void onEnable() {
        PluginDescriptionFile pdfFile = this.getDescription();
        this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " Has Been Enabled!");
        getServer().getPluginManager().registerEvents(new Listeners(this), this);
        this.getCommand("clearname").setExecutor(new Commands(this));   
        pm.addPermission(clearname); 
        }
        @Override
        public void onDisable() {
        PluginDescriptionFile pdfFile = this.getDescription();
        this.logger.info(pdfFile.getName() + " Has Been Disabled!");
    
        }}
        }}
    (The registering of events at the end of onEnable is for another class in my plugin that has nothing to do with this command).

    Commands.java
    Code:
    package me.Jacksparrow3007.sExtras.commands;
    
    import me.Jacksparrow3007.sExtras.core.Core;
    
    import org.bukkit.Color;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public class Commands implements CommandExecutor{
      
        @SuppressWarnings("unused")
        private Core plugin;
        public Commands(Core plugin) {
            this.plugin = plugin;
        }
         public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            Player p = (Player)sender;
           if(cmd.getName().equalsIgnoreCase("clearname")) {
           if(p.hasPermission("clearname.use") || p.isOp()) {
           } else {
              p.sendMessage(Color.RED + "You don't have permission!");
              return true;
           }
            ItemStack item = p.getItemInHand();
           if (item == null) {
             p.sendMessage("Please hold an item to remove the custom name from it");
             return true;
           }
           if (!item.hasItemMeta()) {
             p.sendMessage("Item doesn't have a custom name");
             return true;
           }
           ItemMeta meta = item.getItemMeta();
           if (!meta.hasDisplayName()) {
             p.sendMessage("Item doesn't have a custom name");
             return true;
           }
           meta.setDisplayName(null);
           item.setItemMeta(meta);
           p.updateInventory();
           p.sendMessage("Custom name removed");
           return true;
    
    }
            return true;}}
    
    
    Plugin.yml:
    Code:
    name: sExtras
    version: 1.0
    main: me.Jacksparrow3007.sExtras.core.Core
    author: Jacksparrow3007
    description: SkyLarkPvP Extras.
    commands:
      clearname:
        description: Clear Custom Item Name Command.
        usage: /<command>
        aliases: [realname, unname, removename]
    permissions:
      clearname.use:
        description: Permission to use the clearname command!
        default: op
    Console Error:
    Code:
    [23:35:22 ERROR]: Error occurred while enabling sExtras v1.0 (Is it up to date?)
    
    java.lang.NullPointerException
            at me.Jacksparrow3007.sExtras.core.Core.onEnable(Core.java:25) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:316) ~[c
    raftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader
    .java:332) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManage
    r.java:412) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugin(CraftServer.jav
    a:476) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.enablePlugins(CraftServer.
    java:394) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
            at net.minecraft.server.v1_7_R4.MinecraftServer.n(MinecraftServer.java:3
    60) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
            at net.minecraft.server.v1_7_R4.MinecraftServer.g(MinecraftServer.java:3
    34) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
            at net.minecraft.server.v1_7_R4.MinecraftServer.a(MinecraftServer.java:2
    90) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
            at net.minecraft.server.v1_7_R4.DedicatedServer.init(DedicatedServer.jav
    a:210) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
            at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java
    :458) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
            at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:6
    28) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    Thanks for reading this, any suggestions on how to fix this would be greatly appreciated! :)
     
    Last edited: Dec 10, 2014
  2. Offline

    JordyPwner

    Did you registered it? also use cmd.getname() instead of cmd.Label
     
  3. Offline

    SkyLarkPvP

    How would you register commands? I thought you could only do that with events?
     
  4. Offline

    Skionz

  5. Offline

    Unica

    @SkyLarkPvP
    Code:
    getCommand('command').setExecutor(NewObjectOfTheClassHere);
     
    Last edited by a moderator: Dec 10, 2014
  6. Offline

    leon3001

    Well, you don't register the command, you set its executor. So, well, it's not that accurate. :p
     
  7. Offline

    SkyLarkPvP

    Well, i searched how to register commands before Unica had posted that, thanks for the help anyways. And I'll try to fix up my code. So now it works, but now i'm getting an error from line 25 in Core.java, I'll update the changes that i added to the core.java and the commands.java and post the error soon.

    EDIT: Updated details
     
    Last edited: Dec 10, 2014
  8. Online

    timtower Moderator Moderator

  9. Offline

    SkyLarkPvP

  10. Offline

    JordyPwner

    is it working already?
     
  11. Offline

    SkyLarkPvP

    It now works, its just now i get a console error.
     
  12. Offline

    JordyPwner

    please post the error with the code :p
     
  13. Offline

    SkyLarkPvP

    I've updated the thread, look at the console error.
     
  14. Offline

    JordyPwner

    Please tagh me next time if you want me to get a notification that you replied :)
    Also what is on line 25?
     
  15. Offline

    SkyLarkPvP

    @JordyPwner
    Line 25 on Core.java:
    Code:
    pm.addPermission(clearname); 
     
  16. Offline

    leon3001

    @SkyLarkPvP You never get the pm variable, you just declare it hence it's null.
     
  17. Offline

    Skionz

  18. Offline

    SkyLarkPvP

    Line 16 Core.java
    Code:
    private PluginManager pm;
    Does this count?

    Sorry, but I'm not sure what you mean by that (I'm pretty new at coding)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 29, 2016
  19. Offline

    Skionz

    @SkyLarkPvP You declared 'pm' but you never initialized it. Use google
     
  20. Offline

    leon3001

    You declare the variable but you don't tell compiler where to get the PluginManger variable from. Use PluginManager pm = Bukkit.getPluginManager(); instead.
     
  21. Online

    timtower Moderator Moderator

    Moved to Bukkit alternatives
     
  22. Offline

    SkyLarkPvP

    @leon3001 @Skionz
    Ok, its now telling me that I've registered the permission "clearname.use" twice in the console, and im not really sure where I did that.
    Code:
    [00:46:50 WARN]: Plugin sExtras v1.0 tried to register permission 'clearname.use
    ' but it's already registered
    java.lang.IllegalArgumentException: The permission clearname.use is already defi
    ned!
            at org.bukkit.plugin.SimplePluginManager.addPermission(SimplePluginManag
    er.java:606) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugin(CraftServer.jav
    a:482) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.enablePlugins(CraftServer.
    java:394) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
            at net.minecraft.server.v1_7_R4.MinecraftServer.n(MinecraftServer.java:3
    60) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
            at net.minecraft.server.v1_7_R4.MinecraftServer.g(MinecraftServer.java:3
    34) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
            at net.minecraft.server.v1_7_R4.MinecraftServer.a(MinecraftServer.java:2
    90) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
            at net.minecraft.server.v1_7_R4.DedicatedServer.init(DedicatedServer.jav
    a:210) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
            at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java
    :458) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
            at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:6
    28) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
     
  23. Offline

    Skionz

  24. Offline

    SkyLarkPvP

    I'm not sure, i assume i have.
    Heres the Core.java:
    Code:
    package me.Jacksparrow3007.sExtras.core;
    
    import java.util.logging.Logger;
    
    import me.Jacksparrow3007.sExtras.commands.Commands;
    import me.Jacksparrow3007.sExtras.listeners.Listeners;
    
    import org.bukkit.Bukkit;
    import org.bukkit.permissions.Permission;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Core extends JavaPlugin{
        public final Logger logger = Logger.getLogger("Minecraft");
        public static Core plugin;
        PluginManager pm = Bukkit.getPluginManager();
        public Permission clearname = new Permission("clearname.use");
       
        @Override
        public void onEnable() {
        PluginDescriptionFile pdfFile = this.getDescription();
        this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " Has Been Enabled!");
        getServer().getPluginManager().registerEvents(new Listeners(this), this);
        this.getCommand("clearname").setExecutor(new Commands(this));   
        pm.addPermission(clearname);  
        }
        @Override
        public void onDisable() {
        PluginDescriptionFile pdfFile = this.getDescription();
        this.logger.info(pdfFile.getName() + " Has Been Disabled!");
    
        }}
     
  25. Offline

    Skionz

  26. Offline

    SkyLarkPvP

    @Skionz
    Ok, I'll do that when i wake up, thanks for helping me! :)

    I managed to get it working, the variable of the permission was the same as the command name. Thanks for the help!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 29, 2016
Thread Status:
Not open for further replies.

Share This Page