Search in sources :

Example 11 with Island

use of com.iridium.iridiumskyblock.database.Island in project IridiumSkyblock by Iridium-Development.

the class EntityDeathListener method monitorEntityDeath.

@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void monitorEntityDeath(EntityDeathEvent event) {
    if (!IridiumSkyblockAPI.getInstance().isIslandWorld(event.getEntity().getWorld()))
        return;
    Player player = event.getEntity().getKiller();
    if (player == null)
        return;
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
    Optional<Island> island = user.getIsland();
    island.ifPresent(value -> {
        IridiumSkyblock.getInstance().getMissionManager().handleMissionUpdates(value, "KILL", event.getEntityType().name(), 1);
        IslandBooster islandBooster = IridiumSkyblock.getInstance().getIslandManager().getIslandBooster(island.get(), "experience");
        if (islandBooster.isActive()) {
            event.setDroppedExp(event.getDroppedExp() * 2);
        }
    });
}
Also used : Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) IslandBooster(com.iridium.iridiumskyblock.database.IslandBooster) Island(com.iridium.iridiumskyblock.database.Island) EventHandler(org.bukkit.event.EventHandler)

Example 12 with Island

use of com.iridium.iridiumskyblock.database.Island in project IridiumSkyblock by Iridium-Development.

the class HomeCommand 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).
 * Teleports users to their Island home.
 *
 * @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()) {
        IridiumSkyblock.getInstance().getIslandManager().teleportHome(player, island.get(), IridiumSkyblock.getInstance().getConfiguration().teleportDelay);
        return true;
    } else if (IridiumSkyblock.getInstance().getConfiguration().createIslandOnHome) {
        IridiumSkyblock.getInstance().getCommands().createCommand.execute(player, new String[] {});
        return true;
    } else {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
}
Also used : Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) Island(com.iridium.iridiumskyblock.database.Island)

Example 13 with Island

use of com.iridium.iridiumskyblock.database.Island in project IridiumSkyblock by Iridium-Development.

the class InfoCommand 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 infos about an Island.
 *
 * @param sender    The CommandSender which executes this command
 * @param arguments The arguments used with this command. They contain the sub-command
 */
@Override
public boolean execute(CommandSender sender, String[] arguments) {
    if (arguments.length == 1) {
        if (!(sender instanceof Player)) {
            sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().mustBeAPlayer.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
            return false;
        }
        Player player = (Player) sender;
        User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
        Optional<Island> userIsland = user.getIsland();
        if (!userIsland.isPresent()) {
            sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
            return false;
        }
        sendInfo(sender, userIsland.get(), user);
        return true;
    }
    OfflinePlayer targetPlayer = Bukkit.getOfflinePlayer(arguments[1]);
    User targetUser = IridiumSkyblock.getInstance().getUserManager().getUser(targetPlayer);
    Optional<Island> targetIsland = targetUser.getIsland();
    if (!targetIsland.isPresent()) {
        sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userNoIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    sendInfo(sender, targetIsland.get(), targetUser);
    return true;
}
Also used : Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) User(com.iridium.iridiumskyblock.database.User) OfflinePlayer(org.bukkit.OfflinePlayer) Island(com.iridium.iridiumskyblock.database.Island)

Example 14 with Island

use of com.iridium.iridiumskyblock.database.Island in project IridiumSkyblock by Iridium-Development.

