Search in sources :

Example 1 with YamlConfiguration

use of com.loohp.interactivechat.libs.com.loohp.yamlconfiguration.YamlConfiguration in project InteractiveChat-DiscordSRV-Addon by LOOHP.

the class MinecraftFontRenderer method loadResources.

public void loadResources() {
    try {
        if (!resourceLock.tryLock(0, TimeUnit.MILLISECONDS)) {
            return;
        }
    } catch (InterruptedException e) {
    }
    reloadResourcesButton.setEnabled(false);
    resourceBar.setValue(0);
    resourceBar.setVisible(true);
    textAreaResources.setText("Loading Resources...");
    updateTextAreaInputSize();
    List<String> resourceOrder;
    int valuePerPack;
    try {
        YamlConfiguration yaml = new YamlConfiguration(new FileInputStream("InteractiveChatDiscordSrvAddon/config.yml"));
        resourceOrder = yaml.getStringList("Resources.Order");
        Collections.reverse(resourceOrder);
        valuePerPack = (int) ((1.0 / (double) (resourceOrder.size() + 1)) * 10000);
    } catch (IOException e) {
        Toolkit.getDefaultToolkit().beep();
        JOptionPane.showMessageDialog(null, GUIMain.createLabel("There is an error while loading from config:\n" + e.getMessage(), 13, Color.RED), title, JOptionPane.ERROR_MESSAGE);
        return;
    }
    if (resourceManager != null) {
        resourceManager.close();
    }
    PrintStream original = System.err;
    try {
        resourceManager = new ResourceManager();
        resourceManager.loadResources(new File("InteractiveChatDiscordSrvAddon/built-in", "Default"));
        resourceBar.setValue(valuePerPack);
        for (String resourceName : resourceOrder) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            System.setErr(new PrintStream(baos));
            try {
                File resourcePackFile = new File("InteractiveChatDiscordSrvAddon/resourcepacks/" + resourceName);
                ResourcePackInfo info = resourceManager.loadResources(resourcePackFile);
            } catch (Exception e) {
                e.printStackTrace();
            }
            String error = baos.toString();
            if (!error.isEmpty()) {
                ForkJoinPool.commonPool().execute(() -> JOptionPane.showMessageDialog(null, GUIMain.createLabel("There are errors while loading \"" + resourceName + "\":\n" + error, 13, Color.RED), title, JOptionPane.ERROR_MESSAGE));
            }
            resourceBar.setValue(resourceBar.getValue() + valuePerPack);
        }
    } catch (Throwable e) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        Toolkit.getDefaultToolkit().beep();
        JOptionPane.showMessageDialog(null, GUIMain.createLabel("An error occurred!\n" + sw, 13, Color.RED), title, JOptionPane.ERROR_MESSAGE);
    }
    System.setErr(original);
    textAreaResources.setText("Loaded Resources:\n");
    for (ResourcePackInfo info : resourceManager.getResourcePackInfo()) {
        textAreaResources.append(" - " + info.getName());
        if (!info.getStatus()) {
            textAreaResources.append(" (Failed)");
        }
        textAreaResources.append("\n");
    }
    List<LanguageData> languages = getAllLanguageData(resourceManager.getLanguageManager());
    String lastSelected = comboBoxLanguages.getSelectedItem() == null ? null : ((LanguageData) comboBoxLanguages.getSelectedItem()).getLanguage();
    comboBoxLanguages.removeAllItems();
    for (LanguageData language : languages) {
        comboBoxLanguages.addItem(language);
    }
    Optional<LanguageData> optLanguage = languages.stream().filter(each -> each.getLanguage().equalsIgnoreCase(lastSelected == null ? "en_us" : lastSelected)).findFirst();
    if (optLanguage.isPresent()) {
        comboBoxLanguages.setSelectedItem(optLanguage.get());
    } else {
        comboBoxLanguages.setSelectedIndex(0);
    }
    reloadResourcesButton.setEnabled(true);
    resourceBar.setVisible(false);
    updateTextAreaInputSize();
    resourceLock.unlock();
}
Also used : Color(java.awt.Color) YamlConfiguration(com.loohp.interactivechat.libs.com.loohp.yamlconfiguration.YamlConfiguration) URLClassLoaderAccess(com.loohp.interactivechatdiscordsrvaddon.libs.URLClassLoaderAccess) ResourcePackInfo(com.loohp.interactivechatdiscordsrvaddon.resources.ResourcePackInfo) RenderingHints(java.awt.RenderingHints) TextureAnimation(com.loohp.interactivechatdiscordsrvaddon.resources.textures.TextureAnimation) URLClassLoader(java.net.URLClassLoader) ImageIO(javax.imageio.ImageIO) MouseAdapter(java.awt.event.MouseAdapter) TextureResource(com.loohp.interactivechatdiscordsrvaddon.resources.textures.TextureResource) JFileChooser(javax.swing.JFileChooser) JComboBox(javax.swing.JComboBox) JFrame(javax.swing.JFrame) BorderLayout(java.awt.BorderLayout) Clipboard(java.awt.datatransfer.Clipboard) PrintWriter(java.io.PrintWriter) BufferedImage(java.awt.image.BufferedImage) BorderFactory(javax.swing.BorderFactory) Icon(javax.swing.Icon) LanguageManager(com.loohp.interactivechatdiscordsrvaddon.resources.languages.LanguageManager) ComponentEvent(java.awt.event.ComponentEvent) KeyEvent(java.awt.event.KeyEvent) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) Objects(java.util.Objects) Dimension(java.awt.Dimension) List(java.util.List) GridConstraints(com.loohp.interactivechat.libs.com.intellij.uiDesigner.core.GridConstraints) JCheckBox(javax.swing.JCheckBox) Graphics(java.awt.Graphics) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) JPanel(javax.swing.JPanel) WindowConstants(javax.swing.WindowConstants) Toolkit(java.awt.Toolkit) Insets(java.awt.Insets) ImageUtils(com.loohp.interactivechatdiscordsrvaddon.graphics.ImageUtils) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JTextField(javax.swing.JTextField) ResourceManager(com.loohp.interactivechatdiscordsrvaddon.resources.ResourceManager) SpinnerNumberModel(javax.swing.SpinnerNumberModel) CompletableFuture(java.util.concurrent.CompletableFuture) KeyAdapter(java.awt.event.KeyAdapter) AtomicReference(java.util.concurrent.atomic.AtomicReference) ComponentStyling(com.loohp.interactivechat.utils.ComponentStyling) ArrayList(java.util.ArrayList) GridLayout(java.awt.GridLayout) SwingUtilities(javax.swing.SwingUtilities) FocusAdapter(java.awt.event.FocusAdapter) ResourceDownloadManager(com.loohp.interactivechatdiscordsrvaddon.resources.ResourceDownloadManager) PlainTextComponentSerializer(com.loohp.interactivechat.libs.net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer) JMenuItem(javax.swing.JMenuItem) Graphics2D(java.awt.Graphics2D) JProgressBar(javax.swing.JProgressBar) ExecutorService(java.util.concurrent.ExecutorService) GsonComponentSerializer(com.loohp.interactivechat.libs.net.kyori.adventure.text.serializer.gson.GsonComponentSerializer) JComponent(javax.swing.JComponent) PrintStream(java.io.PrintStream) JButton(javax.swing.JButton) JSpinner(javax.swing.JSpinner) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Component(com.loohp.interactivechat.libs.net.kyori.adventure.text.Component) ResourceRegistry(com.loohp.interactivechatdiscordsrvaddon.registry.ResourceRegistry) JPopupMenu(javax.swing.JPopupMenu) StringWriter(java.io.StringWriter) Spacer(com.loohp.interactivechat.libs.com.intellij.uiDesigner.core.Spacer) TextureMeta(com.loohp.interactivechatdiscordsrvaddon.resources.textures.TextureMeta) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) JOptionPane(javax.swing.JOptionPane) MouseEvent(java.awt.event.MouseEvent) File(java.io.File) JScrollPane(javax.swing.JScrollPane) ComponentAdapter(java.awt.event.ComponentAdapter) TimeUnit(java.util.concurrent.TimeUnit) GridLayoutManager(com.loohp.interactivechat.libs.com.intellij.uiDesigner.core.GridLayoutManager) JLabel(javax.swing.JLabel) FocusEvent(java.awt.event.FocusEvent) ForkJoinPool(java.util.concurrent.ForkJoinPool) ChatColorUtils(com.loohp.interactivechat.utils.ChatColorUtils) TextureProperties(com.loohp.interactivechatdiscordsrvaddon.resources.textures.TextureProperties) JTextArea(javax.swing.JTextArea) NamedTextColor(com.loohp.interactivechat.libs.net.kyori.adventure.text.format.NamedTextColor) Collections(java.util.Collections) LegacyComponentSerializer(com.loohp.interactivechat.libs.net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer) PrintStream(java.io.PrintStream) IOException(java.io.IOException) ResourceManager(com.loohp.interactivechatdiscordsrvaddon.resources.ResourceManager) ByteArrayOutputStream(java.io.ByteArrayOutputStream) YamlConfiguration(com.loohp.interactivechat.libs.com.loohp.yamlconfiguration.YamlConfiguration) FileInputStream(java.io.FileInputStream) ResourcePackInfo(com.loohp.interactivechatdiscordsrvaddon.resources.ResourcePackInfo) IOException(java.io.IOException) StringWriter(java.io.StringWriter) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 2 with YamlConfiguration

