Class CustomCrafterAPIPropertiesChangeEvent

  • All Implemented Interfaces:

    
    public final class CustomCrafterAPIPropertiesChangeEvent<T extends Object>
    extends Event
                        

    Called when CustomCrafterAPI changeable properties changed.

    Only changed. When an old value is same with new value, this won't be called this.

    (External plugins cannot initialize this instance.)

    // Example Code (Safe / Kotlin)
    object PropertiesChangeListener: Listener {
        @EventHandler
        fun <T> CustomCrafterAPIPropertiesChangeEvent<T>.onChange() {
            val baseKey = CustomCrafterAPIPropertiesChangeEvent.PropertyKey.BASE_BLOCK
            if (this.propertyName != baseKey.name) {
                return
            }
            val baseTypeOld: Material = this.oldValue.getOrNull(baseKey) ?: return
            CustomCrafterAPI.setBaseBlock(baseTypeOld)
            println("I rejected new setting... Hahaha!!!")
        }
    }
    // Example Code (Safe / Java)
    public class PropertiesChangeListener implements Listener {
        @EventHandler
        public void <T> onChange(CustomCrafterAPIPropertiesChangeEvent<T> event) {
            String baseKey = CustomCrafterAPIPropertiesChangeEvent.PropertyKey.BASE_BLOCK;
            if (!event.getPropertyName().equals(baseKey.getName())) {
                return;
            }
            Material baseTypeOld = event.getOldValue().getOrNull(baseKey);
            if (baseTypeOld == null) {
                return;
            }
            CustomCrafterAPI.setBaseBlock(baseTypeOld);
            System.out.println("I rejected new setting... Hahaha!!!");
        }
    }
    Since:

    5.0.11