Klasse MuteTemplateAPI

java.lang.Object
me.kzlyth.api.template.mute.MuteTemplateAPI

public class MuteTemplateAPI extends Object
API for accessing mute templates (custom mutes) in Zenith-Mod.

This API provides methods to retrieve mute template information, check offense levels, calculate template results with escalation, and query template availability.

Important:

  • Templates can only be created and modified through configuration files (modules/mute.yml).
  • This API is read-only and does not provide methods to create, modify, or delete templates.
  • To add new templates or modify existing ones, edit the configuration file and reload the plugin.

Database Compatibility: All methods in this API are fully compatible with H2, SQLite, MySQL, and MariaDB databases. The API automatically adapts to the configured database type from the configuration file.

Example usage:


 ZenithAPI api = ZenithAPI.getInstance();
 if (api != null) {
     MuteTemplateAPI templateAPI = api.getMuteTemplateAPI();
     
     // Get all templates
     templateAPI.getAllTemplates().thenAccept(templates -> {
         getLogger().info("Available templates: " + templates.size());
         for (MuteTemplate template : templates) {
             getLogger().info("Template: " + template.getName() + " (" + template.getKey() + ")");
         }
     });
     
     // Get specific template
     templateAPI.getTemplate("spam").thenAccept(template -> {
         if (template != null) {
             getLogger().info("Template: " + template.getName());
             getLogger().info("Auto IP mute: " + template.isAutoIpMute());
             getLogger().info("Duration levels: " + template.getDurations().size());
         }
     });
     
     // Check offense level for a player
     UUID playerUuid = UUID.fromString("123e4567-e89b-12d3-a456-426614174000");
     templateAPI.getOffenseLevel(playerUuid, "spam").thenAccept(level -> {
         getLogger().info("Player offense level: " + level);
     });
     
     // Calculate template result (with escalation)
     templateAPI.getTemplateResult(playerUuid, "spam", "Spamming in chat").thenAccept(result -> {
         if (result != null) {
             getLogger().info("Would mute for: " + result.getFormattedDuration());
             getLogger().info("Reason: " + result.getReason());
             getLogger().info("Offense level: " + result.getOffenseLevel());
         }
     });
 }
 