the class JoinCommand 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).
 * Enables users to join other Islands.
 *
 * @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);
    if (user.getIsland().isPresent()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().alreadyHaveIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(args[1]);
    User offlinePlayerUser = IridiumSkyblock.getInstance().getUserManager().getUser(offlinePlayer);
    Optional<Island> island = offlinePlayerUser.getIsland();
    if (!island.isPresent()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userNoIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    Optional<IslandInvite> islandInvite = IridiumSkyblock.getInstance().getIslandManager().getIslandInvite(island.get(), user);
    if (!islandInvite.isPresent() && !user.isBypassing()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noInvite.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    IslandUpgrade islandUpgrade = IridiumSkyblock.getInstance().getIslandManager().getIslandUpgrade(island.get(), "member");
    int memberLimit = IridiumSkyblock.getInstance().getUpgrades().memberUpgrade.upgrades.get(islandUpgrade.getLevel()).amount;
    if (!user.isBypassing() && island.get().getMembers().size() >= memberLimit) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().islandMemberLimitReached.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    Optional<User> inviter = islandInvite.map(IslandInvite::getInviter);
    UserJoinEvent userJoinEvent = new UserJoinEvent(island.get(), user, inviter.orElse(null));
    Bukkit.getPluginManager().callEvent(userJoinEvent);
    if (userJoinEvent.isCancelled())
        return false;
    // Send a message to all other members
    for (User member : island.get().getMembers()) {
        Player islandMember = Bukkit.getPlayer(member.getName());
        if (islandMember != null) {
            islandMember.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().playerJoinedYourIsland.replace("%player%", player.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        }
    }
    user.setIsland(island.get());
    user.setIslandRank(IslandRank.MEMBER);
    islandInvite.ifPresent(invite -> IridiumSkyblock.getInstance().getDatabaseManager().getIslandInviteTableManager().delete(invite));
    IridiumSkyblock.getInstance().getIslandManager().teleportHome(player, island.get(), 0);
    IslandLog islandLog = new IslandLog(island.get(), LogAction.USER_JOINED, user, null, 0, "");
    IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().addEntry(islandLog);
    return true;
}
Also used : IslandUpgrade(com.iridium.iridiumskyblock.database.IslandUpgrade) IslandLog(com.iridium.iridiumskyblock.database.IslandLog) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) User(com.iridium.iridiumskyblock.database.User) OfflinePlayer(org.bukkit.OfflinePlayer) IslandInvite(com.iridium.iridiumskyblock.database.IslandInvite) UserJoinEvent(com.iridium.iridiumskyblock.api.UserJoinEvent) Island(com.iridium.iridiumskyblock.database.Island)

Example 15 with Island

use of com.iridium.iridiumskyblock.database.Island in project IridiumSkyblock by Iridium-Development.

the class KickCommand 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 user 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;
    }
    OfflinePlayer targetPlayer = Bukkit.getOfflinePlayer(args[1]);
    User targetUser = IridiumSkyblock.getInstance().getUserManager().getUser(targetPlayer);
    if (!island.get().equals(targetUser.getIsland().orElse(null))) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userNotInYourIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    if (targetUser.getIslandRank().getLevel() >= user.getIslandRank().getLevel() || !IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), user, PermissionType.KICK)) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotKickUser.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    UserKickEvent userKickEvent = new UserKickEvent(island.get(), targetUser, user);
    Bukkit.getPluginManager().callEvent(userKickEvent);
    if (userKickEvent.isCancelled())
        return false;
    if (targetPlayer instanceof Player) {
        ((Player) targetPlayer).sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().youHaveBeenKicked.replace("%player%", player.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        PlayerUtils.teleportSpawn((Player) targetPlayer);
    }
    targetUser.setIsland(null);
    // Send a message to all other members
    for (User member : island.get().getMembers()) {
        Player islandMember = Bukkit.getPlayer(member.getUuid());
        if (islandMember != null) {
            if (!islandMember.equals(player)) {
                islandMember.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().kickedPlayer.replace("%kicker%", player.getName()).replace("%player%", targetUser.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
            } else {
                islandMember.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().youKickedPlayer.replace("%player%", targetUser.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
            }
        }
    }
    IslandLog islandLog = new IslandLog(island.get(), LogAction.USER_KICKED, user, targetUser, 0, "");
    IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().addEntry(islandLog);
    return true;
}
Also used : UserKickEvent(com.iridium.iridiumskyblock.api.UserKickEvent) IslandLog(com.iridium.iridiumskyblock.database.IslandLog) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) User(com.iridium.iridiumskyblock.database.User) OfflinePlayer(org.bukkit.OfflinePlayer) Island(com.iridium.iridiumskyblock.database.Island)

Aggregations

Island (com.iridium.iridiumskyblock.database.Island)92 User (com.iridium.iridiumskyblock.database.User)76 Player (org.bukkit.entity.Player)60 EventHandler (org.bukkit.event.EventHandler)18 List (java.util.List)16 IridiumSkyblock (com.iridium.iridiumskyblock.IridiumSkyblock)15 OfflinePlayer (org.bukkit.OfflinePlayer)15 Collectors (java.util.stream.Collectors)14 IslandLog (com.iridium.iridiumskyblock.database.IslandLog)12 Optional (java.util.Optional)11 StringUtils (com.iridium.iridiumcore.utils.StringUtils)10 IslandBank (com.iridium.iridiumskyblock.database.IslandBank)10 Duration (java.time.Duration)10 Collections (java.util.Collections)9 CommandSender (org.bukkit.command.CommandSender)9 XMaterial (com.iridium.iridiumcore.dependencies.xseries.XMaterial)7 PlaceholderBuilder (com.iridium.iridiumskyblock.PlaceholderBuilder)6 BankItem (com.iridium.iridiumskyblock.bank.BankItem)6 IslandBooster (com.iridium.iridiumskyblock.database.IslandBooster)6 Bukkit (org.bukkit.Bukkit)6