LogoyStore

API

Documentação completa da API do plugin ySpawnersShop, incluindo métodos para acessar dados de loja de spawner do jogador.

Obtendo a Instância da API

Para acessar a API ySpawnersShop, recupere a instância do serviço Bukkit:

import br.com.ystoreplugins.product.yspawnersshop.SpawnersShopAPIHolder;
import org.bukkit.Bukkit;

SpawnersShopAPIHolder spawnersShopAPI = (SpawnersShopAPIHolder) Bukkit.getServicesManager()
    .load(SpawnersShopAPIHolder.class);

if (spawnersShopAPI != null) {
    // API está pronta para usar
}

Alternativamente, se você estiver usando Maven e tiver o plugin como uma dependência:

import com.ystoreplugins.yspawnersshop.api.SpawnersShopAPI;

SpawnersShopAPI spawnersShopAPI = new SpawnersShopAPI();

Métodos Disponíveis

getPlayer()

Recupera o titular de dados da loja de spawner para um jogador específico.

Parâmetros:

  • player (String) - O nome de usuário do jogador

Retorna:

  • PlayerSpawnerHolder - Objeto contendo todos os dados de loja de spawner do jogador, ou nulo se o jogador não for encontrado

Observações:

  • Os dados são recuperados do mapa de jogadores em cache
  • Retorna nulo se o jogador nunca fez login ou seus dados não estão em cache
  • Use isto para acessar inventário de spawner específico do jogador e compras
  • Contém histórico de coleta e transações da loja de spawner
PlayerSpawnerHolder playerData = spawnersShopAPI.getPlayer("PlayerName");
if (playerData != null) {
    // Acessar dados de loja de spawner do jogador
}

Estruturas de Dados

PlayerSpawnerHolder

Contém todos os dados relacionados a loja de spawner de um jogador. Contém:

  • Inventário de spawners comprados
  • Estatísticas de coleta de spawner
  • Histórico de compras e transações
  • Upgrades de spawner e níveis
  • Spawners disponíveis para compra

Melhores Práticas

  1. Sempre verifique null ao recuperar dados de spawner do jogador
  2. Cache dados do jogador se você estiver acessando frequentemente as informações do mesmo jogador
  3. Valide existência do jogador antes de acessar dados de spawner
  4. Trate jogadores offline com graça quando dados não estão disponíveis
  5. Use para acesso somente leitura em plugins de terceiros a menos que explicitamente necessário para modificações

Exemplos de Uso

Exemplo 1: Obtendo Dados de Loja de Spawner do Jogador

SpawnersShopAPIHolder spawnersShopAPI = (SpawnersShopAPIHolder) Bukkit.getServicesManager()
    .load(SpawnersShopAPIHolder.class);

PlayerSpawnerHolder playerData = spawnersShopAPI.getPlayer(player.getName());
if (playerData != null) {
    System.out.println("Dados de loja de spawner do jogador carregados com sucesso");
}

Exemplo 2: Verificando Coleção de Spawner do Jogador

SpawnersShopAPIHolder spawnersShopAPI = (SpawnersShopAPIHolder) Bukkit.getServicesManager()
    .load(SpawnersShopAPIHolder.class);

PlayerSpawnerHolder playerData = spawnersShopAPI.getPlayer(player.getName());
if (playerData != null) {
    System.out.println("O jogador tem dados de coleção de spawner");
    // Acessar informações de coleção de spawner
}

Exemplo 3: Cache de Dados do Jogador

public class SpawnerDataCache {
    
    private final SpawnersShopAPIHolder spawnersShopAPI;
    private final Map<String, PlayerSpawnerHolder> cache = new HashMap<>();
    private final Map<String, Long> lastUpdate = new HashMap<>();
    private static final long CACHE_DURATION = 5000; // 5 segundos
    
    public SpawnerDataCache(SpawnersShopAPIHolder spawnersShopAPI) {
        this.spawnersShopAPI = spawnersShopAPI;
    }
    
