Search in sources :

Example 1 with CrateHologram

use of com.badbones69.crazycrates.api.objects.CrateHologram in project Crazy-Crates by Crazy-Crew.

the class DecentHolograms method createHologram.

public void createHologram(Block block, Crate crate) {
    CrateHologram crateHologram = crate.getHologram();
    if (!crateHologram.isEnabled())
        return;
    double height = crateHologram.getHeight();
    Hologram hologram = DHAPI.createHologram(ThreadLocalRandom.current().nextInt() + "", block.getLocation().add(.5, height, .5));
    crateHologram.getMessages().forEach(line -> DHAPI.addHologramLine(hologram, color(line)));
    holograms.put(block, hologram);
}
Also used : CrateHologram(com.badbones69.crazycrates.api.objects.CrateHologram) CrateHologram(com.badbones69.crazycrates.api.objects.CrateHologram) Hologram(eu.decentsoftware.holograms.api.holograms.Hologram)

Example 2 with CrateHologram

use of com.badbones69.crazycrates.api.objects.CrateHologram in project Crazy-Crates by Crazy-Crew.

the class CrazyManager method loadCrates.

/**
 * Loads all the information the plugin needs to run.
 */
public void loadCrates() {
    giveNewPlayersKeys = false;
    crates.clear();
    brokecrates.clear();
    crateLocations.clear();
    crateSchematics.clear();
    nmsSupport = new NMS_Support();
    quadCrateTimer = Files.CONFIG.getFile().getInt("Settings.QuadCrate.Timer") * 20;
    giveVirtualKeysWhenInventoryFull = Files.CONFIG.getFile().getBoolean("Settings.Give-Virtual-Keys-When-Inventory-Full");
    if (Support.HOLOGRAPHIC_DISPLAYS.isPluginLoaded()) {
        hologramController = new HolographicSupport();
    } else if (Support.DECENT_HOLOGRAMS.isPluginLoaded()) {
        hologramController = new DecentHolograms();
    }
    // Removes all holograms so that they can be replaced.
    if (hologramController != null) {
        hologramController.removeAllHolograms();
    }
    if (fileManager.isLogging())
        getJavaPlugin().getLogger().info("Loading all crate information...");
    for (String crateName : fileManager.getAllCratesNames()) {
        // if(fileManager.isLogging()) plugin.getLogger().info(fileManager.getPrefix() + "Loading " + crateName + ".yml information....");
        try {
            FileConfiguration file = fileManager.getFile(crateName).getFile();
            CrateType crateType = CrateType.getFromName(file.getString("Crate.CrateType"));
            ArrayList<Prize> prizes = new ArrayList<>();
            String previewName = file.contains("Crate.Preview-Name") ? file.getString("Crate.Preview-Name") : file.getString("Crate.Name");
            ArrayList<Tier> tiers = new ArrayList<>();
            if (file.contains("Crate.Tiers") && file.getConfigurationSection("Crate.Tiers") != null) {
                for (String tier : file.getConfigurationSection("Crate.Tiers").getKeys(false)) {
                    String path = "Crate.Tiers." + tier;
                    tiers.add(new Tier(tier, file.getString(path + ".Name"), file.getString(path + ".Color"), file.getInt(path + ".Chance"), file.getInt(path + ".MaxRange")));
                }
            }
            if (crateType == CrateType.COSMIC && tiers.isEmpty()) {
                brokecrates.add(crateName);
                getJavaPlugin().getLogger().warning("No tiers were found for this cosmic crate " + crateName + ".yml file.");
                continue;
            }
            for (String prize : file.getConfigurationSection("Crate.Prizes").getKeys(false)) {
                Prize altPrize = null;
                String path = "Crate.Prizes." + prize;
                ArrayList<Tier> prizeTiers = new ArrayList<>();
                for (String tier : file.getStringList(path + ".Tiers")) {
                    for (Tier loadedTier : tiers) {
                        if (loadedTier.getName().equalsIgnoreCase(tier)) {
                            prizeTiers.add(loadedTier);
                        }
                    }
                }
                if (file.contains(path + ".Alternative-Prize")) {
                    if (file.getBoolean(path + ".Alternative-Prize.Toggle")) {
                        altPrize = new Prize("Alternative-Prize", file.getStringList(path + ".Alternative-Prize.Messages"), file.getStringList(path + ".Alternative-Prize.Commands"), // No editor items
                        null, getItems(file, prize + ".Alternative-Prize"));
                    }
                }
                ArrayList<ItemStack> editorItems = new ArrayList<>();
                if (file.contains(path + ".Editor-Items")) {
                    for (Object list : file.getList(path + ".Editor-Items")) {
                        editorItems.add((ItemStack) list);
                    }
                }
                prizes.add(new Prize(prize, getDisplayItem(file, prize), file.getStringList(path + ".Messages"), file.getStringList(path + ".Commands"), editorItems, getItems(file, prize), crateName, file.getInt(path + ".Chance", 100), file.getInt(path + ".MaxRange", 100), file.getBoolean(path + ".Firework"), file.getStringList(path + ".BlackListed-Permissions"), prizeTiers, altPrize));
            }
            int newPlayersKeys = file.getInt("Crate.StartingKeys");
            if (!giveNewPlayersKeys) {
                if (newPlayersKeys > 0) {
                    giveNewPlayersKeys = true;
                }
            }
            crates.add(new Crate(crateName, previewName, crateType, getKey(file), prizes, file, newPlayersKeys, tiers, new CrateHologram(file.getBoolean("Crate.Hologram.Toggle"), file.getDouble("Crate.Hologram.Height", 0.0), file.getStringList("Crate.Hologram.Message"))));
        } catch (Exception e) {
            brokecrates.add(crateName);
            getJavaPlugin().getLogger().warning("There was an error while loading the " + crateName + ".yml file.");
            e.printStackTrace();
        }
    }
    crates.add(new Crate("Menu", "Menu", CrateType.MENU, new ItemStack(Material.AIR), new ArrayList<>(), null, 0, null, null));
    if (fileManager.isLogging())
        getJavaPlugin().getLogger().info("All crate information has been loaded.");
    if (fileManager.isLogging())
        getJavaPlugin().getLogger().info("Loading all the physical crate locations.");
    FileConfiguration locations = Files.LOCATIONS.getFile();
    int loadedAmount = 0;
    int brokeAmount = 0;
    if (locations.getConfigurationSection("Locations") != null) {
        for (String locationName : locations.getConfigurationSection("Locations").getKeys(false)) {
            try {
                String worldName = locations.getString("Locations." + locationName + ".World");
                World world = getJavaPlugin().getServer().getWorld(worldName);
                int x = locations.getInt("Locations." + locationName + ".X");
                int y = locations.getInt("Locations." + locationName + ".Y");
                int z = locations.getInt("Locations." + locationName + ".Z");
                Location location = new Location(world, x, y, z);
                Crate crate = getCrateFromName(locations.getString("Locations." + locationName + ".Crate"));
                if (world != null && crate != null) {
                    crateLocations.add(new CrateLocation(locationName, crate, location));
                    if (hologramController != null) {
                        hologramController.createHologram(location.getBlock(), crate);
                    }
                    loadedAmount++;
                } else {
                    brokeLocations.add(new BrokeLocation(locationName, crate, x, y, z, worldName));
                    brokeAmount++;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    // Checking if all physical locations loaded
    if (fileManager.isLogging()) {
        if (loadedAmount > 0 || brokeAmount > 0) {
            if (brokeAmount <= 0) {
                getJavaPlugin().getLogger().info("All physical crate locations have been loaded.");
            } else {
                getJavaPlugin().getLogger().info("Loaded " + loadedAmount + " physical crate locations.");
                getJavaPlugin().getLogger().info("Failed to load " + brokeAmount + " physical crate locations.");
            }
        }
    }
    // Loading schematic files
    if (fileManager.isLogging())
        getJavaPlugin().getLogger().info("Searching for schematics to load.");
    String[] schems = new File(getJavaPlugin().getDataFolder() + "/schematics/").list();
    for (String schematicName : schems) {
        if (schematicName.endsWith(".nbt")) {
            crateSchematics.add(new CrateSchematic(schematicName.replace(".nbt", ""), new File(getJavaPlugin().getDataFolder() + "/schematics/" + schematicName)));
            if (fileManager.isLogging())
                getJavaPlugin().getLogger().info(schematicName + " was successfully found and loaded.");
        }
    }
    if (fileManager.isLogging())
        getJavaPlugin().getLogger().info("All schematics were found and loaded.");
    cleanDataFile();
    Preview.loadButtons();
}
Also used : HolographicSupport(com.badbones69.crazycrates.support.holograms.HolographicSupport) BrokeLocation(com.badbones69.crazycrates.api.enums.BrokeLocation) DecentHolograms(com.badbones69.crazycrates.support.holograms.DecentHolograms) World(org.bukkit.World) FileConfiguration(org.bukkit.configuration.file.FileConfiguration) NMS_Support(com.badbones69.crazycrates.nms.NMS_Support) CrateType(com.badbones69.crazycrates.api.enums.CrateType) ItemStack(org.bukkit.inventory.ItemStack) File(java.io.File) Location(org.bukkit.Location) BrokeLocation(com.badbones69.crazycrates.api.enums.BrokeLocation)

Example 3 with CrateHologram

use of com.badbones69.crazycrates.api.objects.CrateHologram in project Crazy-Crates by Crazy-Crew.

the class HolographicSupport method createHologram.

public void createHologram(Block block, Crate crate) {
    CrateHologram crateHologram = crate.getHologram();
    if (!crateHologram.isEnabled())
        return;
    double height = crateHologram.getHeight();
    Hologram hologram = HologramsAPI.createHologram(CrazyManager.getJavaPlugin(), block.getLocation().add(.5, height, .5));
    crateHologram.getMessages().forEach(line -> hologram.appendTextLine(color(line)));
    holograms.put(block, hologram);
}
Also used : CrateHologram(com.badbones69.crazycrates.api.objects.CrateHologram) CrateHologram(com.badbones69.crazycrates.api.objects.CrateHologram) Hologram(com.gmail.filoghost.holographicdisplays.api.Hologram)

Aggregations

CrateHologram (com.badbones69.crazycrates.api.objects.CrateHologram)2 BrokeLocation (com.badbones69.crazycrates.api.enums.BrokeLocation)1 CrateType (com.badbones69.crazycrates.api.enums.CrateType)1 NMS_Support (com.badbones69.crazycrates.nms.NMS_Support)1 DecentHolograms (com.badbones69.crazycrates.support.holograms.DecentHolograms)1 HolographicSupport (com.badbones69.crazycrates.support.holograms.HolographicSupport)1 Hologram (com.gmail.filoghost.holographicdisplays.api.Hologram)1 Hologram (eu.decentsoftware.holograms.api.holograms.Hologram)1 File (java.io.File)1 Location (org.bukkit.Location)1 World (org.bukkit.World)1 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)1 ItemStack (org.bukkit.inventory.ItemStack)1