Shift trigger logic to new sign categories

This commit is contained in:
Daniel Saukel 2020-03-20 21:09:36 +01:00
parent 82cb68c3b5
commit 56ef3dd202
5 changed files with 21 additions and 51 deletions

View File

@ -64,29 +64,6 @@ public abstract class Button extends AbstractDSign {
return true; return true;
} }
@Override
public void update() {
if (isErroneous()) {
return;
}
for (Trigger trigger : getTriggers()) {
if (!trigger.isTriggered()) {
return;
}
if (trigger.getPlayer() == null) {
continue;
}
if (push(trigger.getPlayer())) {
return;
}
}
push();
}
/** /**
* This is the same as {@link #push(org.bukkit.entity.Player)}. * This is the same as {@link #push(org.bukkit.entity.Player)}.
* *

View File

@ -119,28 +119,4 @@ public abstract class Deactivatable extends AbstractDSign {
return isActive(); return isActive();
} }
@Override
public void update() {
if (isErroneous()) {
return;
}
for (Trigger trigger : getTriggers()) {
if (!trigger.isTriggered()) {
deactivate();
return;
}
if (trigger.getPlayer() == null) {
continue;
}
if (activate(trigger.getPlayer())) {
return;
}
}
activate();
}
} }

View File

@ -170,9 +170,23 @@ public interface DungeonSign {
void trigger(Player player); void trigger(Player player);
/** /**
* Updates the sign. * Checks if the triggers of the sign have been triggered. If they all are, the sign itself is triggered.
*
* @param lastFired the last trigger that has been triggered
*/ */
void update(); default void updateTriggers(Trigger lastFired) {
if (isErroneous()) {
return;
}
for (Trigger trigger : getTriggers()) {
if (!trigger.isTriggered()) {
return;
}
}
trigger(lastFired != null ? lastFired.getPlayer() : null);
}
/** /**
* Sets the sign to air if it is not erroneous and if its type requires this. * Sets the sign to air if it is not erroneous and if its type requires this.

View File

@ -15,6 +15,7 @@
package de.erethon.dungeonsxl.api.sign; package de.erethon.dungeonsxl.api.sign;
import de.erethon.dungeonsxl.api.DungeonsAPI; import de.erethon.dungeonsxl.api.DungeonsAPI;
import de.erethon.dungeonsxl.api.Trigger;
import de.erethon.dungeonsxl.api.world.InstanceWorld; import de.erethon.dungeonsxl.api.world.InstanceWorld;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -32,9 +33,11 @@ public abstract class Passive extends AbstractDSign {
/** /**
* Does nothing. * Does nothing.
*
* @param lastFired unused
*/ */
@Override @Override
public final void update() { public final void updateTriggers(Trigger lastFired) {
} }
/** /**

View File

@ -106,7 +106,7 @@ public abstract class Trigger implements de.erethon.dungeonsxl.api.Trigger {
public void updateDSigns() { public void updateDSigns() {
for (DungeonSign dSign : dSigns.toArray(new DungeonSign[dSigns.size()])) { for (DungeonSign dSign : dSigns.toArray(new DungeonSign[dSigns.size()])) {
dSign.update(); dSign.updateTriggers(this);
} }
} }