Removed randomnizer in setDefective() because it's useless

This commit is contained in:
stijnb1234 2020-02-26 10:43:00 +01:00
parent 8832db764c
commit 330ead82ff

View file

@ -579,76 +579,60 @@ 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
Block block = Objects.requireNonNull(Bukkit.getWorld(ls.getWorld()), "World is null at setDefective").getBlockAt(ls.getX(), ls.getY(), ls.getZ()); for (LiftSign ls : lift.getSigns()) {
BlockState bs = block.getState(); Block block = Objects.requireNonNull(Bukkit.getWorld(ls.getWorld()), "World is null at setDefective").getBlockAt(ls.getX(), ls.getY(), ls.getZ());
if (!(bs instanceof Sign)) { BlockState bs = block.getState();
Bukkit.getLogger().severe("[V10Lift] Wrong sign removed at: " + LocationSerializer.serialize(block.getLocation())); if (!(bs instanceof Sign)) {
liter.remove(); Bukkit.getLogger().severe("[V10Lift] Wrong sign removed at: " + LocationSerializer.serialize(block.getLocation()));
return -4; return -4;
}
Sign s = (Sign) bs;
ls.setOldText(s.getLine(3));
s.setLine(3, ConfigUtil.getColored("DefectText"));
s.update();
} }
Sign s = (Sign) bs; //Update all cab signs
ls.setOldText(s.getLine(3));
s.setLine(3, ConfigUtil.getColored("DefectText"));
s.update();
//Update all other 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;
Sign s;
while (liter.hasNext()) {
ls = liter.next();
bs = Objects.requireNonNull(Bukkit.getWorld(ls.getWorld()), "World is null at setDefective").getBlockAt(ls.getX(), ls.getY(), ls.getZ()).getState();
if (!(bs instanceof Sign)) {
Bukkit.getLogger().severe("[V10Lift] Wrong sign removed at: " + LocationSerializer.serialize(bs.getBlock().getLocation()));
liter.remove();
continue;
}
s = (Sign) bs;
if (s.getLine(3).equals(ConfigUtil.getColored("DefectText"))) {
s.setLine(3, ls.getOldText());
s.update();
ls.setOldText(null);
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();
if (!(bs instanceof Sign)) continue;
s = (Sign) bs; //Update sign
s.setLine(3, lift.getSignText()); for (LiftSign ls : lift.getSigns()) {
s.update(); Block block = Objects.requireNonNull(Bukkit.getWorld(ls.getWorld()), "World is null at setDefective").getBlockAt(ls.getX(), ls.getY(), ls.getZ());
lift.setSignText(null); BlockState bs = block.getState();
} if (!(bs instanceof Sign)) {
Bukkit.getLogger().severe("[V10Lift] Wrong sign removed at: " + LocationSerializer.serialize(block.getLocation()));
return -4;
} }
Sign s = (Sign) bs;
s.setLine(3, ls.getOldText());
ls.setOldText(null);
s.update();
} }
//Update all cab signs
for (LiftBlock lb : lift.getBlocks()) {
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;
Sign s = (Sign) bs;
s.setLine(3, lift.getSignText());
s.update();
}
lift.setSignText(null);
} }
return 0; return 0;
} }