PEX moniter group change

Discussion in 'Plugin Development' started by hammale, Jan 6, 2012.

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

    hammale

    Hullo to all. I need to create a plugin that does somthing when a user changes groups in PEX. I've thought long and hard and I cant seem to think of a really pretty answer. What I think I might have to do is set up listeners for all pex related group change commands (i think just /pex group * and /pex reload to catch user's who manually edited the file) along with something onEnable that would catch a full reload. Is there any prettier way of doing this? Thanks in advance :D
     
  2. Offline

    wwsean08

    yah your best bet is to do a onCommandPreProccess event, the only possible problem i can see is that it might not work right if the command to change the group is typed wrong (like a wrong letter for the group)
     
  3. Offline

    hammale

    yeah i think i'm going to have to do something like that...thanks anyway :D
     
  4. Offline

    knightidus

    Well there is another thing you could do...

    If you went into the PEX java files and threw a custom event, with all of the necessary info then you could monitor it that way! But the only problem would be is that you have to change it every update, but its better than nothing!
     
  5. Or maybe a repeated scheduler which logs all groups and member to hashmap and then checks for changes in case they modify the file manually and then do a reload?
     
  6. Offline

    hammale

    Good idea! I've never used custom events, can someone show me an example?

    Yeah that would work but it would be a bit heavy in lag...good idea though

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

    knightidus

    I found a thread a while ago showing you how to do it, but sadly i cant find it sry :( but im sure with a bit of searching on google you could find an example!
     
  8. Offline

    hatstand

    This thread should be what you're after.
     
    hammale likes this.
  9. Offline

    hammale

  10. Yes it would but it all depends on how fast you need the updates to be.
     
  11. Offline

    hammale

    yeah but i think im going to try my hand at a custom event, thx anywayz :D
     
  12. Ok best of luck :)
     
  13. Offline

    hammale

    my god theres already one built into PEX :D took a bit to figure out but i got it working now :D :D :D if anyone cares to know how heres my custom listener class:

    Code:
    package me.hammale.PermsPay;
    
    import org.bukkit.event.CustomEventListener;
    import org.bukkit.event.Event;
    import org.bukkit.event.Listener;
    
    import ru.tehkode.permissions.events.PermissionEntityEvent;
    import ru.tehkode.permissions.events.PermissionEntityEvent.Action;
    
    
    public class GroupListener extends CustomEventListener implements Listener {
    /**
      * This is called when your custom event is triggered.
      *
      * @param event Event data
      */
        public void onPermissionEntityEvent(PermissionEntityEvent event) {
        }
    
    /**
      * This is required for your events to be triggered correctly.
      *
      * @param event Event data
      */
        @Override
        public void onCustomEvent(Event event) {
        if(event instanceof PermissionEntityEvent){
            onPermissionEntityEvent((PermissionEntityEvent) event);
            if(((PermissionEntityEvent) event).getAction() == Action.RANK_CHANGED){
                System.out.println("GROUP CHANGED!");
            }
        }
    // you can continue this with else if's as long as you like (if you have many events)
    }
    }
    
    and i have this in my on enable but im not sure if I need it... yup it needed :p
    Code:
     private final GroupListener glistener = new GroupListener();
    
    pm.registerEvent(Event.Type.CUSTOM_EVENT, glistener, Priority.Normal, this);
    
     
Thread Status:
Not open for further replies.

Share This Page