use of com.loohp.interactivechat.libs.com.loohp.yamlconfiguration.YamlConfiguration in project InteractiveChat-DiscordSRV-Addon by LOOHP.

the class GUIMain method validConfigs.

protected static void validConfigs(String title, Icon icon) throws IOException {
    File folder = new File("InteractiveChatDiscordSrvAddon");
    if (!folder.exists() || !folder.isDirectory()) {
        Toolkit.getDefaultToolkit().beep();
        JOptionPane.showMessageDialog(null, createLabel("Error: Plugin folder not found", 15, Color.RED), title, JOptionPane.ERROR_MESSAGE, icon);
        return;
    }
    Map<File, List<String>> results = new LinkedHashMap<>();
    for (File file : folder.listFiles()) {
        String fileName = file.getName();
        if (fileName.endsWith(".yml")) {
            YamlConfiguration yaml = new YamlConfiguration(new FileInputStream(file));
            results.put(file, validateConfigurationSection("", yaml));
        }
    }
    StringBuilder message = new StringBuilder("Validation Results: (Plugin Folder: " + folder.getAbsolutePath() + ")\n");
    for (Entry<File, List<String>> entry : results.entrySet()) {
        String fileName = entry.getKey().getName();
        List<String> errors = entry.getValue();
        message.append("\n").append(fileName).append(": ");
        if (errors.isEmpty()) {
            message.append("Valid!\n");
        } else {
            message.append("\n");
            for (String error : errors) {
                message.append(error).append("\n");
            }
        }
    }
    message.append("\nNote that a valid config doesn't mean REGEX are valid.");
    JOptionPane.showMessageDialog(null, createLabel(message.toString(), 13), title, JOptionPane.INFORMATION_MESSAGE, icon);
}
Also used : LinkedList(java.util.LinkedList) List(java.util.List) YamlConfiguration(com.loohp.interactivechat.libs.com.loohp.yamlconfiguration.YamlConfiguration) File(java.io.File) FileInputStream(java.io.FileInputStream) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with YamlConfiguration

