-
Notifications
You must be signed in to change notification settings - Fork 2
Manipulating Triggers
With Pwing Races, you are able to create your own triggers, and trigger passives to correspond with them. Triggers are what is "checked" when a certain action is met, and trigger passives are what run if that trigger is met.
Calling triggers is probably one of the easiest things to do with the Pwing Races API. Since triggers are just a string, you can call them from almost anywhere and make them whatever you want.
Here is an example of the block break trigger:
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
if (event.isCancelled())
return;
Player player = event.getPlayer();
RaceTriggerManager triggerManager = PwingRacesAPI.getTriggerManager();
triggerManager.runTriggers(player, "block-break");
triggerManager.runTriggers(player, "block-break " + event.getBlock().getType().name().toLowerCase());
}
Now as you may notice, block-break
is being called twice. The first time it's called it simply just calls the block-break
trigger defined like this:
triggers:
speedbreak:
trigger: block-break
delay: 5
run-passives:
- add-potion-effect fast_digging 2 2
The first one will only call block-break
, and nothing after. However, the second one is called every time a block is broken, with the block name included. So you could easily listen for when a player broke a diamond ore.
triggers:
diamondbreak:
trigger: block-break diamond_ore
delay: 5
run-passives:
- add-potion-effect fast_digging 10 10
This second one listens for when a diamond_ore
is broken. But as you notice, the trigger has the ability to listen for all blocks. You can use variables like this to create some pretty powerful triggers.
Trigger passives are the passives that you can define when a trigger is triggered. Since these trigger passives come as a string, you have to parse the string to get it to work.
Here is an example of the burn trigger
package net.pwing.races.race.trigger.passives;
import net.pwing.races.api.race.trigger.RaceTriggerPassive;
import net.pwing.races.utilities.NumberUtil;
import org.bukkit.entity.Player;
public class BurnTrigger extends RaceTriggerPassive {
public BurnTrigger(String name) {
super(name);
}
@Override
public void runTriggerPassive(Player player, String trigger) {
String[] split = trigger.split(" ");
if (split.length < 2)
return;
int ticks = 60;
if (NumberUtil.isInteger(split[1]))
ticks = Integer.parseInt(split[1]);
player.setFireTicks(ticks);
}
}
And for registering them, here is how you would do that:
RaceTriggerManager triggerManager = PwingRacesAPI.getTriggerManager();
triggerManager.getTriggerPassives.put("burn", new BurnTrigger("burn"));
Now when you want to use it, just define it as a string in your trigger passives section, and it will run! Here is an example of it in action:
triggers:
burn:
trigger: in-sunlight
chance: 100
delay: 1
run-passives:
- "burn 20"
- "send-message &cYou are burning! Get out of the sun to find safety!"