Skip to content

Commit bcb1a7e

Browse files
committed
Update API with reachable override
1 parent 42dedeb commit bcb1a7e

File tree

6 files changed

+81
-21
lines changed

6 files changed

+81
-21
lines changed

api/src/main/java/fr/epsilon/api/EpsilonAPI.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ public static EpsilonAPI get() {
6565
*/
6666
public abstract EQueueModule queueModule();
6767

68+
/**
69+
* Get if server is reachable
70+
*
71+
* @return boolean
72+
*/
73+
public abstract boolean isReachable();
74+
6875
public EpsilonAPI() {
6976
singleton = this;
7077
}

common/src/main/java/fr/epsilon/common/Epsilon.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,9 @@ public InstanceModule instanceModule() {
124124
public QueueModule queueModule() {
125125
return queueModule;
126126
}
127+
128+
@Override
129+
public boolean isReachable() {
130+
return true;
131+
}
127132
}

proxy/src/main/java/fr/epsilon/exporter/EpsilonExporter.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
import fr.epsilon.exporter.listener.EpsilonRegister;
66
import net.md_5.bungee.api.plugin.Plugin;
77

8-
import java.io.IOException;
9-
import java.nio.file.Files;
10-
import java.nio.file.Path;
11-
import java.nio.file.Paths;
12-
138
public class EpsilonExporter extends Plugin {
149
private Epsilon epsilon;
1510
private EpsilonRegister register;
@@ -32,12 +27,7 @@ public void onEnable() {
3227

3328
EpsilonEventStream.init(this);
3429

35-
try {
36-
Path path = Paths.get("epsilon_start");
37-
Files.createFile(path);
38-
} catch (IOException e) {
39-
e.printStackTrace();
40-
}
30+
EpsilonReachTask.init(this);
4131
}
4232

4333
public Epsilon getEpsilon() {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package fr.epsilon.exporter;
2+
3+
import fr.epsilon.common.Epsilon;
4+
import net.md_5.bungee.api.scheduler.ScheduledTask;
5+
6+
import java.io.IOException;
7+
import java.nio.file.Files;
8+
import java.nio.file.Path;
9+
import java.nio.file.Paths;
10+
import java.util.concurrent.TimeUnit;
11+
12+
public class EpsilonReachTask {
13+
private static ScheduledTask task;
14+
15+
public static void init(EpsilonExporter main)
16+
{
17+
task = main.getProxy().getScheduler().schedule(main, () ->
18+
{
19+
boolean reachable = Epsilon.get().isReachable();
20+
21+
if (!reachable)
22+
return;
23+
24+
try {
25+
Path path = Paths.get("epsilon_start");
26+
Files.createFile(path);
27+
28+
task.cancel();
29+
} catch (IOException e) {
30+
e.printStackTrace();
31+
}
32+
}, 0, 100, TimeUnit.MILLISECONDS);
33+
}
34+
}

server/src/main/java/fr/epsilon/exporter/EpsilonExporter.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,8 @@
44
import fr.epsilon.common.template.Template;
55
import org.bukkit.plugin.java.JavaPlugin;
66

7-
import java.io.IOException;
87
import java.lang.reflect.Field;
98
import java.lang.reflect.Method;
10-
import java.nio.file.Files;
11-
import java.nio.file.Path;
12-
import java.nio.file.Paths;
139

1410
public class EpsilonExporter extends JavaPlugin {
1511
@Override
@@ -37,12 +33,7 @@ public void onEnable() {
3733
mapIgniter.load();
3834
getServer().getLogger().info("Load maps ...");
3935

40-
try {
41-
Path path = Paths.get("epsilon_start");
42-
Files.createFile(path);
43-
} catch (IOException e) {
44-
e.printStackTrace();
45-
}
36+
EpsilonReachTask.init(this);
4637
});
4738
}
4839

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package fr.epsilon.exporter;
2+
3+
import fr.epsilon.common.Epsilon;
4+
import org.bukkit.scheduler.BukkitTask;
5+
6+
import java.io.IOException;
7+
import java.nio.file.Files;
8+
import java.nio.file.Path;
9+
import java.nio.file.Paths;
10+
11+
public class EpsilonReachTask {
12+
private static BukkitTask task;
13+
14+
public static void init(EpsilonExporter main)
15+
{
16+
task = main.getServer().getScheduler().runTaskTimer(main, () ->
17+
{
18+
boolean reachable = Epsilon.get().isReachable();
19+
20+
if (!reachable)
21+
return;
22+
23+
try {
24+
Path path = Paths.get("epsilon_start");
25+
Files.createFile(path);
26+
27+
task.cancel();
28+
} catch (IOException e) {
29+
e.printStackTrace();
30+
}
31+
}, 0, 10);
32+
}
33+
}

0 commit comments

Comments
 (0)