Search in sources :

Example 1 with ServerPlayer

use of pizzaaxx.bteconosur.serverPlayer.ServerPlayer 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();
                    }
                }
            }
        }
    }
}
Also used : Configuration(pizzaaxx.bteconosur.yaml.Configuration) InputStream(java.io.InputStream) BlockVector2D(com.sk89q.worldedit.BlockVector2D) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URL(java.net.URL) IOException(java.io.IOException) MessageReceivedEvent(net.dv8tion.jda.api.events.message.MessageReceivedEvent) Project(pizzaaxx.bteconosur.projects.Project) Coords2D(pizzaaxx.bteconosur.coords.Coords2D) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) ServerPlayer(pizzaaxx.bteconosur.serverPlayer.ServerPlayer) OfflinePlayer(org.bukkit.OfflinePlayer) Location(org.bukkit.Location)

Example 2 with ServerPlayer

use of pizzaaxx.bteconosur.serverPlayer.ServerPlayer in project bteConoSurCore by BTEConoSur.

the class EventsCommand method onCommand.

@Override
public boolean onCommand(CommandSender p, org.bukkit.command.Command command, String label, final String[] args) {
    if (command.getName().equals("event")) {
        if (p instanceof Player) {
            Player player = (Player) p;
            if (args.length > 0) {
                if (args[0].equals("join")) {
                    OldCountry country = null;
                    if (args.length > 1) {
                        country = new OldCountry(args[1]);
                        if (country.getName() == null) {
                            p.sendMessage(eventsPrefix + "Introduce un país válido.");
                            return true;
                        }
                    } else {
                        RegionManager regionManager = getWorldGuard().getRegionManager(mainWorld);
                        boolean found = false;
                        for (ProtectedRegion region : regionManager.getApplicableRegions(player.getLocation()).getRegions()) {
                            if (region.getId().startsWith("evento_")) {
                                country = new OldCountry(region.getId().replace("evento_", ""));
                                found = true;
                                break;
                            }
                        }
                        if (!found) {
                            player.sendMessage(eventsPrefix + "No estás en la zona de ningún evento.");
                            return true;
                        }
                    }
                    ServerEvent event = new ServerEvent(country);
                    if (event.getStatus() != ServerEvent.Status.OFF) {
                        if (!event.getParticipants().contains(player)) {
                            ServerPlayer s = new ServerPlayer(player);
                            if (s.getPointsManager().getMaxPoints().getValue() >= event.getMinPoints()) {
                                event.addParticipant(player);
                                event.save();
                                player.sendMessage(eventsPrefix + "¡Te has unido al evento \"" + event.getName() + "\"! ¡Esperamos que te diviertas!");
                                if (event.getStatus() == ServerEvent.Status.ON) {
                                    for (OfflinePlayer offlinePlayer : event.getParticipants()) {
                                        if (offlinePlayer.isOnline() && offlinePlayer != player) {
                                            ((Player) offlinePlayer).sendMessage(eventsPrefix + "¡§a" + s.getChatManager().getDisplayName() + "§f se ha unido al evento §a" + event.getName() + "§f.");
                                        }
                                    }
                                    GroupsManager groupsManager = s.getGroupsManager();
                                    if (groupsManager.getPrimaryGroup() == GroupsManager.PrimaryGroup.DEFAULT) {
                                        groupsManager.addSecondaryGroup(GroupsManager.SecondaryGroup.EVENTO);
                                    }
                                } else {
                                    if (s.getDiscordManager().isLinked()) {
                                        player.sendMessage(eventsPrefix + "Recibirás una notificación por Discord cuando el evento comience.");
                                    } else {
                                        player.sendMessage(eventsPrefix + "Se te dejará una notificación en Minecraft cuando el evento comience.");
                                    }
                                }
                                DataManager data = s.getDataManager();
                                List<String> events = data.getStringList("events");
                                if (!events.contains(country.getName())) {
                                    events.add(country.getName());
                                    data.set("events", events);
                                    data.save();
                                }
                            } else {
                                player.sendMessage(eventsPrefix + "Necesitas al menos §a" + event.getMinPoints() + "§f puntos para unirte al evento.");
                            }
                        } else {
                            player.sendMessage(eventsPrefix + "Ya eres parte del evento.");
                        }
                    } else {
                        player.sendMessage(eventsPrefix + "No estás en la zona de ningún evento.");
                    }
                } else if (args[0].equals("leave")) {
                    OldCountry country = null;
                    if (args.length > 1) {
                        country = new OldCountry(args[1]);
                        if (country.getName() == null) {
                            p.sendMessage(eventsPrefix + "Introduce un país válido.");
                            return true;
                        }
                    } else {
                        RegionManager regionManager = getWorldGuard().getRegionManager(mainWorld);
                        boolean found = false;
                        for (ProtectedRegion region : regionManager.getApplicableRegions(player.getLocation()).getRegions()) {
                            if (region.getId().startsWith("evento_")) {
                                country = new OldCountry(region.getId().replace("evento_", ""));
                                found = true;
                                break;
                            }
                        }
                        if (!found) {
                            player.sendMessage(eventsPrefix + "No estás en la zona de ningún evento.");
                            return true;
                        }
                    }
                    ServerEvent event = new ServerEvent(country);
                    if (event.getStatus() != ServerEvent.Status.OFF) {
                        if (event.getParticipants().contains(player)) {
                            ServerPlayer s = new ServerPlayer(player);
                            DataManager data = s.getDataManager();
                            player.sendMessage(eventsPrefix + "Has abandonado el evento \"" + event.getName() + "\".");
                            if (event.getStatus() == ServerEvent.Status.ON) {
                                for (OfflinePlayer offlinePlayer : event.getParticipants()) {
                                    if (offlinePlayer.isOnline() && offlinePlayer != player) {
                                        ((Player) offlinePlayer).sendMessage(eventsPrefix + "§a" + s.getChatManager().getDisplayName() + "§f ha abandonado el evento §a" + event.getName() + "§f.");
                                    }
                                }
                                GroupsManager groupsManager = s.getGroupsManager();
                                if (groupsManager.getPrimaryGroup() == GroupsManager.PrimaryGroup.DEFAULT && s.getDataManager().getStringList("events").size() == 1) {
                                    groupsManager.removeSecondaryGroup(GroupsManager.SecondaryGroup.EVENTO);
                                }
                            }
                            data.set("events", data.getStringList("events").remove(country.getName()));
                            data.save();
                            event.removeParticipant(player);
                            event.save();
                        } else {
                            player.sendMessage(eventsPrefix + "No eres parte del evento.");
                        }
                    } else {
                        player.sendMessage(eventsPrefix + "No estás en la zona de ningún evento.");
                    }
                } else {
                    player.sendMessage(eventsPrefix + "Introduce un subcomando válido.");
                }
            } else {
                Inventory gui = Bukkit.createInventory(null, 27, "Elige un evento");
                for (int i = 0; i < 27; i++) {
                    gui.setItem(i, background);
                }
                gui.setItem(26, Misc.getCustomHead("§fSalir", null, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMzdhZWU5YTc1YmYwZGY3ODk3MTgzMDE1Y2NhMGIyYTdkNzU1YzYzMzg4ZmYwMTc1MmQ1ZjQ0MTlmYzY0NSJ9fX0="));
                ServerEvent event = new ServerEvent(new OldCountry("argentina"));
                gui.setItem(10, Misc.getCustomHead("§a§lArgentina", (event.getStatus() == ServerEvent.Status.OFF ? "§aEstado: §c§lApagado" : "§aEstado: " + (event.getStatus() == ServerEvent.Status.ON ? "§2§lEn curso" : "§e§lPreparado") + "\n§aNombre: §f" + event.getName() + "\n§aFecha: §f" + event.getDate() + "\n§aPuntos mínimos: §f" + event.getMinPoints() + "\n§7§oHaz click para ir"), "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjZkMDMzZGM1ZjY3NWFkNTFiYzA2YzdhMTk0OWMzNWExZDM3ZTQ4YTJlMWMyNzg5YzJjZjdkMzBlYzU4ZjMyYyJ9fX0="));
                event = new ServerEvent(new OldCountry("bolivia"));
                gui.setItem(11, Misc.getCustomHead("§a§lBolivia", (event.getStatus() == ServerEvent.Status.OFF ? "§aEstado: §c§lApagado" : "§aEstado: " + (event.getStatus() == ServerEvent.Status.ON ? "§2§lEn curso" : "§e§lPreparado") + "\n§aNombre: §f" + event.getName() + "\n§aFecha: §f" + event.getDate() + "\n§aPuntos mínimos: §f" + event.getMinPoints() + "\n§7§oHaz click para ir"), "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZmQyYzlmOTg2MThjZDVmN2RiZjBjMWE1NGVlMDk0NzQ2NjJiNzEzYjVhYTI2NWM4NWVmYmZjNDY0MThlOTE1In19fQ=="));
                event = new ServerEvent(new OldCountry("chile"));
                gui.setItem(12, Misc.getCustomHead("§a§lChile", (event.getStatus() == ServerEvent.Status.OFF ? "§aEstado: §c§lApagado" : "§aEstado: " + (event.getStatus() == ServerEvent.Status.ON ? "§2§lEn curso" : "§e§lPreparado") + "\n§aNombre: §f" + event.getName() + "\n§aFecha: §f" + event.getDate() + "\n§aPuntos mínimos: §f" + event.getMinPoints() + "\n§7§oHaz click para ir"), "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTAzNTk0YzBjMTE2YjA1ZDc1NjA2MGEyMjM5ODM3NzQ3ODg4NzMyMjY5MzVkOTYyNzExYmMzZTI1ODQ2ZGM2YiJ9fX0="));
                event = new ServerEvent(new OldCountry("paraguay"));
                gui.setItem(13, Misc.getCustomHead("§a§lParaguay", (event.getStatus() == ServerEvent.Status.OFF ? "§aEstado: §c§lApagado" : "§aEstado: " + (event.getStatus() == ServerEvent.Status.ON ? "§2§lEn curso" : "§e§lPreparado") + "\n§aNombre: §f" + event.getName() + "\n§aFecha: §f" + event.getDate() + "\n§aPuntos mínimos: §f" + event.getMinPoints() + "\n§7§oHaz click para ir"), "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvODE3OGRlNjkxYjUwOGQ2MjQ5MTA5ZmM1NGFmNmZiYTQ5YmFhODM3N2FkMzcwNjEyZWQ2MTdkNzdkZDZhZDU4OCJ9fX0="));
                event = new ServerEvent(new OldCountry("peru"));
                gui.setItem(14, Misc.getCustomHead("§a§lPerú", (event.getStatus() == ServerEvent.Status.OFF ? "§aEstado: §c§lApagado" : "§aEstado: " + (event.getStatus() == ServerEvent.Status.ON ? "§2§lEn curso" : "§e§lPreparado") + "\n§aNombre: §f" + event.getName() + "\n§aFecha: §f" + event.getDate() + "\n§aPuntos mínimos: §f" + event.getMinPoints() + "\n§7§oHaz click para ir"), "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMjRkMDNiZDQ0MTBiYWJkYzY4MjQ5M2IzYzJiYmEyNmU3MzBlNmJjNjU4ZDM4ODhlNzliZjcxMmY4NTMifX19"));
                event = new ServerEvent(new OldCountry("uruguay"));
                gui.setItem(15, Misc.getCustomHead("§a§lUruguay", (event.getStatus() == ServerEvent.Status.OFF ? "§aEstado: §c§lApagado" : "§aEstado: " + (event.getStatus() == ServerEvent.Status.ON ? "§2§lEn curso" : "§e§lPreparado") + "\n§aNombre: §f" + event.getName() + "\n§aFecha: §f" + event.getDate() + "\n§aPuntos mínimos: §f" + event.getMinPoints() + "\n§7§oHaz click para ir"), "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMjg0NDA1OTdjNGJjMmFhZDYwMGE1NDYwNGRjN2IxZmI3NzEzNDNlMDIyZTZhMmUwMjJmOTBlNDBjYzI1ZjlmOCJ9fX0="));
                event = new ServerEvent(new OldCountry("global"));
                gui.setItem(16, Misc.getCustomHead("§a§lGlobal", (event.getStatus() == ServerEvent.Status.OFF ? "§aEstado: §c§lApagado" : "§aEstado: " + (event.getStatus() == ServerEvent.Status.ON ? "§2§lEn curso" : "§e§lPreparado") + "\n§aNombre: §f" + event.getName() + "\n§aFecha: §f" + event.getDate() + "\n§aPuntos mínimos: §f" + event.getMinPoints() + "\n§7§oHaz click para ir"), "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOThkYWExZTNlZDk0ZmYzZTMzZTFkNGM2ZTQzZjAyNGM0N2Q3OGE1N2JhNGQzOGU3NWU3YzkyNjQxMDYifX19"));
                player.openInventory(gui);
            }
        } else {
            p.sendMessage(eventsPrefix + "No puedes usar este comando desde la consola.");
        }
    }
    if (command.getName().equals("manageevent")) {
        if (args.length > 0) {
            if (countryAbbreviations.contains(args[0])) {
                OldCountry pais = new OldCountry(args[0]);
                final String country = pais.getName();
                if (args.length > 1) {
                    ServerEvent event = new ServerEvent(pais);
                    if (args[1].equals("name")) {
                        if (args.length > 2) {
                            String name = String.join(" ", Arrays.asList(args).subList(2, args.length));
                            if (name.matches("[ A-Za-z0-9/]{1,32}")) {
                                event.setName(name);
                                event.save();
                                p.sendMessage(eventsPrefix + "Has establecido el nombre del evento de §a" + country.replace("peru", "perú").toUpperCase() + "§f en §a" + name + "§f.");
                            } else {
                                p.sendMessage(eventsPrefix + "Introduce un nombre válido.");
                            }
                        } else {
                            p.sendMessage(eventsPrefix + "El nombre del evento del evento de §a" + country.replace("peru", "perú").toUpperCase() + "§f es §a" + event.getName() + "§f.");
                        }
                    } else if (args[1].equals("date")) {
                        if (args.length > 2) {
                            String date = String.join(" ", Arrays.asList(args).subList(2, args.length));
                            if (date.matches("[ -A-Za-z0-9/]{1,32}")) {
                                event.setDate(date);
                                event.save();
                                p.sendMessage(eventsPrefix + "Has establecido la fecha del evento de §a" + country.replace("peru", "perú").toUpperCase() + "§f en §a" + date + "§f.");
                            } else {
                                p.sendMessage(eventsPrefix + "Introduce un texto válido.");
                            }
                        } else {
                            p.sendMessage(eventsPrefix + "La fecha del evento de §a" + country.replace("peru", "perú").toUpperCase() + "§f es §a" + event.getDate() + "§f.");
                        }
                    } else if (args[1].equals("status")) {
                        if (args.length > 2) {
                            if (args[2].equals("stop") || args[2].equals("off") || args[2].equals("terminar")) {
                                if (event.getStatus() != ServerEvent.Status.OFF) {
                                    if (stopConfirm.contains(p)) {
                                        stopConfirm.remove(p);
                                        event.stop();
                                        p.sendMessage("Has terminado el evento de §a" + country.replace("peru", "perú").toUpperCase() + "§f.");
                                    } else if (event.getStatus() == ServerEvent.Status.READY) {
                                        stopConfirm.add(p);
                                        p.sendMessage(eventsPrefix + "§cToda la configuración del evento se perderá.§f Usa el comando de nuevo para confirmar.");
                                    } else {
                                        stopConfirm.add(p);
                                        p.sendMessage(eventsPrefix + "§cNo puedes deshacer esta acción.§f Usa el comando de nuevo para confirmar.");
                                    }
                                }
                            } else if (args[2].equals("ready") || args[2].equals("listo") || args[2].equals("preparado")) {
                                if (event.getStatus() == ServerEvent.Status.OFF) {
                                    if (readyConfirm.contains(p)) {
                                        readyConfirm.remove(p);
                                        event.prepared();
                                        p.sendMessage("Has marcado el evento de §a" + country.replace("peru", "perú").toUpperCase() + "§f como preparado.");
                                    } else {
                                        readyConfirm.add(p);
                                        p.sendMessage(eventsPrefix + "¿Estás seguro de que quieres marcar el evento como terminado? A continuación se hay una previsualización del evento. Usa el comando de nuevo para confirmar.");
                                        p.sendMessage(">+-----------+[-< §5EVENTO§f >-]+-----------+<");
                                        p.sendMessage("§aNombre: §f" + event.getName());
                                        p.sendMessage("§aFecha: §f" + event.getDate());
                                        p.sendMessage("§aPuntos mínimos: §f" + event.getMinPoints());
                                        p.sendMessage("§aImagen: §f" + event.getImage());
                                        p.sendMessage("§aCoordenadas: §f" + event.getTp().getBlockX() + ", " + event.getTp().getBlockY() + ", " + event.getTp().getBlockZ());
                                        p.sendMessage(">+-----------+[-< ====== >-]+-----------+<");
                                    }
                                } else {
                                    p.sendMessage(eventsPrefix + "Sólo puedes hacer esto cuando el proyecto está apagado.");
                                }
                            } else if (args[2].equals("start") || args[2].equals("on") || args[2].equals("empezar")) {
                                if (event.getStatus() == ServerEvent.Status.READY) {
                                    if (startConfirm.contains(p)) {
                                        startConfirm.remove(p);
                                        event.start();
                                        p.sendMessage("Has empezado el evento de §a" + country.replace("peru", "perú").toUpperCase() + "§f.");
                                    } else {
                                        startConfirm.add(p);
                                        p.sendMessage(eventsPrefix + "¿Estás seguro de que quieres iniciar el evento? Usa el comando de nuevo para confirmar.");
                                    }
                                } else {
                                    p.sendMessage(eventsPrefix + "Solo puedes iniciar un evento cuando este está marcado como listo.");
                                }
                            }
                        } else {
                            p.sendMessage(eventsPrefix + "Introduce una acción.");
                        }
                    } else if (args[1].equals("tp")) {
                        if (args.length > 2) {
                            if (args[2].equals("here")) {
                                if (p instanceof Player) {
                                    Player player = (Player) p;
                                    event.setTp(player.getLocation());
                                    event.save();
                                    p.sendMessage(eventsPrefix + "Has establecido el teletransporte al evento de §a" + country.replace("peru", "perú").toUpperCase() + "§f en tu posición actual.");
                                } else {
                                    p.sendMessage(eventsPrefix + "No puedes usar este comando desde la consola.");
                                }
                            } else if (args.length > 4 && args[2].matches("^-?[0-9]{1,16}(\\.[0-9]{1,16})?$") && args[3].matches("^-?[0-9]{1,16}(\\.[0-9]{1,16})?$") && args[4].matches("^-?[0-9]{1,16}(\\.[0-9]{1,16})?$")) {
                                double x = Double.parseDouble(args[2]);
                                double y = Double.parseDouble(args[3]);
                                double z = Double.parseDouble(args[4]);
                                event.setTp(new Location(mainWorld, x, y, z));
                                event.save();
                                p.sendMessage(eventsPrefix + "Has establecido el teletransporte al evento de §a" + country.replace("peru", "perú").toUpperCase() + "§f en §a" + x + ", " + y + ", " + z + "§f.");
                            }
                        } else {
                            p.sendMessage(eventsPrefix + "El teletransporte del evento de §a" + country.replace("peru", "perú").toUpperCase() + "§f está en §a" + event.getTp().getBlockX() + ", " + event.getTp().getBlockY() + ", " + event.getTp().getBlockZ() + "§f.");
                        }
                    } else if (args[1].equals("redefine")) {
                        if (event.getStatus() != ServerEvent.Status.ON) {
                            if (p instanceof Player) {
                                Player player = (Player) p;
                                List<BlockVector2D> points = new ArrayList<>();
                                try {
                                    points = polyRegion(getSelection(player)).getPoints();
                                } catch (IllegalArgumentException e) {
                                    player.sendMessage(eventsPrefix + "Selecciona un área cúbica o poligonal.");
                                } catch (IncompleteRegionException e) {
                                    player.sendMessage(eventsPrefix + "Selecciona un área primero.");
                                }
                                event.setNewRegion(points);
                                event.save();
                                p.sendMessage(eventsPrefix + "Has redefinido la región del evento de §a" + country.replace("peru", "perú").toUpperCase() + "§f.");
                            } else {
                                p.sendMessage(eventsPrefix + "No se puede ejecutar este comando desde la consola.");
                            }
                        } else {
                            p.sendMessage(eventsPrefix + "No puedes hacer esto mientras el evento está activo.");
                        }
                    } else if (args[1].equals("minpoints")) {
                        if (args.length > 2) {
                            if (event.getStatus() == ServerEvent.Status.ON) {
                                p.sendMessage(eventsPrefix + "No puedes cambiar esto mientras un evento está activo.");
                                return true;
                            }
                            if (args[2].matches("[0-9]{1,10}") && Integer.parseInt(args[2]) >= 0) {
                                event.setMinPoints(Integer.parseInt(args[2]));
                                event.save();
                                p.sendMessage(eventsPrefix + "Has establecido el mínimo de puntos para el evento de §a" + country.replace("peru", "perú").toUpperCase() + "§f en §a" + args[2] + "§f.");
                            } else {
                                p.sendMessage(eventsPrefix + "Introduce un valor válido.");
                            }
                        } else {
                            p.sendMessage(eventsPrefix + "El mínimo de puntos para el evento de §a" + country.replace("peru", "perú").toUpperCase() + "§f es de §a" + event.getMinPoints() + "§f.");
                        }
                    } else if (args[1].equals("image")) {
                        if (args.length > 2) {
                            if (args[2].equals("delete")) {
                                event.setImage("notSet");
                                event.save();
                                p.sendMessage(eventsPrefix + "Has eliminado la imagen del evento de §a" + country.replace("peru", "perú").toUpperCase() + "§f.");
                            } else {
                                event.setImage(args[2]);
                                event.save();
                                p.sendMessage(eventsPrefix + "Has establecido la imagen del evento de §a" + country.replace("peru", "perú").toUpperCase() + "§f en\n§b" + args[2]);
                            }
                        } else {
                            p.sendMessage(eventsPrefix + "Introduce un enlace a una imagen.");
                        }
                    }
                } else {
                    p.sendMessage(eventsPrefix + "Introduce una acción.");
                }
            } else {
                p.sendMessage(eventsPrefix + "Introduce un país válido.");
            }
        } else {
            p.sendMessage(eventsPrefix + "Introduce un país para manejar.");
        }
    }
    return true;
}
Also used : OldCountry(pizzaaxx.bteconosur.country.OldCountry) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) ServerPlayer(pizzaaxx.bteconosur.serverPlayer.ServerPlayer) BlockVector2D(com.sk89q.worldedit.BlockVector2D) IncompleteRegionException(com.sk89q.worldedit.IncompleteRegionException) DataManager(pizzaaxx.bteconosur.serverPlayer.DataManager) ServerPlayer(pizzaaxx.bteconosur.serverPlayer.ServerPlayer) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) OfflinePlayer(org.bukkit.OfflinePlayer) Inventory(org.bukkit.inventory.Inventory) GroupsManager(pizzaaxx.bteconosur.serverPlayer.GroupsManager) Location(org.bukkit.Location)

