[URGENT] Invalid Plugin Exception

Discussion in 'Plugin Development' started by Phantom_64, Jun 13, 2014.

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

    Phantom_64

    I cannot get to the bottom of this for the life of me. It looks like one exception is triggering others, thus creating a chain reaction. If anyone could take a look:

    Error: http://pastebin.com/6GbGAREz

    TeamDeathMatch.java:
    Code:java
    1. package me.phantom64.teamdeathmatch;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5.  
    6. import me.phantom64.teamdeathmatch.commands.CommandSetSpawn;
    7. import me.phantom64.teamdeathmatch.listeners.PlayerDeath;
    8. import me.phantom64.teamdeathmatch.utils.GameManager;
    9. import me.phantom64.teamdeathmatch.utils.LocationHandler;
    10. import me.phantom64.teamdeathmatch.utils.TeamManager;
    11. import me.phantom64.teamdeathmatch.utils.TeamManager.Team;
    12.  
    13. import org.bukkit.Bukkit;
    14. import org.bukkit.ChatColor;
    15. import org.bukkit.command.Command;
    16. import org.bukkit.command.CommandSender;
    17. import org.bukkit.entity.Player;
    18. import org.bukkit.event.Listener;
    19. import org.bukkit.plugin.java.JavaPlugin;
    20.  
    21. /**
    22.  * Color symbol: §
    23.  * Red team color: §c
    24.  * Blue team color: §9
    25.  */
    26.  
    27. public class TeamDeathMatch extends JavaPlugin {
    28.  
    29. public static GameManager gameManager = new GameManager(new TeamDeathMatch());
    30. public static TeamManager teamManager = new TeamManager(new TeamDeathMatch());
    31. public static LocationHandler locationHandler = new LocationHandler(new TeamDeathMatch());
    32.  
    33. public static GameManager getGameManager() {
    34. return gameManager;
    35. }
    36.  
    37. public static TeamManager getTeamManager() {
    38. return teamManager;
    39. }
    40.  
    41. public static LocationHandler getLocationHandler() {
    42. return locationHandler;
    43. }
    44.  
    45. public static List<Player> red = new ArrayList<Player>();
    46. public static List<Player> blue = new ArrayList<Player>();
    47.  
    48. public static List<Player> getRed() {
    49. return red;
    50. }
    51.  
    52. public static List<Player> getBlue() {
    53. return blue;
    54. }
    55.  
    56. @Override
    57. public void onEnable() {
    58. addPlayersToTeamLists();
    59. registerListeners(new PlayerDeath());
    60. }
    61.  
    62. private void registerListeners(Listener... listeners) {
    63. for (Listener listener : listeners) {
    64. getServer().getPluginManager().registerEvents(listener, this);
    65. getLogger().info("Event " + listener.getClass().getSimpleName() + " has been registered.");
    66. }
    67. getLogger().info("All events registered.");
    68. }
    69.  
    70. public static void addPlayersToTeamLists() {
    71. red.clear();
    72. blue.clear();
    73. for (Player pl : Bukkit.getServer().getOnlinePlayers()) {
    74. if (TeamDeathMatch.getGameManager().isPlaying(pl)) {
    75. if (TeamDeathMatch.getTeamManager().getTeam(pl) == Team.RED) {
    76. red.add(pl);
    77. } else if (TeamDeathMatch.getTeamManager().getTeam(pl) == Team.BLUE) {
    78. blue.add(pl);
    79. }
    80. }
    81. }
    82. }
    83.  
    84. @Override
    85. public boolean onCommand (CommandSender sender, Command cmd, String label, String[] args) {
    86.  
    87. if (label.equalsIgnoreCase("tdm")) {
    88.  
    89. if (sender instanceof Player) {
    90. if (args[0].equalsIgnoreCase("setspawn")) {
    91. CommandSetSpawn.execute((Player)sender, args);
    92. }
    93. } else {
    94. sender.sendMessage(ChatColor.RED + "Only players can use this command.");
    95. }
    96.  
    97. }
    98.  
    99. return true;
    100.  
    101. }
    102.  
    103. }
    104.  


    If you need any other code, just inform me. And please, this is urgent.
     
  2. Offline

    bigteddy98

    Can you send the TeamDeathMatch class? The problem seems to be there.

    Aaah wait, this is the TeamDeathMatch class, let me see.

    I think I found your problem. Never create a new instance of your main class, Bukkit does create one for you. So replace all "new TeamDeathMatch()" with "this". That should do it.
     
  3. Offline

    Phantom_64

    bigteddy98 Just in case.
    GameManager.java: http://pastebin.com/dhA2R2tC
    LocationHandler.java: http://pastebin.com/0bXbCdKU
    TeamManager.java: http://pastebin.com/yZWgNrRV

    I have tried that, but 'this' can't be called in a static context.

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

    bigteddy98

    Place that code in your onEnable, instead of doing it before enabling.

    It should be:
    Code:java
    1. public static GameManager gameManager;
    2. public static TeamManager teamManager;
    3. public static LocationHandler locationHandler;


    And your onEnable should look like this:
    Code:java
    1. @Override
    2. public void onEnable() {
    3. addPlayersToTeamLists();
    4. registerListeners(new PlayerDeath());
    5. gameManager = new GameManager(this);
    6. teamManager = new TeamManager(this);
    7. locationHandler = new LocationHandler(this);
    8. }


    This should work.
     
  5. Offline

    Phantom_64

    Gimme a hug you old teddy bear. I will love you forever for this. <3
     
    bigteddy98 likes this.
Thread Status:
Not open for further replies.

Share This Page