[SOLVED] No MSG to players with capital letters

Discussion in 'Plugin Development' started by recon88, Feb 20, 2012.

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

    recon88

    Someone knows what's wrong with it?
    It checks who owns the chunk. After that it sends a MSG to the player who entered the chunk.
    The Problem is: Players with a capital letter at the beginning (like Recon) don't receive the message.. All other Players (like recon) are receiving it.
    There are a bunch of other messages.. Like "Chunk owned by XX. You can't mine here" (if i destroy sth in others chunks).
    Messages like that are working. Just the onMove Message will not work :/


    If you need more of the code just let me know.

    HTML:
    public void onPlayerMove (PlayerMoveEvent event) {
            Player player = event.getPlayer();
            if (RegionHandler.Messages.contains(player.getName())){
                Chunk acc_chunk = event.getPlayer().getLocation().getBlock().getChunk();
                String owner = plugin.RegionHandler.ClaimCheck(acc_chunk);
                if (OwnerNameChunk.get(player.getName()) == null) OwnerNameChunk.put(player.getName(), "");
                if(owner==""){
                    String temp = OwnerNameChunk.get(player.getName());
                    if (temp == null || temp == ""){
                        OwnerNameChunk.put(player.getName(), "");
                    }else{
                        player.sendMessage(ChatColor.RED + "No owned Chunk.");
                    }
                   
                }else{
                    if (owner.equalsIgnoreCase(OwnerNameChunk.get(player.getName())) == false){
                        player.sendMessage(ChatColor.RED + "Chunk owned by " + owner + ".");
                    }
                   
                }
                OwnerNameChunk.put(player.getName(), owner);
            }
        }
     
  2. Offline

    theguynextdoor

    String owner = plugin.RegionHandler.ClaimCheck(acc_chunk);
    if(owner==""){
    When dealing with strings, use
    .equals or .equalsIgnoreCase("")


     
  3. Offline

    recon88

    But the owner String is just for checking who ownes the chunk.
    Why it will be preventing the player.sendMessage from messaging a player with a capital letter?
    I don't get it sorry :/ And i can't figure out how to fix it

    Nobody?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
  4. Offline

    dillyg10

    Could you give us an example of what happens? Your code does appear to look good :)
     
  5. Offline

    bassfader

    I think it could be this line of code:
    Code:
    if (RegionHandler.Messages.contains(player.getName())){
    It will check the player name case sensitive, and if you are storing the players names in the List / Map "Messages" as lowercase, it won't find them by comparing like that.

    You could just change it to player.getName().toLowerCase() but that wouldn't be the way to go I guess. I think most effective would be to either:

    a.) (Probably the easiest solution:)) Store the player names in the RegionHandler.Messages List / Map not only as lower case but including all capitals

    or b.) Create a function that iterates through a list and checks not case sensitive. Looking something like this:
    Code:
    public boolean listContainsIgnoreCase(List<String> list, String txt) {
        for (String s : list) {
            if (s.equalsIgnoreCase(txt)) return true;
        }   
        return false;
    }
     
  6. Offline

    recon88

    I just added this before i read your message here... I wasted 2 more hours instead of reading your stuff here :/
    And yes, that fixed the problem finally... I should not work with java in the night

    Thanks guys
     
Thread Status:
Not open for further replies.

Share This Page