Solved Custom Event cancellabele

Discussion in 'Plugin Development' started by ToastHelmi, Aug 14, 2013.

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

    ToastHelmi

    if i want to to something in a event that is cancellabele when its cancellabel how do i dont do that when i cancall the event
     
  2. Offline

    rsod

    If you want to completely skip code execution if event cancelled:
    Code:
    @EventHandler(ignoreCancelled = true)
        public void onEvent(Cancellable e){
           
        }
    If you want to execute another code when event cancelled:
    Code:
    @EventHandler
        public void onEvent(Cancellable e){
            if(e.isCancelled()){
                //do something
            }
        }
     
  3. Offline

    Syd

    You should really overhaul your headpost, it's very hard to understand.

    I'll just assume that you want to cancel your own custom event and you're not sure how to cancel the action the event is for.

    Code:
    CustomEvent event = new CustomEvent();
    Bukkit.getServer().getPluginManager().callEvent(event);
     
    if(event.isCancelled())
        return;
    else
        doEventCode()
    
    This would cancel the method, the event is called from, when some listener cancels the event.

    The same is for values you can set in your event. You first need to give the orginal value to the event via constructur and later retrive it from the event in order to use it.
     
  4. Offline

    ToastHelmi

    so i always need a listener and cant do something in the even?
     
  5. Offline

    rsod

    ToastHelmi you wrote 5 plugins and you can't exactly say what you need? Please explain us if you want to get help.
     
  6. Offline

    ToastHelmi

    englisch is not my favorire language ;)

    but i give it a try

    kind a like the PlayerMoveEvent
    where i can cancle the event and the player will not move
    and i can set the location to and the player will move to this location

    I have a valu stored as metadata in a player
    if i change that i call a event

    my questuion is is it posible that if a cancle the event that the metadata is reset to the old value
    and if its posible to change the metadata in the event itself (and reset it by cancle) (and woud it be teh common way to do sutch things)
     
  7. Offline

    rsod

    ToastHelmi you need to store metadata to external variable, then call event with this variable and if event wasn't cancelled, set metadata. Example (untested):
    Code:text
    1.  
    2. String newMetadata = "MetadataValueThatGoingToBeChanged";
    3. YourCancellableEvent event = new YourCancellableEvent(newMetadata, player);
    4. Bukkit.getPluginManager().callEvent( event );
    5. if( !event.isCancelled() ){
    6. player.setMetadata(...);
    7. }
    8.  
     
Thread Status:
Not open for further replies.

Share This Page