Example 3 with ServerPlayer

use of pizzaaxx.bteconosur.serverPlayer.ServerPlayer in project bteConoSurCore by BTEConoSur.

the class ServerEvent method stop.

public void stop() {
    List<String> names = new ArrayList<>();
    for (OfflinePlayer player : participants) {
        ServerPlayer serverPlayer = new ServerPlayer(player);
        DataManager data = serverPlayer.getDataManager();
        GroupsManager groups = serverPlayer.getGroupsManager();
        names.add(serverPlayer.getName());
        if (groups.getSecondaryGroups().contains(GroupsManager.SecondaryGroup.EVENTO)) {
            if (data.getStringList("events").size() == 1) {
                groups.removeSecondaryGroup(GroupsManager.SecondaryGroup.EVENTO);
            }
        }
        data.set("events", data.getStringList("events").remove(this.country.getName()));
        data.save();
        if (!player.isOnline()) {
            serverPlayer.sendNotification(eventsPrefix + "El evento §a**" + this.name + "**§f de §a" + StringUtils.capitalize(country.getName().replace("peru", "perú")) + "§f acaba de terminar. ¡Gracias por participar!");
        }
    }
    for (Player player : Bukkit.getOnlinePlayers()) {
        player.sendMessage(">+-----------+[-< §5EVENTO§f >-]+-----------+<");
        player.sendMessage("¡El evento §a" + name + "§f de §a" + StringUtils.capitalize(country.getName().replace("peru", "perú")) + "§f acaba de terminar!");
        player.sendMessage(">+-----------+[-< ====== >-]+-----------+<");
    }
    EmbedBuilder embed = new EmbedBuilder();
    embed.setColor(new Color(255, 0, 0));
    embed.setThumbnail(country.getIcon());
    embed.setTitle("¡El evento \"" + name + "\" de " + StringUtils.capitalize(country.getName().replace("peru", "perú")) + " acaba de terminar!");
    if (names.size() > 0) {
        embed.addField(":busts_in_silhouette: Participantes finales:", String.join(", ", names), false);
    } else {
        embed.addField(":busts_in_silhouette: Participantes finales:", "No hay.", false);
    }
    gateway.sendMessageEmbeds(embed.build()).queue();
    embed.setTitle("Evento \"" + name + "\"");
    country.getLogs().sendMessageEmbeds(embed.build()).queue();
    this.reset();
    this.save();
}
Also used : Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) ServerPlayer(pizzaaxx.bteconosur.serverPlayer.ServerPlayer) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) ServerPlayer(pizzaaxx.bteconosur.serverPlayer.ServerPlayer) OfflinePlayer(org.bukkit.OfflinePlayer) DataManager(pizzaaxx.bteconosur.serverPlayer.DataManager) GroupsManager(pizzaaxx.bteconosur.serverPlayer.GroupsManager)

