Prevent NPE possibility.

This commit is contained in:
tastybento 2021-09-19 18:36:37 -07:00
parent 29fa03976c
commit 690ea2f99e

View File

@ -1,11 +1,13 @@
package world.bentobox.bentobox.api.commands.island; package world.bentobox.bentobox.api.commands.island;
import java.util.List; import java.util.List;
import java.util.Objects;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.ConfirmableCommand; import world.bentobox.bentobox.api.commands.ConfirmableCommand;
import world.bentobox.bentobox.api.configuration.WorldSettings;
import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
@ -51,29 +53,30 @@ public class IslandSethomeCommand extends ConfirmableCommand {
@Override @Override
public boolean execute(User user, String label, List<String> args) { public boolean execute(User user, String label, List<String> args) {
String number = String.join(" ", args); String number = String.join(" ", args);
WorldSettings ws = Objects.requireNonNull(getIWM().getWorldSettings(user.getWorld()));
// Check if the player is in the Nether // Check if the player is in the Nether
if (getIWM().isNether(user.getWorld())) { if (getIWM().isNether(user.getWorld())) {
// Check if he is (not) allowed to set his home here // Check if he is (not) allowed to set his home here
if (!getIWM().getWorldSettings(user.getWorld()).isAllowSetHomeInNether()) { if (!ws.isAllowSetHomeInNether()) {
user.sendMessage("commands.island.sethome.nether.not-allowed"); user.sendMessage("commands.island.sethome.nether.not-allowed");
return false; return false;
} }
// Check if a confirmation is required // Check if a confirmation is required
if (getIWM().getWorldSettings(user.getWorld()).isRequireConfirmationToSetHomeInNether()) { if (ws.isRequireConfirmationToSetHomeInNether()) {
askConfirmation(user, user.getTranslation("commands.island.sethome.nether.confirmation"), () -> doSetHome(user, number)); askConfirmation(user, user.getTranslation("commands.island.sethome.nether.confirmation"), () -> doSetHome(user, number));
} else { } else {
doSetHome(user, number); doSetHome(user, number);
} }
} else if (getIWM().isEnd(user.getWorld())) { // Check if the player is in the End } else if (getIWM().isEnd(user.getWorld())) { // Check if the player is in the End
// Check if he is (not) allowed to set his home here // Check if he is (not) allowed to set his home here
if (!getIWM().getWorldSettings(user.getWorld()).isAllowSetHomeInTheEnd()) { if (!ws.isAllowSetHomeInTheEnd()) {
user.sendMessage("commands.island.sethome.the-end.not-allowed"); user.sendMessage("commands.island.sethome.the-end.not-allowed");
return false; return false;
} }
// Check if a confirmation is required // Check if a confirmation is required
if (getIWM().getWorldSettings(user.getWorld()).isRequireConfirmationToSetHomeInTheEnd()) { if (ws.isRequireConfirmationToSetHomeInTheEnd()) {
askConfirmation(user, user.getTranslation("commands.island.sethome.the-end.confirmation"), () -> doSetHome(user, number)); askConfirmation(user, user.getTranslation("commands.island.sethome.the-end.confirmation"), () -> doSetHome(user, number));
} else { } else {
doSetHome(user, number); doSetHome(user, number);