Update to spigot 1.20.5, bump mvn plugin version, require jvm 17, require mvn 3.9, require spigot 1.19, use the spigot runtime dependency download system, use the official maxmind geoip database parser

This commit is contained in:
Gabriele C.
2024-04-26 01:29:21 +02:00
parent a14df80a87
commit 1b69abd09e
7 changed files with 277 additions and 340 deletions
@@ -32,7 +32,7 @@ import static fr.xephi.authme.settings.properties.EmailSettings.RECALL_PLAYERS;
*/
public class OnStartupTasks {
private static ConsoleLogger consoleLogger = ConsoleLoggerFactory.get(OnStartupTasks.class);
private static final ConsoleLogger consoleLogger = ConsoleLoggerFactory.get(OnStartupTasks.class);
@Inject
private DataSource dataSource;
@@ -53,6 +53,8 @@ public class OnStartupTasks {
* @param settings the settings
*/
public static void sendMetrics(AuthMe plugin, Settings settings) {
// We do not relocate as the library is downloaded at runtime
System.setProperty("bstats.relocatecheck", "false");
final Metrics metrics = new Metrics(plugin, 164);
metrics.addCustomChart(new SimplePie("messages_language",
@@ -109,6 +111,6 @@ public class OnStartupTasks {
}
});
}
}, 1, TICKS_PER_MINUTE * settings.getProperty(EmailSettings.DELAY_RECALL));
}, 1, (long) TICKS_PER_MINUTE * settings.getProperty(EmailSettings.DELAY_RECALL));
}
}
@@ -34,14 +34,13 @@ import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.List;
class InventoryPacketAdapter extends PacketAdapter {
private static final int PLAYER_INVENTORY = 0;
// http://wiki.vg/Inventory#Inventory (0-4 crafting, 5-8 armor, 9-35 main inventory, 36-44 hotbar, 45 off hand)
// http://wiki.vg/Inventory#Inventory (0-4 crafting, 5-8 armor, 9-35 main inventory, 36-44 hotbar, 45 offhand)
// +1 because an index starts with 0
private static final int CRAFTING_SIZE = 5;
private static final int ARMOR_SIZE = 4;
@@ -116,8 +115,8 @@ class InventoryPacketAdapter extends PacketAdapter {
try {
protocolManager.sendServerPacket(player, inventoryPacket, false);
} catch (InvocationTargetException invocationExc) {
logger.logException("Error during sending blank inventory", invocationExc);
} catch (Throwable throwable) {
logger.logException("Error during sending blank inventory", throwable);
}
}
}
@@ -4,12 +4,12 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.common.hash.HashCode;
import com.google.common.hash.HashFunction;
import com.google.common.hash.Hashing;
import com.maxmind.db.GeoIp2Provider;
import com.maxmind.db.Reader;
import com.maxmind.db.CHMCache;
import com.maxmind.db.Reader.FileMode;
import com.maxmind.db.cache.CHMCache;
import com.maxmind.db.model.Country;
import com.maxmind.db.model.CountryResponse;
import com.maxmind.geoip2.DatabaseReader;
import com.maxmind.geoip2.exception.GeoIp2Exception;
import com.maxmind.geoip2.model.AbstractCountryResponse;
import com.maxmind.geoip2.record.Country;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.initialization.DataFolder;
import fr.xephi.authme.output.ConsoleLoggerFactory;
@@ -61,21 +61,21 @@ public class GeoIpService {
private final BukkitService bukkitService;
private final Settings settings;
private GeoIp2Provider databaseReader;
private DatabaseReader databaseReader;
private volatile boolean downloading;
@Inject
GeoIpService(@DataFolder File dataFolder, BukkitService bukkitService, Settings settings) {
public GeoIpService(@DataFolder File dataFolder, BukkitService bukkitService, Settings settings) {
this.bukkitService = bukkitService;
this.dataFile = dataFolder.toPath().resolve(DATABASE_FILE);
this.settings = settings;
// Fires download of recent data or the initialization of the look up service
// Fires download of recent data or the initialization of the look-up service
isDataAvailable();
}
@VisibleForTesting
GeoIpService(@DataFolder File dataFolder, BukkitService bukkitService, Settings settings, GeoIp2Provider reader) {
GeoIpService(@DataFolder File dataFolder, BukkitService bukkitService, Settings settings, DatabaseReader reader) {
this.bukkitService = bukkitService;
this.settings = settings;
this.dataFile = dataFolder.toPath().resolve(DATABASE_FILE);
@@ -105,7 +105,7 @@ public class GeoIpService {
if (Duration.between(lastModifiedTime.toInstant(), Instant.now()).toDays() <= UPDATE_INTERVAL_DAYS) {
startReading();
// don't fire the update task - we are up to date
// don't fire the update task - we are up-to-date
return true;
} else {
logger.debug("GEO IP database is older than " + UPDATE_INTERVAL_DAYS + " Days");
@@ -149,6 +149,7 @@ public class GeoIpService {
extractDatabase(downloadFile, tempFile);
// MD5 checksum verification
//noinspection deprecation
verifyChecksum(Hashing.md5(), tempFile, expectedChecksum);
Files.copy(tempFile, dataFile, StandardCopyOption.REPLACE_EXISTING);
@@ -170,7 +171,7 @@ public class GeoIpService {
}
private void startReading() throws IOException {
databaseReader = new Reader(dataFile.toFile(), FileMode.MEMORY, new CHMCache());
databaseReader = new DatabaseReader.Builder(dataFile.toFile()).withCache(new CHMCache()).fileMode(FileMode.MEMORY).build();
logger.info(LICENSE);
// clear downloading flag, because we now have working reader instance
@@ -178,7 +179,7 @@ public class GeoIpService {
}
/**
* Downloads the archive to the destination file if it's newer than the locally version.
* Downloads the archive to the destination file if it's newer than the local version.
*
* @param lastModified modification timestamp of the already present file
* @param destination save file
@@ -220,7 +221,7 @@ public class GeoIpService {
}
/**
* Downloads the archive to the destination file if it's newer than the locally version.
* Downloads the archive to the destination file if it's newer than the local version.
*
* @param destination save file
* @return null if no updates were found, the MD5 hash of the downloaded archive if successful
@@ -320,11 +321,11 @@ public class GeoIpService {
InetAddress address = InetAddress.getByName(ip);
// Reader.getCountry() can be null for unknown addresses
return Optional.ofNullable(databaseReader.getCountry(address)).map(CountryResponse::getCountry);
return Optional.ofNullable(databaseReader.country(address)).map(AbstractCountryResponse::getCountry);
} catch (UnknownHostException e) {
// Ignore invalid ip addresses
// Legacy GEO IP Database returned a unknown country object with Country-Code: '--' and Country-Name: 'N/A'
} catch (IOException ioEx) {
// Legacy GEO IP Database returned an unknown country object with Country-Code: '--' and Country-Name: 'N/A'
} catch (GeoIp2Exception | IOException ioEx) {
logger.logException("Cannot lookup country for " + ip + " at GEO IP database", ioEx);
}
+21 -1
View File
@@ -1,10 +1,13 @@
# noinspection YAMLSchemaValidation
name: ${pluginDescription.name}
# noinspection YAMLSchemaValidation
authors: [${pluginDescription.authors}]
website: ${project.url}
description: ${project.description}
# noinspection YAMLSchemaValidation
main: ${pluginDescription.main}
version: ${pluginDescription.version}
api-version: 1.13
api-version: 1.19
softdepend:
- Vault
- LuckPerms
@@ -15,6 +18,23 @@ softdepend:
- Essentials
- EssentialsSpawn
- ProtocolLib
libraries:
- ch.jalu:injector:${dependencies.injector.version}
- net.ricecode:string-similarity:${dependencies.string-similarity.version}
- com.maxmind.geoip2:geoip2:${dependencies.geoip2.version}
- javatar:javatar:${dependencies.javatar.version}
- org.apache.commons:commons-email:${dependencies.commons-email.version}
- com.zaxxer:HikariCP:${dependencies.hikaricp.version}
- org.slf4j:slf4j-simple:${dependencies.slf4j.version}
- com.mysql:mysql-connector-j:${dependencies.mysql-connector-j.version}
- org.mariadb.jdbc:mariadb-java-client:${dependencies.mariadb-java-client.version}
- org.postgresql:postgresql:${dependencies.postgresql.version}
- de.rtner:PBKDF2:${dependencies.pbkdf2.version}
- de.mkammerer:argon2-jvm-nolibs:${dependencies.argon2-jvm-nolibs.version}
- at.favre.lib:bcrypt:${dependencies.bcrypt.version}
- com.warrenstrange:googleauth:${dependencies.googleauth.version}
- ch.jalu:configme:${dependencies.configme.version}
- org.bstats:bstats-bukkit:${dependencies.bstats.version}
commands:
authme:
description: AuthMe op commands
@@ -18,6 +18,7 @@ import org.mockito.Mock;
import java.util.logging.Logger;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.both;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
@@ -25,7 +26,6 @@ import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.sameInstance;
import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
@@ -40,6 +40,7 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
@RunWith(DelayedInjectionRunner.class)
public class LimboPersistenceTest {
@SuppressWarnings("unused")
@InjectDelayed
private LimboPersistence limboPersistence;
@@ -59,7 +60,7 @@ public class LimboPersistenceTest {
public void setUpMocks() {
given(settings.getProperty(LimboSettings.LIMBO_PERSISTENCE_TYPE)).willReturn(LimboPersistenceType.DISABLED);
given(handlerFactory.newInstance(any(Class.class)))
.willAnswer(invocation -> mock(invocation.getArgument(0)));
.willAnswer(invocation -> mock((Class<?>) invocation.getArgument(0)));
}
@Test
@@ -1,13 +1,12 @@
package fr.xephi.authme.service;
import com.maxmind.db.GeoIp2Provider;
import com.maxmind.db.model.Country;
import com.maxmind.db.model.CountryResponse;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import com.maxmind.geoip2.DatabaseReader;
import com.maxmind.geoip2.model.CountryResponse;
import com.maxmind.geoip2.record.Country;
import fr.xephi.authme.settings.Settings;
import org.junit.Before;
import org.junit.Rule;
@@ -17,11 +16,11 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
@@ -33,10 +32,9 @@ import static org.mockito.Mockito.verify;
public class GeoIpServiceTest {
private GeoIpService geoIpService;
private File dataFolder;
@Mock
private GeoIp2Provider lookupService;
private DatabaseReader lookupService;
@Mock
private BukkitService bukkitService;
@@ -49,7 +47,7 @@ public class GeoIpServiceTest {
@Before
public void initializeGeoLiteApi() throws IOException {
dataFolder = temporaryFolder.newFolder();
File dataFolder = temporaryFolder.newFolder();
geoIpService = new GeoIpService(dataFolder, bukkitService, settings, lookupService);
}
@@ -64,14 +62,14 @@ public class GeoIpServiceTest {
CountryResponse response = mock(CountryResponse.class);
given(response.getCountry()).willReturn(country);
given(lookupService.getCountry(ip)).willReturn(response);
given(lookupService.country(ip)).willReturn(response);
// when
String result = geoIpService.getCountryCode(ip.getHostAddress());
// then
assertThat(result, equalTo(countryCode));
verify(lookupService).getCountry(ip);
verify(lookupService).country(ip);
}
@Test
@@ -84,7 +82,7 @@ public class GeoIpServiceTest {
// then
assertThat(result, equalTo("LOCALHOST"));
verify(lookupService, never()).getCountry(any());
verify(lookupService, never()).country(any());
}
@Test
@@ -98,14 +96,14 @@ public class GeoIpServiceTest {
CountryResponse response = mock(CountryResponse.class);
given(response.getCountry()).willReturn(country);
given(lookupService.getCountry(ip)).willReturn(response);
given(lookupService.country(ip)).willReturn(response);
// when
String result = geoIpService.getCountryName(ip.getHostAddress());
// then
assertThat(result, equalTo(countryName));
verify(lookupService).getCountry(ip);
verify(lookupService).country(ip);
}
@Test
@@ -118,6 +116,6 @@ public class GeoIpServiceTest {
// then
assertThat(result, equalTo("LocalHost"));
verify(lookupService, never()).getCountry(ip);
verify(lookupService, never()).country(ip);
}
}