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?
Took me couple seconds... https://github.com/Techcable/Factio...n/java/com/massivecraft/factions/FPlayer.java
How would i be able to store a faction into a HashMap? Im trying to add perks so if your faction is inside a hashmap then people cant get damaged on their land.
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
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?
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?
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"
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?
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?
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.
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.
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