Quests Minecraft Plugin

repository·main·Indexed 42 days ago

https://github.com/pikamug/quests

An open-source questing system for Minecraft servers that allows administrators to create complex questlines and players to complete multiple tasks simultaneously for rewards. Includes administrative tools via /questadmin for managing player progress, quest points, and stages, as well as a developer framework for implementing custom subcommands by extending the BukkitQuestsSubCommand class.

Tokens
7.1K
Snippets
34
Records
43
Agent score
52%

What's inside Quests

  1. Cancel quest listing with BukkitQuestsCommandPreListEvent

    main

    Developers can intercept and cancel the quest listing process by listening for the BukkitQuestsCommandPreListEvent. This event is fired both when a player requests the first page of quests and when they request a specific page.

    If the event is cancelled, the quest listing process will stop and no quests will be displayed to the player.

    Event Details

    • Event Name: BukkitQuestsCommandPreListEvent
    • Purpose: Allows plugins to prevent players from viewing the quest list.
    • Key Method: isCancelled() returns true if the listing process should be aborted.
  2. Implement a BukkitQuestsSubCommand

    main

    To create a new subcommand for the Quests plugin, extend the BukkitQuestsSubCommand class. You must implement several abstract methods to define the command's identity, permissions, and behavior. This class also provides utility methods for common command tasks like player lookup and argument concatenation.

    Required Abstract Methods

    • getName(): Returns the command name.
    • getNameI18N(): Returns the localized version of the command name.
    • getDescription(): Returns a description of the command.
    • getPermission(): Returns the permission node required to use the command.
    • getSyntax(): Returns the command usage syntax.
    • getMaxArguments(): Returns the maximum number of arguments allowed.
    • execute(CommandSender commandSender, String[] args): The core logic to run when the command is invoked.
  3. Handle the /quests journal command with BukkitQuestsCommandPreJournalEvent

    main

    The BukkitQuestsCommandPreJournalEvent is an event fired immediately before the /quests journal command is processed by a player. Developers can listen for this event to intercept the command, perform custom logic, or prevent the command from executing entirely by calling setCancelled(true).

    @EventHandler
    public void onPreJournalCommand(BukkitQuestsCommandPreJournalEvent event) {
        // Example: Prevent players from seeing their journal if they meet a certain condition
        if (someCondition) {
            event.setCancelled(true);
        }
    }
  4. Handle the /quests list command with BukkitQuestsCommandPreListEvent

    main

    The BukkitQuestsCommandPreListEvent is an event fired immediately before the /quests list command is processed by a player. Developers can listen to this event to intercept the command, inspect the requested page, or cancel the command entirely by calling setCancelled(true). This is useful for implementing custom permission checks or restricting access to specific quest pages.

    @EventHandler
    public void onQuestsList(BukkitQuestsCommandPreListEvent event) {
        // Check which page the player is trying to view
        int requestedPage = event.getPage();
        
        // Example: Cancel the command if they try to access a page higher than 5
        if (requestedPage > 5) {
            event.setCancelled(true);
        }
    }
  5. Intercept the /quests editor command with BukkitQuestsCommandPreEditorEvent

    main

    The BukkitQuestsCommandPreEditorEvent is an event fired in the Bukkit environment immediately before a player executes the /quests editor command.

    By listening for this event, you can intercept the command attempt and cancel it using setCancelled(true). This is useful for implementing custom permission checks, cooldowns, or restricting access to the quest editor based on specific server conditions that go beyond standard permission nodes.

    @EventHandler
    public void onPreEditor(BukkitQuestsCommandPreEditorEvent event) {
        // Example: Cancel the command if the player is in a specific world
        if (event.getPlayer().getWorld().getName().equals("restricted_world")) {
            event.setCancelled(true);
        }
    }
  6. Use BukkitQuestsSubCommand utility methods

    main

    The BukkitQuestsSubCommand class provides static helper methods to simplify common command implementation tasks:

    • Player Lookup:
      • getOnlinePlayer(String name): Finds an online player. It supports partial matches (case-insensitive) using startsWith or contains logic.
      • getOfflinePlayer(String name): Finds a player, checking online players first, then searching through offline player data. Also supports partial matches.
    • Validation:
      • assertNonPlayer(CommandSender commandSender): Checks if the sender is NOT a Player (e.g., the Console). If the sender is the console, it sends a consoleError message and returns true to indicate the assertion failed.
    • Argument Handling:
      • concatArgArray(String[] args, int startingIndex, int endingIndex, char delimiter): Combines multiple command arguments into a single string. This is useful for commands where a name or value might contain spaces (e.g., a quest name).
    • Data Manipulation:
      • sort(Map<String, Integer> unsortedMap): Returns a new LinkedHashMap containing the entries of the provided map, sorted by value in descending order.
  7. Handle BukkitQuestsCommandEvent

    main

    The BukkitQuestsCommandEvent is an abstract event fired when a Quests-related command is executed within a Bukkit environment. Developers can listen to this event to intercept or react to command executions. You can retrieve the BukkitQuester involved in the command via getQuester() to access player-specific quest data and actions.

    @EventHandler
    public void onQuestsCommand(BukkitQuestsCommandEvent event) {
        BukkitQuester quester = event.getQuester();
        // Handle the command execution logic here
    }