Solved Land Claiming logic

Discussion in 'Plugin Development' started by Irantwomiles, Mar 12, 2017.

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

    Irantwomiles

    So going straight to the point, I've created this land claiming plugin and It works just fine but I don't want to allow people to claim over each other. I've got some of it but I think I'm overthinking it. Here is what I thought. Since I already have a box of some sort I could probably check each location inside the box to see if the other persons claim has the same location or not, but I don't think thats a good way of going about. Any ideas?
     
  2. Offline

    Caderape2

    @Irantwomiles

    You can create an unique identifier for a claim and add it to an arraylist.
    String uniqueID = location.getWorld().getName()+" "+location.getChunk().getX()+" "+location.getChunk().getZ();

    Get a look of how you can do it.
    Code:
    public class ClaimManager
    {
        private List<Claim> claims = new ArrayList<>();
    
        public boolean isChunkClaimed(Location loc)
        {
            Claim c = new Claim(loc);
        
            for (Claim claim : this.claims)
           {
                if (claim.isEqual(c))
                {
                     return true;
                }
            }
            return false;
        }
    
    
    
        private class Claim
        {
        
            private String uniqueID;
        
        
            private Claim(Location loc)
           {
                this.uniqueID = loc.getWorld().getName()+" " + loc.getChunk().getX()+" "+loc.getChunk().getZ();
            }
        
            private boolean isEqual(Claim c)
            {
                 return c.getUniqueID().equals(uniqueID);
            }
        }
    }
    
     
    Last edited: Mar 13, 2017
  3. Offline

    Irantwomiles

    It's not done by chunks so this will not work, I'm using two locations to create a rectangle/square.
     
  4. Offline

    Caderape2

    @Irantwomiles This is almost the same. Create a class with a variable minimum point and maximum, and store taht class in an arraylist. You just have to do a method in this class for check if the location is in.
     
  5. Offline

    Irantwomiles

    For anyone that is wondering the same thing in the future. I looped through all of the locations in the two selected areans and checked if any preexisting claims existed there.
     
Thread Status:
Not open for further replies.

Share This Page