Custom Crafter APIProperties Change Event
class CustomCrafterAPIPropertiesChangeEvent<T>(val propertyName: String, val oldValue: CustomCrafterAPIPropertiesChangeEvent.Property<T>, val newValue: CustomCrafterAPIPropertiesChangeEvent.Property<T>, isAsync: Boolean = false) : 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!!!")
}
}Content copied to clipboard
// Example Code (Safe / Java)
public class PropertiesChangeListener implements Listener {
@EventHandler
public void <T> onChange(CustomCrafterAPIPropertiesChangeEvent<T> event) {
String baseKey = CustomCrafterAPIPropertiesChangeEvent.PropertyKey.Companion.BASE_BLOCK;
if (!event.getPropertyName().equals(baseKey.getName())) {
return;
}
Material baseTypeOld = event.getOldValue().getOrNull(baseKey);
if (baseTypeOld == null) {
return;
}
CustomCrafterAPI.INSTANCE.setBaseBlock(baseTypeOld);
System.out.println("I rejected new setting... Hahaha!!!");
}
}Content copied to clipboard
Since
5.0.11
Parameters
property Name
Name of property
old Value
An old value
new Value
A new value
Constructors
Link copied to clipboard
constructor(propertyName: String, oldValue: CustomCrafterAPIPropertiesChangeEvent.Property<T>, newValue: CustomCrafterAPIPropertiesChangeEvent.Property<T>, isAsync: Boolean = false)
Types
Link copied to clipboard
A value of CustomCrafterAPI property.
Link copied to clipboard
Key of Property<T>