Solved [FactionsUUID] get Faction location?

Discussion in 'Spigot Plugin Development' started by zDoeProgram, Apr 22, 2017.

  1. Hello, I have never worked with Factions before, however I've been trying to look up the API and stuff and cant find anything to match this. Anyone know how to get a players faction and then get all the claimed land of that faction?
     
  2. What have you tried....
     
  3. By creating a HashMap and using HashMap#values or HashMap#keySet and checking if the faction is in there, It really depends on what you want to do.

    Although, if you are just storing the factions on their own and not looking up anything to get them, you my as well just use an ArrayList
     
  4. Ok, I think I did it in a smart way xP

    First I created a hashmap with the Key set to Location and Value set to Faction
    Code (Text):
    public static HashMap<Location, Faction> map = new HashMap<Location, Faction>();
    Then when the player does whatever, I put the player-faction-location and the players faction as value.
    Code (Text):
    FPlayer fPlayer = FPlayers.getInstance().getByPlayer(p);
                    map.put((Location) fPlayer.getFaction().getAllClaims(), fPlayer.getFaction());
    So for example on a block event thing, I then check if the location of the block(key) is inside the hashmap. and set it to cancelled.
    Code (Text):
    @EventHandler
        public void onExplode(EntityExplodeEvent e) {
           
            Location loc = e.getLocation();
           
            if(GUI.map.containsKey(loc)) {
                e.setCancelled(true);
            } else {
                e.setCancelled(false);
            }
           
        }
       
    Anything that wont work in this code?
     
  5. Stop abusing static.
     
    • Agree Agree x 1
  6. I used it now since I only wanted to see if it works, if it does I will change it and create an instance for the class instead. So this would work?
     
  7. Try it out...
     
  8. Would I use this for FactionsUUID like Factions?

    depend: [Factions]
     
  9. Depends on the plugin's name. Try it and see if it works or not.
     
  10. I cant use the faction commands when I add my own custom faction command. How can I add my faction command to work with this ?

    for example "/f features"
     
  11. what is the issue?
     
  12. I have my own command "f blockcancel" inside my plugin which depend Factions. However when I add it I cant use the default Faction commands. Do I need to register them a different way or does Faction have it own command system I can add my command too?
     
  13. Not sure if Faction has its own command.
     
  14. I managed to use PlayerCommandPreprocessEvent xP

    I tried the code however I get an error on this line inside my consol:
    Code (Text):
    map.put((Location) fPlayer.getFaction().getAllClaims(), fPlayer.getFaction());
    I guess its because I had to cast Location to get all the faction claims. You know what it is supposed to be?
     
  15. maldahleh

    Wiki Team

    You're right, you can't cast all claims to a location, I haven't looked at API but I would still imagine that it wouldn't be possible.

    What I think is probably your best choice, I haven't looked at API, but I assume it's possible, is to store a list of Factions which have the perk in a set then on any event get the location, check if a faction is associated with that location using the API, if so check if the Faction is in the set and cancel the event.
     
  16. So you recommend me to change my HashMap to a Set instead? and only have the value as Faction?
     
  17. maldahleh

    Wiki Team

    I haven't looked at API, but yes I think what you should do is store all Factions with the perk in the set, on event get the location, use the API to check the Faction at the location and check if it's in the set, then cancel the event.
     
  18. Ok, right so now my issue is:

    inside my block event. I need to check if the block location is inside one of the factions claims that are inside the HashSet xP