Giants/src/main/java/eu/m724/giants/GiantsPlugin.java
2025-03-25 16:25:24 +01:00

81 lines
2.9 KiB
Java

package eu.m724.giants;
import eu.m724.giants.updater.PluginUpdater;
import eu.m724.giants.updater.UpdateCommand;
import eu.m724.jarupdater.verify.VerificationException;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SimplePie;
import org.bukkit.Location;
import org.bukkit.command.CommandExecutor;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
public class GiantsPlugin extends JavaPlugin implements CommandExecutor {
private final File configFile = new File(getDataFolder(), "config.yml");
private final Configuration configuration = new Configuration(this, configFile);
private final GiantProcessor giantProcessor = new GiantProcessor(this, configuration);
@Override
public void onEnable() {
if (!configFile.exists()) {
saveResource("config.yml", false);
}
configuration.load();
giantProcessor.start();
// updater
PluginUpdater updater = null;
if (configuration.updater != null) {
try (InputStream keyInputStream = getResource("verifies_downloaded_jars.pem")) {
updater = PluginUpdater.build(this, getFile(), configuration.updater, keyInputStream);
} catch (IOException e) {
e.printStackTrace();
getLogger().severe("Failed to load updater");
}
if (updater != null) {
try {
updater.verifyJar(
getFile().getPath().replace(".paper-remapped/", "") // paper remapping removes data from manifest
);
} catch (VerificationException e) {
getLogger().warning(e.getMessage());
getLogger().warning("Plugin JAR is of invalid signature. If this persists, re-download the JAR from SpigotMC.");
getLogger().warning("If on Paper, try removing plugins/.paper-remapped");
}
updater.initNotifier();
}
}
UpdateCommand updateCommand = new UpdateCommand(updater);
getCommand("giants").setExecutor(new GiantsCommand(this, updateCommand));
Metrics metrics = new Metrics(this, 14131);
metrics.addCustomChart(new SimplePie("jump_mode", () -> String.valueOf(configuration.jumpMode)));
metrics.addCustomChart(new SimplePie("jump_condition", () -> String.valueOf(configuration.jumpCondition)));
metrics.addCustomChart(new SimplePie("jump_delay", () -> String.valueOf(configuration.jumpDelay)));
metrics.addCustomChart(new SimplePie("jump_height", () -> String.valueOf(configuration.jumpHeight)));
}
// TODO api, untested
/**
* Checks if a giant can be spawned at a location<br>
* The check is very approximate, but works for most scenarios
*
* @param location The location
* @return Whether a giant can be spawned
*/
public boolean isSpawnableAt(Location location) {
return giantProcessor.isSpawnableAt(location);
}
}