Example 4 with ServerPlayer

use of pizzaaxx.bteconosur.serverPlayer.ServerPlayer in project bteConoSurCore by BTEConoSur.

the class Events method onKick.

@EventHandler
public void onKick(PlayerKickEvent e) {
    ServerPlayer s = new ServerPlayer(e.getPlayer());
    EmbedBuilder embed = new EmbedBuilder();
    embed.setColor(new Color(252, 127, 3));
    embed.setAuthor(s.getName() + " ha sido expulsado del servidor.", null, "https://cravatar.eu/helmavatar/" + s.getName() + "/190.png");
    embed.addField(":scroll: Razón:", ChatColor.stripColor(e.getReason()), false);
    gateway.sendMessageEmbeds(embed.build()).queue();
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) ServerPlayer(pizzaaxx.bteconosur.serverPlayer.ServerPlayer) ChatColor(org.bukkit.ChatColor) EventHandler(org.bukkit.event.EventHandler)

Example 5 with ServerPlayer

use of pizzaaxx.bteconosur.serverPlayer.ServerPlayer in project bteConoSurCore by BTEConoSur.

the class Events method onFirstJoin.

@EventHandler
public void onFirstJoin(PlayerJoinEvent e) {
    if (!(e.getPlayer().hasPlayedBefore())) {
        ServerPlayer s = new ServerPlayer(e.getPlayer());
        EmbedBuilder embed = new EmbedBuilder();
        embed.setColor(new Color(0, 255, 42));
        embed.setAuthor("¡" + s.getName() + " ha entrado al servidor por primera vez!", null, "https://cravatar.eu/helmavatar/" + s.getName() + "/190.png");
        gateway.sendMessageEmbeds(embed.build()).queue();
    }
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) ServerPlayer(pizzaaxx.bteconosur.serverPlayer.ServerPlayer) ChatColor(org.bukkit.ChatColor) EventHandler(org.bukkit.event.EventHandler)

