mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-27 21:29:14 +01:00
Delay trigger delays other triggers
This commit is contained in:
parent
567b2d5e25
commit
ae6a666bc6
@ -269,10 +269,7 @@ public class LinearWaypointProvider implements WaypointProvider {
|
||||
return; // the player isn't scrolling
|
||||
editingSlot += diff > 0 ? 1 : -1;
|
||||
}
|
||||
if (editingSlot >= waypoints.size())
|
||||
editingSlot = 0;
|
||||
if (editingSlot < 0)
|
||||
editingSlot = waypoints.size() - 1;
|
||||
normaliseEditingSlot();
|
||||
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_EDIT_SLOT_SET, editingSlot,
|
||||
formatLoc(waypoints.get(editingSlot).getLocation()));
|
||||
}
|
||||
|
@ -3,12 +3,15 @@ package net.citizensnpcs.trait.waypoint;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.persistence.Persist;
|
||||
import net.citizensnpcs.api.persistence.PersistenceLoader;
|
||||
import net.citizensnpcs.trait.waypoint.triggers.DelayTrigger;
|
||||
import net.citizensnpcs.trait.waypoint.triggers.WaypointTrigger;
|
||||
import net.citizensnpcs.trait.waypoint.triggers.WaypointTriggerRegistry;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
@ -44,8 +47,27 @@ public class Waypoint {
|
||||
public void onReach(NPC npc) {
|
||||
if (triggers == null)
|
||||
return;
|
||||
for (WaypointTrigger trigger : triggers)
|
||||
runTriggers(npc, 0);
|
||||
}
|
||||
|
||||
private void runTriggers(final NPC npc, int start) {
|
||||
for (int i = start; i < triggers.size(); i++) {
|
||||
WaypointTrigger trigger = triggers.get(i);
|
||||
trigger.onWaypointReached(npc, location);
|
||||
if (trigger instanceof DelayTrigger) {
|
||||
int delay = ((DelayTrigger) trigger).getDelay();
|
||||
if (delay <= 0)
|
||||
continue;
|
||||
final int newStart = i;
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
runTriggers(npc, newStart);
|
||||
}
|
||||
}, delay);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
|
@ -31,6 +31,10 @@ public class DelayTrigger implements WaypointTrigger {
|
||||
scheduleTask(npc.getTrait(Waypoints.class).getCurrentProvider());
|
||||
}
|
||||
|
||||
public int getDelay() {
|
||||
return delay;
|
||||
}
|
||||
|
||||
private void scheduleTask(final WaypointProvider provider) {
|
||||
provider.setPaused(true);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
||||
|
Loading…
Reference in New Issue
Block a user