rework urls in config.yml

This commit is contained in:
2025-12-07 16:28:50 +05:00
parent 8907ffeb51
commit 4e5e6d1cf7
2 changed files with 74 additions and 19 deletions

View File

@ -39,6 +39,7 @@ public final class popa extends JavaPlugin implements Listener {
private HttpClient httpClient;
private String apiBase;
private String apiUrl;
private String serverIp;
private String commandsUrl;
@ -57,13 +58,26 @@ public final class popa extends JavaPlugin implements Listener {
saveDefaultConfig();
reloadConfig();
// База для всех урлов
apiBase = getConfig().getString("api-base", "http://localhost:8000");
// Получаем настройки из конфига
String apiBase = getConfig().getString("api-base", "http://localhost:8000");
apiUrl = getConfig().getString("api-url", apiBase + "/api/server/events");
commandsUrl = getConfig().getString("commands-url", apiBase + "/api/server/commands");
inventoryRequestsUrl = getConfig().getString("inventory-requests-url", apiBase + "/api/server/inventory/requests");
apiUrl = apiBase + "/api/server/events";
commandsUrl = apiBase + "/api/server/commands";
inventoryRequestsUrl = apiBase + "/api/server/inventory/requests";
marketplaceUrl = apiBase + "/api/marketplace";
bonusesUrl = apiBase + "/api/bonuses/effects";
serverIp = getConfig().getString("server-ip", getServerIp());
// Интервалы из конфига (в секундах)
int commandsInterval = getConfig().getInt("commands-interval-seconds", 5);
int inventoryInterval = getConfig().getInt("inventory-interval-seconds", 5);
int onlineUpdateInterval = getConfig().getInt("online-update-interval-seconds", 60);
int marketplaceInterval = getConfig().getInt("marketplace-interval-seconds", 3);
int bonusesInterval = getConfig().getInt("bonuses-interval-seconds", 10);
// Инициализируем HTTP клиент
httpClient = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_1_1)
@ -87,24 +101,55 @@ public final class popa extends JavaPlugin implements Listener {
// Запускаем планировщик для проверки команд
scheduler = Executors.newSingleThreadScheduledExecutor();
scheduler.scheduleAtFixedRate(this::checkAndExecuteCommands, 5, 5, TimeUnit.SECONDS);
// Запускаем планировщик для проверки запросов инвентаря
scheduler.scheduleAtFixedRate(this::checkInventoryRequests, 5, 5, TimeUnit.SECONDS);
// Отправка текущих онлайн-игроков при старте плагина
scheduler.scheduleAtFixedRate(this::sendOnlinePlayersUpdate, 60, 60, TimeUnit.SECONDS);
marketplaceUrl = getConfig().getString("api-base", "http://localhost:8000") + "/api/marketplace";
scheduler.scheduleAtFixedRate(this::checkMarketplaceOperations, 3, 3, TimeUnit.SECONDS);
// Проверка команд
scheduler.scheduleAtFixedRate(
this::checkAndExecuteCommands,
commandsInterval,
commandsInterval,
TimeUnit.SECONDS
);
bonusesUrl = getConfig().getString("api-base", "http://localhost:8000") + "/api/bonuses/effects";
scheduler.scheduleAtFixedRate(this::checkPlayerBonuses, 10, 10, TimeUnit.SECONDS);
// Проверка запросов инвентаря
scheduler.scheduleAtFixedRate(
this::checkInventoryRequests,
inventoryInterval,
inventoryInterval,
TimeUnit.SECONDS
);
// Отправка текущих онлайн-игроков
scheduler.scheduleAtFixedRate(
this::sendOnlinePlayersUpdate,
onlineUpdateInterval,
onlineUpdateInterval,
TimeUnit.SECONDS
);
// Маркетплейс
scheduler.scheduleAtFixedRate(
this::checkMarketplaceOperations,
marketplaceInterval,
marketplaceInterval,
TimeUnit.SECONDS
);
// Бонусы
scheduler.scheduleAtFixedRate(
this::checkPlayerBonuses,
bonusesInterval,
bonusesInterval,
TimeUnit.SECONDS
);
getLogger().info("PopaPlugin has been enabled!");
getLogger().info("API base: " + apiBase);
getLogger().info("API URL: " + apiUrl);
getLogger().info("Commands URL: " + commandsUrl);
getLogger().info("Inventory Requests URL: " + inventoryRequestsUrl);
getLogger().info("Marketplace URL: " + marketplaceUrl);
getLogger().info("Bonuses URL: " + bonusesUrl);
getLogger().info("Server IP: " + serverIp);
}
@ -383,6 +428,12 @@ public final class popa extends JavaPlugin implements Listener {
if (json.has("status") && "success".equals(json.get("status").getAsString())) {
if (json.has("inventory_requests")) {
JsonArray requests = json.getAsJsonArray("inventory_requests");
if (requests.size() == 0) {
// тишина, просто выходим
return;
}
getLogger().info("Найдено запросов инвентаря: " + requests.size());
for (JsonElement req : requests) {
@ -521,7 +572,7 @@ public final class popa extends JavaPlugin implements Listener {
*/
private void sendInventoryToBackend(String jsonPayload) {
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(getConfig().getString("api-base", "http://localhost:8000") + "/api/server/inventory/submit"))
.uri(URI.create(apiBase + "/api/server/inventory/submit"))
.version(HttpClient.Version.HTTP_1_1)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonPayload))

View File

@ -1,8 +1,12 @@
# Настройки API
api-base: "http://localhost:3001"
api-url: "http://localhost:3001/api/server/events"
commands-url: "http://localhost:3001/api/server/commands"
inventory-requests-url: "http://localhost:3001/api/server/inventory/requests"
# IP сервера (оставьте пустым для автоматического определения)
server-ip: "survival.hub.popa-popa.ru"
server-ip: "minecraft.hub.popa-popa.ru"
# Интервалы обновления (в секундах)
commands-interval-seconds: 5 # проверка команд
inventory-interval-seconds: 5 # запросы инвентаря
online-update-interval-seconds: 60 # отправка онлайна
marketplace-interval-seconds: 3 # операции маркета
bonuses-interval-seconds: 10 # проверка бонусов