error on making player chat

Discussion in 'Plugin Development' started by 16davidjm6, Jul 22, 2014.

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

    16davidjm6

    so my code:
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String alias, String[] args) {
    2.  
    3. //if not player, return
    4. if(!(sender instanceof Player)){
    5. return true;
    6. }
    7.  
    8. //get player
    9. Player player = (Player) sender;
    10.  
    11. //permission check if player is trying to use admin or mod chat
    12. if((cmd.getName().equalsIgnoreCase("a") && !player.hasPermission("brierieutil.admin")) || (cmd.getName().equalsIgnoreCase("m") && !player.hasPermission("brierieutil.mod"))){
    13. player.sendMessage(ChatColor.RED + "You do not have permission to use this command.");
    14. return true;
    15. }
    16.  
    17. //get the player's current channel
    18. ChannelType channel = ChatChannelHandler.getChannel(player.getUniqueId());
    19.  
    20. //set the channel based on command used
    21. switch(cmd.getName()){
    22. case "a":
    23. ChatChannelHandler.setChannel(player.getUniqueId(), ChannelType.ADMIN);
    24. break;
    25. case "g":
    26. ChatChannelHandler.setChannel(player.getUniqueId(), ChannelType.GLOBAL);
    27. break;
    28. case "l":
    29. ChatChannelHandler.setChannel(player.getUniqueId(), ChannelType.LOCAL);
    30. break;
    31. case "m":
    32. ChatChannelHandler.setChannel(player.getUniqueId(), ChannelType.MOD);
    33. break;
    34. case "nc":
    35. ChatChannelHandler.setChannel(player.getUniqueId(), ChannelType.NATION);
    36. break;
    37. case "tc":
    38. ChatChannelHandler.setChannel(player.getUniqueId(), ChannelType.TOWN);
    39. break;
    40. }
    41.  
    42. //get section containing worldgroups
    43. ConfigurationSection path = ChatConfig.get("worldGroups");
    44. String worldgroup = "";
    45.  
    46. //find world group
    47. for(String group: path.getKeys(false)){
    48. if(path.getStringList(group + ".worlds").contains(player.getWorld().getName())){
    49. worldgroup = group;
    50. }
    51. }
    52.  
    53. //get the group section from the config
    54. path = path.getConfigurationSection(worldgroup);
    55.  
    56. //check to see if chat is enabled for worldgroup
    57. boolean flag = false;
    58. String chats[] = path.getString("chats").split(",");
    59. for(String s: chats){
    60. if(s.equalsIgnoreCase(ChatChannelHandler.getChannel(player.getUniqueId()).toString())){
    61. flag = true;
    62. }
    63. }
    64.  
    65. if(flag == false){
    66. player.sendMessage(ChatColor.DARK_RED + "That chat is not enabled for this world.");
    67. return true;
    68. }
    69.  
    70. //if there are arguments, send the message and change channel back to what it was before
    71. if(args.length != 0){
    72. String message = "";
    73. for(String s: args){
    74. message += s + " ";
    75. }
    76. player.chat(message);
    77. ChatChannelHandler.setChannel(player.getUniqueId(), channel);
    78. return true;
    79. }
    80. //if already in specified channel switch to local
    81. else if(ChatChannelHandler.getChannel(player.getUniqueId()).equals(channel)){
    82. ChatChannelHandler.setChannel(player.getUniqueId(), ChannelType.LOCAL);
    83. player.sendMessage(ChatColor.DARK_GREEN + "Switching to LOCAL chat.");
    84. return true;
    85. //switch to chat specified
    86. } else{
    87. player.sendMessage(ChatColor.DARK_GREEN + "Switching to " + ChatChannelHandler.getChannel(player.getUniqueId()).toString() + " chat.");
    88. return true;
    89. }
    90. }


    on the line that says "player.chat(message)" sometimes this error will be thrown:
    Code:
    org.bukkit.command.CommandException: Unhandled exception executing command 'a' in plugin BrierieUtil v0.2
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit.jar:git-Spigot-1570]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:181) ~[craftbukkit.jar:git-Spigot-1570]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServer.java:767) ~[craftbukkit.jar:git-Spigot-1570]
        at net.minecraft.server.v1_7_R4.PlayerConnection.handleCommand(PlayerConnection.java:1017) [craftbukkit.jar:git-Spigot-1570]
        at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:847) [craftbukkit.jar:git-Spigot-1570]
        at net.minecraft.server.v1_7_R4.PacketPlayInChat.a(PacketPlayInChat.java:28) [craftbukkit.jar:git-Spigot-1570]
        at net.minecraft.server.v1_7_R4.PacketPlayInChat.handle(PacketPlayInChat.java:65) [craftbukkit.jar:git-Spigot-1570]
        at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:184) [craftbukkit.jar:git-Spigot-1570]
        at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java:81) [craftbukkit.jar:git-Spigot-1570]
        at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:731) [craftbukkit.jar:git-Spigot-1570]
        at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:289) [craftbukkit.jar:git-Spigot-1570]
        at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [craftbukkit.jar:git-Spigot-1570]
        at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [craftbukkit.jar:git-Spigot-1570]
        at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Spigot-1570]
    Caused by: java.lang.RuntimeException: Exception processing chat event
        at net.minecraft.server.v1_7_R4.PlayerConnection.chat(PlayerConnection.java:977) ~[craftbukkit.jar:git-Spigot-1570]
        at org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer.chat(CraftPlayer.java:264) ~[craftbukkit.jar:git-Spigot-1570]
        at backcab.BrierieUtil.Commands.ChatCommand.onCommand(ChatCommand.java:100) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Spigot-1570]
        ... 13 more
    (note that line 100 is the line "player.chat(message)")

    I can't figure out why this error is occurring. It is somehow causing users to hit this error, and causing them to no longer be able to send chat of any kind.

    My channels (for this chat plugin if you couldn't tell what it was), and their handlers all function properly with no issues as long as the command is issued without a message behind it.
     
  2. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    Seek support where you acquired your server mod.
     
Thread Status:
Not open for further replies.

Share This Page