Files
src
pom.xml
Code
10 798
src/main/java/com/asteria/asterialives/AsteriaLives.java
package com.asteria.asterialives;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.HashMap;
import java.util.Map;
public class AsteriaLives extends JavaPlugin {
private LivesManager livesManager;
private AsteriaLivesExpansion placeholderExpansion;
@Override
public void onEnable() {
saveDefaultConfig();
livesManager = new LivesManager(this);
LivesCommand command = new LivesCommand(this);
PluginCommand livesCommand = getCommand("lives");
if (livesCommand != null) {
livesCommand.setExecutor(command);
livesCommand.setTabCompleter(command);
}
Bukkit.getPluginManager().registerEvents(new LivesListener(this), this);
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
placeholderExpansion = new AsteriaLivesExpansion(this);
placeholderExpansion.register();
getLogger().info("PlaceholderAPI интеграция включена.");
}
long period = 20L * 60L;
Bukkit.getScheduler().runTaskTimer(this, () -> livesManager.processRegeneration(), period, period);
getLogger().info("AsteriaLives включен.");
}
@Override
public void onDisable() {
if (placeholderExpansion != null) {
placeholderExpansion.unregister();
}
if (livesManager != null) {
livesManager.close();
}
}
public LivesManager getLivesManager() {
return livesManager;
}
public int getLives(Player player) {
return livesManager.getLives(player);
}
public int getLives(java.util.UUID uuid) {
return livesManager.getLives(uuid);
}
public boolean isLivesEnabled() {
return getConfig().getBoolean("enabled", true);
}
public void reloadSettings() {
reloadConfig();
livesManager.reloadDataLimits();
}
public String message(String key, Object... replacements) {
String message = getConfig().getString("messages." + key, key);
Map<String, String> values = new HashMap<>();
for (int index = 0; index + 1 < replacements.length; index += 2) {
values.put(String.valueOf(replacements[index]), String.valueOf(replacements[index + 1]));
}
for (Map.Entry<String, String> entry : values.entrySet()) {
message = message.replace("%" + entry.getKey() + "%", entry.getValue());
}
return ChatColor.translateAlternateColorCodes('&', message);
}
}