Muting Chat Isn't Working

Discussion in 'Plugin Development' started by BJCxMC, Jul 7, 2014.

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

    BJCxMC

    I can never seen to get this thing right, my mute chat NEVER works hopefully one of you can help out. No errors or nothing, just wont work.

    Code:java
    1. package com.MrBJC412.bServer;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.World;
    8. import org.bukkit.command.Command;
    9. import org.bukkit.command.CommandSender;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.event.EventHandler;
    12. import org.bukkit.event.Listener;
    13. import org.bukkit.event.player.AsyncPlayerChatEvent;
    14. import org.bukkit.event.player.PlayerJoinEvent;
    15. import org.bukkit.event.server.ServerListPingEvent;
    16. import org.bukkit.plugin.java.JavaPlugin;
    17.  
    18. public class Main extends JavaPlugin implements Listener{
    19.  
    20. private boolean chatDisabled = false;
    21. public ArrayList<String> worlds = new ArrayList();
    22.  
    23. public void onEnable() {
    24. Bukkit.getPluginManager().registerEvents(this, this);
    25. }
    26.  
    27. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String [] args ) {
    28. Player p = (Player) sender;
    29. if(cmd.getName().equalsIgnoreCase("mutechat")) {
    30. if(p.hasPermission("Basic.mutechat")) {
    31. this.worlds.removeAll(this.worlds);
    32.  
    33. this.chatDisabled = false;
    34. Bukkit.broadcastMessage(ChatColor.RED + "Chat has been muted!");
    35. return true;
    36. }
    37. }
    38. if(cmd.getName().equalsIgnoreCase("unmutechat")) {
    39. if(p.hasPermission("Basic.unmutechat")) {
    40. this.chatDisabled = true;
    41. Bukkit.broadcastMessage(ChatColor.RED + "Chat has been unmuted!");
    42. }
    43. }
    44. return false;
    45. }
    46.  
    47.  
    48. @EventHandler
    49. public void onChat(AsyncPlayerChatEvent e) {
    50. Player p = e.getPlayer();
    51. World w = p.getWorld();
    52. String world = w.toString();
    53. if (((this.chatDisabled) || (this.worlds.contains(world))) &&
    54. (!p.hasPermission("mchat.bypass")))
    55. {
    56. e.setCancelled(true);
    57. }
    58. }
    59.  
     
  2. Offline

    Asgernohns

    BJCxMC if you wanna get the name of the world the player is in, then you will need to call w.getName();
     
  3. Offline

    BJCxMC

    All that did was give me an error in console while loading the plugin.


     
  4. Offline

    Asgernohns

    BJCxMC did you add anything else to the code than that? Because it seems to have trouble finding the main class
     
  5. Offline

    BJCxMC

    All I changed was this:
    Code:java
    1. String world = w.toString();

    to:
    Code:java
    1. String world = w.getName();
     
  6. Offline

    Asgernohns

    BJCxMC it seems quite odd because that piece of code doesn't even get executed at that point. Are you sure you didn't modify the plugin.yml or change anything other in your IDE/workspace than that piece of code?
     
  7. Offline

    caderape

    I dun know if its the cause, but you don't need a method onDisable() ? Even if it's empty
     
  8. Offline

    valon750

    BJCxMC

    Check your plugin.yml, check for that class, you could of changed one little letter.
     
  9. Offline

    mythbusterma

    BJCxMC
    Bukkit says that that class doesn't exist, try checking to make sure it's exporting correctly, and the fully-qualified name is typed EXACTLY in the plugin.yml.

    Now, about the name. The package name should be all lower case, and you shouldn't begin it with a domain name you don't own, i.e. unless you own mrbjc412.com, you shouldn't use that as a package name (alternative: me.mrbjc412.bserver.Main as the fully-qualified name).

    Next, about your variables. There is no reason (at least, in the code that you have shown us) that you have the toString() value of worlds stored, and you shouldn't be storing the toString() value of worlds anyways, use the UUID of the world, World#getUid() I believe it is.

    Finally, you can't just use Player#hasPermission(String) in an async method (in this case, onChat()). You must make the call thread safe, I've described one method for doing so here: http://forums.bukkit.org/threads/real-quick-asyncplayerchatevent-question.288386/#post-2637595
     
  10. Offline

    teej107

    caderape Your main: in your plugin.yml is pointing to a non-existant JavaPlugin extended class

    EDIT: Ninja'D
     
  11. Offline

    BJCxMC

    Okay I fixed the error, but I can still chat when it's supposed to be muted, heres a picture.
    http://gyazo.com/d14425064859f61d023447c1958d9112
    **The code has already been posted for new viewers**
     
  12. Offline

    mythbusterma

    Make lines 53-54 each separate if statements and add different behaviour for each to determine where your code is failing, also see my post above.
     
  13. Offline

    Asgernohns

    BJCxMC you need to swap the two true and false in the onCommand
     
Thread Status:
Not open for further replies.

Share This Page