Files
src
build.gradle
Code
14 742
src/main/java/com/kaiz/playerprofile/PlayerProfilePlugin.java
package com.kaiz.playerprofile;
import com.kaiz.playerprofile.commands.ProfileCommand;
import com.kaiz.playerprofile.inventory.InventoryGUI;
import com.kaiz.playerprofile.inventory.gui.GUIListener;
import com.kaiz.playerprofile.inventory.gui.GUIManager;
import com.kaiz.playerprofile.inventory.impl.ProfileGUI;
import com.kaiz.playerprofile.managers.ConfigManager;
import lombok.Getter;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.Map;
import java.util.UUID;
@Getter
public class PlayerProfilePlugin extends JavaPlugin {
private GUIManager guiManager;
private ConfigManager configManager;
@Override
public void onEnable() {
configManager = new ConfigManager(this);
guiManager = new GUIManager();
getServer().getPluginManager().registerEvents(new GUIListener(guiManager), this);
ProfileCommand profileCommand = new ProfileCommand(this);
if (getCommand("profile") != null) {
getCommand("profile").setExecutor(profileCommand);
}
startUpdateTask();
getLogger().info("PlayerProfile enabled.");
}
@Override
public void onDisable() {
getLogger().info("PlayerProfile disabled.");
}
private void startUpdateTask() {
long intervalTicks = configManager.getUpdateInterval() * 20L;
new BukkitRunnable() {
@Override
public void run() {
Map<UUID, InventoryGUI> openGUIs = guiManager.getPlayerGUIs();
for (Map.Entry<UUID, InventoryGUI> entry : openGUIs.entrySet()) {
Player player = getServer().getPlayer(entry.getKey());
if (player != null && player.isOnline() && entry.getValue() instanceof ProfileGUI) {
ProfileGUI gui = (ProfileGUI) entry.getValue();
gui.refresh(player);
}
}
}
}.runTaskTimer(this, intervalTicks, intervalTicks);
}
}