mirror of
https://github.com/unmojang/OnlineModeFix.git
synced 2025-09-10 07:47:20 -04:00
Change HMOD to use its own config file
This commit is contained in:
parent
4c49c87995
commit
311f190d92
@ -34,6 +34,7 @@ public class MineOnlineBroadcast extends Plugin {
|
|||||||
PluginRegisteredListener registeredListener;
|
PluginRegisteredListener registeredListener;
|
||||||
boolean initialized;
|
boolean initialized;
|
||||||
String serverName = "Minecraft Server";
|
String serverName = "Minecraft Server";
|
||||||
|
private MineOnlineConfig mineOnlineConfig;
|
||||||
|
|
||||||
public void launchProxy() throws IOException {
|
public void launchProxy() throws IOException {
|
||||||
ServerSocket serverSocket = new ServerSocket(0);
|
ServerSocket serverSocket = new ServerSocket(0);
|
||||||
@ -55,7 +56,7 @@ public class MineOnlineBroadcast extends Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] createChecksum(String filename) throws Exception {
|
public static byte[] createChecksum(String filename) throws Exception {
|
||||||
InputStream fis = new FileInputStream(filename);
|
InputStream fis = new FileInputStream(filename);
|
||||||
|
|
||||||
byte[] buffer = new byte[1024];
|
byte[] buffer = new byte[1024];
|
||||||
MessageDigest complete = MessageDigest.getInstance("MD5");
|
MessageDigest complete = MessageDigest.getInstance("MD5");
|
||||||
@ -76,8 +77,8 @@ public class MineOnlineBroadcast extends Plugin {
|
|||||||
byte[] b = createChecksum(filename);
|
byte[] b = createChecksum(filename);
|
||||||
String result = "";
|
String result = "";
|
||||||
|
|
||||||
for (int i=0; i < b.length; i++) {
|
for (int i = 0; i < b.length; i++) {
|
||||||
result += Integer.toString( ( b[i] & 0xff ) + 0x100, 16).substring( 1 );
|
result += Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1);
|
||||||
}
|
}
|
||||||
return result.toUpperCase();
|
return result.toUpperCase();
|
||||||
}
|
}
|
||||||
@ -98,7 +99,7 @@ public class MineOnlineBroadcast extends Plugin {
|
|||||||
HttpURLConnection connection = null;
|
HttpURLConnection connection = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
URLClassLoader classLoader = new URLClassLoader(new URL[] { MineOnlineBroadcast.class.getProtectionDomain().getCodeSource().getLocation() });
|
URLClassLoader classLoader = new URLClassLoader(new URL[]{MineOnlineBroadcast.class.getProtectionDomain().getCodeSource().getLocation()});
|
||||||
|
|
||||||
Class jsonObjectClass = classLoader.loadClass("org.json.JSONObject");
|
Class jsonObjectClass = classLoader.loadClass("org.json.JSONObject");
|
||||||
|
|
||||||
@ -117,12 +118,12 @@ public class MineOnlineBroadcast extends Plugin {
|
|||||||
jsonObjectPut.invoke(jsonObject, "onlinemode", onlineMode);
|
jsonObjectPut.invoke(jsonObject, "onlinemode", onlineMode);
|
||||||
jsonObjectPut.invoke(jsonObject, "md5", md5);
|
jsonObjectPut.invoke(jsonObject, "md5", md5);
|
||||||
jsonObjectPut.invoke(jsonObject, "whitelisted", whitelisted);
|
jsonObjectPut.invoke(jsonObject, "whitelisted", whitelisted);
|
||||||
if(!dontListPlayers)
|
if (!dontListPlayers)
|
||||||
jsonObjectPut.invoke(jsonObject, "players", playerNames);
|
jsonObjectPut.invoke(jsonObject, "players", playerNames);
|
||||||
jsonObjectPut.invoke(jsonObject, "motd", motd);
|
jsonObjectPut.invoke(jsonObject, "motd", motd);
|
||||||
jsonObjectPut.invoke(jsonObject, "dontListPlayers", dontListPlayers);
|
jsonObjectPut.invoke(jsonObject, "dontListPlayers", dontListPlayers);
|
||||||
|
|
||||||
String json = (String)jsonObjectToString.invoke(jsonObject);
|
String json = (String) jsonObjectToString.invoke(jsonObject);
|
||||||
|
|
||||||
URL url = new URL("https://mineonline.codie.gg/api/servers");
|
URL url = new URL("https://mineonline.codie.gg/api/servers");
|
||||||
connection = (HttpURLConnection) url.openConnection();
|
connection = (HttpURLConnection) url.openConnection();
|
||||||
@ -174,47 +175,39 @@ public class MineOnlineBroadcast extends Plugin {
|
|||||||
broadcastThread = new Thread(new Runnable() {
|
broadcastThread = new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while(true) {
|
while (true) {
|
||||||
if (System.currentTimeMillis() - MineOnlineBroadcast.lastPing > 45000) {
|
if (System.currentTimeMillis() - MineOnlineBroadcast.lastPing > 45000) {
|
||||||
lastPing = System.currentTimeMillis();
|
lastPing = System.currentTimeMillis();
|
||||||
try {
|
boolean isPublic = mineOnlineConfig.getConfigBoolean("public");
|
||||||
Properties propertiesFile = new Properties();
|
if (!isPublic)
|
||||||
propertiesFile.load(new FileInputStream(new File("server.properties")));
|
return;
|
||||||
|
|
||||||
boolean isPublic = propertiesFile.getProperty("public", "true").equals("true");
|
String ip = mineOnlineConfig.getConfigString("serverlist-ip");
|
||||||
if(!isPublic)
|
String port = mineOnlineConfig.getConfigString("serverlist-port");
|
||||||
return;
|
int users = etc.getServer().getPlayerList().size();
|
||||||
|
int maxUsers = mineOnlineConfig.getConfigInteger("max-players");
|
||||||
|
String name = mineOnlineConfig.getConfigString("server-name");
|
||||||
|
boolean onlineMode = mineOnlineConfig.getConfigBoolean("online-mode");
|
||||||
|
//String md5 = propertiesFile.getProperty("version-md5", "");
|
||||||
|
boolean whitelisted = mineOnlineConfig.getConfigBoolean("whitelist");
|
||||||
|
boolean dontListPlayers = mineOnlineConfig.getConfigBoolean("dont-list-players");
|
||||||
|
String motd = mineOnlineConfig.getConfigString("serverlist-motd");
|
||||||
|
|
||||||
String ip = propertiesFile.getProperty("serverlist-ip", propertiesFile.getProperty("server-ip", propertiesFile.getProperty("ip", null)));
|
String[] playerNames = etc.getServer().getPlayerList().stream().map(player -> player.getName()).collect(Collectors.toList()).toArray(new String[users]);
|
||||||
String port = propertiesFile.getProperty("serverlist-port", propertiesFile.getProperty("server-port", propertiesFile.getProperty("port", "25565")));
|
|
||||||
int users = etc.getServer().getPlayerList().size();
|
|
||||||
int maxUsers = Integer.parseInt(propertiesFile.getProperty("max-players", "20"));
|
|
||||||
String name = propertiesFile.getProperty("server-name", "Minecraft Server");
|
|
||||||
boolean onlineMode = propertiesFile.getProperty("online-mode", "true").equals("true");
|
|
||||||
//String md5 = propertiesFile.getProperty("version-md5", "");
|
|
||||||
boolean whitelisted = propertiesFile.getProperty("whitelist", "false").equals("true");
|
|
||||||
boolean dontListPlayers = propertiesFile.getProperty("dont-list-players", "false").equals("true");
|
|
||||||
String motd = propertiesFile.getProperty("serverlist-motd", null);
|
|
||||||
|
|
||||||
String[] playerNames = etc.getServer().getPlayerList().stream().map(player -> player.getName()).collect(Collectors.toList()).toArray(new String[users]);
|
listServer(
|
||||||
|
ip,
|
||||||
listServer(
|
port,
|
||||||
ip,
|
users,
|
||||||
port,
|
maxUsers,
|
||||||
users,
|
name,
|
||||||
maxUsers,
|
onlineMode,
|
||||||
name,
|
md5,
|
||||||
onlineMode,
|
whitelisted,
|
||||||
md5,
|
playerNames,
|
||||||
whitelisted,
|
motd,
|
||||||
playerNames,
|
dontListPlayers
|
||||||
motd,
|
);
|
||||||
dontListPlayers
|
|
||||||
);
|
|
||||||
} catch (IOException ex) {
|
|
||||||
//ex.printStackTrace();
|
|
||||||
// ignore.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -224,13 +217,15 @@ public class MineOnlineBroadcast extends Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
if(initialized)
|
if (initialized)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.log = Logger.getLogger("Minecraft");
|
this.log = Logger.getLogger("Minecraft");
|
||||||
|
|
||||||
MinecraftColorCodeProvider colorCodeProvider = new MinecraftColorCodeProvider();
|
MinecraftColorCodeProvider colorCodeProvider = new MinecraftColorCodeProvider();
|
||||||
|
|
||||||
|
mineOnlineConfig = new MineOnlineConfig(new File("." + File.separator + "plugins" + File.separator + "MineOnlineBroadcast" + File.separator + "config.properties"));
|
||||||
|
|
||||||
Properties propertiesFile = new Properties();
|
Properties propertiesFile = new Properties();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -277,7 +272,7 @@ public class MineOnlineBroadcast extends Plugin {
|
|||||||
String saneName = event.getAuthor().getName();
|
String saneName = event.getAuthor().getName();
|
||||||
String saneMessage = sb.toString();
|
String saneMessage = sb.toString();
|
||||||
|
|
||||||
if(saneMessage.trim().isEmpty())
|
if (saneMessage.trim().isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Pattern trailingWhite = Pattern.compile(colorCodeProvider.getColorCode(EColorCodeColor.White) + "\\s{0,}$");
|
Pattern trailingWhite = Pattern.compile(colorCodeProvider.getColorCode(EColorCodeColor.White) + "\\s{0,}$");
|
||||||
@ -325,7 +320,7 @@ public class MineOnlineBroadcast extends Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void unregister() {
|
private void unregister() {
|
||||||
if(registeredListener != null)
|
if (registeredListener != null)
|
||||||
etc.getLoader().removeListener(registeredListener);
|
etc.getLoader().removeListener(registeredListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -334,7 +329,7 @@ public class MineOnlineBroadcast extends Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void disable() {
|
public void disable() {
|
||||||
if(!initialized)
|
if (!initialized)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
unregister();
|
unregister();
|
||||||
|
73
src/MineOnlineConfig.java
Normal file
73
src/MineOnlineConfig.java
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class MineOnlineConfig {
|
||||||
|
private boolean newFile = false;
|
||||||
|
private PropertiesFile propertiesFile;
|
||||||
|
|
||||||
|
public MineOnlineConfig(File file) {
|
||||||
|
if (!file.exists()) {
|
||||||
|
newFile = true;
|
||||||
|
file.getParentFile().mkdirs();
|
||||||
|
}
|
||||||
|
propertiesFile = new PropertiesFile(file.getAbsolutePath());
|
||||||
|
write();
|
||||||
|
propertiesFile.save();
|
||||||
|
}
|
||||||
|
public void write() {
|
||||||
|
//Main
|
||||||
|
generateConfigOption("config-version", 1);
|
||||||
|
//Setting
|
||||||
|
generateConfigOption("public", true);
|
||||||
|
generateConfigOption("serverlist-ip", null);
|
||||||
|
generateConfigOption("serverlist-port", 25565);
|
||||||
|
generateConfigOption("max-players", 20);
|
||||||
|
generateConfigOption("server-name", "Minecraft Server");
|
||||||
|
generateConfigOption("online-mode", true);
|
||||||
|
generateConfigOption("version-md", "");
|
||||||
|
generateConfigOption("whitelist", false);
|
||||||
|
generateConfigOption("dont-list-players", false);
|
||||||
|
generateConfigOption("serverlist-motd", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Getters Start
|
||||||
|
public Object getConfigOption(String key) {
|
||||||
|
return this.propertiesFile.getProperty(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getConfigString(String key) {
|
||||||
|
return String.valueOf(getConfigOption(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getConfigInteger(String key) {
|
||||||
|
return Integer.valueOf(getConfigString(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getConfigLong(String key) {
|
||||||
|
return Long.valueOf(getConfigString(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getConfigDouble(String key) {
|
||||||
|
return Double.valueOf(getConfigString(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getConfigBoolean(String key) {
|
||||||
|
return Boolean.valueOf(getConfigString(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Getters End
|
||||||
|
|
||||||
|
|
||||||
|
private void generateConfigOption(String key, Object defaultValue) {
|
||||||
|
if (propertiesFile.getProperty(key) == null) {
|
||||||
|
propertiesFile.setString(key, String.valueOf(defaultValue));
|
||||||
|
}
|
||||||
|
final Object value = propertiesFile.getProperty(key);
|
||||||
|
propertiesFile.removeKey(key);
|
||||||
|
propertiesFile.setString(key, String.valueOf(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user