Aggregations

ServerPlayer (pizzaaxx.bteconosur.serverPlayer.ServerPlayer)41 Player (org.bukkit.entity.Player)23 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)12 OfflinePlayer (org.bukkit.OfflinePlayer)12 EventHandler (org.bukkit.event.EventHandler)11 ChatColor (org.bukkit.ChatColor)6 GroupsManager (pizzaaxx.bteconosur.serverPlayer.GroupsManager)6 Configuration (pizzaaxx.bteconosur.yaml.Configuration)6 BlockVector2D (com.sk89q.worldedit.BlockVector2D)4 IncompleteRegionException (com.sk89q.worldedit.IncompleteRegionException)4 ItemMeta (org.bukkit.inventory.meta.ItemMeta)4 OldCountry (pizzaaxx.bteconosur.country.OldCountry)4 PlayerData (pizzaaxx.bteconosur.player.data.PlayerData)4 YamlManager (pizzaaxx.bteconosur.yaml.YamlManager)4 RegionManager (com.sk89q.worldguard.protection.managers.RegionManager)3 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)3 URL (java.net.URL)3 ArrayList (java.util.ArrayList)3 MessageReceivedEvent (net.dv8tion.jda.api.events.message.MessageReceivedEvent)3 Location (org.bukkit.Location)3