mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-14 12:11:32 +01:00
Made IslandSethomeCommand a ConfirmableCommand
#237 It adds a bunch of WorldSettings and updates the en-US locale as well!
This commit is contained in:
parent
09ce51259d
commit
ec2793e6f8
@ -1,13 +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.UUID;
|
|
||||||
|
|
||||||
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.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
|
||||||
public class IslandSethomeCommand extends CompositeCommand {
|
public class IslandSethomeCommand extends ConfirmableCommand {
|
||||||
|
|
||||||
public IslandSethomeCommand(CompositeCommand islandCommand) {
|
public IslandSethomeCommand(CompositeCommand islandCommand) {
|
||||||
super(islandCommand, "sethome");
|
super(islandCommand, "sethome");
|
||||||
@ -23,7 +23,6 @@ public class IslandSethomeCommand extends CompositeCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(User user, String label, List<String> args) {
|
public boolean execute(User user, String label, List<String> args) {
|
||||||
UUID playerUUID = user.getUniqueId();
|
|
||||||
// Check island
|
// Check island
|
||||||
if (getPlugin().getIslands().getIsland(getWorld(), user.getUniqueId()) == null) {
|
if (getPlugin().getIslands().getIsland(getWorld(), user.getUniqueId()) == null) {
|
||||||
user.sendMessage("general.errors.no-island");
|
user.sendMessage("general.errors.no-island");
|
||||||
@ -35,8 +34,8 @@ public class IslandSethomeCommand extends CompositeCommand {
|
|||||||
}
|
}
|
||||||
if (args.isEmpty()) {
|
if (args.isEmpty()) {
|
||||||
// island sethome
|
// island sethome
|
||||||
getPlugin().getPlayers().setHomeLocation(playerUUID, user.getLocation());
|
setHome(user, 1);
|
||||||
user.sendMessage("commands.island.sethome.home-set");
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// Dynamic home sizes with permissions
|
// Dynamic home sizes with permissions
|
||||||
int maxHomes = user.getPermissionValue(getPermissionPrefix() + "island.maxhomes", getIWM().getMaxHomes(getWorld()));
|
int maxHomes = user.getPermissionValue(getPermissionPrefix() + "island.maxhomes", getIWM().getMaxHomes(getWorld()));
|
||||||
@ -49,8 +48,8 @@ public class IslandSethomeCommand extends CompositeCommand {
|
|||||||
user.sendMessage("commands.island.sethome.num-homes", TextVariables.NUMBER, String.valueOf(maxHomes));
|
user.sendMessage("commands.island.sethome.num-homes", TextVariables.NUMBER, String.valueOf(maxHomes));
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
getPlugin().getPlayers().setHomeLocation(user, user.getLocation(), number);
|
setHome(user, number);
|
||||||
user.sendMessage("commands.island.sethome.home-set");
|
return true;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
user.sendMessage("commands.island.sethome.num-homes", TextVariables.NUMBER, String.valueOf(maxHomes));
|
user.sendMessage("commands.island.sethome.num-homes", TextVariables.NUMBER, String.valueOf(maxHomes));
|
||||||
@ -61,7 +60,45 @@ public class IslandSethomeCommand extends CompositeCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
if (!getIWM().getWorldSettings(user.getLocation().getWorld()).isAllowSetHomeInNether()) {
|
||||||
|
user.sendMessage("commands.island.sethome.nether.not-allowed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if a confirmation is required
|
||||||
|
if (getIWM().getWorldSettings(user.getLocation().getWorld()).isRequireConfirmationToSetHomeInNether()) {
|
||||||
|
askConfirmation(user, "commands.island.sethome.nether.confirmation", setHomeRunnable);
|
||||||
|
} else {
|
||||||
|
setHomeRunnable.run();
|
||||||
|
}
|
||||||
|
} 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
|
||||||
|
if (!getIWM().getWorldSettings(user.getLocation().getWorld()).isAllowSetHomeInTheEnd()) {
|
||||||
|
user.sendMessage("commands.island.sethome.the-end.not-allowed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if a confirmation is required
|
||||||
|
if (getIWM().getWorldSettings(user.getLocation().getWorld()).isRequireConfirmationToSetHomeInTheEnd()) {
|
||||||
|
askConfirmation(user, "commands.island.sethome.the-end.confirmation", setHomeRunnable);
|
||||||
|
} else {
|
||||||
|
setHomeRunnable.run();
|
||||||
|
}
|
||||||
|
} else { // The player is in the Overworld, no need to run a check
|
||||||
|
setHomeRunnable.run();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -257,4 +257,24 @@ public interface WorldSettings {
|
|||||||
*/
|
*/
|
||||||
boolean isDeathsCounted();
|
boolean isDeathsCounted();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return whether a player can set their home in the Nether or not.
|
||||||
|
*/
|
||||||
|
boolean isAllowSetHomeInNether();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return whether a player can set their home in the End or not.
|
||||||
|
*/
|
||||||
|
boolean isAllowSetHomeInTheEnd();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return whether a confirmation is required when a player tries to set their home in the Nether.
|
||||||
|
*/
|
||||||
|
boolean isRequireConfirmationToSetHomeInNether();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return whether a confirmation is required when a player tries to set their home in the End.
|
||||||
|
*/
|
||||||
|
boolean isRequireConfirmationToSetHomeInTheEnd();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -246,6 +246,12 @@ commands:
|
|||||||
must-be-on-your-island: "&cYou must be on your island to set home!"
|
must-be-on-your-island: "&cYou must be on your island to set home!"
|
||||||
num-homes: "&cHomes can be 1 to [number]."
|
num-homes: "&cHomes can be 1 to [number]."
|
||||||
home-set: "&6Your island home has been set to your current location."
|
home-set: "&6Your island home has been set to your current location."
|
||||||
|
nether:
|
||||||
|
not-allowed: "&cYou are not allowed to set your home in the Nether."
|
||||||
|
confirmation: "&cAre you sure you want to set your home in the Nether?"
|
||||||
|
the-end:
|
||||||
|
not-allowed: "&cYou are not allowed to set your home in the End."
|
||||||
|
confirmation: "&cAre you sure you want to set your home in the End?"
|
||||||
parameters: "[home number]"
|
parameters: "[home number]"
|
||||||
setname:
|
setname:
|
||||||
description: "set a name for your island"
|
description: "set a name for your island"
|
||||||
|
Loading…
Reference in New Issue
Block a user