Censored words plugin

Discussion in 'Plugin Development' started by DubstepPrins, Nov 29, 2014.

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

    DubstepPrins

    Hello, I'm trying to create a plugin so if someone swears, the message get's cancelled and the player get's warned. The plugin's working fine except for that I don't know how to end the event. Everytime someone says "Hi!" or something like that he get's the warning too. Is there any way so I can end the event after the user swore?
    Code:java
    1. @EventHandler
    2. public void onPlayerChat(AsyncPlayerChatEvent e) {
    3. e.getMessage().contains("[CENSORED]");
    4. e.setCancelled(true);
    5. e.getPlayer().sendMessage(ChatColor.RED + "Watch your language!");

    Thanks.
     
  2. Offline

    timtower Moderator Moderator

  3. Offline

    DubstepPrins

    So after a player said a censored word, the plugin will end itself until the user says it again.
    With the code above I get warnings even if I type for example "How are you doing".
    And I want to add other words to the list too but then I get the "Watch your language" message 3 times.
     
    ChipDev likes this.
  4. Offline

    timtower Moderator Moderator

    ChipDev likes this.
  5. Offline

    DubstepPrins

    timtower
    Code:java
    1. @EventHandler
    2. public void onPlayerChat(AsyncPlayerChatEvent e) {
    3. if(e.getMessage().contains("[CENSORED WORD]"));
    4. e.setCancelled(true);
    5. e.getPlayer().sendMessage(ChatColor.RED + "Watch your language!");

    Using the if statement now but it still wont work...
     
  6. Offline

    timtower Moderator Moderator

    DubstepPrins You also need to put something in the result.
    if(condition){
    //Execute this stuff
    }
     
  7. Offline

    DubstepPrins

    timtower is it possible to write it down along my code? I don't really understand you. Sorry :)
     
  8. Offline

    timtower Moderator Moderator

    DubstepPrins
    Code:java
    1. @EventHandler
    2. public void onPlayerChat(AsyncPlayerChatEvent e) {
    3. if(e.getMessage().contains("[CENSORED WORD]")){ //These are important and basic java. Every if statement has them
    4. e.setCancelled(true);
    5. e.getPlayer().sendMessage(ChatColor.RED + "Watch your language!");
    6. }
     
  9. Offline

    DubstepPrins

    Thanks for your help! :)
     
  10. Offline

    ChipDev

    Use array list / hash maps for warnings (I would prefer Hashmaps for warnings Becuase you can have a int for how many warnings that the certain players has.)
    Also, learn java. it may help you in the future!

    Not ''May' it WILL help you not to be a noob in the future
     
  11. Offline

    DubstepPrins

    ChipDev Learning it at the moment, started about 2 weeks ago :p
     
    ChipDev likes this.
  12. Offline

    FisheyLP

    Dont try to make Bukkit Plugins when you don't event know the basics of Java!
     
    ChipDev and Skionz like this.
  13. Offline

    DubstepPrins

    FisheyLP Look at the post above yours, sir. :)
     
    ChipDev likes this.
  14. Offline

    FisheyLP

    i read it, but
     
    ChipDev likes this.
  15. Offline

    ChipDev

    I learned before knowing java :(
     
  16. Offline

    BrentHogeling

    ChipDev And yet you still don't know Java... as well as that timtower try to avoid spoon feeding, it won't help in the future...
     
  17. Offline

    leon3001

    Funneh. Showing him how to use parathenses isn't what I would call spoonfeeding.
     
  18. Offline

    BrentHogeling

    leon3001 He never fully explained what they were, for all you know he could go placing them at the end of every line...
     
  19. Offline

    timtower Moderator Moderator

    BrentHogeling If I was spoonfeeding then I would give him the entire plugin is source files.
     
    leon3001 and ChipDev like this.
  20. Offline

    indyetoile

    BrentHogeling
    "Spoon-feed: to provide so fully with information or the like that one is prevented from thinking or acting independently."
    Since he already had the base for his plugin, which was mostly correct, a simple correction is not called spoon-feeding.
     
    leon3001 likes this.
  21. Offline

    timtower Moderator Moderator

    Further conversation about spoonfeeding will be removed. Lets get back on topic again.
     
    ChipDev likes this.
Thread Status:
Not open for further replies.

Share This Page