Crashes my server!?

Discussion in 'Plugin Development' started by CraftCreeper6, Apr 24, 2014.

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

    CraftCreeper6

    Hello! I have a plugin that I am creating and when I access the GUI for my plugin it crashes my server...
    Code:
    Code:java
    1. package me.CraftCreeper6.utilites;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5.  
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.Location;
    9. import org.bukkit.Material;
    10. import org.bukkit.block.Block;
    11. import org.bukkit.block.Sign;
    12. import org.bukkit.enchantments.Enchantment;
    13. import org.bukkit.entity.Player;
    14. import org.bukkit.event.EventHandler;
    15. import org.bukkit.event.Listener;
    16. import org.bukkit.event.block.Action;
    17. import org.bukkit.event.inventory.InventoryClickEvent;
    18. import org.bukkit.event.player.PlayerInteractEvent;
    19. import org.bukkit.event.player.PlayerJoinEvent;
    20. import org.bukkit.inventory.Inventory;
    21. import org.bukkit.inventory.ItemStack;
    22. import org.bukkit.inventory.meta.ItemMeta;
    23. import org.bukkit.plugin.java.JavaPlugin;
    24. import org.bukkit.potion.PotionEffect;
    25. import org.bukkit.potion.PotionEffectType;
    26.  
    27. public class InvGUI extends JavaPlugin implements Listener {
    28.  
    29. private String pn = ChatColor.BLUE + "[" + ChatColor.GREEN + ChatColor.BOLD
    30. + "Mini" + ChatColor.RED + ChatColor.BOLD + " Game"
    31. + ChatColor.BLUE + "] " + ChatColor.LIGHT_PURPLE;
    32.  
    33. private void teleportInWorld(Player p, int x, int y, int z) {
    34.  
    35. p.teleport(new Location(p.getWorld(), x, y, z));
    36.  
    37. }
    38.  
    39. private void openGUI(Player p) {
    40.  
    41. Inventory inv = Bukkit.createInventory(null, 27, ChatColor.BLUE
    42. + "Kit Selector");
    43.  
    44. ItemStack tank = new ItemStack(Material.DIAMOND_CHESTPLATE);
    45. ItemMeta tankMeta = tank.getItemMeta();
    46.  
    47. ItemStack archer = new ItemStack(Material.BOW);
    48. ItemMeta archerMeta = archer.getItemMeta();
    49.  
    50. ItemStack knight = new ItemStack(Material.DIAMOND_SWORD);
    51. ItemMeta knightMeta = knight.getItemMeta();
    52.  
    53. ItemStack horse = new ItemStack(Material.HAY_BLOCK);
    54. ItemMeta horseMeta = horse.getItemMeta();
    55.  
    56. List<String> tankLore = new ArrayList<String>();
    57. tankLore.add(ChatColor.DARK_PURPLE + "" + ChatColor.ITALIC
    58. + "Tank for your friend and obliterate all in sight!");
    59. tankMeta.setLore(tankLore);
    60. tankMeta.setDisplayName(ChatColor.BOLD + "" + ChatColor.RED + ""
    61. + ChatColor.ITALIC + "TANK");
    62. tank.setItemMeta(tankMeta);
    63.  
    64. List<String> archerLore = new ArrayList<String>();
    65. archerLore.add(ChatColor.DARK_PURPLE + "" + ChatColor.ITALIC
    66. + "Stay back, Shoot, Kill!");
    67. archerMeta.setLore(archerLore);
    68. archerMeta.setDisplayName(ChatColor.BOLD + "" + ChatColor.RED + ""
    69. + ChatColor.ITALIC + "ARCHER");
    70. archer.setItemMeta(archerMeta);
    71.  
    72. List<String> knightLore = new ArrayList<String>();
    73. knightLore.add(ChatColor.DARK_PURPLE + "" + ChatColor.ITALIC
    74. + "Melee fighter deals alot of damage!");
    75. knightMeta.setLore(knightLore);
    76. knightMeta.setDisplayName(ChatColor.BOLD + "" + ChatColor.RED + ""
    77. + ChatColor.ITALIC + "KNIGHT");
    78. knight.setItemMeta(knightMeta);
    79.  
    80. List<String> horseLore = new ArrayList<String>();
    81. horseLore.add(ChatColor.DARK_PURPLE + "" + ChatColor.ITALIC
    82. + "High damage but low armor!");
    83. horseMeta.setLore(horseLore);
    84. horseMeta.setDisplayName(ChatColor.BOLD + "" + ChatColor.RED + ""
    85. + ChatColor.ITALIC + "HORSE");
    86. horse.setItemMeta(horseMeta);
    87.  
    88. inv.setItem(10, tank);
    89.  
    90. inv.setItem(12, archer);
    91.  
    92. inv.setItem(14, knight);
    93.  
    94. inv.setItem(16, horse);
    95.  
    96. p.openInventory(inv);
    97.  
    98. }
    99.  
    100. @EventHandler
    101. public void onInvClick(InventoryClickEvent e) {
    102.  
    103. if (!ChatColor.stripColor(e.getInventory().getName()).equalsIgnoreCase(
    104. "Kit Selector"))
    105. return;
    106.  
    107. Player p = (Player) e.getWhoClicked();
    108.  
    109. e.setCancelled(true);
    110.  
    111. if (e.getCurrentItem() == null
    112. || e.getCurrentItem().getType() == Material.AIR
    113. || !e.getCurrentItem().hasItemMeta()) {
    114. p.closeInventory();
    115. return;
    116. }
    117.  
    118. switch (e.getCurrentItem().getType()) {
    119.  
    120. case DIAMOND_CHESTPLATE:
    121.  
    122. p.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST,
    123. 2, Integer.MAX_VALUE));
    124.  
    125. p.getInventory().clear();
    126.  
    127. teleportInWorld(p, 72, 69, 140);
    128. ItemStack tankarmorchest = new ItemStack(
    129. Material.DIAMOND_CHESTPLATE);
    130. ItemStack tankarmorhelm = new ItemStack(Material.DIAMOND_HELMET);
    131. ItemStack tankarmorleggs = new ItemStack(Material.DIAMOND_LEGGINGS);
    132. ItemStack tankarmorboots = new ItemStack(Material.DIAMOND_BOOTS);
    133. ItemStack tankarmorsword = new ItemStack(Material.IRON_SWORD);
    134. ItemStack tankarmorfood = new ItemStack(Material.COOKED_BEEF, 32);
    135.  
    136. tankarmorchest.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL,
    137. 1);
    138. tankarmorhelm.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL,
    139. 1);
    140. tankarmorleggs.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL,
    141. 1);
    142. tankarmorboots.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL,
    143. 1);
    144. tankarmorsword.addEnchantment(Enchantment.DAMAGE_ALL, 2);
    145.  
    146. p.getInventory().setHelmet(tankarmorhelm);
    147. p.getInventory().setChestplate(tankarmorchest);
    148. p.getInventory().setLeggings(tankarmorleggs);
    149. p.getInventory().setBoots(tankarmorboots);
    150.  
    151. p.getInventory().addItem(tankarmorsword);
    152. p.getInventory().addItem(tankarmorfood);
    153.  
    154. p.closeInventory();
    155.  
    156. break;
    157.  
    158. case BOW:
    159. p.getInventory().clear();
    160.  
    161. p.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST,
    162. 2, 1));
    163.  
    164. teleportInWorld(p, 72, 69, 140);
    165. ItemStack archerarmorchest = new ItemStack(
    166. Material.LEATHER_CHESTPLATE);
    167. ItemStack archerarmorhelm = new ItemStack(Material.LEATHER_HELMET);
    168. ItemStack archerarmorleggs = new ItemStack(
    169. Material.LEATHER_LEGGINGS);
    170. ItemStack archerarmorboots = new ItemStack(Material.LEATHER_BOOTS);
    171. ItemStack archerarmorbow = new ItemStack(Material.BOW);
    172. ItemStack archerarmorfood = new ItemStack(Material.COOKED_BEEF, 32);
    173. ItemStack archerarrow = new ItemStack(Material.ARROW);
    174.  
    175. archerarmorchest.addEnchantment(
    176. Enchantment.PROTECTION_ENVIRONMENTAL, 2);
    177. archerarmorhelm.addEnchantment(
    178. Enchantment.PROTECTION_ENVIRONMENTAL, 2);
    179. archerarmorleggs.addEnchantment(
    180. Enchantment.PROTECTION_ENVIRONMENTAL, 2);
    181. archerarmorboots.addEnchantment(
    182. Enchantment.PROTECTION_ENVIRONMENTAL, 2);
    183. archerarmorbow.addEnchantment(Enchantment.ARROW_DAMAGE, 2);
    184. archerarmorbow.addEnchantment(Enchantment.ARROW_INFINITE, 1);
    185.  
    186. p.getInventory().setHelmet(archerarmorhelm);
    187. p.getInventory().setChestplate(archerarmorchest);
    188. p.getInventory().setLeggings(archerarmorleggs);
    189. p.getInventory().setBoots(archerarmorboots);
    190.  
    191. p.getInventory().addItem(archerarmorbow);
    192. p.getInventory().addItem(archerarmorfood);
    193. p.getInventory().addItem(archerarrow);
    194.  
    195. p.closeInventory();
    196.  
    197. break;
    198.  
    199. case DIAMOND_SWORD:
    200.  
    201. p.getInventory().clear();
    202.  
    203. p.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST,
    204. 2, Integer.MAX_VALUE));
    205.  
    206. teleportInWorld(p, 72, 69, 140);
    207. ItemStack knightarmorchest = new ItemStack(Material.IRON_CHESTPLATE);
    208. ItemStack knightarmorhelm = new ItemStack(Material.IRON_HELMET);
    209. ItemStack knightarmorleggs = new ItemStack(Material.IRON_LEGGINGS);
    210. ItemStack knightarmorboots = new ItemStack(Material.IRON_BOOTS);
    211. ItemStack knightarmorsword = new ItemStack(Material.DIAMOND_SWORD);
    212. ItemStack knightarmorfood = new ItemStack(Material.COOKED_BEEF, 32);
    213.  
    214. knightarmorchest.addEnchantment(
    215. Enchantment.PROTECTION_ENVIRONMENTAL, 2);
    216. knightarmorhelm.addEnchantment(
    217. Enchantment.PROTECTION_ENVIRONMENTAL, 2);
    218. knightarmorleggs.addEnchantment(
    219. Enchantment.PROTECTION_ENVIRONMENTAL, 2);
    220. knightarmorboots.addEnchantment(
    221. Enchantment.PROTECTION_ENVIRONMENTAL, 2);
    222. knightarmorsword.addEnchantment(Enchantment.DAMAGE_ALL, 1);
    223. knightarmorsword.addEnchantment(Enchantment.KNOCKBACK, 1);
    224.  
    225. p.getInventory().setHelmet(knightarmorhelm);
    226. p.getInventory().setChestplate(knightarmorchest);
    227. p.getInventory().setLeggings(knightarmorleggs);
    228. p.getInventory().setBoots(knightarmorboots);
    229.  
    230. p.getInventory().addItem(knightarmorsword);
    231. p.getInventory().addItem(knightarmorfood);
    232.  
    233. p.closeInventory();
    234.  
    235. break;
    236.  
    237. case HAY_BLOCK:
    238.  
    239. p.getInventory().clear();
    240.  
    241. p.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST,
    242. 2, Integer.MAX_VALUE));
    243.  
    244. teleportInWorld(p, 72, 69, 140);
    245. ItemStack horsearmorchest = new ItemStack(Material.IRON_CHESTPLATE);
    246. ItemStack horsearmorhelm = new ItemStack(Material.IRON_HELMET);
    247. ItemStack horsearmorleggs = new ItemStack(Material.IRON_LEGGINGS);
    248. ItemStack horsearmorboots = new ItemStack(Material.IRON_BOOTS);
    249. ItemStack horsearmorsword = new ItemStack(Material.IRON_SWORD);
    250. ItemStack horsearmorfood = new ItemStack(Material.COOKED_BEEF, 32);
    251.  
    252. horsearmorchest.addEnchantment(
    253. Enchantment.PROTECTION_ENVIRONMENTAL, 2);
    254. horsearmorhelm.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL,
    255. 2);
    256. horsearmorleggs.addEnchantment(
    257. Enchantment.PROTECTION_ENVIRONMENTAL, 2);
    258. horsearmorboots.addEnchantment(
    259. Enchantment.PROTECTION_ENVIRONMENTAL, 2);
    260. horsearmorsword.addEnchantment(Enchantment.DAMAGE_ALL, 3);
    261.  
    262. p.getInventory().setHelmet(horsearmorhelm);
    263. p.getInventory().setChestplate(horsearmorchest);
    264. p.getInventory().setLeggings(horsearmorleggs);
    265. p.getInventory().setBoots(horsearmorboots);
    266.  
    267. p.getInventory().addItem(horsearmorsword);
    268. p.getInventory().addItem(horsearmorfood);
    269.  
    270. p.closeInventory();
    271.  
    272. break;
    273.  
    274. default:
    275. break;
    276. }
    277.  
    278. }
    279.  
    280. @EventHandler
    281. public void onPlayerInteract(PlayerInteractEvent event) {
    282. Player p = event.getPlayer();
    283. Block block = event.getClickedBlock();
    284.  
    285. if (block != null && block.getType() == Material.SIGN_POST
    286. || block.getType() == Material.WALL_SIGN) {
    287. Sign sign = (Sign) block.getState();
    288. Action action = event.getAction();
    289. if (action == Action.RIGHT_CLICK_BLOCK) {
    290. if (sign.getLine(0).equalsIgnoreCase("[Minigame]")
    291. && sign.getLine(1).equalsIgnoreCase("Kit")
    292. && sign.getLine(2).equalsIgnoreCase("Selector")
    293. || sign.getLine(0).equalsIgnoreCase("§a[Minigame]")
    294. && sign.getLine(1).equalsIgnoreCase("§bKit")
    295. && sign.getLine(2).equalsIgnoreCase("§bSelector")
    296. && p.hasPermission("Sign.Interact.KitSelect")) {
    297.  
    298. if (p.hasPermission("Sign.Create.KitSelect")) {
    299.  
    300. sign.setLine(0, "§a[Minigame]");
    301. sign.setLine(1, "§bKit");
    302. sign.setLine(2, "§bSelector");
    303. sign.setLine(3, "§aRight Click");
    304. sign.update();
    305.  
    306. openGUI(event.getPlayer());
    307. }
    308. } else {
    309.  
    310. }
    311. }
    312. }
    313. }
    314.  
    315. @EventHandler
    316. public void onPlayerInteractSign(PlayerInteractEvent event) {
    317. Player p = event.getPlayer();
    318. Block block = event.getClickedBlock();
    319.  
    320. if (block != null && block.getType() == Material.SIGN_POST
    321. || block.getType() == Material.WALL_SIGN) {
    322.  
    323. Sign sign = (Sign) block.getState();
    324. Action action = event.getAction();
    325. if (action == Action.RIGHT_CLICK_BLOCK) {
    326. if (sign.getLine(0).equalsIgnoreCase("[Minigame]")
    327. && sign.getLine(1).equalsIgnoreCase("Help")
    328. || sign.getLine(0).equalsIgnoreCase("§a[Minigame]")
    329. && sign.getLine(1).equalsIgnoreCase("§4Help")
    330. && p.hasPermission("Sign.Interact.Help")) {
    331.  
    332. if (p.hasPermission("Sign.Create.Help")) {
    333.  
    334. sign.setLine(0, "§a[Minigame]");
    335. sign.setLine(1, "§4HELP ME");
    336. sign.update();
    337.  
    338. p.sendMessage(pn + "Commands:");
    339. p.sendMessage(pn + "/minigame leave - Leave the game!");
    340. p.sendMessage(pn
    341. + "/minigame set leavespawn - Set leave spawn!");
    342.  
    343. } else {
    344.  
    345. }
    346. } else {
    347.  
    348. }
    349. }
    350. }
    351. }
    352.  
    353. @EventHandler
    354. public void onJoin(PlayerJoinEvent e) {
    355. e.getPlayer().getInventory().addItem(new ItemStack(Material.COMPASS));
    356. Player p = e.getPlayer();
    357.  
    358. p.sendMessage("TEST");
    359. }
    360.  
    361. @EventHandler
    362. public void Interact(PlayerInteractEvent e) {
    363.  
    364. Action a = e.getAction();
    365. ItemStack is = e.getItem();
    366.  
    367. if (a == Action.PHYSICAL || is == null || is.getType() == Material.AIR)
    368. return;
    369.  
    370. if (is.getType() == Material.COMPASS) {
    371. openGUI(e.getPlayer());
    372. }
    373.  
    374. }
    375. }


    It takes about 5 seconds for the server to crash after you access the GUI :/
    Any help apprecieated!
     
  2. Offline

    coasterman10

    Try putting a debug message when the GUI is opened to make sure there isn't an infinite loop somewhere. Also if you can wait for the server to generate stacktraces or any other errors that would be useful.
     
  3. Offline

    CraftCreeper6

    coasterman10
    It does not repeat as t only sends me the message once :/
    Did get a stacktrace though :D
    Here it is:
    Code:
    [18:03:41 ERROR]: Could not pass event PlayerInteractEvent to Minigame v1.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:427) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:481) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:466) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.callPlayerInte
    ractEvent(CraftEventFactory.java:191) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b29
    74jnks]
            at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.callPlayerInte
    ractEvent(CraftEventFactory.java:161) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b29
    74jnks]
            at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java
    :604) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.PacketPlayInBlockPlace.a(SourceFile:60)
    [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.PacketPlayInBlockPlace.handle(SourceFile
    :9) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146
    ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craf
    tbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:6
    55) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:2
    50) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:5
    45) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java
    :457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:6
    17) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    Caused by: java.lang.NullPointerException
            at me.CraftCreeper6.utilites.InvGUI.onPlayerInteractSign(InvGUI.java:322
    ) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0
    _45]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0
    _45]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
    .7.0_45]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_45]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:425) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            ... 15 more
     
  4. Offline

    BDKing88

    CraftCreeper6 Check line 322 the stack trace says there is an error there: "me.CraftCreeper6.utilites.InvGUI.onPlayerInteractSign(InvGUI.java:322"
     
  5. Offline

    stink123456

    This won't fix the issue but i would use .equals to compare stuff, is alot safer (especially on objects).
     
  6. Offline

    coasterman10

    It is not safer at all except when testing objects that may be the same but have different references. Using == cannot throw any null pointer exceptions, and is the correct way to compare enums, since all equals() does for an enum is call ==.
     
  7. Offline

    stink123456

    That's completly correct. I am sorry for the confusion.
     
Thread Status:
Not open for further replies.

Share This Page