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();
}
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);
}
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);
}
}
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();
}
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();
}
}
Aggregations