Problem/Bug Anyone Help Me With Reading From List

Discussion in 'General Help' started by Tomw787, Aug 12, 2015.

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

    Tomw787

    Hi, I have the code below and it always underlines it with the red line when plugins has a capital "P" and when it's lowercase it just underlines the "plugins" word. I'm just wondering if anyone could help me, All it needs to do is read a list called "Blocked-Words"?

    Code:

    Code:
    if (message.contains(plugin.getConfig().getList("Blocked-Words"))) {
                event.setCancelled(true);
                player.sendMessage(ChatColor.RED + "You May Not Use That Language!");
            }
     
  2. Online

    timtower Moderator Moderator

    @Tomw787 You need to loop through the strings in the list.
     
  3. Offline

    Tomw787

    Okay
    @timtower
     
  4. Online

    timtower Moderator Moderator

    @Tomw787 I won't give an example of a for loop as it is basic java.
     
  5. Offline

    Tomw787

    And For A moderator I expected you to be more helpful...
     
  6. Online

    timtower Moderator Moderator

    I was spoonfeeding for a while, then people came back every time that they needed something, I was pretty much writing their plugins.
    I don't want to do that now.
    You need to loop through the values of the list and see if that value is in the message. That is all that I am gonna give you.
     
  7. Offline

    Tomw787

    Okay, I get it if your seeing my name frequently but for a matter of fact this is my first time in posting on here for help, most the stuff I need is online.
     
  8. Online

    timtower Moderator Moderator

  9. Offline

    Tomw787

    Thanks For Links
     
  10. Offline

    Boomer

    Doesn't really address his "underlined plugin" issue though, which indicates another problem still even if he puts his loop in place. with a capital P it does one thing, with a small p another thing in terms of underlining.

    Any IDE that is underlining an entry, esp in red, will also be able to provide an error /explanation of it when you hover over it, or look at the line marker error symbol. It will indicate that the VARIABLE "plugin" can not be found, perhaps, or needs to be made static, perhaps, or is not initialized perhaps... The IDE is there to help.
     
  11. Offline

    Tomw787

    Here is what it's saying, thanks for your help @Boomer Capture.JPG
     
  12. Offline

    Boomer

    it means you dont have a local variable called "plugin" that is in scope where you are trying to access it
     
  13. Offline

    Tomw787

    So, How Would I fix this? Can you please Explain in detail? @Boomer
     
  14. Offline

    oceantheskatr

    If the code you pasted is from the main class, you should be able to remove the "plugin.".

    Right @Boomer?
     
  15. Offline

    Boomer

    or he is using it in a different class, but hasn't defined plugin in it, etc. A two lines of code does not give enough of an idea about his plugin infrastructure and context for the code..

    A lot comes down to "Why did you type plugin in the first place?" Were you using other example code to follow, do you have plugin somewhere in your code already, etc
     
  16. Offline

    Tomw787

    @oceantheskatr No, sadly it is not from the main glass. :(

    And here is the whole class:


    Code:
    package com.tomw787.tutorial.event.player;
    
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.*;
    import org.bukkit.plugin.messaging.*;
    
    
    public class PlayerChat implements Listener {
    
        @EventHandler
        public void onPlayerChat(AsyncPlayerChatEvent event) {
            Player player = event.getPlayer();
            String message = event.getMessage().toLowerCase();
          
          
        
            if (message.contains(plugin.Config().getList("Blocked-Words"))) {
                event.setCancelled(true);
                player.sendMessage(ChatColor.RED + "You May Not Use That Language!");
            }
        }
    }
    
     
  17. Online

    timtower Moderator Moderator

    @Tomw787 You need a constructor to pass a reference of the main plugin instance.
     
    oceantheskatr likes this.
  18. Offline

    Tomw787

    Sorry, Please Explain?
     
  19. Online

    timtower Moderator Moderator

Thread Status:
Not open for further replies.

Share This Page