forked from MinecraftUtilities/Backend
fix the fixy
This commit is contained in:
parent
cb9181010a
commit
b3e560d1e2
@ -0,0 +1,17 @@
|
|||||||
|
package xyz.mcutils.backend.common;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public final class EnvironmentUtils {
|
||||||
|
/**
|
||||||
|
* Is the app running in a production environment?
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
private static final boolean production;
|
||||||
|
static { // Are we running on production?
|
||||||
|
String env = System.getenv("ENVIRONMENT");
|
||||||
|
production = env != null && (env.equals("production"));
|
||||||
|
}
|
||||||
|
}
|
@ -23,18 +23,9 @@ public class Config {
|
|||||||
@Value("${public-url}")
|
@Value("${public-url}")
|
||||||
private String webPublicUrl;
|
private String webPublicUrl;
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether the server is in production mode.
|
|
||||||
*/
|
|
||||||
private boolean production = false;
|
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
INSTANCE = this;
|
INSTANCE = this;
|
||||||
|
|
||||||
String environmentProperty = environment.getProperty("ENVIRONMENT", "development");
|
|
||||||
production = environmentProperty.equalsIgnoreCase("production"); // Set the production mode
|
|
||||||
log.info("Server is running in {} mode", production ? "production" : "development");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
@ -6,6 +6,7 @@ import com.influxdb.spring.influx.InfluxDB2AutoConfiguration;
|
|||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import xyz.mcutils.backend.common.EnvironmentUtils;
|
||||||
import xyz.mcutils.backend.common.Timer;
|
import xyz.mcutils.backend.common.Timer;
|
||||||
import xyz.mcutils.backend.config.Config;
|
import xyz.mcutils.backend.config.Config;
|
||||||
import xyz.mcutils.backend.repository.mongo.MetricsRepository;
|
import xyz.mcutils.backend.repository.mongo.MetricsRepository;
|
||||||
@ -56,7 +57,7 @@ public class MetricService {
|
|||||||
collectorEnabled.put(metric, metric.isCollector());
|
collectorEnabled.put(metric, metric.isCollector());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Config.INSTANCE.isProduction()) {
|
if (EnvironmentUtils.isProduction()) {
|
||||||
// Load the metrics from Redis
|
// Load the metrics from Redis
|
||||||
loadMetrics();
|
loadMetrics();
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ import org.springframework.http.ResponseEntity;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import xyz.mcutils.backend.Main;
|
import xyz.mcutils.backend.Main;
|
||||||
import xyz.mcutils.backend.common.Endpoint;
|
import xyz.mcutils.backend.common.Endpoint;
|
||||||
|
import xyz.mcutils.backend.common.EnvironmentUtils;
|
||||||
import xyz.mcutils.backend.common.ExpiringSet;
|
import xyz.mcutils.backend.common.ExpiringSet;
|
||||||
import xyz.mcutils.backend.common.WebRequest;
|
import xyz.mcutils.backend.common.WebRequest;
|
||||||
import xyz.mcutils.backend.config.Config;
|
import xyz.mcutils.backend.config.Config;
|
||||||
@ -190,7 +191,7 @@ public class MojangService {
|
|||||||
public CachedEndpointStatus getMojangApiStatus() {
|
public CachedEndpointStatus getMojangApiStatus() {
|
||||||
log.info("Getting Mojang API status");
|
log.info("Getting Mojang API status");
|
||||||
Optional<CachedEndpointStatus> endpointStatus = mojangEndpointStatusRepository.findById(MOJANG_ENDPOINT_STATUS_KEY);
|
Optional<CachedEndpointStatus> endpointStatus = mojangEndpointStatusRepository.findById(MOJANG_ENDPOINT_STATUS_KEY);
|
||||||
if (endpointStatus.isPresent() && Config.INSTANCE.isProduction()) {
|
if (endpointStatus.isPresent() && EnvironmentUtils.isProduction()) {
|
||||||
log.info("Got cached Mojang API status");
|
log.info("Got cached Mojang API status");
|
||||||
return endpointStatus.get();
|
return endpointStatus.get();
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,7 @@ package xyz.mcutils.backend.service;
|
|||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import xyz.mcutils.backend.common.ImageUtils;
|
import xyz.mcutils.backend.common.*;
|
||||||
import xyz.mcutils.backend.common.PlayerUtils;
|
|
||||||
import xyz.mcutils.backend.common.Tuple;
|
|
||||||
import xyz.mcutils.backend.common.UUIDUtils;
|
|
||||||
import xyz.mcutils.backend.config.Config;
|
import xyz.mcutils.backend.config.Config;
|
||||||
import xyz.mcutils.backend.exception.impl.BadRequestException;
|
import xyz.mcutils.backend.exception.impl.BadRequestException;
|
||||||
import xyz.mcutils.backend.exception.impl.MojangAPIRateLimitException;
|
import xyz.mcutils.backend.exception.impl.MojangAPIRateLimitException;
|
||||||
@ -67,7 +64,7 @@ public class PlayerService {
|
|||||||
((UniquePlayerLookupsMetric) metricService.getMetric(UniquePlayerLookupsMetric.class)).addLookup(id); // Add the lookup to the unique player lookups
|
((UniquePlayerLookupsMetric) metricService.getMetric(UniquePlayerLookupsMetric.class)).addLookup(id); // Add the lookup to the unique player lookups
|
||||||
|
|
||||||
Optional<CachedPlayer> cachedPlayer = playerCacheRepository.findById(uuid);
|
Optional<CachedPlayer> cachedPlayer = playerCacheRepository.findById(uuid);
|
||||||
if (cachedPlayer.isPresent() && Config.INSTANCE.isProduction()) { // Return the cached player if it exists
|
if (cachedPlayer.isPresent() && EnvironmentUtils.isProduction()) { // Return the cached player if it exists
|
||||||
log.info("Player {} is cached", id);
|
log.info("Player {} is cached", id);
|
||||||
return cachedPlayer.get();
|
return cachedPlayer.get();
|
||||||
}
|
}
|
||||||
@ -107,7 +104,7 @@ public class PlayerService {
|
|||||||
log.info("Getting UUID from username: {}", username);
|
log.info("Getting UUID from username: {}", username);
|
||||||
String id = username.toUpperCase();
|
String id = username.toUpperCase();
|
||||||
Optional<CachedPlayerName> cachedPlayerName = playerNameCacheRepository.findById(id);
|
Optional<CachedPlayerName> cachedPlayerName = playerNameCacheRepository.findById(id);
|
||||||
if (cachedPlayerName.isPresent() && Config.INSTANCE.isProduction()) {
|
if (cachedPlayerName.isPresent() && EnvironmentUtils.isProduction()) {
|
||||||
return cachedPlayerName.get();
|
return cachedPlayerName.get();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -157,7 +154,7 @@ public class PlayerService {
|
|||||||
Optional<CachedPlayerSkinPart> cache = playerSkinPartCacheRepository.findById(key);
|
Optional<CachedPlayerSkinPart> cache = playerSkinPartCacheRepository.findById(key);
|
||||||
|
|
||||||
// The skin part is cached
|
// The skin part is cached
|
||||||
if (cache.isPresent() && Config.INSTANCE.isProduction()) {
|
if (cache.isPresent() && EnvironmentUtils.isProduction()) {
|
||||||
log.info("Skin part {} for player {} is cached", name, player.getUniqueId());
|
log.info("Skin part {} for player {} is cached", name, player.getUniqueId());
|
||||||
return cache.get();
|
return cache.get();
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import xyz.mcutils.backend.common.DNSUtils;
|
import xyz.mcutils.backend.common.DNSUtils;
|
||||||
import xyz.mcutils.backend.common.EnumUtils;
|
import xyz.mcutils.backend.common.EnumUtils;
|
||||||
|
import xyz.mcutils.backend.common.EnvironmentUtils;
|
||||||
import xyz.mcutils.backend.config.Config;
|
import xyz.mcutils.backend.config.Config;
|
||||||
import xyz.mcutils.backend.exception.impl.BadRequestException;
|
import xyz.mcutils.backend.exception.impl.BadRequestException;
|
||||||
import xyz.mcutils.backend.exception.impl.ResourceNotFoundException;
|
import xyz.mcutils.backend.exception.impl.ResourceNotFoundException;
|
||||||
@ -69,7 +70,7 @@ public class ServerService {
|
|||||||
|
|
||||||
// Check if the server is cached
|
// Check if the server is cached
|
||||||
Optional<CachedMinecraftServer> cached = serverCacheRepository.findById(key);
|
Optional<CachedMinecraftServer> cached = serverCacheRepository.findById(key);
|
||||||
if (cached.isPresent() && Config.INSTANCE.isProduction()) {
|
if (cached.isPresent() && EnvironmentUtils.isProduction()) {
|
||||||
log.info("Server {}:{} is cached", hostname, port);
|
log.info("Server {}:{} is cached", hostname, port);
|
||||||
return cached.get();
|
return cached.get();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user