Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Fix data directory, handle PreLogin async on Velocity
Browse files Browse the repository at this point in the history
  • Loading branch information
awumii committed Aug 18, 2021
1 parent 458dd58 commit b45c544
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.0.0
7.0.0
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ plugins {

allprojects {
group = "me.xneox"
version = "6.0.0"
version = "7.0.0"
}

subprojects {
// IF I TOUCH THIS THEN BUILD FAILS. WHAT THE FUCK
// PLEASE SOMEONE JUST REWRITE THIS FOR ME I WASTED TOO MUCH TIME ON THIS
// TODO: REWRITE EVERYTHING HERE
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11

Expand Down
13 changes: 5 additions & 8 deletions core/src/main/java/me/xneox/epicguard/core/EpicGuard.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ private void startup() {
this.loadConfigurations();

logger().info("Initializing managers...");
this.geoManager = new GeoManager(this);
this.storageManager = new StorageManager(this);
this.proxyManager = new ProxyManager(this);
this.attackManager = new AttackManager();
this.userManager = new UserManager();
this.proxyManager = new ProxyManager(this);
this.geoManager = new GeoManager(this);

this.commandHandler = new CommandHandler(this);

Expand All @@ -75,14 +75,11 @@ private void startup() {
logger().info("Scheduling tasks...");
this.platform.scheduleRepeatingTask(new MonitorTask(this), 1L);
this.platform.scheduleRepeatingTask(new UpdateCheckerTask(this), 1800L);
this.platform.scheduleRepeatingTask(
new AttackResetTask(this), this.config.misc().attackResetInterval());
this.platform.scheduleRepeatingTask(
new DataSaveTask(this), TimeUnit.MINUTES.toSeconds(this.config.misc().autoSaveInterval()));
this.platform.scheduleRepeatingTask(new AttackResetTask(this), this.config.misc().attackResetInterval());
this.platform.scheduleRepeatingTask(new DataSaveTask(this), TimeUnit.MINUTES.toSeconds(this.config.misc().autoSaveInterval()));

EpicGuardAPI.INSTANCE.setInstance(this);
logger()
.info("Startup completed successfully. Welcome to EpicGuard v" + this.platform.version());
logger().info("Startup completed successfully. Welcome to EpicGuard v" + this.platform.version());
}

public void loadConfigurations() {
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/me/xneox/epicguard/core/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

package me.xneox.epicguard.core;

import me.xneox.epicguard.core.user.OnlineUser;
import java.util.UUID;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;
Expand All @@ -30,15 +30,15 @@ public interface Platform {

/** Returns an audience for the provided user. */
@Nullable
Audience audience(@NotNull OnlineUser user);
Audience audience(@NotNull UUID uuid);

/**
* Kicks the user from the server with a specified message (find the player using User#getUUID).
*
* @param onlineUser The user to be kicked.
* @param uuid The UUID of user to be kicked.
* @param message The kick message.
*/
void disconnectUser(@NotNull OnlineUser onlineUser, @NotNull Component message);
void disconnectUser(@NotNull UUID uuid, @NotNull Component message);

/**
* Schedules a task to be run asynchronously after the specified time (in seconds).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void handle(@NotNull UUID uuid, @NotNull String address) {
if (this.epicGuard.config().settingsCheck().enabled()) {
this.epicGuard.platform().runTaskLater(() -> {
if (user != null && !user.settingsChanged()) {
this.epicGuard.platform().disconnectUser(user, MessageUtils.multilineComponent(this.epicGuard.messages().disconnect().settingsPacket()));
this.epicGuard.platform().disconnectUser(uuid, MessageUtils.multilineComponent(this.epicGuard.messages().disconnect().settingsPacket()));
}
}, this.epicGuard.config().settingsCheck().delay());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ public GeoManager(EpicGuard epicGuard) {
this.epicGuard = epicGuard;
epicGuard.logger().info("This product includes GeoLite2 data created by MaxMind, available from https://www.maxmind.com");

String parent = FileUtils.EPICGUARD_DIR + "/data";
File parent = new File(FileUtils.EPICGUARD_DIR, "/data");
//noinspection ResultOfMethodCallIgnored
parent.mkdirs();

File countryDatabase = new File(parent, "GeoLite2-Country.mmdb");
File cityDatabase = new File(parent, "GeoLite2-City.mmdb");
File countryArchive = new File(parent, "GeoLite2-Country.tar.gz");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ public class ProxyManager {

public ProxyManager(EpicGuard epicGuard) {
this.epicGuard = epicGuard;
this.resultCache =
CacheBuilder.newBuilder()
.expireAfterWrite(epicGuard.config().proxyCheck().cacheDuration(), TimeUnit.SECONDS)
.build();
this.resultCache = CacheBuilder.newBuilder()
.expireAfterWrite(epicGuard.config().proxyCheck().cacheDuration(), TimeUnit.SECONDS)
.build();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ public void updateAccounts(@NotNull ConnectingUser user) {
*
* <p>Returned list is immutable, used only for statistics and command suggestions.
*/
public List<String> viewAddresses(Predicate<AddressMeta> predicate) {
@NotNull
public List<String> viewAddresses(@NotNull Predicate<AddressMeta> predicate) {
return this.addresses.entrySet().stream()
.filter(entry -> predicate.test(entry.getValue()))
.map(Map.Entry::getKey)
Expand All @@ -116,7 +117,6 @@ public SQLDatabase database() {
return this.database;
}

@NotNull
public Collection<String> pingCache() {
return this.pingCache;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void run() {

for (OnlineUser user : this.epicGuard.userManager().users()) {
if (user.notifications()) {
Audience audience = this.epicGuard.platform().audience(user);
Audience audience = this.epicGuard.platform().audience(user.uuid());
if (audience != null) {
audience.sendActionBar(monitor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
public final class FileUtils {
public static final String EPICGUARD_DIR = "plugins/EpicGuard";

private FileUtils() {}

@SuppressWarnings("ResultOfMethodCallIgnored")
public static void downloadFile(@NotNull String urlFrom, @NotNull File file) throws IOException {
Validate.notNull(urlFrom, "Download URL cannot be null!");
Expand Down
11 changes: 6 additions & 5 deletions paper/src/main/java/me/xneox/epicguard/paper/EpicGuardPaper.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

package me.xneox.epicguard.paper;

import java.util.UUID;
import me.xneox.epicguard.core.EpicGuard;
import me.xneox.epicguard.core.Platform;
import me.xneox.epicguard.core.user.OnlineUser;
import me.xneox.epicguard.paper.listener.PlayerJoinListener;
import me.xneox.epicguard.paper.listener.PlayerPreLoginListener;
import me.xneox.epicguard.paper.listener.PlayerQuitListener;
Expand Down Expand Up @@ -76,13 +76,14 @@ public String version() {
}

@Override
public @Nullable Audience audience(OnlineUser user) {
return Bukkit.getPlayer(user.uuid());
@Nullable
public Audience audience(@NotNull UUID uuid) {
return Bukkit.getPlayer(uuid);
}

@Override
public void disconnectUser(@NotNull OnlineUser onlineUser, @NotNull Component message) {
Player player = Bukkit.getPlayer(onlineUser.uuid());
public void disconnectUser(@NotNull UUID uuid, @NotNull Component message) {
Player player = Bukkit.getPlayer(uuid);
if (player != null) {
player.kick(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.proxy.ProxyServer;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import me.xneox.epicguard.core.EpicGuard;
import me.xneox.epicguard.core.Platform;
Expand Down Expand Up @@ -96,13 +97,14 @@ public String version() {
}

@Override
public @Nullable Audience audience(@NotNull OnlineUser user) {
return this.server.getPlayer(user.uuid()).orElse(null);
@Nullable
public Audience audience(@NotNull UUID uuid) {
return this.server.getPlayer(uuid).orElse(null);
}

@Override
public void disconnectUser(@NotNull OnlineUser onlineUser, @NotNull Component message) {
this.server.getPlayer(onlineUser.uuid()).ifPresent(player -> player.disconnect(message));
public void disconnectUser(@NotNull UUID uuid, @NotNull Component message) {
this.server.getPlayer(uuid).ifPresent(player -> player.disconnect(message));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package me.xneox.epicguard.velocity.listener;

import com.velocitypowered.api.event.EventTask;
import com.velocitypowered.api.event.PostOrder;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.connection.PreLoginEvent;
Expand All @@ -27,11 +28,11 @@ public PreLoginListener(EpicGuard epicGuard) {
}

@Subscribe(order = PostOrder.FIRST)
public void onPreLogin(PreLoginEvent event) {
public EventTask onPreLogin(PreLoginEvent event) {
String address = event.getConnection().getRemoteAddress().getAddress().getHostAddress();
String nickname = event.getUsername();

this.handle(address, nickname).ifPresent(result ->
event.setResult(PreLoginEvent.PreLoginComponentResult.denied(result)));
return EventTask.async(() ->
this.handle(address, nickname).ifPresent(result -> event.setResult(PreLoginEvent.PreLoginComponentResult.denied(result))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package me.xneox.epicguard.waterfall;

import java.util.UUID;
import java.util.concurrent.TimeUnit;
import me.xneox.epicguard.waterfall.listener.DisconnectListener;
import me.xneox.epicguard.waterfall.listener.PlayerSettingsListener;
Expand All @@ -23,7 +24,6 @@
import me.xneox.epicguard.waterfall.listener.ServerPingListener;
import me.xneox.epicguard.core.EpicGuard;
import me.xneox.epicguard.core.Platform;
import me.xneox.epicguard.core.user.OnlineUser;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
import net.kyori.adventure.text.Component;
Expand Down Expand Up @@ -76,18 +76,18 @@ public String version() {

@Override
@Nullable
public Audience audience(@NotNull OnlineUser user) {
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.uuid());
public Audience audience(@NotNull UUID uuid) {
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid);
if (player != null) {
return this.adventure.player(player);
}
return null;
}

@Override
public void disconnectUser(@NotNull OnlineUser onlineUser, @NotNull Component component) {
public void disconnectUser(@NotNull UUID uuid, @NotNull Component component) {
ProxyServer.getInstance()
.getPlayer(onlineUser.uuid())
.getPlayer(uuid)
.disconnect(BungeeUtils.toLegacyComponent(component));
}

Expand Down

0 comments on commit b45c544

Please sign in to comment.