112 lines
4.1 KiB
Java
112 lines
4.1 KiB
Java
package net.limework.gal;
|
|
|
|
import com.google.common.cache.Cache;
|
|
import com.google.common.cache.CacheBuilder;
|
|
import com.google.inject.Inject;
|
|
import com.velocitypowered.api.event.PostOrder;
|
|
import com.velocitypowered.api.event.Subscribe;
|
|
import com.velocitypowered.api.event.connection.PostLoginEvent;
|
|
import com.velocitypowered.api.event.connection.PreLoginEvent;
|
|
import com.velocitypowered.api.event.player.GameProfileRequestEvent;
|
|
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
|
import com.velocitypowered.api.plugin.Plugin;
|
|
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
|
import com.velocitypowered.api.proxy.ProxyServer;
|
|
import com.velocitypowered.api.util.GameProfile;
|
|
import net.kyori.adventure.text.Component;
|
|
import net.limework.gal.utils.Messages;
|
|
|
|
import java.io.File;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Path;
|
|
import java.util.List;
|
|
import java.util.Locale;
|
|
import java.util.Objects;
|
|
import java.util.UUID;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.logging.Logger;
|
|
|
|
import static net.limework.gal.utils.PlayerUUIDUtils.*;
|
|
import static net.limework.gal.utils.PlayerNamesUtils.*;
|
|
|
|
@Plugin(name = "GreenAppleLogin", id = "greenapplelogin", version = "1.0.0", description = "Plugin that handle cracked + premium")
|
|
public class VelocityGalPlugin {
|
|
|
|
private final ProxyServer proxyServer;
|
|
private final Logger logger;
|
|
private final File dataFolder;
|
|
private final ConfigLoader config;
|
|
|
|
@Inject
|
|
public VelocityGalPlugin(ProxyServer proxyServer, Logger logger, @DataDirectory Path dataDirectory) {
|
|
this.proxyServer = proxyServer;
|
|
this.logger = logger;
|
|
this.dataFolder = dataDirectory.toFile();
|
|
if (this.dataFolder.mkdir()) {
|
|
getLogger().info("Created Plugin data folder.");
|
|
}
|
|
File file = new File(getDataFolder(), "config.json");
|
|
if (!file.exists()) {
|
|
try (InputStream in = getClass().getClassLoader().getResourceAsStream("config.json")) {
|
|
Files.copy(Objects.requireNonNull(in), file.toPath());
|
|
} catch (NullPointerException | IOException e) {
|
|
throw new RuntimeException("unable to load config file", e);
|
|
}
|
|
}
|
|
try {
|
|
this.config = new ConfigLoader(file);
|
|
} catch (FileNotFoundException e) {
|
|
throw new RuntimeException("unable to load config file", e);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
@Subscribe
|
|
public void onProxyInitializeEvent(ProxyInitializeEvent event) {
|
|
//this.proxyServer.getEventManager().register(this, this);
|
|
}
|
|
|
|
@Subscribe(order = PostOrder.FIRST)
|
|
public void onPreLoginEvent(PreLoginEvent event) {
|
|
if (event.getConnection().getVirtualHost().get().getHostName().equalsIgnoreCase(this.config.getOnlineModeDomain())) {
|
|
event.setResult(PreLoginEvent.PreLoginComponentResult.forceOnlineMode());
|
|
} else {
|
|
event.setResult(PreLoginEvent.PreLoginComponentResult.forceOfflineMode());
|
|
}
|
|
}
|
|
|
|
@Subscribe
|
|
public void onGameProfileRequestEvent(GameProfileRequestEvent event) {
|
|
if (!event.isOnlineMode()) {
|
|
logger.info("handling " + event.getUsername());
|
|
String username = getCorrectCrackedUsername(event.getUsername(), config);
|
|
logger.info("new username -> " + username);
|
|
List<GameProfile.Property> properties = event.getGameProfile().getProperties();
|
|
UUID uuid = getCrackedPlayerUUIDByName(username);
|
|
event.setGameProfile(new GameProfile(uuid, username, properties));
|
|
}
|
|
}
|
|
|
|
@Subscribe
|
|
public void onPostLoginEvent(PostLoginEvent event) {
|
|
if (isCrackedPlayer(event.getPlayer().getUsername(), this.config)) {
|
|
event.getPlayer().sendMessage(Component.text(Messages.cracked_disclaimer));
|
|
}
|
|
}
|
|
public ProxyServer getProxyServer() {
|
|
return proxyServer;
|
|
}
|
|
|
|
public Logger getLogger() {
|
|
return logger;
|
|
}
|
|
|
|
public File getDataFolder() {
|
|
return dataFolder;
|
|
}
|
|
}
|