Files
purpur-heights/src/main/java/games/dmg/spigotheights/SpigotHeightsPlugin.java
T
dmg 47d5060dac
Release / release (push) Successful in 2m36s
CI / build (push) Successful in 1m1s
feat(heights): add durable temporary throwable stature
2026-09-10 22:41:20 -04:00

75 lines
3.4 KiB
Java

package games.dmg.spigotheights;
import java.util.Objects;
import org.bukkit.command.PluginCommand;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
public final class SpigotHeightsPlugin extends JavaPlugin {
private BukkitStatureService stature;
private PotionRecipes potions;
@Override
public void onEnable() {
saveDefaultConfig();
HeightSettings settings;
try {
settings = loadSettings(getConfig());
} catch (IllegalArgumentException exception) {
getLogger().severe("Invalid configuration: " + exception.getMessage());
getServer().getPluginManager().disablePlugin(this);
return;
}
SettingsFileStore configStore = new SettingsFileStore(getDataFolder().toPath().resolve("config.yml"));
LiveHeightSettings liveSettings = new LiveHeightSettings(settings, next -> {
configStore.save(next);
getConfig().set("height.minimum", next.minimum());
getConfig().set("height.maximum", next.maximum());
});
HeightStore store = new HeightStore(getDataFolder());
BukkitPlayerHeights onlinePlayers = new BukkitPlayerHeights(getServer());
PlayerHeights playerHeights = new PlayerHeights(liveSettings, store, onlinePlayers::find, onlinePlayers::names);
stature = new BukkitStatureService(this, liveSettings, store);
HeightsCommand executor = new HeightsCommand(liveSettings, playerHeights, getLogger(), stature::set);
PluginCommand command = Objects.requireNonNull(getCommand("heights"), "Missing heights command declaration");
command.setExecutor(executor);
command.setTabCompleter(executor);
potions = new PotionRecipes(this);
potions.register();
getServer().getPluginManager().registerEvents(
new StatureListener(potions, stature::drink, stature::resume,
task -> getServer().getScheduler().runTask(this, task)), this);
ThrowableStatureListener throwable = new ThrowableStatureListener(potions,
new org.bukkit.NamespacedKey(this, "cloud_kind"), stature::temporary);
getServer().getPluginManager().registerEvents(throwable, this);
StatureClouds clouds = new StatureClouds(getServer(), throwable, stature::retireSource);
getServer().getPluginManager().registerEvents(clouds, this);
getServer().getScheduler().runTaskTimer(this, clouds::tick, 5L, 5L);
getServer().getScheduler().runTaskTimer(this, stature::expireOnline, 20L, 20L);
getServer().getOnlinePlayers().forEach(stature::resume);
getServer().getPluginManager().registerEvents(new TinyPlayerLauncher(liveSettings), this);
getLogger().info("Spigot Heights enabled.");
}
@Override
public void onDisable() {
if (stature != null) {
stature.close();
}
if (potions != null) {
potions.unregisterBrewing();
}
}
static HeightSettings loadSettings(FileConfiguration config) {
return new HeightSettings(
config.getDouble("height.minimum"),
config.getDouble("height.maximum"),
config.getDouble("height.adjustment-step"),
config.getDouble("launcher.maximum-player-scale-exclusive"),
config.getDouble("launcher.speed"),
config.getInt("launcher.cooldown-ticks"));
}
}