Files
src
build.gradle
settings.gradle
Code
11 1,072
src/main/java/com/kodari/lungestacks/LungeStacksPlugin.java
package com.kodari.lungestacks;
import io.papermc.paper.event.server.ServerResourcesReloadedEvent;
import org.bukkit.Bukkit;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
public final class LungeStacksPlugin extends JavaPlugin implements Listener {
private ChargeManager charges;
private StackDisplay display;
private LungeHook hook;
private WizardHat wizardHat;
private WizardHatProtection hatProtection;
@Override
public void onEnable() {
boolean existingInstallation = new File(getDataFolder(), "config.yml").isFile();
saveDefaultConfig();
try {
wizardHat = new WizardHat(this, existingInstallation);
} catch (IOException | InvalidConfigurationException exception) {
getLogger().log(Level.SEVERE, "위자드 모자 발급 기록을 읽거나 저장하지 못해 플러그인을 비활성화합니다.", exception);
Bukkit.getPluginManager().disablePlugin(this);
return;
}
getCommand("wizardhat").setExecutor(wizardHat);
getCommand("wizardhat").setTabCompleter(wizardHat);
charges = new ChargeManager(this);
hook = new LungeHook(this, player -> {
boolean allowed = wizardHat.isWearing(player) || charges.tryConsume(player);
if (display != null) {
display.update(player);
}
return allowed;
});
try {
hook.install();
} catch (ReflectiveOperationException | RuntimeException exception) {
getLogger().log(Level.SEVERE, "돌진 스택 적용에 실패하여 플러그인을 비활성화합니다.", exception);
Bukkit.getPluginManager().disablePlugin(this);
return;
}
display = new StackDisplay(this, charges, wizardHat);
hatProtection = new WizardHatProtection(this, wizardHat);
Bukkit.getPluginManager().registerEvents(this, this);
getLogger().info("돌진 스택 활성화: 최대 5스택, "
+ Math.max(1, getConfig().getInt("refill-seconds", 15)) + "초마다 1스택 충전.");
}
@Override
public void onDisable() {
if (hatProtection != null) {
hatProtection.stop();
}
if (display != null) {
display.stop();
}
if (charges != null) {
for (Player player : Bukkit.getOnlinePlayers()) {
charges.forget(player);
}
}
if (hook != null) {
try {
hook.restore();
} catch (ReflectiveOperationException exception) {
getLogger().log(Level.SEVERE, "바닐라 돌진 조건을 복구하지 못했습니다.", exception);
}
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onQuit(PlayerQuitEvent event) {
display.forget(event.getPlayer());
charges.forget(event.getPlayer());
}
@EventHandler(priority = EventPriority.MONITOR)
public void onResourcesReloaded(ServerResourcesReloadedEvent event) {
try {
hook.install();
} catch (ReflectiveOperationException | RuntimeException exception) {
getLogger().log(Level.SEVERE, "리소스 재로딩 후 돌진 스택 재적용에 실패했습니다.", exception);
Bukkit.getPluginManager().disablePlugin(this);
}
}
}