RuneHive-Game
Loading...
Searching...
No Matches
IPBannedPlayers.java
Go to the documentation of this file.
1package com.runehive.game.world.entity.mob.player;
2
3import com.runehive.game.task.Task;
4import com.runehive.game.world.World;
5
6import java.io.IOException;
7import java.nio.charset.Charset;
8import java.nio.file.Files;
9import java.nio.file.Paths;
10import java.util.ArrayList;
11import java.util.List;
12
13public class IPBannedPlayers {
14
15 private static final String IP_BAN_LIST_PATH = "./data/ip-bans.txt";
16
17 public static final List<String> ipBans = new ArrayList<>();
18
19 public static void load() {
20 if (!ipBans.isEmpty()) {
21 ipBans.clear();
22 }
23 try {
24 ipBans.addAll(Files.readAllLines(Paths.get(IP_BAN_LIST_PATH)));
25 } catch (IOException e) {
26 e.printStackTrace();
27 }
28 }
29
30 public static void ipBan(String host) {
31 host = host.toLowerCase();
32 if (ipBans.contains(host)) {
33 return;
34 }
35 ipBans.add(host);
37 }
38
39 private static void writeIpBans() {
40 World.schedule(new Task(1) {
41 @Override
42 public void execute() {
43 try {
44 Files.write(Paths.get(IP_BAN_LIST_PATH), ipBans, Charset.defaultCharset());
45 cancel();
46 } catch (IOException e) {
47 e.printStackTrace();
48 }
49 }
50 });
51 }
52}
A game representing a cyclic unit of work.
Definition Task.java:11
Represents the game world.
Definition World.java:46
static void schedule(Task task)
Submits a new event.
Definition World.java:247