Added a lot of things!!
This commit is contained in:
parent
5b1ef5bfa9
commit
daacbe2eb4
9 changed files with 472 additions and 31 deletions
|
@ -2,36 +2,38 @@ package nl.SBDeveloper.V10Lift.API.Objects;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import nl.SBDeveloper.V10Lift.API.Runnables.DoorCloser;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class Lift {
|
public class Lift {
|
||||||
@Getter @Setter private String worldName;
|
@Getter @Setter private String worldName;
|
||||||
@Getter @Setter private int y;
|
@Getter @Setter private int y;
|
||||||
@Getter private ArrayList<UUID> owners;
|
@Getter private ArrayList<UUID> owners;
|
||||||
@Getter private ArrayList<String> whitelist;
|
@Getter private ArrayList<String> whitelist;
|
||||||
@Getter private ArrayList<LiftBlock> blocks;
|
@Getter private TreeSet<LiftBlock> blocks;
|
||||||
@Getter private LinkedHashMap<String, Floor> floors;
|
@Getter private LinkedHashMap<String, Floor> floors;
|
||||||
@Getter private ArrayList<LiftSign> signs;
|
@Getter private ArrayList<LiftSign> signs;
|
||||||
@Getter private ArrayList<LiftBlock> inputs;
|
@Getter private ArrayList<LiftBlock> inputs;
|
||||||
@Getter private ArrayList<LiftBlock> offlineInputs;
|
@Getter private ArrayList<LiftBlock> offlineInputs;
|
||||||
@Getter private LinkedHashMap<String, Floor> queue;
|
@Getter private LinkedHashMap<String, Floor> queue;
|
||||||
@Getter private ArrayList<LiftRope> ropes;
|
@Getter private ArrayList<LiftRope> ropes;
|
||||||
|
@Getter private ArrayList<V10Entity> toMove;
|
||||||
@Getter @Setter private int speed;
|
@Getter @Setter private int speed;
|
||||||
@Getter @Setter private boolean realistic;
|
@Getter @Setter private boolean realistic;
|
||||||
@Getter @Setter private boolean offline;
|
@Getter @Setter private boolean offline;
|
||||||
@Getter @Setter private boolean sound;
|
@Getter @Setter private boolean sound;
|
||||||
@Getter @Setter private boolean defective;
|
@Getter @Setter private boolean defective;
|
||||||
@Getter @Setter private String signText;
|
@Getter @Setter private String signText;
|
||||||
|
@Getter @Setter private int counter;
|
||||||
|
@Getter @Setter private Floor doorOpen;
|
||||||
|
@Getter @Setter private DoorCloser doorCloser;
|
||||||
|
|
||||||
public Lift(ArrayList<UUID> owners, int speed, boolean realistic) {
|
public Lift(ArrayList<UUID> owners, int speed, boolean realistic) {
|
||||||
this.owners = owners;
|
this.owners = owners;
|
||||||
this.speed = speed;
|
this.speed = speed;
|
||||||
this.realistic = realistic;
|
this.realistic = realistic;
|
||||||
this.blocks = new ArrayList<>();
|
this.blocks = new TreeSet<>();
|
||||||
this.signs = new ArrayList<>();
|
this.signs = new ArrayList<>();
|
||||||
this.whitelist = new ArrayList<>();
|
this.whitelist = new ArrayList<>();
|
||||||
this.floors = new LinkedHashMap<>();
|
this.floors = new LinkedHashMap<>();
|
||||||
|
@ -39,9 +41,11 @@ public class Lift {
|
||||||
this.offlineInputs = new ArrayList<>();
|
this.offlineInputs = new ArrayList<>();
|
||||||
this.queue = new LinkedHashMap<>();
|
this.queue = new LinkedHashMap<>();
|
||||||
this.ropes = new ArrayList<>();
|
this.ropes = new ArrayList<>();
|
||||||
|
this.toMove = new ArrayList<>();
|
||||||
this.offline = false;
|
this.offline = false;
|
||||||
this.sound = true;
|
this.sound = true;
|
||||||
this.defective = false;
|
this.defective = false;
|
||||||
|
this.counter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Lift(UUID owner, int speed, boolean realistic) {
|
public Lift(UUID owner, int speed, boolean realistic) {
|
||||||
|
|
|
@ -3,29 +3,27 @@ package nl.SBDeveloper.V10Lift.API.Objects;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.Map;
|
||||||
|
|
||||||
@Getter @Setter
|
|
||||||
public class LiftBlock implements Comparable<LiftBlock> {
|
public class LiftBlock implements Comparable<LiftBlock> {
|
||||||
|
|
||||||
private String world;
|
@Getter @Setter private String world;
|
||||||
private int x;
|
@Getter @Setter private int x;
|
||||||
private int y;
|
@Getter @Setter private int y;
|
||||||
private int z;
|
@Getter @Setter private int z;
|
||||||
|
|
||||||
//Only used for cabine blocks, because those need caching!
|
//Only used for cabine blocks, because those need caching!
|
||||||
private Material mat;
|
@Getter @Setter private Material mat;
|
||||||
private String[] signLines;
|
@Getter @Setter private String[] signLines;
|
||||||
|
|
||||||
//Only used for inputs!
|
//Only used for inputs!
|
||||||
private String floor;
|
@Getter @Setter private String floor;
|
||||||
private boolean active = false;
|
@Getter @Setter private boolean active = false;
|
||||||
|
|
||||||
//Only used for chests
|
//Only used for chests
|
||||||
private LinkedHashMap<Integer, ItemStack> chestContent = new LinkedHashMap<>();
|
public Map<String, Object>[] serializedItemStacks = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add lift block with material
|
* Add lift block with material
|
||||||
|
|
|
@ -1,14 +1,30 @@
|
||||||
package nl.SBDeveloper.V10Lift.API.Objects;
|
package nl.SBDeveloper.V10Lift.API.Objects;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import javafx.scene.paint.Material;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
@Getter @Setter @AllArgsConstructor
|
@Getter @Setter
|
||||||
public class LiftRope {
|
public class LiftRope {
|
||||||
private String world;
|
private final Material type;
|
||||||
private int x;
|
private final String startWorld;
|
||||||
private int z;
|
private final String endWorld;
|
||||||
private int minY;
|
private final int x;
|
||||||
private int maxY;
|
private final int minY;
|
||||||
|
private final int maxY;
|
||||||
|
private final int z;
|
||||||
|
private String currentWorld;
|
||||||
|
private int currently;
|
||||||
|
|
||||||
|
public LiftRope(Material type, String startWorld, String endWorld, int x, int minY, int maxY, int z) {
|
||||||
|
this.type = type;
|
||||||
|
this.startWorld = startWorld;
|
||||||
|
this.endWorld = endWorld;
|
||||||
|
this.x = x;
|
||||||
|
this.minY = minY;
|
||||||
|
this.maxY = maxY;
|
||||||
|
this.z = z;
|
||||||
|
this.currently = minY;
|
||||||
|
this.currentWorld = endWorld;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
package nl.SBDeveloper.V10Lift.API.Objects;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class V10Entity {
|
||||||
|
private final Entity e;
|
||||||
|
private final Location loc;
|
||||||
|
private final int y;
|
||||||
|
@Setter private short step;
|
||||||
|
|
||||||
|
public V10Entity(Entity e, Location loc, int y) {
|
||||||
|
this.e = e;
|
||||||
|
this.loc = loc;
|
||||||
|
this.y = y;
|
||||||
|
this.step = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void moveUp() {
|
||||||
|
if (e == null || e.isDead()) return;
|
||||||
|
loc.setY(y + step);
|
||||||
|
e.teleport(loc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void moveDown() {
|
||||||
|
if (e == null || e.isDead()) return;
|
||||||
|
loc.setY(y - step);
|
||||||
|
e.teleport(loc);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package nl.SBDeveloper.V10Lift.API.Runnables;
|
||||||
|
|
||||||
|
import nl.SBDeveloper.V10Lift.Managers.DataManager;
|
||||||
|
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
public class DoorCloser implements Runnable {
|
||||||
|
private final String liftName;
|
||||||
|
private int pid;
|
||||||
|
|
||||||
|
public DoorCloser(String liftName) {
|
||||||
|
this.liftName = liftName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (V10LiftPlugin.getAPI().closeDoor(liftName)) stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPid(int pid) {
|
||||||
|
this.pid = pid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop() {
|
||||||
|
Bukkit.getScheduler().cancelTask(pid);
|
||||||
|
if (DataManager.containsLift(liftName)) DataManager.getLift(liftName).setDoorCloser(null);
|
||||||
|
}
|
||||||
|
}
|
179
src/main/java/nl/SBDeveloper/V10Lift/API/Runnables/MoveLift.java
Normal file
179
src/main/java/nl/SBDeveloper/V10Lift/API/Runnables/MoveLift.java
Normal file
|
@ -0,0 +1,179 @@
|
||||||
|
package nl.SBDeveloper.V10Lift.API.Runnables;
|
||||||
|
|
||||||
|
import nl.SBDeveloper.V10Lift.API.Objects.Floor;
|
||||||
|
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.V10LiftPlugin;
|
||||||
|
import org.bukkit.*;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.Chest;
|
||||||
|
import org.bukkit.entity.Item;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class MoveLift implements Runnable {
|
||||||
|
|
||||||
|
private final String liftName;
|
||||||
|
private final long speed;
|
||||||
|
private final int ft;
|
||||||
|
|
||||||
|
public MoveLift(String liftName, long speed) {
|
||||||
|
this.liftName = liftName;
|
||||||
|
this.speed = speed;
|
||||||
|
|
||||||
|
if (speed > 32L) {
|
||||||
|
ft = 1;
|
||||||
|
} else if (speed > 16L) {
|
||||||
|
ft = 2;
|
||||||
|
} else if (speed > 8L) {
|
||||||
|
ft = 4;
|
||||||
|
} else if (speed > 4L) {
|
||||||
|
ft = 8;
|
||||||
|
} else if (speed > 2L) {
|
||||||
|
ft = 16;
|
||||||
|
} else if (speed > 1L) {
|
||||||
|
ft = 32;
|
||||||
|
} else {
|
||||||
|
ft = 64;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Lift lift = DataManager.getLift(liftName);
|
||||||
|
if (lift == null) {
|
||||||
|
stopMe();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lift.getQueue().isEmpty() || lift.isOffline()) {
|
||||||
|
stopMe();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DataManager.containsEditLift(liftName)) return;
|
||||||
|
|
||||||
|
if (lift.getCounter() > 0) {
|
||||||
|
lift.setCounter(lift.getCounter() - 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LiftBlock lb = lift.getBlocks().first();
|
||||||
|
World w = Bukkit.getWorld(lb.getWorld());
|
||||||
|
if (w == null) {
|
||||||
|
lift.setCounter(ft);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Location loc = new Location(w, lb.getX(), lb.getY(), lb.getZ());
|
||||||
|
if (!loc.getChunk().isLoaded()) {
|
||||||
|
lift.setCounter(ft);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO Add defaults to config (chanceOfDefect)
|
||||||
|
double changeOfDefect = 0.0D;
|
||||||
|
if (changeOfDefect > 0.0D) {
|
||||||
|
int 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chance < changeOfDefect) {
|
||||||
|
V10LiftPlugin.getAPI().setDefective(liftName, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<LiftBlock> tb = new ArrayList<>();
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
String tmpw = lift.getWorldName();
|
||||||
|
if (up) {
|
||||||
|
if (!V10LiftPlugin.getAPI().closeDoor(liftName)) return;
|
||||||
|
|
||||||
|
//MOVE ROPES
|
||||||
|
for (LiftRope rope : lift.getRopes()) {
|
||||||
|
if (rope.getCurrentWorld().equals(rope.getStartWorld()) && rope.getCurrently() > rope.getMaxY()) {
|
||||||
|
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();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Block block = Objects.requireNonNull(Bukkit.getWorld(rope.getCurrentWorld()), "World is null at MoveLift").getBlockAt(rope.getX(), rope.getCurrently(), rope.getZ());
|
||||||
|
block.setType(Material.AIR);
|
||||||
|
rope.setCurrently(rope.getCurrently() + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterator<LiftBlock> iter = lift.getBlocks().iterator();
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
LiftBlock lblock = iter.next();
|
||||||
|
if (V10LiftPlugin.getAPI().getACBM().isAntiCopy(lblock.getMat())) {
|
||||||
|
tb.add(lblock);
|
||||||
|
iter.remove();
|
||||||
|
Block block = Objects.requireNonNull(Bukkit.getWorld(lblock.getWorld()), "World is null at MoveLift").getBlockAt(lblock.getX(), lblock.getY(), lblock.getZ());
|
||||||
|
block.setType(Material.AIR);
|
||||||
|
lblock.setY(lblock.getY() + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean wc = false;
|
||||||
|
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());
|
||||||
|
if (lib.getMat() == Material.CHEST || lib.getMat() == Material.TRAPPED_CHEST && lib.serializedItemStacks == null) {
|
||||||
|
Chest c = (Chest) block.getState();
|
||||||
|
Inventory inv = c.getInventory();
|
||||||
|
ItemStack[] isa = inv.getContents();
|
||||||
|
boolean by = false;
|
||||||
|
lib.serializedItemStacks = new Map[isa.length];
|
||||||
|
for (int i = 0; i < isa.length; i++) {
|
||||||
|
ItemStack 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);
|
||||||
|
Block b = Objects.requireNonNull(Bukkit.getWorld(lib.getWorld()), "World is null at MoveLift").getBlockAt(lib.getX(), lib.getY(), lib.getZ());
|
||||||
|
b.setType(lib.getMat());
|
||||||
|
lb = lift.getBlocks().first();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void stopMe() {
|
||||||
|
Bukkit.getServer().getScheduler().cancelTask(DataManager.getMovingTask(liftName));
|
||||||
|
DataManager.removeMovingTask(liftName);
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,16 +4,17 @@ import nl.SBDeveloper.V10Lift.API.Objects.Floor;
|
||||||
import nl.SBDeveloper.V10Lift.API.Objects.Lift;
|
import nl.SBDeveloper.V10Lift.API.Objects.Lift;
|
||||||
import nl.SBDeveloper.V10Lift.API.Objects.LiftBlock;
|
import nl.SBDeveloper.V10Lift.API.Objects.LiftBlock;
|
||||||
import nl.SBDeveloper.V10Lift.API.Objects.LiftSign;
|
import nl.SBDeveloper.V10Lift.API.Objects.LiftSign;
|
||||||
|
import nl.SBDeveloper.V10Lift.API.Runnables.DoorCloser;
|
||||||
|
import nl.SBDeveloper.V10Lift.Managers.AntiCopyBlockManager;
|
||||||
import nl.SBDeveloper.V10Lift.Managers.DataManager;
|
import nl.SBDeveloper.V10Lift.Managers.DataManager;
|
||||||
import nl.SBDeveloper.V10Lift.Managers.ForbiddenBlockManager;
|
import nl.SBDeveloper.V10Lift.Managers.ForbiddenBlockManager;
|
||||||
import nl.SBDeveloper.V10Lift.Utils.LocationSerializer;
|
import nl.SBDeveloper.V10Lift.Utils.LocationSerializer;
|
||||||
import org.bukkit.Bukkit;
|
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.*;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
@ -22,15 +23,21 @@ import java.util.*;
|
||||||
public class V10LiftAPI {
|
public class V10LiftAPI {
|
||||||
/* Load managers... */
|
/* Load managers... */
|
||||||
private static ForbiddenBlockManager fbm;
|
private static ForbiddenBlockManager fbm;
|
||||||
|
private static AntiCopyBlockManager acbm;
|
||||||
|
|
||||||
public V10LiftAPI() {
|
public V10LiftAPI() {
|
||||||
fbm = new ForbiddenBlockManager();
|
fbm = new ForbiddenBlockManager();
|
||||||
|
acbm = new AntiCopyBlockManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ForbiddenBlockManager getFBM() {
|
public ForbiddenBlockManager getFBM() {
|
||||||
return fbm;
|
return fbm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AntiCopyBlockManager getACBM() {
|
||||||
|
return acbm;
|
||||||
|
}
|
||||||
|
|
||||||
/* Private API methods */
|
/* Private API methods */
|
||||||
private void sortFloors(@Nonnull Lift lift) {
|
private void sortFloors(@Nonnull Lift lift) {
|
||||||
ArrayList<Map.Entry<String, Floor>> as = new ArrayList<>(lift.getFloors().entrySet());
|
ArrayList<Map.Entry<String, Floor>> as = new ArrayList<>(lift.getFloors().entrySet());
|
||||||
|
@ -180,7 +187,7 @@ public class V10LiftAPI {
|
||||||
public void sortLiftBlocks(String liftName) {
|
public void sortLiftBlocks(String liftName) {
|
||||||
if (liftName != null && DataManager.containsLift(liftName)) {
|
if (liftName != null && DataManager.containsLift(liftName)) {
|
||||||
Lift lift = DataManager.getLift(liftName);
|
Lift lift = DataManager.getLift(liftName);
|
||||||
if (lift.getWorldName() == null) lift.setWorldName(lift.getBlocks().get(0).getWorld());
|
if (lift.getWorldName() == null) lift.setWorldName(lift.getBlocks().first().getWorld());
|
||||||
World world = Bukkit.getWorld(lift.getWorldName());
|
World world = Bukkit.getWorld(lift.getWorldName());
|
||||||
if (world == null) return;
|
if (world == null) return;
|
||||||
lift.setY(world.getMaxHeight());
|
lift.setY(world.getMaxHeight());
|
||||||
|
@ -193,6 +200,94 @@ public class V10LiftAPI {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean openDoor(String liftName) {
|
||||||
|
if (liftName == null || !DataManager.containsLift(liftName)) return false;
|
||||||
|
|
||||||
|
Lift lift = DataManager.getLift(liftName);
|
||||||
|
|
||||||
|
if (lift.getQueue() != null) return false;
|
||||||
|
|
||||||
|
Floor f = null;
|
||||||
|
for (Floor fl : lift.getFloors().values()) {
|
||||||
|
if (fl.getY() == lift.getY() && fl.getWorld().equals(lift.getWorldName())) {
|
||||||
|
f = fl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (f == null) return false;
|
||||||
|
|
||||||
|
if (lift.getDoorOpen() != null && !closeDoor(liftName)) return false;
|
||||||
|
|
||||||
|
for (LiftBlock lb : f.getDoorBlocks()) {
|
||||||
|
Block block = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at openDoor").getBlockAt(lb.getX(), lb.getY(), lb.getZ());
|
||||||
|
block.setType(Material.AIR);
|
||||||
|
}
|
||||||
|
|
||||||
|
lift.setDoorOpen(f);
|
||||||
|
|
||||||
|
if (lift.isRealistic()) {
|
||||||
|
lift.setDoorCloser(new DoorCloser(liftName));
|
||||||
|
//TODO Add defaults (doorclosetime) to config
|
||||||
|
long doorCloseTime = 5 * 20;
|
||||||
|
int pid = Bukkit.getScheduler().scheduleSyncRepeatingTask(V10LiftPlugin.getInstance(), lift.getDoorCloser(), doorCloseTime, doorCloseTime);
|
||||||
|
lift.getDoorCloser().setPid(pid);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close a lift door
|
||||||
|
*
|
||||||
|
* @param liftName The name of the lift
|
||||||
|
* @return true if door was closed, false if else.
|
||||||
|
*/
|
||||||
|
public boolean closeDoor(String liftName) {
|
||||||
|
if (liftName == null || !DataManager.containsLift(liftName)) return false;
|
||||||
|
|
||||||
|
Lift lift = DataManager.getLift(liftName);
|
||||||
|
|
||||||
|
boolean blocked = false;
|
||||||
|
if (lift.getDoorOpen() == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lift.isRealistic()) {
|
||||||
|
for (LiftBlock lb : lift.getDoorOpen().getDoorBlocks()) {
|
||||||
|
Block block = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at closeDoor").getBlockAt(lb.getX(), lb.getY(), lb.getZ());
|
||||||
|
for (Entity ent : block.getChunk().getEntities()) {
|
||||||
|
Location loc = ent.getLocation();
|
||||||
|
if (loc.getBlockX() == lb.getX() && loc.getBlockY() == lb.getY() && loc.getBlockZ() == lb.getZ()) {
|
||||||
|
blocked = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (blocked) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!blocked) {
|
||||||
|
for (LiftBlock lb : lift.getDoorOpen().getDoorBlocks()) {
|
||||||
|
Block block = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at closeDoor").getBlockAt(lb.getX(), lb.getY(), lb.getZ());
|
||||||
|
block.setType(lb.getMat(), true);
|
||||||
|
}
|
||||||
|
lift.setDoorOpen(null);
|
||||||
|
if (lift.getDoorCloser() != null) lift.getDoorCloser().stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
return !blocked;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To check if a lift has an open door.
|
||||||
|
*
|
||||||
|
* @param liftName The name of the lift
|
||||||
|
* @return true if open, false if else
|
||||||
|
*/
|
||||||
|
public boolean hasDoorOpen(String liftName) {
|
||||||
|
return (liftName != null && DataManager.containsLift(liftName)) && DataManager.getLift(liftName).getDoorOpen() != null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a new floor to a lift
|
* Adds a new floor to a lift
|
||||||
*
|
*
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
package nl.SBDeveloper.V10Lift.Managers;
|
||||||
|
|
||||||
|
import nl.SBDeveloper.V10Lift.Utils.XMaterial;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class AntiCopyBlockManager {
|
||||||
|
private ArrayList<XMaterial> antiCopy = new ArrayList<>();
|
||||||
|
|
||||||
|
public AntiCopyBlockManager() {
|
||||||
|
//TODO Add more anti copy materials
|
||||||
|
antiCopy.add(XMaterial.REDSTONE_TORCH);
|
||||||
|
antiCopy.add(XMaterial.REDSTONE_WALL_TORCH);
|
||||||
|
antiCopy.add(XMaterial.REPEATER);
|
||||||
|
antiCopy.add(XMaterial.COMPARATOR);
|
||||||
|
antiCopy.add(XMaterial.REDSTONE_WIRE);
|
||||||
|
antiCopy.add(XMaterial.ACACIA_BUTTON);
|
||||||
|
antiCopy.add(XMaterial.BIRCH_BUTTON);
|
||||||
|
antiCopy.add(XMaterial.DARK_OAK_BUTTON);
|
||||||
|
antiCopy.add(XMaterial.JUNGLE_BUTTON);
|
||||||
|
antiCopy.add(XMaterial.OAK_BUTTON);
|
||||||
|
antiCopy.add(XMaterial.SPRUCE_BUTTON);
|
||||||
|
antiCopy.add(XMaterial.STONE_BUTTON);
|
||||||
|
antiCopy.add(XMaterial.TORCH);
|
||||||
|
antiCopy.add(XMaterial.ACACIA_TRAPDOOR);
|
||||||
|
antiCopy.add(XMaterial.BIRCH_TRAPDOOR);
|
||||||
|
antiCopy.add(XMaterial.DARK_OAK_TRAPDOOR);
|
||||||
|
antiCopy.add(XMaterial.JUNGLE_TRAPDOOR);
|
||||||
|
antiCopy.add(XMaterial.OAK_TRAPDOOR);
|
||||||
|
antiCopy.add(XMaterial.SPRUCE_TRAPDOOR);
|
||||||
|
antiCopy.add(XMaterial.IRON_TRAPDOOR);
|
||||||
|
antiCopy.add(XMaterial.ACACIA_PRESSURE_PLATE);
|
||||||
|
antiCopy.add(XMaterial.BIRCH_PRESSURE_PLATE);
|
||||||
|
antiCopy.add(XMaterial.DARK_OAK_PRESSURE_PLATE);
|
||||||
|
antiCopy.add(XMaterial.JUNGLE_PRESSURE_PLATE);
|
||||||
|
antiCopy.add(XMaterial.OAK_PRESSURE_PLATE);
|
||||||
|
antiCopy.add(XMaterial.SPRUCE_PRESSURE_PLATE);
|
||||||
|
antiCopy.add(XMaterial.STONE_PRESSURE_PLATE);
|
||||||
|
antiCopy.add(XMaterial.HEAVY_WEIGHTED_PRESSURE_PLATE);
|
||||||
|
antiCopy.add(XMaterial.LIGHT_WEIGHTED_PRESSURE_PLATE);
|
||||||
|
antiCopy.add(XMaterial.ACACIA_SIGN);
|
||||||
|
antiCopy.add(XMaterial.BIRCH_SIGN);
|
||||||
|
antiCopy.add(XMaterial.DARK_OAK_SIGN);
|
||||||
|
antiCopy.add(XMaterial.JUNGLE_SIGN);
|
||||||
|
antiCopy.add(XMaterial.OAK_SIGN);
|
||||||
|
antiCopy.add(XMaterial.SPRUCE_SIGN);
|
||||||
|
antiCopy.add(XMaterial.ACACIA_WALL_SIGN);
|
||||||
|
antiCopy.add(XMaterial.BIRCH_WALL_SIGN);
|
||||||
|
antiCopy.add(XMaterial.DARK_OAK_WALL_SIGN);
|
||||||
|
antiCopy.add(XMaterial.JUNGLE_WALL_SIGN);
|
||||||
|
antiCopy.add(XMaterial.OAK_WALL_SIGN);
|
||||||
|
antiCopy.add(XMaterial.SPRUCE_WALL_SIGN);
|
||||||
|
antiCopy.add(XMaterial.RAIL);
|
||||||
|
antiCopy.add(XMaterial.POWERED_RAIL);
|
||||||
|
antiCopy.add(XMaterial.DETECTOR_RAIL);
|
||||||
|
antiCopy.add(XMaterial.ACTIVATOR_RAIL);
|
||||||
|
antiCopy.add(XMaterial.LADDER);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAntiCopy(Material mat) {
|
||||||
|
XMaterial xmat = XMaterial.matchXMaterial(mat);
|
||||||
|
return antiCopy.contains(xmat);
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ import nl.SBDeveloper.V10Lift.API.Objects.Lift;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ -21,6 +22,7 @@ public class DataManager {
|
||||||
private static ArrayList<UUID> ropeRemoves = new ArrayList<>();
|
private static ArrayList<UUID> ropeRemoves = new ArrayList<>();
|
||||||
private static ArrayList<UUID> doorEdits = new ArrayList<>();
|
private static ArrayList<UUID> doorEdits = new ArrayList<>();
|
||||||
private static ArrayList<UUID> whoisReq = new ArrayList<>();
|
private static ArrayList<UUID> whoisReq = new ArrayList<>();
|
||||||
|
private static HashMap<String, Integer> movingTasks = new HashMap<>();
|
||||||
|
|
||||||
/* HashMap methods */
|
/* HashMap methods */
|
||||||
|
|
||||||
|
@ -97,6 +99,10 @@ public class DataManager {
|
||||||
return editors.containsKey(player);
|
return editors.containsKey(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean containsEditLift(String liftName) {
|
||||||
|
return editors.containsValue(liftName);
|
||||||
|
}
|
||||||
|
|
||||||
public static void addEditPlayer(UUID player, String liftName) {
|
public static void addEditPlayer(UUID player, String liftName) {
|
||||||
editors.put(player, liftName);
|
editors.put(player, liftName);
|
||||||
}
|
}
|
||||||
|
@ -109,6 +115,23 @@ public class DataManager {
|
||||||
return editors.get(player);
|
return editors.get(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// //
|
||||||
|
public static void addMovingTask(String liftName, int taskid) {
|
||||||
|
movingTasks.put(liftName, taskid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeMovingTask(String liftName) {
|
||||||
|
movingTasks.remove(liftName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean containsMovingTask(String liftName) {
|
||||||
|
return movingTasks.containsKey(liftName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getMovingTask(String liftName) {
|
||||||
|
return movingTasks.get(liftName);
|
||||||
|
}
|
||||||
|
|
||||||
/* ArrayList methods */
|
/* ArrayList methods */
|
||||||
|
|
||||||
// //
|
// //
|
||||||
|
|
Loading…
Reference in a new issue