use of com.iridium.iridiumskyblock.database.User in project IridiumSkyblock by Iridium-Development.
the class PlayerMoveListener method onPlayerMove.
@EventHandler(ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
if (event.getTo().getBlockX() != event.getFrom().getBlockX() || event.getTo().getBlockZ() != event.getFrom().getBlockZ()) {
if (user.getTeleportingTask() != null) {
user.getTeleportingTask().cancel();
user.setTeleportingTask(null);
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().teleportCanceled.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
Optional<Island> island = IridiumSkyblock.getInstance().getIslandManager().getIslandViaPlayerLocation(player);
if (island.isPresent()) {
if (IridiumSkyblock.getInstance().getIslandManager().isBannedOnIsland(island.get(), user)) {
event.getPlayer().sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().youHaveBeenBanned.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%owner%", island.get().getOwner().getName()).replace("%name%", island.get().getName())));
PlayerUtils.teleportSpawn(player);
} else {
IslandSetting islandTimeSetting = IridiumSkyblock.getInstance().getIslandManager().getIslandSetting(island.get(), SettingType.TIME);
IslandSetting islandWeatherSetting = IridiumSkyblock.getInstance().getIslandManager().getIslandSetting(island.get(), SettingType.WEATHER);
IslandTime islandTime = IslandTime.valueOf(islandTimeSetting.getValue());
IslandWeatherType islandWeatherType = IslandWeatherType.valueOf(islandWeatherSetting.getValue());
if (islandWeatherType == IslandWeatherType.DEFAULT) {
player.resetPlayerWeather();
} else {
WeatherType newWeatherType = islandWeatherType == IslandWeatherType.CLEAR ? WeatherType.CLEAR : WeatherType.DOWNFALL;
if (player.getPlayerWeather() != newWeatherType) {
player.setPlayerWeather(newWeatherType);
}
}
if ((islandTime == IslandTime.DEFAULT && player.getPlayerTime() != player.getWorld().getTime()) || player.getPlayerTime() != islandTime.getTime()) {
player.setPlayerTime(islandTime.getTime(), islandTime.isRelative());
}
}
}
if (user.isFlying()) {
if (island.isPresent()) {
IslandBooster islandBooster = IridiumSkyblock.getInstance().getIslandManager().getIslandBooster(island.get(), "flight");
if (!islandBooster.isActive() && !player.hasPermission("iridiumskyblock.fly")) {
user.setFlying(false);
if (player.getGameMode().equals(GameMode.SURVIVAL) || player.getGameMode().equals(GameMode.ADVENTURE)) {
player.setFlying(false);
player.setAllowFlight(false);
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().flightDisabled.replace("%player%", player.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
}
} else if (!player.hasPermission("iridiumskyblock.fly")) {
user.setFlying(false);
if (player.getGameMode().equals(GameMode.SURVIVAL) || player.getGameMode().equals(GameMode.ADVENTURE)) {
player.setFlying(false);
player.setAllowFlight(false);
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().flightDisabled.replace("%player%", player.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
}
}
}
if (event.getTo().getY() < LocationUtils.getMinHeight(event.getTo().getWorld()) && IridiumSkyblock.getInstance().getConfiguration().voidTeleport && IridiumSkyblockAPI.getInstance().isIslandWorld(player.getWorld())) {
Optional<Island> island = IridiumSkyblock.getInstance().getIslandManager().getIslandViaPlayerLocation(player);
if (island.isPresent()) {
IridiumSkyblock.getInstance().getIslandManager().teleportHome(player, island.get(), 0);
} else {
Optional<Island> userIsland = user.getIsland();
if (userIsland.isPresent()) {
IridiumSkyblock.getInstance().getIslandManager().teleportHome(player, userIsland.get(), 0);
} else {
PlayerUtils.teleportSpawn(player);
}
}
}
}
use of com.iridium.iridiumskyblock.database.User in project IridiumSkyblock by Iridium-Development.
the class PlayerPortalListener method onPlayerPortal.
@EventHandler(ignoreCancelled = true)
public void onPlayerPortal(PlayerPortalEvent event) {
IslandManager islandManager = IridiumSkyblock.getInstance().getIslandManager();
final Optional<Island> island = IridiumSkyblock.getInstance().getIslandManager().getIslandViaLocation(event.getFrom());
if (!island.isPresent())
return;
final User user = IridiumSkyblock.getInstance().getUserManager().getUser(event.getPlayer());
if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), user, PermissionType.PORTAL)) {
if (hasNoCooldown(event.getPlayer())) {
event.getPlayer().sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotUsePortal.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
event.setCancelled(true);
return;
}
if (event.getCause() == PlayerTeleportEvent.TeleportCause.NETHER_PORTAL) {
if (IridiumSkyblock.getInstance().getConfiguration().netherIslands) {
World world = Objects.equals(event.getFrom().getWorld(), islandManager.getNetherWorld()) ? islandManager.getWorld() : islandManager.getNetherWorld();
event.setTo(island.get().getCenter(world));
return;
}
event.setCancelled(true);
if (hasNoCooldown(event.getPlayer())) {
event.getPlayer().sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().netherIslandsDisabled.replace("%prefix", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
return;
}
if (event.getCause().equals(PlayerTeleportEvent.TeleportCause.END_PORTAL)) {
event.setCancelled(true);
if (IridiumSkyblock.getInstance().getConfiguration().endIslands) {
World world = Objects.equals(event.getFrom().getWorld(), islandManager.getEndWorld()) ? islandManager.getWorld() : islandManager.getEndWorld();
event.getPlayer().teleport(LocationUtils.getSafeLocation(island.get().getCenter(world), island.get()));
return;
}
if (hasNoCooldown(event.getPlayer())) {
event.getPlayer().sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().endIslandsDisabled.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
}
}
use of com.iridium.iridiumskyblock.database.User in project IridiumSkyblock by Iridium-Development.
the class PlayerRespawnListener method onRespawn.
@EventHandler
public void onRespawn(PlayerRespawnEvent event) {
if (IridiumSkyblock.getInstance().getConfiguration().respawnOnIsland) {
User user = IridiumSkyblock.getInstance().getUserManager().getUser(event.getPlayer());
user.getIsland().ifPresent(island -> {
if (!island.isInIsland(event.getRespawnLocation())) {
event.setRespawnLocation(LocationUtils.getSafeLocation(island.getHome(), island));
}
});
}
}
use of com.iridium.iridiumskyblock.database.User in project IridiumSkyblock by Iridium-Development.
the class PlayerTeleportListener method onPlayerTeleport.
@EventHandler(ignoreCancelled = true)
public void onPlayerTeleport(PlayerTeleportEvent event) {
if (event.getTo() == null)
return;
User user = IridiumSkyblock.getInstance().getUserManager().getUser(event.getPlayer());
IridiumSkyblock.getInstance().getIslandManager().getIslandViaLocation(event.getTo()).ifPresent(island -> {
if (IridiumSkyblock.getInstance().getIslandManager().isBannedOnIsland(island, user)) {
event.getPlayer().sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().youHaveBeenBanned.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%owner%", island.getOwner().getName()).replace("%name%", island.getName())));
event.setCancelled(true);
} else {
Bukkit.getScheduler().runTaskLater(IridiumSkyblock.getInstance(), () -> PlayerUtils.sendBorder(event.getPlayer(), island), 1);
}
});
}
use of com.iridium.iridiumskyblock.database.User in project IridiumSkyblock by Iridium-Development.
the class Placeholders method getIslandPlaceholders.
private static Map<String, Placeholder> getIslandPlaceholders(String startKey, IslandGetter islandGetter) {
ImmutableMap.Builder<String, Placeholder> placeholderBuilder = ImmutableMap.<String, Placeholder>builder().put(startKey + "_name", player -> islandGetter.getIsland(player).map(Island::getName).orElse(placeholdersConfig.islandName)).put(startKey + "_owner", player -> islandGetter.getIsland(player).map(island -> island.getOwner().getName()).orElse(placeholdersConfig.islandOwner)).put(startKey + "_rank", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getNumberFormatter().format(island.getRank())).orElse(placeholdersConfig.islandRank)).put(startKey + "_level", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getNumberFormatter().format(island.getLevel())).orElse(placeholdersConfig.islandLevel)).put(startKey + "_value", player -> islandGetter.getIsland(player).map(Island::getFormattedValue).orElse(placeholdersConfig.islandValue)).put(startKey + "_extravalue", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getNumberFormatter().format(island.getExtraValue())).orElse(placeholdersConfig.islandExtraValue)).put(startKey + "_visitable", player -> islandGetter.getIsland(player).map(island -> island.isVisitable() ? IridiumSkyblock.getInstance().getMessages().visitable : IridiumSkyblock.getInstance().getMessages().notVisitable).orElse(placeholdersConfig.islandValue)).put(startKey + "_members", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getNumberFormatter().format(island.getMembers().size())).orElse(placeholdersConfig.islandMembers)).put(startKey + "_member_names", player -> islandGetter.getIsland(player).map(island -> island.getMembers().stream().map(User::getName).collect(Collectors.joining(", "))).orElse(placeholdersConfig.islandMemberNames)).put(startKey + "_visitors", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getNumberFormatter().format(IridiumSkyblock.getInstance().getIslandManager().getPlayersOnIsland(island).stream().filter(user -> !island.equals(user.getIsland().orElse(null))).count())).orElse(placeholdersConfig.islandVisitors)).put(startKey + "_visitor_names", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getIslandManager().getPlayersOnIsland(island).stream().filter(user -> !island.equals(user.getIsland().orElse(null))).map(User::getName).collect(Collectors.joining(", "))).orElse(placeholdersConfig.islandVisitorNames)).put(startKey + "_players", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getNumberFormatter().format(IridiumSkyblock.getInstance().getIslandManager().getPlayersOnIsland(island).size())).orElse(placeholdersConfig.islandPlayers)).put(startKey + "_player_names", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getIslandManager().getPlayersOnIsland(island).stream().map(User::getName).collect(Collectors.joining(", "))).orElse(placeholdersConfig.islandPlayerNames)).put(startKey + "_experience", player -> islandGetter.getIsland(player).map(Island::getFormattedExperience).orElse(placeholdersConfig.islandExperience)).put(startKey + "_experience_required", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getNumberFormatter().format(island.getExperienceRequiredToLevelUp())).orElse(placeholdersConfig.islandExperienceRequired)).put(startKey + "_experience_remaining", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getNumberFormatter().format(island.getExperienceRemainingToLevelUp())).orElse(placeholdersConfig.islandExperienceRemaining)).put(startKey + "_overworld_biome", player -> islandGetter.getIsland(player).map(island -> island.getCenter(IridiumSkyblock.getInstance().getIslandManager().getWorld()).getBlock()).map(Block::getBiome).map(biome -> WordUtils.capitalizeFully(biome.name().toLowerCase().replace("_", " "))).orElse(placeholdersConfig.islandBiome)).put(startKey + "_nether_biome", player -> islandGetter.getIsland(player).map(island -> island.getCenter(IridiumSkyblock.getInstance().getIslandManager().getNetherWorld()).getBlock()).map(Block::getBiome).map(biome -> WordUtils.capitalizeFully(biome.name().toLowerCase().replace("_", " "))).orElse(placeholdersConfig.islandBiome)).put(startKey + "_end_biome", player -> islandGetter.getIsland(player).map(island -> island.getCenter(IridiumSkyblock.getInstance().getIslandManager().getEndWorld()).getBlock()).map(Block::getBiome).map(biome -> WordUtils.capitalizeFully(biome.name().toLowerCase().replace("_", " "))).orElse(placeholdersConfig.islandBiome)).put(startKey + "_bank_experience", player -> islandGetter.getIsland(player).map(Island::getFormattedBankExperience).orElse(placeholdersConfig.islandBankExperience)).put(startKey + "_bank_crystals", player -> islandGetter.getIsland(player).map(Island::getFormattedCrystals).orElse(placeholdersConfig.islandBankCrystals)).put(startKey + "_bank_money", player -> islandGetter.getIsland(player).map(Island::getFormattedMoney).orElse(placeholdersConfig.islandBankMoney)).put(startKey + "_upgrade_blocklimit_level", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getNumberFormatter().format(islandManager.getIslandUpgrade(island, "blocklimit").getLevel())).orElse(placeholdersConfig.islandUpgradeBlocklimitLevel)).put(startKey + "_upgrade_member_level", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getNumberFormatter().format(islandManager.getIslandUpgrade(island, "member").getLevel())).orElse(placeholdersConfig.islandUpgradeMemberLevel)).put(startKey + "_upgrade_size_level", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getNumberFormatter().format(islandManager.getIslandUpgrade(island, "size").getLevel())).orElse(placeholdersConfig.islandUpgradeSizeLevel)).put(startKey + "_upgrade_generator_level", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getNumberFormatter().format(islandManager.getIslandUpgrade(island, "generator").getLevel())).orElse(placeholdersConfig.islandUpgradeGeneratorLevel)).put(startKey + "_upgrade_warp_level", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getNumberFormatter().format(islandManager.getIslandUpgrade(island, "warp").getLevel())).orElse(placeholdersConfig.islandUpgradeWarpLevel)).put(startKey + "_upgrade_member_amount", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getNumberFormatter().format(IridiumSkyblock.getInstance().getUpgrades().memberUpgrade.upgrades.get(islandManager.getIslandUpgrade(island, "member").getLevel()).amount)).orElse(placeholdersConfig.islandUpgradeMemberAmount)).put(startKey + "_upgrade_size_dimensions", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getNumberFormatter().format(IridiumSkyblock.getInstance().getUpgrades().sizeUpgrade.upgrades.get(islandManager.getIslandUpgrade(island, "size").getLevel()).size)).orElse(placeholdersConfig.islandUpgradeSizeDimensions)).put(startKey + "_upgrade_warp_amount", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getNumberFormatter().format(IridiumSkyblock.getInstance().getUpgrades().warpsUpgrade.upgrades.get(islandManager.getIslandUpgrade(island, "warp").getLevel()).amount)).orElse(placeholdersConfig.islandUpgradeWarpAmount));
// Boosters
for (String booster : IridiumSkyblock.getInstance().getBoosterList().keySet()) {
placeholderBuilder.put(startKey + "_booster_" + booster + "_remaining_minutes", player -> islandGetter.getIsland(player).map(island -> {
IslandBooster islandBooster = IridiumSkyblock.getInstance().getIslandManager().getIslandBooster(island, booster);
long minutes = LocalDateTime.now().until(islandBooster.getTime(), ChronoUnit.MINUTES);
return String.valueOf(Math.max(minutes, 0));
}).orElse(placeholdersConfig.islandBoosterRemainingMinutes));
placeholderBuilder.put(startKey + "_booster_" + booster + "_remaining_seconds", player -> islandGetter.getIsland(player).map(island -> {
IslandBooster islandBooster = IridiumSkyblock.getInstance().getIslandManager().getIslandBooster(island, booster);
long minutes = LocalDateTime.now().until(islandBooster.getTime(), ChronoUnit.MINUTES);
long seconds = LocalDateTime.now().until(islandBooster.getTime(), ChronoUnit.SECONDS) - minutes * 60;
return String.valueOf(Math.max(seconds, 0));
}).orElse(placeholdersConfig.islandBoosterRemainingSeconds));
}
return placeholderBuilder.build();
}
Aggregations