How to disable chat for a certain player?

Discussion in 'Plugin Development' started by bobbysmithyy, Dec 30, 2011.

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

    bobbysmithyy

    Hey guys just wondering, how do you disable chat for a certain player?
     
  2. Offline

    immac636

    bobbysmithyy likes this.
  3. Offline

    bobbysmithyy

    Do you by any chance know how to set timed/delayed messages so that if someone does say, "/rules" then the messages go one at a time so like it would say "1. no griefing" then 2 seconds later "2.blah" Please reply so I get a notification
     
  4. Offline

    ItsHarry

    Just wondering, does onPlayerChat also work if you use /me? If not, that's something you could add to your plugin :D
     
  5. Offline

    immac636

    You can use:
    Code:
    try {
        s.sendMessage("Rule 1 - No griefing");
        Thread.sleep(Time in milliseconds/*long*/); // For seconds, use (long) * 1000
        s.sendMessage("Rule 2");
        Thread.sleep(2000); // 2 seconds
        s.sendMessage("Rule 3");
    } catch (InterruptedException e) {
        e.printStackTrace;
    }
        
     
    bobbysmithyy and WizzleDonker like this.
  6. Offline

    bobbysmithyy

    Your awesome
     
  7. Offline

    immac636

    Looking at this: https://github.com/Bukkit/Bukkit/bl...va/org/bukkit/command/defaults/MeCommand.java

    It looks like you can't stop that, as it broadcasts a server message. You could only stop it if you made a new /me command

    Thanks, but this breaks if you use it in things directly related to the server. (If you put Thread.sleep() in onEnable(), for example).

    It works well with commands though, so feel free to use it. If you need it for another purpose, see here: http://wiki.bukkit.org/Scheduler_Programming#Delayed_Tasks

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

    hatstand

    Nope. Calling it where you are is putting the main thread to sleep. This is bad. Do not do it.

    As for intercepting /me, you can do that (and other commands) with the playerCommandPreprocess event.
     
  9. Offline

    immac636

    Calling it in onCommand()? It works fine for me. If you put the main thread to sleep, it crashes the whole server, which this does not. I was meaning that if you were going to delay anything else, you should use bukkit scheduler. :/

    EDIT: I may have been a little bit confusing when I explained it. Heres what I meant. DO NOT put Thread.sleep in onEnable(), or anywhere that is related to the server. As what bobbysmithyy was trying to do was just delay a message, Thread.sleep() was fine. I always test things before I post (or commit/export), so it will work.
     
  10. Offline

    hatstand

    I called Thread.Sleep(10000) inside my onCommand, server stopped for 10 seconds. Calling it anywhere outside of a separate thread will sleep the server's main thread. If you do it in a separate thread, ie, in a delayed or async task, that's fine. Your initial example however, does not use these.
     
  11. Offline

    immac636

    This, then?

    Code:
    	p.sendMessage(ChatColor.GOLD + "Rules:");
    	Mute.plugin.getServer().getScheduler().scheduleSyncDelayedTask(Mute.plugin, new Runnable() {
    		public void run() {
    			p.sendMessage(config.getString("Rules.1"));
    		}
    	}, 60L);
    	Mute.plugin.getServer().getScheduler().scheduleSyncDelayedTask(Mute.plugin, new Runnable() {
    		public void run() {
    			p.sendMessage(config.getString("Rules.2"));
    		}
    	}, 60L);
    	Mute.plugin.getServer().getScheduler().scheduleSyncDelayedTask(Mute.plugin, new Runnable() {
    		public void run() {
    			p.sendMessage(config.getString("Rules.3"));
    		}
    	}, 60L);
     
  12. Offline

    bergerkiller

    @immac636 You do need to increment the delays (60L, 120L, 180L) if you want to show the rules one by one. Right now it simply shows all rules at once, but after a 60 tick delay.
     
    immac636 likes this.
Thread Status:
Not open for further replies.

Share This Page