Skip to content

Commit 746ca17

Browse files
committed
rework
1 parent 2daf9ba commit 746ca17

File tree

2 files changed

+48
-38
lines changed

2 files changed

+48
-38
lines changed

pom.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@
6969
<url>https://oss.sonatype.org/content/groups/public/</url>
7070
</repository>
7171
<repository>
72-
<id>jitpack.io</id>
73-
<url>https://jitpack.io</url>
72+
<id>grimac-snapshots</id>
73+
<name>GrimAC's Maven Repository</name>
74+
<url>https://repo.grim.ac/snapshots</url>
7475
</repository>
7576
</repositories>
7677

@@ -94,10 +95,9 @@
9495
</dependency>
9596

9697
<dependency>
97-
<groupId>com.github.GrimAnticheat</groupId>
98-
<artifactId>Grim</artifactId>
99-
<version>5a0a04d</version>
100-
<classifier>all</classifier>
98+
<groupId>ac.grim.grimac</groupId>
99+
<artifactId>GrimAPI</artifactId>
100+
<version>1.1.0.0</version>
101101
<scope>provided</scope>
102102
</dependency>
103103
</dependencies>
Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
package me.hsgamer.grimcheckup;
22

33
import ac.grim.grimac.api.AbstractCheck;
4-
import ac.grim.grimac.api.events.FlagEvent;
5-
import ac.grim.grimac.manager.CheckManager;
6-
import ac.grim.grimac.player.GrimPlayer;
7-
import ac.grim.grimac.shaded.com.github.retrooper.packetevents.protocol.player.User;
8-
import ac.grim.grimac.shaded.com.github.retrooper.packetevents.protocol.player.UserProfile;
9-
import com.google.common.collect.ClassToInstanceMap;
4+
import ac.grim.grimac.api.GrimAPIProvider;
5+
import ac.grim.grimac.api.GrimAbstractAPI;
6+
import ac.grim.grimac.api.GrimUser;
7+
import ac.grim.grimac.api.event.EventBus;
8+
import ac.grim.grimac.api.event.events.FlagEvent;
9+
import ac.grim.grimac.api.event.events.GrimJoinEvent;
10+
import ac.grim.grimac.api.plugin.BasicGrimPlugin;
11+
import ac.grim.grimac.api.plugin.GrimPlugin;
1012
import me.hsgamer.hscore.bukkit.config.BukkitConfig;
1113
import me.hsgamer.hscore.bukkit.simpleplugin.SimplePlugin;
1214
import me.hsgamer.hscore.config.PathString;
13-
import org.bukkit.event.EventHandler;
1415
import org.bukkit.event.Listener;
1516

1617
import java.util.HashSet;
1718
import java.util.Set;
18-
import java.util.UUID;
1919

2020
public final class GrimCheckup extends SimplePlugin implements Listener {
2121
private final BukkitConfig config = new BukkitConfig(this);
@@ -25,36 +25,46 @@ public final class GrimCheckup extends SimplePlugin implements Listener {
2525
public void enable() {
2626
config.setup();
2727

28-
GrimPlayer grimPlayer = fakeGrimPlayer();
29-
CheckManager checkManager = new CheckManager(grimPlayer);
30-
ClassToInstanceMap<AbstractCheck> checks = checkManager.allChecks;
31-
32-
checks.forEach((clazz, check) -> {
33-
String configName = check.getConfigName();
34-
PathString pathString = new PathString(configName);
35-
config.setIfAbsent(pathString, true);
36-
37-
Object value = config.getNormalized(pathString);
28+
config.getNormalizedValues(false).forEach((key, value) -> {
29+
String check = PathString.toPath(key);
3830
if (value instanceof Boolean && !(Boolean) value) {
39-
disabledChecks.add(configName);
31+
disabledChecks.add(check);
4032
}
4133
});
4234

43-
config.save();
35+
GrimAbstractAPI api = GrimAPIProvider.get();
36+
GrimPlugin plugin = new BasicGrimPlugin(
37+
this.getLogger(),
38+
this.getDataFolder(),
39+
this.getDescription().getVersion(),
40+
this.getDescription().getDescription(),
41+
this.getDescription().getAuthors()
42+
);
4443

45-
registerListener(this);
46-
}
44+
EventBus eventBus = api.getEventBus();
4745

48-
@EventHandler
49-
public void onFlag(FlagEvent event) {
50-
AbstractCheck check = event.getCheck();
51-
if (disabledChecks.contains(check.getConfigName())) {
52-
event.setCancelled(true);
53-
}
54-
}
46+
eventBus.subscribe(plugin, FlagEvent.class, event -> {
47+
String check = event.getCheck().getConfigName();
48+
if (disabledChecks.contains(check)) {
49+
event.setCancelled(true);
50+
}
51+
});
5552

56-
private GrimPlayer fakeGrimPlayer() {
57-
User user = new User(null, null, null, new UserProfile(UUID.randomUUID(), "Fake"));
58-
return new GrimPlayer(user);
53+
eventBus.subscribe(plugin, GrimJoinEvent.class, event -> {
54+
GrimUser grimUser = event.getUser();
55+
56+
boolean configChanged = false;
57+
for (AbstractCheck abstractCheck : grimUser.getChecks()) {
58+
PathString path = new PathString(abstractCheck.getConfigName());
59+
if (!config.contains(path)) {
60+
config.set(path, true);
61+
configChanged = true;
62+
}
63+
}
64+
65+
if (configChanged) {
66+
config.save();
67+
}
68+
});
5969
}
6070
}

0 commit comments

Comments
 (0)