Solved Player Kick and Quit Problem

Discussion in 'Plugin Development' started by Sicka_gp, Aug 19, 2013.

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

    Sicka_gp

    Hi, Please help. When a player is kicked out of the game, getting two messages. One message is PlayerKickEvent and the other is PlayerQuitEvent. Does anyone know how to fix it?

    Code:java
    1. @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
    2. public void onPlayerQuit(PlayerQuitEvent e){
    3. Player p = e.getPlayer();
    4. CSidebarManager.RemoveScoreBoardObjective(p);
    5. ConfigurableMessages.getScoreboardManager().RemoveScores(p);
    6. if(joinmessage){
    7. if(groupmessage && ConfigurableMessages.chat != null && ConfigurableMessages.permission != null){
    8. for(Player pl : Bukkit.getServer().getOnlinePlayers()){
    9. if(pl.canSee(p)){
    10. String jmessage = "Messages.Groups." + ConfigurableMessages.permission.getPrimaryGroup(p) + ".quit-message";
    11. String message = ConfigurableMessagesStringReplacer.replacer(p, jmessage);
    12. if(message != null){
    13. pl.sendMessage(message);
    14. }
    15. }
    16. }
    17. }else{
    18. for(Player pl : Bukkit.getServer().getOnlinePlayers()){
    19. if(pl.canSee(p)){
    20. String message = ConfigurableMessagesStringReplacer.replacer(p, "Messages.Default.quit-message");
    21. if(message != null){
    22. pl.sendMessage(message);
    23. }
    24. }
    25. }
    26. }
    27. }
    28. ConfigurableMessages.log.info("[ConfigurableMessages] " + p.getName() + " has quit the game.");
    29. e.setQuitMessage(null);
    30. }
    31.  
    32.  
    33. @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
    34. public void onPlayerKick(PlayerKickEvent e){
    35. Player p = e.getPlayer();
    36. CSidebarManager.RemoveScoreBoardObjective(p);
    37. ConfigurableMessages.getScoreboardManager().RemoveScores(p);
    38. if(joinmessage){
    39. if(groupmessage && ConfigurableMessages.chat != null && ConfigurableMessages.permission != null){
    40. for(Player pl : Bukkit.getServer().getOnlinePlayers()){
    41. if(pl.canSee(p)){
    42. String jmessage = "Messages.Groups." + ConfigurableMessages.permission.getPrimaryGroup(p) + ".kick-message";
    43. String message = ConfigurableMessagesStringReplacer.replacer(p, jmessage);
    44. if(message != null){
    45. if(message.contains("{REASON}")){
    46. message = message.replace("{REASON}", e.getReason());
    47. ConfigurableMessages.log.info(message);
    48. pl.sendMessage(message);
    49. }else{
    50. pl.sendMessage(message);
    51. }
    52. }
    53. }
    54. }
    55. }else{
    56. for(Player pl : Bukkit.getServer().getOnlinePlayers()){
    57. if(pl.canSee(p)){
    58. String message = ConfigurableMessagesStringReplacer.replacer(p, "Messages.Default.kick-message");
    59. if(message != null){
    60. if(message.contains("{REASON}")){
    61. message = message.replace("{REASON}", e.getReason());
    62. pl.sendMessage(message);
    63. ConfigurableMessages.log.info(message);
    64. }else{
    65. pl.sendMessage(message);
    66. }
    67. }
    68. }
    69. }
    70. }
    71. }
    72. ConfigurableMessages.log.info("[ConfigurableMessages] " + p.getName() + " has been kicked out of the game.");
    73. e.setLeaveMessage(null);
    74. }
     
  2. Offline

    Lactem

    PlayerKickEvent and PlayerQuitEvent should be separate. PlayerQuitEvent is when the player leaves the game on purpose, while PlayerKickEvent is when the player is kicked. Are you saying that it sends the message twice?
     
  3. Offline

    Sicka_gp

    Yes. Here is the log.
    Code:
    2013-08-19 22:01:24 [INFO] [ConfigurableMessages] Sicka_gp has been kicked out of the game.
    2013-08-19 22:01:24 [INFO] [ConfigurableMessages] Sicka_gp has quit the game.
    Please advise me

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  4. maybe use PlayerQuitEvent.setCancelled(true) or something?
     
  5. Offline

    Sicka_gp

    The problem is that if a player is kicked out of the game, performs are PlayerQuitEvent and PlayerKickEvent
     
  6. Sicka_gp
    maybe add them to a hashset, when the playerquitevent occurs check if the player who quits is in the hashset, and set the quitmessage to null and remove the player from the hashset? (I didn't test this)
     
  7. Offline

    Sicka_gp

    Good idea, I'll try it

    Datdenkikniet
    It works. Thank you for your help :)

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

Share This Page