Solved Player join event gives internal error

Discussion in 'Plugin Development' started by LordTherd, Aug 18, 2014.

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

    LordTherd

    So I did this:
    Code:
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e){
            Player p = e.getPlayer();
            p.teleport(p.getWorld().getSpawnLocation());
            Menu.openGUI(p);
    and when I join i get an internal server error :/
    The Gui works, i tested it with i command.

    any help? :)
     
  2. Offline

    DinosParkour

    LordTherd What's the error? I tested it and it works just fine
     
  3. Offline

    LordTherd

    no error in the console only internal server error in minecraft. I cant event connect.
    EDIT: now it gives me an error log:

    Code:
    Lord_Therd[/192.168.2.11:62262] logged in with entity id 245 at ([world] 451.0, 129.0, 1108.0)
    [14:33:01] [Server thread/WARN]: Failed to handle packet for /192.168.2.11:62262
    java.lang.IllegalArgumentException: Listener already listening
        at net.minecraft.server.v1_7_R1.Container.addSlotListener(Container.java:53) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.EntityPlayer.syncInventory(EntityPlayer.java:152) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PlayerList.a(PlayerList.java:131) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.LoginListener.c(LoginListener.java:78) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.LoginListener.a(LoginListener.java:42) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:149) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    [14:33:01] [Server thread/INFO]: Lord_Therd lost connection: Internal server error
    [14:33:01] [Server thread/INFO]: Lord_Therd left the game.
    DinosParkour
     
  4. Offline

    Tecno_Wizard

    LordTherd Do you accidentally have 2 on join listeners?
     
  5. Offline

    parat26

    It seems to me that you are registering the listener more than one time. Are you sure you did not register it on the main class and on it's class itself?
     
  6. Offline

    LordTherd

    checked it but no :/
     
  7. Offline

    DinosParkour

  8. Offline

    LordTherd


    public void onEnable() {
    PluginManager pm = Bukkit.getPluginManager();
    pm.registerEvents(this, this);
    }


    Code:java
    1. public class Main extends JavaPlugin implements Listener{
    2.  
    3. World kitpvpworld;
    4.  
    5. String k = "§8[§b§lKitPvp§8] ";
    6. String kb = "§8[§c§lKitPvp§8] ";
    7. Location spawn = new Location(kitpvpworld, 1, 1, 1);
    8. ArrayList<String> build = new ArrayList<String>();
    9.  
    10. public void onEnable() {
    11. PluginManager pm = Bukkit.getPluginManager();
    12. pm.registerEvents(new Scoreboard(),this);
    13. pm.registerEvents(this, this);
    14.  
    15. kitpvpworld = Bukkit.getWorld("kitpvpworld");
    16.  
    17. }
    18.  
    19. @EventHandler
    20. public void onClickSlot(InventoryClickEvent e) {
    21. Player p = (Player) e.getWhoClicked();
    22. if(!build.contains(p.getName())){
    23. e.setResult(Result.DENY);
    24. e.setCancelled(true);
    25. }
    26. else {
    27. return;
    28. }
    29. }
    30.  
    31. @EventHandler
    32. public void onInventoryClick(InventoryClickEvent event) {
    33. if (!ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase("Select your kit!")) return;
    34. Player p = (Player) event.getWhoClicked();
    35. event.setCancelled(true);
    36.  
    37. if(event.getCurrentItem()==null || event.getCurrentItem().getType()==Material.AIR||!event.getCurrentItem().hasItemMeta()){
    38. p.closeInventory();
    39. return;
    40. }
    41.  
    42. switch(event.getCurrentItem().getType()) {
    43. case BOW:
    44. KitItems.getArcherKit(p);
    45. p.closeInventory();
    46. break;
    47. case DIAMOND_SWORD:
    48. KitItems.getAssasinKit(p);
    49. p.closeInventory();
    50. break;
    51. case NETHER_STAR:
    52. if(!p.hasPermission("therdgames.vip")){
    53. p.sendMessage(kb + "§c§lThis is a vip kit!");
    54. return;
    55. }
    56. else{
    57. KitItems.getVipKit(p);
    58. p.closeInventory();
    59. break;
    60. }
    61. case POTION:
    62. KitItems.getWitchKit(p);
    63. p.closeInventory();
    64. break;
    65. case DIAMOND_CHESTPLATE:
    66. KitItems.getTankKit(p);
    67. break;
    68. default:
    69. p.closeInventory();
    70. break;
    71. }
    72. }
    73.  
    74. @EventHandler
    75. public void onItemDrop(PlayerDropItemEvent e){
    76.  
    77. Item item = e.getItemDrop();
    78. int slot = e.getPlayer().getInventory().getHeldItemSlot();
    79. PlayerInventory pi = e.getPlayer().getInventory();
    80. ItemMeta meta = item.getItemStack().getItemMeta();
    81. ItemStack stack = item.getItemStack();
    82. Player p = e.getPlayer();
    83.  
    84. stack.setItemMeta(meta);
    85. pi.setItem(slot, stack);
    86. e.getItemDrop().remove();
    87.  
    88. p.sendMessage(kb + "§c§lYou can not drop that item!");
    89. }
    90.  
    91. @EventHandler
    92. public void onPlayerDeath(PlayerDeathEvent e) {
    93. Player p = e.getEntity().getPlayer();
    94. if(p.getKiller() instanceof Player){
    95. Player k = (Player) p.getKiller();
    96. Location loc = p.getWorld().getSpawnLocation();
    97. p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 1, 1));
    98. p.teleport(loc);
    99. p.setHealth(20D);
    100. Bukkit.broadcastMessage(k + "§4§l" + p.getName() + " §c§lwas killed by §a§l" +
    101. k.getName() + "§c§l!");
    102. Menu.openGUI(p);
    103. }
    104. else{
    105. Location loc = p.getWorld().getSpawnLocation();
    106. p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 20, 1));
    107. p.teleport(p.getWorld().getSpawnLocation());
    108. p.setHealth(20D);
    109. p.getInventory().clear();
    110. p.teleport(loc);
    111. Menu.openGUI(p);
    112. }
    113. }
    114.  
    115. @EventHandler
    116. public void onPlayerJoin(PlayerJoinEvent e){
    117. Player p = e.getPlayer();
    118. p.teleport(p.getWorld().getSpawnLocation());
    119. Menu.openGUI(p);
    120. }
    121.  
    122. @Override
    123. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    124. Player p = (Player) sender;
    125. Location loc = p.getLocation();
    126. if (cmd.getName().equalsIgnoreCase("setspawnloc")) {
    127. if(args.length == 0){
    128. p.getWorld().setSpawnLocation((int)loc.getX(), (int)loc.getY(), (int)loc.getZ());
    129. p.sendMessage(k + "§b§lSpawn point set!");
    130. }
    131. else {
    132. p.sendMessage(kb + "§c§lNo need for arguments.");
    133. }
    134. }
    135. else if(cmd.getName().equalsIgnoreCase("build")){
    136. if (!(sender instanceof Player)) {
    137. sender.sendMessage("This command can only be run by a player.");
    138. }
    139. else {
    140. Player player = (Player) sender;
    141. if(!player.hasPermission("therdgames.build")){
    142. player.sendMessage(kb + "§c§lYou dont have permission to do this!");
    143. }
    144. else {
    145. if(!build.contains(p.getName())){
    146. build.add(player.getName());
    147. player.sendMessage(k + "§b§lYou can now build.");
    148. }
    149. else {
    150. build.remove(player.getName());
    151. player.sendMessage(k + "§b§lYou can no longer build.");
    152. }
    153. }
    154. }
    155. }
    156. else if(cmd.getName().equalsIgnoreCase("archerkit")){
    157. KitItems.getArcherKit(p);
    158. }
    159. else if(cmd.getName().equalsIgnoreCase("kitpvp")){
    160. Menu.openGUI(p);
    161. }
    162.  
    163. return false;
    164. }
    165.  
    166. @EventHandler
    167. public void onBlockBreak(BlockBreakEvent e){
    168. Player p = e.getPlayer();
    169. if(!build.contains(p.getName())){
    170. e.setCancelled(true);
    171. }
    172. }
    173. }


    DinosParkour all my listeners are in the main class

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

    DinosParkour

    LordTherd If teleporting the player to spawn is your problem, I cannot see why that happens because when I test the code, it works
     
  10. Offline

    LordTherd

    DinosParkour when i connect to the server it throws this error message and i get kicked immediately
     
  11. Offline

    DinosParkour

    LordTherd Maybe you've loaded the plugin twice? (check your plugins folder) I'm sure this doesn't make sense but I cannot see why you get that error :(
     
  12. Offline

    LordTherd

    DinosParkour :( k. Thanks for at leats trying to help! :/

    DinosParkour i fixed it. Just had to remove the openGui(p); :D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page