2020-04-30 06:40:45 +00:00
|
|
|
/*
|
2022-01-01 19:03:05 +00:00
|
|
|
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
2020-04-30 06:40:45 +00:00
|
|
|
*
|
2020-07-30 20:10:15 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2020-04-30 06:40:45 +00:00
|
|
|
*
|
2020-07-30 20:10:15 +00:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
2020-04-30 06:40:45 +00:00
|
|
|
*
|
2020-07-30 20:10:15 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
2020-04-30 06:40:45 +00:00
|
|
|
*
|
2020-07-30 20:10:15 +00:00
|
|
|
* @author GeyserMC
|
|
|
|
* @link https://github.com/GeyserMC/Geyser
|
2020-04-30 06:40:45 +00:00
|
|
|
*/
|
|
|
|
|
2021-11-20 23:29:46 +00:00
|
|
|
package org.geysermc.geyser;
|
2020-04-30 06:40:45 +00:00
|
|
|
|
|
|
|
import javax.swing.*;
|
|
|
|
import java.io.InputStream;
|
2020-07-05 23:35:51 +00:00
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.util.Locale;
|
2020-04-30 06:40:45 +00:00
|
|
|
import java.util.Scanner;
|
|
|
|
|
2021-11-20 23:29:46 +00:00
|
|
|
public class GeyserMain {
|
2020-04-30 06:40:45 +00:00
|
|
|
|
2020-07-05 23:35:51 +00:00
|
|
|
/**
|
|
|
|
* Displays the run help message in the console and a message box if running with a gui
|
|
|
|
*/
|
2020-04-30 06:40:45 +00:00
|
|
|
public void displayMessage() {
|
|
|
|
String message = createMessage();
|
|
|
|
|
2020-07-05 23:35:51 +00:00
|
|
|
if (System.console() == null && !isHeadless()) {
|
2020-04-30 06:40:45 +00:00
|
|
|
JOptionPane.showMessageDialog(null, message, "GeyserMC Plugin: " + this.getPluginType(), JOptionPane.ERROR_MESSAGE);
|
|
|
|
}
|
|
|
|
|
|
|
|
printMessage(message);
|
|
|
|
}
|
|
|
|
|
2020-07-05 23:35:51 +00:00
|
|
|
/**
|
|
|
|
* Load and format the run help text
|
|
|
|
*
|
|
|
|
* @return The formatted message
|
|
|
|
*/
|
2020-04-30 06:40:45 +00:00
|
|
|
private String createMessage() {
|
2021-02-16 21:25:46 +00:00
|
|
|
StringBuilder message = new StringBuilder();
|
2020-04-30 06:40:45 +00:00
|
|
|
|
2021-11-20 23:29:46 +00:00
|
|
|
InputStream helpStream = GeyserMain.class.getClassLoader().getResourceAsStream("languages/run-help/" + Locale.getDefault().toString() + ".txt");
|
2020-07-05 23:35:51 +00:00
|
|
|
|
|
|
|
if (helpStream == null) {
|
2021-11-20 23:29:46 +00:00
|
|
|
helpStream = GeyserMain.class.getClassLoader().getResourceAsStream("languages/run-help/en_US.txt");
|
2020-07-05 23:35:51 +00:00
|
|
|
}
|
|
|
|
|
2020-04-30 06:40:45 +00:00
|
|
|
Scanner help = new Scanner(helpStream).useDelimiter("\\Z");
|
|
|
|
String line = "";
|
|
|
|
while (help.hasNext()) {
|
|
|
|
line = help.next();
|
|
|
|
|
|
|
|
line = line.replace("${plugin_type}", this.getPluginType());
|
|
|
|
line = line.replace("${plugin_folder}", this.getPluginFolder());
|
|
|
|
|
2021-02-16 21:25:46 +00:00
|
|
|
message.append(line).append("\n");
|
2020-04-30 06:40:45 +00:00
|
|
|
}
|
|
|
|
|
2021-02-16 21:25:46 +00:00
|
|
|
return message.toString();
|
2020-04-30 06:40:45 +00:00
|
|
|
}
|
|
|
|
|
2020-07-05 23:35:51 +00:00
|
|
|
/**
|
|
|
|
* Check if we are in a headless environment
|
|
|
|
*
|
|
|
|
* @return Are we in a headless environment?
|
|
|
|
*/
|
|
|
|
private boolean isHeadless() {
|
|
|
|
try {
|
|
|
|
Class<?> graphicsEnvironment = Class.forName("java.awt.GraphicsEnvironment");
|
|
|
|
Method isHeadless = graphicsEnvironment.getDeclaredMethod("isHeadless");
|
|
|
|
return (Boolean)isHeadless.invoke(null);
|
2021-06-21 01:42:22 +00:00
|
|
|
} catch (Exception ignored) {
|
|
|
|
}
|
2020-07-05 23:35:51 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Simply print a message to console
|
|
|
|
*
|
|
|
|
* @param message The message to print
|
|
|
|
*/
|
2020-04-30 06:40:45 +00:00
|
|
|
private void printMessage(String message) {
|
|
|
|
System.out.print(message);
|
|
|
|
}
|
|
|
|
|
2020-07-05 23:35:51 +00:00
|
|
|
/**
|
|
|
|
* Get the platform the plugin is for
|
|
|
|
*
|
|
|
|
* @return The string representation of the plugin platforms name
|
|
|
|
*/
|
2020-04-30 06:40:45 +00:00
|
|
|
public String getPluginType() {
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
|
2020-07-05 23:35:51 +00:00
|
|
|
/**
|
|
|
|
* Get the folder name the plugin should go into
|
|
|
|
*
|
|
|
|
* @return The string representation of the folder
|
|
|
|
*/
|
2020-04-30 06:40:45 +00:00
|
|
|
public String getPluginFolder() {
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
}
|