Files
src
build.gradle
settings.gradle
Code
11 1,143
src/main/java/com/kodari/hybrids/HybridPlugin.java
package com.kodari.hybrids;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ShapelessRecipe;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.Optional;
public final class HybridPlugin extends JavaPlugin {
private NamespacedKey hybridTypeKey;
private NamespacedKey milkReadyKey;
private NamespacedKey encyclopediaKey;
private NamespacedKey recipeKey;
private DiscoveryManager discoveryManager;
private FusionManager fusionManager;
private EncyclopediaManager encyclopediaManager;
@Override
public void onEnable() {
hybridTypeKey = new NamespacedKey(this, "hybrid_type");
milkReadyKey = new NamespacedKey(this, "milk_ready_at");
encyclopediaKey = new NamespacedKey(this, "encyclopedia");
recipeKey = new NamespacedKey(this, "encyclopedia_recipe");
discoveryManager = new DiscoveryManager(this);
fusionManager = new FusionManager(this);
encyclopediaManager = new EncyclopediaManager(this);
getServer().getPluginManager().registerEvents(new HybridListener(this), this);
getServer().getPluginManager().registerEvents(new EncyclopediaListener(this), this);
Bukkit.removeRecipe(recipeKey);
ShapelessRecipe recipe = new ShapelessRecipe(recipeKey, encyclopediaManager.createBook());
recipe.addIngredient(Material.BOOK);
recipe.addIngredient(Material.GOLDEN_APPLE);
Bukkit.addRecipe(recipe);
}
@Override
public void onDisable() {
if (discoveryManager != null) {
discoveryManager.save();
}
Bukkit.removeRecipe(recipeKey);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!command.getName().equalsIgnoreCase("hybridbook")) {
return false;
}
Player target = args.length > 0
? Bukkit.getPlayerExact(args[0])
: (sender instanceof Player self ? self : null);
if (target == null) {
sender.sendMessage(Text.color("&cPlayer not found. Usage: /hybridbook <player>"));
return true;
}
target.getInventory().addItem(encyclopediaManager.createBook())
.values()
.forEach(leftover -> target.getWorld().dropItemNaturally(target.getLocation(), leftover));
sender.sendMessage(Text.color("&aGave a Hybrid Animals Encyclopedia to " + target.getName() + "."));
return true;
}
public Optional<HybridType> hybridOf(Entity entity) {
String id = entity.getPersistentDataContainer().get(hybridTypeKey, PersistentDataType.STRING);
return id == null ? Optional.empty() : HybridType.fromId(id);
}
public NamespacedKey getHybridTypeKey() {
return hybridTypeKey;
}
public NamespacedKey getMilkReadyKey() {
return milkReadyKey;
}
public NamespacedKey getEncyclopediaKey() {
return encyclopediaKey;
}
public DiscoveryManager getDiscoveryManager() {
return discoveryManager;
}
public FusionManager getFusionManager() {
return fusionManager;
}
public EncyclopediaManager getEncyclopediaManager() {
return encyclopediaManager;
}
}