Search in sources :

Example 1 with IslandSetting

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

the class EntityExplodeListener method onEntityExplode.

@EventHandler(ignoreCancelled = true)
public void onEntityExplode(EntityExplodeEvent event) {
    List<MetadataValue> list = event.getEntity().getMetadata("island_spawned");
    if (list.isEmpty())
        return;
    int islandId = list.get(0).asInt();
    IridiumSkyblock.getInstance().getIslandManager().getIslandById(islandId).ifPresent(island -> {
        IslandSetting tntExplosion = IridiumSkyblock.getInstance().getIslandManager().getIslandSetting(island, SettingType.TNT_DAMAGE);
        if (!tntExplosion.getBooleanValue()) {
            event.setCancelled(true);
            return;
        }
        if (!island.isInIsland(event.getLocation())) {
            event.setCancelled(true);
            return;
        }
        event.blockList().removeIf(block -> !island.isInIsland(block.getLocation()));
    });
}
Also used : MetadataValue(org.bukkit.metadata.MetadataValue) IslandSetting(com.iridium.iridiumskyblock.database.IslandSetting) EventHandler(org.bukkit.event.EventHandler)

Example 2 with IslandSetting

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

the class IslandSettingsGUI 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) {
    Player player = (Player) event.getWhoClicked();
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
    if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(getIsland(), user, PermissionType.ISLAND_SETTINGS)) {
        event.getWhoClicked().sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotChangeSettings.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return;
    }
    for (Map.Entry<String, Setting> setting : IridiumSkyblock.getInstance().getSettingsList().entrySet()) {
        if (event.getSlot() != setting.getValue().getItem().slot)
            continue;
        if (!setting.getValue().isModifiable())
            continue;
        SettingType settingType = SettingType.getByName(setting.getKey());
        IslandSetting islandSetting = IridiumSkyblock.getInstance().getIslandManager().getIslandSetting(getIsland(), settingType);
        String newValue = (event.getClick() == ClickType.RIGHT ? settingType.getNext() : settingType.getPrevious()).getNew(islandSetting.getValue());
        IslandSettingChangeEvent islandSettingChangeEvent = new IslandSettingChangeEvent(player, getIsland(), settingType, newValue);
        Bukkit.getPluginManager().callEvent(islandSettingChangeEvent);
        if (islandSettingChangeEvent.isCancelled())
            return;
        newValue = islandSettingChangeEvent.getNewValue();
        islandSetting.setValue(newValue);
        settingType.getOnChange().run(getIsland(), newValue);
        addContent(event.getInventory());
    }
}
Also used : Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) IslandSetting(com.iridium.iridiumskyblock.database.IslandSetting) IslandSetting(com.iridium.iridiumskyblock.database.IslandSetting) Setting(com.iridium.iridiumskyblock.Setting) SettingType(com.iridium.iridiumskyblock.SettingType) IslandSettingChangeEvent(com.iridium.iridiumskyblock.api.IslandSettingChangeEvent) Map(java.util.Map)

Example 3 with IslandSetting

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

the class IslandSettingsGUI method addContent.

@Override
public void addContent(Inventory inventory) {
    inventory.clear();
    InventoryUtils.fillInventory(inventory, IridiumSkyblock.getInstance().getInventories().islandSettingsGUI.background);
    for (Map.Entry<String, Setting> setting : IridiumSkyblock.getInstance().getSettingsList().entrySet()) {
        if (!setting.getValue().isModifiable())
            continue;
        IslandSetting islandSetting = IridiumSkyblock.getInstance().getIslandManager().getIslandSetting(getIsland(), setting.getKey(), setting.getValue().getDefaultValue());
        inventory.setItem(setting.getValue().getItem().slot, ItemStackUtils.makeItem(setting.getValue().getItem(), Collections.singletonList(new Placeholder("value", WordUtils.capitalize(islandSetting.getValue().toLowerCase().replace("_", " "))))));
    }
    if (IridiumSkyblock.getInstance().getConfiguration().backButtons && getPreviousInventory() != null) {
        inventory.setItem(inventory.getSize() + IridiumSkyblock.getInstance().getInventories().backButton.slot, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().backButton));
    }
}
Also used : Placeholder(com.iridium.iridiumcore.utils.Placeholder) IslandSetting(com.iridium.iridiumskyblock.database.IslandSetting) IslandSetting(com.iridium.iridiumskyblock.database.IslandSetting) Setting(com.iridium.iridiumskyblock.Setting) Map(java.util.Map)

Example 4 with IslandSetting

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

the class BlockExplodeListener method onBlockExplode.

@EventHandler(ignoreCancelled = true)
public void onBlockExplode(BlockExplodeEvent event) {
    IridiumSkyblock.getInstance().getIslandManager().getIslandViaLocation(event.getBlock().getLocation()).ifPresent(island -> {
        IslandSetting tntExplosion = IridiumSkyblock.getInstance().getIslandManager().getIslandSetting(island, SettingType.TNT_DAMAGE);
        if (!tntExplosion.getBooleanValue()) {
            event.setCancelled(true);
            return;
        }
        event.blockList().removeIf(block -> !island.isInIsland(block.getLocation()));
    });
}
Also used : IslandSetting(com.iridium.iridiumskyblock.database.IslandSetting) EventHandler(org.bukkit.event.EventHandler)

Example 5 with IslandSetting

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

the class EntitySpawnListener method onEntitySpawn.

@EventHandler(ignoreCancelled = true)
public void onEntitySpawn(EntitySpawnEvent event) {
    IridiumSkyblock.getInstance().getIslandManager().getIslandViaLocation(event.getLocation()).ifPresent(island -> {
        IslandSetting mobSpawnSetting = IridiumSkyblock.getInstance().getIslandManager().getIslandSetting(island, SettingType.MOB_SPAWN);
        // Exception for ArmorStands because they're a LivingEntity
        if (!mobSpawnSetting.getBooleanValue() && event.getEntity() instanceof LivingEntity && event.getEntityType() != EntityType.ARMOR_STAND) {
            event.setCancelled(true);
            return;
        }
        event.getEntity().setMetadata("island_spawned", new FixedMetadataValue(IridiumSkyblock.getInstance(), island.getId()));
    });
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) IslandSetting(com.iridium.iridiumskyblock.database.IslandSetting) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) EventHandler(org.bukkit.event.EventHandler)

Aggregations

IslandSetting (com.iridium.iridiumskyblock.database.IslandSetting)6 EventHandler (org.bukkit.event.EventHandler)4 Setting (com.iridium.iridiumskyblock.Setting)2 User (com.iridium.iridiumskyblock.database.User)2 Map (java.util.Map)2 Player (org.bukkit.entity.Player)2 Placeholder (com.iridium.iridiumcore.utils.Placeholder)1 IslandTime (com.iridium.iridiumskyblock.IslandTime)1 IslandWeatherType (com.iridium.iridiumskyblock.IslandWeatherType)1 SettingType (com.iridium.iridiumskyblock.SettingType)1 IslandSettingChangeEvent (com.iridium.iridiumskyblock.api.IslandSettingChangeEvent)1 Island (com.iridium.iridiumskyblock.database.Island)1 IslandBooster (com.iridium.iridiumskyblock.database.IslandBooster)1 WeatherType (org.bukkit.WeatherType)1 LivingEntity (org.bukkit.entity.LivingEntity)1 FixedMetadataValue (org.bukkit.metadata.FixedMetadataValue)1 MetadataValue (org.bukkit.metadata.MetadataValue)1