Files
src
build.gradle
Code
15 1,326
src/main/java/com/soulstaff/SoulStaffPlugin.java
package com.soulstaff;
import com.cryptomorin.xseries.XMaterial;
import com.soulstaff.command.GiveSoulsCommand;
import com.soulstaff.command.GiveStaffCommand;
import com.soulstaff.command.SoulsCommand;
import com.soulstaff.data.SoulDataManager;
import com.soulstaff.item.ItemManager;
import com.soulstaff.listener.CraftListener;
import com.soulstaff.listener.PlayerDeathListener;
import com.soulstaff.listener.PlayerJoinListener;
import com.soulstaff.listener.StaffUseListener;
import com.soulstaff.manager.HerobrineManager;
import com.soulstaff.manager.MinionManager;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
@Getter
public class SoulStaffPlugin extends JavaPlugin {
private SoulDataManager soulDataManager;
private ItemManager itemManager;
private MinionManager minionManager;
private HerobrineManager herobrineManager;
private boolean hasExecutableItems = false;
private boolean hasModelEngine = false;
@Override
public void onEnable() {
saveDefaultConfig();
checkDependencies();
this.soulDataManager = new SoulDataManager(this);
this.itemManager = new ItemManager(this);
this.minionManager = new MinionManager(this);
this.herobrineManager = new HerobrineManager(this);
registerRecipe();
registerListeners();
registerCommands();
getLogger().info("SoulStaffPlugin has been enabled!");
}
@Override
public void onDisable() {
if (minionManager != null) {
minionManager.cleanup();
}
if (herobrineManager != null) {
herobrineManager.cleanup();
}
if (soulDataManager != null) {
soulDataManager.saveAll();
}
getLogger().info("SoulStaffPlugin has been disabled!");
}
private void checkDependencies() {
Plugin executableItems = Bukkit.getPluginManager().getPlugin("ExecutableItems");
if (executableItems != null && executableItems.isEnabled()) {
hasExecutableItems = true;
getLogger().info("ExecutableItems hooked!");
} else {
getLogger().warning("ExecutableItems not found - Herobrine sword will not be given");
}
Plugin modelEngine = Bukkit.getPluginManager().getPlugin("ModelEngine");
if (modelEngine != null && modelEngine.isEnabled()) {
hasModelEngine = true;
getLogger().info("ModelEngine hooked!");
} else {
getLogger().warning("ModelEngine not found - Herobrine model will not be applied");
}
}
private void registerRecipe() {
NamespacedKey key = new NamespacedKey(this, "soul_staff");
ShapedRecipe recipe = new ShapedRecipe(key, itemManager.createSoulStaff());
recipe.shape("DDD", "DND", "DDD");
recipe.setIngredient('D', XMaterial.DIAMOND_BLOCK.parseMaterial());
recipe.setIngredient('N', XMaterial.NETHER_STAR.parseMaterial());
Bukkit.addRecipe(recipe);
}
private void registerListeners() {
Bukkit.getPluginManager().registerEvents(new PlayerJoinListener(this), this);
Bukkit.getPluginManager().registerEvents(new PlayerDeathListener(this), this);
Bukkit.getPluginManager().registerEvents(new StaffUseListener(this), this);
Bukkit.getPluginManager().registerEvents(new CraftListener(this), this);
}
private void registerCommands() {
getCommand("souls").setExecutor(new SoulsCommand(this));
getCommand("givesouls").setExecutor(new GiveSoulsCommand(this));
getCommand("givestaff").setExecutor(new GiveStaffCommand(this));
}
}