    public PlayerSpawnerHolder getPlayerData(String playerName) {
        long now = System.currentTimeMillis();
        
        if (cache.containsKey(playerName)) {
            long last = lastUpdate.getOrDefault(playerName, 0L);
            if (now - last < CACHE_DURATION) {
                return cache.get(playerName);
            }
        }
        
        PlayerSpawnerHolder data = spawnersShopAPI.getPlayer(playerName);
        if (data != null) {
            cache.put(playerName, data);
            lastUpdate.put(playerName, now);
        }
        
        return data;
    }
}

Exemplo 4: Validação de Dados de Spawner

public class SpawnerDataValidator {
    
    private final SpawnersShopAPIHolder spawnersShopAPI;
    
    public SpawnerDataValidator(SpawnersShopAPIHolder spawnersShopAPI) {
        this.spawnersShopAPI = spawnersShopAPI;
    }
    
    public boolean isPlayerDataValid(String playerName) {
        PlayerSpawnerHolder data = spawnersShopAPI.getPlayer(playerName);
        
        if (data == null) {
            return false;
        }
        
        // Verificações de validação adicionais
        return true;
    }
    
    public void validateAndLog(String playerName) {
        PlayerSpawnerHolder data = spawnersShopAPI.getPlayer(playerName);
        
        if (data == null) {
            System.out.println("[VALIDAR] Jogador " + playerName + 
                " não tem dados de spawner");
        } else {
            System.out.println("[VALIDAR] Dados do jogador " + playerName + 
                " são válidos");
        }
    }
}

Exemplo 5: Exibição de Estatísticas de Spawner

public class SpawnerStatistics {
    
    private final SpawnersShopAPIHolder spawnersShopAPI;
    private final JavaPlugin plugin;
    
    public SpawnerStatistics(SpawnersShopAPIHolder spawnersShopAPI, 
                            JavaPlugin plugin) {
        this.spawnersShopAPI = spawnersShopAPI;
        this.plugin = plugin;
    }
    
    public void displayPlayerSpawnerStats(String playerName) {
        PlayerSpawnerHolder data = spawnersShopAPI.getPlayer(playerName);
        
        if (data == null) {
            System.out.println("Jogador " + playerName + " não tem dados de spawner");
            return;
        }
        
        plugin.getLogger().info("=== Estatísticas de Spawner para " + playerName + " ===");
        plugin.getLogger().info("Dados de spawner recuperados com sucesso");
    }
}

Exemplo 6: Manipulador de Entrada do Jogador

@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
    SpawnersShopAPIHolder spawnersShopAPI = (SpawnersShopAPIHolder) 
        Bukkit.getServicesManager().load(SpawnersShopAPIHolder.class);
    
    Player player = event.getPlayer();
    PlayerSpawnerHolder data = spawnersShopAPI.getPlayer(player.getName());
    
    if (data != null) {
        player.sendMessage("§aBem-vindo de volta! Sua coleção de spawner está pronta.");
    }
}

Exemplo 7: Integração com Plugin de Economia

public class SpawnerEconomyIntegration {
    
    private final SpawnersShopAPIHolder spawnersShopAPI;
    private final JavaPlugin plugin;
    
    public SpawnerEconomyIntegration(SpawnersShopAPIHolder spawnersShopAPI, 
                                     JavaPlugin plugin) {
        this.spawnersShopAPI = spawnersShopAPI;
        this.plugin = plugin;
    }
    
    public void logSpawnerActivity(String playerName) {
        PlayerSpawnerHolder data = spawnersShopAPI.getPlayer(playerName);
        
        if (data != null) {
            plugin.getLogger().info("[ECONOMIA] Atividade de spawner do jogador " + playerName + 
                " registrada");
        }
    }
}

Exemplo 8: Recuperação em Lote de Dados do Jogador

public class BatchSpawnerDataRetrieval {
    
