use of com.iridium.iridiumskyblock.database.Island in project IridiumSkyblock by Iridium-Development.
the class BoosterCommand method execute.
/**
* Executes the command for the specified {@link CommandSender} with the provided arguments.
* Not called when the command execution was invalid (no permission, no player or command disabled).
* Shows an overview over the members of the Island and allows quick rank management.
*
* @param sender The CommandSender which executes this command
* @param args The arguments used with this command. They contain the sub-command
*/
@Override
public boolean execute(CommandSender sender, String[] args) {
Player player = (Player) sender;
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
Optional<Island> island = user.getIsland();
if (!island.isPresent()) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
if (args.length != 2) {
player.openInventory(new IslandBoostersGUI(island.get(), player.getOpenInventory().getTopInventory()).getInventory());
return true;
}
String boosterName = args[1];
Booster booster = IridiumSkyblock.getInstance().getBoosterList().get(boosterName);
if (booster == null) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().unknownBooster.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
IslandBooster islandBooster = IridiumSkyblock.getInstance().getIslandManager().getIslandBooster(island.get(), boosterName);
if (islandBooster.isActive() && !booster.stackable) {
return false;
}
if (!PlayerUtils.pay(player, island.get(), booster.crystalsCost, booster.vaultCost)) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotAfford.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
islandBooster.setTime(LocalDateTime.now().plusSeconds(booster.time + (islandBooster.isActive() && booster.stackable ? islandBooster.getRemainingTime() : 0)));
IslandLog islandLog = new IslandLog(island.get(), LogAction.BOOSTER_PURCHASE, user, null, 0, boosterName);
IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().addEntry(islandLog);
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().successfullyBoughtBooster.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%booster%", IridiumSkyblock.getInstance().getBoosterList().get(islandBooster.getBooster()).name).replace("%vault_cost%", IridiumSkyblock.getInstance().getNumberFormatter().format(booster.vaultCost)).replace("%crystal_cost%", IridiumSkyblock.getInstance().getNumberFormatter().format(booster.crystalsCost))));
return true;
}
use of com.iridium.iridiumskyblock.database.Island in project IridiumSkyblock by Iridium-Development.
the class BorderCommand method execute.
/**
* Executes the command for the specified {@link CommandSender} with the provided arguments.
* Not called when the command execution was invalid (no permission, no player or command disabled).
* Changes the Island Border
*
* @param sender The CommandSender which executes this command
* @param args The arguments used with this command. They contain the sub-command
*/
@Override
public boolean execute(CommandSender sender, String[] args) {
Player player = (Player) sender;
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
Optional<Island> island = user.getIsland();
if (!island.isPresent()) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), IridiumSkyblock.getInstance().getUserManager().getUser(player), PermissionType.BORDER)) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotManageBorder.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
if (args.length != 2) {
player.openInventory(new InventoryConfigGUI(IridiumSkyblock.getInstance().getInventories().islandBorder, player.getOpenInventory().getTopInventory()).getInventory());
return true;
}
Color color = Color.getColor(args[1]);
if (color == null) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notAColor.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
if (!IridiumSkyblock.getInstance().getBorder().enabled.getOrDefault(color, true)) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().borderColorDisabled.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
island.get().setColor(color);
island.get().getMembers().stream().map(islandUser -> Bukkit.getPlayer(islandUser.getUuid())).filter(Objects::nonNull).forEach(islandPlayer -> islandPlayer.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().islandBorderChanged.replace("%player%", player.getName()).replace("%color%", color.toString()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))));
return true;
}
use of com.iridium.iridiumskyblock.database.Island in project IridiumSkyblock by Iridium-Development.
the class LogsCommand method execute.
/**
* Executes the command for the specified {@link CommandSender} with the provided arguments.
* Not called when the command execution was invalid (no permission, no player or command disabled).
*
* @param sender The CommandSender which executes this command
* @param args The arguments used with this command. They contain the sub-command
*/
@Override
public boolean execute(CommandSender sender, String[] args) {
Player player = (Player) sender;
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
Optional<Island> island = user.getIsland();
if (!island.isPresent()) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
player.openInventory(new IslandLogsGUI(island.get(), player.getOpenInventory().getTopInventory()).getInventory());
return true;
}
use of com.iridium.iridiumskyblock.database.Island in project IridiumSkyblock by Iridium-Development.
the class ExperienceBankItem method deposit.
/**
* Deposits the given amount of this item to the Player's bank.
*
* @param player The player who wants to deposit
* @param amount The amount which should be deposited
*/
@Override
public double deposit(Player player, Number amount) {
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
Optional<Island> island = user.getIsland();
if (island.isPresent()) {
IslandBank islandBank = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(island.get(), this);
int experience = Math.min(amount.intValue(), PlayerUtils.getTotalExperience(player));
if (experience > 0) {
islandBank.setNumber(islandBank.getNumber() + experience);
PlayerUtils.setTotalExperience(player, PlayerUtils.getTotalExperience(player) - experience);
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().bankDeposited.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)).replace("%amount%", String.valueOf(experience)).replace("%type%", getDisplayName()));
} else {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().insufficientFundsToDeposit.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)).replace("%type%", getDisplayName()));
}
return experience;
} else {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
return 0;
}
use of com.iridium.iridiumskyblock.database.Island in project IridiumSkyblock by Iridium-Development.
the class BanCommand method execute.
/**
* Executes the command for the specified {@link CommandSender} with the provided arguments.
* Not called when the command execution was invalid (no permission, no player or command disabled).
* Bans a player visiting from an island
*
* @param sender The CommandSender which executes this command
* @param args The arguments used with this command. They contain the sub-command
*/
@Override
public boolean execute(CommandSender sender, String[] args) {
if (args.length > 2) {
sender.sendMessage(StringUtils.color(syntax.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
Player player = (Player) sender;
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
Optional<Island> island = user.getIsland();
if (!island.isPresent()) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
if (args.length == 1) {
player.openInventory(new IslandBansGUI(1, island.get(), player.getOpenInventory().getTopInventory()).getInventory());
return false;
}
if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), user, PermissionType.BAN)) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noPermission.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
Player targetPlayer = Bukkit.getPlayer(args[1]);
if (targetPlayer == null) {
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notAPlayer.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
User targetUser = IridiumSkyblock.getInstance().getUserManager().getUser(targetPlayer);
if (island.get().equals(targetUser.getIsland().orElse(null)) || IridiumSkyblock.getInstance().getIslandManager().getIslandTrusted(island.get(), targetUser).isPresent()) {
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().inYourTeam.replace("%player%", targetUser.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
if (targetUser.isBypassing() || targetPlayer.hasPermission("iridiumskyblock.visitbypass")) {
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotBanned.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
if (IridiumSkyblock.getInstance().getIslandManager().isBannedOnIsland(island.get(), targetUser)) {
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().alreadyBanned.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
IridiumSkyblock.getInstance().getDatabaseManager().getIslandBanTableManager().addEntry(new IslandBan(island.get(), user, targetUser));
if (island.get().isInIsland(targetPlayer.getLocation())) {
PlayerUtils.teleportSpawn(targetPlayer);
targetPlayer.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().youHaveBeenBanned.replace("%player%", user.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().playerBanned.replace("%player%", targetUser.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return true;
}
Aggregations