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().put(newName, f);
|
||||
sortFloors(lift);
|
||||
Iterator<LiftBlock> liter = lift.getInputs().iterator();
|
||||
LiftBlock lb;
|
||||
ArrayList<LiftBlock> newBlocks = new ArrayList<>();
|
||||
Iterator<LiftInput> liter = lift.getInputs().iterator();
|
||||
LiftInput lb;
|
||||
ArrayList<LiftInput> newBlocks = new ArrayList<>();
|
||||
while (liter.hasNext()) {
|
||||
lb = liter.next();
|
||||
if (lb.getFloor().equals(oldName)) {
|
||||
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));
|
||||
|
|
|
@ -23,8 +23,8 @@ public class Lift {
|
|||
private final TreeSet<LiftBlock> blocks = new TreeSet<>();
|
||||
private final LinkedHashMap<String, Floor> floors = new LinkedHashMap<>();
|
||||
private final HashSet<LiftSign> signs = new HashSet<>();
|
||||
private final HashSet<LiftBlock> inputs = new HashSet<>();
|
||||
private final HashSet<LiftBlock> offlineInputs = new HashSet<>();
|
||||
private final HashSet<LiftInput> inputs = new HashSet<>();
|
||||
private final HashSet<LiftInput> offlineInputs = new HashSet<>();
|
||||
@Setter
|
||||
private LinkedHashMap<String, Floor> queue = null;
|
||||
private final HashSet<LiftRope> ropes = new HashSet<>();
|
||||
|
|
|
@ -37,37 +37,8 @@ public class LiftBlock implements Comparable<LiftBlock> {
|
|||
private String[] signLines;
|
||||
@Setter
|
||||
private Boolean open;
|
||||
|
||||
//Only used for inputs!
|
||||
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;
|
||||
}
|
||||
//Used for chests
|
||||
public Map<String, Object>[] serializedItemStacks;
|
||||
|
||||
/**
|
||||
* 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.Lift;
|
||||
import tech.sbdevelopment.v10lift.api.objects.LiftBlock;
|
||||
import tech.sbdevelopment.v10lift.api.objects.LiftInput;
|
||||
import tech.sbdevelopment.v10lift.managers.DataManager;
|
||||
import tech.sbdevelopment.v10lift.utils.ConfigUtil;
|
||||
import tech.sbdevelopment.v10lift.utils.DoorUtil;
|
||||
|
@ -28,7 +29,7 @@ public class BlockBreakListener implements Listener {
|
|||
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()) {
|
||||
Lift lift = entry.getValue();
|
||||
if (lift.getBlocks().contains(tlb)) {
|
||||
|
|
|
@ -8,6 +8,8 @@ import org.bukkit.Material;
|
|||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
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.event.EventHandler;
|
||||
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.Lift;
|
||||
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.ForbiddenBlockManager;
|
||||
import tech.sbdevelopment.v10lift.managers.VaultManager;
|
||||
|
@ -42,31 +45,47 @@ public class PlayerInteractListener implements Listener {
|
|||
Material button = block.getType();
|
||||
|
||||
if (action == Action.RIGHT_CLICK_BLOCK
|
||||
&& e.getHand() != EquipmentSlot.OFF_HAND
|
||||
&& (button.toString().contains("BUTTON") || button == XMaterial.LEVER.parseMaterial())) {
|
||||
&& e.getHand() != EquipmentSlot.OFF_HAND) {
|
||||
String world = block.getWorld().getName();
|
||||
int x = block.getX();
|
||||
int y = block.getY();
|
||||
int z = block.getZ();
|
||||
|
||||
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
|
||||
Lift lift = entry.getValue();
|
||||
for (LiftBlock lb : lift.getOfflineInputs()) {
|
||||
if (world.equals(lb.getWorld()) && x == lb.getX() && y == lb.getY() && z == lb.getZ()) {
|
||||
lb.setActive(!lb.isActive());
|
||||
V10LiftAPI.getInstance().setOffline(entry.getKey(), lb.isActive());
|
||||
return;
|
||||
|
||||
for (LiftInput lbi : lift.getOfflineInputs()) {
|
||||
if (world.equals(lbi.getWorld()) && x == lbi.getX() && y == lbi.getY() && z == lbi.getZ()) {
|
||||
boolean newState = !lift.isOffline();
|
||||
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()) {
|
||||
if (world.equals(lb.getWorld()) && x == lb.getX() && y == lb.getY() && z == lb.getZ()) {
|
||||
V10LiftAPI.getInstance().addToQueue(entry.getKey(), lift.getFloors().get(lb.getFloor()), lb.getFloor());
|
||||
for (LiftInput lbi : lift.getInputs()) {
|
||||
if (world.equals(lbi.getWorld()) && x == lbi.getX() && y == lbi.getY() && z == lbi.getZ()) {
|
||||
V10LiftAPI.getInstance().addToQueue(entry.getKey(), lift.getFloors().get(lbi.getFloor()), lbi.getFloor());
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -104,7 +123,7 @@ public class PlayerInteractListener implements Listener {
|
|||
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;
|
||||
if (DataManager.containsEditLift(liftName)) return;
|
||||
e.setCancelled(true);
|
||||
|
@ -160,7 +179,7 @@ public class PlayerInteractListener implements Listener {
|
|||
} else if (DataManager.containsInputEditsPlayer(p.getUniqueId())) {
|
||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
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()));
|
||||
e.setCancelled(true);
|
||||
if (lift.getInputs().contains(tlb)) {
|
||||
|
@ -173,7 +192,7 @@ public class PlayerInteractListener implements Listener {
|
|||
} else if (DataManager.containsOfflineEditsPlayer(p.getUniqueId())) {
|
||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
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()));
|
||||
e.setCancelled(true);
|
||||
if (lift.getOfflineInputs().contains(tlb)) {
|
||||
|
@ -186,7 +205,7 @@ public class PlayerInteractListener implements Listener {
|
|||
} else if (DataManager.containsInputRemovesPlayer(p.getUniqueId())) {
|
||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
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()));
|
||||
e.setCancelled(true);
|
||||
if (lift.getInputs().contains(tlb)) {
|
||||
|
@ -199,7 +218,7 @@ public class PlayerInteractListener implements Listener {
|
|||
} else if (DataManager.containsOfflineRemovesPlayer(p.getUniqueId())) {
|
||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
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()));
|
||||
e.setCancelled(true);
|
||||
if (lift.getOfflineInputs().contains(tlb)) {
|
||||
|
@ -234,8 +253,8 @@ public class PlayerInteractListener implements Listener {
|
|||
Block now = e.getClickedBlock();
|
||||
if (start == null) {
|
||||
ConfigUtil.sendMessage(e.getPlayer(), "Rope.ClickOnEnd");
|
||||
DataManager.addRopeEditPlayer(p.getUniqueId(), new LiftBlock(now.getWorld().getName(), now.getX(), now.getY(), now.getZ(), (String) null));
|
||||
} else if (start.equals(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))) {
|
||||
DataManager.addRopeEditPlayer(p.getUniqueId(), null);
|
||||
ConfigUtil.sendMessage(e.getPlayer(), "Rope.PartRemoved");
|
||||
} else {
|
||||
|
@ -306,7 +325,7 @@ public class PlayerInteractListener implements Listener {
|
|||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
e.setCancelled(true);
|
||||
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());
|
||||
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
|
||||
Lift lift = entry.getValue();
|
||||
|
@ -363,7 +382,7 @@ public class PlayerInteractListener implements Listener {
|
|||
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;
|
||||
if (DataManager.containsEditLift(liftName)) return;
|
||||
e.setCancelled(true);
|
||||
|
|
Loading…
Reference in a new issue