use of com.loohp.interactivechat.libs.com.loohp.yamlconfiguration.YamlConfiguration in project InteractiveChat-DiscordSRV-Addon by LOOHP.

the class GUIMain method launch.

public static void launch(String[] args) {
    String title = "InteractiveChat DiscordSRV Addon Tools";
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        Enumeration<URL> enumeration = GUIMain.class.getClassLoader().getResources("plugin.yml");
        YamlConfiguration pluginYaml = new YamlConfiguration(enumeration.nextElement().openStream());
        String pluginName = pluginYaml.getString("name");
        String version = pluginYaml.getString("version");
        YamlConfiguration icPluginYaml = new YamlConfiguration(enumeration.nextElement().openStream());
        String icPluginName = icPluginYaml.getString("name");
        String icVersion = icPluginYaml.getString("version");
        String append;
        if (compatible()) {
            append = "Select one of the tools below";
        } else {
            append = "<p style=\"color:red;\"><b>These versions of InteractiveChat & InteractiveChat DiscordSRV Addon are incompatible!<br>Please Upgrade!</b></p>";
        }
        BufferedImage image = ImageIO.read(GUIMain.class.getClassLoader().getResourceAsStream("icon.png"));
        Icon icon = new ImageIcon(image);
        title = pluginName + " v" + version + " Tools";
        String message = "<html><center><b>You are running " + pluginName + " v" + version + "</b><br>" + "(Paired with " + icPluginName + " v" + icVersion + ")<br>" + append + "<html/>";
        JLabel messageLabel = createLabel(message, 15);
        messageLabel.setHorizontalAlignment(SwingConstants.CENTER);
        BufferedImage resizedIcon = new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = resizedIcon.createGraphics();
        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        g.drawImage(image, 0, 0, 32, 32, null);
        g.dispose();
        main: while (true) {
            int input = JOptionPane.showOptionDialog(null, messageLabel, title, JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, icon, new Object[] { "Check for Updates", "Validate Plugin Configs", "Generate Default Configs", "Download Assets", "Block Model Renderer (1.13+)", "Minecraft Font Renderer (1.13+)", "Visit Links" }, null);
            switch(input) {
                case 0:
                    checkForUpdates(title, icon, version);
                    break;
                case 1:
                    validConfigs(title, icon);
                    break;
                case 2:
                    generateDefaultConfigs(title, icon);
                    break;
                case 3:
                    downloadAssets(title, resizedIcon, icon);
                    break;
                case 4:
                    blockModelRenderer(title, resizedIcon, icon);
                    break main;
                case 5:
                    minecraftFontRenderer(title, resizedIcon, icon);
                    break main;
                case 6:
                    visitLinks(title, icon);
                    break;
                default:
                    break main;
            }
        }
    } catch (Throwable e) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        Toolkit.getDefaultToolkit().beep();
        JOptionPane.showMessageDialog(null, createLabel("An error occurred!\n" + sw, 13, Color.RED), title, JOptionPane.ERROR_MESSAGE);
    }
}
Also used : ImageIcon(javax.swing.ImageIcon) JLabel(javax.swing.JLabel) YamlConfiguration(com.loohp.interactivechat.libs.com.loohp.yamlconfiguration.YamlConfiguration) URL(java.net.URL) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) StringWriter(java.io.StringWriter) JSONObject(com.loohp.interactivechat.libs.org.json.simple.JSONObject) ImageIcon(javax.swing.ImageIcon) Icon(javax.swing.Icon) PrintWriter(java.io.PrintWriter)

