Anti Swear Plugin Problem

Discussion in 'Plugin Development' started by Atomicbeast101, Jan 5, 2013.

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

    Atomicbeast101

    Okay this plugin is supposed to kick player for swearing the three common swear words. (its in the code). I dont see any error in the eclipse program and when i tried to run it in the server ( btw there was no errors showing from the server) i tried swearing, nothing happened. Heres what i got:

    AtomicSwear.java:
    http://pastebin.com/n30mJKm3

    PlayerListener.java:
    http://pastebin.com/10bPaKWA

    plugin.yml:
    name: AtomicSwear
    main: com.chaoticunited.AtomicSwear
    version: 1.0
    permissions:
    atomicswear.notify:
    description: Notifys players with permission who was kicked for swearing.
    default: op


    Thanks!
    Atomicbeast101

    EDIT: Updated the codes.
     
  2. Offline

    chenr1

    I dont think your player chat event is correct. Gimme one sec and I'll pull up one of my old plugins.
     
  3. Offline

    Atomicbeast101

    chenr1
    Okay thanks and I think its with the new craftbukkit that changed something. Correct me if Im wrong.
     
  4. Offline

    chenr1

    Try
    Code:
    public void onChat(PlayerChatEvent event){
    
    Instead of

    1. Code:
              public void PlayerChat(AsyncPlayerChatEvent chat)
      
    EDIT: Don't forget the {
     
  5. Offline

    Atomicbeast101

    chenr1 PlayerChatEvent was changed to AsyncPlayerChatEvent when 1.3 came out.

    EDIT: It did not work still.

    bump.

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

    hockeygoalie5

    It doesn't affect anything, but the convention is to start a method's name lowercase. On topic: Do not register your listener twice, remove line 20 of PlayerListener. Add a line to the playerChat method that prints to console to see if it gets called at all.
     
  7. Offline

    Atomicbeast101

    hockeygoalie5
    Okay i removed line 20 and added a server log in the chat event before the if message part. Nothing shows up. Any idea whats wrong with the AsyncPlayerChatEvent part?

    EDIT: Updated the codes.
     
  8. Offline

    fireblast709

    player.hasPermission(String) is not thread-safe
    player.sendMessage(String) is not thread-safe (afaik)
    player.kickPlayer(Player) is not thread-safe (afaik, as it calls events on the main thread)

    Why not use PlayerChatEvent
     
  9. Offline

    68x

    PlayerChatEvent is deprecated and it locks up the main server thread.
    In the end, AsyncPlayerChatEvent accomplishes the same thing.
     
    Atomicbeast101 likes this.
  10. Offline

    Atomicbeast101

    fireblast709
    So what do you suggest I should do?

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

    fireblast709

    Using the PlayerChatEvent is not as worse as violating thread-safety. This is what was adviced by Wolvereness on another thread. If you do not know how to handle thread safety, and need methods that are not thread-safe, use PlayerChatEvent

    Atomicbeast101 not sure, but use PlayerChatEvent for now
     
  12. Offline

    Atomicbeast101

    fireblast709
    Did not change anything. Its depreceted and I tried testing it, nothing still happened.
     
  13. Offline

    fireblast709

    @EventHandler above the public void onChat(PlayerChatEvent event)
     
  14. Offline

    Atomicbeast101

    fireblast709
    You sir are a life saver. Thank you soo much.
     
  15. Offline

    Atomicbeast101

    Okay I am now getting a problem with this plugin. (I changed the plugin name). It caused a server crash and all it showed is Read time out and kept spamming it. It happens on the last kick event from the NukeSwear. I cannot figure out what was going on. Heres the updated plugin.

    NukeSwear.java
    Code:
    package com.chaoticunited;
     
    import java.util.logging.Logger;
    import org.bukkit.plugin.java.JavaPlugin;
     
    //            NukeSwear
     
    public class NukeSwear extends JavaPlugin
    {
        public void onDisable()
        {
            Logger.getLogger("Minecraft").info("[NukeSwear] Successfully disabled!");
        }
        public void onEnable()
        {
            Logger.getLogger("Minecraft").info("[NukeSwear] Successfully enabled!");
            getServer().getPluginManager().registerEvents(new NukeSwearListener(), this);
        }
    }
    
    NukeSwearListener.java
    Code:
    package com.chaoticunited;
     
    import java.util.logging.Logger;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
     
    //            NukeSwear Listener Class
     
    public class NukeSwearListener implements Listener
    {
        @EventHandler
        public void onPlayerChat(AsyncPlayerChatEvent event)
        {
            Player p = event.getPlayer();
            String playername = p.getName();
            String message = event.getMessage();
            String messagetwo = message.toLowerCase();
            if(!event.getPlayer().hasPermission("nukeswear.canswear"))
            {
                if(messagetwo.contains("fuck") || messagetwo.contains("bitch") || messagetwo.contains("shit"))
                {
                    event.setCancelled(true);
                    p.kickPlayer("Do not swear. You have been warned.");
                    Logger.getLogger("Minecraft").info("[NukeSwear] Player " + playername + " was kicked for swearing.");
                    for(Player players: Bukkit.getServer().getOnlinePlayers())
                    {
                        if(players.hasPermission("nukeswear.notify"))
                        {
                            players.sendMessage(ChatColor.RED + "[" + ChatColor.AQUA + "NukeSwear" + ChatColor.RED + "]:" + ChatColor.YELLOW + " Player " + playername + " is kicked for swearing.");
                        }
                    }
                }
            }
        }
    }
    plugin.yml
    Code:
    name: NukeSwear
    main: com.chaoticunited.NukeSwear
    version: 1.0
    author: Atomicbeast101
    permissions:
      nukeswear.notify:
        description: Notifys players with permission who was kicked for swearing.
        default: op
      nukeswear.canswear:
        description: Has permission to swear.
        default: op
    bump

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

    fireblast709

    any stacktraces in the console?
     
  17. Offline

    Atomicbeast101

    Nope none at all. All it showed was read time out and it disconnected the players out of the server.
     
  18. Offline

    fireblast709

    Then my bet is that you are using non thread-safe methods in an async thread
     
  19. Offline

    Lau950

    In your plugin.yml, you forgot to put the main class.
    Code:
    main: com.chaoticunited.NukeSwear
    Must be:
    Code:
    main: com.chaoticunited.NukeSwear.NukeSwear
    Greatz,
    Lau950
     
  20. Offline

    Panjab

    His package doesn't contain a first 'NukeSwear'..
     
  21. Offline

    Atomicbeast101

    Lau950
    No lol its correct.
     
  22. Offline

    william9518

    didnt register events?
     
  23. Offline

    Atomicbeast101

    Its registered i believe. It does work but the problem is that it crashes the server with read time out words.
     
  24. Offline

    keelar

    I compiled your code and everything works fine. It's something other than your code.
     
  25. Offline

    Atomicbeast101

    keelar
    Mmm interesting. Do you think if for example anticaps and antiswear kicks player for using caps and swearing at once cause a read time out? because of two plugins kicking the player at once?
     
  26. Offline

    libraryaddict

    Just a suggestion.

    http://dev.bukkit.org/server-mods/simplecensor/

    Its a pretty good censoring plugin, And does caps as well.
    It can even correct grammer such as 'wont'!

    But the best feature I think it has is that it sends the non-censored version to the sender, Meaning they are not going to try bypass it as they see themselves offending everyone.

    'You can all suck on my twig!'
     
  27. Offline

    keelar

    I'm not sure. Try your plugin in a test server without any other plugins installed. If that fixes the problem then you will have to disable plugins one by one until it stops throwing an Exception to figure out what plugin is causing the problem.
     
  28. Offline

    Midnight Blue

    Here's an anti swear plugin that i made, it works fine.

    Code:
        @EventHandler
        public void onChat(AsyncPlayerChatEvent event) {
            Player player = event.getPlayer();
            String message = event.getMessage().toLowerCase();
              String[] curse = new String[] {"douche", "twat", "dick", "cock", "shit", "fuck", "cunt", "bitch", "whore", "nigger", "slut", "pussy"};
                for(String blacklist : curse){
              if (message.contains(blacklist)) {
              event.setCancelled(true);
                  player.chat(message.replaceAll(blacklist, ChatColor.RED + "****" + ChatColor.WHITE));
                  return;
              }
            }
          }
     
Thread Status:
Not open for further replies.

Share This Page