Need help with my plugin.

Discussion in 'Plugin Development' started by Straiker123, Dec 11, 2018.

Thread Status:
Not open for further replies.
  1. Hello i have little problem, i creating plugin but plugin not work fine..
    I have this in my Custom Config:
    Player: Straiker123
    VulgarWords: 21
    if i say to chat vulgar word it add to vulgarWord +1 but on first use it add + 1 and after next use it adds 1 * 2 and after next use it adds 2* 2 .. I need help :(

    here is my short version of the code (event part only):

    Code:
    @EventHandler
        public void onPlayerChat(AsyncPlayerChatEvent event) {
            int VulgarWords = this.getConfig().getInt("VulgarWords");
            int VulgarWordsPlayer = this.Players.getInt("VulgarWordsPlayer");
            int Spam = this.getConfig().getInt("Spam");
        Player p = event.getPlayer();
        String message = event.getMessage().toLowerCase();
      
        if (p.hasPermission("ChatSecurity.Admin")) {
          
            if(message.contains("Idiot")) {
              
            Players.set("Player", p.getName());
            this.Players.set("VulgarWordsPlayer", VulgarWordsPlayer + 1);
            savePlayers();
                }
                    if(message.contains("Stupid")) {
                        Players.set("Player", p.getName());
                        this.Players.set("VulgarWordsPlayer", VulgarWordsPlayer + 1);
                        savePlayers();
                      
                    }
    ....
     
    Last edited: Dec 11, 2018
  2. Offline

    timtower Administrator Administrator Moderator

    @Straiker123 1. Make a list of bad words instead of 2000 if statements that do the same thing.
    2. What does savePlayers do?
     
  3. it save config
     
  4. Offline

    timtower Administrator Administrator Moderator

    Please post the code.
     
  5. Offline

    timtower Administrator Administrator Moderator

    @Straiker123
    Code:
                Bukkit.getServer().broadcastMessage("");
                Bukkit.getServer().broadcastMessage("");
                Bukkit.getServer().broadcastMessage("");
                Bukkit.getServer().broadcastMessage("");
                Bukkit.getServer().broadcastMessage("");
                Bukkit.getServer().broadcastMessage("");
                Bukkit.getServer().broadcastMessage("");
                Bukkit.getServer().broadcastMessage("");
                Bukkit.getServer().broadcastMessage("");
                Bukkit.getServer().broadcastMessage("");
                Bukkit.getServer().broadcastMessage("");
                Bukkit.getServer().broadcastMessage("");
                Bukkit.getServer().broadcastMessage("");
                Bukkit.getServer().broadcastMessage("");
    Please, use a loop here.
    For all the bad words: make a list in the config, loop over the list, check if the message contains it.
    Will decrease the length of your code by ~1750 lines.
     
    TheEnderCrafter9 likes this.
  6. emm how do i put it into config? :/
     
  7. Offline

    timtower Administrator Administrator Moderator

    getStringList
     
  8. Players.getStringList("VulgarWordsList"); this is code ?
    and in config VulgarWordsList:
    - Stupid ...
     
  9. Offline

    timtower Administrator Administrator Moderator

  10. Yeey
    I test it

    It works ! Thanks and now test if work this code:
    this.Players.set("VulgarWordsPlayer", VulgarWordsPlayer + 1);

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.

    Ok i need help :(
    And Code have same problems :(

    Code:
       @EventHandler
        public void onPlayerChat(AsyncPlayerChatEvent event) {
            int VulgarWordsPlayer = this.Players.getInt("VulgarWordsPlayer");
            int VulgarWords = this.getConfig().getInt("VulgarWords");
            int Spam = this.getConfig().getInt("Spam");
        Player p = event.getPlayer();
      
        if (p.hasPermission("ChatSecurity.Admin")) {
            Players.getStringList("VulgarWordsList");
        }
            Players.getStringList("SpamList");
      
               if(!(p.hasPermission("ChatSecurity.Admin"))) {
                   Players.getStringList("VulgarWordsList");
                event.setCancelled(true);
                Players.set("Player", p.getName());
                this.Players.set("VulgarWordsPlayer", VulgarWordsPlayer + 1);
                savePlayers();
                this.getConfig().set("VulgarWords", VulgarWords + 1);
                saveConfig();
                Bukkit.getServer().broadcastMessage(Colors.chat(getConfig().getString("Prefix")+ChatColor.YELLOW+" >>> " +ChatColor.RED+p.getDisplayName() +  " "+Colors.chat(getConfig().getString("triedscoff"))));
            }
               if(!(p.hasPermission("ChatSecurity.Admin"))) {
                   Players.getStringList("VulgarWordsList");
               Players.getStringList("SpamList");
                event.setCancelled(true);
                this.getConfig().set("Spam", Spam + 1);
                saveConfig();
               Bukkit.getServer().broadcastMessage(Colors.chat(getConfig().getString("Prefix")+ChatColor.YELLOW+" >>> " +ChatColor.RED+p.getDisplayName() +  " "+Colors.chat(getConfig().getString("triedspam"))));
    }
        }
    
    }
     
    Last edited by a moderator: Dec 11, 2018
  11. Offline

    KarimAKL

  12. if the player writes a word that is in the config eg Shit .. it stops the event and sends to the chat that the player was trying to write a bad word .. but only once and not 10x to one word and which is not yet in the list eg letter W
     
  13. Offline

    KarimAKL

    @Straiker123 Well if you only wrote the message once but it sends it multiple times i would guess it's in a loop, try moving the message outside of the loop.
     
  14. And how do I do that? : /

    otherwise for info. when I put / reload I write a letter so it will write 1x Spam message and Vulgate message but when I write it again (another letter or word) so it does the same but 2 * so much

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Dec 11, 2018
  15. Offline

    KarimAKL

    @Straiker123 Do you mean that when you write a message it counts as spam and warns you with 1 message, then if you "spam" again it sends 2 messages, and then 3 etc?
     
  16. Yes, but the message is not even on that list.

    you can just go look .. i will give you server ip but not still :/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
  17. Offline

    KarimAKL

  18. Offline

    timtower Administrator Administrator Moderator

    @Straiker123 You are never checking if anything is in the list.
     
  19. Emm what do I do?
     
Thread Status:
Not open for further replies.

Share This Page