Asynchronous player kick

Discussion in 'Plugin Development' started by michiletsplay, Jul 1, 2013.

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

    michiletsplay

    Hi,

    here is my code:
    Code:java
    1. @EventHandler (priority = EventPriority.NORMAL)
    2. public void antiSpam (AsyncPlayerChatEvent e) {
    3. //code
    4. e.getPlayer().kickPlayer("You are not allowed to spam!");
    5. //more code
    6. }

    The console says '[INFO] Error: Asynchronous player kick!'
    I googled the problem and it looks like I have to use the PlayerChatEvent (Sync).

    But then I get this:
    Code:
    The type PlayerChatEvent is deprecated
    What could I use?
     
  2. Offline

    phrstbrn

    Use Bukkit.getScheduler().runTask(...)

    Ie:


    Code:java
    1. final Player p = ...
    2. Bukkit.getScheduler().runTask(plugin, new Runnable() {
    3. public void run() {
    4. p.kickPlayer(....);
    5. }
    6. });
     
  3. Offline

    michiletsplay

    Thanks you.
    But now I get much errores like 'insert {' when I repeat this.

    Can a runTask() be in an if() ?

    My Code :D (open)

    Code:java
    1. if (statsC.getInt(e.getPlayer().getName() + ".badPoints") == 5){
    2. Bukkit.getScheduler().runTask(this, new Runnable() {
    3. @Override
    4. public void run() {
    5. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "tempban " + e.getPlayer().getName() + " 1 h");
    6. e.getPlayer().kickPlayer(this.tag + ChatColor.RED + "Du wurdest für eine Stunde gebannt! Grund: Beleidigung/Anstößiges verhalten. Bitte Unterlasse es in Zukunft!");
    7. }
    8. });
    9. }
    10. if (statsC.getInt(e.getPlayer().getName() + ".badPoints") == 15){
    11. Bukkit.getScheduler().runTask(this, new Runnable() {
    12. @Override
    13. public void run() {
    14. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "tempban " + e.getPlayer().getName() + " 1 h");
    15. e.getPlayer().kickPlayer(this.tag + ChatColor.RED + "Du wurdest für eine Stunde gebannt! Grund: Beleidigung/Anstößiges verhalten. Bitte Unterlasse es in Zukunft!");
    16. }
    17. });
    18. }

     
Thread Status:
Not open for further replies.

Share This Page