Skip to content

Commit bdf437d

Browse files
author
FungY911
committed
Initial commit
0 parents  commit bdf437d

12 files changed

Lines changed: 529 additions & 0 deletions

File tree

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.gitignore

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# User-specific stuff
2+
.idea/
3+
4+
*.iml
5+
*.ipr
6+
*.iws
7+
8+
# IntelliJ
9+
out/
10+
11+
# Compiled class file
12+
*.class
13+
14+
# Log file
15+
*.log
16+
17+
# BlueJ files
18+
*.ctxt
19+
20+
# Package Files #
21+
*.jar
22+
*.war
23+
*.nar
24+
*.ear
25+
*.zip
26+
*.tar.gz
27+
*.rar
28+
29+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
30+
hs_err_pid*
31+
32+
*~
33+
34+
# temporary files which can be created if a process still has a handle open of a deleted file
35+
.fuse_hidden*
36+
37+
# KDE directory preferences
38+
.directory
39+
40+
# Linux trash folder which might appear on any partition or disk
41+
.Trash-*
42+
43+
# .nfs files are created when an open file is removed but is still being accessed
44+
.nfs*
45+
46+
# General
47+
.DS_Store
48+
.AppleDouble
49+
.LSOverride
50+
51+
# Icon must end with two \r
52+
Icon
53+
54+
# Thumbnails
55+
._*
56+
57+
# Files that might appear in the root of a volume
58+
.DocumentRevisions-V100
59+
.fseventsd
60+
.Spotlight-V100
61+
.TemporaryItems
62+
.Trashes
63+
.VolumeIcon.icns
64+
.com.apple.timemachine.donotpresent
65+
66+
# Directories potentially created on remote AFP share
67+
.AppleDB
68+
.AppleDesktop
69+
Network Trash Folder
70+
Temporary Items
71+
.apdisk
72+
73+
# Windows thumbnail cache files
74+
Thumbs.db
75+
Thumbs.db:encryptable
76+
ehthumbs.db
77+
ehthumbs_vista.db
78+
79+
# Dump file
80+
*.stackdump
81+
82+
# Folder config file
83+
[Dd]esktop.ini
84+
85+
# Recycle Bin used on file shares
86+
$RECYCLE.BIN/
87+
88+
# Windows Installer files
89+
*.cab
90+
*.msi
91+
*.msix
92+
*.msm
93+
*.msp
94+
95+
# Windows shortcuts
96+
*.lnk
97+
98+
target/
99+
100+
pom.xml.tag
101+
pom.xml.releaseBackup
102+
pom.xml.versionsBackup
103+
pom.xml.next
104+
105+
release.properties
106+
dependency-reduced-pom.xml
107+
buildNumber.properties
108+
.mvn/timing.properties
109+
.mvn/wrapper/maven-wrapper.jar
110+
.flattened-pom.xml
111+
112+
# Common working directory
113+
run/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 FungY911
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# WSForMC
2+

