Changes resource loading
Some checks failed
KnarCraft/Minecraft-Server-Launcher/master There was a failure building this commit
Some checks failed
KnarCraft/Minecraft-Server-Launcher/master There was a failure building this commit
Loads configuration and image files from resources folder Removes duplicate resources
This commit is contained in:
@ -19,6 +19,8 @@ import java.util.concurrent.Executors;
|
||||
|
||||
import static java.awt.Frame.NORMAL;
|
||||
import static javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE;
|
||||
import static net.knarcraft.minecraftserverlauncher.Shared.getResourceAsScanner;
|
||||
import static net.knarcraft.minecraftserverlauncher.Shared.getResourceAsStream;
|
||||
|
||||
/**
|
||||
* Generates a GUI.
|
||||
@ -60,7 +62,7 @@ public class GUI implements ActionListener {
|
||||
/**
|
||||
* Create the application window.
|
||||
*/
|
||||
public GUI() {
|
||||
public GUI() throws IOException {
|
||||
initialize(440, 170);
|
||||
loadMessages();
|
||||
this.globalPlayers = new ArrayList<>();
|
||||
@ -72,7 +74,7 @@ public class GUI implements ActionListener {
|
||||
* @param width The preferred width
|
||||
* @param height The preferred height
|
||||
*/
|
||||
public GUI(int width, int height) {
|
||||
public GUI(int width, int height) throws IOException {
|
||||
initialize(width, height);
|
||||
loadMessages();
|
||||
this.globalPlayers = new ArrayList<>();
|
||||
@ -117,11 +119,7 @@ public class GUI implements ActionListener {
|
||||
* @param name The name of the player to remove.
|
||||
*/
|
||||
public void removePlayer(String name) {
|
||||
for (int i = 0; i < this.globalPlayers.size(); i++) {
|
||||
if (this.globalPlayers.get(i).equals(name)) {
|
||||
this.globalPlayers.remove(i);
|
||||
}
|
||||
}
|
||||
globalPlayers.removeIf(playerName -> playerName.equals(name));
|
||||
this.updatePlayers();
|
||||
}
|
||||
|
||||
@ -165,7 +163,7 @@ public class GUI implements ActionListener {
|
||||
/**
|
||||
* Creates the GUI,
|
||||
*/
|
||||
private void initialize(int width, int height) {
|
||||
private void initialize(int width, int height) throws IOException {
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
} catch (ClassNotFoundException |
|
||||
@ -179,12 +177,9 @@ public class GUI implements ActionListener {
|
||||
frame = new JFrame("Minecraft server launcher");
|
||||
frame.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||
frame.getContentPane().setPreferredSize(new Dimension(width, height));
|
||||
ImageIcon img;
|
||||
try {
|
||||
img = new ImageIcon(ImageIO.read(GUI.class.getResourceAsStream("/files/GUIIcon.png")));
|
||||
} catch (IOException | IllegalArgumentException e) {
|
||||
img = new ImageIcon("files/GUIIcon.png");
|
||||
}
|
||||
|
||||
ImageIcon img = new ImageIcon(ImageIO.read(getResourceAsStream("GUIIcon.png")));
|
||||
|
||||
frame.setIconImage(img.getImage());
|
||||
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
@ -839,15 +834,11 @@ public class GUI implements ActionListener {
|
||||
/**
|
||||
* Loads popup messages from a text file.
|
||||
*/
|
||||
private void loadMessages() {
|
||||
Scanner file;
|
||||
try {
|
||||
file = new Scanner(new File("config/menumsg.csv"));
|
||||
} catch (FileNotFoundException e) {
|
||||
file = new Scanner(GUI.class.getResourceAsStream("/config/menumsg.csv"));
|
||||
}
|
||||
private void loadMessages() throws FileNotFoundException {
|
||||
Scanner file = getResourceAsScanner("menumsg.csv");
|
||||
while (file.hasNextLine()) {
|
||||
String[] line = file.nextLine().split("=");
|
||||
String nextLine = file.nextLine();
|
||||
String[] line = nextLine.split("=");
|
||||
String content = line[1].replaceAll("_BREAK_", System.getProperty("line.separator"));
|
||||
switch (line[0]) {
|
||||
case "setup":
|
||||
@ -895,7 +886,7 @@ public class GUI implements ActionListener {
|
||||
return;
|
||||
}
|
||||
}
|
||||
String files[] = src.list();
|
||||
String[] files = src.list();
|
||||
if (files != null) {
|
||||
for (String file : files) {
|
||||
File srcFile = new File(src, file);
|
||||
|
Reference in New Issue
Block a user