Factions API - New question [See first post]

Discussion in 'Plugin Development' started by bennie3211, May 9, 2016.

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

    bennie3211

    Hello guys,

    I was looking through the events from Factions and I couldn't find a event that get called when a faction toggles peaceful mode. Anyone an idea if there is one? The events I found are https://github.com/MassiveCraft/Factions/tree/master/src/com/massivecraft/factions/event.

    Thnx


    EDIT:

    I don't want to create a new thread because the question is asked in this one, so I just bump this thread. I'm trying to log data when a faction is created. To do this I used the Factions API with the vent EventFactionsCreate but this doesn't work correctly. If an user types /f create <name> the event works correctly when the name is too short or too long, but when the economy part of the plugin should cancel the event it doesn't. When a factions costs 100$ and the user has 90$, the factions will not be created but the event still gets called, so I register factions create events that should not happen.

    I contacted the Factions devs and they told me by mail the following thing:
    But I tried all type of EventPriority in the eventhandler but none of them helped. Anyone that can help me with this? I had some help before in this thread but that's not the way it should be done and they don't work properly.
     
    Last edited: Jun 7, 2016
  2. Offline

    DoggyCode™

  3. Offline

    bennie3211

    That's a solution, I will try that. But I got one more problem right now. I'm listening to the event "EventFactionsCreate" but it gets fired if a player uses "/f create <name>" even when the player has no money to make one, I can't check if the event is cancelled so any idea how to do solve it?
     
  4. Offline

    DoggyCode™

    That's how it is with events; they're thrown before a execution happens often. If the event implements Cancelable then you could possibly check if the users money is above a set amount, and if it isn't, return or cancel.

    Sent from my SM-N9005 using Tapatalk
     
  5. Offline

    bennie3211

    The event doesn't have implemented Cancelable :L And the money is always different because it can be set in the plugin configurations. Any idea how to without having to edit Factions?
     
  6. Offline

    DoggyCode™

    public void onCreate (FactionCreateEvent e) {
    Player p = event.getPlayer();
    long bal = //do some vault stuff the get the money of the player;
    if (bal < whateveritcoststocreatefaction) {
    return;
    } else {
    //faction was probably created successfully
    }

    Sent from my SM-N9005 using Tapatalk
     
  7. Offline

    bennie3211

    Sorry to bumb an old thread, but I can't get it to work. I'm trying to log the create of an faction but it fails when it should be cancelled when the player has no money to make it. I thought it was a bug so I contacted the faction developers and they told me this:
    But I can't get it to work correctly, every time I listen to the EventFactionsCreate event it fires every time a player tries to make a faction when he doesn't have the money for it. Can someone tell me how I implement that?
     
  8. Offline

    DoggyCode™

    If you read my response there's a bad solution. But there's probs a better one.
     
  9. Offline

    Zombie_Striker

    @DoggyCode™
    This will do nothing then. If you want to prevent the player from creating the faction, you have to cancel the event/ write code preventing the faction from being created. What the return does is just stops your one method from being read.
     
    DoggyCode™ likes this.
  10. Offline

    bennie3211

    Bump [see first post for more information]
     
  11. Offline

    Betagear

    @bennie3211 Use EventPriority at medium, low or lowest. The higher the priority is, the first it gets called. If you register if after, then it's good because it has been processed by the other plugins.
     
  12. Offline

    bennie3211

    I tried all EventPriority types, none of them gaved the correct result
     
  13. Offline

    bennie3211

    Bump. Is there someone an expert with the factions API? :) I need this to register the creation with the EventFactionsCreate from the API.
     
  14. Offline

    bennie3211

    Anyone please? Bump. The dev from Factions told me to compensate with the EventPriority but that didn't change anything.
     
  15. Offline

    Zombie_Striker

    @bennie3211
    Can you post your current code? Priority "LOWEST" means that the event should be called first before any other event, so this should be the one you should use.
     
  16. Offline

    bennie3211

    Sure, it's not much xD I didn't wrote anything because the events gets fired all the time.
    Code:
    @EventHandler(priority = EventPriority.LOWEST)
        public void onFactionCreate(EventFactionsCreate e) {
            System.out.println("CREATED!");
        }
    In the console it will print "CREATED" even when the factions plugin tells the player "You can't afford $xxx to create a new faction."
     
  17. Online

    timtower Administrator Administrator Moderator

  18. Offline

    Zombie_Striker

    @bennie3211
    Could it be that the event is called before the player balance is checked? You may have to check the amount of money the player has yourself.
     
  19. Offline

    bennie3211

    The event doesn't support that, I can't do e.isCancelled() in the create event.


    @DoggyCode™ told me that too, but the needed money is set in the factions plugin folder and I don't want it that users needs to configure 2 configs. Besides that I don't understand why it fires the event when the plugin itself cancels it :(
     
  20. Offline

    bennie3211

  21. Offline

    Zombie_Striker

    @bennie3211
    You don't have to create a new config. Just access Faction's config and grab the value from there.
     
    bennie3211 likes this.
  22. Offline

    bennie3211

    #facepalm I didn't even think about that, but I'm not sure if this is the solution the dev from the factions told me when he said 'compensate for the EventPriority.HIGH' :l But I will try that when I have time.
     
Thread Status:
Not open for further replies.

Share This Page