parent
4ffd4a45eb
commit
c03a7ee5b7
6 changed files with 121 additions and 59 deletions
|
@ -470,14 +470,14 @@ public class V10LiftAPI {
|
||||||
lift.getFloors().remove(oldName);
|
lift.getFloors().remove(oldName);
|
||||||
lift.getFloors().put(newName, f);
|
lift.getFloors().put(newName, f);
|
||||||
sortFloors(lift);
|
sortFloors(lift);
|
||||||
Iterator<LiftBlock> liter = lift.getInputs().iterator();
|
Iterator<LiftInput> liter = lift.getInputs().iterator();
|
||||||
LiftBlock lb;
|
LiftInput lb;
|
||||||
ArrayList<LiftBlock> newBlocks = new ArrayList<>();
|
ArrayList<LiftInput> newBlocks = new ArrayList<>();
|
||||||
while (liter.hasNext()) {
|
while (liter.hasNext()) {
|
||||||
lb = liter.next();
|
lb = liter.next();
|
||||||
if (lb.getFloor().equals(oldName)) {
|
if (lb.getFloor().equals(oldName)) {
|
||||||
liter.remove();
|
liter.remove();
|
||||||
newBlocks.add(new LiftBlock(lb.getWorld(), lb.getX(), lb.getY(), lb.getZ(), newName));
|
newBlocks.add(new LiftInput(lb.getWorld(), lb.getX(), lb.getY(), lb.getZ(), newName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
newBlocks.forEach(nlb -> lift.getInputs().add(nlb));
|
newBlocks.forEach(nlb -> lift.getInputs().add(nlb));
|
||||||
|
|
|
@ -23,8 +23,8 @@ public class Lift {
|
||||||
private final TreeSet<LiftBlock> blocks = new TreeSet<>();
|
private final TreeSet<LiftBlock> blocks = new TreeSet<>();
|
||||||
private final LinkedHashMap<String, Floor> floors = new LinkedHashMap<>();
|
private final LinkedHashMap<String, Floor> floors = new LinkedHashMap<>();
|
||||||
private final HashSet<LiftSign> signs = new HashSet<>();
|
private final HashSet<LiftSign> signs = new HashSet<>();
|
||||||
private final HashSet<LiftBlock> inputs = new HashSet<>();
|
private final HashSet<LiftInput> inputs = new HashSet<>();
|
||||||
private final HashSet<LiftBlock> offlineInputs = new HashSet<>();
|
private final HashSet<LiftInput> offlineInputs = new HashSet<>();
|
||||||
@Setter
|
@Setter
|
||||||
private LinkedHashMap<String, Floor> queue = null;
|
private LinkedHashMap<String, Floor> queue = null;
|
||||||
private final HashSet<LiftRope> ropes = new HashSet<>();
|
private final HashSet<LiftRope> ropes = new HashSet<>();
|
||||||
|
|
|
@ -37,37 +37,8 @@ public class LiftBlock implements Comparable<LiftBlock> {
|
||||||
private String[] signLines;
|
private String[] signLines;
|
||||||
@Setter
|
@Setter
|
||||||
private Boolean open;
|
private Boolean open;
|
||||||
|
//Used for chests
|
||||||
//Only used for inputs!
|
public Map<String, Object>[] serializedItemStacks;
|
||||||
private String floor;
|
|
||||||
@Setter
|
|
||||||
private boolean active = false;
|
|
||||||
|
|
||||||
//Only used for chests
|
|
||||||
public Map<String, Object>[] serializedItemStacks = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a floor based liftblock, without material (no caching)
|
|
||||||
*
|
|
||||||
* @param world The world
|
|
||||||
* @param x The x-pos
|
|
||||||
* @param y The y-pos
|
|
||||||
* @param z The z-pos
|
|
||||||
* @param floor The floorname of the block
|
|
||||||
*/
|
|
||||||
public LiftBlock(String world, int x, int y, int z, String floor) {
|
|
||||||
this.world = world;
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.z = z;
|
|
||||||
this.mat = null;
|
|
||||||
this.face = null;
|
|
||||||
this.signLines = null;
|
|
||||||
this.floor = floor;
|
|
||||||
this.bisected = null;
|
|
||||||
this.slabType = null;
|
|
||||||
this.open = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new liftblock from a block
|
* Create a new liftblock from a block
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
package tech.sbdevelopment.v10lift.api.objects;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A lift input object
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@ToString
|
||||||
|
public class LiftInput implements Comparable<LiftInput> {
|
||||||
|
private String world;
|
||||||
|
private int x;
|
||||||
|
private int y;
|
||||||
|
private int z;
|
||||||
|
|
||||||
|
private String floor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new lift input
|
||||||
|
*
|
||||||
|
* @param world The world
|
||||||
|
* @param x The x-pos
|
||||||
|
* @param y The y-pos
|
||||||
|
* @param z The z-pos
|
||||||
|
* @param floor The floor
|
||||||
|
*/
|
||||||
|
public LiftInput(String world, int x, int y, int z, String floor) {
|
||||||
|
this.world = world;
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.z = z;
|
||||||
|
this.floor = floor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(@Nonnull LiftInput lb) {
|
||||||
|
int ret = Integer.compare(y, lb.y);
|
||||||
|
if (ret == 0) ret = Integer.compare(x, lb.x);
|
||||||
|
if (ret == 0) ret = Integer.compare(z, lb.z);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof LiftInput)) return false;
|
||||||
|
LiftInput other = (LiftInput) o;
|
||||||
|
return world.equals(other.world) &&
|
||||||
|
x == other.x &&
|
||||||
|
y == other.y &&
|
||||||
|
z == other.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + ((world == null) ? 0 : world.hashCode());
|
||||||
|
result = prime * result + x;
|
||||||
|
result = prime * result + y;
|
||||||
|
result = prime * result + z;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,6 +11,7 @@ import tech.sbdevelopment.v10lift.api.V10LiftAPI;
|
||||||
import tech.sbdevelopment.v10lift.api.objects.Floor;
|
import tech.sbdevelopment.v10lift.api.objects.Floor;
|
||||||
import tech.sbdevelopment.v10lift.api.objects.Lift;
|
import tech.sbdevelopment.v10lift.api.objects.Lift;
|
||||||
import tech.sbdevelopment.v10lift.api.objects.LiftBlock;
|
import tech.sbdevelopment.v10lift.api.objects.LiftBlock;
|
||||||
|
import tech.sbdevelopment.v10lift.api.objects.LiftInput;
|
||||||
import tech.sbdevelopment.v10lift.managers.DataManager;
|
import tech.sbdevelopment.v10lift.managers.DataManager;
|
||||||
import tech.sbdevelopment.v10lift.utils.ConfigUtil;
|
import tech.sbdevelopment.v10lift.utils.ConfigUtil;
|
||||||
import tech.sbdevelopment.v10lift.utils.DoorUtil;
|
import tech.sbdevelopment.v10lift.utils.DoorUtil;
|
||||||
|
@ -28,7 +29,7 @@ public class BlockBreakListener implements Listener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LiftBlock tlb = new LiftBlock(b.getWorld().getName(), b.getX(), b.getY(), b.getZ(), (String) null);
|
LiftBlock tlb = new LiftBlock(b);
|
||||||
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
|
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
|
||||||
Lift lift = entry.getValue();
|
Lift lift = entry.getValue();
|
||||||
if (lift.getBlocks().contains(tlb)) {
|
if (lift.getBlocks().contains(tlb)) {
|
||||||
|
|
|
@ -8,6 +8,8 @@ import org.bukkit.Material;
|
||||||
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.block.data.BlockData;
|
||||||
|
import org.bukkit.block.data.Powerable;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
|
@ -22,6 +24,7 @@ import tech.sbdevelopment.v10lift.api.V10LiftAPI;
|
||||||
import tech.sbdevelopment.v10lift.api.objects.Floor;
|
import tech.sbdevelopment.v10lift.api.objects.Floor;
|
||||||
import tech.sbdevelopment.v10lift.api.objects.Lift;
|
import tech.sbdevelopment.v10lift.api.objects.Lift;
|
||||||
import tech.sbdevelopment.v10lift.api.objects.LiftBlock;
|
import tech.sbdevelopment.v10lift.api.objects.LiftBlock;
|
||||||
|
import tech.sbdevelopment.v10lift.api.objects.LiftInput;
|
||||||
import tech.sbdevelopment.v10lift.managers.DataManager;
|
import tech.sbdevelopment.v10lift.managers.DataManager;
|
||||||
import tech.sbdevelopment.v10lift.managers.ForbiddenBlockManager;
|
import tech.sbdevelopment.v10lift.managers.ForbiddenBlockManager;
|
||||||
import tech.sbdevelopment.v10lift.managers.VaultManager;
|
import tech.sbdevelopment.v10lift.managers.VaultManager;
|
||||||
|
@ -42,31 +45,47 @@ public class PlayerInteractListener implements Listener {
|
||||||
Material button = block.getType();
|
Material button = block.getType();
|
||||||
|
|
||||||
if (action == Action.RIGHT_CLICK_BLOCK
|
if (action == Action.RIGHT_CLICK_BLOCK
|
||||||
&& e.getHand() != EquipmentSlot.OFF_HAND
|
&& e.getHand() != EquipmentSlot.OFF_HAND) {
|
||||||
&& (button.toString().contains("BUTTON") || button == XMaterial.LEVER.parseMaterial())) {
|
|
||||||
String world = block.getWorld().getName();
|
String world = block.getWorld().getName();
|
||||||
int x = block.getX();
|
int x = block.getX();
|
||||||
int y = block.getY();
|
int y = block.getY();
|
||||||
int z = block.getZ();
|
int z = block.getZ();
|
||||||
|
|
||||||
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
|
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
|
||||||
Lift lift = entry.getValue();
|
Lift lift = entry.getValue();
|
||||||
for (LiftBlock lb : lift.getOfflineInputs()) {
|
|
||||||
if (world.equals(lb.getWorld()) && x == lb.getX() && y == lb.getY() && z == lb.getZ()) {
|
for (LiftInput lbi : lift.getOfflineInputs()) {
|
||||||
lb.setActive(!lb.isActive());
|
if (world.equals(lbi.getWorld()) && x == lbi.getX() && y == lbi.getY() && z == lbi.getZ()) {
|
||||||
V10LiftAPI.getInstance().setOffline(entry.getKey(), lb.isActive());
|
boolean newState = !lift.isOffline();
|
||||||
return;
|
V10LiftAPI.getInstance().setOffline(entry.getKey(), newState);
|
||||||
|
|
||||||
|
//Update all offline inputs
|
||||||
|
for (LiftInput li : lift.getOfflineInputs()) {
|
||||||
|
Block b = Bukkit.getWorld(li.getWorld()).getBlockAt(li.getX(), li.getY(), li.getZ());
|
||||||
|
BlockData bd = b.getBlockData();
|
||||||
|
if (!(bd instanceof Powerable)) {
|
||||||
|
Bukkit.getLogger().warning("[V10Lift] Block at " + li.getX() + ", " + li.getY() + ", " + li.getZ() + " is not powerable, while it should be an offline input of " + entry.getKey() + "!");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
((Powerable) bd).setPowered(newState);
|
||||||
|
b.setBlockData(bd);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lift.isOffline()) return;
|
if (lift.isOffline()) break;
|
||||||
|
|
||||||
for (LiftBlock lb : lift.getInputs()) {
|
for (LiftInput lbi : lift.getInputs()) {
|
||||||
if (world.equals(lb.getWorld()) && x == lb.getX() && y == lb.getY() && z == lb.getZ()) {
|
if (world.equals(lbi.getWorld()) && x == lbi.getX() && y == lbi.getY() && z == lbi.getZ()) {
|
||||||
V10LiftAPI.getInstance().addToQueue(entry.getKey(), lift.getFloors().get(lb.getFloor()), lb.getFloor());
|
V10LiftAPI.getInstance().addToQueue(entry.getKey(), lift.getFloors().get(lbi.getFloor()), lbi.getFloor());
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,7 +123,7 @@ public class PlayerInteractListener implements Listener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lift.getBlocks().contains(new LiftBlock(sign.getWorld().getName(), sign.getX(), sign.getY(), sign.getZ(), (String) null)))
|
if (!lift.getBlocks().contains(new LiftBlock(sign.getBlock())))
|
||||||
return;
|
return;
|
||||||
if (DataManager.containsEditLift(liftName)) return;
|
if (DataManager.containsEditLift(liftName)) return;
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
|
@ -160,7 +179,7 @@ public class PlayerInteractListener implements Listener {
|
||||||
} else if (DataManager.containsInputEditsPlayer(p.getUniqueId())) {
|
} else if (DataManager.containsInputEditsPlayer(p.getUniqueId())) {
|
||||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||||
Block block = e.getClickedBlock();
|
Block block = e.getClickedBlock();
|
||||||
LiftBlock tlb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), DataManager.getInputEditsPlayer(p.getUniqueId()));
|
LiftInput tlb = new LiftInput(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), DataManager.getInputEditsPlayer(p.getUniqueId()));
|
||||||
Lift lift = DataManager.getLift(DataManager.getEditPlayer(p.getUniqueId()));
|
Lift lift = DataManager.getLift(DataManager.getEditPlayer(p.getUniqueId()));
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
if (lift.getInputs().contains(tlb)) {
|
if (lift.getInputs().contains(tlb)) {
|
||||||
|
@ -173,7 +192,7 @@ public class PlayerInteractListener implements Listener {
|
||||||
} else if (DataManager.containsOfflineEditsPlayer(p.getUniqueId())) {
|
} else if (DataManager.containsOfflineEditsPlayer(p.getUniqueId())) {
|
||||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||||
Block block = e.getClickedBlock();
|
Block block = e.getClickedBlock();
|
||||||
LiftBlock tlb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), (String) null);
|
LiftInput tlb = new LiftInput(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), null);
|
||||||
Lift lift = DataManager.getLift(DataManager.getEditPlayer(p.getUniqueId()));
|
Lift lift = DataManager.getLift(DataManager.getEditPlayer(p.getUniqueId()));
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
if (lift.getOfflineInputs().contains(tlb)) {
|
if (lift.getOfflineInputs().contains(tlb)) {
|
||||||
|
@ -186,7 +205,7 @@ public class PlayerInteractListener implements Listener {
|
||||||
} else if (DataManager.containsInputRemovesPlayer(p.getUniqueId())) {
|
} else if (DataManager.containsInputRemovesPlayer(p.getUniqueId())) {
|
||||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||||
Block block = e.getClickedBlock();
|
Block block = e.getClickedBlock();
|
||||||
LiftBlock tlb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), (String) null);
|
LiftInput tlb = new LiftInput(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), null);
|
||||||
Lift lift = DataManager.getLift(DataManager.getEditPlayer(p.getUniqueId()));
|
Lift lift = DataManager.getLift(DataManager.getEditPlayer(p.getUniqueId()));
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
if (lift.getInputs().contains(tlb)) {
|
if (lift.getInputs().contains(tlb)) {
|
||||||
|
@ -199,7 +218,7 @@ public class PlayerInteractListener implements Listener {
|
||||||
} else if (DataManager.containsOfflineRemovesPlayer(p.getUniqueId())) {
|
} else if (DataManager.containsOfflineRemovesPlayer(p.getUniqueId())) {
|
||||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||||
Block block = e.getClickedBlock();
|
Block block = e.getClickedBlock();
|
||||||
LiftBlock tlb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), (String) null);
|
LiftInput tlb = new LiftInput(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), null);
|
||||||
Lift lift = DataManager.getLift(DataManager.getEditPlayer(p.getUniqueId()));
|
Lift lift = DataManager.getLift(DataManager.getEditPlayer(p.getUniqueId()));
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
if (lift.getOfflineInputs().contains(tlb)) {
|
if (lift.getOfflineInputs().contains(tlb)) {
|
||||||
|
@ -234,8 +253,8 @@ public class PlayerInteractListener implements Listener {
|
||||||
Block now = e.getClickedBlock();
|
Block now = e.getClickedBlock();
|
||||||
if (start == null) {
|
if (start == null) {
|
||||||
ConfigUtil.sendMessage(e.getPlayer(), "Rope.ClickOnEnd");
|
ConfigUtil.sendMessage(e.getPlayer(), "Rope.ClickOnEnd");
|
||||||
DataManager.addRopeEditPlayer(p.getUniqueId(), new LiftBlock(now.getWorld().getName(), now.getX(), now.getY(), now.getZ(), (String) null));
|
DataManager.addRopeEditPlayer(p.getUniqueId(), new LiftBlock(now));
|
||||||
} else if (start.equals(new LiftBlock(now.getWorld().getName(), now.getX(), now.getY(), now.getZ(), (String) null))) {
|
} else if (start.equals(new LiftBlock(now))) {
|
||||||
DataManager.addRopeEditPlayer(p.getUniqueId(), null);
|
DataManager.addRopeEditPlayer(p.getUniqueId(), null);
|
||||||
ConfigUtil.sendMessage(e.getPlayer(), "Rope.PartRemoved");
|
ConfigUtil.sendMessage(e.getPlayer(), "Rope.PartRemoved");
|
||||||
} else {
|
} else {
|
||||||
|
@ -306,7 +325,7 @@ public class PlayerInteractListener implements Listener {
|
||||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
Block block = e.getClickedBlock();
|
Block block = e.getClickedBlock();
|
||||||
LiftBlock lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), (String) null);
|
LiftBlock lb = new LiftBlock(block);
|
||||||
DataManager.removeWhoisREQPlayer(p.getUniqueId());
|
DataManager.removeWhoisREQPlayer(p.getUniqueId());
|
||||||
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
|
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
|
||||||
Lift lift = entry.getValue();
|
Lift lift = entry.getValue();
|
||||||
|
@ -363,7 +382,7 @@ public class PlayerInteractListener implements Listener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lift.getBlocks().contains(new LiftBlock(sign.getWorld().getName(), sign.getX(), sign.getY(), sign.getZ(), (String) null)))
|
if (!lift.getBlocks().contains(new LiftBlock(sign.getBlock())))
|
||||||
return;
|
return;
|
||||||
if (DataManager.containsEditLift(liftName)) return;
|
if (DataManager.containsEditLift(liftName)) return;
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
|
|
Loading…
Reference in a new issue