Example 4 with YamlConfiguration

use of com.loohp.interactivechat.libs.com.loohp.yamlconfiguration.YamlConfiguration in project InteractiveChat-DiscordSRV-Addon by LOOHP.

the class BlockModelRenderer method loadResources.

public void loadResources() {
    try {
        if (!lock.tryLock(0, TimeUnit.MILLISECONDS)) {
            return;
        }
    } catch (InterruptedException e) {
    }
    renderModelButton.setEnabled(false);
    reloadResourcesButton.setEnabled(false);
    resourceBar.setValue(0);
    resourceBar.setVisible(true);
    textAreaResources.setText("Loading Resources...");
    List<String> resourceOrder;
    int valuePerPack;
    try {
        YamlConfiguration yaml = new YamlConfiguration(new FileInputStream("InteractiveChatDiscordSrvAddon/config.yml"));
        resourceOrder = yaml.getStringList("Resources.Order");
        Collections.reverse(resourceOrder);
        valuePerPack = (int) ((1.0 / (double) (resourceOrder.size() + 1)) * 10000);
    } catch (IOException e) {
        Toolkit.getDefaultToolkit().beep();
        JOptionPane.showMessageDialog(null, GUIMain.createLabel("There is an error while loading from config:\n" + e.getMessage(), 13, Color.RED), title, JOptionPane.ERROR_MESSAGE);
        return;
    }
    if (resourceManager != null) {
        resourceManager.close();
    }
    PrintStream original = System.err;
    try {
        resourceManager = new ResourceManager();
        resourceManager.loadResources(new File("InteractiveChatDiscordSrvAddon/built-in", "Default"));
        resourceBar.setValue(valuePerPack);
        for (String resourceName : resourceOrder) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            System.setErr(new PrintStream(baos));
            try {
                File resourcePackFile = new File("InteractiveChatDiscordSrvAddon/resourcepacks/" + resourceName);
                ResourcePackInfo info = resourceManager.loadResources(resourcePackFile);
            } catch (Exception e) {
                e.printStackTrace();
            }
            String error = baos.toString();
            if (!error.isEmpty()) {
                ForkJoinPool.commonPool().execute(() -> JOptionPane.showMessageDialog(null, GUIMain.createLabel("There are errors while loading \"" + resourceName + "\":\n" + error, 13, Color.RED), title, JOptionPane.ERROR_MESSAGE));
            }
            resourceBar.setValue(resourceBar.getValue() + valuePerPack);
        }
    } catch (Throwable e) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        Toolkit.getDefaultToolkit().beep();
        JOptionPane.showMessageDialog(null, GUIMain.createLabel("An error occurred!\n" + sw, 13, Color.RED), title, JOptionPane.ERROR_MESSAGE);
    }
    System.setErr(original);
    textAreaResources.setText("Loaded Resources:\n");
    for (ResourcePackInfo info : resourceManager.getResourcePackInfo()) {
        textAreaResources.append(" - " + info.getName());
        if (!info.getStatus()) {
            textAreaResources.append(" (Failed)");
        }
        textAreaResources.append("\n");
    }
    renderModelButton.setEnabled(true);
    reloadResourcesButton.setEnabled(true);
    resourceBar.setVisible(false);
    lock.unlock();
}
Also used : PrintStream(java.io.PrintStream) IOException(java.io.IOException) ResourceManager(com.loohp.interactivechatdiscordsrvaddon.resources.ResourceManager) ByteArrayOutputStream(java.io.ByteArrayOutputStream) YamlConfiguration(com.loohp.interactivechat.libs.com.loohp.yamlconfiguration.YamlConfiguration) FileInputStream(java.io.FileInputStream) ResourcePackInfo(com.loohp.interactivechatdiscordsrvaddon.resources.ResourcePackInfo) IOException(java.io.IOException) StringWriter(java.io.StringWriter) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 5 with YamlConfiguration

