RuneHive-Game
Loading...
Searching...
No Matches
IPMutedPlayers.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 IPMutedPlayers {
14
15 private static final String IP_MUTE_LIST_PATH = "./data/ip-mutes.txt";
16
17 public static final List<String> ipMutes = new ArrayList<>();
18
19 public static void load() {
20 if (!ipMutes.isEmpty()) {
21 ipMutes.clear();
22 }
23 try {
24 ipMutes.addAll(Files.readAllLines(Paths.get(IP_MUTE_LIST_PATH)));
25 } catch (IOException e) {
26 e.printStackTrace();
27 }
28 }
29
30 public static boolean isIpMuted(String host) {
31 return ipMutes.contains(host);
32 }
33
34 public static void ipMute(String host) {
35 host = host.toLowerCase();
36 if (ipMutes.contains(host)) {
37 return;
38 }
39 ipMutes.add(host);
41 }
42
43 public static boolean unIpMute(String host) {
44 host = host.toLowerCase();
45 if (!ipMutes.remove(host)) {
46 return false;
47 }
49 return true;
50 }
51
52 private static void writeIpMutes() {
53 World.schedule(new Task(1) {
54 @Override
55 public void execute() {
56 try {
57 Files.write(Paths.get(IP_MUTE_LIST_PATH), ipMutes, Charset.defaultCharset());
58 cancel();
59 } catch (IOException e) {
60 e.printStackTrace();
61 }
62 }
63 });
64 }
65}
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