notbritish64

create the mod minecraft origins as a plugin for 26.3

Kodari AI
KodariOct 26 at 10:59 pm 1
OriginsPlugin
Implements the Origins mod concept as a Spigot/Paper plugin for Minecraft 1.26.3. Players choose from distinct origins (Human, Arachnid, Blazeborn, Elytrian, Feline, Phantom, Shulk, Merling) via GUI at first join or command. Each origin grants unique active and passive abilities: Arachnid gets wall-climbing and web-shooting, Blazeborn deals fire damage and immune to lava, Elytrian has glide and slow fall, Feline has night vision and jump boost, Phantom can phase through blocks and burn in daylight, Shulk gains natural armor and extra inventory slots, Merling breathes underwater and swims fast. Abilities are implemented through custom effects, event listeners, and cooldown systems. Includes origin selection GUI, persistent player data storage, admin commands to set/change origins, and configurable ability parameters.
  1. Create a Paper plugin project with a /origin command and origin-selection GUI.

  2. Add seven selectable origins with passive effects, cooldown abilities, and saved player choices.

  3. Target the stable Paper 1.21 API for forward compatibility with newer server versions.

Created a Paper Origins plugin with seven selectable origins, passive effects, cooldown-based abilities, a selection GUI, and saved player choices.

It uses Paper API 1.21.4 with plugin API version 1.21 for forward compatibility; it is not compiled against a Minecraft 26.3-specific API.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
6 294
src/main/java/com/kodari/origins/OriginsPlugin.java
package com.kodari.origins;

import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XPotion;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

public final class OriginsPlugin extends JavaPlugin implements Listener, CommandExecutor {
    private static final String MENU_TITLE = ChatColor.DARK_PURPLE + "Choose Your Origin";
    private static final long POWER_COOLDOWN_MILLIS = 30_000L;

    private final Map<UUID, OriginType> origins = new HashMap<>();
    private final Map<UUID, Long> powerCooldowns = new HashMap<>();

    @Override
    public void onEnable() {
        saveDefaultConfig();
        loadOrigins();
        getCommand("origin").setExecutor(this);
        getServer().getPluginManager().registerEvents(this, this);
        getServer().getScheduler().runTaskTimer(this, this::applyPassiveEffects, 20L, 100L);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!(sender instanceof Player player)) {
            sender.sendMessage("This command can only be used in-game.");
            return true;
        }