use of com.loohp.interactivechat.libs.com.loohp.yamlconfiguration.YamlConfiguration in project InteractiveChat-DiscordSRV-Addon by LOOHP.

the class CMLMain method launch.

public static void launch(String[] args) {
    try {
        Enumeration<URL> enumeration = GUIMain.class.getClassLoader().getResources("plugin.yml");
        YamlConfiguration pluginYaml = new YamlConfiguration(enumeration.nextElement().openStream());
        String pluginName = pluginYaml.getString("name");
        String version = pluginYaml.getString("version");
        YamlConfiguration icPluginYaml = new YamlConfiguration(enumeration.nextElement().openStream());
        String icPluginName = icPluginYaml.getString("name");
        String icVersion = icPluginYaml.getString("version");
        System.out.println("Starting " + pluginName + " v" + version + " Tools...");
        System.out.println();
        main: while (true) {
            System.out.println("You are running " + pluginName + " v" + version);
            System.out.println("Paired with " + icPluginName + " v" + icVersion);
            System.out.println();
            System.out.println("Links:");
            System.out.println("SpigotMC: \"https://www.spigotmc.org/resources/83917/\"");
            System.out.println("GitHub: \"https://github.com/LOOHP/InteractiveChat-DiscordSRV-Addon\"");
            System.out.println("Discord: \"http://dev.discord.loohpjames.com\"");
            System.out.println("Build Server: \"https://ci.loohpjames.com\"");
            if (Registry.INTERACTIVE_CHAT_DISCORD_SRV_ADDON_COMPATIBLE_VERSION != InteractiveChatRegistry.INTERACTIVE_CHAT_DISCORD_SRV_ADDON_COMPATIBLE_VERSION) {
                System.out.println();
                System.out.println("These versions of InteractiveChat & InteractiveChat DiscordSRV Addon are incompatible! Please Upgrade!");
                System.out.println("These versions of InteractiveChat & InteractiveChat DiscordSRV Addon are incompatible! Please Upgrade!");
                System.out.println("These versions of InteractiveChat & InteractiveChat DiscordSRV Addon are incompatible! Please Upgrade!");
            }
            System.out.println();
            System.out.println("Select one of the tools by typing in their corresponding number");
            System.out.println("1. Check for Updates   2. Validate Plugin Configs   3.Generate Default Configs   4. Download Assets    5. Exit");
            String input = IN.readLine();
            switch(input) {
                case "1":
                    checkForUpdates(version);
                    break;
                case "2":
                    validConfigs();
                    break;
                case "3":
                    generateDefaultConfigs();
                    break;
                case "4":
                    downloadAssets();
                    break;
                default:
                    break main;
            }
        }
    } catch (Throwable e) {
        System.err.println("An error occurred!");
        e.printStackTrace();
    }
}
Also used : YamlConfiguration(com.loohp.interactivechat.libs.com.loohp.yamlconfiguration.YamlConfiguration) URL(java.net.URL)

