Skip to content

Commit

Permalink
Merge pull request #1407 from Dans-Plugins/removing-second-teleport-d…
Browse files Browse the repository at this point in the history
…elay

Removed Unnecessary Delay
  • Loading branch information
dmccoystephenson authored Jun 17, 2022
2 parents 1039464 + 752356e commit 2ad2666
Showing 1 changed file with 2 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private boolean isFactionExceedingTheirDemesneLimit(Faction faction) {
public void scheduleTeleport(Player player, Location destinationLocation) {
final int teleport_delay = LocalConfigService.getInstance().getInt("teleportDelay");
player.sendMessage(ChatColor.AQUA + "Teleporting in " + teleport_delay + " seconds...");
DelayedTeleportTask delayedTeleportTask = new DelayedTeleportTask(teleport_delay, player, destinationLocation);
DelayedTeleportTask delayedTeleportTask = new DelayedTeleportTask(player, destinationLocation);
delayedTeleportTask.runTaskLater(MedievalFactions.getInstance(), (long) (teleport_delay * getRandomNumberBetween(15, 25)));
}

Expand All @@ -113,12 +113,11 @@ private int getRandomNumberBetween(int num1, int num2) {
}

private class DelayedTeleportTask extends BukkitRunnable {
private int seconds;
private Player player;
private Location initialLocation;
private Location destinationLocation;

public DelayedTeleportTask(int seconds, Player player, Location destinationLocation) {
public DelayedTeleportTask(Player player, Location destinationLocation) {
this.seconds = seconds;
this.player = player;
this.initialLocation = player.getLocation();
Expand All @@ -127,14 +126,6 @@ public DelayedTeleportTask(int seconds, Player player, Location destinationLocat

@Override
public void run() {
try {
delay();
} catch(Exception e) {
player.sendMessage(ChatColor.RED + "Something went wrong.");
Logger.getInstance().debug("Something went wrong running a delayed teleport task.");
return;
}

if (playerHasNotMoved()) {
teleportPlayer();
}
Expand All @@ -143,10 +134,6 @@ public void run() {
}
}

private void delay() throws InterruptedException {
TimeUnit.SECONDS.sleep(seconds);
}

private boolean playerHasNotMoved() {
return initialLocation.getX() == player.getLocation().getX() && initialLocation.getY() == player.getLocation().getY() && initialLocation.getZ() == player.getLocation().getZ();
}
Expand Down

0 comments on commit 2ad2666

Please sign in to comment.