        String subcommand = args.length == 0 ? "choose" : args[0].toLowerCase();
        switch (subcommand) {
            case "choose" -> openOriginMenu(player);
            case "info" -> showOriginInfo(player);
            case "power" -> usePower(player);
            case "reset" -> resetOrigin(player);
            default -> player.sendMessage(ChatColor.YELLOW + "Use /origin [choose|info|power|reset].");
        }
        return true;
    }

    @EventHandler
    public void onInventoryClick(InventoryClickEvent event) {
        if (!MENU_TITLE.equals(event.getView().getTitle())) {
            return;
        }
        event.setCancelled(true);
        if (!(event.getWhoClicked() instanceof Player player)
                || event.getRawSlot() < 0
                || event.getRawSlot() >= event.getView().getTopInventory().getSize()) {
            return;
        }

        for (OriginType origin : OriginType.values()) {
            if (origin.ordinal() + 10 == event.getRawSlot()) {
                chooseOrigin(player, origin);
                return;
            }
        }
    }

    private void openOriginMenu(Player player) {
        if (origins.containsKey(player.getUniqueId()) && !player.hasPermission("origins.admin")) {
            player.sendMessage(ChatColor.RED + "You already chose an origin. Use /origin info or /origin power.");
            return;
        }

        Inventory inventory = Bukkit.createInventory(null, 27, MENU_TITLE);
        for (OriginType origin : OriginType.values()) {
            ItemStack item = XMaterial.matchXMaterial(origin.getIcon())
                    .map(XMaterial::parseItem)
                    .orElse(null);
            if (item == null) {
                continue;
            }

            ItemMeta meta = item.getItemMeta();
            if (meta != null) {
                meta.setDisplayName(ChatColor.LIGHT_PURPLE + origin.getDisplayName());
                meta.setLore(List.of(
                        ChatColor.GRAY + "Passive: " + origin.getPassiveDescription(),
                        ChatColor.YELLOW + "Click to choose"
                ));
                item.setItemMeta(meta);
            }
            inventory.setItem(origin.ordinal() + 10, item);
        }
        player.openInventory(inventory);
    }

    private void chooseOrigin(Player player, OriginType origin) {
        UUID playerId = player.getUniqueId();
        if (origins.containsKey(playerId) && !player.hasPermission("origins.admin")) {
            player.closeInventory();
            player.sendMessage(ChatColor.RED + "You already chose an origin.");
            return;
        }

        origins.put(playerId, origin);
        getConfig().set("players." + playerId, origin.name());
        saveConfig();
        player.closeInventory();
        player.sendMessage(ChatColor.GREEN + "Your origin is now " + ChatColor.LIGHT_PURPLE
                + origin.getDisplayName() + ChatColor.GREEN + ". Use /origin power to use its ability.");
        applyPassiveEffect(player, origin);
    }

    private void showOriginInfo(Player player) {
        OriginType origin = origins.get(player.getUniqueId());
        if (origin == null) {
            player.sendMessage(ChatColor.YELLOW + "You have not chosen an origin. Use /origin choose.");
            return;
        }
        player.sendMessage(ChatColor.LIGHT_PURPLE + "Origin: " + origin.getDisplayName()
                + ChatColor.GRAY + " | Passive: " + origin.getPassiveDescription()
                + ChatColor.GRAY + " | Ability cooldown: 30 seconds");
    }

    private void usePower(Player player) {
        OriginType origin = origins.get(player.getUniqueId());
        if (origin == null) {
            player.sendMessage(ChatColor.YELLOW + "Choose an origin first with /origin choose.");
            return;
        }

        long now = System.currentTimeMillis();
        long readyAt = powerCooldowns.getOrDefault(player.getUniqueId(), 0L);
        if (now < readyAt) {
            long secondsLeft = (readyAt - now + 999L) / 1000L;
            player.sendMessage(ChatColor.RED + "Your ability is on cooldown for " + secondsLeft + " more seconds.");
            return;
        }

        XPotion.matchXPotion(origin.getPowerEffect())
                .map(potion -> potion.buildPotionEffect(160, origin.getPowerAmplifier()))
                .ifPresent(effect -> player.addPotionEffect(effect, true));
        powerCooldowns.put(player.getUniqueId(), now + POWER_COOLDOWN_MILLIS);
        player.sendMessage(ChatColor.GREEN + origin.getDisplayName() + " ability activated.");
    }

    private void resetOrigin(Player player) {
        if (!player.hasPermission("origins.admin")) {
            player.sendMessage(ChatColor.RED + "You do not have permission to reset an origin.");
            return;
        }
        UUID playerId = player.getUniqueId();
        origins.remove(playerId);
        powerCooldowns.remove(playerId);
        getConfig().set("players." + playerId, null);
        saveConfig();
        player.sendMessage(ChatColor.GREEN + "Your origin has been reset. Use /origin choose to select another.");
    }

    private void applyPassiveEffects() {
        for (Player player : Bukkit.getOnlinePlayers()) {
            OriginType origin = origins.get(player.getUniqueId());
            if (origin != null) {
                applyPassiveEffect(player, origin);
            }
        }
    }

    private void applyPassiveEffect(Player player, OriginType origin) {
        if (origin.getPassiveEffect() == null) {
            return;
        }
        XPotion.matchXPotion(origin.getPassiveEffect())
                .map(potion -> potion.buildPotionEffect(140, 0))
                .ifPresent(effect -> player.addPotionEffect(effect, true));
    }

    private void loadOrigins() {
        origins.clear();
        var players = getConfig().getConfigurationSection("players");
        if (players == null) {
            return;
        }

        for (String key : players.getKeys(false)) {
            try {
                UUID playerId = UUID.fromString(key);
                OriginType origin = OriginType.valueOf(players.getString(key, ""));
                origins.put(playerId, origin);