Skip to content

Commit

Permalink
(*) Fixed Icon Folder generation on plugin reload
Browse files Browse the repository at this point in the history
  • Loading branch information
MrUniverse44 committed Feb 12, 2022
1 parent 4a2dfb5 commit 996b0d5
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ private void load(MotdType motdType) {

File folder = IconFolders.fromText(plugin.getStorage().getFiles(), motdType);

if (!folder.exists()) {
logs.info("Icon-Folder (" + folder.getName() + ") has been created. [" + folder.mkdirs() + "]");
}

File[] files = folder.listFiles((d, fn) -> fn.endsWith(".png"));

if (files == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import dev.mruniverse.pixelmotd.bungeecord.PixelMOTD;
import dev.mruniverse.pixelmotd.commons.Control;
import dev.mruniverse.pixelmotd.commons.Extras;
import dev.mruniverse.pixelmotd.commons.GLogger;
import dev.mruniverse.pixelmotd.commons.enums.*;
import dev.mruniverse.pixelmotd.commons.iridiumcolorapi.IridiumColorAPI;
import dev.mruniverse.pixelmotd.commons.minedown.MineDown;
Expand All @@ -13,17 +14,20 @@
import net.md_5.bungee.api.ServerPing;
import net.md_5.bungee.api.chat.TextComponent;

import java.util.List;
import java.util.UUID;
import java.util.*;

public class PingBuilder {
private final Map<MotdType, List<String>> motdsMap = new HashMap<>();

private final PixelMOTD plugin;

private final MotdBuilder builder;

private final Extras extras;

private boolean playerSystem;
private boolean playerSystem = false;

private boolean iconSystem = true;

private Control control;

Expand All @@ -41,37 +45,72 @@ public void update() {
}

private void load() {
motdsMap.clear();

for (MotdType motdType : MotdType.values()) {
motdsMap.put(
motdType,
control.getContent(
motdType.getPath().replace(".", ""),
false
)
);
}
iconSystem = plugin.getStorage().getFiles().getControl(GuardianFiles.SETTINGS).getStatus("settings.icon-system");
playerSystem = plugin.getStorage().getFiles().getControl(GuardianFiles.SETTINGS).getStatus("settings.player-system.toggle",true);
control = plugin.getStorage().getFiles().getControl(GuardianFiles.MOTDS);
}

private List<String> loadMotds(MotdType type) {
List<String> list = control.getContent(
type.getPath().replace(".", ""),
false
);
motdsMap.put(
type,
list
);
return list;
}

private String getMotd(MotdType type) {
List<String> motds = control.getContent(type.getPath().replace(".",""),false);
List<String> motds = motdsMap.get(type);
if (motds == null) {
motds = loadMotds(type);
}
return motds.get(control.getRandom().nextInt(motds.size()));
}

public void execute(MotdType motdType, ServerPing ping, int code) {

final GLogger logs = plugin.getStorage().getLogs();

if (!plugin.getConfigVersion().isWork()) {
plugin.getStorage().getLogs().info("Your configuration is outdated,please check your config for missing paths, paths issues or update the plugin for new paths!");
plugin.getStorage().getLogs().info("You can backup your plugin files and let the plugin create new files to fix the issue");
plugin.getStorage().getLogs().info("Or apply manually file changes and update the config-version of the settings.yml to the latest config-version.");
logs.info("Your configuration is outdated,please check your config for missing paths, paths issues or update the plugin for new paths!");
logs.info("You can backup your plugin files and let the plugin create new files to fix the issue");
logs.info("Or apply manually file changes and update the config-version of the settings.yml to the latest config-version.");
return;
}

String motd;

try {
motd = getMotd(motdType);
} catch (Exception ignored) {
plugin.getStorage().getLogs().error("This file isn't updated to the latest file or the motd-path is incorrect, can't find motds for MotdType: " + motdType.getName());
logs.error("This file isn't updated to the latest file or the motd-path is incorrect, can't find motds for MotdType: " + motdType.getName());
return;
}

String line1,line2,completed;
int online,max;

motdType.setMotd(motd);

if (plugin.getStorage().getFiles().getControl(GuardianFiles.SETTINGS).getStatus("settings.icon-system")) {
if (iconSystem) {
Favicon img = builder.getFavicon(motdType, control.getString(motdType.getSettings(MotdSettings.ICONS_ICON)));
if (img != null) ping.setFavicon(img);
if (img != null) {
ping.setFavicon(img);
}
}

if (control.getStatus(motdType.getSettings(MotdSettings.PLAYERS_ONLINE_TOGGLE))) {
Expand Down Expand Up @@ -108,9 +147,21 @@ public void execute(MotdType motdType, ServerPing ping, int code) {

String result;
if (!motdType.isHexMotd()) {
result = ChatColor.translateAlternateColorCodes('&', extras.getVariables(control.getString(motdType.getSettings(MotdSettings.PROTOCOL_MESSAGE)), online, max));
result = ChatColor.translateAlternateColorCodes('&',
extras.getVariables(
control.getString(motdType.getSettings(MotdSettings.PROTOCOL_MESSAGE)),
online,
max
)
);
} else {
result = IridiumColorAPI.process(extras.getVariables(control.getString(motdType.getSettings(MotdSettings.PROTOCOL_MESSAGE)), online, max));
result = IridiumColorAPI.process(
extras.getVariables(
control.getString(motdType.getSettings(MotdSettings.PROTOCOL_MESSAGE)),
online,
max
)
);
}
ping.getVersion().setName(result);
}
Expand All @@ -119,27 +170,17 @@ public void execute(MotdType motdType, ServerPing ping, int code) {
if (!motdType.isHexMotd()) {
line1 = control.getColoredString(motdType.getSettings(MotdSettings.LINE1));
line2 = control.getColoredString(motdType.getSettings(MotdSettings.LINE2));
completed = extras.getVariables(line1,online,max) + "\n" + extras.getVariables(line2,online,max);

completed = extras.getVariables(line1, online, max) + "\n" + extras.getVariables(line2, online, max);

result.addExtra(completed);
} else {
line1 = control.getStringWithoutColors(motdType.getSettings(MotdSettings.LINE1));
line2 = control.getStringWithoutColors(motdType.getSettings(MotdSettings.LINE2));
try {
if (plugin.getStorage().getFiles().getControl(GuardianFiles.SETTINGS).getString("settings.hex-system-process","IRIDIUMCOLORAPI").equalsIgnoreCase("IRIDIUMCOLORAPI")) {
TextComponent firstLine = new TextComponent(IridiumColorAPI.process(extras.getVariables(line1, online, max) + "&f"));
TextComponent secondLine = new TextComponent(IridiumColorAPI.process(extras.getVariables(line2, online, max) + "&f"));
result.addExtra(firstLine);
result.addExtra("\n");
result.addExtra(secondLine);
} else {
completed = extras.getVariables(line1,online,max) + "\n" + extras.getVariables(line2,online,max);
result = new TextComponent(new MineDown(completed.replace('§', '&')).urlDetection(false).toComponent());
}
}catch (Exception exception) {
plugin.getStorage().getLogs().error(exception);
completed = ChatColor.translateAlternateColorCodes('&',extras.getVariables(line1,online,max)) + "\n" + ChatColor.translateAlternateColorCodes('&',extras.getVariables(line2,online,max));
result.addExtra(completed);
}

completed = extras.getVariables(line1, online, max) + "\n" + extras.getVariables(line2, online, max);

result = new TextComponent(new MineDown(completed.replace('§', '&')).urlDetection(false).toComponent());
}

ping.setDescriptionComponent(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ private void load(MotdType motdType) {

File folder = IconFolders.fromText(plugin.getStorage().getFiles(), motdType);

if (!folder.exists()) {
logs.info("Icon-Folder (" + folder.getName() + ") has been created. [" + folder.mkdirs() + "]");
}

File[] files = folder.listFiles((d, fn) -> fn.endsWith(".png"));

if (files == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ private void load(MotdType motdType) {

File folder = IconFolders.fromText(plugin.getStorage().getFiles(), motdType);

if (!folder.exists()) {
logs.info("Icon-Folder (" + folder.getName() + ") has been created. [" + folder.mkdirs() + "]");
}

File[] files = folder.listFiles((d, fn) -> fn.endsWith(".png"));

if (files == null) {
Expand Down

0 comments on commit 996b0d5

Please sign in to comment.