Anti Swearing

Discussion in 'Plugin Development' started by Shadownd63, Dec 4, 2014.

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

    Shadownd63

    Hi everybody,

    I wanted to make an plugin, that if you swear 1 time, you will be warned.
    But if you swear a second time that you will be kicked.

    It kind of works, when you swear, you will recieve the message, but if you swear the second time, you will get the message again and you will not be kicked.

    Help!

    P.S. Gesencuurde woorden and Schelden is not english, i know. Its dutch

    Code:java
    1. ArrayList<Player> Schelden = new ArrayList<Player>();
    2. @EventHandler
    3. public void onPlayerChat(AsyncPlayerChatEvent e) {
    4. Player p = e.getPlayer();
    5. for (String word : e.getMessage().split(" ")) {
    6. if (plugin.getConfig().getStringList("Gesencuurde woorden")
    7. .contains(word)) {
    8. e.setCancelled(true);
    9. e.getPlayer().sendMessage(ChatColor.RED + "Dont swear!");
    10. Schelden.add(p);
    11. if(Schelden.contains(p) == true){
    12. p.kickPlayer("Dont swear!");
    13. }
     
  2. Offline

    mine-care

    Schelden.contains(p) == true
    can be:
    if(Schelden.contains(p))

    It is a good idea not to keep player objects in classes once they may cause ram leakage if not handled correctly

    Code:java
    1. for (String word : e.getMessage().split(" ")) {
    2. if (plugin.getConfig().getStringList("Gesencuurde woorden")
    3. .contains(word)) {
    4. e.setCancelled(true);
    5. e.getPlayer().sendMessage(ChatColor.RED + "Dont swear!");
    6. Schelden.add(p);
    7. if(Schelden.contains(p) == true){
    8. p.kickPlayer("Dont swear!");
    9. }

    here^ you loop through evey word, check if the confic contains the word, cancel the event, send the message and then put him in the arrray list and then check if the array list contains the player (it does all the time because you add him right before the if) and kick him.
     
  3. Offline

    Experminator

    Shadownd63 I did see you are dutch. But ontopic.
    If i may give a suggestion. Don't use spaces in configuration paths. And next, Listen to mine-care, he is right.
     
    mine-care likes this.
  4. Offline

    Kilovice

    Shadownd63 It also might be a good idea to add:
    Code:java
    1. Schelden.remove(p);

    Otherwise they will continue to get kicked everytime he chats :p
     
    Experminator likes this.
Thread Status:
Not open for further replies.

Share This Page