RuneHive-Game
Loading...
Searching...
No Matches
WebsitePlayerCountService.java
Go to the documentation of this file.
1package com.runehive.game.service;
2
3import com.google.common.util.concurrent.AbstractScheduledService;
4import com.runehive.Config;
5import com.runehive.game.world.World;
6import org.apache.logging.log4j.LogManager;
7import org.apache.logging.log4j.Logger;
8
9import java.io.IOException;
10import java.io.InputStream;
11import java.net.URL;
12import java.util.concurrent.TimeUnit;
13
14public final class WebsitePlayerCountService extends AbstractScheduledService {
15
16 private static final Logger logger = LogManager.getLogger(WebsitePlayerCountService.class);
17
19
21 return INSTANCE;
22 }
23
24 @Override
25 protected void runOneIteration() throws Exception {
26 try {
27 final int count = World.getPlayerCount();
28 InputStream is = new URL(String.format("%s/player_count.php?key=9A@2U0764JqB&amount=%d", Config.WEBSITE_URL, count)).openStream();
29 is.close();
30 } catch (IOException ex) {
31 logger.error("Error writing player count on website.", ex);
32 }
33 }
34
35 @Override
36 protected Scheduler scheduler() {
37 return Scheduler.newFixedRateSchedule(10, 30, TimeUnit.SECONDS);
38 }
39
40}
The class that contains setting-related constants for the server.
Definition Config.java:24
static final String WEBSITE_URL
Definition Config.java:241
Represents the game world.
Definition World.java:46
static int getPlayerCount()
Gets the amount of valid players online.
Definition World.java:490