Skip to content

Placeholder type handlers #30

@Maximvdw

Description

@Maximvdw

Problem statement
Many code duplication and inconsistencies occur with various generic placeholders. A common example is a Bukkit location that returns an X,Y,Z,Pitch,Yaw,Roll value. Currently, expansions have to create a placeholder for every _x, _y, _z variant of the placeholder. Similar issues can appear with other default Bukkit types such as Players, etc...

Goal
The goal is to create type handlers that convert a one placeholder type to many (string) placeholders. This will enforce consistency throughout expansions and limit code duplication.

Requirements

  • Type handlers should accept any Object that is not a String
  • Type handlers could be registered globally and locally per expansions, local type handlers should have a higher priority. I envision that every expansion can register a type handler (e.g. a LocationExpansion offers all placeholders associated to a Location)
  • Type handlers should be able to create multiple placeholders, either by cancelling the creation of the non-string placeholder and using the PAPI API to register placeholders, or some other interface to facilitate this
  • Placeholder information should be forwarded to type handlers, such as the placeholder name and arguments
  • String types should not support type handlers - they should remain unmodified. However, there might be use cases where a user is interested in a %player_name_uppercase% or similar 'text' action. Maybe a 'Text' object can be added to PAPI to indicate a string that can support text manipulation like uppercase, lowercase, substring, ....

Use cases

  • Many decimal numbers accept arguments to round the value. A type handler could facilitate this to create consistency for these arguments when returning a double or float.
  • Similar to the above use case, the same thing can be done for a java.util.Date object, using consistent arguments to determine the formatting
  • Many placeholders return the 'player' (e.g. player of a town, player nearby, top player, ...) a player on itself might have more information, the Player Expansion could register a 'Player type handler' that returns all placeholders currently available for every single player placeholder. Example: townyadvanced_town_owner (fictional placeholder) returns a Player instance. The Player Expansion registers a player handler that offers placeholders such as townyadvanced_town_owner_uuid, townyadvanced_town_owner_is_flying,.. without code repetition

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions