Search in sources :

Example 1 with OldCountry

use of pizzaaxx.bteconosur.country.OldCountry 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 2 with OldCountry

use of pizzaaxx.bteconosur.country.OldCountry in project bteConoSurCore by BTEConoSur.

the class Misc method getCountryAtLocation.

public static OldCountry getCountryAtLocation(Location loc) {
    RegionManager regionManager = getWorldGuard().getRegionManager(mainWorld);
    Set<ProtectedRegion> regions = regionManager.getApplicableRegions(loc).getRegions();
    if (regions.contains(regionManager.getRegion("argentina"))) {
        return new OldCountry("argentina");
    }
    if (regions.contains(regionManager.getRegion("bolivia"))) {
        return new OldCountry("bolivia");
    }
    if (regions.contains(regionManager.getRegion("chile_cont")) || regions.contains(regionManager.getRegion("chile_idp"))) {
        return new OldCountry("chile");
    }
    if (regions.contains(regionManager.getRegion("paraguay"))) {
        return new OldCountry("paraguay");
    }
    if (regions.contains(regionManager.getRegion("peru"))) {
        return new OldCountry("peru");
    }
    if (regions.contains(regionManager.getRegion("uruguay"))) {
        return new OldCountry("uruguay");
    }
    return null;
}
Also used : OldCountry(pizzaaxx.bteconosur.country.OldCountry) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager)

Example 3 with OldCountry

use of pizzaaxx.bteconosur.country.OldCountry in project bteConoSurCore by BTEConoSur.

the class TabCompletions method onTabComplete.

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
    List<String> completions = new ArrayList<>();
    if (sender instanceof Player) {
        Player p = (Player) sender;
        ServerPlayer s = new ServerPlayer(p);
        if (command.getName().equals("project")) {
            if (args.length == 0) {
                completions.add("find");
                completions.add("create");
                completions.add("tutorial");
                Project project = new Project(p.getLocation());
                completions.add("leave");
                completions.add("borders");
                if (!(project.isPending())) {
                    completions.add("claim");
                }
                if (project.getOwner() != null) {
                    completions.add("request");
                }
                if (project.getOwner() == p) {
                    completions.add("add");
                    completions.add("remove");
                    completions.add("transfer");
                    completions.add("name");
                    completions.add("redefine");
                    completions.add("finish");
                    completions.add("redefine");
                }
                if (s.getPermissionCountries().contains(new OldCountry(p.getLocation()))) {
                    if (project.isPending()) {
                        completions.add("review");
                    }
                    if (p.hasPermission("bteconosur.projects.manage.tag")) {
                        completions.add("tag");
                    }
                }
                if (p.hasPermission("bteconosur.projects.manage.pending")) {
                    completions.add("pending");
                }
                if (s.getPermissionCountries().contains(new OldCountry(p.getLocation()))) {
                    completions.add("delete");
                }
            }
        }
    }
    Collections.sort(completions);
    return completions;
}
Also used : OldCountry(pizzaaxx.bteconosur.country.OldCountry) Player(org.bukkit.entity.Player) ServerPlayer(pizzaaxx.bteconosur.serverPlayer.ServerPlayer) ServerPlayer(pizzaaxx.bteconosur.serverPlayer.ServerPlayer) ArrayList(java.util.ArrayList)

Example 4 with OldCountry

use of pizzaaxx.bteconosur.country.OldCountry 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");
        }
    }
}
Also used : OldCountry(pizzaaxx.bteconosur.country.OldCountry) Player(org.bukkit.entity.Player) BlockVector2D(com.sk89q.worldedit.BlockVector2D) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Coords2D(pizzaaxx.bteconosur.coords.Coords2D) Tag(pizzaaxx.bteconosur.projects.Project.Tag) List(java.util.List) Tag(pizzaaxx.bteconosur.projects.Project.Tag) ItemStack(org.bukkit.inventory.ItemStack) Inventory(org.bukkit.inventory.Inventory) ItemMeta(org.bukkit.inventory.meta.ItemMeta) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 5 with OldCountry

use of pizzaaxx.bteconosur.country.OldCountry 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&center=" + 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);
        }
    });
}
Also used : OldCountry(pizzaaxx.bteconosur.country.OldCountry) User(net.dv8tion.jda.api.entities.User) Message(net.dv8tion.jda.api.entities.Message) Configuration(pizzaaxx.bteconosur.yaml.Configuration) DataTime(pizzaaxx.bteconosur.helper.DataTime) URL(java.net.URL) TextChannel(net.dv8tion.jda.api.entities.TextChannel) OfflinePlayer(org.bukkit.OfflinePlayer) InputStream(java.io.InputStream) IOException(java.io.IOException) IOException(java.io.IOException) Coords2D(pizzaaxx.bteconosur.coords.Coords2D) Project(pizzaaxx.bteconosur.projects.Project) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder)

Aggregations

OldCountry (pizzaaxx.bteconosur.country.OldCountry)14 Player (org.bukkit.entity.Player)10 ArrayList (java.util.ArrayList)5 OfflinePlayer (org.bukkit.OfflinePlayer)5 Coords2D (pizzaaxx.bteconosur.coords.Coords2D)5 ServerPlayer (pizzaaxx.bteconosur.serverPlayer.ServerPlayer)5 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)4 Inventory (org.bukkit.inventory.Inventory)4 Project (pizzaaxx.bteconosur.projects.Project)4 BlockVector2D (com.sk89q.worldedit.BlockVector2D)3 RegionManager (com.sk89q.worldguard.protection.managers.RegionManager)3 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)3 IOException (java.io.IOException)3 URL (java.net.URL)3 List (java.util.List)3 Configuration (pizzaaxx.bteconosur.yaml.Configuration)3 IncompleteRegionException (com.sk89q.worldedit.IncompleteRegionException)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 TextChannel (net.dv8tion.jda.api.entities.TextChannel)2