pom.xml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>tk.fungy</groupId>
8+
<artifactId>WebServerForMC</artifactId>
9+
<version>1.0</version>
10+
<packaging>jar</packaging>
11+
12+
<name>WebServerForMinecraft</name>
13+
14+
<description>Host your website in your Minecraft Server!</description>
15+
<properties>
16+
<java.version>1.8</java.version>
17+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18+
</properties>
19+
20+
<build>
21+
<plugins>
22+
<plugin>
23+
<groupId>org.apache.maven.plugins</groupId>
24+
<artifactId>maven-compiler-plugin</artifactId>
25+
<version>3.8.1</version>
26+
<configuration>
27+
<source>${java.version}</source>
28+
<target>${java.version}</target>
29+
</configuration>
30+
</plugin>
31+
<plugin>
32+
<groupId>org.apache.maven.plugins</groupId>
33+
<artifactId>maven-shade-plugin</artifactId>
34+
<version>3.2.4</version>
35+
<executions>
36+
<execution>
37+
<phase>package</phase>
38+
<goals>
39+
<goal>shade</goal>
40+
</goals>
41+
<configuration>
42+
<createDependencyReducedPom>false</createDependencyReducedPom>
43+
</configuration>
44+
</execution>
45+
</executions>
46+
</plugin>
47+
</plugins>
48+
<resources>
49+
<resource>
50+
<directory>src/main/resources</directory>
51+
<filtering>true</filtering>
52+
</resource>
53+
</resources>
54+
</build>
55+
56+
<repositories>
57+
<repository>
58+
<id>spigotmc-repo</id>
59+
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
60+
</repository>
61+
<repository>
62+
<id>sonatype</id>
63+
<url>https://oss.sonatype.org/content/groups/public/</url>
64+
</repository>
65+
</repositories>
66+
67+
<dependencies>
68+
<dependency>
69+
<groupId>org.nanohttpd</groupId>
70+
<artifactId>nanohttpd</artifactId>
71+
<version>2.2.0</version>
72+
</dependency>
73+
<dependency>
74+
<groupId>org.spigotmc</groupId>
75+
<artifactId>spigot-api</artifactId>
76+
<version>1.19.3-R0.1-SNAPSHOT</version>
77+
<scope>provided</scope>
78+
</dependency>
79+
</dependencies>
80+
</project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package tk.fungy.wsformc;
2+
3+
import org.bukkit.ChatColor;
4+
5+
import java.util.List;
6+
7+
public class Colors {
8+
public static List<String> translate;
9+
public static final String WITH_DELIMITER = "((?<=%1$s)|(?=%1$s))";
10+
11+
public static String translate(String text) {
12+
String[] texts = text.split(String.format(WITH_DELIMITER, "&"));
13+
StringBuilder finalText = new StringBuilder();
14+
for (int i = 0; i < texts.length; i++) {
15+
if (texts[i].equalsIgnoreCase("&")) {
16+
i++;
17+
finalText.append(texts[i].charAt(0) == '#' ? net.md_5.bungee.api.ChatColor.of(texts[i].substring(0, 7)) + texts[i].substring(7) : ChatColor.translateAlternateColorCodes('&', "&" + texts[i]));
18+
} else {
19+
finalText.append(texts[i]);
20+
}
21+
}
22+
return finalText.toString();
23+
}
24+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package tk.fungy.wsformc;
2+
3+
import org.bukkit.Bukkit;
4+
import org.bukkit.OfflinePlayer;
5+
import org.bukkit.command.CommandExecutor;
6+
import org.bukkit.command.CommandSender;
7+
import org.bukkit.entity.Player;
8+
9+
import java.io.File;
10+
import java.io.IOException;
11+
12+
public class Command implements CommandExecutor {
13+
@Override
14+
public boolean onCommand(CommandSender sender, org.bukkit.command.Command command, String label, String[] args) {
15+
if (!(sender instanceof Player)) {
16+
sender.sendMessage("Failed to execute command, are connected to server?");
17+
return true;
18+
}
19+
20+
Player player = (Player) sender;
21+
22+
if(args.length == 0) {
23+
switch (command.getName()) {
24+
case "wsm":
25+
sender.getServer().getLogger().info("pucovina");
26+
sender.sendMessage("napisal som to..");
27+
return true;
28+
case "webserver":
29+
sender.getServer().getLogger().info("pucovina");
30+
sender.sendMessage("napisal som to..");
31+
return true;
32+
}
33+
}
34+
35+
if (args.length >= 0 && sender.hasPermission("ws.*")) {
36+
switch (args[0]) {
37+
case "help":
38+
sender.sendMessage(
39+
"/wsm blabla\n" +
40+
"/wsm reload\n" +
41+
"/wsm stop\n" +
42+
"/wsm start\n" +
43+
"/wsm status\n" +
44+
"/wsm \n");
45+
return true;
46+
case "toggle":
47+
sender.sendMessage("Toggling...");
48+
if (Boolean.parseBoolean(new FileManager().getStringFromConfig("WebServer.isRunning"))) {
49+
FileManager.setStringInConfig("WebServer.isRunning", String.valueOf(false));
50+
} else {
51+
FileManager.setStringInConfig("WebServer.isRunning", String.valueOf(true));
52+
}
53+
WebServer server = new WebServer();
54+
server.toggle();
55+
return true;
56+
case "reload":
57+
switch (args[1]) {
58+
case "config":
59+
sender.sendMessage("Reloading config...");
60+
new FileManager().reloadConfig();
61+
sender.sendMessage("Reloaded");
62+
return true;
63+
case "plugin":
64+
sender.sendMessage("Reloading plugin...");
65+
Bukkit.getPluginManager().disablePlugin(Main.instance);
66+
Bukkit.getPluginManager().enablePlugin(Main.instance);
67+
sender.sendMessage("Reloaded");
68+
return true;
69+
}
70+
sender.sendMessage("config, plugin");
71+
return true;
72+
default:
73+
sender.sendMessage("Command not found!");
74+
}
75+
} else {
76+
sender.sendMessage(new FileManager().getStringFromConfig("No-Permission"));
77+
}
78+
return true;
79+
}
80+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package tk.fungy.wsformc;
2+
3+
import org.bukkit.Bukkit;
4+
import org.bukkit.configuration.file.YamlConfiguration;
5+
6+
import java.io.File;
7+
import java.io.IOException;
8+
import java.net.InetAddress;
9+
import java.net.UnknownHostException;
10+
11+
public class FileManager {
12+
13+
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 YamlConfiguration config;
16+
public Integer getIntegerFromConfig(Integer in) { config.getString(String.valueOf(in)); return in; }
17+
public boolean getBooleanFromConfig(boolean b) { return Boolean.parseBoolean(config.getString(String.valueOf(b))); }
18+
public static void setStringInConfig(String key, String value) {
19+
config.set(key, value);
20+
try {
21+
config.save(configFile);
22+
} catch (IOException e) {
23+
Main.getInstance().getLogger().warning("Failed to set string. Executed with this error: \n" + e);
24+
}
25+
}
26+
27+
28+
public void startup() throws UnknownHostException {
29+
if(!configFile.exists()) {
30+
Main.instance.saveResource("config.yml", true);
31+
config = new YamlConfiguration().loadConfiguration(configFile);
32+
String domain = getStringFromConfig("WebServer.domain");
33+
if (domain.equalsIgnoreCase("CHANGE_ME")) {
34+
InetAddress localhost = InetAddress.getLocalHost();
35+
FileManager.setStringInConfig("WebServer.domain", "free.boathost.xyz");
36+
}
37+
38+
File cfgFile = new File(Main.instance.getDataFolder(), "config.yml");
39+
config = YamlConfiguration.loadConfiguration(cfgFile);
40+
}
41+
if(!webFolder.exists()) {
42+
webFolder.mkdir();
43+
}
44+
}
45+
public String getStringFromConfig(String string) {
46+
if (config == null) {
47+
config = new YamlConfiguration().loadConfiguration(configFile);
48+
}
49+
return config.getString(string);
50+
}
51+
public void reloadConfig() {
52+
File cfgFile = new File(Main.instance.getDataFolder(), "config.yml");
53+
config = YamlConfiguration.loadConfiguration(cfgFile);
54+
}
55+
}

0 commit comments

Comments
 (0)