Seit:
1.2.3
Autor:
Zenith-Studios
  • Konstruktordetails

    • MuteTemplateAPI

      public MuteTemplateAPI(@NotNull @NotNull me.kzlyth.ZenithMod plugin, @NotNull @NotNull ZenithAPI api)
      Constructs a new MuteTemplateAPI instance.
      Parameter:
      plugin - The plugin instance
      api - The main API instance
  • Methodendetails

    • isTemplatesEnabled

      @NotNull public @NotNull CompletableFuture<Boolean> isTemplatesEnabled()
      Checks if mute templates are enabled.

      Example:

      
       templateAPI.isTemplatesEnabled().thenAccept(enabled -> {
           if (enabled) {
               getLogger().info("Mute templates are enabled");
           } else {
               getLogger().info("Mute templates are disabled");
           }
       });
       
      Gibt zurück:
      A CompletableFuture that completes with true if templates are enabled, false otherwise
    • getTemplate

      @NotNull public @NotNull CompletableFuture<MuteTemplate> getTemplate(@NotNull @NotNull String templateKey)
      Gets a mute template by its key (identifier).

      Example:

      
       templateAPI.getTemplate("spam").thenAccept(template -> {
           if (template != null) {
               getLogger().info("Template: " + template.getName());
               getLogger().info("Description: " + template.getDescription());
               getLogger().info("Auto IP mute: " + template.isAutoIpMute());
               getLogger().info("Default reason: " + template.getDefaultReason());
               
               if (template.getEscalation() != null) {
                   getLogger().info("Escalation enabled: " + template.getEscalation().isEnabled());
                   getLogger().info("Track by IP: " + template.getEscalation().isTrackByIp());
               }
               
               getLogger().info("Duration levels: " + template.getDurations().size());
           } else {
               getLogger().info("Template not found");
           }
       });
       
      Parameter:
      templateKey - The template key (identifier, e.g., "spam", "toxicity")
      Gibt zurück:
      A CompletableFuture that completes with the template, or null if not found
    • getAllTemplates

      @NotNull public @NotNull CompletableFuture<List<MuteTemplate>> getAllTemplates()
      Gets all available mute templates.

      Example:

      
       templateAPI.getAllTemplates().thenAccept(templates -> {
           getLogger().info("Available templates: " + templates.size());
           for (MuteTemplate template : templates) {
               getLogger().info("Template: " + template.getName() + " (" + template.getKey() + ")");
               getLogger().info("  Description: " + template.getDescription());
               getLogger().info("  Auto IP mute: " + template.isAutoIpMute());
               getLogger().info("  Duration levels: " + template.getDurations().size());
           }
       });
       
      Gibt zurück:
      A CompletableFuture that completes with a list of all mute templates
    • getTemplateNames

      @NotNull public @NotNull CompletableFuture<List<String>> getTemplateNames()
      Gets a list of all template keys (identifiers).

      Example:

      
       templateAPI.getTemplateNames().thenAccept(names -> {
           getLogger().info("Available template keys: " + names);
           for (String name : names) {
               getLogger().info("Template key: " + name);
           }
       });
       
      Gibt zurück:
      A CompletableFuture that completes with a list of template keys
    • templateExists

      @NotNull public @NotNull CompletableFuture<Boolean> templateExists(@NotNull @NotNull String templateKey)
      Checks if a template exists.

      Example:

      
       templateAPI.templateExists("spam").thenAccept(exists -> {
           if (exists) {
               getLogger().info("Template 'spam' exists");
           } else {
               getLogger().info("Template 'spam' does not exist");
           }
       });
       
      Parameter:
      templateKey - The template key to check
      Gibt zurück:
      A CompletableFuture that completes with true if the template exists, false otherwise
    • getOffenseLevel

      @NotNull public @NotNull CompletableFuture<Integer> getOffenseLevel(@NotNull @NotNull UUID playerUuid, @NotNull @NotNull String templateKey)
      Gets the offense level for a player with a specific template.

      The offense level represents how many times the player (or IP) has been muted using this template. This is used for escalation calculation.

      Example:

      
       UUID playerUuid = UUID.fromString("123e4567-e89b-12d3-a456-426614174000");
       templateAPI.getOffenseLevel(playerUuid, "spam").thenAccept(level -> {
           getLogger().info("Player offense level for 'spam' template: " + level);
           if (level > 1) {
               getLogger().info("This will be their " + level + " offense");
           }
       });
       
      Parameter:
      playerUuid - The UUID of the player
      templateKey - The template key (identifier)
      Gibt zurück:
      A CompletableFuture that completes with the offense level (1 = first offense, 2 = second offense, etc.)
    • getOffenseLevel

      @NotNull public @NotNull CompletableFuture<Integer> getOffenseLevel(@NotNull @NotNull String playerName, @NotNull @NotNull String templateKey)
      Gets the offense level for a player with a specific template.

      This is an overloaded method that accepts a player name instead of UUID.

      Example:

      
       templateAPI.getOffenseLevel("PlayerName", "spam").thenAccept(level -> {
           getLogger().info("Player offense level: " + level);
       });
       
      Parameter:
      playerName - The name of the player
      templateKey - The template key (identifier)
      Gibt zurück:
      A CompletableFuture that completes with the offense level
    • getTemplateResult

      @NotNull public @NotNull CompletableFuture<TemplateResult> getTemplateResult(@NotNull @NotNull UUID playerUuid, @NotNull @NotNull String templateKey, @Nullable @Nullable String customReason)
      Calculates the template result for a player (including escalation).

      This method calculates what mute duration and reason would be applied if the player were muted using this template, taking escalation into account.

      Example:

      
       UUID playerUuid = UUID.fromString("123e4567-e89b-12d3-a456-426614174000");
       templateAPI.getTemplateResult(playerUuid, "spam", "Spamming in chat").thenAccept(result -> {
           if (result != null) {
               getLogger().info("Would mute for: " + result.getFormattedDuration());
               getLogger().info("Final reason: " + result.getReason());
               getLogger().info("Offense level: " + result.getOffenseLevel());
               getLogger().info("Is permanent: " + result.isPermanent());
           }
       });
       
      Parameter:
      playerUuid - The UUID of the player
      templateKey - The template key (identifier)
      customReason - Optional custom reason (if null, uses template default reason)
      Gibt zurück:
      A CompletableFuture that completes with the template result, or null if template not found
    • getTemplateResult

      @NotNull public @NotNull CompletableFuture<TemplateResult> getTemplateResult(@NotNull @NotNull String playerName, @NotNull @NotNull String templateKey, @Nullable @Nullable String customReason)
      Calculates the template result for a player (including escalation).

      This is an overloaded method that accepts a player name instead of UUID.

      Example:

      
       templateAPI.getTemplateResult("PlayerName", "spam", "Spamming in chat").thenAccept(result -> {
           if (result != null) {
               getLogger().info("Would mute for: " + result.getFormattedDuration());
           }
       });
       
      Parameter:
      playerName - The name of the player
      templateKey - The template key (identifier)
      customReason - Optional custom reason (if null, uses template default reason)
      Gibt zurück:
      A CompletableFuture that completes with the template result, or null if template not found
    • isAutoIpMuteEnabled

      @NotNull public @NotNull CompletableFuture<Boolean> isAutoIpMuteEnabled(@NotNull @NotNull String templateKey)
      Checks if auto IP mute is enabled for a specific template.

      Auto IP mute means that when a player is muted using this template, their IP address is also automatically muted.

      Example:

      
       templateAPI.isAutoIpMuteEnabled("spam").thenAccept(enabled -> {
           if (enabled) {
               getLogger().info("Template 'spam' automatically IP mutes players");
           } else {
               getLogger().info("Template 'spam' only mutes the player, not the IP");
           }
       });
       
      Parameter:
      templateKey - The template key (identifier)
      Gibt zurück:
      A CompletableFuture that completes with true if auto IP mute is enabled, false otherwise or if template not found
    • getAutoIpMute

      @NotNull public @NotNull CompletableFuture<Boolean> getAutoIpMute(@NotNull @NotNull String templateKey)
      Gets the auto IP mute setting for a specific template.

      This is an alias for isAutoIpMuteEnabled(String).

      Example:

      
       templateAPI.getAutoIpMute("spam").thenAccept(autoIpMute -> {
           getLogger().info("Auto IP mute: " + autoIpMute);
       });
       
      Parameter:
      templateKey - The template key (identifier)
      Gibt zurück:
      A CompletableFuture that completes with true if auto IP mute is enabled, false otherwise