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

Commit

Permalink
More Cleanup + Docstring ( I got bored ;[ )
Browse files Browse the repository at this point in the history
  • Loading branch information
KernelDotDLL committed Jan 5, 2024
1 parent 136a14a commit fd35c3d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package ir.Mehran1022.EventCore.Listeners;

import com.google.gson.annotations.SerializedName;
import ir.Mehran1022.EventCore.Commands.EventCommand;
import ir.Mehran1022.EventCore.Main;
import ir.Mehran1022.EventCore.Managers.ConfigManager;
import ir.Mehran1022.EventCore.Utils.Common;
import lombok.SneakyThrows;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand All @@ -12,26 +14,29 @@
import java.util.UUID;

public final class PlayerJoinEvent implements Listener {
/**
* Handles the event when a player joins the server.
*
* @param event The PlayerJoinEvent
*/
@SneakyThrows
@EventHandler
public void onPlayerJoin(org.bukkit.event.player.PlayerJoinEvent event) {
Player player = event.getPlayer();
UUID uuid = player.getUniqueId();
String uuidString = uuid.toString();
final Player player = event.getPlayer();
final String uuidString = player.getUniqueId().toString();

// Send event command message to player if Active
if (EventCommand.Active) {
Common.sendMessage(player, ConfigManager.PREFIX + EventCommand.EventDesc);
}

// Update player data in playersData.yml
Main.playersData.set(uuidString + ".NAME", player.getName());
Main.playersData.set(uuidString + ".BANNED", false);
Main.playersData.save(Main.file);

try {
Main.playersData.save(Main.file);
} catch (IOException e) {
e.printStackTrace();
}

Common.logDebug("[Debug] Added " + player.getName() + " to playersData.yml (PlayerJoin)");
// Log debug message
Common.logDebug(String.format("[Debug] Added %s to playersData.yml (PlayerJoin)", player.getName()));
}
}

13 changes: 3 additions & 10 deletions src/main/java/ir/Mehran1022/EventCore/Managers/UpdateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,20 @@

public final class UpdateManager {
private static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
private static final String USER_AGENT = "SpigotPluginUpdater";
private static final String RESOURCE_URL = "https://api.spigotmc.org/legacy/update.php?resource=%s";
private static final String resourceId = "110088";

public static void start() {
final Runnable updater = new Runnable() {
public void run() {
checkForUpdates();
}
};
final Runnable updater = UpdateManager::checkForUpdates;
scheduler.scheduleAtFixedRate(updater, 0, 1, TimeUnit.HOURS);
}

private static void checkForUpdates() {
if (ConfigManager.DEBUG) {
Common.log("[Debug] Checking for updates.");
}
Common.logDebug("[Debug] Checking for updates.");
try {
HttpURLConnection connection = (HttpURLConnection) new URL(String.format(RESOURCE_URL, resourceId)).openConnection();
connection.setRequestMethod("GET");
connection.addRequestProperty("User-Agent", USER_AGENT);
connection.addRequestProperty("User-Agent", "SpigotPluginUpdater");
String latestVersion = new Scanner(connection.getInputStream()).nextLine();
String currentVersion = Main.getInstance().getDescription().getVersion();
if (!currentVersion.equals(latestVersion)) {
Expand Down

0 comments on commit fd35c3d

Please sign in to comment.