use of com.iridium.iridiumskyblock.database.User 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.User 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.User in project IridiumSkyblock by Iridium-Development.
the class IslandMembersGUI method onInventoryClick.
/**
* Called when there is a click in this GUI.
* Cancelled automatically.
*
* @param event The InventoryClickEvent provided by Bukkit
*/
@Override
public void onInventoryClick(InventoryClickEvent event) {
if (members.containsKey(event.getSlot())) {
User user = members.get(event.getSlot());
switch(event.getClick()) {
case LEFT:
IridiumSkyblock.getInstance().getCommands().demoteCommand.execute(event.getWhoClicked(), new String[] { "", user.getName() });
break;
case RIGHT:
IridiumSkyblock.getInstance().getCommands().promoteCommand.execute(event.getWhoClicked(), new String[] { "", user.getName() });
break;
}
addContent(event.getInventory());
}
}
use of com.iridium.iridiumskyblock.database.User in project IridiumSkyblock by Iridium-Development.
the class IslandPermissionsGUI method onInventoryClick.
/**
* Called when there is a click in this GUI.
* Cancelled automatically.
*
* @param event The InventoryClickEvent provided by Bukkit
*/
@Override
public void onInventoryClick(InventoryClickEvent event) {
for (Map.Entry<String, Permission> permission : IridiumSkyblock.getInstance().getPermissionList().entrySet()) {
if (permission.getValue().getItem().slot != event.getSlot())
continue;
if (permission.getValue().getPage() != page)
continue;
if (!permission.getValue().isModifiable())
continue;
User user = IridiumSkyblock.getInstance().getUserManager().getUser((Player) event.getWhoClicked());
if (user.getIslandRank().getLevel() <= islandRank.getLevel() || !IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(getIsland(), user, PermissionType.CHANGE_PERMISSIONS)) {
event.getWhoClicked().sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotChangePermissions.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
} else {
boolean allowed = IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(getIsland(), islandRank, permission.getValue(), permission.getKey());
IridiumSkyblock.getInstance().getIslandManager().setIslandPermission(getIsland(), islandRank, permission.getKey(), !allowed);
event.getWhoClicked().openInventory(getInventory());
}
return;
}
if (event.getSlot() == getNoItemGUI().size - 7 && hasPage(page - 1)) {
page--;
event.getWhoClicked().openInventory(getInventory());
return;
}
if (event.getSlot() == getNoItemGUI().size - 3 && hasPage(page + 1)) {
page++;
event.getWhoClicked().openInventory(getInventory());
}
}
use of com.iridium.iridiumskyblock.database.User in project IridiumSkyblock by Iridium-Development.
the class BlockPlaceListener method monitorBlockPlace.
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void monitorBlockPlace(BlockPlaceEvent event) {
if (!IridiumSkyblockAPI.getInstance().isIslandWorld(event.getBlock().getWorld()))
return;
Player player = event.getPlayer();
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
XMaterial material = XMaterial.matchXMaterial(event.getBlock().getType());
user.getIsland().ifPresent(island -> {
IridiumSkyblock.getInstance().getMissionManager().handleMissionUpdates(island, "PLACE", material.name(), 1);
IslandBlocks islandBlocks = IridiumSkyblock.getInstance().getIslandManager().getIslandBlock(island, material);
islandBlocks.setAmount(islandBlocks.getAmount() + 1);
if (event.getBlock().getState() instanceof CreatureSpawner) {
CreatureSpawner creatureSpawner = (CreatureSpawner) event.getBlock().getState();
IslandSpawners islandSpawners = IridiumSkyblock.getInstance().getIslandManager().getIslandSpawners(island, creatureSpawner.getSpawnedType());
islandSpawners.setAmount(islandSpawners.getAmount() + 1);
}
});
}
Aggregations