Example usage for java.lang SecurityException SecurityException

List of usage examples for java.lang SecurityException SecurityException

Introduction

In this page you can find the example usage for java.lang SecurityException SecurityException.

Prototype

public SecurityException() 

Source Link

Document

Constructs a SecurityException with no detail message.

Usage

From source file:net.creativeparkour.GameManager.java

private static CPMap construireMapTelechargee(JsonObject jsData, CPMapState etatAMettre, CommandSender sender) {
    final String uuid = jsData.get("uuidMap").getAsString();
    String nomMap = jsData.get("nomMap").getAsString();
    if (!mapExistante(uuid)) {
        // Ajout d'un chiffre au nom s'il est dj pris
        int nb = 1;
        for (CPMap map : maps.values()) {
            String nomTemp = nomMap;
            if (nb > 1)
                nomTemp += " " + nb;
            if (nomTemp.equalsIgnoreCase(map.getName())) {
                nb++;/* ww w.  ja  v a 2s. co m*/
            }
        }
        if (nb > 1)
            nomMap += " " + nb;

        int taille = jsData.get("taille").getAsInt();
        // Cration de la map
        int id = getIdMapDispo(taille);
        final World m = Config.getMonde();
        Block blocMin;
        CPMap mapID = maps.get(id);
        if (mapID != null && mapID.getState() == CPMapState.DELETED) // Si c'est le remplacement d'une map (la taille a dj t vrifie dans getIdMapDispo()
            blocMin = mapID.getMinLoc();
        else {
            blocMin = getBlocMapDispo(taille);
        }

        final int xMin = blocMin.getX();
        final int yMin = blocMin.getY();
        final int zMin = blocMin.getZ();
        int xMax = xMin + taille;
        int yMax = Math.min(yMin + taille, 126); // Au maximum 126 (1 de marge pour le toit en barrire invisible)
        int zMax = zMin + taille;
        RemplisseurBlocs remplisseur = null;
        try {
            JsonObject jsContenu = CPUtils.getJsonObjectPropre(jsData.get("contenu"));

            // Suppression des entits
            List<Entity> listeEntites = new ArrayList<Entity>();
            for (int i = 0; i < m.getEntities().size(); i++) {
                Entity e = m.getEntities().get(i);
                if (!(e instanceof Player) && e.getLocation().getX() >= xMin && e.getLocation().getX() <= xMax
                        && e.getLocation().getY() >= yMin && e.getLocation().getY() <= yMax
                        && e.getLocation().getZ() >= zMin && e.getLocation().getZ() <= zMax) {
                    listeEntites.add(e);
                }
            }
            for (int i = 0; i < listeEntites.size(); i++) {
                listeEntites.get(i).remove();
            }

            // Traitement des blocs
            Map<Vector, MaterialData> listeBlocs = new HashMap<Vector, MaterialData>();
            int blocsFaits = 0;
            int moitie = Math.round((taille * (taille + 1) * taille) / 2);
            // Ajout d'air partout
            for (int x = xMin; x <= xMax; x++) {
                for (int y = yMin; y <= yMax; y++) {
                    for (int z = zMin; z <= zMax; z++) {
                        if (m.getBlockAt(x, y, z).getType() != Material.AIR)
                            listeBlocs.put(new Vector(x, y, z), new MaterialData(Material.AIR));

                        blocsFaits++;
                        if (blocsFaits == moitie) {
                            sender.sendMessage(ChatColor.GRAY + "" + ChatColor.ITALIC + "10 %");
                        }
                    }
                }
            }
            // Couche de bedrock
            listeBlocs.putAll(genererContours(m, xMin, yMin, zMin, xMax, yMax, zMax));
            sender.sendMessage(ChatColor.GRAY + "" + ChatColor.ITALIC + "20 %");

            // Remplacement des blocs d'air qu'il faut par des blocs
            // Remplissage de la liste des types
            Map<Integer, JsonObject> types = new HashMap<Integer, JsonObject>();
            JsonArray jsTypes = jsContenu.get("types").getAsJsonArray();
            for (JsonElement t : jsTypes) {
                JsonObject jsO = t.getAsJsonObject();
                types.put(jsO.get("i").getAsInt(), jsO);
            }
            JsonArray blocs = jsContenu.get("blocs").getAsJsonArray();
            List<JsonObject> blocsDelai = new ArrayList<JsonObject>();
            List<JsonObject> blocsRedstone = new ArrayList<JsonObject>();
            boolean blocsConvertis = false;
            for (JsonElement jsB : blocs) {
                JsonObject jsO = jsB.getAsJsonObject();
                JsonObject type = types.get(jsO.get("i").getAsInt());
                Material mat = null;
                try {
                    mat = Material.getMaterial(type.get("t").getAsString());
                } catch (NoSuchFieldError e) {
                    // Nothing, see below
                }
                if (mat == null) {
                    // Trying to replace the unknown Material with a compatible one
                    switch (type.get("t").getAsString()) {
                    case "END_BRICKS":
                        mat = Material.SANDSTONE;
                        type.addProperty("d", 2);
                        break;
                    case "PURPUR_BLOCK":
                    case "PURPUR_PILLAR":
                    case "PURPUR_DOUBLE_SLAB":
                    case "RED_NETHER_BRICK":
                        mat = Material.NETHER_BRICK;
                        break;
                    case "PURPUR_STAIRS":
                        mat = Material.NETHER_BRICK_STAIRS;
                        break;
                    case "PURPUR_SLAB":
                        mat = Material.STEP;
                        type.addProperty("d", 6);
                        break;
                    case "BEETROOT_BLOCK":
                        mat = Material.CARROT;
                        break;
                    case "MAGMA":
                        mat = Material.NETHERRACK;
                        break;
                    case "NETHER_WART_BLOCK":
                        mat = Material.STAINED_CLAY;
                        type.addProperty("d", 14);
                        break;
                    case "BONE_BLOCK":
                        mat = Material.QUARTZ_BLOCK;
                        break;
                    case "STRUCTURE_BLOCK":
                        mat = Material.OBSIDIAN;
                        break;
                    case "STRUCTURE_VOID":
                        mat = Material.AIR;
                        break;
                    case "WHITE_SHULKER_BOX":
                    case "WHITE_GLAZED_TERRACOTTA":
                        mat = Material.STAINED_CLAY;
                        type.addProperty("d", 0);
                        break;
                    case "ORANGE_SHULKER_BOX":
                    case "ORANGE_GLAZED_TERRACOTTA":
                        mat = Material.STAINED_CLAY;
                        type.addProperty("d", 1);
                        break;
                    case "MAGENTA_SHULKER_BOX":
                    case "MAGENTA_GLAZED_TERRACOTTA":
                        mat = Material.STAINED_CLAY;
                        type.addProperty("d", 2);
                        break;
                    case "LIGHT_BLUE_SHULKER_BOX":
                    case "LIGHT_BLUE_GLAZED_TERRACOTTA":
                        mat = Material.STAINED_CLAY;
                        type.addProperty("d", 3);
                        break;
                    case "YELLOW_SHULKER_BOX":
                    case "YELLOW_GLAZED_TERRACOTTA":
                        mat = Material.STAINED_CLAY;
                        type.addProperty("d", 4);
                        break;
                    case "LIME_SHULKER_BOX":
                    case "LIME_GLAZED_TERRACOTTA":
                        mat = Material.STAINED_CLAY;
                        type.addProperty("d", 5);
                        break;
                    case "PINK_SHULKER_BOX":
                    case "PINK_GLAZED_TERRACOTTA":
                        mat = Material.STAINED_CLAY;
                        type.addProperty("d", 6);
                        break;
                    case "GRAY_SHULKER_BOX":
                    case "GRAY_GLAZED_TERRACOTTA":
                        mat = Material.STAINED_CLAY;
                        type.addProperty("d", 7);
                        break;
                    case "SILVER_SHULKER_BOX":
                    case "SILVER_GLAZED_TERRACOTTA":
                        mat = Material.STAINED_CLAY;
                        type.addProperty("d", 8);
                        break;
                    case "CYAN_SHULKER_BOX":
                    case "CYAN_GLAZED_TERRACOTTA":
                        mat = Material.STAINED_CLAY;
                        type.addProperty("d", 9);
                        break;
                    case "PURPLE_SHULKER_BOX":
                    case "PURPLE_GLAZED_TERRACOTTA":
                        mat = Material.STAINED_CLAY;
                        type.addProperty("d", 10);
                        break;
                    case "BLUE_SHULKER_BOX":
                    case "BLUE_GLAZED_TERRACOTTA":
                        mat = Material.STAINED_CLAY;
                        type.addProperty("d", 11);
                        break;
                    case "BROWN_SHULKER_BOX":
                    case "BROWN_GLAZED_TERRACOTTA":
                        mat = Material.STAINED_CLAY;
                        type.addProperty("d", 12);
                        break;
                    case "GREEN_SHULKER_BOX":
                    case "GREEN_GLAZED_TERRACOTTA":
                        mat = Material.STAINED_CLAY;
                        type.addProperty("d", 13);
                        break;
                    case "RED_SHULKER_BOX":
                    case "RED_GLAZED_TERRACOTTA":
                        mat = Material.STAINED_CLAY;
                        type.addProperty("d", 14);
                        break;
                    case "BLACK_SHULKER_BOX":
                    case "BLACK_GLAZED_TERRACOTTA":
                        mat = Material.STAINED_CLAY;
                        type.addProperty("d", 15);
                        break;
                    case "CONCRETE":
                        mat = Material.STAINED_CLAY;
                        break;
                    case "CONCRETE_POWDER":
                        mat = Material.SAND;
                        break;
                    }

                    // If mat was changed, we warn the player that some blocks are changed
                    // And we also change the Json because it is reused after
                    if (mat != null) {
                        blocsConvertis = true;
                        type.addProperty("t", mat.toString());
                    }
                }
                if (mat == null)
                    throw new UnknownMaterialException("material \"" + type.get("t").getAsString()
                            + "\" does not exist in your Minecraft version.");
                if (mat == Material.SIGN_POST || mat == Material.WALL_SIGN || mat == Material.STANDING_BANNER
                        || mat == Material.WALL_BANNER || mat == Material.VINE || mat == Material.LADDER
                        || mat == Material.SKULL || mat == Material.BEACON || mat == Material.CARPET
                        || mat == Material.SNOW || mat == Material.GLOWSTONE || mat == Material.REDSTONE_LAMP_ON
                        || mat == Material.SEA_LANTERN || mat == Material.JACK_O_LANTERN
                        || mat == Material.BED_BLOCK || mat.name().contains("PISTON")
                        || mat.name().contains("STAIR") || mat.name().contains("CHORUS")
                        || mat.name().contains("DOOR")) {
                    blocsDelai.add(jsO);

                    if (mat == Material.BEACON && uuid.equalsIgnoreCase("e7d54103-66ec-42a1-9895-560c77e2cdf1")) // Dans Beacon Barrage, on ajoute des blocs sous les balises...
                    {
                        Map<Character, Integer> coords = CPUtils.parseCoordinates(jsO.get("c").getAsString());
                        listeBlocs.put(new Vector(xMin + coords.get('x'), yMin + coords.get('y') - 1,
                                zMin + coords.get('z')), new MaterialData(mat));
                        listeBlocs.put(new Vector(xMin + coords.get('x') - 1, yMin + coords.get('y') - 1,
                                zMin + coords.get('z')), new MaterialData(mat));
                        listeBlocs.put(new Vector(xMin + coords.get('x') - 1, yMin + coords.get('y') - 1,
                                zMin + coords.get('z') - 1), new MaterialData(mat));
                        listeBlocs.put(new Vector(xMin + coords.get('x') - 1, yMin + coords.get('y') - 1,
                                zMin + coords.get('z') + 1), new MaterialData(mat));
                        listeBlocs.put(new Vector(xMin + coords.get('x') + 1, yMin + coords.get('y') - 1,
                                zMin + coords.get('z')), new MaterialData(mat));
                        listeBlocs.put(new Vector(xMin + coords.get('x') + 1, yMin + coords.get('y') - 1,
                                zMin + coords.get('z') - 1), new MaterialData(mat));
                        listeBlocs.put(new Vector(xMin + coords.get('x') + 1, yMin + coords.get('y') - 1,
                                zMin + coords.get('z') + 1), new MaterialData(mat));
                        listeBlocs.put(new Vector(xMin + coords.get('x'), yMin + coords.get('y') - 1,
                                zMin + coords.get('z') - 1), new MaterialData(mat));
                        listeBlocs.put(new Vector(xMin + coords.get('x'), yMin + coords.get('y') - 1,
                                zMin + coords.get('z') + 1), new MaterialData(mat));
                    }
                } else if (mat == Material.LEVER
                        || (mat.name().contains("REDSTONE") && !mat.name().contains("LAMP")
                                && !mat.name().contains("ORE"))
                        || mat.name().contains("BUTTON") || mat.name().contains("DIODE")
                        || mat.name().contains("TORCH") || mat.name().contains("_PLATE")) {
                    blocsRedstone.add(jsO);
                } else {
                    Map<Character, Integer> coords = CPUtils.parseCoordinates(jsO.get("c").getAsString());
                    Vector vect = new Vector(xMin + coords.get('x'), yMin + coords.get('y'),
                            zMin + coords.get('z'));
                    final Block b = m.getBlockAt(xMin + coords.get('x'), yMin + coords.get('y'),
                            zMin + coords.get('z'));
                    if (b.getX() < xMin || b.getY() < yMin || b.getZ() < zMin || b.getX() > xMax
                            || b.getY() > yMax || b.getZ() > zMax) // Si le bloc n'est pas dans la map
                    {
                        throw new SecurityException();
                    } else {
                        listeBlocs.put(vect, new MaterialData(mat, type.get("d").getAsByte()));
                    }
                }
            }
            sender.sendMessage(ChatColor.GRAY + "" + ChatColor.ITALIC + "30 %");

            // Placement des blocs
            remplisseur = new RemplisseurBlocs(listeBlocs, m, sender, 30);
            remplisseur.runTaskTimer(CreativeParkour.getPlugin(), 1, 1);

            // Autres blocs
            Map<Integer, List<JsonObject>> listeDelais = new HashMap<Integer, List<JsonObject>>();
            int delai = remplisseur.getDureeTraitement() + 1;
            int cpt64 = 0; // Le dlai augmente ds que ce truc est un multiple de 64
            for (JsonObject jsO : blocsDelai) {
                if (!listeDelais.containsKey(delai)) {
                    listeDelais.put(delai, new ArrayList<JsonObject>());
                }
                listeDelais.get(delai).add(jsO);

                // Incrmentation
                if (cpt64 % 64 == 0)
                    delai++;
                cpt64++;
            }
            // Blocs redstone aprs les autres, 2 fois
            delai++;
            listeDelais.put(delai, new ArrayList<JsonObject>());
            listeDelais.put(delai + 20, new ArrayList<JsonObject>());
            for (JsonObject jsO : blocsRedstone) {
                listeDelais.get(delai).add(jsO);
                listeDelais.get(delai + 20).add(jsO);
            }
            new RemplisseurBlocsDelai(listeDelais, types, m, xMin, yMin, zMin, xMax, yMax, zMax)
                    .runTaskTimer(CreativeParkour.getPlugin(), 1, 1);

            // Entits
            final JsonArray entites = jsContenu.get("entites").getAsJsonArray();
            Bukkit.getScheduler().runTaskLater(CreativeParkour.getPlugin(), new Runnable() {
                public void run() {
                    for (JsonElement jsE : entites) {
                        JsonObject jsO = jsE.getAsJsonObject();
                        Location loc = new Location(m, xMin + jsO.get("x").getAsDouble(),
                                yMin + jsO.get("y").getAsDouble(), zMin + jsO.get("z").getAsDouble(),
                                jsO.get("yaw").getAsFloat(), jsO.get("pitch").getAsFloat());
                        try {
                            Entity e = m.spawnEntity(loc, EntityType.valueOf(jsO.get("type").getAsString()));
                            if (e instanceof Painting) {
                                Painting painting = (Painting) e;
                                painting.setArt(Art.getByName(jsO.get("art").getAsString()));
                            } else if (e instanceof ItemFrame) {
                                ItemFrame itemFrame = (ItemFrame) e;
                                try {
                                    itemFrame.setItem(
                                            new ItemStack(Material.getMaterial(jsO.get("item").getAsString())));
                                } catch (NullPointerException e0) {
                                    // Nothing
                                }
                                itemFrame.setRotation(Rotation.valueOf(jsO.get("rotation").getAsString()));
                            }
                        } catch (IllegalArgumentException e) {
                            // Nothing
                        }
                    }
                }
            }, delai);

            String uuidCreateur = CPUtils.separerUuidNom(jsData.get("createur").getAsString()).get("uuid");
            NameManager.enregistrerNomJoueur(uuidCreateur,
                    CPUtils.separerUuidNom(jsData.get("createur").getAsString()).get("nom"));

            // Blocs spciaux
            List<BlocSpecial> blocsSpeciaux = new ArrayList<BlocSpecial>();
            BlocSpawn spawn = null;
            JsonArray blocsS = jsContenu.get("blocs speciaux").getAsJsonArray();
            // Regroupement de tous les blocs sand un seul Array pour faciliter les choses aprs (c'tait divis dans d'anciennes versions car la programmeur est un con)
            JsonArray vrac = new JsonArray();
            for (JsonElement bloc : blocsS) {
                if (!bloc.isJsonArray()) // Que pour spawn, dparts, arrives, mort
                {
                    vrac.add(bloc);
                } else {
                    for (JsonElement bloc2 : bloc.getAsJsonArray())
                        vrac.add(bloc2);
                }
            }
            // Traitement des blocs spciaux
            for (JsonElement bloc : vrac) {
                JsonObject jsO = bloc.getAsJsonObject();
                String type = jsO.get("t").getAsString();
                Map<Character, Integer> coords = CPUtils.parseCoordinates(jsO.get("c").getAsString());
                Block block = m.getBlockAt(xMin + coords.get('x'), yMin + coords.get('y'),
                        zMin + coords.get('z'));
                byte dir = jsO.has("dir") ? jsO.get("dir").getAsByte() : 0;

                if (type.equalsIgnoreCase(BlocSpawn.getType())) // Spawn
                {
                    spawn = new BlocSpawn(block, dir);
                } else if (type.equalsIgnoreCase(BlocDepart.getType())) // Dparts
                {
                    blocsSpeciaux.add(new BlocDepart(block));
                } else if (type.equalsIgnoreCase(BlocArrivee.getType())) // Arrives
                {
                    blocsSpeciaux.add(new BlocArrivee(block));
                } else if (type.equalsIgnoreCase(BlocCheckpoint.getType())) // Checkpoints
                {
                    blocsSpeciaux.add(new BlocCheckpoint(block, dir, jsO.get("prop").getAsString()));
                } else if (type.equalsIgnoreCase(BlocEffet.getType())) // Effets
                {
                    blocsSpeciaux.add(new BlocEffet(block, jsO.get("effect").getAsString(),
                            jsO.get("duration").getAsInt(), jsO.get("amplifier").getAsInt()));
                } else if (type.equalsIgnoreCase(BlocGive.getType())) // Gives
                {
                    blocsSpeciaux.add(new BlocGive(block, jsO.get("type").getAsString(),
                            jsO.get("action").getAsString()));
                } else if (type.equalsIgnoreCase(BlocMort.getType())) // Morts
                {
                    blocsSpeciaux.add(new BlocMort(block));
                } else if (type.equalsIgnoreCase(BlocTP.getType())) // TP
                {
                    blocsSpeciaux.add(new BlocTP(block, new Location(m, xMin + jsO.get("x").getAsDouble(),
                            yMin + jsO.get("y").getAsDouble(), zMin + jsO.get("z").getAsDouble())));
                }
            }

            Set<UUID> contributeurs = new HashSet<UUID>();
            if (jsData.get("contributeurs").isJsonArray()) {
                JsonArray c = jsData.get("contributeurs").getAsJsonArray();
                for (JsonElement contributeur : c) {
                    String contributeurS = contributeur.getAsString();
                    if (!contributeurS.isEmpty()) {
                        String uuidContrib = CPUtils.separerUuidNom(contributeurS).get("uuid");
                        contributeurs.add(UUID.fromString(uuidContrib));
                        NameManager.enregistrerNomJoueur(uuidContrib,
                                CPUtils.separerUuidNom(contributeurS).get("nom"));
                    }
                }
            }

            // Nettoyage du spawn pour pas que le mec tombe
            spawn.getBloc().setType(Material.AIR);
            spawn.getBloc().getRelative(BlockFace.UP).setType(Material.AIR);
            spawn.getBloc().getRelative(BlockFace.DOWN).setType(Material.BEDROCK);

            final CPMap map = new CPMap(id, uuid, etatAMettre, m, m.getBlockAt(xMin, yMin, zMin),
                    m.getBlockAt(xMax, yMax, zMax), nomMap, UUID.fromString(uuidCreateur), contributeurs, false,
                    spawn, blocsSpeciaux, jsContenu.get("hauteurMort").getAsInt(),
                    (jsContenu.has("sneakAutorise") ? jsContenu.get("sneakAutorise").getAsBoolean() : true),
                    (jsContenu.has("mortLave") ? jsContenu.get("mortLave").getAsBoolean() : false),
                    (jsContenu.has("mortEau") ? jsContenu.get("mortEau").getAsBoolean() : false),
                    (jsContenu.has("interactionsAutorisees")
                            ? jsContenu.get("interactionsAutorisees").getAsBoolean()
                            : true),
                    null, jsData.get("difficulte").getAsFloat(), jsData.get("qualite").getAsFloat(), false);
            maps.put(id, map);
            map.sauvegarder();

            map.setRemplisseur(remplisseur);

            if (blocsConvertis)
                sender.sendMessage(
                        Config.prefix() + ChatColor.YELLOW + Langues.getMessage("play.download converted"));

            return map;

        } catch (Exception | Error e) {
            CreativeParkour.erreur("TELECHARGER/IMPORTER-" + uuid, e, true);
            if (remplisseur != null)
                remplisseur.cancel();
            File f = getFichierMap(id);
            if (f != null && f.exists())
                f.delete();
        }
    }
    return null;
}