use of com.iridium.iridiumskyblock.database.User 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.iridiumskyblock.database.User in project IridiumSkyblock by Iridium-Development.
the class PlayerInteractListener method onPlayerInteractEntity.
@EventHandler(ignoreCancelled = true)
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
Player player = event.getPlayer();
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
Optional<Island> island = IridiumSkyblock.getInstance().getIslandManager().getIslandViaLocation(event.getRightClicked().getLocation());
if (!island.isPresent())
return;
if (IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), user, PermissionType.INTERACT_ENTITIES)) {
return;
}
event.setCancelled(true);
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotInteractEntities.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
use of com.iridium.iridiumskyblock.database.User in project IridiumSkyblock by Iridium-Development.
the class IslandMembersGUI method addContent.
@Override
public void addContent(Inventory inventory) {
inventory.clear();
members.clear();
InventoryUtils.fillInventory(inventory, IridiumSkyblock.getInstance().getInventories().membersGUI.background);
AtomicInteger slot = new AtomicInteger(0);
for (User user : getIsland().getMembers()) {
int itemSlot = slot.getAndIncrement();
inventory.setItem(itemSlot, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().membersGUI.item, new PlaceholderBuilder().applyPlayerPlaceholders(user).applyIslandPlaceholders(getIsland()).build()));
members.put(itemSlot, user);
}
}
use of com.iridium.iridiumskyblock.database.User in project IridiumSkyblock by Iridium-Development.
the class IslandRanksGUI method addContent.
@Override
public void addContent(Inventory inventory) {
inventory.clear();
IslandRanksInventoryConfig islandRanks = IridiumSkyblock.getInstance().getInventories().islandRanksGUI;
InventoryUtils.fillInventory(inventory, islandRanks.background);
List<User> members = IridiumSkyblock.getInstance().getIslandManager().getIslandMembers(getIsland());
inventory.setItem(islandRanks.owner.slot, ItemStackUtils.makeItem(islandRanks.owner, Collections.singletonList(new Placeholder("members", getIsland().getOwner().getName()))));
inventory.setItem(islandRanks.coOwner.slot, ItemStackUtils.makeItem(islandRanks.coOwner, Collections.singletonList(new Placeholder("members", members.stream().filter(member -> member.getIslandRank().equals(IslandRank.CO_OWNER)).map(User::getName).collect(Collectors.joining(", "))))));
inventory.setItem(islandRanks.moderator.slot, ItemStackUtils.makeItem(islandRanks.moderator, Collections.singletonList(new Placeholder("members", members.stream().filter(member -> member.getIslandRank().equals(IslandRank.MODERATOR)).map(User::getName).collect(Collectors.joining(", "))))));
inventory.setItem(islandRanks.member.slot, ItemStackUtils.makeItem(islandRanks.member, Collections.singletonList(new Placeholder("members", members.stream().filter(member -> member.getIslandRank().equals(IslandRank.MEMBER)).map(User::getName).collect(Collectors.joining(", "))))));
inventory.setItem(islandRanks.visitor.slot, ItemStackUtils.makeItem(islandRanks.visitor));
if (IridiumSkyblock.getInstance().getConfiguration().backButtons && getPreviousInventory() != null) {
inventory.setItem(inventory.getSize() + IridiumSkyblock.getInstance().getInventories().backButton.slot, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().backButton));
}
}
use of com.iridium.iridiumskyblock.database.User in project IridiumSkyblock by Iridium-Development.
the class IslandRegenGUI method selectSchematic.
/**
* Executed when the player selects the Island schematic.
*
* @param schematicConfig The data of the selected schematic
*/
@Override
public void selectSchematic(Map.Entry<String, Schematics.SchematicConfig> schematicConfig) {
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
Optional<Island> island = user.getIsland();
IslandRegenSettings regenSettings = IridiumSkyblock.getInstance().getConfiguration().regenSettings;
if (island.isPresent()) {
if (PlayerUtils.pay(player, island.get(), regenSettings.crystalPrice, regenSettings.moneyPrice)) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().regeneratingIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
IridiumSkyblock.getInstance().getIslandManager().regenerateIsland(island.get(), user, schematicConfig.getValue());
cooldownProvider.applyCooldown(player);
} else {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotAfford.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
} else {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
}
Aggregations