use of com.iridium.iridiumcore.dependencies.xseries.XMaterial in project IridiumSkyblock by Iridium-Development.
the class FurnaceSmeltListener method monitorFurnaceSmelt.
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void monitorFurnaceSmelt(FurnaceSmeltEvent event) {
Optional<Island> island = IridiumSkyblock.getInstance().getIslandManager().getIslandViaLocation(event.getBlock().getLocation());
XMaterial material = XMaterial.matchXMaterial(event.getSource().getType());
island.ifPresent(value -> IridiumSkyblock.getInstance().getMissionManager().handleMissionUpdates(value, "SMELT", material.name(), 1));
}
use of com.iridium.iridiumcore.dependencies.xseries.XMaterial in project IridiumSkyblock by Iridium-Development.
the class PlayerInteractListener method onPlayerInteract.
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
user.getIsland().ifPresent(island -> {
if (event.getAction() != Action.PHYSICAL) {
int islandCrystals = IridiumSkyblock.getInstance().getIslandManager().getIslandCrystals(event.getPlayer().getInventory().getItemInMainHand());
if (islandCrystals > 0) {
// Required because Spigot likes to trigger this event for each hand which removes two items
if (event.getHand() == EquipmentSlot.HAND) {
int amount = event.getPlayer().getInventory().getItemInMainHand().getAmount();
if (amount == 1) {
event.getPlayer().getInventory().setItemInMainHand(null);
} else {
event.getPlayer().getInventory().getItemInMainHand().setAmount(amount - 1);
}
IslandBank islandBank = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(island, IridiumSkyblock.getInstance().getBankItems().crystalsBankItem);
islandBank.setNumber(islandBank.getNumber() + islandCrystals);
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().bankDeposited.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%type%", IridiumSkyblock.getInstance().getBankItems().crystalsBankItem.getDisplayName()).replace("%amount%", String.valueOf(islandCrystals))));
event.setCancelled(true);
}
}
}
});
if (event.getClickedBlock() == null)
return;
IridiumSkyblock.getInstance().getIslandManager().getIslandViaLocation(event.getClickedBlock().getLocation()).ifPresent(island -> {
XMaterial material = XMaterial.matchXMaterial(event.getClickedBlock().getType());
String materialName = material.name();
if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island, user, PermissionType.INTERACT)) {
event.setCancelled(true);
if (hasNoCooldown(player)) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotInteract.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
return;
}
if (event.getAction() == Action.PHYSICAL && material == XMaterial.FARMLAND) {
if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island, user, PermissionType.TRAMPLE_CROPS)) {
event.setCancelled(true);
if (hasNoCooldown(player)) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotTrampleCrops.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
}
} else if (materialName.contains("DOOR")) {
if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island, user, PermissionType.DOORS)) {
event.setCancelled(true);
if (hasNoCooldown(player)) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotOpenDoors.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
}
} else if (event.getClickedBlock().getState() instanceof InventoryHolder) {
if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island, user, PermissionType.OPEN_CONTAINERS)) {
event.setCancelled(true);
if (hasNoCooldown(player)) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotOpenContainers.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
}
} else if (redstoneMaterials.contains(material) || materialName.contains("BUTTON") || materialName.contains("PRESSURE_PLATE")) {
if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island, user, PermissionType.REDSTONE)) {
event.setCancelled(true);
if (hasNoCooldown(player)) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotUseRedstone.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
}
} else if (materialName.contains("MINECART") || materialName.contains("BOAT") || materialName.contains("EGG") || materialName.contains("BUCKET") || material == XMaterial.END_CRYSTAL || material == XMaterial.ARMOR_STAND) {
if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island, user, PermissionType.INTERACT_ENTITIES)) {
event.setCancelled(true);
if (hasNoCooldown(player)) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotSpawnEntities.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
}
}
});
}
use of com.iridium.iridiumcore.dependencies.xseries.XMaterial in project IridiumSkyblock by Iridium-Development.
the class BlockBreakListener method monitorBlockBreak.
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void monitorBlockBreak(BlockBreakEvent 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 -> {
BlockData blockData = event.getBlock().getBlockData();
if (blockData instanceof Ageable) {
Ageable ageable = (Ageable) blockData;
if (ageable.getAge() == ageable.getMaximumAge()) {
IridiumSkyblock.getInstance().getMissionManager().handleMissionUpdates(island, "MINE", material.name(), 1);
}
} else {
IridiumSkyblock.getInstance().getMissionManager().handleMissionUpdates(island, "MINE", material.name(), 1);
}
IslandBooster islandBooster = IridiumSkyblock.getInstance().getIslandManager().getIslandBooster(island, "experience");
if (islandBooster.isActive()) {
event.setExpToDrop(event.getExpToDrop() * 2);
}
IslandBlocks islandBlocks = IridiumSkyblock.getInstance().getIslandManager().getIslandBlock(island, material);
if (islandBlocks.getAmount() > 0) {
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());
if (islandSpawners.getAmount() > 0) {
islandSpawners.setAmount(islandSpawners.getAmount() - 1);
}
}
});
}
use of com.iridium.iridiumcore.dependencies.xseries.XMaterial in project IridiumSkyblock by Iridium-Development.
the class BlockBreakListener method onBlockBreak.
@EventHandler(ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
Player player = event.getPlayer();
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
Optional<Island> island = IridiumSkyblock.getInstance().getIslandManager().getIslandViaLocation(event.getBlock().getLocation());
if (!island.isPresent())
return;
XMaterial material = XMaterial.matchXMaterial(event.getBlock().getType());
if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), user, PermissionType.BLOCK_BREAK)) {
event.setCancelled(true);
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotBreakBlocks.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
} else if (material.equals(XMaterial.SPAWNER) && !IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), user, PermissionType.SPAWNERS)) {
event.setCancelled(true);
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotMineSpawners.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
}
use of com.iridium.iridiumcore.dependencies.xseries.XMaterial in project IridiumSkyblock by Iridium-Development.
the class BlockFormListener method onBlockForm.
@EventHandler(ignoreCancelled = true)
public void onBlockForm(BlockFormEvent event) {
if (!IridiumSkyblockAPI.getInstance().isIslandWorld(event.getBlock().getWorld()))
return;
XMaterial newMaterial = XMaterial.matchXMaterial(event.getNewState().getType());
// Custom basalt generators should only work in nether
if (newMaterial == XMaterial.COBBLESTONE || newMaterial == XMaterial.STONE || (newMaterial == XMaterial.BASALT && event.getBlock().getLocation().getWorld().getEnvironment() == World.Environment.NETHER)) {
Optional<Island> island = IridiumSkyblock.getInstance().getIslandManager().getIslandViaLocation(event.getNewState().getLocation());
if (island.isPresent()) {
int upgradeLevel = IridiumSkyblock.getInstance().getIslandManager().getIslandUpgrade(island.get(), "generator").getLevel();
RandomAccessList<XMaterial> randomMaterialList = newMaterial == XMaterial.BASALT ? netherOreLevels.get(upgradeLevel) : normalOreLevels.get(upgradeLevel);
if (randomMaterialList == null)
return;
Optional<XMaterial> xMaterialOptional = randomMaterialList.nextElement();
if (!xMaterialOptional.isPresent())
return;
Material material = xMaterialOptional.get().parseMaterial();
if (material == Material.COBBLESTONE && newMaterial == XMaterial.STONE)
material = Material.STONE;
if (material != null)
event.getNewState().setType(material);
}
}
}
Aggregations