Delay trigger delays other triggers

This commit is contained in:
fullwall 2012-10-31 12:03:38 +08:00
parent 567b2d5e25
commit ae6a666bc6
3 changed files with 28 additions and 5 deletions

View File

@ -269,10 +269,7 @@ public class LinearWaypointProvider implements WaypointProvider {
return; // the player isn't scrolling return; // the player isn't scrolling
editingSlot += diff > 0 ? 1 : -1; editingSlot += diff > 0 ? 1 : -1;
} }
if (editingSlot >= waypoints.size()) normaliseEditingSlot();
editingSlot = 0;
if (editingSlot < 0)
editingSlot = waypoints.size() - 1;
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_EDIT_SLOT_SET, editingSlot, Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_EDIT_SLOT_SET, editingSlot,
formatLoc(waypoints.get(editingSlot).getLocation())); formatLoc(waypoints.get(editingSlot).getLocation()));
} }

View File

@ -3,12 +3,15 @@ package net.citizensnpcs.trait.waypoint;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.persistence.Persist; import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.persistence.PersistenceLoader; 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.WaypointTrigger;
import net.citizensnpcs.trait.waypoint.triggers.WaypointTriggerRegistry; import net.citizensnpcs.trait.waypoint.triggers.WaypointTriggerRegistry;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
@ -44,8 +47,27 @@ public class Waypoint {
public void onReach(NPC npc) { public void onReach(NPC npc) {
if (triggers == null) if (triggers == null)
return; 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); 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 { static {

View File

@ -31,6 +31,10 @@ public class DelayTrigger implements WaypointTrigger {
scheduleTask(npc.getTrait(Waypoints.class).getCurrentProvider()); scheduleTask(npc.getTrait(Waypoints.class).getCurrentProvider());
} }
public int getDelay() {
return delay;
}
private void scheduleTask(final WaypointProvider provider) { private void scheduleTask(final WaypointProvider provider) {
provider.setPaused(true); provider.setPaused(true);
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() { Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {