Help :)

Discussion in 'Plugin Development' started by Skify, Sep 8, 2015.

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

    Skify

    I tried many ways to make it so capitalization does not matter, equalsIgnoreCase. Help?

    Code:java
    1.  
    2. Stringmessage = event.getMessage().toLowerCase().replaceAll("pussy", "#@%&")
    3.  
    4. .replaceAll("slut", "#@%&").replaceAll("horny", "#@%&")
    5.  
    6. .replaceAll("whore", "#@%&").replaceAll("nigga", "#@%&")
    7.  
    8. .replaceAll("fag", "#@%&").replaceAll("cum", "#@%&")
    9.  
    10. .replaceAll("porn", "#@%&").replaceAll("nigger", "#@%&")
    11.  
    12. .replaceAll("bitch", "#@%&").replaceAll("fuck", "#@%&")
    13.  
    14. .replaceAll("dick", "#@%&").replaceAll("faggot", "#@%&")
    15.  
    16. .replaceAll("ez", "#@%&").replaceAll("skrub", "#@%&")
    17.  
    18. .replaceAll("gg10", "#@%&").replaceAll("rekt", "#@%&")
    19.  
    20. .replaceAll("gg 10", "#@%&").replaceAll("noob", "#@%&")
    21.  
    22. .replaceAll("e z", "#@%&").replaceAll("n00b", "#@%&")
    23.  
    24. .replaceAll("3z", "#@%&").replaceAll("fuk", "#@%&")
    25.  
    26. .replaceAll("fck", "#@%&").replaceAll("shit", "#@%&");
    27.  
    28. event.setMessage(message);
    29.  


    I don't know why this isn't working, no errors. Just the healing the killer part.

    Code:java
    1.  
    2.  
    3. finalPlayerkiller = e.getEntity().getKiller();
    4.  
    5. if (killer.getWorld().equals("FFA")) {
    6.  
    7. finalPlayerInventoryinv = killer.getInventory();
    8.  
    9. inv.addItem(new ItemStack(Material.ARROW, 5));
    10.  
    11. if (!inv.contains(Material.FLINT_AND_STEEL)) {
    12.  
    13. inv.addItem(newItemStack(Material.FLINT_AND_STEEL));
    14.  
    15. Bukkit.getServer().getScheduler()
    16.  
    17. .scheduleSyncDelayedTask(this, newRunnable() {
    18.  
    19. public void run() {
    20.  
    21. killer.setHealth(20D);
    22.  
    23. }
    24.  
    25. }, (20));
     
  2. @Skify Try adding some debug messages to see if the event fires
    Also, you say killer.getWorld().equals, use killer.getWorld().getName()
     
  3. Worst antiswear plugin I've EVER seen :p Good practice though, if you get it right.
     
  4. Offline

    Skify

    @DoggyCode™
    I started bukkit coding last week, no java knowledge, don't judge, at least help if your complaining.
     
  5. Online

    timtower Ninja on the waves Moderator

    @Skify 1. Try getting into java some more, you can learn some nice tricks.
    2. Regex, it has something about capitalization.
    3. Lists, make a list of bad words, then use a loop to check for them using regex
     
    Zombie_Striker and Ruptur like this.
  6. Correct me if I'm wrong, but doesn't replaceAll() work with regex?
     
  7. Online

    timtower Ninja on the waves Moderator

    It does, but if you just input a regular string then you aren't really using the regex part of it.
     
  8. Offline

    Ruptur

    @Skify
    Just to learn java before bukkit, its like trying to fly before learning to crawl

    For the anti swear part what you are doing is wrong dont do that.
    I recommend using an external file to store all words you want to replace.
    A simple way would be
    1. Store all words you want to replace into a iterable collection (either a list, set etc)
    2. Iterate through all the banned words and check if the string has a banned word
    3. If it does then replace all of the banned word in the string with the what you want it to be eg '#@%&"'
    However this is one solution that doesnt not replace banned phrases only individual words.
    Im is easiest to understand if you only just started to learn java
     
  9. Offline

    DuaneTheDev_

    @Skify

    A simple way of handling anti-curse without using a configuration file is through a string object.

    Create the string object and name it. Give it some values, in this case it'll be a list of bad words.
    Code:
    public String[] badwords = { "ass", "bitch", "cunt", "dick", "fucker", "fuck" };
    Now since you're checking for a curse word. You'll create a AsyncPlayerChatEvent.

    Code:
    @EventHandler
          public void onChat(AsyncPlayerChatEvent e) {
    }
    Inside this event it'll be easier to assign the message to a string.
    Code:
    String msg = e.getMessage();
    After that, you'll use a for loop. A for loop is used to iterate over a range of values.
    Code:
    for(String bw : badwords) {
    }
    Inside this for loop, you're going to check if the message contains a badword. The for loop is used to loop through the message and check if it contains a badword you listed in your string object.
    Code:
    if(msg.contains(bw)) {
    }
    Now if your message contains a badword. You're gonna wanna replace all badwords(old character) with a new character. So inside the if statement, you'll put.
    Code:
    msg = msg.replaceAll(bw, "***");
    Now in-order for this to work, you must set the message with your replacements.
    Code:
    e.setMessage(msg);
    Now if I type "bitch" it'll be replaced with ***. Also you don't need to enter "asshole" or "motherfucker" because it'll be replaced with ***. Ex: ***hole, mother***.
     
    Last edited: Sep 9, 2015
Thread Status:
Not open for further replies.

Share This Page