use of com.iridium.iridiumskyblock.gui.IslandTrustedGUI in project IridiumSkyblock by Iridium-Development.
the class TrustCommand 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).
* Shows an overview over the members of the Island and allows quick rank management.
*
* @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) {
Player player = (Player) sender;
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
Optional<Island> island = user.getIsland();
if (!island.isPresent()) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), IridiumSkyblock.getInstance().getUserManager().getUser(player), PermissionType.TRUST)) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotManageTrusts.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
if (args.length != 2) {
player.openInventory(new IslandTrustedGUI(island.get()).getInventory());
return true;
}
Player targetPlayer = Bukkit.getPlayer(args[1]);
if (targetPlayer == null) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notAPlayer.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
User targetUser = IridiumSkyblock.getInstance().getUserManager().getUser(targetPlayer);
if (targetUser.getIsland().map(Island::getId).orElse(0) == island.get().getId()) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().alreadyInYourIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
if (IridiumSkyblock.getInstance().getIslandManager().getIslandTrusted(island.get(), targetUser).isPresent()) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().alreadyTrusted.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
IslandTrusted islandTrusted = new IslandTrusted(island.get(), targetUser, user);
IridiumSkyblock.getInstance().getDatabaseManager().getIslandTrustedTableManager().addEntry(islandTrusted);
island.get().getMembers().stream().map(user1 -> Bukkit.getPlayer(user1.getUuid())).filter(Objects::nonNull).forEach(onlineMember -> onlineMember.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().trustedPlayer.replace("%truster%", player.getName()).replace("%player%", targetPlayer.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))));
targetPlayer.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().playerTrustedYou.replace("%truster%", player.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
IslandLog islandLog = new IslandLog(island.get(), LogAction.USER_TRUSTED, user, targetUser, 0, "");
IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().addEntry(islandLog);
return true;
}
Aggregations