mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-24 19:45:43 +01:00
Extended Sign Redstone
This commit is contained in:
parent
3ca26eff16
commit
c82d45ced4
@ -4,6 +4,7 @@ import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
|
||||
import com.dre.dungeonsxl.game.GameWorld;
|
||||
import com.dre.dungeonsxl.P;
|
||||
|
||||
public class SIGNRedstone extends DSign {
|
||||
|
||||
@ -14,7 +15,13 @@ public class SIGNRedstone extends DSign {
|
||||
// Variables
|
||||
private boolean initialized;
|
||||
private boolean active;
|
||||
private int enableTaskId = -1;
|
||||
private int disableTaskId = -1;
|
||||
private Block block;
|
||||
private long delay = 0;
|
||||
private long offDelay = 0;
|
||||
private int repeat = 1;
|
||||
private int repeatsToDo = 1;
|
||||
|
||||
public SIGNRedstone(Sign sign, GameWorld gworld) {
|
||||
super(sign, gworld);
|
||||
@ -22,12 +29,38 @@ public class SIGNRedstone extends DSign {
|
||||
|
||||
@Override
|
||||
public boolean check() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInit() {
|
||||
int line1 = 0;
|
||||
int line11 = 0;
|
||||
if (!sign.getLine(1).equals("")) {
|
||||
String line[] = sign.getLine(1).split(",");
|
||||
line1 = P.p.parseInt(line[0]);
|
||||
if (line.length > 1) {
|
||||
line11 = P.p.parseInt(line[1]);
|
||||
}
|
||||
}
|
||||
|
||||
int line2 = 1;
|
||||
if (!sign.getLine(2).equals("")) {
|
||||
line2 = P.p.parseInt(sign.getLine(2));
|
||||
}
|
||||
|
||||
if (line1 > 0) {
|
||||
delay = (long) line1 * 2;
|
||||
if (line11 > 0) {
|
||||
offDelay = (long) line11 * 2;
|
||||
} else {
|
||||
offDelay = delay;
|
||||
}
|
||||
if (line2 >= 0) {
|
||||
repeat = line2;
|
||||
}
|
||||
}
|
||||
|
||||
this.block = sign.getBlock();
|
||||
this.block.setTypeId(0);
|
||||
|
||||
@ -37,7 +70,15 @@ public class SIGNRedstone extends DSign {
|
||||
@Override
|
||||
public void onTrigger() {
|
||||
if (initialized && !active) {
|
||||
block.setTypeId(152);
|
||||
if (delay > 0) {
|
||||
enableTaskId = P.p.getServer().getScheduler().scheduleSyncRepeatingTask(P.p, new DelayedPower(true), delay, delay + offDelay);
|
||||
if (repeat != 1) {
|
||||
repeatsToDo = repeat;
|
||||
disableTaskId = P.p.getServer().getScheduler().scheduleSyncRepeatingTask(P.p, new DelayedPower(false), delay + offDelay, delay + offDelay);
|
||||
}
|
||||
} else {
|
||||
power();
|
||||
}
|
||||
active = true;
|
||||
}
|
||||
}
|
||||
@ -45,11 +86,33 @@ public class SIGNRedstone extends DSign {
|
||||
@Override
|
||||
public void onDisable() {
|
||||
if (initialized && active) {
|
||||
block.setTypeId(0);
|
||||
unpower();
|
||||
|
||||
disableTask(enableTaskId);
|
||||
disableTask(disableTaskId);
|
||||
enableTaskId = -1;
|
||||
disableTaskId = -1;
|
||||
|
||||
active = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void power() {
|
||||
block.setTypeId(152);
|
||||
}
|
||||
|
||||
public void unpower() {
|
||||
block.setTypeId(0);
|
||||
}
|
||||
|
||||
public void disableTask(int taskId) {
|
||||
if (taskId != -1) {
|
||||
if (P.p.getServer().getScheduler().isCurrentlyRunning(taskId) || P.p.getServer().getScheduler().isQueued(taskId)) {
|
||||
P.p.getServer().getScheduler().cancelTask(taskId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissions() {
|
||||
return buildPermissions;
|
||||
@ -59,4 +122,30 @@ public class SIGNRedstone extends DSign {
|
||||
public boolean isOnDungeonInit() {
|
||||
return onDungeonInit;
|
||||
}
|
||||
|
||||
public class DelayedPower implements Runnable {
|
||||
private final boolean enable;
|
||||
|
||||
public DelayedPower(boolean enable) {
|
||||
this.enable = enable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (enable) {
|
||||
power();
|
||||
if (repeatsToDo == 1) {
|
||||
disableTask(enableTaskId);
|
||||
enableTaskId = -1;
|
||||
}
|
||||
} else {
|
||||
unpower();
|
||||
if (repeatsToDo == 1) {
|
||||
disableTask(disableTaskId);
|
||||
disableTaskId = -1;
|
||||
}
|
||||
repeatsToDo--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user