Files
src
build.gradle
settings.gradle
Code
8 378
src/main/java/com/zyrovex/withercore/ZyrovexWitherCorePlugin.java
package com.zyrovex.withercore;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.NamespacedKey;
import org.bukkit.command.PluginCommand;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.IOException;
import java.util.List;
public final class ZyrovexWitherCorePlugin extends JavaPlugin {
private NamespacedKey coreKey;
private ClaimStore claimStore;
@Override
public void onEnable() {
saveDefaultConfig();
coreKey = new NamespacedKey(this, "wither_core");
try {
claimStore = new ClaimStore(getDataFolder().toPath(), getLogger());
} catch (IOException exception) {
getLogger().severe("Could not load the persistent Wither Core claim state; disabling safely.");
getLogger().severe(exception.getMessage());
Bukkit.getPluginManager().disablePlugin(this);
return;
}
PluginCommand command = getCommand("wither");
if (command == null) {
getLogger().severe("The /wither command is missing from plugin.yml; disabling.");
Bukkit.getPluginManager().disablePlugin(this);
return;
}
command.setExecutor(new WitherCoreCommand(this, claimStore));
Bukkit.getPluginManager().registerEvents(new WitherListener(this, claimStore), this);
getLogger().info("ZyrovexWitherCore enabled. Server-wide trophy status: "
+ (claimStore.isClaimed() ? "already claimed." : "not yet claimed."));
}
NamespacedKey getCoreKey() {
return coreKey;
}
ItemStack createWitherCore() {
ItemStack item = XMaterial.matchXMaterial("WITHER_SKELETON_SKULL")
.map(XMaterial::parseItem)
.orElse(null);
if (item == null) {
return null;
}
ItemMeta meta = item.getItemMeta();
if (meta == null) {
return null;
}
meta.setDisplayName(ChatColor.DARK_PURPLE.toString() + ChatColor.BOLD + "Wither Core");
meta.setLore(List.of(
ChatColor.GRAY + "The essence of the Wither",
ChatColor.DARK_GRAY + "A one-of-a-kind Nether trophy",
ChatColor.DARK_PURPLE + "ZYROVEX SMP"
));
meta.getPersistentDataContainer().set(coreKey, PersistentDataType.BYTE, (byte) 1);
item.setItemMeta(meta);
return item;
}
}