Beautified MoveLift (removed duplicate code)
This commit is contained in:
parent
4f5ef2cee5
commit
a1e158eb01
5 changed files with 196 additions and 302 deletions
6
pom.xml
6
pom.xml
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>nl.SBDeveloper</groupId>
|
||||
|
@ -148,7 +149,7 @@
|
|||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<serverId>nexus</serverId>
|
||||
<serverId>iobyte-nexus</serverId>
|
||||
<nexusUrl>https://nexus.iobyte.nl/</nexusUrl>
|
||||
<skipStaging>true</skipStaging>
|
||||
</configuration>
|
||||
|
@ -241,5 +242,4 @@
|
|||
<version>1.6.4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -11,6 +11,7 @@ import nl.SBDeveloper.V10Lift.sbutils.LocationSerializer;
|
|||
import nl.SBDeveloper.V10Lift.utils.ConfigUtil;
|
||||
import nl.SBDeveloper.V10Lift.utils.DirectionUtil;
|
||||
import nl.SBDeveloper.V10Lift.utils.DoorUtil;
|
||||
import org.apache.commons.collections4.map.LinkedMap;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
@ -941,7 +942,7 @@ public class V10LiftAPI {
|
|||
if (liftName == null || queue == null || !DataManager.containsLift(liftName)) return false;
|
||||
|
||||
Lift lift = DataManager.getLift(liftName);
|
||||
lift.setQueue(new LinkedHashMap<>());
|
||||
lift.setQueue(new LinkedMap<>());
|
||||
for (Map.Entry<String, Floor> e : queue.entrySet()) {
|
||||
addToQueue(liftName, e.getValue(), e.getKey());
|
||||
}
|
||||
|
@ -989,7 +990,7 @@ public class V10LiftAPI {
|
|||
|
||||
Lift l = DataManager.getLift(lift);
|
||||
if (l.getQueue() == null) {
|
||||
l.setQueue(new LinkedHashMap<>());
|
||||
l.setQueue(new LinkedMap<>());
|
||||
}
|
||||
|
||||
if (!l.getQueue().containsValue(floor)) {
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package nl.SBDeveloper.V10Lift.api.enums;
|
||||
|
||||
public enum LiftDirection {
|
||||
UP, DOWN, STOP
|
||||
}
|
|
@ -14,12 +14,11 @@ public class Lift {
|
|||
@Getter @Setter private String worldName;
|
||||
@Getter @Setter private int y;
|
||||
@Getter private HashSet<UUID> owners;
|
||||
//@Getter @Setter private ArrayList<String> whitelist;
|
||||
@Getter private final TreeSet<LiftBlock> blocks = new TreeSet<>();
|
||||
@Getter private final LinkedHashMap<String, Floor> floors = new LinkedHashMap<>();
|
||||
@Getter private final HashSet<LiftSign> signs = new HashSet<>();
|
||||
@Getter private final HashSet<LiftBlock> inputs = new HashSet<>();
|
||||
@Getter private HashSet<LiftBlock> offlineInputs = new HashSet<>();
|
||||
@Getter private final HashSet<LiftBlock> offlineInputs = new HashSet<>();
|
||||
@Getter @Setter private LinkedHashMap<String, Floor> queue = null;
|
||||
@Getter private final HashSet<LiftRope> ropes = new HashSet<>();
|
||||
@Getter private transient final ArrayList<V10Entity> toMove = new ArrayList<>();
|
||||
|
|
|
@ -3,6 +3,7 @@ package nl.SBDeveloper.V10Lift.api.runnables;
|
|||
import com.cryptomorin.xseries.XMaterial;
|
||||
import com.cryptomorin.xseries.XSound;
|
||||
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
|
||||
import nl.SBDeveloper.V10Lift.api.enums.LiftDirection;
|
||||
import nl.SBDeveloper.V10Lift.api.objects.*;
|
||||
import nl.SBDeveloper.V10Lift.managers.AntiCopyBlockManager;
|
||||
import nl.SBDeveloper.V10Lift.managers.DataManager;
|
||||
|
@ -20,11 +21,11 @@ import org.bukkit.inventory.ItemStack;
|
|||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/** The MoveLift runnable, used for moving a lift. */
|
||||
public class MoveLift implements Runnable {
|
||||
|
||||
/* Packet teleportation method */
|
||||
private final Method[] methods = ((Supplier<Method[]>) () -> {
|
||||
try {
|
||||
|
@ -62,57 +63,44 @@ public class MoveLift implements Runnable {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
Iterator<LiftBlock> iter;
|
||||
ArrayList<LiftBlock> tb = new ArrayList<>();
|
||||
Block block = null;
|
||||
World world;
|
||||
Location loc;
|
||||
BlockState bs;
|
||||
boolean by;
|
||||
int y;
|
||||
Chest c;
|
||||
V10Entity v10ent;
|
||||
Iterator<V10Entity> veiter;
|
||||
Sign sign;
|
||||
LiftBlock lb;
|
||||
Lift lift;
|
||||
LiftSign ls;
|
||||
Inventory inv;
|
||||
ItemStack is;
|
||||
ItemStack[] isa;
|
||||
|
||||
lift = DataManager.getLift(liftName);
|
||||
//Check if lift exists
|
||||
Lift lift = DataManager.getLift(liftName);
|
||||
if (lift == null) {
|
||||
stopMe();
|
||||
stop();
|
||||
return;
|
||||
}
|
||||
|
||||
//If the queue is NOT empty and the lift is NOT offline
|
||||
if (lift.getQueue().isEmpty() || lift.isOffline()) {
|
||||
lift.setQueue(null);
|
||||
stopMe();
|
||||
stop();
|
||||
return;
|
||||
}
|
||||
|
||||
//If the lift is NOT in edit mode and the lift is NOT defective
|
||||
if (DataManager.containsEditLift(liftName) || lift.isDefective()) return;
|
||||
|
||||
//If the lift is NOT in delay
|
||||
if (lift.getCounter() > 0) {
|
||||
lift.setCounter(lift.getCounter() - 1);
|
||||
return;
|
||||
}
|
||||
|
||||
lb = lift.getBlocks().first();
|
||||
world = Bukkit.getWorld(lb.getWorld());
|
||||
//Check if the chunk of the first block is loaded
|
||||
LiftBlock lb = lift.getBlocks().first();
|
||||
World world = Bukkit.getWorld(lb.getWorld());
|
||||
if (world == null) {
|
||||
lift.setCounter(ft);
|
||||
return;
|
||||
}
|
||||
|
||||
loc = new Location(world, lb.getX(), lb.getY(), lb.getZ());
|
||||
Location loc = new Location(world, lb.getX(), lb.getY(), lb.getZ());
|
||||
if (!loc.getChunk().isLoaded()) {
|
||||
lift.setCounter(ft);
|
||||
return;
|
||||
}
|
||||
|
||||
//And if the chunk of the last block is loaded
|
||||
lb = lift.getBlocks().last();
|
||||
world = Bukkit.getWorld(lb.getWorld());
|
||||
if (world == null) {
|
||||
|
@ -126,82 +114,87 @@ public class MoveLift implements Runnable {
|
|||
return;
|
||||
}
|
||||
|
||||
//Handle malfunction
|
||||
double changeOfDefect = V10LiftPlugin.getSConfig().getFile().getDouble("DefectRate");
|
||||
if (changeOfDefect > 0.0D) {
|
||||
y = new Random().nextInt(100);
|
||||
double chance;
|
||||
if (y < 100) {
|
||||
long co = new Random().nextLong();
|
||||
if (co < 0) co = -co;
|
||||
chance = Double.parseDouble(y + "." + co);
|
||||
} else {
|
||||
chance = y;
|
||||
}
|
||||
|
||||
double chance = ThreadLocalRandom.current().nextDouble(100);
|
||||
if (chance < changeOfDefect) {
|
||||
V10LiftPlugin.getAPI().setDefective(liftName, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Iterator<Map.Entry<String, Floor>> quiter = lift.getQueue().entrySet().iterator();
|
||||
Map.Entry<String, Floor> floor = quiter.next();
|
||||
Floor to = floor.getValue();
|
||||
String fl = floor.getKey();
|
||||
boolean up = false;
|
||||
boolean down = false;
|
||||
if (lift.getY() < to.getY()) {
|
||||
up = true;
|
||||
} else if (lift.getY() > to.getY()) {
|
||||
down = true;
|
||||
Iterator<Map.Entry<String, Floor>> queueIterator = lift.getQueue().entrySet().iterator();
|
||||
Map.Entry<String, Floor> floor = queueIterator.next();
|
||||
String floorName = floor.getKey();
|
||||
Floor floorTo = floor.getValue();
|
||||
|
||||
LiftDirection direction;
|
||||
if (lift.getY() < floorTo.getY()) {
|
||||
direction = LiftDirection.UP;
|
||||
} else if (lift.getY() > floorTo.getY()) {
|
||||
direction = LiftDirection.DOWN;
|
||||
} else {
|
||||
direction = LiftDirection.STOP;
|
||||
}
|
||||
|
||||
if (up) {
|
||||
List<LiftBlock> antiCopyBlocks = new ArrayList<>();
|
||||
|
||||
if (direction == LiftDirection.UP || direction == LiftDirection.DOWN) {
|
||||
if (!V10LiftPlugin.getAPI().closeDoor(liftName)) return;
|
||||
|
||||
if (direction == LiftDirection.UP) {
|
||||
//MOVE ROPES
|
||||
for (LiftRope rope : lift.getRopes()) {
|
||||
if (rope.getCurrently() > rope.getMaxY()) {
|
||||
Bukkit.getLogger().info("[V10Lift] Lift " + liftName + " reaches the upper rope end but won't stop!! 1");
|
||||
Bukkit.getLogger().info("[V10Lift] Lift " + liftName + " reaches the upper rope end but won't stop!!");
|
||||
|
||||
V10LiftPlugin.getAPI().setDefective(liftName, true);
|
||||
lift.getToMove().clear();
|
||||
quiter.remove();
|
||||
queueIterator.remove();
|
||||
return;
|
||||
}
|
||||
world = Objects.requireNonNull(Bukkit.getWorld(rope.getWorld()), "World is null at MoveLift");
|
||||
block = world.getBlockAt(rope.getX(), rope.getCurrently(), rope.getZ());
|
||||
block.setType(Material.AIR);
|
||||
|
||||
Block currentRopeBlock = Bukkit.getWorld(rope.getWorld()).getBlockAt(rope.getX(), rope.getCurrently(), rope.getZ());
|
||||
currentRopeBlock.setType(Material.AIR);
|
||||
|
||||
rope.setCurrently(rope.getCurrently() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
iter = lift.getBlocks().iterator();
|
||||
while (iter.hasNext()) {
|
||||
lb = iter.next();
|
||||
if (AntiCopyBlockManager.isAntiCopy(lb.getMat())) {
|
||||
tb.add(lb);
|
||||
iter.remove();
|
||||
block = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at MoveLift").getBlockAt(lb.getX(), lb.getY(), lb.getZ());
|
||||
block.setType(Material.AIR);
|
||||
lb.setY(lb.getY() + 1);
|
||||
Iterator<LiftBlock> blockIterator = lift.getBlocks().iterator();
|
||||
while (blockIterator.hasNext()) {
|
||||
LiftBlock liftBlock = blockIterator.next();
|
||||
if (AntiCopyBlockManager.isAntiCopy(liftBlock.getMat())) {
|
||||
antiCopyBlocks.add(liftBlock);
|
||||
blockIterator.remove();
|
||||
|
||||
Block antiCopyBlock = Bukkit.getWorld(liftBlock.getWorld()).getBlockAt(liftBlock.getX(), liftBlock.getY(), liftBlock.getZ());
|
||||
antiCopyBlock.setType(Material.AIR);
|
||||
|
||||
liftBlock.setY(direction == LiftDirection.UP ? liftBlock.getY() + 1 : liftBlock.getY() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
for (LiftBlock lib : lift.getBlocks().descendingSet()) {
|
||||
world = Objects.requireNonNull(Bukkit.getWorld(lib.getWorld()), "World is null at MoveLift");
|
||||
block = world.getBlockAt(lib.getX(), lib.getY(), lib.getZ());
|
||||
Set<LiftBlock> set = direction == LiftDirection.UP ? lift.getBlocks().descendingSet() : lift.getBlocks();
|
||||
for (LiftBlock lib : set) {
|
||||
Block block = Bukkit.getWorld(lib.getWorld()).getBlockAt(lib.getX(), lib.getY(), lib.getZ());
|
||||
|
||||
if ((lib.getMat() == Material.CHEST || lib.getMat() == Material.TRAPPED_CHEST) && lib.serializedItemStacks == null) {
|
||||
c = (Chest) block.getState();
|
||||
inv = c.getInventory();
|
||||
isa = inv.getContents();
|
||||
by = false;
|
||||
lib.serializedItemStacks = new Map[isa.length];
|
||||
for (int i = 0; i < isa.length; i++) {
|
||||
is = isa[i];
|
||||
Chest c = (Chest) block.getState();
|
||||
Inventory inv = c.getInventory();
|
||||
ItemStack[] invContents = inv.getContents();
|
||||
boolean by = false;
|
||||
|
||||
lib.serializedItemStacks = new Map[invContents.length];
|
||||
for (int i = 0; i < invContents.length; i++) {
|
||||
ItemStack is = invContents[i];
|
||||
if (is != null) {
|
||||
by = true;
|
||||
lib.serializedItemStacks[i] = is.serialize();
|
||||
}
|
||||
}
|
||||
|
||||
if (by) {
|
||||
inv.clear();
|
||||
c.update();
|
||||
|
@ -211,84 +204,86 @@ public class MoveLift implements Runnable {
|
|||
}
|
||||
|
||||
block.setType(Material.AIR);
|
||||
lib.setY(lib.getY() + 1);
|
||||
block = Objects.requireNonNull(Bukkit.getWorld(lib.getWorld()), "World is null at MoveLift").getBlockAt(lib.getX(), lib.getY(), lib.getZ());
|
||||
BlockState state = block.getState();
|
||||
|
||||
lib.setY(direction == LiftDirection.UP ? lib.getY() + 1 : lib.getY() - 1);
|
||||
Block nextBlock = Bukkit.getWorld(lib.getWorld()).getBlockAt(lib.getX(), lib.getY(), lib.getZ());
|
||||
if (lib.getMat() == null) lib.setMat(Material.AIR);
|
||||
|
||||
BlockState state = nextBlock.getState();
|
||||
state.setType(lib.getMat());
|
||||
if (!XMaterial.isNewVersion()) {
|
||||
state.setRawData(lib.getData());
|
||||
}
|
||||
state.update(true);
|
||||
|
||||
if (XMaterial.isNewVersion()) {
|
||||
DirectionUtil.setDirection(block, lib.getFace());
|
||||
DirectionUtil.setBisected(block, lib.getBisected());
|
||||
DirectionUtil.setSlabType(block, lib.getSlabtype());
|
||||
}
|
||||
lb = lift.getBlocks().first();
|
||||
for (Entity ent : Objects.requireNonNull(Bukkit.getWorld(lib.getWorld()), "World is null at MoveLift").getBlockAt(lib.getX(), lib.getY(), lib.getZ()).getChunk().getEntities()) {
|
||||
v10ent = new V10Entity(ent.getUniqueId(), null, 0, 0, 0, 0);
|
||||
if (lift.getToMove().contains(v10ent)) continue;
|
||||
loc = ent.getLocation();
|
||||
y = loc.getBlockY();
|
||||
if (y == lib.getY()) {
|
||||
by = true;
|
||||
} else if (y + 1 == lib.getY()) {
|
||||
by = true;
|
||||
y++;
|
||||
} else {
|
||||
by = false;
|
||||
DirectionUtil.setDirection(nextBlock, lib.getFace());
|
||||
DirectionUtil.setBisected(nextBlock, lib.getBisected());
|
||||
DirectionUtil.setSlabType(nextBlock, lib.getSlabtype());
|
||||
}
|
||||
|
||||
if (by && loc.getBlockX() == lib.getX() && loc.getBlockZ() == lib.getZ()) {
|
||||
loc.setY(loc.getY() + 1);
|
||||
if (direction == LiftDirection.UP) { //Teleportation is only required if we go up, for down gravity works fine. ;)
|
||||
for (Entity ent : nextBlock.getChunk().getEntities()) {
|
||||
V10Entity v10ent = new V10Entity(ent.getUniqueId(), null, 0, 0, 0, 0);
|
||||
if (lift.getToMove().contains(v10ent)) continue;
|
||||
|
||||
Location entLoc = ent.getLocation();
|
||||
if ((entLoc.getBlockY() == lib.getY() || entLoc.getBlockY() + 1 == lib.getY()) && entLoc.getBlockX() == lib.getX() && entLoc.getBlockZ() == lib.getZ()) {
|
||||
entLoc.setY(entLoc.getY() + 1);
|
||||
if (V10LiftPlugin.getSConfig().getFile().getBoolean("PacketTeleport")) {
|
||||
try {
|
||||
methods[1].invoke(methods[0].invoke(ent), loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
|
||||
methods[1].invoke(methods[0].invoke(ent), entLoc.getX(), entLoc.getY(), entLoc.getZ(), entLoc.getYaw(), entLoc.getPitch());
|
||||
} catch (Exception ex) {
|
||||
Bukkit.getLogger().severe("[V10Lift] PacketTeleportation is enabled, but couldn't get the method.");
|
||||
}
|
||||
} else {
|
||||
ent.teleport(loc);
|
||||
ent.teleport(entLoc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
veiter = lift.getToMove().iterator();
|
||||
while (veiter.hasNext()) {
|
||||
v10ent = veiter.next();
|
||||
}
|
||||
|
||||
Iterator<V10Entity> toMoveIterator = lift.getToMove().iterator();
|
||||
while (toMoveIterator.hasNext()) {
|
||||
V10Entity v10ent = toMoveIterator.next();
|
||||
if (v10ent.getStep() > 0) {
|
||||
v10ent.moveUp();
|
||||
if (direction == LiftDirection.UP) v10ent.moveUp(); else v10ent.moveDown();
|
||||
if (v10ent.getStep() > 16) {
|
||||
veiter.remove();
|
||||
toMoveIterator.remove();
|
||||
}
|
||||
}
|
||||
v10ent.setStep((short) (v10ent.getStep() + 1));
|
||||
}
|
||||
for (LiftBlock lib : tb) {
|
||||
block = Objects.requireNonNull(Bukkit.getWorld(lib.getWorld()), "World is null at MoveLift").getBlockAt(lib.getX(), lib.getY(), lib.getZ());
|
||||
BlockState state = block.getState();
|
||||
|
||||
for (LiftBlock lib : antiCopyBlocks) {
|
||||
Block block = Bukkit.getWorld(lib.getWorld()).getBlockAt(lib.getX(), lib.getY(), lib.getZ());
|
||||
if (lib.getMat() == null) lib.setMat(Material.AIR);
|
||||
|
||||
BlockState state = block.getState();
|
||||
state.setType(lib.getMat());
|
||||
if (!XMaterial.isNewVersion()) {
|
||||
state.setRawData(lib.getData());
|
||||
}
|
||||
state.update(true);
|
||||
|
||||
if (XMaterial.isNewVersion()) {
|
||||
DirectionUtil.setDirection(block, lib.getFace());
|
||||
DirectionUtil.setBisected(block, lib.getBisected());
|
||||
DirectionUtil.setSlabType(block, lib.getSlabtype());
|
||||
}
|
||||
|
||||
lift.getBlocks().add(lib);
|
||||
|
||||
if (lib.getSignLines() != null) {
|
||||
bs = block.getState();
|
||||
BlockState bs = block.getState();
|
||||
if (bs instanceof Sign) {
|
||||
sign = (Sign) bs;
|
||||
Sign sign = (Sign) bs;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
sign.setLine(i, lib.getSignLines()[i]);
|
||||
if (i == 0 && lib.getSignLines()[i].equalsIgnoreCase(ConfigUtil.getConfigText("SignText")) && lib.getSignLines()[1].equals(liftName)) {
|
||||
sign.setLine(1, liftName);
|
||||
sign.setLine(3, ChatColor.GOLD + fl);
|
||||
sign.setLine(3, ChatColor.GOLD + floorName);
|
||||
}
|
||||
}
|
||||
sign.update();
|
||||
|
@ -296,155 +291,55 @@ public class MoveLift implements Runnable {
|
|||
}
|
||||
}
|
||||
|
||||
lift.setY(lift.getY() + 1);
|
||||
Iterator<LiftSign> liter = lift.getSigns().iterator();
|
||||
while (liter.hasNext()) {
|
||||
ls = liter.next();
|
||||
if (ls.getState() == 1) continue;
|
||||
block = Objects.requireNonNull(Bukkit.getWorld(ls.getWorld()), "World is null at MoveLift").getBlockAt(ls.getX(), ls.getY(), ls.getZ());
|
||||
bs = block.getState();
|
||||
lift.setY(direction == LiftDirection.UP ? lift.getY() + 1 : lift.getY() - 1);
|
||||
|
||||
int signState = direction == LiftDirection.UP ? 1 : 2;
|
||||
|
||||
Iterator<LiftSign> signIterator = lift.getSigns().iterator();
|
||||
while (signIterator.hasNext()) {
|
||||
LiftSign ls = signIterator.next();
|
||||
if (ls.getState() == signState) continue;
|
||||
|
||||
Block block = Bukkit.getWorld(ls.getWorld()).getBlockAt(ls.getX(), ls.getY(), ls.getZ());
|
||||
BlockState bs = block.getState();
|
||||
if (!(bs instanceof Sign)) {
|
||||
Bukkit.getLogger().severe("[V10Lift] Wrong sign removed at: " + LocationSerializer.serialize(block.getLocation()));
|
||||
liter.remove();
|
||||
signIterator.remove();
|
||||
continue;
|
||||
}
|
||||
sign = (Sign) bs;
|
||||
|
||||
Sign sign = (Sign) bs;
|
||||
if (ls.getType() == 0) {
|
||||
sign.setLine(3, ConfigUtil.getConfigText("UpText"));
|
||||
String text = direction == LiftDirection.UP ? ConfigUtil.getConfigText("UpText") : ConfigUtil.getConfigText("DownText");
|
||||
sign.setLine(3, text);
|
||||
} else {
|
||||
sign.setLine(3, ChatColor.GRAY + ChatColor.stripColor(sign.getLine(3)));
|
||||
}
|
||||
sign.update();
|
||||
ls.setState((byte) 1);
|
||||
}
|
||||
} else if (down) {
|
||||
if (!V10LiftPlugin.getAPI().closeDoor(liftName)) return;
|
||||
|
||||
iter = lift.getBlocks().iterator();
|
||||
while (iter.hasNext()) {
|
||||
lb = iter.next();
|
||||
if (AntiCopyBlockManager.isAntiCopy(lb.getMat())) {
|
||||
tb.add(lb);
|
||||
iter.remove();
|
||||
block = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at MoveLift").getBlockAt(lb.getX(), lb.getY(), lb.getZ());
|
||||
block.setType(Material.AIR);
|
||||
lb.setY(lb.getY() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
for (LiftBlock lib : lift.getBlocks()) {
|
||||
block = Objects.requireNonNull(Bukkit.getWorld(lib.getWorld()), "World is null at MoveLift").getBlockAt(lib.getX(), lib.getY(), lib.getZ());
|
||||
if ((lib.getMat() == Material.CHEST || lib.getMat() == Material.TRAPPED_CHEST) && lib.serializedItemStacks == null) {
|
||||
c = (Chest) block.getState();
|
||||
inv = c.getInventory();
|
||||
isa = inv.getContents();
|
||||
by = false;
|
||||
lib.serializedItemStacks = new Map[isa.length];
|
||||
for (int i = 0; i < isa.length; i++) {
|
||||
is = isa[i];
|
||||
if (is != null) {
|
||||
by = true;
|
||||
lib.serializedItemStacks[i] = is.serialize();
|
||||
}
|
||||
}
|
||||
if (by) {
|
||||
inv.clear();
|
||||
c.update();
|
||||
} else {
|
||||
lib.serializedItemStacks = null;
|
||||
}
|
||||
}
|
||||
block.setType(Material.AIR);
|
||||
lib.setY(lib.getY() - 1);
|
||||
y = lib.getY();
|
||||
block = world.getBlockAt(lib.getX(), lib.getY(), lib.getZ());
|
||||
BlockState state = block.getState();
|
||||
if (lib.getMat() == null) lib.setMat(Material.AIR);
|
||||
state.setType(lib.getMat());
|
||||
if (!XMaterial.isNewVersion()) {
|
||||
state.setRawData(lib.getData());
|
||||
}
|
||||
state.update(true);
|
||||
if (XMaterial.isNewVersion()) {
|
||||
DirectionUtil.setDirection(block, lib.getFace());
|
||||
DirectionUtil.setBisected(block, lib.getBisected());
|
||||
DirectionUtil.setSlabType(block, lib.getSlabtype());
|
||||
}
|
||||
}
|
||||
veiter = lift.getToMove().iterator();
|
||||
while (veiter.hasNext()) {
|
||||
v10ent = veiter.next();
|
||||
if (v10ent.getStep() > 0) {
|
||||
v10ent.moveDown();
|
||||
if (v10ent.getStep() > 16) {
|
||||
veiter.remove();
|
||||
}
|
||||
}
|
||||
v10ent.setStep((short) (v10ent.getStep() + 1));
|
||||
}
|
||||
for (LiftBlock lib : tb) {
|
||||
block = Objects.requireNonNull(Bukkit.getWorld(lib.getWorld()), "World is null at MoveLift").getBlockAt(lib.getX(), lib.getY(), lib.getZ());
|
||||
BlockState state = block.getState();
|
||||
if (lib.getMat() == null) lib.setMat(Material.AIR);
|
||||
state.setType(lib.getMat());
|
||||
if (!XMaterial.isNewVersion()) {
|
||||
state.setRawData(lib.getData());
|
||||
}
|
||||
state.update(true);
|
||||
if (XMaterial.isNewVersion()) {
|
||||
DirectionUtil.setDirection(block, lib.getFace());
|
||||
DirectionUtil.setBisected(block, lib.getBisected());
|
||||
DirectionUtil.setSlabType(block, lib.getSlabtype());
|
||||
}
|
||||
lift.getBlocks().add(lib);
|
||||
if (lib.getSignLines() != null) {
|
||||
bs = block.getState();
|
||||
if (bs instanceof Sign) {
|
||||
sign = (Sign) bs;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
sign.setLine(i, lib.getSignLines()[i]);
|
||||
if (i == 0 && lib.getSignLines()[i].equalsIgnoreCase(ConfigUtil.getConfigText("SignText")) && lib.getSignLines()[1].equals(liftName)) {
|
||||
sign.setLine(1, liftName);
|
||||
sign.setLine(3, ChatColor.GOLD + fl);
|
||||
}
|
||||
}
|
||||
sign.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
lift.setY(lift.getY() - 1);
|
||||
Iterator<LiftSign> liter = lift.getSigns().iterator();
|
||||
while (liter.hasNext()) {
|
||||
ls = liter.next();
|
||||
if (ls.getState() == 2) continue;
|
||||
block = Objects.requireNonNull(Bukkit.getWorld(ls.getWorld()), "World is null at MoveLift").getBlockAt(ls.getX(), ls.getY(), ls.getZ());
|
||||
bs = block.getState();
|
||||
if (!(bs instanceof Sign)) {
|
||||
Bukkit.getLogger().severe("[V10Lift] Wrong sign removed at: " + LocationSerializer.serialize(block.getLocation()));
|
||||
liter.remove();
|
||||
continue;
|
||||
}
|
||||
sign = (Sign) bs;
|
||||
if (ls.getType() == 0) {
|
||||
sign.setLine(3, ConfigUtil.getConfigText("DownText"));
|
||||
} else {
|
||||
sign.setLine(3, ChatColor.GRAY + ChatColor.stripColor(sign.getLine(3)));
|
||||
}
|
||||
sign.update();
|
||||
ls.setState((byte) 2);
|
||||
ls.setState((byte) signState);
|
||||
}
|
||||
|
||||
if (direction == LiftDirection.DOWN) { //TODO Fix for down
|
||||
//MOVE ROPES
|
||||
for (LiftRope rope : lift.getRopes()) {
|
||||
boolean stopAfter = false;
|
||||
|
||||
if (rope.getCurrently() < rope.getMinY()) {
|
||||
Bukkit.getLogger().info("[V10Lift] Lift " + liftName + " reaches the upper rope end but won't stop!! 2");
|
||||
Bukkit.getLogger().info("[V10Lift] Lift " + liftName + " reaches the upper rope end but won't stop!!");
|
||||
|
||||
V10LiftPlugin.getAPI().setDefective(liftName, true);
|
||||
lift.getToMove().clear();
|
||||
quiter.remove();
|
||||
queueIterator.remove();
|
||||
|
||||
stopAfter = true;
|
||||
}
|
||||
|
||||
rope.setCurrently(rope.getCurrently() - 1);
|
||||
block = world.getBlockAt(rope.getX(), rope.getCurrently(), rope.getZ());
|
||||
|
||||
Block block = Bukkit.getWorld(rope.getWorld()).getBlockAt(rope.getX(), rope.getCurrently(), rope.getZ());
|
||||
if (rope.getType() == null) rope.setType(Material.AIR);
|
||||
|
||||
block.setType(rope.getType());
|
||||
if (XMaterial.isNewVersion()) {
|
||||
DirectionUtil.setDirection(block, rope.getFace());
|
||||
|
@ -455,71 +350,67 @@ public class MoveLift implements Runnable {
|
|||
state.setData(ladder);
|
||||
state.update(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
world = Objects.requireNonNull(Bukkit.getWorld(rope.getWorld()), "World is null at MoveLift");
|
||||
rope.setCurrently(rope.getCurrently() - 1);
|
||||
block = world.getBlockAt(rope.getX(), rope.getCurrently(), rope.getZ());
|
||||
if (rope.getType() == null) rope.setType(Material.AIR);
|
||||
block.setType(rope.getType());
|
||||
if (XMaterial.isNewVersion()) {
|
||||
DirectionUtil.setDirection(block, rope.getFace());
|
||||
} else {
|
||||
BlockState state = block.getState();
|
||||
org.bukkit.material.Ladder ladder = new org.bukkit.material.Ladder(rope.getType());
|
||||
ladder.setFacingDirection(rope.getFace());
|
||||
state.setData(ladder);
|
||||
state.update(true);
|
||||
|
||||
if (stopAfter) return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
lift.getToMove().clear();
|
||||
quiter.remove();
|
||||
bs = null;
|
||||
queueIterator.remove();
|
||||
|
||||
for (LiftBlock lib : lift.getBlocks()) {
|
||||
bs = Objects.requireNonNull(Bukkit.getWorld(lib.getWorld()), "World is null at MoveLift").getBlockAt(lib.getX(), lib.getY(), lib.getZ()).getState();
|
||||
BlockState bs = Bukkit.getWorld(lib.getWorld()).getBlockAt(lib.getX(), lib.getY(), lib.getZ()).getState();
|
||||
if (!(bs instanceof Sign)) {
|
||||
if (bs instanceof Chest && lib.serializedItemStacks != null) {
|
||||
isa = new ItemStack[lib.serializedItemStacks.length];
|
||||
by = false;
|
||||
ItemStack[] isa = new ItemStack[lib.serializedItemStacks.length];
|
||||
boolean by = false;
|
||||
|
||||
for (int i = 0; i < lib.serializedItemStacks.length; i++) {
|
||||
if (lib.serializedItemStacks[i] != null) {
|
||||
isa[i] = ItemStack.deserialize(lib.serializedItemStacks[i]);
|
||||
by = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (by) {
|
||||
c = (Chest) bs;
|
||||
Chest c = (Chest) bs;
|
||||
c.getInventory().setContents(isa);
|
||||
c.update();
|
||||
}
|
||||
|
||||
lib.serializedItemStacks = null;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
sign = (Sign) bs;
|
||||
|
||||
Sign sign = (Sign) bs;
|
||||
if (!sign.getLine(0).equalsIgnoreCase(ConfigUtil.getConfigText("SignText"))) continue;
|
||||
sign.setLine(1, liftName);
|
||||
sign.setLine(3, ChatColor.GREEN + fl);
|
||||
sign.setLine(3, ChatColor.GREEN + floorName);
|
||||
sign.update();
|
||||
}
|
||||
Iterator<LiftSign> liter = lift.getSigns().iterator();
|
||||
while (liter.hasNext()) {
|
||||
ls = liter.next();
|
||||
|
||||
Block block = null;
|
||||
|
||||
Iterator<LiftSign> signIterator = lift.getSigns().iterator();
|
||||
while (signIterator.hasNext()) {
|
||||
LiftSign ls = signIterator.next();
|
||||
if (ls.getState() == 0) continue;
|
||||
block = Objects.requireNonNull(Bukkit.getWorld(ls.getWorld()), "World is null at MoveLift").getBlockAt(ls.getX(), ls.getY(), ls.getZ());
|
||||
bs = block.getState();
|
||||
|
||||
block = Bukkit.getWorld(ls.getWorld()).getBlockAt(ls.getX(), ls.getY(), ls.getZ());
|
||||
BlockState bs = block.getState();
|
||||
if (!(bs instanceof Sign)) {
|
||||
Bukkit.getLogger().severe("[V10Lift] Wrong sign removed at: " + LocationSerializer.serialize(block.getLocation()));
|
||||
liter.remove();
|
||||
signIterator.remove();
|
||||
continue;
|
||||
}
|
||||
sign = (Sign) bs;
|
||||
|
||||
Sign sign = (Sign) bs;
|
||||
if (ls.getType() == 0) {
|
||||
sign.setLine(3, ChatColor.GREEN + fl);
|
||||
sign.setLine(3, ChatColor.GREEN + floorName);
|
||||
} else {
|
||||
String l3 = ChatColor.stripColor(sign.getLine(3));
|
||||
if (!fl.equals(l3)) {
|
||||
if (!floorName.equals(l3)) {
|
||||
sign.setLine(3, ChatColor.GRAY + l3);
|
||||
} else {
|
||||
sign.setLine(3, ChatColor.GREEN + l3);
|
||||
|
@ -528,18 +419,16 @@ public class MoveLift implements Runnable {
|
|||
sign.update();
|
||||
ls.setState((byte) 0);
|
||||
}
|
||||
V10LiftPlugin.getAPI().openDoor(lift, liftName, to);
|
||||
|
||||
V10LiftPlugin.getAPI().openDoor(lift, liftName, floorTo);
|
||||
|
||||
if (lift.isRealistic()) lift.setCounter(ft);
|
||||
if (lift.isSound()) {
|
||||
if (block != null) {
|
||||
loc = block.getLocation();
|
||||
XSound.ENTITY_EXPERIENCE_ORB_PICKUP.play(loc, 2.0F, 63.0F);
|
||||
}
|
||||
}
|
||||
|
||||
if (lift.isSound() && block != null) XSound.ENTITY_EXPERIENCE_ORB_PICKUP.play(block.getLocation(), 2.0F, 63.0F);
|
||||
}
|
||||
}
|
||||
|
||||
private void stopMe() {
|
||||
private void stop() {
|
||||
Bukkit.getServer().getScheduler().cancelTask(DataManager.getMovingTask(liftName));
|
||||
DataManager.removeMovingTask(liftName);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue