use of com.iridium.iridiumskyblock.database.Island in project IridiumSkyblock by Iridium-Development.
the class DeleteCommand 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).
* Deletes a User's 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.hasPermission("iridiumskyblock.delete.other")) {
Optional<Island> islandOptional = IridiumSkyblockAPI.getInstance().getUser(Bukkit.getOfflinePlayer(args[1])).getIsland();
if (!islandOptional.isPresent()) {
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userNoIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
} else {
IridiumSkyblock.getInstance().getIslandManager().deleteIsland(islandOptional.get(), null);
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().otherIslandDeleted.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
return false;
}
if (!(sender instanceof Player)) {
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notAPlayer).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 (!user.getIslandRank().equals(IslandRank.OWNER)) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotDeleteIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
player.openInventory(new ConfirmationGUI(() -> IridiumSkyblock.getInstance().getIslandManager().deleteIsland(island.get(), user), getCooldownProvider()).getInventory());
// Always return false because the cooldown is set by the ConfirmationGUI
return false;
}
use of com.iridium.iridiumskyblock.database.Island in project IridiumSkyblock by Iridium-Development.
the class DeleteWarpCommand 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) {
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 (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), IridiumSkyblock.getInstance().getUserManager().getUser(player), PermissionType.MANAGE_WARPS)) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotManageWarps.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
List<IslandWarp> islandWarps = IridiumSkyblock.getInstance().getDatabaseManager().getIslandWarpTableManager().getEntries(island.get());
Optional<IslandWarp> islandWarp = islandWarps.stream().filter(warp -> warp.getName().equalsIgnoreCase(args[1])).findFirst();
if (!islandWarp.isPresent()) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().unknownWarp.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().deletingWarp.replace("%name%", islandWarp.get().getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
IridiumSkyblock.getInstance().getDatabaseManager().getIslandWarpTableManager().delete(islandWarp.get());
return true;
}
use of com.iridium.iridiumskyblock.database.Island in project IridiumSkyblock by Iridium-Development.
the class DepositCommand 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).
* Deposits a currency into the Island bank.
*
* @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 != 3) {
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;
}
Optional<BankItem> bankItem = IridiumSkyblock.getInstance().getBankItemList().stream().filter(item -> item.getName().equalsIgnoreCase(args[1])).findFirst();
if (!bankItem.isPresent()) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noSuchBankItem.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
try {
double amount = bankItem.get().deposit(player, Double.parseDouble(args[2]));
if (amount > 0) {
IslandLog islandLog = new IslandLog(island.get(), LogAction.BANK_DEPOSIT, user, null, amount, bankItem.get().getName());
IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().addEntry(islandLog);
}
return true;
} catch (NumberFormatException exception) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notANumber.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
}
use of com.iridium.iridiumskyblock.database.Island in project IridiumSkyblock by Iridium-Development.
the class ExpelCommand 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).
* Kicks a visitor 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 IslandVisitorsGUI(1, island.get()).getInventory());
return true;
}
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 (!island.get().isInIsland(targetPlayer.getLocation())) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userNotVisitingYourIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
if (targetUser.isBypassing() || targetPlayer.hasPermission("iridiumskyblock.visitbypass")) {
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotExpelPlayer.replace("%player%", targetUser.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), user, PermissionType.EXPEL)) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noPermission.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
targetPlayer.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().youHaveBeenExpelled.replace("%player%", user.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().expelledVisitor.replace("%player%", targetUser.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
PlayerUtils.teleportSpawn(targetPlayer);
return true;
}
use of com.iridium.iridiumskyblock.database.Island in project IridiumSkyblock by Iridium-Development.
the class BlockPlaceListener method onBlockPlaceEvent.
@EventHandler(ignoreCancelled = true)
public void onBlockPlaceEvent(BlockPlaceEvent event) {
Player player = event.getPlayer();
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
Optional<Island> island = IridiumSkyblock.getInstance().getIslandManager().getIslandViaLocation(event.getBlock().getLocation());
if (!island.isPresent()) {
World world = event.getBlock().getLocation().getWorld();
if (IridiumSkyblockAPI.getInstance().isIslandWorld(world)) {
if (!user.isBypassing())
event.setCancelled(true);
}
return;
}
XMaterial material = XMaterial.matchXMaterial(event.getBlock().getType());
if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), user, PermissionType.BLOCK_PLACE)) {
event.setCancelled(true);
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotPlaceBlocks.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return;
}
int limitUpgradeLevel = IridiumSkyblock.getInstance().getIslandManager().getIslandUpgrade(island.get(), "blocklimit").getLevel();
int blockLimit = IridiumSkyblock.getInstance().getUpgrades().blockLimitUpgrade.upgrades.get(limitUpgradeLevel).limits.getOrDefault(material, 0);
if (blockLimit > 0 && IridiumSkyblock.getInstance().getIslandManager().getIslandBlockAmount(island.get(), material) >= blockLimit) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().blockLimitReached.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%limit%", String.valueOf(blockLimit)).replace("%block%", WordUtils.capitalizeFully(material.name().toLowerCase().replace("_", " ")))));
event.setCancelled(true);
}
}
Aggregations