GlobalMute not working?

Discussion in 'Plugin Development' started by Joshuak52, Jun 21, 2014.

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

    Joshuak52

    So i'm trying to make a GlobalMute plugin but it doesn't seem to be working? Here is my code

    Code:java
    1. public class Main extends JavaPlugin implements Listener{
    2.  
    3. public boolean chatEnabled = true;
    4.  
    5. public void onEnable() {
    6. System.out.print("OP Prison has been enabled!");
    7. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    8. }
    9.  
    10. public void onDisable() {
    11. System.out.print("OP Prison has been disabled!");
    12. }
    13. @EventHandler
    14. public void onPlayerChat(AsyncPlayerChatEvent e) {
    15. if(!chatEnabled) {
    16. System.out.print("test");
    17. e.setCancelled(true);
    18. }
    19. }
    20. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    21. if(cmd.getName().equalsIgnoreCase("MuteChat")) {
    22. chatEnabled = !chatEnabled;
    23. Bukkit.broadcastMessage(ChatColor.RED + "Chat is now muted!");
    24. }
     
  2. Offline

    fireblast709

  3. Offline

    Joshuak52

  4. Offline

    fireblast709

    Joshuak52 have you registered the command in your plugin.yml?
     
  5. Offline

    Joshuak52

  6. Offline

    sooon_mitch

    I do not know if you have fixed it yet or not but maybe instead of:

    chatEnabled = !chatEnabled;

    do

    chatEnabled = false;

    its more simple and is worth a test. Also you can make your command a boolean switch. So when you type the command it turns global chat on or off. Just a thought.
     
  7. Offline

    Joshuak52

  8. Offline

    Graysoldier

    Joshuak52
    Code:java
    1. @EventHandler
    2. public void onPlayerChat(AsyncPlayerChatEvent e) {
    3. if(chatEnabled == false) {
    4. System.out.print("test");
    5. e.setCancelled(true);
    6. }
    7. }

    and,
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    2. if(cmd.getName().equalsIgnoreCase("MuteChat")) {
    3. chatEnabled = !chatEnabled;
    4. Bukkit.broadcastMessage(ChatColor.RED + "Chat is now muted!");
    5. }
     
  9. Offline

    Joshuak52

  10. Offline

    Graysoldier

    Joshuak52
    Sorry, for the second one:
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    2. if(cmd.getName().equalsIgnoreCase("MuteChat")) {
    3. chatEnabled = false;
    4. Bukkit.broadcastMessage(ChatColor.RED + "Chat is now muted!");
    5. }
    6. }
     
  11. Offline

    Tommsy64

    First of all, don't use
    Code:java
    1. System.out.println();
    for logging, use
    Code:java
    1. plugin.getLogger().info();

    Second, make sure your events are registered during the onEnable();
    Third, try changing the event priority to something higher than normal (But not monitor).
     
  12. Offline

    Joshuak52

    That didn't work either
     
  13. Offline

    Graysoldier

    Joshuak52
    Can't see what else is wrong, sorry...
     
  14. Offline

    Joshuak52

  15. Offline

    Gater12

  16. Offline

    xize

    Joshuak52
    did the command printed its output? and any errors before enabling the plugin?, have you test to use the plugin without other plugins?
     
  17. Offline

    Joshuak52

    Gater12
    Same code as first post above

    xize
    No it didn't print the message
    No errors
    Thats how I tested it
     
  18. Offline

    xize

    Joshuak52
    aha, could it be that you have a other plugin with the same package name?

    like this:

    plugin1.jar:
    me.blub (where Main.java is the main class)

    and plugin2.jar:
    me.blub(where Main.java is the main class)

    ?
     
  19. Offline

    Joshuak52

    xize That couldn't be it because while testing this is the only plugin thats in the plugin folder
     
  20. Offline

    xize

    Joshuak52
    in that case I think your plugin.yml has a wrong package or what also could be a possibillity is that the plugin.yml is on a wrong location, mind sharing the plugin.yml and maybe a screenshot showing your project tree?
     
  21. Offline

    Fhbgsdhkfbl

    Joshuak52
    I don't believe in spoon feeding code, but you're having a bit of trouble, I'll help you out.

    Code:java
    1. private boolean chatDisabled = false; //Having a boolean, if chatdisabled is false, then you mute chat, it's putting it to true
    2. if (label.equalsIgnoreCase("cmute")) { //Command (Duh)
    3. if (p.hasPermission("p.admin")) { //permission if you don't want all the players to do it
    4. chatDisabled = chatDisabled ? false : true; // this toggles a boolean
    5. String enabledStr = chatDisabled ? "Disabled" : "Enabled"; //Broadcasts if it's on disabled, and you do the command, it will broadcast enabled.
    6. Bukkit.broadcastMessage(ChatColor.GOLD + "" + ChatColor.AQUA + " Chat has been " + enabledStr + " by " + ChatColor.RED + p.getName()); //broadcasts the message saying it's disabled
    7. } else {
    8. p.sendMessage(ChatColor.GOLD + "" + ChatColor.RED + "You must be a Mod to use this command!");
    9. }
    10. }
    11.  
    12.  
    13.  


    Then you need an event to stop the players from talking
    Code:java
    1. @EventHandler
    2. public void onChat(AsyncPlayerChatEvent e) { //Chat event you need
    3. Player p = e.getPlayer();
    4. if ((this.chatDisabled)//gets the boolean/string if it's disabled && (!p.hasPermission("p.mod"))) { //if they have that permission, they can talk, if not, they can't.
    5. e.setCancelled(true); //Cancels the chat so you don't see messages
    6. p.sendMessage(ChatColor.GOLD + "[DP Staff] " + ChatColor.RED + "Chat is currently disabled!"); //Sends a message to the player saying chat is disabled
    7. }
    8. }
     
Thread Status:
Not open for further replies.

Share This Page