Worldguard if in region problem

Discussion in 'Plugin Development' started by fishtime9, Mar 17, 2013.

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

    fishtime9

    i have a small issue here in my code some how, everytime i walk in the protected region ("backpack") and type in /getbackpack it returns with "you are not at the backpack-point!"

    i hope that somebody can find that mistake in the code:

    code:

    defining backpack , backpackloc:
    Code:
    int backpack;
    int backpackloc;
    isinregion check:
    Code:
    protected boolean isInRegion(Location loc, String region)
        {
            if (getWorldGuard() != null)
            {
                Vector v = new Vector(loc.getX(), loc.getBlockY(), loc.getZ());
       
                return getWorldGuard().getRegionManager(loc.getWorld()).getApplicableRegionsIDs(v).contains(region);
           
            }
            if(region.contains("backpack")){
                backpackloc = 1;
                return true;
            } else {
                backpackloc = 0;
            }
            return false;
        }
    and the command:
    Code:
    else if(commandlabel.equalsIgnoreCase("getbackpack")){
                       
                        if(backpackloc == 1){
                            backpack = 1;
                            player.sendMessage(ChatColor.GREEN + "You have now an backpack!");
                            return true;
                        } else {
                            backpack = 0;
                            player.sendMessage(ChatColor.RED + "You are not at the Backpack-point!");
                            return false;
                        }
                            }

    Fishtime9 :D

    help ? ? ??

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

    Murderscene

    First of all once you call "return" no more code in that method will be run. So it is never even reaching the second part of the code if getWorldGuard() is not null

    Also, region.getId() should be used to check the name of the region not contains() i believe.
     
  3. Offline

    fishtime9

    well it didnt help , i changed the return of the code to true (only 1x return1)
     
Thread Status:
Not open for further replies.

Share This Page