use of org.spongepowered.api.advancement.criteria.trigger.Trigger in project SpongeCommon by SpongePowered.
the class MixinICriterionInstance method getType.
@Override
default Trigger getType() {
final ICriterionTrigger triggerType = CriteriaTriggers.get(getId());
checkNotNull(triggerType, "triggerType");
return (Trigger) triggerType;
}
use of org.spongepowered.api.advancement.criteria.trigger.Trigger in project SpongeCommon by SpongePowered.
the class SpongeTriggerBuilder method build.
@Override
public Trigger<C> build() {
checkState(this.id != null, "The id must be set");
checkState(this.configType != null, "The configType must be set");
final PluginContainer plugin = Sponge.getCauseStackManager().getCurrentCause().first(PluginContainer.class).get();
final String name = StringUtils.isNotEmpty(this.name) ? this.name : this.id;
return (Trigger<C>) new SpongeTrigger((Class) this.configType, (Function) this.constructor, new ResourceLocation(plugin.getId(), id), (Consumer) this.eventHandler, name);
}
use of org.spongepowered.api.advancement.criteria.trigger.Trigger in project SpongeCommon by SpongePowered.
the class CriterionTriggerInstanceMixin_API method type.
@Override
default Trigger type() {
final CriterionTrigger triggerType = CriteriaTriggers.getCriterion(this.shadow$getCriterion());
Preconditions.checkNotNull(triggerType, "triggerType");
return (Trigger) triggerType;
}
use of org.spongepowered.api.advancement.criteria.trigger.Trigger in project SpongeCommon by SpongePowered.
the class AdvancementTest method onRegisterTriggers.
@Listener
public void onRegisterTriggers(GameRegistryEvent.Register<Trigger> event) {
this.logger.info("Advancements test source: " + this.pluginContainer.getSource().orElse(null));
this.trigger = Trigger.builder().typeSerializableConfig(MyTriggerConfig.class).listener(triggerEvent -> {
final Random random = new Random();
final float value = random.nextFloat();
final float chance = triggerEvent.getTrigger().getConfiguration().chance;
triggerEvent.setResult(value < chance);
triggerEvent.getTargetEntity().sendMessage(Text.of(value + " < " + chance + " -> " + triggerEvent.getResult()));
}).id("my_trigger").build();
event.register(this.trigger);
}
use of org.spongepowered.api.advancement.criteria.trigger.Trigger in project LanternServer by LanternPowered.
the class AdvancementTest method onRegisterTriggers.
@Listener
public void onRegisterTriggers(GameRegistryEvent.Register<Trigger> event) {
this.trigger = Trigger.builder().typeSerializableConfig(MyTriggerConfig.class).listener(triggerEvent -> {
final Random random = new Random();
final float value = random.nextFloat();
final float chance = triggerEvent.getTrigger().getConfiguration().chance;
triggerEvent.setResult(value < chance);
}).id("my_trigger").build();
event.register(this.trigger);
}
Aggregations