Solved Null pointer exception error on start up

Discussion in 'Plugin Development' started by sockmonkey1, Aug 6, 2013.

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

    sockmonkey1

    Hey, I'm learning to make plugins and I read the tut on figuring this out for my self however I'm still stumped and was hoping I could wast someone's time for a little aid towards me.
    So I get this error on start up.
    Code:
    C:\Users\PurpleAnarchist\Dropbox\Cencraft\random\Cencraft Dead>java -Xms2G -Xmx2
    G -jar craftbukkit.jar -o true
    19:26:51 [INFO] Starting minecraft server version 1.6.2
    19:26:51 [INFO] Loading properties
    19:26:51 [INFO] Default game type: ADVENTURE
    19:26:51 [INFO] Generating keypair
    19:26:52 [INFO] Starting Minecraft server on *:25565
    19:26:52 [INFO] This server is running CraftBukkit version git-Bukkit-1.6.2-R0.1
    -b2838jnks (MC: 1.6.2) (Implementing API version 1.6.2-R0.1)
    19:26:52 [SEVERE] Could not load 'plugins\CencraftTag.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.NullPointerException
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:182)
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.
    java:305)
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager
    .java:230)
            at org.bukkit.craftbukkit.v1_6_R2.CraftServer.loadPlugins(CraftServer.ja
    va:239)
            at org.bukkit.craftbukkit.v1_6_R2.CraftServer.<init>(CraftServer.java:21
    7)
            at net.minecraft.server.v1_6_R2.PlayerList.<init>(PlayerList.java:56)
            at net.minecraft.server.v1_6_R2.DedicatedPlayerList.<init>(SourceFile:11
    )
            at net.minecraft.server.v1_6_R2.DedicatedServer.init(DedicatedServer.jav
    a:106)
            at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java
    :391)
            at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:5
    82)
    Caused by: java.lang.NullPointerException
            at me.Elithous.Tag.Tag.<init>(Tag.java:50)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
     
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
     
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
    rce)
            at java.lang.reflect.Constructor.newInstance(Unknown Source)
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:178)
            ... 9 more
    19:26:52 [INFO] [SaleSigns] Loading SaleSigns v1.0
    19:26:52 [INFO] Preparing level "Wordl1"
    19:26:52 [INFO] Preparing start region for level 0 (Seed: -9192521251640166598)
    19:26:53 [INFO] ----- Bukkit Auto Updater -----
    19:26:53 [INFO] It appears that you're running a Beta Build, when you've specifi
    ed in bukkit.yml that you prefer to run Recommended Builds.
    19:26:53 [INFO] If you would like to be kept informed about new Beta Build relea
    ses, it is recommended that you change 'preferred-channel' in your bukkit.yml to
    'beta'.
    19:26:53 [INFO] With that set, you will be told whenever a new version is availa
    ble for download, so that you can always keep up to date and secure with the lat
    est fixes.
    19:26:53 [INFO] If you would like to disable this warning, simply set 'suggest-c
    hannels' to false in bukkit.yml.
    19:26:53 [INFO] ----- ------------------- -----
    19:26:53 [INFO] Preparing spawn area: 71%
    19:26:53 [INFO] Preparing start region for level 1 (Seed: 5656689878067918962)
    19:26:54 [INFO] [SaleSigns] Enabling SaleSigns v1.0
    19:26:54 [INFO] SaleSigns version 1.0 Has been enabled
    19:26:54 [INFO] Server permissions file permissions.yml is empty, ignoring it
    19:26:54 [INFO] Done (1.805s)! For help, type "help" or "?"
    19:26:54 [INFO] Starting GS4 status listener
    19:26:54 [INFO] Query running on 0.0.0.0:25565
    >
    
    And here is my java file that I think it having the problem.

    Code:java
    1. package me.Elithous.Tag;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.HashMap;
    5. import java.util.logging.Logger;
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.Color;
    9. import org.bukkit.FireworkEffect;
    10. import org.bukkit.GameMode;
    11. import org.bukkit.Location;
    12. import org.bukkit.Material;
    13. import org.bukkit.FireworkEffect.Type;
    14. import org.bukkit.Sound;
    15. import org.bukkit.block.Block;
    16. import org.bukkit.command.Command;
    17. import org.bukkit.command.CommandSender;
    18. import org.bukkit.entity.Entity;
    19. import org.bukkit.entity.EntityType;
    20. import org.bukkit.entity.Firework;
    21. import org.bukkit.entity.HumanEntity;
    22. import org.bukkit.entity.Player;
    23. import org.bukkit.event.EventHandler;
    24. import org.bukkit.event.EventPriority;
    25. import org.bukkit.event.Listener;
    26. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    27. import org.bukkit.event.entity.EntityDamageEvent;
    28. import org.bukkit.event.inventory.InventoryClickEvent;
    29. import org.bukkit.inventory.ItemStack;
    30. import org.bukkit.inventory.PlayerInventory;
    31. import org.bukkit.inventory.meta.FireworkMeta;
    32. import org.bukkit.plugin.PluginManager;
    33. import org.bukkit.plugin.java.JavaPlugin;
    34. import org.bukkit.scoreboard.DisplaySlot;
    35. import org.bukkit.scoreboard.Objective;
    36. import org.bukkit.scoreboard.Score;
    37. import org.bukkit.scoreboard.Scoreboard;
    38. import org.bukkit.scoreboard.ScoreboardManager;
    39.  
    40. public class Tag extends JavaPlugin implements Listener {
    41. public static Tag plugin;
    42. public final Logger logger = Logger.getLogger("Minecraft");
    43. public final TagLogger tlo = new TagLogger(this);
    44. public final HashMap<Player, ArrayList<Block>> IsIt = new HashMap<Player, ArrayList<Block>>();
    45. public final HashMap<Player, ArrayList<Block>> NotIt = new HashMap<Player, ArrayList<Block>>();
    46. public ScoreboardManager manager;
    47. public Scoreboard board;
    48. Objective obj = board.registerNewObjective("Currently it", "dummy");
    49.  
    50. public void onEnable() {
    51. tlo.enabled(true);
    52. PluginManager pm = this.getServer().getPluginManager();
    53. getServer().getPluginManager().registerEvents(this, this);
    54. pm.addPermission(new Permissions().ctagjoin);
    55. pm.addPermission(new Permissions().ctagleave);
    56. pm.addPermission(new Permissions().ctagme);
    57. manager = Bukkit.getScoreboardManager();
    58. board = manager.getNewScoreboard();
    59. }
    60.  
    61. public void onDisable() {
    62. IsIt.remove(IsIt);
    63. NotIt.remove(NotIt);
    64. tlo.enabled(false);
    65. getServer().getPluginManager().removePermission(
    66. new Permissions().ctagjoin);
    67. getServer().getPluginManager().removePermission(
    68. new Permissions().ctagleave);
    69. getServer().getPluginManager().removePermission(
    70. new Permissions().ctagme);
    71. }
    72.  
    73. // Inventory grab stopper thing :P
    74. @EventHandler
    75. public void onInventoryUse(InventoryClickEvent event) {
    76. HumanEntity player = event.getWhoClicked();
    77. if (IsIt.containsKey(player)) {
    78. event.setCancelled(true);
    79. } else if (NotIt.containsKey(player)) {
    80. event.setCancelled(true);
    81. } else if (!IsIt.containsKey(player)) {
    82. event.setCancelled(false);
    83. } else if (!NotIt.containsKey(player)) {
    84. event.setCancelled(false);
    85. }
    86. }
    87.  
    88. // If statement mess area thing
    89. @EventHandler(priority = EventPriority.HIGH)
    90. public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
    91. Entity hit = event.getEntity();
    92. Entity hitter = event.getDamager();
    93. Player playere = (Player) hit;
    94. Player playerd = (Player) hitter;
    95. PlayerInventory pie = playere.getInventory();
    96. PlayerInventory pid = playerd.getInventory();
    97. ItemStack wool = new ItemStack(Material.WOOL, 1, (byte) 14);
    98. ItemStack glass = new ItemStack(Material.GLASS);
    99. if (IsIt.containsKey(playerd)) {
    100. if (NotIt.containsKey(playere)) {
    101. Location loc = playere.getLocation();
    102. playere.playSound(loc, Sound.ZOMBIE_UNFECT, 8, 1);
    103. }
    104. }
    105. if (IsIt.containsKey(playerd)) {
    106. if (NotIt.containsKey(playere)) {
    107. Location loc = playere.getLocation();
    108. Firework firework = (Firework) loc.getWorld().spawnEntity(loc,
    109. EntityType.FIREWORK);
    110. FireworkMeta fwm = (FireworkMeta) firework.getFireworkMeta();
    111. fwm.addEffect(FireworkEffect.builder().withColor(Color.RED)
    112. .with(Type.BALL_LARGE).build());
    113. fwm.setPower(0);
    114. firework.setFireworkMeta(fwm);
    115. } else {
    116. event.setCancelled(true);
    117. }
    118. }
    119. if (NotIt.containsKey(playerd)) {
    120. if (IsIt.containsKey(playere)) {
    121. playerd.sendMessage(ChatColor.GOLD + "You are not it.");
    122. }
    123. } else if (NotIt.containsKey(playere)) {
    124. if (NotIt.containsKey(playerd)) {
    125. playerd.sendMessage(ChatColor.GOLD + "You are not it.");
    126. }
    127. }
    128. if (IsIt.containsKey(playerd)) {
    129. if (!NotIt.containsKey(playere)) {
    130. event.setCancelled(true);
    131. playerd.sendMessage(ChatColor.GOLD
    132. + "That player is not in tag!");
    133. } else if (NotIt.containsKey(playere)) {
    134. board.resetScores(playere);
    135. board.resetScores(playerd);
    136. IsIt.remove(playerd);
    137. NotIt.put(playerd, null);
    138. playerd.sendMessage(ChatColor.GOLD + "You are no longer it!");
    139. event.setCancelled(true);
    140. pid.setHelmet(glass);
    141. NotIt.remove(playere);
    142. IsIt.put(playere, null);
    143. pie.setHelmet(wool);
    144. playere.sendMessage(ChatColor.GOLD + "You are now it!");
    145. Score score = obj.getScore(playere);
    146. score.setScore(1);
    147. }
    148. }
    149. // Old broke code. Use to copy above.
    150. /*
    151.   * if (NotIt.containsKey(hit)) { if (IsIt.containsKey(hitter)) {
    152.   * playere.sendMessage(ChatColor.GOLD + "You are now it!");
    153.   * NotIt.remove(playere); IsIt.put(playere, null);
    154.   * event.setCancelled(true); pie.setHelmet(wool); } } else if
    155.   * (IsIt.containsKey(hit)) { IsIt.remove(playerd); NotIt.put(playerd,
    156.   * null); playerd.sendMessage(ChatColor.GOLD + "You are no longer it!");
    157.   * event.setCancelled(true); pid.setHelmet(glass); } else {
    158.   * playerd.sendMessage("You are not it."); }
    159.   */
    160. }
    161.  
    162. // Oh god so many if statements!
    163. @EventHandler
    164. public void onEntityDamage(EntityDamageEvent event) {
    165. Entity damaged = event.getEntity();
    166. if (NotIt.containsKey(damaged)) {
    167. event.setDamage(0);
    168. event.setCancelled(true);
    169. }
    170. if (IsIt.containsKey(damaged)) {
    171. event.setDamage(0);
    172. event.setCancelled(true);
    173. }
    174. }
    175.  
    176. // NO MORE IF STATMENTS!! Command area thing VVVV
    177. public boolean onCommand(CommandSender sender, Command cmd,
    178. String commandLabel, String[] args) {
    179. Player player = (Player) sender;
    180. PlayerInventory pi = player.getInventory();
    181. ItemStack glass = new ItemStack(Material.GLASS);
    182. ItemStack wool = new ItemStack(Material.WOOL, 1, (byte) 14);
    183. ItemStack air = new ItemStack(Material.AIR);
    184. ItemStack head = pi.getHelmet();
    185. if (commandLabel.equalsIgnoreCase("ctag")) {
    186. if (sender instanceof Player) {
    187. if (args.length == 0)
    188. player.sendMessage(ChatColor.DARK_RED
    189. + "Incorrect Syntax. Use /ctag join and /ctag leave");
    190. if (args.length == 1) {
    191. if (args[0].equalsIgnoreCase("join")) {
    192. obj.setDisplaySlot(DisplaySlot.SIDEBAR);
    193. obj.setDisplayName("§aCurrently it");
    194. if (player.hasPermission(new Permissions().ctagjoin)) {
    195. if (head == null) {
    196. getServer().broadcastMessage(
    197. player.getDisplayName()
    198. + ChatColor.GOLD
    199. + " is now playing tag!");
    200. player.setScoreboard(board);
    201. pi.setHelmet(glass);
    202. NotIt.put(player, null);
    203. player.setGameMode(GameMode.ADVENTURE);
    204. player.setHealth(20);
    205. player.setFoodLevel(1000);
    206. } else if (IsIt.containsKey(player)) {
    207. player.sendMessage(ChatColor.DARK_RED
    208. + "You are already playing tag!");
    209. } else if (NotIt.containsKey(player)) {
    210. player.sendMessage(ChatColor.DARK_RED
    211. + "You are already playing tag!");
    212. } else {
    213. player.sendMessage(ChatColor.DARK_RED
    214. + "Remove your helmet to play tag!");
    215. }
    216. } else {
    217. player.sendMessage(ChatColor.DARK_RED
    218. + "You can't play tag in this area!");
    219. }
    220. } else if (args[0].equalsIgnoreCase("leave")) {
    221. if (player.hasPermission(new Permissions().ctagleave)) {
    222. if (IsIt.containsKey(player)) {
    223. getServer().broadcastMessage(
    224. player.getDisplayName()
    225. + ChatColor.GOLD
    226. + " is no longer playing tag!");
    227. board.resetScores(player);
    228. player.setScoreboard(manager.getNewScoreboard());
    229. pi.setHelmet(air);
    230. IsIt.remove(player);
    231. player.setHealth(20);
    232. player.setFoodLevel(20);
    233. player.setGameMode(GameMode.SURVIVAL);
    234. } else if (NotIt.containsKey(player)) {
    235. getServer().broadcastMessage(
    236. player.getDisplayName()
    237. + ChatColor.GOLD
    238. + " is no longer playing tag!");
    239. pi.setHelmet(air);
    240. NotIt.remove(player);
    241. player.setHealth(20);
    242. player.setFoodLevel(20);
    243. player.setGameMode(GameMode.SURVIVAL);
    244. } else {
    245. player.sendMessage(ChatColor.DARK_RED
    246. + "You are not playing tag!");
    247. }
    248. } else {
    249. player.sendMessage(ChatColor.DARK_RED
    250. + "You can't play tag in this area!");
    251. }
    252. } else if (args[0].equalsIgnoreCase("me")) {
    253. if (player.hasPermission(new Permissions().ctagme)) {
    254. if (IsIt.containsKey(player)) {
    255. player.sendMessage(ChatColor.DARK_RED
    256. + "You are already it!");
    257. } else if (NotIt.containsKey(player)) {
    258. NotIt.remove(player);
    259. IsIt.put(player, null);
    260. Score score = obj.getScore(player);
    261. score.setScore(1);
    262. player.sendMessage(ChatColor.GOLD
    263. + "You are now it!");
    264. pi.setHelmet(wool);
    265. } else {
    266. player.sendMessage(ChatColor.DARK_RED
    267. + "Join Tag to become it!");
    268. }
    269. }
    270. } else if (args[0].equalsIgnoreCase("check")) {
    271. if (IsIt.containsKey(player)) {
    272. player.sendMessage(ChatColor.DARK_RED
    273. + "You are in the it group!");
    274. } else if (NotIt.containsKey(player)) {
    275. player.sendMessage(ChatColor.GOLD
    276. + "You are in the not it group!");
    277. } else {
    278. player.sendMessage(ChatColor.DARK_RED
    279. + "You are not even in tag!");
    280. }
    281. } else {
    282. player.sendMessage(ChatColor.DARK_RED
    283. + "You can't play tag in this area!");
    284. }
    285. }
    286. }
    287. }
    288. return false;
    289. }
    290. }

    I thought the part of
    Code:
    Caused by: java.lang.NullPointerException
            at me.Elithous.Tag.Tag.<init>(Tag.java:50)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
     
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
     
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
    rce)
            at java.lang.reflect.Constructor.newInstance(Unknown Source)
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:178)
            ... 9 more
    would mean that the problem is at line 50, I thought that this didn't include the whitespaces because with the whitespaces line 50 is blank... without the whitespace it says
    Code:java
    1. getServer().getPluginManager().registerEvents(this, this);

    Thats what I did to try and fix it. Its not working..
    It used to be
    Code:java
    1. pm.registerEvents(this, this);


    I am looking for help in fixing this. I'm still learning and the weird part about this is, if I reload the server after it has already started this error is ignored. It is only on the servers first run does this error pop up.
    Thanks a lot in advance. (Assuming someone helps!)
     
  2. Offline

    newboyhun

    sockmonkey1
    Problem is at line 43:
    public final TagLogger tlo = new TagLogger(this); << YOU CAN'T USE 'this'
    change to
    public final TagLogger tlo = null;

    add this
    tlo = new TagLogger(this);
    after
    tlo.enabled(true);
     
  3. Offline

    thecrystalflame

    It does count blank lines so are you sure your looking at the correct space?
    Also your paste up above says that line 50 is public void onEnable() {
    which makes no sense.
     
  4. Offline

    sockmonkey1

    newboyhun
    Tried this and still getting the same error with the same line number. and this is only happening on start up of the server. If I reload the plugin starts just fine. I also updated the server it was running on thinking that would do it. Its running the beta build for 1.6.2. My bukkit api is up to date too.

    I thought it was weird too, I thought maybe it was some weird glitch with my test server so I moved folders re downloaded everything reexported and it still says line 50.

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

    newboyhun

    sockmonkey1
    Wait.
    Line 48.
    You are using 'board' field whilst it doesn't have value.
     
  6. Offline

    Syd

    sockmonkey1
    The actual problem it at line 48, where you try to register a objective at the scoreboard board, which isn't initialized yet (-> null)
    Move that part of the code to a position, where board is initialized. (Line 59 for example)

    Another "issue" is the fact, that you retrive your logger with Logger.getLogger("Minecraft").
    Way better is logger = getLogger(); in your onEnable() method.
    (I heard many tutorials make this mistake, however it's part of the Common Mistakes Thread)


    newboyhun
    As far as I remember you can use 'this' at this point of code, as the object is already existing, but it's construction is not finished yet.
    However, I actually never thought about it what kind of errors this habit could cause...
    (So, I would say, what you suggested is most likely more correct)
     
  7. Offline

    sockmonkey1

    Syd
    So I tried what you suggest and I'm still getting the same error and on the same line (line:50) which is the onenable(){

    I think I'll just start over and just keep the parts I know are working.

    Code:java
    1. package me.Elithous.Tag;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.HashMap;
    5. import java.util.logging.Logger;
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.Color;
    9. import org.bukkit.FireworkEffect;
    10. import org.bukkit.GameMode;
    11. import org.bukkit.Location;
    12. import org.bukkit.Material;
    13. import org.bukkit.FireworkEffect.Type;
    14. import org.bukkit.Sound;
    15. import org.bukkit.block.Block;
    16. import org.bukkit.command.Command;
    17. import org.bukkit.command.CommandSender;
    18. import org.bukkit.entity.Entity;
    19. import org.bukkit.entity.EntityType;
    20. import org.bukkit.entity.Firework;
    21. import org.bukkit.entity.HumanEntity;
    22. import org.bukkit.entity.Player;
    23. import org.bukkit.event.EventHandler;
    24. import org.bukkit.event.EventPriority;
    25. import org.bukkit.event.Listener;
    26. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    27. import org.bukkit.event.entity.EntityDamageEvent;
    28. import org.bukkit.event.inventory.InventoryClickEvent;
    29. import org.bukkit.inventory.ItemStack;
    30. import org.bukkit.inventory.PlayerInventory;
    31. import org.bukkit.inventory.meta.FireworkMeta;
    32. import org.bukkit.plugin.PluginManager;
    33. import org.bukkit.plugin.java.JavaPlugin;
    34. import org.bukkit.scoreboard.DisplaySlot;
    35. import org.bukkit.scoreboard.Objective;
    36. import org.bukkit.scoreboard.Score;
    37. import org.bukkit.scoreboard.Scoreboard;
    38. import org.bukkit.scoreboard.ScoreboardManager;
    39.  
    40. public class Tag extends JavaPlugin implements Listener {
    41. public static Tag plugin;
    42. public final Logger logger = Logger.getLogger("Minecraft");
    43. public TagLogger tlo = null;
    44. public final HashMap<Player, ArrayList<Block>> IsIt = new HashMap<Player, ArrayList<Block>>();
    45. public final HashMap<Player, ArrayList<Block>> NotIt = new HashMap<Player, ArrayList<Block>>();
    46. public ScoreboardManager manager;
    47. public Scoreboard board;
    48. Objective obj = board.registerNewObjective("Currently it", "dummy");
    49.  
    50. public void onEnable() {
    51. tlo.enabled(true);
    52. tlo = new TagLogger(this);
    53. PluginManager pm = this.getServer().getPluginManager();
    54. getServer().getPluginManager().registerEvents(this, this);
    55. pm.addPermission(new Permissions().ctagjoin);
    56. pm.addPermission(new Permissions().ctagleave);
    57. pm.addPermission(new Permissions().ctagme);
    58. manager = Bukkit.getScoreboardManager();
    59. board = manager.getNewScoreboard();
    60. Objective obj = board.registerNewObjective("Currently it", "dummy");
    61. obj.setDisplaySlot(DisplaySlot.SIDEBAR);
    62. obj.setDisplayName("§aCurrently it");
    63. }
    64.  
    65. public void onDisable() {
    66. IsIt.remove(IsIt);
    67. NotIt.remove(NotIt);
    68. tlo.enabled(false);
    69. getServer().getPluginManager().removePermission(
    70. new Permissions().ctagjoin);
    71. getServer().getPluginManager().removePermission(
    72. new Permissions().ctagleave);
    73. getServer().getPluginManager().removePermission(
    74. new Permissions().ctagme);
    75. }
    76.  
    77. // Inventory grab stopper thing :P
    78. @EventHandler
    79. public void onInventoryUse(InventoryClickEvent event) {
    80. HumanEntity player = event.getWhoClicked();
    81. if (IsIt.containsKey(player)) {
    82. event.setCancelled(true);
    83. } else if (NotIt.containsKey(player)) {
    84. event.setCancelled(true);
    85. } else if (!IsIt.containsKey(player)) {
    86. event.setCancelled(false);
    87. } else if (!NotIt.containsKey(player)) {
    88. event.setCancelled(false);
    89. }
    90. }
    91.  
    92. // If statement mess area thing
    93. @EventHandler(priority = EventPriority.HIGH)
    94. public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
    95. Entity hit = event.getEntity();
    96. Entity hitter = event.getDamager();
    97. Player playere = (Player) hit;
    98. Player playerd = (Player) hitter;
    99. PlayerInventory pie = playere.getInventory();
    100. PlayerInventory pid = playerd.getInventory();
    101. ItemStack wool = new ItemStack(Material.WOOL, 1, (byte) 14);
    102. ItemStack glass = new ItemStack(Material.GLASS);
    103. if (IsIt.containsKey(playerd)) {
    104. if (NotIt.containsKey(playere)) {
    105. Location loc = playere.getLocation();
    106. playere.playSound(loc, Sound.ZOMBIE_UNFECT, 8, 1);
    107. }
    108. }
    109. if (IsIt.containsKey(playerd)) {
    110. if (NotIt.containsKey(playere)) {
    111. Location loc = playere.getLocation();
    112. Firework firework = (Firework) loc.getWorld().spawnEntity(loc,
    113. EntityType.FIREWORK);
    114. FireworkMeta fwm = (FireworkMeta) firework.getFireworkMeta();
    115. fwm.addEffect(FireworkEffect.builder().withColor(Color.RED)
    116. .with(Type.BALL_LARGE).build());
    117. fwm.setPower(0);
    118. firework.setFireworkMeta(fwm);
    119. } else {
    120. event.setCancelled(true);
    121. }
    122. }
    123. if (NotIt.containsKey(playerd)) {
    124. if (IsIt.containsKey(playere)) {
    125. playerd.sendMessage(ChatColor.GOLD + "You are not it.");
    126. }
    127. } else if (NotIt.containsKey(playere)) {
    128. if (NotIt.containsKey(playerd)) {
    129. playerd.sendMessage(ChatColor.GOLD + "You are not it.");
    130. }
    131. }
    132. if (IsIt.containsKey(playerd)) {
    133. if (!NotIt.containsKey(playere)) {
    134. event.setCancelled(true);
    135. playerd.sendMessage(ChatColor.GOLD
    136. + "That player is not in tag!");
    137. } else if (NotIt.containsKey(playere)) {
    138. board.resetScores(playere);
    139. board.resetScores(playerd);
    140. IsIt.remove(playerd);
    141. NotIt.put(playerd, null);
    142. playerd.sendMessage(ChatColor.GOLD + "You are no longer it!");
    143. event.setCancelled(true);
    144. pid.setHelmet(glass);
    145. NotIt.remove(playere);
    146. IsIt.put(playere, null);
    147. pie.setHelmet(wool);
    148. playere.sendMessage(ChatColor.GOLD + "You are now it!");
    149. Score score = obj.getScore(playere);
    150. score.setScore(1);
    151. }
    152. }
    153. }
    154.  
    155. // Oh god so many if statements!
    156. @EventHandler
    157. public void onEntityDamage(EntityDamageEvent event) {
    158. Entity damaged = event.getEntity();
    159. if (NotIt.containsKey(damaged)) {
    160. event.setDamage(0);
    161. event.setCancelled(true);
    162. }
    163. if (IsIt.containsKey(damaged)) {
    164. event.setDamage(0);
    165. event.setCancelled(true);
    166. }
    167. }
    168.  
    169. // NO MORE IF STATMENTS!! Command area thing VVVV
    170. public boolean onCommand(CommandSender sender, Command cmd,
    171. String commandLabel, String[] args) {
    172. Player player = (Player) sender;
    173. PlayerInventory pi = player.getInventory();
    174. ItemStack glass = new ItemStack(Material.GLASS);
    175. ItemStack wool = new ItemStack(Material.WOOL, 1, (byte) 14);
    176. ItemStack air = new ItemStack(Material.AIR);
    177. ItemStack head = pi.getHelmet();
    178. if (commandLabel.equalsIgnoreCase("ctag")) {
    179. if (sender instanceof Player) {
    180. if (args.length == 0)
    181. player.sendMessage(ChatColor.DARK_RED
    182. + "Incorrect Syntax. Use /ctag join and /ctag leave");
    183. if (args.length == 1) {
    184. if (args[0].equalsIgnoreCase("join")) {
    185. if (player.hasPermission(new Permissions().ctagjoin)) {
    186. if (head == null) {
    187. getServer().broadcastMessage(
    188. player.getDisplayName()
    189. + ChatColor.GOLD
    190. + " is now playing tag!");
    191. player.setScoreboard(board);
    192. pi.setHelmet(glass);
    193. NotIt.put(player, null);
    194. player.setGameMode(GameMode.ADVENTURE);
    195. player.setHealth(20);
    196. player.setFoodLevel(1000);
    197. } else if (IsIt.containsKey(player)) {
    198. player.sendMessage(ChatColor.DARK_RED
    199. + "You are already playing tag!");
    200. } else if (NotIt.containsKey(player)) {
    201. player.sendMessage(ChatColor.DARK_RED
    202. + "You are already playing tag!");
    203. } else {
    204. player.sendMessage(ChatColor.DARK_RED
    205. + "Remove your helmet to play tag!");
    206. }
    207. } else {
    208. player.sendMessage(ChatColor.DARK_RED
    209. + "You can't play tag in this area!");
    210. }
    211. } else if (args[0].equalsIgnoreCase("leave")) {
    212. if (player.hasPermission(new Permissions().ctagleave)) {
    213. if (IsIt.containsKey(player)) {
    214. getServer().broadcastMessage(
    215. player.getDisplayName()
    216. + ChatColor.GOLD
    217. + " is no longer playing tag!");
    218. board.resetScores(player);
    219. player.setScoreboard(manager.getNewScoreboard());
    220. pi.setHelmet(air);
    221. IsIt.remove(player);
    222. player.setHealth(20);
    223. player.setFoodLevel(20);
    224. player.setGameMode(GameMode.SURVIVAL);
    225. } else if (NotIt.containsKey(player)) {
    226. getServer().broadcastMessage(
    227. player.getDisplayName()
    228. + ChatColor.GOLD
    229. + " is no longer playing tag!");
    230. pi.setHelmet(air);
    231. NotIt.remove(player);
    232. player.setHealth(20);
    233. player.setFoodLevel(20);
    234. player.setGameMode(GameMode.SURVIVAL);
    235. } else {
    236. player.sendMessage(ChatColor.DARK_RED
    237. + "You are not playing tag!");
    238. }
    239. } else {
    240. player.sendMessage(ChatColor.DARK_RED
    241. + "You can't play tag in this area!");
    242. }
    243. } else if (args[0].equalsIgnoreCase("me")) {
    244. if (player.hasPermission(new Permissions().ctagme)) {
    245. if (IsIt.containsKey(player)) {
    246. player.sendMessage(ChatColor.DARK_RED
    247. + "You are already it!");
    248. } else if (NotIt.containsKey(player)) {
    249. NotIt.remove(player);
    250. IsIt.put(player, null);
    251. Score score = obj.getScore(player);
    252. score.setScore(1);
    253. player.sendMessage(ChatColor.GOLD
    254. + "You are now it!");
    255. pi.setHelmet(wool);
    256. } else {
    257. player.sendMessage(ChatColor.DARK_RED
    258. + "Join Tag to become it!");
    259. }
    260. }
    261. } else if (args[0].equalsIgnoreCase("check")) {
    262. if (IsIt.containsKey(player)) {
    263. player.sendMessage(ChatColor.DARK_RED
    264. + "You are in the it group!");
    265. } else if (NotIt.containsKey(player)) {
    266. player.sendMessage(ChatColor.GOLD
    267. + "You are in the not it group!");
    268. } else {
    269. player.sendMessage(ChatColor.DARK_RED
    270. + "You are not even in tag!");
    271. }
    272. } else {
    273. player.sendMessage(ChatColor.DARK_RED
    274. + "You can't play tag in this area!");
    275. }
    276. }
    277. }
    278. }
    279. return false;
    280. }
    281. }
    282. // YAY NO MORE IF STATMENT!
     
  8. Offline

    newboyhun

    sockmonkey1
    Swap line 51 with 52.
    Change line 48 to:
    Objective obj = null;

    Man......
    Simple Java.
     
  9. Offline

    sockmonkey1

    Fixed the problem. Thanks so much I will keep this in mind and hopefully help other people. Thank you to all that helped.
     
Thread Status:
Not open for further replies.

Share This Page