use of pizzaaxx.bteconosur.coords.Coords2D in project bteConoSurCore by BTEConoSur.
the class ProjectCommand method onEvent.
@Override
public void onEvent(@NotNull GenericEvent event) {
if (event instanceof MessageReceivedEvent) {
MessageReceivedEvent e = (MessageReceivedEvent) event;
if (e.getMessage().getContentRaw().startsWith("/")) {
String fullCommand = e.getMessage().getContentRaw();
String[] args = fullCommand.replaceFirst("/", "").split(" ");
if (args.length > 0) {
if (args[0].equals("project")) {
if (args.length > 1 && args[1].matches("[a-z]{6}")) {
try {
Project project = new Project(args[1]);
// DIFICULTAD
CompletableFuture.runAsync(() -> {
EmbedBuilder embed = new EmbedBuilder();
if (project.getDifficulty() == Project.Difficulty.DIFICIL) {
embed.setColor(new Color(255, 0, 0));
embed.addField(":tools: Dificultad: ", ":red_circle: Difícil", false);
} else if (project.getDifficulty() == Project.Difficulty.INTERMEDIO) {
embed.setColor(new Color(255, 220, 0));
embed.addField(":tools: Dificultad: ", ":yellow_circle: Intermedio", false);
} else {
embed.setColor(new Color(0, 255, 42));
embed.addField(":tools: Dificultad: ", ":green_circle: Fácil", false);
}
if (project.getOwner() != null) {
embed.setThumbnail("https://mc-heads.net/head/" + project.getOwner().getUniqueId().toString());
}
if (!Objects.equals(project.getName(), project.getId())) {
embed.setTitle("Proyecto \"" + project.getName() + "\" (ID: " + project.getId().toUpperCase() + ")");
} else {
embed.setTitle("Proyecto " + project.getId().toUpperCase());
}
// PAIS
embed.addField(":globe_with_meridians: País:", ":flag_" + project.getCountry().getAbbreviation() + ": " + StringUtils.capitalize(project.getCountry().getName()), false);
if (project.getTag() != null) {
embed.addField(":label: Etiqueta:", project.getTag().toString().toLowerCase().replace("edificios", ":cityscape: Edificios").replace("casas", ":house_with_garden: Casas").replace("departamentos", ":hotel: Departamentos").replace("centros_comerciales", ":shpping_bags: Centros Comerciales").replace("establecimientos", ":hospital: Establecimientos").replace("parques", ":deciduous_tree: Parques").replace("carreteras", ":motorway: Carreteras"), false);
}
// GOOGLE MAPS
double minX = project.getPoints().get(0).getX();
double maxX = project.getPoints().get(0).getX();
double minZ = project.getPoints().get(0).getZ();
double maxZ = project.getPoints().get(0).getZ();
for (BlockVector2D point : project.getPoints()) {
if (point.getX() > maxX) {
maxX = point.getX();
}
if (point.getX() < minX) {
minX = point.getX();
}
if (point.getZ() > maxZ) {
maxZ = point.getZ();
}
if (point.getZ() < minZ) {
minZ = point.getZ();
}
}
Coords2D geoCoord = new Coords2D(new Location(mainWorld, (minX + maxX) / 2, 100, (minZ + maxZ) / 2));
embed.addField(":round_pushpin: Coordenadas:", ("> " + geoCoord.getX() + " " + geoCoord.getHighestY() + " " + geoCoord.getZ()).replace(".5", "").replace(".0", ""), false);
embed.addField(":map: Google Maps:", "https://www.google.com/maps/@" + geoCoord.getLat() + "," + geoCoord.getLon() + ",19z", false);
if (project.getOwner() != null) {
embed.addField(":crown: Líder:", new ServerPlayer(project.getOwner()).getName(), false);
}
if (!project.getMembers().isEmpty()) {
List<String> members = new ArrayList<>();
for (OfflinePlayer player : project.getMembers()) {
members.add(new ServerPlayer(player).getName());
}
embed.addField(":busts_in_silhouette: Miembros:", String.join(", ", members), false);
}
// IMAGE
InputStream file;
try {
file = new URL(project.getImageUrl()).openStream();
} catch (IOException ex) {
ex.printStackTrace();
return;
}
embed.setImage("attachment://map.png");
e.getTextChannel().sendFile(file, "map.png").setEmbeds(embed.build()).reference(e.getMessage()).mentionRepliedUser(false).queue();
});
} catch (Exception exception) {
exception.printStackTrace();
EmbedBuilder error = new EmbedBuilder();
error.setColor(new Color(255, 0, 0));
error.setAuthor("Este proyecto no existe.");
e.getMessage().replyEmbeds(error.build()).mentionRepliedUser(false).queue();
}
} else {
EmbedBuilder error = new EmbedBuilder();
error.setColor(new Color(255, 0, 0));
error.setAuthor("Introduce un proyecto válido.");
e.getMessage().replyEmbeds(error.build()).mentionRepliedUser(false).queue();
}
}
if (args[0].equals("pending")) {
if (YamlManager.getYamlData(pluginFolder, "pending_projects/pending.yml").size() != 0) {
EmbedBuilder pending = new EmbedBuilder();
pending.setColor(new Color(0, 255, 42));
List<String> lines = new ArrayList<>();
List<String> projects = new Configuration(Bukkit.getPluginManager().getPlugin("bteConoSur"), "pending_projects/pending").getStringList("pending");
for (String str : projects) {
try {
Project project = new Project(str);
String line = "• :flag_" + project.getCountry().getAbbreviation() + ": " + project.getId();
if (!Objects.equals(project.getName(), project.getId())) {
line = line + " - " + project.getName();
}
lines.add(line);
} catch (Exception ignored) {
}
}
Collections.sort(lines);
String value = String.join("\n", lines);
pending.addField("Proyectos pendientes de revisión:", value, false);
e.getTextChannel().sendMessageEmbeds(pending.build()).reference(e.getMessage()).mentionRepliedUser(false).queue();
} else {
EmbedBuilder noPending = new EmbedBuilder();
noPending.setColor(new Color(255, 0, 0));
noPending.setAuthor("No hay proyectos pendientes de revisión.");
e.getTextChannel().sendMessageEmbeds(noPending.build()).reference(e.getMessage()).mentionRepliedUser(false).queue();
}
}
}
}
}
}
use of pizzaaxx.bteconosur.coords.Coords2D in project bteConoSurCore by BTEConoSur.
the class Project method getImageUrl.
public String getImageUrl() {
if (points != null && points.size() > 1) {
List<String> coords = new ArrayList<>();
for (BlockVector2D point : this.points) {
coords.add(new Coords2D(point).getLat() + "," + new Coords2D(point).getLon());
}
coords.add(new Coords2D(this.points.get(0)).getLat() + "," + new Coords2D(this.points.get(0)).getLon());
return "https://open.mapquestapi.com/staticmap/v5/map?key=" + key + "&type=sat&shape=" + String.join("|", coords) + "|fill:6382DC50&size=1920,1080&imagetype=png";
}
return null;
}
use of pizzaaxx.bteconosur.coords.Coords2D in project bteConoSurCore by BTEConoSur.
the class pFind method onInventoryClick.
@EventHandler
public void onInventoryClick(InventoryClickEvent e) {
if (e.getInventory().getName().equals("1. Elige una dificultad")) {
e.setCancelled(true);
if (e.getSlot() == 11 || e.getSlot() == 13 || e.getSlot() == 15) {
Project.Difficulty difficulty;
if (e.getSlot() == 11) {
difficulty = Project.Difficulty.FACIL;
} else if (e.getSlot() == 13) {
difficulty = Project.Difficulty.INTERMEDIO;
} else {
difficulty = Project.Difficulty.DIFICIL;
}
pRandomDifficulties.put((Player) e.getWhoClicked(), difficulty);
Inventory pRandomGui = Bukkit.createInventory(null, 27, "2. Elige un tipo de proyecto");
ItemStack glass = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 15);
ItemMeta gMeta = glass.getItemMeta();
gMeta.setDisplayName(" ");
glass.setItemMeta(gMeta);
for (int i = 0; i < 27; i++) {
pRandomGui.setItem(i, glass);
}
OldCountry country = new OldCountry(e.getWhoClicked().getLocation());
Map<Project.Tag, List<String>> availableProjects = getAvailableProjects(country, difficulty);
int available = availableProjects.get(EDIFICIOS).size();
pRandomGui.setItem(10, getCustomHead("§aEdificios", "§fEdificios de oficinas y otros edificios de gran magnitud.\n\n" + "§aDisponibles: §f" + available, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOWY2YmIzYWQ4ZGFmMGMxNDk5YjVlNDZkY2Y0MTc2YzgzNDU0MzU1M2ExYTgxODAwOWU3Njc1ZTg5NjI5NWUxYSJ9fX0="));
available = availableProjects.get(CASAS).size();
pRandomGui.setItem(11, getCustomHead("§aCasas", "§fBarrios residenciales y/o con tiendas y empresas de menor tamaño.\n\n" + "§aDisponibles: §f" + available, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvY2Y3Y2RlZWZjNmQzN2ZlY2FiNjc2YzU4NGJmNjIwODMyYWFhYzg1Mzc1ZTlmY2JmZjI3MzcyNDkyZDY5ZiJ9fX0="));
available = availableProjects.get(DEPARTAMENTOS).size();
pRandomGui.setItem(12, getCustomHead("§aDepartamentos", "§fEdificios residenciales, hoteles, y otros edificios de tamaño medio.\n\n" + "§aDisponibles: §f" + available, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDk5MTBjZjYwMGQyMWEwNDA0ZDlkZjRiMGQ2NTllZDQ4NDE4NmFlMDYxNDI3MGY3YTY0MjlmNzA0ZDBiZGJjOSJ9fX0="));
available = availableProjects.get(CENTROS_COMERCIALES).size();
pRandomGui.setItem(13, getCustomHead("§aCentros comerciales", "§fFranjas comerciales, malls, supermercados, fábricas.\n\n" + "§aDisponibles: §f" + available, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYTAzYmQwMDQyMTcyOWNkNjM1Y2QzYjQ4MjQzNDMwYWQ0N2NmNzA3MDE4YTU5MTZmZjU5NTQ5ZDVlY2Q2Zjg3OSJ9fX0="));
available = availableProjects.get(ESTABLECIMIENTOS).size();
pRandomGui.setItem(14, getCustomHead("§aEstablecimientos", "§fColegios, universidades, bancos, museos, estaciones, lugares históricos, iglesias, etc.\n\n" + "§aDisponibles: §f" + available, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZWVlOGQ2ZjVjYjdhMzVhNGRkYmRhNDZmMDQ3ODkxNWRkOWViYmNlZjkyNGViOGNhMjg4ZTkxZDE5YzhjYiJ9fX0="));
available = availableProjects.get(PARQUES).size();
pRandomGui.setItem(15, getCustomHead("§aParques", "§fGrandes áreas verdes y otros lugares abiertos como canchas de deportes o cerros.\n\n" + "§aDisponibles: §f" + available, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZWExZmJlZjNkMGM1MWFkNmM3MTNhYTIwYzQyZGIxODM0MzRjZWM0ZmI2M2E1YTNlYWExMDFhZDNjNWY3NWQxNSJ9fX0="));
available = availableProjects.get(CARRETERAS).size();
pRandomGui.setItem(16, getCustomHead("§aCarreteras", "§fCarreteras, caminos, túneles, puentes, intersecciones, etc.\n\n" + "§aDisponibles: §f" + available, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOGRjMGJmZmZiNTg1YjNkNGU2ZThkM2Y5Y2JiMzAzZGUyZjUyZjIwMTQ4OGQ4MjEwZmE4Y2RjNDBiYmFkNTg4ZCJ9fX0="));
pRandomGui.setItem(26, getCustomHead("Volver", null, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMzdhZWU5YTc1YmYwZGY3ODk3MTgzMDE1Y2NhMGIyYTdkNzU1YzYzMzg4ZmYwMTc1MmQ1ZjQ0MTlmYzY0NSJ9fX0="));
e.getWhoClicked().openInventory(pRandomGui);
}
}
if (e.getInventory().getName().equals("2. Elige un tipo de proyecto")) {
e.setCancelled(true);
if (e.getSlot() >= 10 && e.getSlot() <= 16) {
Project.Tag tag;
if (e.getSlot() == 10) {
tag = EDIFICIOS;
} else if (e.getSlot() == 11) {
tag = CASAS;
} else if (e.getSlot() == 12) {
tag = DEPARTAMENTOS;
} else if (e.getSlot() == 13) {
tag = CENTROS_COMERCIALES;
} else if (e.getSlot() == 14) {
tag = ESTABLECIMIENTOS;
} else if (e.getSlot() == 15) {
tag = PARQUES;
} else {
tag = CARRETERAS;
}
List<String> projects = getAvailableProjects(new OldCountry(e.getWhoClicked().getLocation()), pRandomDifficulties.get((Player) e.getWhoClicked())).get(tag);
Player p = (Player) e.getWhoClicked();
if (projects.size() > 0) {
double minDistance = 100000000.0;
Project closest = new Project(projects.get(0));
BlockVector2D loc1 = new BlockVector2D(p.getLocation().getX(), p.getLocation().getZ());
for (String id : projects) {
Project project = new Project(id);
if (loc1.distance(project.getAverageCoordinate()) < minDistance) {
minDistance = loc1.distance(project.getAverageCoordinate());
closest = project;
}
}
Coords2D closestLoc = new Coords2D(closest.getAverageCoordinate());
p.teleport(new Location(mainWorld, closest.getAverageCoordinate().getBlockX(), closestLoc.getHighestY(), closest.getAverageCoordinate().getBlockZ()));
p.sendMessage(projectsPrefix + "¡Proyecto encontrado!");
p.sendMessage(projectsPrefix + "Usa §a/project info §fpara ver información del proyecto.");
p.sendMessage(projectsPrefix + "Usa §a/project borders §fpara ver los bordes del proyecto.");
p.sendMessage(projectsPrefix + "Usa §a/project claim §fpara reclamar el proyecto.");
} else {
p.closeInventory();
p.sendMessage(projectsPrefix + "No hay proyectos §a" + pRandomDifficulties.get((Player) e.getWhoClicked()).toString().replace("dificil", "§aDIFÍCILES").replace("facil", "§aFÁCILES").replace("intermiedio", "§aINTERMEDIOS") + "§f de tipo §a" + tag.toString().replace("_", " ").toUpperCase() + "§f disponibles en §a" + new OldCountry(e.getWhoClicked().getLocation()).getName().toUpperCase() + "§f.");
BukkitRunnable runnable = new BukkitRunnable() {
@Override
public void run() {
((Player) e.getWhoClicked()).performCommand("p find");
}
};
runnable.runTaskLater(Bukkit.getPluginManager().getPlugin("bteConoSur"), 30);
}
} else if (e.getSlot() == 26) {
((Player) e.getWhoClicked()).performCommand("p find");
}
}
}
use of pizzaaxx.bteconosur.coords.Coords2D in project bteConoSurCore by BTEConoSur.
the class PlayerCommand method onMessageReceived.
@Override
public void onMessageReceived(@NotNull MessageReceivedEvent event) {
CompletableFuture.runAsync(() -> {
Message message = event.getMessage();
TextChannel textChannel = message.getTextChannel();
String contentRaw = message.getContentRaw();
if (contentRaw.startsWith(COMMAND_PREFIX)) {
String[] args = contentRaw.replaceFirst("/", "").split(" ");
if (args.length > 0 && args[0].equals(COMMAND)) {
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(args[1]);
ServerPlayer serverPlayer = null;
if (offlinePlayer.hasPlayedBefore()) {
serverPlayer = new ServerPlayer(offlinePlayer);
} else {
String id;
if (args[1].startsWith("<@!")) {
id = args[1].replace("<@!", "").replace(">", "");
} else {
id = args[1];
}
User user = conoSurBot.retrieveUserById(id).complete();
if (user != null) {
try {
serverPlayer = new ServerPlayer(user);
} catch (Exception e) {
textChannel.sendMessageEmbeds(new EmbedBuilder().setColor(ERROR_COLOR).setAuthor("El usuario introducido no tiene una cuenta de Minecraft conectada.").build()).reference(message).mentionRepliedUser(false).queue();
}
}
}
final boolean[] hasFile = { false };
final InputStream[] file = { null };
EmbedBuilder embedBuilder = new EmbedBuilder();
if (serverPlayer != null) {
embedBuilder.setTitle(serverPlayer.getName());
offlinePlayer = serverPlayer.getPlayer();
if (offlinePlayer.isOnline()) {
org.bukkit.entity.Player player = offlinePlayer.getPlayer();
OldCountry country = new OldCountry(player.getLocation());
Coords2D coords = new Coords2D(player.getLocation());
embedBuilder.setColor(new Color(0, 255, 42)).addField("Status:", ":green_circle: Online", false).addField("Coordenadas:", (country.getName().equals("global") ? ":globe_with_meridians" : ":flag_" + country.getAbbreviation() + ":") + " " + coords.getX() + ", " + coords.getZ(), false).addField("Coordenadas geográficas:", (country.getName().equals("global") ? ":globe_with_meridians" : ":flag_" + country.getAbbreviation() + ":") + " [" + coords.getLat() + ", " + coords.getLon() + "](" + "https://www.google.com/maps/@" + coords.getLat() + "," + coords.getLon() + ",19z" + ")", false);
String chatType;
String chatName = serverPlayer.getChatManager().getChat().getName();
if (chatName.startsWith("project_")) {
chatType = ":tools:";
} else {
chatType = (chatName.equals("global") ? ":earth_americas:" : ":flag_" + new OldCountry(chatName).getAbbreviation() + ":");
}
embedBuilder.addField("Chat:", chatType + " " + serverPlayer.getChatManager().getChat().getFormattedName(), false);
try {
file[0] = new URL("https://open.mapquestapi.com/staticmap/v4/getmap?key=" + key + "&size=1280,720&type=sat&scalebar=false&imagetype=png¢er=" + coords.getLat() + "," + coords.getLon() + "&zoom=18&xis=https://cravatar.eu/helmavatar/" + player.getName() + "/64.png,1,c," + coords.getLat() + "," + coords.getLon()).openStream();
hasFile[0] = true;
} catch (IOException ex) {
ex.printStackTrace();
return;
}
embedBuilder.setImage("attachment://map.png");
} else {
embedBuilder.setColor(ERROR_COLOR).addField("Status:", ":red_circle: Offline", false);
DataTime time = DateHelper.differenceToData(new Date(offlinePlayer.getLastPlayed()), new Date());
embedBuilder.addField("Ultima vez conectado: ", (time.get(DateHelper.Type.MINUTE) > 0 ? "Hace " + (time.get(DateHelper.Type.HOUR) > 0 ? time.get(DateHelper.Type.HOUR) + " hora(s) y " : "") + time.get(DateHelper.Type.MINUTE) + " minuto(s)" : "Recién"), false);
}
if (serverPlayer.getDiscordManager().isLinked()) {
DiscordManager dscManager = serverPlayer.getDiscordManager();
dscManager.loadUser();
embedBuilder.addField("Discord:", serverPlayer.getDiscordManager().getUser().getAsMention(), false);
} else {
embedBuilder.addField("Discord:", "No conectado.", false);
}
GroupsManager groups = serverPlayer.getGroupsManager();
embedBuilder.addField("Rango:", new Configuration(Bukkit.getPluginManager().getPlugin("bteConoSur"), "discord/groupEmojis").getString(groups.getPrimaryGroup().toString()) + " " + groups.getPrimaryGroup().toString().replace("default", "visita").toUpperCase(), false);
if (groups.getSecondaryGroups().size() > 0) {
List<String> ranks = new ArrayList<>();
for (GroupsManager.SecondaryGroup secondaryGroup : groups.getSecondaryGroups()) {
ranks.add(new Configuration(Bukkit.getPluginManager().getPlugin("bteConoSur"), "discord/groupEmojis").getString(secondaryGroup.toString()) + " " + secondaryGroup.toString().toUpperCase());
}
embedBuilder.addField("Rangos secundarios:", String.join("\n", ranks), false);
}
PointsManager pointsManager = serverPlayer.getPointsManager();
if (pointsManager.getMaxPoints().getValue() > 0) {
List<String> points = new ArrayList<>();
for (Map.Entry<OldCountry, Integer> entry : pointsManager.getSorted().entrySet()) {
String bRank;
if (entry.getValue() >= 1000) {
bRank = ":gem:";
} else if (entry.getValue() >= 500) {
bRank = ":crossed_swords:";
} else if (entry.getValue() >= 150) {
bRank = ":hammer_pick:";
} else {
bRank = ":hammer:";
}
points.add("• :flag_" + entry.getKey().getAbbreviation() + ": " + bRank + " " + StringUtils.capitalize(entry.getKey().getName().replace("peru", "perú")) + ": " + entry.getValue());
}
embedBuilder.addField("Puntos:", String.join("\n", points), false);
}
ProjectsManager projects = serverPlayer.getProjectsManager();
embedBuilder.addField("Proyectos terminados:", Integer.toString(projects.getTotalFinishedProjects()), false);
List<String> allProjects = projects.getAllProjects();
if (allProjects.size() > 0) {
List<String> projectsLines = new ArrayList<>();
boolean max = false;
for (String id : projects.getAllOwnedProjects()) {
Project project = new Project(id);
projectsLines.add("• :flag_" + project.getCountry().getAbbreviation() + ": " + project.getDifficulty().toString().toLowerCase().replace("facil", ":green_circle:").replace("intermedio", ":yellow_circle:").replace("dificil", ":red_circle:") + " :crown: `" + project.getId() + "`" + ((!project.getName().equals(project.getId())) ? " - " + project.getName() : ""));
if (projectsLines.size() >= 15) {
projectsLines.add("y " + (allProjects.size() - 15) + " más...");
max = true;
break;
}
}
if (!max) {
for (String id : allProjects) {
Project project = new Project(id);
if (project.getOwner() != serverPlayer.getPlayer()) {
projectsLines.add("• :flag_" + project.getCountry().getAbbreviation() + ": " + project.getDifficulty().toString().toLowerCase().replace("facil", ":green_circle:").replace("intermedio", ":yellow_circle:").replace("dificil", ":red_circle:") + " `" + project.getId() + "`" + ((!project.getName().equals(project.getId())) ? " - " + project.getName() : ""));
}
if (projectsLines.size() >= 15) {
projectsLines.add("y " + (allProjects.size() - 15) + " más...");
break;
}
}
}
embedBuilder.addField("Proyectos activos (Total: " + allProjects.size() + "):", String.join("\n", projectsLines), false);
}
embedBuilder.setThumbnail("https://mc-heads.net/head/" + serverPlayer.getPlayer().getUniqueId());
if (hasFile[0]) {
textChannel.sendFile(file[0], "map.png").setEmbeds(embedBuilder.build()).reference(message).mentionRepliedUser(false).queue();
} else {
textChannel.sendMessageEmbeds(embedBuilder.build()).reference(message).mentionRepliedUser(false).queue();
}
} else {
errorInsertAPlayer(textChannel, message);
}
return;
}
errorInsertAPlayer(textChannel, message);
}
});
}
use of pizzaaxx.bteconosur.coords.Coords2D in project bteConoSurCore by BTEConoSur.
the class OnlineWhereCommand method onEvent.
@Override
public void onEvent(@NotNull GenericEvent event) {
if (event instanceof MessageReceivedEvent) {
MessageReceivedEvent e = (MessageReceivedEvent) event;
if (e.getMessage().getContentRaw().startsWith("/")) {
String fullCommand = e.getMessage().getContentRaw();
String[] args = fullCommand.replaceFirst("/", "").split(" ");
if (args.length > 0) {
if (args[0].equals("online")) {
if (Bukkit.getOnlinePlayers().size() > 0) {
EmbedBuilder embed = new EmbedBuilder();
embed.setColor(new Color(0, 255, 42));
List<String> names = new ArrayList<>();
for (Player p : Bukkit.getOnlinePlayers()) {
names.add(p.getName().replace("_", "\\_"));
}
Collections.sort(names);
embed.addField("Hay " + Bukkit.getOnlinePlayers().size() + " jugador" + (Bukkit.getOnlinePlayers().size() == 1 ? "" : "es") + " online:", String.join(", ", names), false);
e.getTextChannel().sendMessageEmbeds(embed.build()).reference(e.getMessage()).mentionRepliedUser(false).queue();
} else {
EmbedBuilder embed = new EmbedBuilder();
embed.setColor(new Color(255, 0, 0));
embed.setAuthor("No hay jugadores online.");
e.getTextChannel().sendMessageEmbeds(embed.build()).reference(e.getMessage()).mentionRepliedUser(false).queue();
}
}
if (args[0].equals("where")) {
if (Bukkit.getOnlinePlayers().size() > 0) {
CompletableFuture.runAsync(() -> {
EmbedBuilder embed = new EmbedBuilder();
embed.setColor(new Color(0, 255, 42));
List<String> xis = new ArrayList<>();
for (String c : "argentina bolivia chile paraguay peru uruguay".split(" ")) {
OldCountry country = new OldCountry(c);
List<String> names = new ArrayList<>();
for (Player p : country.getPlayers()) {
names.add(p.getName().replace("_", "\\_"));
Coords2D coords = new Coords2D(p.getLocation());
xis.add("https://cravatar.eu/helmavatar/" + p.getName() + "/32.png,1,c," + coords.getLat() + "," + coords.getLon());
}
Collections.sort(names);
embed.addField(":flag_" + country.getAbbreviation() + ": " + StringUtils.capitalize(c.replace("peru", "perú")) + ": " + names.size(), (names.size() > 0 ? String.join(", ", names) : "N/A"), true);
}
embed.setThumbnail("https://media.discordapp.net/attachments/807694452214333482/845857288609988628/conosur.png?width=471&height=473");
InputStream file;
try {
file = new URL("https://open.mapquestapi.com/staticmap/v4/getmap?key=" + key + "&scalebar=false&size=1280,720&type=sat&imagetype=png¢er=-33.43957706920842,-66.86130716417696&zoom=4&xis=" + String.join(",", xis)).openStream();
} catch (IOException ex) {
ex.printStackTrace();
return;
}
embed.setImage("attachment://map.png");
e.getTextChannel().sendFile(file, "map.png").setEmbeds(embed.build()).reference(e.getMessage()).mentionRepliedUser(false).queue();
});
} else {
EmbedBuilder embed = new EmbedBuilder();
embed.setColor(new Color(255, 0, 0));
embed.setAuthor("No hay jugadores online.");
e.getTextChannel().sendMessageEmbeds(embed.build()).reference(e.getMessage()).mentionRepliedUser(false).queue();
}
}
}
}
}
}
Aggregations