Solved Error checking for a safe location

Discussion in 'Spigot Plugin Development' started by Kechu, Feb 10, 2020.

Thread Status:
Not open for further replies.
  1. Hi! I have a teletransportation plugin and i want that before the teleport check if the location is safe, if isnt player will have to confirm if he wants to be teleported to a near safe location. My codes try to first check if there is a safe location on Y coord, above the actual location and under and save the nearest, if there isnt any safe location on Y coord, i have a metod that add coords X and Z to the location like in a spiral form, so will check if there is a safe location at Y coord of all block around the player. But i am having an error that crash the server, stop respondig and send me lots of error message saying that server stop respondig.
    I am getting really mad trying to make my code work, here it is:

    [​IMG]

    [​IMG]

    AND MUCH MORE MESSAGES LIKE THIS UNTIL THE SERVERS STOP ITSELF

    Code (Java):

      public static final HashMap<UUID, Boolean> confirmQueue = new HashMap<>();
      public static final HashMap<UUID, Location> locationQueue = new HashMap<>();

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
      //SOME CHECKINGS HERE
    }

     private boolean confirmedLocation(Player player, Location b, boolean confirmed, boolean safe) {
            FileConfiguration messages = this.plugin.getMessages();
            LocationUtil locutil = new LocationUtil();
            if(!safe) {
                if (!confirmed) {
                    return false;
                }else {
                    boolean checkhight = true;
                    Location above = null;
                    Location below = null;
                    Block near = null;
                    if (confirmQueue.containsKey(player.getUniqueId()) && confirmQueue.get(player.getUniqueId())) {
                        do {
                            if (checkhight) {
                                Location c = b;
                                above = locutil.getSafeAbove(c);
                                below = locutil.getSafeBelow(c);
                                if (b.distance(above) <= b.distance(below)) {
                                    near = above.getBlock();
                                }else {
                                    near = below.getBlock();
                                }
                            }
                            if (near != null) {
                                b = near.getLocation().add(0.5,0,0.5);
                                locationQueue.put(player.getUniqueId(), b);
                                checkhight = false;
                            }else {
                                Integer[] nextCoords = locutil.getNext(b);
                                if (nextCoords[0] < 0 || nextCoords[1] < 0) {
                                    b = b.subtract(nextCoords[0], 0, nextCoords[0]);
                                }else {
                                    b = b.add(nextCoords[0], 0, nextCoords[0]);
                                }
                                locationQueue.put(player.getUniqueId(), b);
                            }
                   
                        } while(!locutil.isSafeLocation(b));
                        player.sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("Messages.is-safe")));

                    }else {
                        return false;
                    }
                }
            }
     
            CommandBack.confirmQueue.remove(player.getUniqueId());
            CommandBack.locationQueue.remove(player.getUniqueId());
            long delay = 0L;
            if (!player.hasPermission("worldsback.teleport.delay.bypass")) {
              delay = this.plugin.getConfig().getLong("teleport-delay") * 4L;
              tpQueue.add(player.getUniqueId());
            }
            if (delay != 0L) player.sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("Messages.teleport-delay").replaceAll("%sec-left%", String.valueOf(this.plugin.getConfig().getLong("teleport-delay")))));
     
            TpTask task1 = new TpTask(this.plugin, player, b, delay);
            task1.execute();
     
            return true;
      }
     

    Attached Files:

    #1 Kechu, Feb 10, 2020
    Last edited: Feb 10, 2020
  2. Your while(!locutil.isSafeLocation(b)) loop is locking up the server.
     
    • Winner Winner x 1
Thread Status:
Not open for further replies.