Files
src
build.gradle
Code
10 688
src/main/java/com/example/deathnote/DeathNote.java
package com.example.deathnote;
import com.example.deathnote.commands.DeathNoteCommand;
import com.example.deathnote.listeners.BookListener;
import lombok.Getter;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@Getter
public class DeathNote extends JavaPlugin {
private FileConfiguration config;
private final Map<UUID, Long> cooldowns = new HashMap<>();
@Override
public void onEnable() {
saveDefaultConfig();
this.config = getConfig();
getCommand("deathnote").setExecutor(new DeathNoteCommand(this));
getServer().getPluginManager().registerEvents(new BookListener(this), this);
getLogger().info("Death Note plugin has been enabled!");
}
@Override
public void onDisable() {
cooldowns.clear();
getLogger().info("Death Note plugin has been disabled!");
}
public boolean isOnCooldown(UUID playerId) {
if (!cooldowns.containsKey(playerId)) {
return false;
}
long timeLeft = cooldowns.get(playerId) - System.currentTimeMillis();
return timeLeft > 0;
}
public long getCooldownTime(UUID playerId) {
if (!cooldowns.containsKey(playerId)) {
return 0;
}
long timeLeft = cooldowns.get(playerId) - System.currentTimeMillis();
return Math.max(0, timeLeft / 1000);
}
public void setCooldown(UUID playerId) {
long cooldownSeconds = config.getLong("cooldown", 60);
cooldowns.put(playerId, System.currentTimeMillis() + (cooldownSeconds * 1000));
}
public void removeCooldown(UUID playerId) {
cooldowns.remove(playerId);
}
public String getMessage(String path) {
String prefix = config.getString("messages.prefix", "&4[Death Note]&r");
String message = config.getString("messages." + path, "");
return colorize(prefix + " " + message);
}
public String getMessageRaw(String path) {
return colorize(config.getString("messages." + path, ""));
}
public String colorize(String message) {
return message.replace("&", "Β§");
}
}