shit code with 1 class
package org.yAuth.yAuth;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import java.util.UUID;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarFlag;
import org.bukkit.boss.BarStyle;
import org.bukkit.boss.BossBar;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
public class YAuth extends JavaPlugin implements Listener, CommandExecutor {
private Map<UUID, String> playerPasswords = new HashMap();
private Map<UUID, Integer> playerPremiumStatus = new HashMap();
private Map<UUID, Boolean> playerLoggedIn = new HashMap();
private Map<UUID, String> playerIPs = new HashMap();
private Map<UUID, String> playerQuitIPs = new HashMap();
private Map<UUID, Long> playerQuitTimes = new HashMap();
private Map<UUID, BossBar> playerBossBars = new HashMap();
private Location spawnLocation;
private Location loginLocation;
private FileConfiguration config;
private String prefix;
private int titleFadeIn;
private int titleStay;
private int titleFadeOut;
private boolean logEnabled;
private int authTimeout;
private long sessionTimeout;
private String language;
private File dataFolder;
private File playerDataFile;
public void onEnable() {
this.dataFolder = new File(this.getDataFolder(), "playerdata");
if (!this.dataFolder.exists()) {
this.dataFolder.mkdirs();
}
this.playerDataFile = new File(this.dataFolder, "players.yml");
this.saveDefaultConfig();
this.config = this.getConfig();
this.loadConfigValues();
this.loadPlayerData();
this.getServer().getPluginManager().registerEvents(this, this);
this.getCommand("register").setExecutor(this);
this.getCommand("r").setExecutor(this);
this.getCommand("login").setExecutor(this);
this.getCommand("l").setExecutor(this);
this.getCommand("changepassword").setExecutor(this);
this.getCommand("premium").setExecutor(this);
this.getCommand("yoloauth").setExecutor(this);
(new BukkitRunnable() {
public void run() {
Iterator var1 = YAuth.this.getServer().getOnlinePlayers().iterator();
while(var1.hasNext()) {
Player p = (Player)var1.next();
UUID uuid = p.getUniqueId();
if ((Integer)YAuth.this.playerPremiumStatus.getOrDefault(uuid, 0) != 2) {
YAuth.this.playerLoggedIn.put(uuid, false);
}
}
}
}).runTaskTimer(this, 0L, 12000L);
this.checkForUpdates();
this.getLogger().info("Yolo Auth Loading...");
this.getLogger().info("");
this.getLogger().info("*************************************");
this.getLogger().info("");
this.getLogger().info("Thanks For Using yAuth");
this.getLogger().info("");
this.getLogger().info("Join Our Discord For Any Problem");
this.getLogger().info("");
this.getLogger().info("
https://discord.gg/mvhAeenX");
this.getLogger().info("");
this.getLogger().info("Plugin Made by yolo.huzai");
this.getLogger().info("");
this.getLogger().info("*************************************");
this.getLogger().info("");
this.getLogger().info(ChatColor.translateAlternateColorCodes('&', this.prefix + "&aAuthors: yolo.huzai & Grok (xAI)"));
}
public void onDisable() {
this.savePlayerData();
Iterator var1 = this.playerBossBars.values().iterator();
while(var1.hasNext()) {
BossBar bar = (BossBar)var1.next();
bar.removeAll();
}
this.getLogger().info("Yolo Auth Unloading...");
this.getLogger().info("");
this.getLogger().info("*************************************");
this.getLogger().info("");
this.getLogger().info("Thanks For Using yAuth");
this.getLogger().info("");
this.getLogger().info("Join Our Discord For Any Problem");
this.getLogger().info("");
this.getLogger().info("
https://discord.gg/mvhAeenX");
this.getLogger().info("");
this.getLogger().info("Plugin Made by yolo.huzai");
this.getLogger().info("");
this.getLogger().info("*************************************");
this.getLogger().info("");
this.getLogger().info(ChatColor.translateAlternateColorCodes('&', this.prefix + "&aAuthors: yolo.huzai & Grok (xAI)"));
}
private void loadConfigValues() {
this.prefix = ChatColor.translateAlternateColorCodes('&', this.config.getString("prefix", "&e&l! "));
this.titleFadeIn = this.config.getInt("title.fade-in", 10);
this.titleStay = this.config.getInt("title.stay", 80);
this.titleFadeOut = this.config.getInt("title.fade-out", 10);
this.logEnabled = this.config.getBoolean("logging.enabled", true);
this.authTimeout = this.config.getInt("auth-timeout", 30);
this.sessionTimeout = this.config.getLong("session-timeout", 30L);
this.language = this.config.getString("language", "en");
}
private void loadPlayerData() {
YamlConfiguration data = YamlConfiguration.loadConfiguration(this.playerDataFile);
Iterator var2 = data.getKeys(false).iterator();
while(var2.hasNext()) {
String uuidStr = (String)var2.next();
UUID uuid = UUID.fromString(uuidStr);
this.playerPasswords.put(uuid, data.getString(uuidStr + ".password"));
this.playerPremiumStatus.put(uuid, data.getInt(uuidStr + ".premium", 0));
this.playerQuitIPs.put(uuid, data.getString(uuidStr + ".quit-ip", ""));
this.playerQuitTimes.put(uuid, data.getLong(uuidStr + ".quit-time", 0L));
}
}
private void savePlayerData() {
YamlConfiguration data = new YamlConfiguration();
Iterator var2 = this.playerPasswords.keySet().iterator();
while(var2.hasNext()) {
UUID uuid = (UUID)var2.next();
data.set(uuid + ".password", this.playerPasswords.get(uuid));
data.set(uuid + ".premium", this.playerPremiumStatus.getOrDefault(uuid, 0));
data.set(uuid + ".quit-ip", this.playerQuitIPs.getOrDefault(uuid, ""));
data.set(uuid + ".quit-time", this.playerQuitTimes.getOrDefault(uuid, 0L));
}
try {
data.save(this.playerDataFile);
} catch (IOException var4) {
this.getLogger().log(Level.SEVERE, "Failed to save player data", var4);
}
}
private void checkForUpdates() {
(new BukkitRunnable() {
public void run() {
try {
URL url = new URL("
https://api.spigotmc.org/legacy/update.php?resource=12345");
Scanner scanner = new Scanner(url.openStream());
String latest = scanner.nextLine();
scanner.close();
if (!YAuth.this.getDescription().getVersion().equals(latest)) {
YAuth.this.getLogger().info(ChatColor.translateAlternateColorCodes('&', YAuth.this.prefix + "&eA new version (" + latest + ") is available! Current: " + YAuth.this.getDescription().getVersion()));
}
} catch (IOException var4) {
YAuth.this.getLogger().warning("Failed to check for updates: " + var4.getMessage());
}
}
}).runTaskAsynchronously(this);
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
UUID uuid = player.getUniqueId();
String currentIP = player.getAddress().getAddress().getHostAddress();
this.playerIPs.put(uuid, currentIP);
if ((Integer)this.playerPremiumStatus.getOrDefault(uuid, 0) == 2) {
this.playerLoggedIn.put(uuid, true);
if (this.spawnLocation != null) {
player.teleport(this.spawnLocation);
}
this.sendMessage(player, "premium_auto_login");
} else {
if (this.loginLocation != null) {
player.teleport(this.loginLocation);
}
this.playerLoggedIn.put(uuid, false);
if (this.playerPasswords.containsKey(uuid)) {
this.sendMessage(player, "login_prompt");
this.startAuthTimer(player);
} else {
this.sendMessage(player, "register_prompt");
this.startAuthTimer(player);
}
}
}
private void startAuthTimer(final Player player) {
final UUID uuid = player.getUniqueId();
final BossBar bossBar = Bukkit.createBossBar(ChatColor.RED + this.getMessage("timer_title") + this.authTimeout + "s", BarColor.RED, BarStyle.SOLID, new BarFlag[0]);
bossBar.addPlayer(player);
this.playerBossBars.put(uuid, bossBar);
(new BukkitRunnable() {
int timeLeft;
{
this.timeLeft = YAuth.this.authTimeout;
}
public void run() {
if (!(Boolean)YAuth.this.playerLoggedIn.getOrDefault(uuid, false)) {
if (this.timeLeft <= 0) {
player.kickPlayer(ChatColor.translateAlternateColorCodes('&', YAuth.this.getMessage("timeout_kick", "{timeout}", String.valueOf(YAuth.this.authTimeout))));
bossBar.removePlayer(player);
YAuth.this.playerBossBars.remove(uuid);
this.cancel();
} else {
bossBar.setTitle(ChatColor.RED + YAuth.this.getMessage("timer_title") + this.timeLeft + "s");
bossBar.setProgress((double)this.timeLeft / (double)YAuth.this.authTimeout);
--this.timeLeft;
}
} else {
bossBar.removePlayer(player);
YAuth.this.playerBossBars.remove(uuid);
if (YAuth.this.spawnLocation != null) {
player.teleport(YAuth.this.spawnLocation);
}
this.cancel();
}
}
}).runTaskTimer(this, 0L, 20L);
}
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
UUID uuid = player.getUniqueId();
if (!(Boolean)this.playerLoggedIn.getOrDefault(uuid, false)) {
if (this.loginLocation != null) {
player.teleport(this.loginLocation);
}
if (this.playerPasswords.containsKey(uuid)) {
this.sendMessage(player, "login_prompt");
} else {
this.sendMessage(player, "register_prompt");
}
event.setCancelled(true);
}
}
@EventHandler
public void onPlayerCommand(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();
UUID uuid = player.getUniqueId();
String cmd = event.getMessage().split(" ")[0].substring(1).toLowerCase();
if (!(Boolean)this.playerLoggedIn.getOrDefault(uuid, false) && !cmd.equals("login") && !cmd.equals("l") && !cmd.equals("register") && !cmd.equals("r") && !cmd.equals("changepassword")) {
event.setCancelled(true);
this.sendMessage(player, "need_login");
}
}
@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent event) {
Player player = event.getPlayer();
UUID uuid = player.getUniqueId();
if (!(Boolean)this.playerLoggedIn.getOrDefault(uuid, false)) {
event.setCancelled(true);
this.sendMessage(player, "need_login");
}
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
UUID uuid = player.getUniqueId();
if (this.playerBossBars.containsKey(uuid)) {
((BossBar)this.playerBossBars.get(uuid)).removePlayer(player);
this.playerBossBars.remove(uuid);
}
if ((Boolean)this.playerLoggedIn.getOrDefault(uuid, false)) {
this.playerQuitIPs.put(uuid, (String)this.playerIPs.get(uuid));
this.playerQuitTimes.put(uuid, System.currentTimeMillis());
this.savePlayerData();
}
}
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', this.prefix + "&cThis command can only be used by players!"));
return true;
} else {
Player player = (Player)sender;
UUID uuid = player.getUniqueId();
String commandName = command.getName().toLowerCase();
if (commandName.equals("r")) {
commandName = "register";
}
if (commandName.equals("l")) {
commandName = "login";
}
byte var9 = -1;
switch(commandName.hashCode()) {
case -942188479:
if (commandName.equals("yoloauth")) {
var9 = 4;
}
break;
case -690213213:
if (commandName.equals("register")) {
var9 = 0;
}
break;
case -318452137:
if (commandName.equals("premium")) {
var9 = 3;
}
break;
case 103149417:
if (commandName.equals("login")) {
var9 = 1;
}
break;
case 866786891:
if (commandName.equals("changepassword")) {
var9 = 2;
}
}
switch(var9) {
case 0:
if (!player.hasPermission("yoloauth.register")) {
return true;
}
if (this.playerPasswords.containsKey(uuid)) {
this.sendMessage(player, "already_registered");
} else if (args.length == 2 && args[0].equals(args[1])) {
this.playerPasswords.put(uuid, args[0]);
this.playerLoggedIn.put(uuid, true);
this.sendMessage(player, "register_success");
this.logToFile("[REGISTER] " + player.getName() + " Has registered his account");
this.savePlayerData();
} else {
this.sendMessage(player, "register_usage");
}
return true;
case 1:
if (!player.hasPermission("yoloauth.login")) {
return true;
}
if (!this.playerPasswords.containsKey(uuid)) {
this.sendMessage(player, "need_register");
} else if ((Boolean)this.playerLoggedIn.getOrDefault(uuid, false)) {
this.sendMessage(player, "already_logged_in");
} else if (args.length == 1 && args[0].equals(this.playerPasswords.get(uuid))) {
this.playerLoggedIn.put(uuid, true);
this.sendMessage(player, "login_success");
this.logToFile("[LOGIN] " + player.getName() + " Has logged in his account");
} else {
this.sendMessage(player, "incorrect_password");
}
return true;
case 2:
if (!player.hasPermission("yoloauth.changepassword")) {
return true;
}
if (args.length != 2) {
this.sendMessage(player, "changepassword_usage");
} else if (!this.playerPasswords.containsKey(uuid)) {
this.sendMessage(player, "need_register");
} else if ((Boolean)this.playerLoggedIn.getOrDefault(uuid, false)) {
this.sendMessage(player, "need_logout");
} else if (!args[0].equals(this.playerPasswords.get(uuid))) {
this.sendMessage(player, "incorrect_password");
} else {
this.playerPasswords.put(uuid, args[1]);
this.playerLoggedIn.put(uuid, true);
this.sendMessage(player, "changepassword_success");
this.logToFile("[INFO] " + player.getName() + " Has changed the password to " + args[1]);
this.savePlayerData();
}
return true;
case 3:
if ((Integer)this.playerPremiumStatus.getOrDefault(uuid, 0) == 2) {
this.sendMessage(player, "premium_active");
} else if (args.length == 0) {
int status = (Integer)this.playerPremiumStatus.getOrDefault(uuid, 0);
if (status == 1) {
this.playerPremiumStatus.put(uuid, 2);
this.playerLoggedIn.put(uuid, true);
this.sendMessage(player, "premium_confirmed");
this.savePlayerData();
} else {
this.sendMessage(player, "premium_confirm");
this.playerPremiumStatus.put(uuid, 1);
this.savePlayerData();
}
} else {
this.sendMessage(player, "not_premium");
}
return true;
case 4:
if (!player.hasPermission("yoloauth.admin") && !player.isOp()) {
this.sendMessage(player, "no_permission");
return true;
} else {
if (args.length == 0) {
this.sendAdminHelp(player);
return true;
}
String var10 = args[0].toLowerCase();
byte var11 = -1;
switch(var10.hashCode()) {
case -1103478608:
if (var10.equals("deletespawn")) {
var11 = 3;
}
break;
case -934641255:
if (var10.equals("reload")) {
var11 = 7;
}
break;
case -900635322:
if (var10.equals("deletepassword")) {
var11 = 5;
}
break;
case -347518567:
if (var10.equals("setloginloc")) {
var11 = 1;
}
break;
case -94848542:
if (var10.equals("deleteloginloc")) {
var11 = 4;
}
break;
case 109638523:
if (var10.equals("spawn")) {
var11 = 2;
}
break;
case 1433904217:
if (var10.equals("setspawn")) {
var11 = 0;
}
break;
case 1780962147:
if (var10.equals("deactivatepremium")) {
var11 = 6;
}
}
Player target;
UUID targetUUID;
switch(var11) {
case 0:
this.spawnLocation = player.getLocation();
this.sendMessage(player, "setspawn_success", "{location}", this.formatLocation(this.spawnLocation));
break;
case 1:
this.loginLocation = player.getLocation();
this.sendMessage(player, "setloginloc_success", "{location}", this.formatLocation(this.loginLocation));
break;
case 2:
if (this.spawnLocation != null) {
player.teleport(this.spawnLocation);
}
break;
case 3:
this.spawnLocation = null;
this.sendMessage(player, "deletespawn_success");
break;
case 4:
this.loginLocation = null;
this.sendMessage(player, "deleteloginloc_success");
break;
case 5:
if (args.length == 2) {
target = this.getServer().getPlayer(args[1]);
if (target != null) {
targetUUID = target.getUniqueId();
this.playerPasswords.remove(targetUUID);
this.playerLoggedIn.remove(targetUUID);
target.kickPlayer(ChatColor.translateAlternateColorCodes('&', this.getMessage("admin_change_kick")));
this.logToFile("[INFO] " + player.getName() + " Has deleted the password for " + args[1]);
this.sendMessage(player, "deletepassword_success", "{player}", args[1]);
this.savePlayerData();
}
}
break;
case 6:
if (args.length == 2) {
target = this.getServer().getPlayer(args[1]);
if (target != null) {
targetUUID = target.getUniqueId();
this.playerPremiumStatus.remove(targetUUID);
this.playerPasswords.remove(targetUUID);
this.playerLoggedIn.remove(targetUUID);
target.kickPlayer(ChatColor.translateAlternateColorCodes('&', this.getMessage("admin_change_kick")));
this.sendMessage(player, "deactivatepremium_success", "{player}", args[1]);
this.savePlayerData();
}
}
break;
case 7:
this.reloadConfig();
this.config = this.getConfig();
this.loadConfigValues();
this.sendMessage(player, "reload_success");
break;
default:
this.sendAdminHelp(player);
}
return true;
}
default:
return false;
}
}
}
private void sendAdminHelp(Player player) {
player.sendMessage(ChatColor.translateAlternateColorCodes('&', this.prefix + "&aYoloAuth Admin Commands"));
String[] var2 = this.getMessage("admin_help").split("\n");
int var3 = var2.length;
for(int var4 = 0; var4 < var3; ++var4) {
String line = var2[var4];
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7" + line));
}
}
private void sendMessage(Player player, String key, String... placeholders) {
String message = this.getMessage(key);
for(int i = 0; i < placeholders.length; i += 2) {
message = message.replace(placeholders[i], placeholders[i + 1]);
}
if (message.contains("{title}")) {
String[] parts = message.split("\\{title\\}");
if (parts.length == 2) {
player.sendTitle(ChatColor.translateAlternateColorCodes('&', parts[0].trim()), ChatColor.translateAlternateColorCodes('&', parts[1].trim()), this.titleFadeIn, this.titleStay, this.titleFadeOut);
} else {
player.sendMessage(ChatColor.translateAlternateColorCodes('&', this.prefix + message));
}
} else {
player.sendMessage(ChatColor.translateAlternateColorCodes('&', this.prefix + message));
}
}
private String getMessage(String key, String... placeholders) {
String message = this.config.getString("messages." + this.language + "." + key, this.config.getString("messages.en." + key, "&cMessage not found: " + key));
for(int i = 0; i < placeholders.length; i += 2) {
message = message.replace(placeholders[i], placeholders[i + 1]);
}
return message;
}
private String formatLocation(Location loc) {
return loc == null ? "none" : String.format("(%d, %d, %d)", loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
}
private void logToFile(String message) {
if (this.logEnabled) {
try {
FileWriter fw = new FileWriter(new File(this.getDataFolder(), "yoloauthlog.log"), true);
try {
fw.write(message + "\n");
} catch (Throwable var6) {
try {
fw.close();
} catch (Throwable var5) {
var6.addSuppressed(var5);
}
throw var6;
}
fw.close();
} catch (IOException var7) {
this.getLogger().log(Level.SEVERE, "Failed to write to log file", var7);
}
}
}
}