Can't create new teams

Discussion in 'Plugin Development' started by Beauseant, Aug 23, 2014.

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

    Beauseant

    Don't blame me for anything, i'm new at coding and a friend of mine explained me to do this. However, it doesn't work and i can't reach my friend. I don't even know WHAT i'm doing in the main class, as it looks al gibberish to me. What i do know, is that it doesn't work. :) Can someone please help me and explain me what to do to make it work?


    Code:java
    1. package me.Beauseant.Tabnames;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5.  
    6. import org.bukkit.plugin.java.JavaPlugin;
    7. import org.bukkit.scoreboard.Scoreboard;
    8. import org.bukkit.scoreboard.Team;
    9.  
    10. public class Main extends JavaPlugin {
    11. private static Scoreboard manager;
    12. private static List<Team> teamlist;
    13.  
    14. public void onEnable() {
    15. teamlist = new ArrayList<Team>();
    16. teamlist.add(manager.registerNewTeam("Red"));
    17. teamlist.add(manager.registerNewTeam("Blue"));
    18. }
    19.  
    20. public static List<Team> teamlist() {
    21. return teamlist;
    22. }
    23.  
    24. public Scoreboard getScoreboardManager() {
    25. return manager;
    26. }


    It gives the following error:

    Code:
     [01:51:36] [Server thread/INFO]: [Tabnames] Enabling Tabnames v1.0
    [01:51:36] [Server thread/ERROR]: Error occurred while enabling Tabnames v1.0 (Is it up to date?)
    java.lang.NullPointerException
     at me.Beauseant.Tabnames.Main.onEnable(Main.java:16) ~[?:?]
     at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:316) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
     at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:324) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
     at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:404) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
     at org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugin(CraftServer.java:455) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
     at org.bukkit.craftbukkit.v1_7_R4.CraftServer.enablePlugins(CraftServer.java:389) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
     at net.minecraft.server.v1_7_R4.MinecraftServer.n(MinecraftServer.java:352) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
     at net.minecraft.server.v1_7_R4.MinecraftServer.g(MinecraftServer.java:326) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
     at net.minecraft.server.v1_7_R4.MinecraftServer.a(MinecraftServer.java:282) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
     at net.minecraft.server.v1_7_R4.DedicatedServer.init(DedicatedServer.java:189) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
     at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:436) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
     at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks] 
     
  2. Offline

    Dragonphase

    Beauseant

    You should learn Java and the Bukkit API before attempting to make a Bukkit Plugin.
     
  3. Offline

    Beauseant


    Best response ever. How can i learn without trying? The only way to learn is to try and fail, and then try again. I'm asking for help so i can learn from my mistakes.
     
  4. Offline

    Dragonphase

    Beauseant

    If you don't have an understanding of Java or Object Oriented Programming, you'll be at a disadvantage. It also pays to check out the resources made available to you by the Bukkit team, such as this Plugin Tutorial page.
     
  5. Offline

    Beauseant


    In the mean time i just fixed my problem without your help. Could someone close this topic?
     
  6. Offline

    aredherring

    No, it's not. The only way to learn is to understand what you are doing in the first place. You didn't even read the error you were having which said one of your plugins was out of date which had nothing to do with your code.

    Even if you don't understand Java, that's in plain English. If you didn't understand the error message you probably should not be trying to develop plugins... "trying" or not. Learn Java on it's own first before attempting Bukkit plugins.

    While your code fragment in OP is not great it would not have caused a NullPointerException in just the things it is doing right now.

    EDIT: Wrong answer - actually it would, your "manager" variable is null. That's why you got the exception.
     
  7. Offline

    Dragonphase

    Beauseant

    Your first post clearly points out that you don't understand Java or Object Oriented Programming. I'm trying to help you by pointing you in the right directions. If I gave you a solution to your problem, I might as well have spoon fed you and you would not have learned anything.
     
  8. Offline

    AronTheGamer

    My pointouts:

    Package names should be lowercase, when you follow the Java Naming Convetions
    Code:java
    1. package me.Beauseant.Tabnames;

    Should be:
    Code:java
    1. package me.beauseant.TabNames;

    (don't forget to update your plugin.yml file)

    This is all good:
    Code:java
    1. import java.util.ArrayList;
    2. import java.util.List;
    3.  
    4. import org.bukkit.plugin.java.JavaPlugin;
    5. import org.bukkit.scoreboard.Scoreboard;
    6. import org.bukkit.scoreboard.Team;


    Next thing: Null References.
    When you don't initialize something (such as your Scoreboard), it won't work, because it will return 'null' (aka: this thing doesn't point to any object).

    Code:java
    1. public class Main extends JavaPlugin {
    2. private static Scoreboard manager;
    3. private static List<Team> teamlist;

    Code:java
    1.  
    2. public void onEnable() {
    3. teamlist = new ArrayList<Team>();
    4. teamlist.add(manager.registerNewTeam("Red"));
    5. teamlist.add(manager.registerNewTeam("Blue"));
    6. }
    7.  

    Should be:
    Code:java
    1.  
    2. public void onEnable() {
    3. manager = getServer().getScoreboardManager().getMainScoreboard(); // << Now it references to a Scoreboard
    4. teamlist = new ArrayList<Team>();
    5. teamlist.add(manager.registerNewTeam("Red"));
    6. teamlist.add(manager.registerNewTeam("Blue"));
    7. }
    8.  


    Your final code would be something like:
    Code:java
    1. package me.beauseant.Tabnames;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5.  
    6. import org.bukkit.plugin.java.JavaPlugin;
    7. import org.bukkit.scoreboard.Scoreboard;
    8. import org.bukkit.scoreboard.Team;
    9.  
    10. public class Main extends JavaPlugin {
    11. private static Scoreboard manager;
    12. private static List<Team> teamlist;
    13.  
    14. public void onEnable() {
    15. manager = getServer().getScoreboardManager().getMainScoreboard();
    16. teamlist = new ArrayList<Team>();
    17. teamlist.add(manager.registerNewTeam("Red"));
    18. teamlist.add(manager.registerNewTeam("Blue"));
    19. }
    20.  
    21. public static List<Team> teamlist() {
    22. return teamlist;
    23. }
    24.  
    25. public Scoreboard getScoreboardManager() {
    26. return manager;
    27. }


    Another thing to point out is that a Scoreboard is different from a ScoreboardManager.
     
Thread Status:
Not open for further replies.

Share This Page