Move Up system done, down system WIP
This commit is contained in:
parent
daacbe2eb4
commit
75390dfd08
2 changed files with 148 additions and 33 deletions
|
@ -10,11 +10,15 @@ public class LiftSign {
|
||||||
private int z;
|
private int z;
|
||||||
private int y;
|
private int y;
|
||||||
private String oldText;
|
private String oldText;
|
||||||
|
private final byte type;
|
||||||
|
private byte state;
|
||||||
|
|
||||||
public LiftSign(String world, int x, int y, int z) {
|
public LiftSign(String world, int x, int y, int z, byte type, byte state) {
|
||||||
this.world = world;
|
this.world = world;
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
|
this.type = type;
|
||||||
|
this.state = state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
package nl.SBDeveloper.V10Lift.API.Runnables;
|
package nl.SBDeveloper.V10Lift.API.Runnables;
|
||||||
|
|
||||||
import nl.SBDeveloper.V10Lift.API.Objects.Floor;
|
import nl.SBDeveloper.V10Lift.API.Objects.*;
|
||||||
import nl.SBDeveloper.V10Lift.API.Objects.Lift;
|
|
||||||
import nl.SBDeveloper.V10Lift.API.Objects.LiftBlock;
|
|
||||||
import nl.SBDeveloper.V10Lift.API.Objects.LiftRope;
|
|
||||||
import nl.SBDeveloper.V10Lift.Managers.DataManager;
|
import nl.SBDeveloper.V10Lift.Managers.DataManager;
|
||||||
|
import nl.SBDeveloper.V10Lift.Utils.LocationSerializer;
|
||||||
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
|
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.block.Chest;
|
import org.bukkit.block.Chest;
|
||||||
|
import org.bukkit.block.Sign;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Item;
|
import org.bukkit.entity.Item;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
@ -44,7 +45,26 @@ public class MoveLift implements Runnable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Lift lift = DataManager.getLift(liftName);
|
Iterator < LiftBlock > iter;
|
||||||
|
ArrayList < LiftBlock > tb = new ArrayList < LiftBlock > ();
|
||||||
|
Block block;
|
||||||
|
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);
|
||||||
if (lift == null) {
|
if (lift == null) {
|
||||||
stopMe();
|
stopMe();
|
||||||
return;
|
return;
|
||||||
|
@ -55,21 +75,21 @@ public class MoveLift implements Runnable {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DataManager.containsEditLift(liftName)) return;
|
if (DataManager.containsEditLift(liftName) || lift.isDefective()) return;
|
||||||
|
|
||||||
if (lift.getCounter() > 0) {
|
if (lift.getCounter() > 0) {
|
||||||
lift.setCounter(lift.getCounter() - 1);
|
lift.setCounter(lift.getCounter() - 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LiftBlock lb = lift.getBlocks().first();
|
lb = lift.getBlocks().first();
|
||||||
World w = Bukkit.getWorld(lb.getWorld());
|
world = Bukkit.getWorld(lb.getWorld());
|
||||||
if (w == null) {
|
if (world == null) {
|
||||||
lift.setCounter(ft);
|
lift.setCounter(ft);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Location loc = new Location(w, lb.getX(), lb.getY(), lb.getZ());
|
loc = new Location(world, lb.getX(), lb.getY(), lb.getZ());
|
||||||
if (!loc.getChunk().isLoaded()) {
|
if (!loc.getChunk().isLoaded()) {
|
||||||
lift.setCounter(ft);
|
lift.setCounter(ft);
|
||||||
return;
|
return;
|
||||||
|
@ -78,7 +98,7 @@ public class MoveLift implements Runnable {
|
||||||
//TODO Add defaults to config (chanceOfDefect)
|
//TODO Add defaults to config (chanceOfDefect)
|
||||||
double changeOfDefect = 0.0D;
|
double changeOfDefect = 0.0D;
|
||||||
if (changeOfDefect > 0.0D) {
|
if (changeOfDefect > 0.0D) {
|
||||||
int y = new Random().nextInt(100);
|
y = new Random().nextInt(100);
|
||||||
double chance;
|
double chance;
|
||||||
if (y < 100) {
|
if (y < 100) {
|
||||||
long co = new Random().nextLong();
|
long co = new Random().nextLong();
|
||||||
|
@ -94,15 +114,12 @@ public class MoveLift implements Runnable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<LiftBlock> tb = new ArrayList<>();
|
|
||||||
|
|
||||||
Iterator < Map.Entry < String, Floor >> quiter = lift.getQueue().entrySet().iterator();
|
Iterator < Map.Entry < String, Floor >> quiter = lift.getQueue().entrySet().iterator();
|
||||||
Map.Entry < String, Floor > floor = quiter.next();
|
Map.Entry < String, Floor > floor = quiter.next();
|
||||||
Floor to = floor.getValue();
|
Floor to = floor.getValue();
|
||||||
String fl = floor.getKey();
|
String fl = floor.getKey();
|
||||||
boolean up = false;
|
boolean up = false;
|
||||||
boolean down = false;
|
boolean down = false;
|
||||||
|
|
||||||
if (lift.getY() < to.getY()) {
|
if (lift.getY() < to.getY()) {
|
||||||
up = true;
|
up = true;
|
||||||
} else if (lift.getY() > to.getY()) {
|
} else if (lift.getY() > to.getY()) {
|
||||||
|
@ -122,34 +139,36 @@ public class MoveLift implements Runnable {
|
||||||
quiter.remove();
|
quiter.remove();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Block block = Objects.requireNonNull(Bukkit.getWorld(rope.getCurrentWorld()), "World is null at MoveLift").getBlockAt(rope.getX(), rope.getCurrently(), rope.getZ());
|
world = Objects.requireNonNull(Bukkit.getWorld(rope.getCurrentWorld()), "World is null at MoveLift");
|
||||||
|
block = world.getBlockAt(rope.getX(), rope.getCurrently(), rope.getZ());
|
||||||
block.setType(Material.AIR);
|
block.setType(Material.AIR);
|
||||||
rope.setCurrently(rope.getCurrently() + 1);
|
rope.setCurrently(rope.getCurrently() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator<LiftBlock> iter = lift.getBlocks().iterator();
|
iter = lift.getBlocks().iterator();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
LiftBlock lblock = iter.next();
|
lb = iter.next();
|
||||||
if (V10LiftPlugin.getAPI().getACBM().isAntiCopy(lblock.getMat())) {
|
if (V10LiftPlugin.getAPI().getACBM().isAntiCopy(lb.getMat())) {
|
||||||
tb.add(lblock);
|
tb.add(lb);
|
||||||
iter.remove();
|
iter.remove();
|
||||||
Block block = Objects.requireNonNull(Bukkit.getWorld(lblock.getWorld()), "World is null at MoveLift").getBlockAt(lblock.getX(), lblock.getY(), lblock.getZ());
|
block = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at MoveLift").getBlockAt(lb.getX(), lb.getY(), lb.getZ());
|
||||||
block.setType(Material.AIR);
|
block.setType(Material.AIR);
|
||||||
lblock.setY(lblock.getY() + 1);
|
lb.setY(lb.getY() + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean wc = false;
|
boolean wc = false;
|
||||||
for (LiftBlock lib : lift.getBlocks().descendingSet()) {
|
for (LiftBlock lib : lift.getBlocks().descendingSet()) {
|
||||||
Block block = Objects.requireNonNull(Bukkit.getWorld(lib.getWorld()), "World is null at MoveLift").getBlockAt(lib.getX(), lib.getY(), lib.getZ());
|
world = Objects.requireNonNull(Bukkit.getWorld(lib.getWorld()), "World is null at MoveLift");
|
||||||
if (lib.getMat() == Material.CHEST || lib.getMat() == Material.TRAPPED_CHEST && lib.serializedItemStacks == null) {
|
block = world.getBlockAt(lib.getX(), lib.getY(), lib.getZ());
|
||||||
Chest c = (Chest) block.getState();
|
if ((lib.getMat() == Material.CHEST || lib.getMat() == Material.TRAPPED_CHEST) && lib.serializedItemStacks == null) {
|
||||||
Inventory inv = c.getInventory();
|
c = (Chest) block.getState();
|
||||||
ItemStack[] isa = inv.getContents();
|
inv = c.getInventory();
|
||||||
boolean by = false;
|
isa = inv.getContents();
|
||||||
|
by = false;
|
||||||
lib.serializedItemStacks = new Map[isa.length];
|
lib.serializedItemStacks = new Map[isa.length];
|
||||||
for (int i = 0; i < isa.length; i++) {
|
for (int i = 0; i < isa.length; i++) {
|
||||||
ItemStack is = isa[i];
|
is = isa[i];
|
||||||
if (is != null) {
|
if (is != null) {
|
||||||
by = true;
|
by = true;
|
||||||
lib.serializedItemStacks[i] = is.serialize();
|
lib.serializedItemStacks[i] = is.serialize();
|
||||||
|
@ -165,9 +184,101 @@ public class MoveLift implements Runnable {
|
||||||
|
|
||||||
block.setType(Material.AIR);
|
block.setType(Material.AIR);
|
||||||
lib.setY(lib.getY() + 1);
|
lib.setY(lib.getY() + 1);
|
||||||
Block b = Objects.requireNonNull(Bukkit.getWorld(lib.getWorld()), "World is null at MoveLift").getBlockAt(lib.getX(), lib.getY(), lib.getZ());
|
block = Objects.requireNonNull(Bukkit.getWorld(lib.getWorld()), "World is null at MoveLift").getBlockAt(lib.getX(), lib.getY(), lib.getZ());
|
||||||
b.setType(lib.getMat());
|
block.setType(lib.getMat());
|
||||||
lb = lift.getBlocks().first();
|
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, null, 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (by && loc.getBlockX() == lib.getX() && loc.getBlockZ() == lib.getZ()) {
|
||||||
|
loc.setY(loc.getY() + 1);
|
||||||
|
ent.teleport(loc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
veiter = lift.getToMove().iterator();
|
||||||
|
while (veiter.hasNext()) {
|
||||||
|
v10ent = veiter.next();
|
||||||
|
if (v10ent.getStep() > 0) {
|
||||||
|
v10ent.moveUp();
|
||||||
|
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());
|
||||||
|
block.setType(lib.getMat(), true);
|
||||||
|
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("[v10lift]") && 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() == 1) 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, ChatColor.GREEN + "up");
|
||||||
|
} 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 (V10LiftPlugin.getAPI().getACBM().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) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue