TriggerReactor

TriggerReactor

24.6k Downloads

Add "optional" option in Executor/Placeholder validation

Sayakie opened this issue ยท 1 comments

commented

It would be great if we could control the need for these parameters.

For example, #VELOCITY Executor accepts 3 arguments for x, y, z. Buf what if we want to handle the target entity?

Current:

validation = {
  overloads: [
    { name: 'x', type: 'number' },
    { name: 'y', type: 'number' },
    { name: 'z', type: 'number' }
  ]
}
// Could not handle target entity. Target is fixed the running player.
#VELOCITY 64, 128, 64

Feature:

var Entity = Java.type('org.spongepowered.api.entity.Entity')

validation = {
  overloads: [
    { name: 'x', type: 'number' },
    { name: 'y', type: 'number' },
    { name: 'z', type: 'number' },
    { name: 'target', type: Entity.class, optional: true }
  ]
}
// Target is the running player
#VELOCITY 64, 128, 64

// Target is the onlined player, "Sayakie"
target = Sponge.getGame().getServer().getPlayer("Sayakie").orElse(null)
#VELOCITY 64, 128, 64, target
commented

Validation options only have the power to reject, not to do something like fill in a missing value or make it optional.
That was my mistake when designing it.

I still look back on the validation code as an example of badly designed code I wrote. I want to fix it.