use of com.iridium.iridiumskyblock.database.Island in project IridiumSkyblock by Iridium-Development.
the class SetCommand 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) {
if (args.length < 4) {
sender.sendMessage(StringUtils.color(syntax.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
OfflinePlayer player = Bukkit.getOfflinePlayer(args[2]);
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
Optional<Island> optionalIsland = user.getIsland();
if (!optionalIsland.isPresent()) {
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userNoIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
double amount;
try {
amount = Double.parseDouble(args[3]);
} catch (NumberFormatException exception) {
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notANumber.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
Island island = optionalIsland.get();
island.setExtraValue(amount);
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().extraValueSet.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%player%", player.getName()).replace("%amount%", String.valueOf(island.getExtraValue()))));
return true;
}
use of com.iridium.iridiumskyblock.database.Island in project IridiumSkyblock by Iridium-Development.
the class CurrentOffsetCommand 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 arguments The arguments used with this command. They contain the sub-command
*/
@Override
public boolean execute(CommandSender sender, String[] arguments) {
Player player = (Player) sender;
Location playerLocation = player.getLocation();
Optional<Island> islandOptional = IridiumSkyblock.getInstance().getIslandManager().getIslandViaPlayerLocation(player);
if (!islandOptional.isPresent()) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notOnAnIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
Location offset = playerLocation.subtract(islandOptional.get().getCenter(player.getWorld()));
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().islandCenterOffset.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%x%", String.valueOf(offset.getBlockX() + 0.5)).replace("%y%", String.valueOf(offset.getBlockY())).replace("%z%", String.valueOf(offset.getBlockZ() + 0.5)).replace("%yaw%", String.valueOf(playerLocation.getYaw()))));
return true;
}
use of com.iridium.iridiumskyblock.database.Island 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.Island 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.Island in project IridiumSkyblock by Iridium-Development.
the class PotionBrewListener method monitorPotionBrew.
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void monitorPotionBrew(BrewEvent event) {
// Delay the check so the new potion is checked
Bukkit.getScheduler().scheduleSyncDelayedTask(IridiumSkyblock.getInstance(), () -> {
Optional<Island> island = IridiumSkyblock.getInstance().getIslandManager().getIslandViaLocation(event.getBlock().getLocation());
for (int i = 0; i < 3; i++) {
ItemStack itemStack = event.getContents().getItem(i);
if (itemStack != null && itemStack.getItemMeta() instanceof PotionMeta) {
PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta();
island.ifPresent(value -> IridiumSkyblock.getInstance().getMissionManager().handleMissionUpdates(value, "BREW", potionMeta.getBasePotionData().getType() + ":" + (potionMeta.getBasePotionData().isUpgraded() ? 2 : 1), 1));
}
}
});
}
Aggregations