Browse Source

Status Provider dynamisch von Resources abhängig gemacht

master
Yannic Link 3 years ago
parent
commit
49a6ba3df2
2 changed files with 23 additions and 9 deletions
  1. +18
    -0
      app/src/main/java/de/yannicpunktdee/yoshibot/utils/Resources.java
  2. +5
    -9
      app/src/main/java/de/yannicpunktdee/yoshibot/utils/StatusProvider.java

+ 18
- 0
app/src/main/java/de/yannicpunktdee/yoshibot/utils/Resources.java View File

@ -64,6 +64,13 @@ public final class Resources {
private static String[] filteredTags;
@Getter
private static final Map<String, List<String>> feedDetails = new HashMap<>();
@Getter
private static String mc_server;
@Getter
private static String status_channel;
@Getter
private static String status_message;
private static Properties propertiesFile;
private static Properties redditCreds;
@ -86,6 +93,7 @@ public final class Resources {
if (isOk) isOk = initImages();
if (isOk) isOk = initBonkPngPath();
if (isOk) isOk = initReddit();
if (isOk) isOk = initStatusMessage();
if (isOk) Logger.logInfo("Die Konfigurationen wurden erfolgreich geladen.");
else Logger.logError("Die Konfiguration konnte nicht geladen werden");
@ -308,5 +316,15 @@ public final class Resources {
return null;
}
}
private static boolean initStatusMessage(){
if(propertiesFile.containsKey("mc_server") && propertiesFile.containsKey("status_channel")
&& propertiesFile.containsKey("status_message")) {
mc_server = propertiesFile.getProperty("mc_server");
status_channel = propertiesFile.getProperty("status_channel");
status_message = propertiesFile.getProperty("status_message");
return true;
} else return false;
}
}

+ 5
- 9
app/src/main/java/de/yannicpunktdee/yoshibot/utils/StatusProvider.java View File

@ -15,17 +15,13 @@ import java.util.concurrent.TimeUnit;
public class StatusProvider {
private static final String SERVER_URL = "85.214.148.23";
private static final String statusChannelId = "889880296168755231";
private static final String messageId = "889887149850251304";
private static final ScheduledExecutorService statusScheduler = Executors.newScheduledThreadPool(1);
private static int lastPlayersOnline = -1;
public static void provide(int secondsPerTime, Guild guild){
TextChannel statusChannel = guild.getTextChannelById(statusChannelId);
TextChannel statusChannel = guild.getTextChannelById(Resources.getStatus_channel());
statusScheduler.scheduleAtFixedRate(() -> {
try {
updateStatusMessage(statusChannel);
@ -43,7 +39,7 @@ public class StatusProvider {
EmbedBuilder eb = new EmbedBuilder();
eb.setTitle("Status");
eb.addField("Minecraft-Server, Spieler online: ", Integer.toString(lastPlayersOnline), false);
statusChannel.editMessageById(messageId, eb.build()).queue();
statusChannel.editMessageById(Resources.getStatus_message(), eb.build()).queue();
}
private static int getPlayersOnline() throws IOException {
@ -52,13 +48,13 @@ public class StatusProvider {
DataInputStream in = null;
try {
socket = new Socket(SERVER_URL, 25565);
socket = new Socket(Resources.getMc_server(), 25565);
out = new DataOutputStream(socket.getOutputStream());
in = new DataInputStream(socket.getInputStream());
} catch (UnknownHostException e) {
System.err.println("Don't know about host: " + SERVER_URL);
System.err.println("Don't know about host: " + Resources.getMc_server());
} catch (IOException e) {
System.err.println("Couldn't get I/O for " + "the connection to:" + SERVER_URL);
System.err.println("Couldn't get I/O for " + "the connection to:" + Resources.getMc_server());
}
out.write(0xFE);


Loading…
Cancel
Save