Files
src
pom.xml
README.md
Code
14 1,552
src/main/java/com/superpowers/SuperPowersPlugin.java
package com.superpowers;
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 final class SuperPowersPlugin extends JavaPlugin {
private PowerItems items;
private SingularityPower singularity;
private HellfirePower hellfire;
private ChronoPower chrono;
private ThunderPower thunder;
private final Map<String, Long> cooldowns = new HashMap<>();
@Override
public void onEnable() {
saveDefaultConfig();
items = new PowerItems(this);
singularity = new SingularityPower(this);
hellfire = new HellfirePower(this);
chrono = new ChronoPower(this);
thunder = new ThunderPower(this);
getServer().getPluginManager().registerEvents(new PowerListener(this), this);
PowerCommand command = new PowerCommand(this);
PluginCommand pc = getCommand("power");
if (pc != null) {
pc.setExecutor(command);
pc.setTabCompleter(command);
}
chrono.start();
getLogger().info("SuperPowers enabled - use /power give <player> <power>.");
}
@Override
public void onDisable() {
getServer().getScheduler().cancelTasks(this);
if (singularity != null) singularity.cleanup();
if (chrono != null) chrono.cleanup();
if (thunder != null) thunder.cleanup();
if (hellfire != null) hellfire.cleanup();
}
public PowerItems items() { return items; }
public SingularityPower singularity() { return singularity; }
public HellfirePower hellfire() { return hellfire; }
public ChronoPower chrono() { return chrono; }
public ThunderPower thunder() { return thunder; }
public long remainingMillis(Player p, PowerType t) {
Long end = cooldowns.get(p.getUniqueId() + ":" + t.id());
if (end == null) return 0L;
return Math.max(0L, end - System.currentTimeMillis());
}
public void startCooldown(Player p, PowerType t) {
double seconds = getConfig().getDouble(t.id() + ".cooldown-seconds", 30.0);
if (seconds <= 0 || p.hasPermission("superpowers.bypass.cooldown")) return;
cooldowns.put(p.getUniqueId() + ":" + t.id(), System.currentTimeMillis() + (long) (seconds * 1000.0));
}
}