use of com.iridium.iridiumskyblock.database.User in project IridiumSkyblock by Iridium-Development.
the class UserManager method getUser.
/**
* Gets a {@link User}'s info. Creates one if he doesn't exist.
*
* @param offlinePlayer The player who's data should be fetched
* @return The user data
*/
@NotNull
public User getUser(@NotNull OfflinePlayer offlinePlayer) {
Optional<User> userOptional = getUserByUUID(offlinePlayer.getUniqueId());
if (userOptional.isPresent()) {
return userOptional.get();
} else {
Optional<String> name = Optional.ofNullable(offlinePlayer.getName());
User user = new User(offlinePlayer.getUniqueId(), name.orElse(""));
IridiumSkyblock.getInstance().getDatabaseManager().getUserTableManager().addEntry(user);
return user;
}
}
use of com.iridium.iridiumskyblock.database.User in project IridiumSkyblock by Iridium-Development.
the class IslandTrustedGUI 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) {
if (members.containsKey(event.getSlot())) {
User user = members.get(event.getSlot());
IridiumSkyblock.getInstance().getCommands().unTrustCommand.execute(event.getWhoClicked(), new String[] { "", user.getName() });
addContent(event.getInventory());
}
}
use of com.iridium.iridiumskyblock.database.User in project IridiumSkyblock by Iridium-Development.
the class IslandVisitorsGUI 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) {
final int size = IridiumSkyblock.getInstance().getInventories().bansGUI.size;
Player player = (Player) event.getWhoClicked();
if (event.getSlot() == size - 7 && page > 1) {
player.openInventory(new IslandVisitorsGUI(page - 1, getIsland()).getInventory());
return;
}
if (event.getSlot() == size - 3 && (size - 9) * page < visitors.size()) {
player.openInventory(new IslandVisitorsGUI(page + 1, getIsland()).getInventory());
return;
}
if (visitors.size() > event.getSlot()) {
User visitor = visitors.get(event.getSlot());
if (event.isLeftClick()) {
IridiumSkyblock.getInstance().getCommands().expelCommand.execute(event.getWhoClicked(), new String[] { "", visitor.getName() });
} else if (event.isRightClick()) {
IridiumSkyblock.getInstance().getCommands().banCommand.execute(event.getWhoClicked(), new String[] { "", visitor.getName() });
}
addContent(event.getInventory());
}
}
use of com.iridium.iridiumskyblock.database.User in project IridiumSkyblock by Iridium-Development.
the class EntityTargetListener method onEntityTargetEntity.
@EventHandler
public void onEntityTargetEntity(EntityTargetLivingEntityEvent event) {
if (IridiumSkyblock.getInstance().getConfiguration().pvpSettings.mobsVisitorTargeting)
return;
Optional<Island> island = IridiumSkyblock.getInstance().getIslandManager().getIslandViaLocation(event.getEntity().getLocation());
if (!island.isPresent())
return;
if (event.getTarget() == null || !(event.getTarget() instanceof Player))
return;
Player targetPlayer = (Player) event.getTarget();
User targetUser = IridiumSkyblock.getInstance().getUserManager().getUser(targetPlayer);
Optional<IslandTrusted> targetTrusted = IridiumSkyblock.getInstance().getIslandManager().getIslandTrusted(island.get(), targetUser);
if (island.get().equals(targetUser.getIsland().orElse(null)) || targetTrusted.isPresent())
return;
if (!canSearchTarget(event.getEntity())) {
return;
}
List<Player> nextTargets = event.getEntity().getNearbyEntities(8, 8, 8).stream().filter(entity -> entity instanceof Player).filter(entity -> island.get().isInIsland(entity.getLocation())).map(entity -> (Player) entity).filter(player -> player != targetPlayer).filter(player -> island.get().equals(IridiumSkyblock.getInstance().getUserManager().getUser(player).getIsland().orElse(null))).filter(player -> IridiumSkyblock.getInstance().getIslandManager().getIslandTrusted(island.get(), IridiumSkyblock.getInstance().getUserManager().getUser(player)).isPresent()).filter(player -> player.hasLineOfSight(event.getEntity())).collect(Collectors.toList());
if (nextTargets.isEmpty()) {
event.setCancelled(true);
return;
}
Player nextTarget = nextTargets.get(ThreadLocalRandom.current().nextInt(nextTargets.size()));
event.setTarget(nextTarget);
}
use of com.iridium.iridiumskyblock.database.User in project IridiumSkyblock by Iridium-Development.
the class PlayerChatListener method onPlayerChat.
@EventHandler(ignoreCancelled = true)
public void onPlayerChat(AsyncPlayerChatEvent event) {
User user = IridiumSkyblock.getInstance().getUserManager().getUser(event.getPlayer());
Optional<Island> island = user.getIsland();
if (user.isIslandChat() && island.isPresent()) {
event.setCancelled(true);
for (User islandUser : island.get().getMembers()) {
Player recipient = Bukkit.getPlayer(islandUser.getUuid());
if (recipient != null) {
recipient.sendMessage(StringUtils.color(StringUtils.processMultiplePlaceholders(IridiumSkyblock.getInstance().getMessages().islandMemberChat, new PlaceholderBuilder().applyIslandPlaceholders(island.get()).build()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%player%", event.getPlayer().getName()).replace("%message%", event.getMessage())));
}
}
for (Player player : Bukkit.getOnlinePlayers()) {
User onlineUser = IridiumSkyblockAPI.getInstance().getUser(player);
if (onlineUser.isIslandChatSpying()) {
player.sendMessage(StringUtils.color(StringUtils.processMultiplePlaceholders(IridiumSkyblock.getInstance().getMessages().islandChatSpyMessage, new PlaceholderBuilder().applyIslandPlaceholders(island.get()).build()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%island%", island.get().getName()).replace("%player%", event.getPlayer().getName()).replace("%message%", event.getMessage())));
}
}
} else {
String format = event.getFormat();
for (Map.Entry<String, Placeholders.Placeholder> entry : Placeholders.placeholders.entrySet()) {
if (format.contains(entry.getKey().toUpperCase())) {
format = format.replace(entry.getKey().toUpperCase(), entry.getValue().placeholderProcess(event.getPlayer()));
}
}
event.setFormat(format);
}
}
Aggregations