Removed randomnizer in setDefective() because it's useless
This commit is contained in:
parent
8832db764c
commit
330ead82ff
1 changed files with 38 additions and 54 deletions
|
@ -579,30 +579,14 @@ public class V10LiftAPI {
|
||||||
boolean oldState = lift.isDefective();
|
boolean oldState = lift.isDefective();
|
||||||
if (oldState == state) return -2;
|
if (oldState == state) return -2;
|
||||||
lift.setDefective(state);
|
lift.setDefective(state);
|
||||||
Iterator<LiftSign> liter = lift.getSigns().iterator();
|
|
||||||
if (state) {
|
if (state) {
|
||||||
//SET DEFECTIVE
|
//SET DEFECTIVE
|
||||||
int max = lift.getSigns().size();
|
|
||||||
if (max == 0) return -3;
|
|
||||||
LiftSign ls;
|
|
||||||
if (max == 1) {
|
|
||||||
//If one sign, update that one.
|
|
||||||
ls = liter.next();
|
|
||||||
} else {
|
|
||||||
//If multiple signs, get random one.
|
|
||||||
int r = new Random().nextInt(max);
|
|
||||||
for (int i = 0; i < r; i++) {
|
|
||||||
liter.next();
|
|
||||||
}
|
|
||||||
ls = liter.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
//Update sign
|
//Update sign
|
||||||
|
for (LiftSign ls : lift.getSigns()) {
|
||||||
Block block = Objects.requireNonNull(Bukkit.getWorld(ls.getWorld()), "World is null at setDefective").getBlockAt(ls.getX(), ls.getY(), ls.getZ());
|
Block block = Objects.requireNonNull(Bukkit.getWorld(ls.getWorld()), "World is null at setDefective").getBlockAt(ls.getX(), ls.getY(), ls.getZ());
|
||||||
BlockState bs = block.getState();
|
BlockState bs = block.getState();
|
||||||
if (!(bs instanceof Sign)) {
|
if (!(bs instanceof Sign)) {
|
||||||
Bukkit.getLogger().severe("[V10Lift] Wrong sign removed at: " + LocationSerializer.serialize(block.getLocation()));
|
Bukkit.getLogger().severe("[V10Lift] Wrong sign removed at: " + LocationSerializer.serialize(block.getLocation()));
|
||||||
liter.remove();
|
|
||||||
return -4;
|
return -4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -610,46 +594,46 @@ public class V10LiftAPI {
|
||||||
ls.setOldText(s.getLine(3));
|
ls.setOldText(s.getLine(3));
|
||||||
s.setLine(3, ConfigUtil.getColored("DefectText"));
|
s.setLine(3, ConfigUtil.getColored("DefectText"));
|
||||||
s.update();
|
s.update();
|
||||||
|
}
|
||||||
|
|
||||||
//Update all other signs
|
//Update all cab signs
|
||||||
for (LiftBlock lb : lift.getBlocks()) {
|
for (LiftBlock lb : lift.getBlocks()) {
|
||||||
bs = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at setDefective").getBlockAt(lb.getX(), lb.getY(), lb.getZ()).getState();
|
BlockState bs = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at setDefective").getBlockAt(lb.getX(), lb.getY(), lb.getZ()).getState();
|
||||||
if (!(bs instanceof Sign)) continue;
|
if (!(bs instanceof Sign)) continue;
|
||||||
|
|
||||||
s = (Sign) bs;
|
Sign s = (Sign) bs;
|
||||||
lift.setSignText(s.getLine(3));
|
lift.setSignText(s.getLine(3));
|
||||||
s.setLine(3, ConfigUtil.getColored("DefectText"));
|
s.setLine(3, ConfigUtil.getColored("DefectText"));
|
||||||
s.update();
|
s.update();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LiftSign ls;
|
|
||||||
BlockState bs;
|
//Update sign
|
||||||
Sign s;
|
for (LiftSign ls : lift.getSigns()) {
|
||||||
while (liter.hasNext()) {
|
Block block = Objects.requireNonNull(Bukkit.getWorld(ls.getWorld()), "World is null at setDefective").getBlockAt(ls.getX(), ls.getY(), ls.getZ());
|
||||||
ls = liter.next();
|
BlockState bs = block.getState();
|
||||||
bs = Objects.requireNonNull(Bukkit.getWorld(ls.getWorld()), "World is null at setDefective").getBlockAt(ls.getX(), ls.getY(), ls.getZ()).getState();
|
|
||||||
if (!(bs instanceof Sign)) {
|
if (!(bs instanceof Sign)) {
|
||||||
Bukkit.getLogger().severe("[V10Lift] Wrong sign removed at: " + LocationSerializer.serialize(bs.getBlock().getLocation()));
|
Bukkit.getLogger().severe("[V10Lift] Wrong sign removed at: " + LocationSerializer.serialize(block.getLocation()));
|
||||||
liter.remove();
|
return -4;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
s = (Sign) bs;
|
|
||||||
if (s.getLine(3).equals(ConfigUtil.getColored("DefectText"))) {
|
Sign s = (Sign) bs;
|
||||||
s.setLine(3, ls.getOldText());
|
s.setLine(3, ls.getOldText());
|
||||||
s.update();
|
|
||||||
ls.setOldText(null);
|
ls.setOldText(null);
|
||||||
|
s.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Update all cab signs
|
||||||
for (LiftBlock lb : lift.getBlocks()) {
|
for (LiftBlock lb : lift.getBlocks()) {
|
||||||
bs = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at setDefective").getBlockAt(lb.getX(), lb.getY(), lb.getZ()).getState();
|
BlockState bs = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at setDefective").getBlockAt(lb.getX(), lb.getY(), lb.getZ()).getState();
|
||||||
if (!(bs instanceof Sign)) continue;
|
if (!(bs instanceof Sign)) continue;
|
||||||
|
|
||||||
s = (Sign) bs;
|
Sign s = (Sign) bs;
|
||||||
s.setLine(3, lift.getSignText());
|
s.setLine(3, lift.getSignText());
|
||||||
s.update();
|
s.update();
|
||||||
|
}
|
||||||
lift.setSignText(null);
|
lift.setSignText(null);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue