Error that is weird

Discussion in 'Plugin Development' started by PizzaPixel, Mar 24, 2014.

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

    PizzaPixel

    On my server console i get an error ponting at this line
    Code:
    Scoreboard sBoard = sbManager.getNewScoreboard();
    Here is my error

    Code:
    Could not load 'plugins/ZeRealCTO.jar' in folder 'plugins'
     
    org.bukkit.plugin.InvalidPluginException: java.lang.NullPointerException
     
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:182) ~[spigot.jar:git-Spigot-1223]
     
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:309) ~[spigot.jar:git-Spigot-1223]
     
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:231) [spigot.jar:git-Spigot-1223]
     
        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugins(CraftServer.java:259) [spigot.jar:git-Spigot-1223]
     
        at net.minecraft.server.v1_7_R1.DedicatedServer.init(DedicatedServer.java:135) [spigot.jar:git-Spigot-1223]
     
        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:430) [spigot.jar:git-Spigot-1223]
     
        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [spigot.jar:git-Spigot-1223]
     
    Caused by: java.lang.NullPointerException
     
        at me.firstminigame.CTO.<init>(CTO.java:104) ~[?:?]
     
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.6.0_65]
     
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) ~[?:1.6.0_65]
     
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) ~[?:1.6.0_65]
     
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513) ~[?:1.6.0_65]
     
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:178) ~[spigot.jar:git-Spigot-1223]
     
        ... 6 more
     
    
    and here is my whole code
    Code:
    package me.firstminigame;
     
     
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;
    import org.bukkit.scoreboard.Team;
     
    public class CTO extends JavaPlugin implements Listener {
        public static CTO plugin;
       
       
     
     
     
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
     
       
       
           
        }       
       
        public static Inventory myInventory = Bukkit.createInventory(null, 9, "Choose your team");
     
           
       
           
        static {
            myInventory.setItem(0, new ItemStack(Material.REDSTONE_BLOCK, 1));
            myInventory.setItem(1, new ItemStack(Material.LAPIS_BLOCK, 1));
            myInventory.setItem(2, new ItemStack (Material.GOLD_BLOCK, 1));
            myInventory.setItem(3, new ItemStack (Material.EMERALD_BLOCK, 1));
            }
     
       
       
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event) {
        Player player = event.getPlayer();
        Material mat = player.getItemInHand().getType();
        if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        if(mat == Material.IRON_BLOCK){ player.openInventory(myInventory);
       
            }
        }
        }
       
        @EventHandler
        public void onPlayerInteract1(PlayerInteractEvent event) {
        Player player = event.getPlayer();
        Material mat = player.getItemInHand().getType();
        if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        if(mat == Material.REDSTONE_BLOCK){ player.openInventory(myInventory);
       
            }
        }
        }
       
        @EventHandler
        public void onPlayerInteract2(PlayerInteractEvent event) {
        Player player = event.getPlayer();
        Material mat = player.getItemInHand().getType();
        if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        if(mat == Material.LAPIS_BLOCK){ player.openInventory(myInventory);
       
            }
        }
        }
       
        @EventHandler
        public void onPlayerInteract3(PlayerInteractEvent event) {
        Player player = event.getPlayer();
        Material mat = player.getItemInHand().getType();
        if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        if(mat == Material.GOLD_BLOCK){ player.openInventory(myInventory);
       
            }
        }
        }
           
        @EventHandler
        public void onPlayerInteract4(PlayerInteractEvent event) {
        Player player = event.getPlayer();
        Material mat = player.getItemInHand().getType();
        if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        if(mat == Material.EMERALD_BLOCK){ player.openInventory(myInventory);
       
            }
        }
        }
       
        ScoreboardManager sbManager = Bukkit.getScoreboardManager();
        Scoreboard sBoard = sbManager.getNewScoreboard();
       
        Team Red = sBoard.registerNewTeam("Red");
        Team Blue = sBoard.registerNewTeam("Blue");
        Team Yellow = sBoard.registerNewTeam("Yellow");
        Team Green = sBoard.registerNewTeam("Green");
       
            @EventHandler
            public void onInventoryClick(InventoryClickEvent event) {
            Player player = (Player) event.getWhoClicked();
            ItemStack clicked = event.getCurrentItem();
            Inventory inventory = event.getInventory();
            if (inventory.getName().equals(myInventory.getName())) {
            if (clicked.getType() == Material.REDSTONE_BLOCK) {
               
            event.setCancelled(true);
            player.closeInventory();
            Red.addPlayer(player);
            player.sendMessage("You are now in the Red Team");
            }
            }
            }
           
           
            @EventHandler
            public void onInventoryClick1(InventoryClickEvent event) {
            Player player = (Player) event.getWhoClicked();
            ItemStack clicked = event.getCurrentItem();
            Inventory inventory = event.getInventory();
            if (inventory.getName().equals(myInventory.getName())) {
            if (clicked.getType() == Material.LAPIS_BLOCK) {
            event.setCancelled(true);
            player.closeInventory();
            Blue.addPlayer(player);
            player.sendMessage("You are now in the Blue Team");
            }
            }
            }
            @EventHandler
            public void onInventoryClick2(InventoryClickEvent event) {
            Player player = (Player) event.getWhoClicked();
            ItemStack clicked = event.getCurrentItem();
            Inventory inventory = event.getInventory();
            if (inventory.getName().equals(myInventory.getName())) {
            if (clicked.getType() == Material.GOLD_BLOCK) {
            event.setCancelled(true);
            player.closeInventory();
            Yellow.addPlayer(player);
            player.sendMessage("You are now in the Yellow Team");
            }
            }
            }
           
            @EventHandler
            public void onInventoryClick3(InventoryClickEvent event) {
            Player player = (Player) event.getWhoClicked();
            ItemStack clicked = event.getCurrentItem();
            Inventory inventory = event.getInventory();
            if (inventory.getName().equals(myInventory.getName())) {
            if (clicked.getType() == Material.EMERALD) {
            event.setCancelled(true);
            player.closeInventory();
            Green.addPlayer(player);
            player.sendMessage("You are now in the Green Team");
            }
            }
           
            }}
           
     
     
        
    MrInspector maybe you can help me?

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

    nlthijs48

    PizzaPixel The following line returns null:
    Code:java
    1. Bukkit.getScoreboardManager();

    Apparently you did not create any objectives on the server, so there is no scoreboard yet.
     
  3. Offline

    PizzaPixel

    nlthijs48 oh lol I forgot to make the objective
     
  4. Offline

    ShadowLAX

    nlthijs48 That has nothing to do with it, it's how he called the scoreboard.

    PizzaPixel You have to define the scoreboard in the onEnable method. Otherwise it will return null every time.
     
  5. Offline

    PizzaPixel

    nlthijs48 thanx

    ShadowLAX how would I use the variable out of the onenable method then?

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

    ShadowLAX

    PizzaPixel You create a global field, then you define it in the onEnable method. Like so;
    Code:java
    1. public void onEnable() {
    2. this.sbm = Bukkit.getSocreboardManager();
    3. this.sb = sbm.getNewScoreboard();
    4. }
    5.  
    6. ScoreboardManager sbm;
    7. Scoreboard sb;
     
  7. Offline

    PizzaPixel

    ShadowLAX ok I will try that when I get home
     
  8. Offline

    MrInspector

    Code:java
    1. // dont mind this, i need to see the line numbers
    2. package me.firstminigame;
    3.  
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.Material;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.block.Action;
    11. import org.bukkit.event.inventory.InventoryClickEvent;
    12. import org.bukkit.event.player.PlayerInteractEvent;
    13. import org.bukkit.inventory.Inventory;
    14. import org.bukkit.inventory.ItemStack;
    15. import org.bukkit.plugin.java.JavaPlugin;
    16. import org.bukkit.scoreboard.Scoreboard;
    17. import org.bukkit.scoreboard.ScoreboardManager;
    18. import org.bukkit.scoreboard.Team;
    19.  
    20. public class CTO extends JavaPlugin implements Listener {
    21. public static CTO plugin;
    22.  
    23.  
    24.  
    25.  
    26.  
    27. public void onEnable() {
    28. getServer().getPluginManager().registerEvents(this, this);
    29.  
    30.  
    31.  
    32.  
    33. }
    34.  
    35. public static Inventory myInventory = Bukkit.createInventory(null, 9, "Choose your team");
    36.  
    37.  
    38.  
    39.  
    40. static {
    41. myInventory.setItem(0, new ItemStack(Material.REDSTONE_BLOCK, 1));
    42. myInventory.setItem(1, new ItemStack(Material.LAPIS_BLOCK, 1));
    43. myInventory.setItem(2, new ItemStack (Material.GOLD_BLOCK, 1));
    44. myInventory.setItem(3, new ItemStack (Material.EMERALD_BLOCK, 1));
    45. }
    46.  
    47.  
    48.  
    49. @EventHandler
    50. public void onPlayerInteract(PlayerInteractEvent event) {
    51. Player player = event.getPlayer();
    52. Material mat = player.getItemInHand().getType();
    53. if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    54. if(mat == Material.IRON_BLOCK){ player.openInventory(myInventory);
    55.  
    56. }
    57. }
    58. }
    59.  
    60. @EventHandler
    61. public void onPlayerInteract1(PlayerInteractEvent event) {
    62. Player player = event.getPlayer();
    63. Material mat = player.getItemInHand().getType();
    64. if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    65. if(mat == Material.REDSTONE_BLOCK){ player.openInventory(myInventory);
    66.  
    67. }
    68. }
    69. }
    70.  
    71. @EventHandler
    72. public void onPlayerInteract2(PlayerInteractEvent event) {
    73. Player player = event.getPlayer();
    74. Material mat = player.getItemInHand().getType();
    75. if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    76. if(mat == Material.LAPIS_BLOCK){ player.openInventory(myInventory);
    77.  
    78. }
    79. }
    80. }
    81.  
    82. @EventHandler
    83. public void onPlayerInteract3(PlayerInteractEvent event) {
    84. Player player = event.getPlayer();
    85. Material mat = player.getItemInHand().getType();
    86. if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    87. if(mat == Material.GOLD_BLOCK){ player.openInventory(myInventory);
    88.  
    89. }
    90. }
    91. }
    92.  
    93. @EventHandler
    94. public void onPlayerInteract4(PlayerInteractEvent event) {
    95. Player player = event.getPlayer();
    96. Material mat = player.getItemInHand().getType();
    97. if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    98. if(mat == Material.EMERALD_BLOCK){ player.openInventory(myInventory);
    99.  
    100. }
    101. }
    102. }
    103.  
    104. ScoreboardManager sbManager = Bukkit.getScoreboardManager();
    105. Scoreboard sBoard = sbManager.getNewScoreboard();
    106.  
    107. Team Red = sBoard.registerNewTeam("Red");
    108. Team Blue = sBoard.registerNewTeam("Blue");
    109. Team Yellow = sBoard.registerNewTeam("Yellow");
    110. Team Green = sBoard.registerNewTeam("Green");
    111.  
    112. @EventHandler
    113. public void onInventoryClick(InventoryClickEvent event) {
    114. Player player = (Player) event.getWhoClicked();
    115. ItemStack clicked = event.getCurrentItem();
    116. Inventory inventory = event.getInventory();
    117. if (inventory.getName().equals(myInventory.getName())) {
    118. if (clicked.getType() == Material.REDSTONE_BLOCK) {
    119.  
    120. event.setCancelled(true);
    121. player.closeInventory();
    122. Red.addPlayer(player);
    123. player.sendMessage("You are now in the Red Team");
    124. }
    125. }
    126. }
    127.  
    128.  
    129. @EventHandler
    130. public void onInventoryClick1(InventoryClickEvent event) {
    131. Player player = (Player) event.getWhoClicked();
    132. ItemStack clicked = event.getCurrentItem();
    133. Inventory inventory = event.getInventory();
    134. if (inventory.getName().equals(myInventory.getName())) {
    135. if (clicked.getType() == Material.LAPIS_BLOCK) {
    136. event.setCancelled(true);
    137. player.closeInventory();
    138. Blue.addPlayer(player);
    139. player.sendMessage("You are now in the Blue Team");
    140. }
    141. }
    142. }
    143. @EventHandler
    144. public void onInventoryClick2(InventoryClickEvent event) {
    145. Player player = (Player) event.getWhoClicked();
    146. ItemStack clicked = event.getCurrentItem();
    147. Inventory inventory = event.getInventory();
    148. if (inventory.getName().equals(myInventory.getName())) {
    149. if (clicked.getType() == Material.GOLD_BLOCK) {
    150. event.setCancelled(true);
    151. player.closeInventory();
    152. Yellow.addPlayer(player);
    153. player.sendMessage("You are now in the Yellow Team");
    154. }
    155. }
    156. }
    157.  
    158. @EventHandler
    159. public void onInventoryClick3(InventoryClickEvent event) {
    160. Player player = (Player) event.getWhoClicked();
    161. ItemStack clicked = event.getCurrentItem();
    162. Inventory inventory = event.getInventory();
    163. if (inventory.getName().equals(myInventory.getName())) {
    164. if (clicked.getType() == Material.EMERALD) {
    165. event.setCancelled(true);
    166. player.closeInventory();
    167. Green.addPlayer(player);
    168. player.sendMessage("You are now in the Green Team");
    169. }
    170. }
    171.  
    172. }}


    I'm a little tired right now, I barely have my eyes open, i'll just wait a bit before answering because I know i'll help you in the wrong way, sorry.
     
  9. Offline

    PizzaPixel

Thread Status:
Not open for further replies.

Share This Page