Aggregations

YamlConfiguration (com.loohp.interactivechat.libs.com.loohp.yamlconfiguration.YamlConfiguration)6 File (java.io.File)4 FileInputStream (java.io.FileInputStream)4 PrintWriter (java.io.PrintWriter)3 StringWriter (java.io.StringWriter)3 List (java.util.List)3 ResourceManager (com.loohp.interactivechatdiscordsrvaddon.resources.ResourceManager)2 ResourcePackInfo (com.loohp.interactivechatdiscordsrvaddon.resources.ResourcePackInfo)2 Graphics2D (java.awt.Graphics2D)2 BufferedImage (java.awt.image.BufferedImage)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 PrintStream (java.io.PrintStream)2 Icon (javax.swing.Icon)2 JLabel (javax.swing.JLabel)2 GridConstraints (com.loohp.interactivechat.libs.com.intellij.uiDesigner.core.GridConstraints)1 GridLayoutManager (com.loohp.interactivechat.libs.com.intellij.uiDesigner.core.GridLayoutManager)1 Spacer (com.loohp.interactivechat.libs.com.intellij.uiDesigner.core.Spacer)1 Component (com.loohp.interactivechat.libs.net.kyori.adventure.text.Component)1 NamedTextColor (com.loohp.interactivechat.libs.net.kyori.adventure.text.format.NamedTextColor)1