    private final SpawnersShopAPIHolder spawnersShopAPI;
    private final JavaPlugin plugin;
    
    public BatchSpawnerDataRetrieval(SpawnersShopAPIHolder spawnersShopAPI, 
                                     JavaPlugin plugin) {
        this.spawnersShopAPI = spawnersShopAPI;
        this.plugin = plugin;
    }
    
    public void retrieveMultiplePlayerData(List<String> playerNames) {
        for (String playerName : playerNames) {
            PlayerSpawnerHolder data = spawnersShopAPI.getPlayer(playerName);
            
            if (data != null) {
                plugin.getLogger().info("Dados para " + playerName + 
                    " recuperados com sucesso");
            } else {
                plugin.getLogger().warning("Dados para " + playerName + 
                    " não encontrados");
            }
        }
    }
}

Exemplo 9: Integração de Comando Customizado

public class SpawnerInfoCommand implements CommandExecutor {
    
    private final SpawnersShopAPIHolder spawnersShopAPI;
    
    public SpawnerInfoCommand(SpawnersShopAPIHolder spawnersShopAPI) {
        this.spawnersShopAPI = spawnersShopAPI;
    }
    
    @Override
    public boolean onCommand(CommandSender sender, Command command, 
                            String label, String[] args) {
        if (!(sender instanceof Player)) {
            sender.sendMessage("Apenas jogadores podem usar este comando");
            return true;
        }
        
        Player player = (Player) sender;
        PlayerSpawnerHolder data = spawnersShopAPI.getPlayer(player.getName());
        
        if (data == null) {
            player.sendMessage("§cSeus dados de spawner não estão disponíveis");
            return true;
        }
        
        player.sendMessage("§a§l=== Sua Coleção de Spawner ===");
        player.sendMessage("§eSeus dados de spawner estão carregados");
        
        return true;
    }
}

Exemplo 10: Manipulador Abrangente de Dados de Spawner

public class ComprehensiveSpawnerHandler {
    
    private final SpawnersShopAPIHolder spawnersShopAPI;
    private final JavaPlugin plugin;
    private final Map<String, PlayerSpawnerHolder> cachedData = new HashMap<>();
    
    public ComprehensiveSpawnerHandler(SpawnersShopAPIHolder spawnersShopAPI, 
                                       JavaPlugin plugin) {
        this.spawnersShopAPI = spawnersShopAPI;
        this.plugin = plugin;
    }
    
    public PlayerSpawnerHolder getOrLoadPlayerData(String playerName) {
        // Verificar cache primeiro
        if (cachedData.containsKey(playerName)) {
            return cachedData.get(playerName);
        }
        
        // Carregar da API
        PlayerSpawnerHolder data = spawnersShopAPI.getPlayer(playerName);
        
        if (data != null) {
            cachedData.put(playerName, data);
            plugin.getLogger().info("[CARREGAR] Dados de spawner para " + playerName + 
                " carregados com sucesso");
        } else {
            plugin.getLogger().warning("[CARREGAR] Dados de spawner para " + playerName + 
                " não encontrados");
        }
        
        return data;
    }
    
    public void validatePlayerData(Player player) {
        String playerName = player.getName();
        PlayerSpawnerHolder data = getOrLoadPlayerData(playerName);
        
        if (data == null) {
            player.sendMessage("§cDados de spawner não estão disponíveis");
            return;
        }
        
        player.sendMessage("§aSeus dados de spawner são válidos e carregados");
    }
    
    public void clearCache(String playerName) {
        if (cachedData.remove(playerName) != null) {
            plugin.getLogger().info("[CACHE] Dados de spawner limpos para " + playerName);
        }
    }
    
    public void clearAllCache() {
        cachedData.clear();
        plugin.getLogger().info("[CACHE] Todo cache de dados de spawner foi limpo");
    }
    
    public int getCacheSize() {
        return cachedData.size();
    }
}

Nesta página