From 1dc56dfc4fe4dd059c88ac40164e85e7b2750aec Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 10 Feb 2019 20:11:50 -0800 Subject: [PATCH] Removes runnable from approach. This could cause problems with threads because runnable should not be run like this (effectively async). It should only be run inside a Bukkit scheduled task to run on the main thread. --- .../commands/island/IslandSethomeCommand.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/api/commands/island/IslandSethomeCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/island/IslandSethomeCommand.java index 2db403e3a..9277b7712 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/island/IslandSethomeCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/island/IslandSethomeCommand.java @@ -63,12 +63,6 @@ public class IslandSethomeCommand extends ConfirmableCommand { } private void setHome(User user, int number) { - // Define a runnable as we will be using it often in the code below. - Runnable setHomeRunnable = () -> { - getPlugin().getPlayers().setHomeLocation(user, user.getLocation(), number); - user.sendMessage("commands.island.sethome.home-set"); - }; - // Check if the player is in the Nether if (getIWM().isNether(user.getLocation().getWorld())) { // Check if he is (not) allowed to set his home here @@ -79,9 +73,9 @@ public class IslandSethomeCommand extends ConfirmableCommand { // Check if a confirmation is required if (getIWM().getWorldSettings(user.getLocation().getWorld()).isRequireConfirmationToSetHomeInNether()) { - askConfirmation(user, "commands.island.sethome.nether.confirmation", setHomeRunnable); + askConfirmation(user, "commands.island.sethome.nether.confirmation", () -> doSetHome(user, number)); } else { - setHomeRunnable.run(); + doSetHome(user, number); } } else if (getIWM().isEnd(user.getLocation().getWorld())) { // Check if the player is in the End // Check if he is (not) allowed to set his home here @@ -92,13 +86,19 @@ public class IslandSethomeCommand extends ConfirmableCommand { // Check if a confirmation is required if (getIWM().getWorldSettings(user.getLocation().getWorld()).isRequireConfirmationToSetHomeInTheEnd()) { - askConfirmation(user, user.getTranslation("commands.island.sethome.the-end.confirmation"), setHomeRunnable); + askConfirmation(user, user.getTranslation("commands.island.sethome.the-end.confirmation"), () -> doSetHome(user, number)); } else { - setHomeRunnable.run(); + doSetHome(user, number); } } else { // The player is in the Overworld, no need to run a check - setHomeRunnable.run(); + doSetHome(user, number); } } + private void doSetHome(User user, int number) { + // Define a runnable as we will be using it often in the code below. + getPlugin().getPlayers().setHomeLocation(user, user.getLocation(), number); + user.sendMessage("commands.island.sethome.home-set"); + + } }