Files
src
pom.xml
Code
9 870
src/main/java/com/kodari/godarmor/GodArmorPlugin.java
package com.kodari.godarmor;
import java.util.Objects;
import org.bukkit.Bukkit;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;
public final class GodArmorPlugin extends JavaPlugin {
private GodArmorManager godArmorManager;
private DoubleJumpListener doubleJumpListener;
@Override
public void onEnable() {
ArmorFactory armorFactory = new ArmorFactory(this);
this.godArmorManager = new GodArmorManager(this);
this.doubleJumpListener = new DoubleJumpListener(this, this.godArmorManager);
this.registerCommand("godarmor", new GodArmorCommand(armorFactory, "godarmor.give", null));
this.registerCommand("godhelmet", new GodArmorCommand(armorFactory, "godarmor.helmet", ArmorFactory.HELMET));
this.registerCommand("godchestplate", new GodArmorCommand(armorFactory, "godarmor.chestplate", ArmorFactory.CHESTPLATE));
this.registerCommand("godleggings", new GodArmorCommand(armorFactory, "godarmor.leggings", ArmorFactory.LEGGINGS));
this.registerCommand("godboots", new GodArmorCommand(armorFactory, "godarmor.boots", ArmorFactory.BOOTS));
Bukkit.getPluginManager().registerEvents(
new ArmorListener(this, this.godArmorManager, this.doubleJumpListener),
this
);
Bukkit.getPluginManager().registerEvents(this.doubleJumpListener, this);
Bukkit.getPluginManager().registerEvents(new FallDamageListener(this.godArmorManager), this);
Bukkit.getOnlinePlayers().forEach(this.godArmorManager::initializePlayer);
Bukkit.getOnlinePlayers().forEach(this.doubleJumpListener::refreshFlightState);
Bukkit.getScheduler().runTaskTimer(this, () -> {
this.godArmorManager.refreshOnlinePlayers();
this.doubleJumpListener.refreshOnlinePlayers();
}, 20L, 20L);
}
@Override
public void onDisable() {
if (this.doubleJumpListener != null) {
this.doubleJumpListener.resetFlightStates();
}
if (this.godArmorManager != null) {
this.godArmorManager.shutdown();
}
}
private void registerCommand(String commandName, GodArmorCommand executor) {
PluginCommand command = this.getCommand(commandName);
if (command == null) {
throw new IllegalStateException("The " + commandName + " command is missing from plugin.yml.");
}
command.setExecutor(executor);
}
public GodArmorManager getGodArmorManager() {
return Objects.requireNonNull(this.godArmorManager, "GodArmorManager has not been initialized.");
}
}