Skip to content

Commit 3da365c

Browse files
committed
Example index.html
1 parent bf3592b commit 3da365c

3 files changed

Lines changed: 51 additions & 6 deletions

File tree

src/main/java/tk/fungy/wsformc/FileManager.java

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
public class FileManager {
1212

1313
public static File configFile = new File(Main.instance.getDataFolder(), "config.yml");
14-
public static File webFolder = new File(Main.instance.getDataFolder(), "web");
15-
public static File logsFolder = new File(Main.instance.getDataFolder(), "logs");
14+
public static File webFolder = new File(Main.instance.getDataFolder(), "/web");
15+
public static File logsFolder = new File(Main.instance.getDataFolder(), "/logs");
1616
public static File logsFile = new File(Main.instance.getDataFolder(), "/logs/access.log");
1717
public static YamlConfiguration config;
1818
public static String ipaddr;
@@ -75,7 +75,52 @@ public void startup() throws UnknownHostException {
7575
}
7676
if (!logsFolder.exists()) logsFolder.mkdir();
7777
if(!webFolder.exists()) webFolder.mkdir();
78+
saveMyResource("index.html", false);
7879
}
80+
81+
public void saveMyResource(String resourceName, boolean replace) {
82+
// Get the plugin's data folder
83+
File dataFolder = Main.instance.getDataFolder();
84+
85+
// Create the destination file
86+
File destFile = new File(dataFolder, resourceName);
87+
88+
// If the file already exists and 'replace' is false, return early
89+
if (destFile.exists() && !replace) {
90+
return;
91+
}
92+
93+
// Open the resource file
94+
InputStream is = Main.instance.getResource(resourceName);
95+
96+
// If the resource file is not found, throw an exception
97+
if (is == null) {
98+
throw new IllegalArgumentException("Resource not found: " + resourceName);
99+
}
100+
101+
try {
102+
// Create the parent directories if they don't exist
103+
destFile.getParentFile().mkdirs();
104+
105+
// Open the destination file for writing
106+
OutputStream os = new FileOutputStream(destFile);
107+
108+
// Copy the contents of the resource to the destination file
109+
byte[] buffer = new byte[1024];
110+
int length;
111+
while ((length = is.read(buffer)) > 0) {
112+
os.write(buffer, 0, length);
113+
}
114+
115+
// Close the input and output streams
116+
is.close();
117+
os.close();
118+
} catch (IOException e) {
119+
e.printStackTrace();
120+
}
121+
}
122+
123+
79124
public String getStringFromConfig(String string) {
80125
if (config == null) {
81126
config = new YamlConfiguration().loadConfiguration(configFile);

src/main/resources/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
########################################################################
3131
WebServer:
3232
port: 8080 # Set this to your open port
33-
isRunning: false # Automatically run server on crash if was started
33+
isRunning: false # Automatically run web on crash, if was started
3434
domain: "CHANGE_ME" # Domain of your server, default is ip of your server.
3535
ssl: false # toggle: true/false, set this to true only if you have generated certificate and webserver pointed to domain
3636

src/main/resources/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@
5757
</head>
5858
<body>
5959
<div class="container">
60-
<h1>Installation Success</h1>
60+
<h1>Installation Success (%server_online% - Online)</h1> <!-- If placehoder is not working, check if you have downloaded placeholder server -->
6161
<p>
62-
Your plugin has been installed successfully. <br>Check out our <a href="https://github.com/user/repo/wiki">Wiki</a> for more information on how to use it and visit our <a href="https://github.com/user/repo">Main Page</a> for metadata and updates.
62+
Your plugin has been installed successfully. <br>Check out our <a target="_blank" href="https://github.com/CodeItForFun/WSForMC/">Wiki</a> for more information on how to use it and visit our <a target="_blank" href="https://www.codemein.tech/">Main Page</a> for metadata and updates.
6363
</p>
64-
<a href="#" class="btn">Learn More</a>
64+
<a href="https://discord.gg/Y49sdJHJET" class="btn">Discord</a>
6565
</div>
6666
</body>
6767
</html>

0 commit comments

Comments
 (0)