Disable bad words plugin not working!

Discussion in 'Plugin Development' started by jusjus112, Mar 11, 2014.

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

    jusjus112

    I need help with my plugin thats disables bad words. But the canceling for the bad words is not that hard. but im in an orther part stuck! i have this code:
    Code:java
    1. public class DisWords implements Listener {
    2.  
    3. private ScoreBoard plugin;
    4.  
    5. public DisWords(ScoreBoard instance) {
    6. this.plugin = instance;
    7. }
    8.  
    9. int kick = 0;
    10. final public ArrayList<Player> mute = new ArrayList<Player>();
    11.  
    12. @EventHandler
    13. public void onPlayerChat(final AsyncPlayerChatEvent e) {
    14. if (e.getMessage().contains("test")) {
    15. e.setCancelled(true);
    16. e.getPlayer().sendMessage(MsgType.NORMAL + "Swearing in such words is NOT allowed. We like to ask you to leave if you come for nonsense stuff like this!");
    17. this.kick += 1;
    18. }
    19.  
    20. if (this.kick == 2) {
    21. e.getPlayer().sendMessage(MsgType.NORMAL + "You really do not understand what we mean by NOT.");
    22. e.getPlayer().sendMessage(ChatColor.LIGHT_PURPLE + "Sorry but we have to really mute for one minute! i.v.m such childish words!");
    23. this.mute.add(e.getPlayer());
    24. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    25. @Override
    26. public void run() {
    27. mute.remove(e.getPlayer());
    28. }
    29. }, 60 * 20L);
    30. }
    31.  
    32. if (this.kick == 3) {
    33. e.getPlayer().kickPlayer(MsgType.NORMAL + "KICKED, we give your karma!");
    34. this.kick = 0;
    35. }
    36. }
    37.  
    38. @EventHandler
    39. public void onPlayerMute(AsyncPlayerChatEvent e) {
    40. if (this.mute.contains(e.getPlayer())) {
    41. e.setCancelled(true);
    42. }
    43. }
    44. }

    Everything works fine, but only one thing not! The not working thing, is when an player types test, it says the first message. but when they typed it again, it says the first message and the "if (this.kick == 2) {" message and it dont mute the player. when they typed it 3 times, it dont kick the player, but it says the first message. Can someone tell me what im doing wrong. I have registred my events and all the other stuff!
     
  2. Offline

    TopTobster5

    First of all, try putting some debug messages in to make sure all the variables are as they should be. Secondly, what is 'this.kick'?
     
  3. Offline

    jusjus112

    TopTobster5
    I have debug messages, see they as the text! And the kick is on line 9 "int kick = 0"
    I had an debug message in the runnable, but that worked, but he spams the first message!
     
  4. Offline

    TopTobster5

    jusjus112 Ok, I don't think you need to use 'this.' before every variable, if it has been declared in this class, you should be alright. What you need to do with he debug messages is find out what kick is every time someone does something. These shouldn't make it into the release of the plugin, but help you find out why things are not working rather than using the messages which a regular user will see as your debug messages. I for example would log how many times someone did something to the console, so you can tell what the count is when you wonder why it has not kicked someone. Finally, I think your issue is that when you mute someone for a minute, you never add one onto kick.
     
  5. Offline

    acecheesecr14

  6. Offline

    jusjus112

    acecheesecr14
    If you read this thread good, it is not an scoreboard! its just an disable bad words plugin :D
     
  7. Offline

    acecheesecr14

    jusjus112 I know, but i presumed that you were using scoreboards to log the number of attempts to swear...
    Only bacause the Scoreboard variable type is used and I don't see any declaration of the "kick" variable defined anywhere in this class... per player*
     
  8. Offline

    TopTobster5

    acecheesecr14
    jusjus112 Did you see my fix? If so, is that what was causing the problem?
     
  9. Offline

    acecheesecr14

    Thats not going to be per player, use a hashmap.

    That creates the hashmap var:
    Code:java
    1. private HashMap<String, int> kick = new HashMap<String, int>();
    2. //Use the player name instead of the actual player
    3.  


    this will add to the player's kick var, Im not sure about the kick.remove(name), be sure to check it
    Code:java
    1. if(kick.contains(e.getPlayer().getName())){
    2. if (kick.get(e.getPlayer().getName()) == 1 /*1 or 2 */){
    3. //send message.
    4. int oldInt = kick.get(e.getPlayer.getName());
    5. kick.put(e.getPlayer().getName(), oldInt++);
    6. }//Repeate this with differnt message's etc...
    7. }else{
    8. kick.put(e.getPlayer().getName(), 1);
    9. }
     
    TopTobster5 likes this.
  10. Offline

    TopTobster5

  11. Offline

    acecheesecr14

    That's why I thought he was using scoreboards.

    And on the 1st "BadWord" you need to add the playername (My bad. Slightly tired)!
    Code:
    kicks.put(e.getPlayer().getName(), 1);
    I edited my code above!
     
  12. Offline

    Borlea

    HashMaps are smart enough that when you try to put, and it has it already, it will replace. no need to remove
    all you would need to do is kick.put(e.getPlayer().getName(), kick.get(e.getPlayer().getName()));
     
  13. Offline

    acecheesecr14

    Thanks, I didn't know that!
     
Thread Status:
Not open for further replies.

Share This Page