PlayerInteractListener done! :)

This commit is contained in:
stijnb1234 2020-02-02 11:24:12 +01:00
parent 54fe26647a
commit f619080a2d
7 changed files with 397 additions and 48 deletions

View file

@ -16,7 +16,7 @@ public class Lift {
@Getter private ArrayList<LiftSign> signs;
@Getter private ArrayList<LiftBlock> inputs;
@Getter private ArrayList<LiftBlock> offlineInputs;
@Getter private LinkedHashMap<String, Floor> queue;
@Getter @Setter private LinkedHashMap<String, Floor> queue;
@Getter private ArrayList<LiftRope> ropes;
@Getter private ArrayList<V10Entity> toMove;
@Getter @Setter private int speed;

View file

@ -7,25 +7,21 @@ import org.bukkit.Material;
@Getter @Setter
public class LiftRope {
private final Material type;
private final String startWorld;
private final String endWorld;
private final String world;
private final int x;
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) {
public LiftRope(Material type, String world, int x, int minY, int maxY, int z) {
this.type = type;
this.startWorld = startWorld;
this.endWorld = endWorld;
this.world = world;
this.x = x;
this.minY = minY;
this.maxY = maxY;
this.z = z;
this.currently = minY;
this.currentWorld = endWorld;
}
public boolean equals(Object obj) {
@ -33,8 +29,7 @@ public class LiftRope {
if (obj == null) return false;
if (!(obj instanceof LiftRope)) return false;
LiftRope other = (LiftRope) obj;
return getStartWorld().equals(other.getStartWorld())
&& endWorld.equals(other.getEndWorld())
return getWorld().equals(other.getWorld())
&& getX() == other.getX()
&& getMinY() == other.getMinY()
&& getMaxY() == other.getMaxY()

View file

@ -130,14 +130,14 @@ public class MoveLift implements Runnable {
//MOVE ROPES
for (LiftRope rope : lift.getRopes()) {
if (rope.getCurrentWorld().equals(rope.getStartWorld()) && rope.getCurrently() > rope.getMaxY()) {
if (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;
}
world = Objects.requireNonNull(Bukkit.getWorld(rope.getCurrentWorld()), "World is null at MoveLift");
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);
rope.setCurrently(rope.getCurrently() + 1);
@ -354,7 +354,7 @@ public class MoveLift implements Runnable {
//MOVE ROPES
for (LiftRope rope : lift.getRopes()) {
if (rope.getCurrentWorld().equals(rope.getStartWorld()) && rope.getCurrently() < rope.getMinY()) {
if (rope.getCurrently() < rope.getMinY()) {
Bukkit.getLogger().info("[V10Lift] Lift " + liftName + " reaches the upper rope end but won't stop!!");
V10LiftPlugin.getAPI().setDefective(liftName, true);
lift.getToMove().clear();
@ -364,7 +364,7 @@ public class MoveLift implements Runnable {
block.setType(rope.getType());
return;
}
world = Objects.requireNonNull(Bukkit.getWorld(rope.getCurrentWorld()), "World is null at MoveLift");
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());
block.setType(rope.getType());

View file

@ -2,6 +2,7 @@ package nl.SBDeveloper.V10Lift.API;
import nl.SBDeveloper.V10Lift.API.Objects.*;
import nl.SBDeveloper.V10Lift.API.Runnables.DoorCloser;
import nl.SBDeveloper.V10Lift.API.Runnables.MoveLift;
import nl.SBDeveloper.V10Lift.Managers.AntiCopyBlockManager;
import nl.SBDeveloper.V10Lift.Managers.DataManager;
import nl.SBDeveloper.V10Lift.Managers.ForbiddenBlockManager;
@ -15,6 +16,7 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import javax.annotation.Nonnull;
import javax.xml.crypto.Data;
import java.util.*;
public class V10LiftAPI {
@ -109,8 +111,11 @@ public class V10LiftAPI {
public int addBlockToLift(String liftName, Block block) {
if (liftName == null || block == null || !DataManager.containsLift(liftName)) return -1;
Lift lift = DataManager.getLift(liftName);
return addBlockToLift(lift.getBlocks(), block);
}
public int addBlockToLift(Set<LiftBlock> blocks, @Nonnull Block block) {
Material type = block.getType();
if (getFBM().isForbidden(type)) return -2;
LiftBlock lb;
if (type.toString().contains("SIGN")) {
//SIGN
@ -118,8 +123,13 @@ public class V10LiftAPI {
} else {
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type);
}
if (lift.getBlocks().contains(lb)) return -3;
lift.getBlocks().add(lb);
return addBlockToLift(blocks, lb);
}
public int addBlockToLift(Set<LiftBlock> blocks, @Nonnull LiftBlock block) {
if (getFBM().isForbidden(block.getMat())) return -2;
if (blocks.contains(block)) return -3;
blocks.add(block);
return 0;
}
@ -147,17 +157,13 @@ public class V10LiftAPI {
return 0;
}
/**
* Switch a block at a lift
* Use {@link nl.SBDeveloper.V10Lift.API.V10LiftAPI#sortLiftBlocks(String liftName)} after!
*
* @param liftName The name of the lift
* @param block The block
* @return 0 if added, 1 if removed, -1 if null or doesn't exists, -2 if forbidden
*/
public int switchBlockAtLift(String liftName, Block block) {
if (liftName == null || block == null || !DataManager.containsLift(liftName)) return -1;
Lift lift = DataManager.getLift(liftName);
return switchBlockAtLift(DataManager.getLift(liftName).getBlocks(), block);
}
public int switchBlockAtLift(TreeSet<LiftBlock> blocks, Block block) {
if (blocks == null || block == null) return -1;
Material type = block.getType();
if (getFBM().isForbidden(type)) return -2;
LiftBlock lb;
@ -167,11 +173,11 @@ public class V10LiftAPI {
} else {
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type);
}
if (lift.getBlocks().contains(lb)) {
lift.getBlocks().remove(lb);
if (blocks.contains(lb)) {
blocks.remove(lb);
return 1;
}
lift.getBlocks().add(lb);
blocks.add(lb);
return 0;
}
@ -586,10 +592,8 @@ public class V10LiftAPI {
for (LiftRope rope : lift.getRopes()) {
if (x != rope.getX() || z != rope.getZ()) continue;
if (rope.getStartWorld().equals(rope.getEndWorld())) {
if (y >= rope.getMinY() && y <= rope.getMaxY()) {
return true;
}
if (y >= rope.getMinY() && y <= rope.getMaxY()) {
return true;
}
}
return false;
@ -603,10 +607,10 @@ public class V10LiftAPI {
}
public void sendLiftInfo(Player p, String liftName) {
if (p == null || liftName == null || !DataManager.containsLift(liftName)) return;
Lift lift = DataManager.getLift(liftName);
sendLiftInfo(p, liftName, DataManager.getLift(liftName));
}
public void sendLiftInfo(@Nonnull Player p, String liftName, @Nonnull Lift lift) {
if (!lift.getOwners().contains(p.getUniqueId()) && !p.hasPermission("v10lift.admin")) {
p.sendMessage(ChatColor.RED + "You don't have the permission to check this lift!");
} else {
@ -647,4 +651,96 @@ public class V10LiftAPI {
}
}
public int addRope(String lift, World world, int x, int minY, int maxY, int z) {
if (lift == null || !DataManager.containsLift(lift) || world == null) return -1;
boolean change = minY > maxY;
Block block = world.getBlockAt(x, minY, z);
if (isRope(block)) return -3;
Material mat = block.getType();
if (getFBM().isForbidden(mat)) return -4;
for (int i = minY + 1; i <= maxY; i++) {
block = world.getBlockAt(x, i, z);
if (isRope(block)) return -3;
if (block.getType() != mat) return -2;
}
DataManager.getLift(lift).getRopes().add(new LiftRope(mat, world.getName(), x, minY, maxY, z));
return 0;
}
public boolean removeRope(String lift, Block block) {
if (lift == null || block == null || !DataManager.containsLift(lift) || !containsRope(lift, block)) return false;
String world = block.getWorld().getName();
int x = block.getX();
int y = block.getY();
int z = block.getZ();
Iterator<LiftRope> riter = DataManager.getLift(lift).getRopes().iterator();
while (riter.hasNext()) {
LiftRope rope = riter.next();
if (x != rope.getX() || z != rope.getZ()) continue;
if (world.equals(rope.getWorld())) {
if (y >= rope.getMinY() && y <= rope.getMaxY()) {
riter.remove();
return true;
}
}
}
return false;
}
public boolean setQueue(String liftName, LinkedHashMap<String, Floor> queue) {
if (liftName == null || queue == null || !DataManager.containsLift(liftName)) return false;
Lift lift = DataManager.getLift(liftName);
lift.setQueue(new LinkedHashMap<>());
for (Map.Entry<String, Floor> e : queue.entrySet()) {
addToQueue(liftName, e.getValue(), e.getKey());
}
return true;
}
public boolean addToQueue(String lift, int y, World world) {
return addToQueue(lift, y, world, null);
}
public boolean addToQueue(String lift, int y, @Nonnull World world, String floorName) {
return addToQueue(lift, new Floor(y, world.getName()), floorName);
}
public boolean addToQueue(String lift, Floor floor, String floorName) {
if (lift == null || floor == null || !DataManager.containsLift(lift)) return false;
Lift l = DataManager.getLift(lift);
if (l.getQueue() == null) {
l.setQueue(new LinkedHashMap<>());
}
if (!l.getQueue().containsValue(floor)) {
if (floorName == null) {
floorName = ChatColor.MAGIC + "-----";
for (Map.Entry<String, Floor> e : l.getFloors().entrySet()) {
if (e.getValue().equals(floor)) {
floorName = e.getKey();
floor = e.getValue();
break;
}
}
}
l.getQueue().put(floorName, floor);
startLift(lift);
return true;
}
return false;
}
private void startLift(String liftName) {
if (!DataManager.containsMovingTask(liftName)) {
Lift lift = DataManager.getLift(liftName);
DataManager.addMovingTask(liftName, Bukkit.getScheduler().scheduleSyncRepeatingTask(V10LiftPlugin.getInstance(), new MoveLift(liftName, lift.getSpeed()), lift.getSpeed(), lift.getSpeed()));
}
}
}

View file

@ -766,7 +766,7 @@ public class V10LiftCommand implements CommandExecutor {
return true;
}
ArrayList<Block> blocks = DataManager.getPlayer(p.getUniqueId());
TreeSet<LiftBlock> blocks = DataManager.getPlayer(p.getUniqueId());
if (blocks.isEmpty()) {
sender.sendMessage(ChatColor.RED + "Add blocks first!");
return true;
@ -776,7 +776,9 @@ public class V10LiftCommand implements CommandExecutor {
sender.sendMessage(ChatColor.RED + "A lift with that name already exists.");
}
blocks.forEach(block -> V10LiftPlugin.getAPI().addBlockToLift(args[1], block));
TreeSet<LiftBlock> blcks = DataManager.getLift(args[1]).getBlocks();
blocks.forEach(block -> V10LiftPlugin.getAPI().addBlockToLift(blcks, block));
V10LiftPlugin.getAPI().sortLiftBlocks(args[1]);
DataManager.removePlayer(p.getUniqueId());
sender.sendMessage(ChatColor.GREEN + "The lift " + args[1] + " is created successfully!");

View file

@ -1,12 +1,18 @@
package nl.SBDeveloper.V10Lift.Listeners;
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.Managers.DataManager;
import nl.SBDeveloper.V10Lift.Utils.XMaterial;
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -14,8 +20,10 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import javax.xml.crypto.Data;
import java.util.Iterator;
import java.util.Map;
public class PlayerInteractListener implements Listener {
@ -49,14 +57,262 @@ public class PlayerInteractListener implements Listener {
//BLOCK ADD
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerInteract(PlayerInteractEvent e) {
if (e.getHand() != EquipmentSlot.OFF_HAND) {
if (e.getHand() != EquipmentSlot.OFF_HAND && e.getClickedBlock() != null) {
Player p = e.getPlayer();
if (DataManager.containsPlayer(p.getUniqueId())) {
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
e.setCancelled(true);
//TODO Fix hashmap for player -> lift (because I need it here)
int res = V10LiftPlugin.getAPI().switchBlockAtLift(DataManager.getPlayer(p.getUniqueId()), e.getClickedBlock());
switch (res) {
case 0:
p.sendMessage(ChatColor.GREEN + "Block added to the elevator.");
break;
case 1:
p.sendMessage(ChatColor.GOLD + "Block removed from the elevator.");
break;
case -2:
p.sendMessage(ChatColor.RED + "The material " + e.getClickedBlock().getType().toString() + " cannot be used!");
break;
default:
p.sendMessage(ChatColor.RED + "Internal error.");
break;
}
} 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()));
Lift lift = DataManager.getLift(DataManager.getEditPlayer(p.getUniqueId()));
e.setCancelled(true);
if (lift.getInputs().contains(tlb)) {
p.sendMessage(ChatColor.RED + "This block has already been chosen as an input. Choose another block!");
return;
}
lift.getInputs().add(tlb);
DataManager.removeInputEditsPlayer(p.getUniqueId());
p.sendMessage(ChatColor.GREEN + "Input created!");
} 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);
Lift lift = DataManager.getLift(DataManager.getEditPlayer(p.getUniqueId()));
e.setCancelled(true);
if (lift.getOfflineInputs().contains(tlb)) {
p.sendMessage(ChatColor.RED + "This block has already been chosen as an input. Choose another block!");
return;
}
lift.getOfflineInputs().add(tlb);
DataManager.removeOfflineEditsPlayer(p.getUniqueId());
p.sendMessage(ChatColor.GREEN + "Offline input created!");
} 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);
Lift lift = DataManager.getLift(DataManager.getEditPlayer(p.getUniqueId()));
e.setCancelled(true);
if (lift.getInputs().contains(tlb)) {
lift.getInputs().remove(tlb);
DataManager.removeInputRemovesPlayer(p.getUniqueId());
p.sendMessage(ChatColor.GREEN + "Input removed!");
return;
}
p.sendMessage(ChatColor.RED + "This block is not an input. Choose another block!");
} 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);
Lift lift = DataManager.getLift(DataManager.getEditPlayer(p.getUniqueId()));
e.setCancelled(true);
if (lift.getOfflineInputs().contains(tlb)) {
lift.getOfflineInputs().remove(tlb);
DataManager.removeOfflineRemovesPlayer(p.getUniqueId());
p.sendMessage(ChatColor.GREEN + "Offline input removed!");
return;
}
p.sendMessage(ChatColor.RED + "This block is not an offline input. Choose another block!");
} else if (DataManager.containsBuilderPlayer(p.getUniqueId())) {
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
e.setCancelled(true);
int res = V10LiftPlugin.getAPI().switchBlockAtLift(DataManager.getEditPlayer(p.getUniqueId()), e.getClickedBlock());
switch (res) {
case 0:
p.sendMessage(ChatColor.GREEN + "Block added to the elevator.");
break;
case 1:
p.sendMessage(ChatColor.GOLD + "Block removed from the elevator.");
break;
case -2:
p.sendMessage(ChatColor.RED + "The material " + e.getClickedBlock().getType().toString() + " cannot be used!");
break;
default:
p.sendMessage(ChatColor.RED + "Internal error.");
break;
}
} else if (DataManager.containsRopeEditPlayer(p.getUniqueId())) {
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
e.setCancelled(true);
LiftBlock start = DataManager.getRopeEditPlayer(p.getUniqueId());
Block now = e.getClickedBlock();
if (start == null) {
p.sendMessage(ChatColor.GOLD + "Now right-click on the end of the rope!");
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(), null);
p.sendMessage(ChatColor.GOLD + "Start removed!");
p.sendMessage(ChatColor.GOLD + "Now right-click on the end of the rope!");
} else {
if (start.getX() != now.getX() || start.getZ() != now.getZ()) {
p.sendMessage(ChatColor.RED + "A rope can only go up!");
return;
}
int res = V10LiftPlugin.getAPI().addRope(DataManager.getEditPlayer(p.getUniqueId()), now.getWorld(), start.getX(), now.getY(), start.getY(), start.getZ());
switch (res) {
case 0:
p.sendMessage(ChatColor.GREEN + "Rope created.");
break;
case -2:
p.sendMessage(ChatColor.RED + "The rope must be of the same material!");
break;
case -3:
p.sendMessage(ChatColor.RED + "Part of the rope is already part of another rope!");
break;
case -4:
p.sendMessage(ChatColor.RED + "The rope is build of blacklisted blocks!");
break;
default:
p.sendMessage(ChatColor.RED + "Internal error.");
break;
}
DataManager.removeRopeEditPlayer(p.getUniqueId());
}
} else if (DataManager.containsRopeRemovesPlayer(p.getUniqueId())) {
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
e.setCancelled(true);
Block block = e.getClickedBlock();
if (V10LiftPlugin.getAPI().getFBM().isForbidden(block.getType())) {
p.sendMessage(ChatColor.RED + "The material " + e.getClickedBlock().getType().toString() + " is currently not supported!");
return;
}
String liftName = DataManager.getEditPlayer(p.getUniqueId());
if (!V10LiftPlugin.getAPI().containsRope(liftName, block)) {
p.sendMessage(ChatColor.RED + "This block is not part of the rope.");
return;
}
V10LiftPlugin.getAPI().removeRope(liftName, block);
DataManager.removeRopeRemovesPlayer(p.getUniqueId());
p.sendMessage(ChatColor.GREEN + "Rope removed.");
} else if (DataManager.containsDoorEditPlayer(p.getUniqueId())) {
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
e.setCancelled(true);
Block block = e.getClickedBlock();
if (V10LiftPlugin.getAPI().getFBM().isForbidden(block.getType())) {
p.sendMessage(ChatColor.RED + "The material " + e.getClickedBlock().getType().toString() + " is currently not supported!");
return;
}
LiftBlock lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), block.getType());
Lift lift = DataManager.getLift(DataManager.getEditPlayer(p.getUniqueId()));
Floor floor = lift.getFloors().get(DataManager.getDoorEditPlayer(p.getUniqueId()));
if (floor.getDoorBlocks().contains(lb)) {
floor.getDoorBlocks().remove(lb);
p.sendMessage(ChatColor.GOLD + "Door removed.");
return;
}
floor.getDoorBlocks().add(lb);
p.sendMessage(ChatColor.GREEN + "Door created.");
} else if (DataManager.containsWhoisREQPlayer(p.getUniqueId())) {
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);
DataManager.removeWhoisREQPlayer(p.getUniqueId());
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
Lift lift = entry.getValue();
if (lift.getBlocks().contains(lb) || lift.getInputs().contains(lb) || lift.getSigns().contains(lb) || lift.getRopes().contains(lb) || lift.getOfflineInputs().contains(lb)) {
V10LiftPlugin.getAPI().sendLiftInfo(p, entry.getKey(), lift);
return;
}
}
p.sendMessage(ChatColor.RED + "This block is not part of a lift.");
} else {
Action a = e.getAction();
if (a != Action.RIGHT_CLICK_BLOCK && a != Action.LEFT_CLICK_BLOCK) return;
BlockState bs = e.getClickedBlock().getState();
if (!(bs instanceof Sign)) return;
Sign sign = (Sign) bs;
//TODO Add defaults to config!
if (!sign.getLine(0).equalsIgnoreCase("[v10lift]")) return;
String liftName = sign.getLine(1);
if (!DataManager.containsLift(liftName)) return;
Lift lift = DataManager.getLift(liftName);
if (lift.isOffline()) {
e.setCancelled(true);
return;
}
if (lift.isDefective()) {
//TODO Add defaults to config!!!
if (sign.getLine(3).equals(ChatColor.MAGIC + "Defect!") && p.hasPermission("v10lift.repair") && a == Action.RIGHT_CLICK_BLOCK) {
int masterAmount = 2;
Material masterItem = Material.DIAMOND;
if (p.getGameMode() != GameMode.CREATIVE && masterAmount > 0) {
if (!p.getInventory().contains(masterItem)) {
p.sendMessage(ChatColor.RED + "You need " + masterAmount + "x " + masterItem.toString().toLowerCase() + "!");
return;
}
p.getInventory().remove(new ItemStack(masterItem, masterAmount));
}
V10LiftPlugin.getAPI().setDefective(liftName, false);
}
e.setCancelled(true);
return;
}
if (!lift.getBlocks().contains(new LiftBlock(sign.getWorld().getName(), sign.getX(), sign.getY(), sign.getZ(), (String) null))) return;
if (DataManager.containsEditLift(liftName)) return;
e.setCancelled(true);
if (lift.isDefective()) return;
String f = ChatColor.stripColor(sign.getLine(3));
if (a == Action.RIGHT_CLICK_BLOCK) {
Iterator<String> iter = lift.getFloors().keySet().iterator();
if (!lift.getFloors().containsKey(f)) {
if (!iter.hasNext()) {
p.sendMessage(ChatColor.RED + "This elevator has no floors!");
return;
}
f = iter.next();
}
while (iter.hasNext()) {
if (iter.next().equals(f)) break;
}
if (!iter.hasNext()) iter = lift.getFloors().keySet().iterator();
String f2 = iter.next();
Floor floor = lift.getFloors().get(f2);
if (lift.getY() == floor.getY()) {
sign.setLine(3, ChatColor.GREEN + f2);
} else if (!floor.getWhitelist().isEmpty() && !floor.getWhitelist().contains(p.getUniqueId()) && !p.hasPermission("v10lift.admin")) {
sign.setLine(3, ChatColor.RED + f2);
} else {
sign.setLine(3, ChatColor.YELLOW + f2);
}
sign.update();
} else {
if (!lift.getFloors().containsKey(f)) {
p.sendMessage(ChatColor.RED + "Floor not found!");
return;
}
Floor floor = lift.getFloors().get(f);
if (!floor.getWhitelist().isEmpty() && !floor.getWhitelist().contains(p.getUniqueId()) && !p.hasPermission("v10lift.admin")) {
p.sendMessage(ChatColor.RED + "You can't go to that floor!");
e.setCancelled(true);
return;
}
V10LiftPlugin.getAPI().addToQueue(liftName, lift.getFloors().get(f), f);
}
}
}
}

View file

@ -1,21 +1,21 @@
package nl.SBDeveloper.V10Lift.Managers;
import nl.SBDeveloper.V10Lift.API.Objects.Lift;
import org.bukkit.block.Block;
import nl.SBDeveloper.V10Lift.API.Objects.LiftBlock;
import java.util.*;
public class DataManager {
/* A manager for general HashMaps */
private static LinkedHashMap<String, Lift> lifts = new LinkedHashMap<>();
private static LinkedHashMap<UUID, ArrayList<Block>> builds = new LinkedHashMap<>();
private static LinkedHashMap<UUID, TreeSet<LiftBlock>> builds = new LinkedHashMap<>();
private static LinkedHashMap<UUID, String> editors = new LinkedHashMap<>();
private static LinkedHashMap<UUID, String> inputEdits = new LinkedHashMap<>();
private static ArrayList<UUID> inputRemoves = new ArrayList<>();
private static ArrayList<UUID> offlineEdits = new ArrayList<>();
private static ArrayList<UUID> offlineRemoves = new ArrayList<>();
private static ArrayList<UUID> builder = new ArrayList<>();
private static LinkedHashMap<UUID, String> ropeEdits = new LinkedHashMap<>();
private static LinkedHashMap<UUID, LiftBlock> ropeEdits = new LinkedHashMap<>();
private static ArrayList<UUID> ropeRemoves = new ArrayList<>();
private static HashMap<UUID, String> doorEdits = new HashMap<>();
private static ArrayList<UUID> whoisReq = new ArrayList<>();
@ -48,14 +48,14 @@ public class DataManager {
}
public static void addPlayer(UUID player) {
builds.put(player, new ArrayList<>());
builds.put(player, new TreeSet<>());
}
public static void removePlayer(UUID player) {
builds.remove(player);
}
public static ArrayList<Block> getPlayer(UUID player) {
public static TreeSet<LiftBlock> getPlayer(UUID player) {
return builds.get(player);
}
@ -81,15 +81,15 @@ public class DataManager {
return ropeEdits.containsKey(player);
}
public static void addRopeEditPlayer(UUID player, String liftName) {
ropeEdits.put(player, liftName);
public static void addRopeEditPlayer(UUID player, LiftBlock liftBlock) {
ropeEdits.put(player, liftBlock);
}
public static void removeRopeEditPlayer(UUID player) {
ropeEdits.remove(player);
}
public static String getRopeEditPlayer(UUID player) {
public static LiftBlock getRopeEditPlayer(UUID player) {
return ropeEdits.get(player);
}