1
0
mirror of https://github.com/GeyserMC/Floodgate.git synced 2025-12-19 14:59:20 +00:00

Finished news. Added git properties, closes GeyserMC/Floodgate#127

Co-authored-by: Konicai <71294714+Konicai@users.noreply.github.com>
This commit is contained in:
Tim203
2021-06-08 15:28:55 +02:00
parent a65d4e821d
commit efdd17d642
6 changed files with 132 additions and 4 deletions

View File

@@ -47,6 +47,8 @@ import org.geysermc.floodgate.link.PlayerLinkLoader;
import org.geysermc.floodgate.module.ConfigLoadedModule;
import org.geysermc.floodgate.module.PostInitializeModule;
import org.geysermc.floodgate.news.NewsChecker;
import org.geysermc.floodgate.util.FloodgateInfoHolder;
import org.geysermc.floodgate.util.GitProperties;
import org.geysermc.floodgate.util.PrefixCheckTask;
import org.geysermc.floodgate.util.TimeSyncerHolder;
@@ -60,6 +62,9 @@ public class FloodgatePlatform {
private FloodgateConfig config;
private Injector guice;
@Inject
private GitProperties properties;
@Inject
public FloodgatePlatform(
FloodgateApi api,
@@ -102,6 +107,11 @@ public class FloodgatePlatform {
TimeSyncerHolder.init();
InstanceHolder.set(api, link, this.injector, packetHandlers, handshakeHandlers, KEY);
// for Geyser dump
FloodgateInfoHolder.setGitProperties(properties.getProperties());
guice.getInstance(NewsChecker.class).start();
}
public boolean enable(Module... postInitializeModules) {
@@ -124,7 +134,6 @@ public class FloodgatePlatform {
PrefixCheckTask.checkAndExecuteDelayed(config, logger);
guice.getInstance(NewsChecker.class).start();
return true;
}

View File

@@ -61,6 +61,7 @@ import org.geysermc.floodgate.player.FloodgateHandshakeHandler;
import org.geysermc.floodgate.pluginmessage.PluginMessageManager;
import org.geysermc.floodgate.skin.SkinApplier;
import org.geysermc.floodgate.skin.SkinUploadManager;
import org.geysermc.floodgate.util.GitProperties;
import org.geysermc.floodgate.util.LanguageManager;
@RequiredArgsConstructor
@@ -175,11 +176,27 @@ public class CommonModule extends AbstractModule {
@Provides
@Singleton
public NewsChecker newsChecker(CommandUtil commandUtil, FloodgateLogger logger) {
public GitProperties gitProperties() {
return new GitProperties();
}
@Provides
@Singleton
public NewsChecker newsChecker(
CommandUtil commandUtil,
FloodgateLogger logger,
GitProperties properties) {
// will be loaded after enabling, so we can use the link instance in InstanceHolder
PlayerLink link = InstanceHolder.getPlayerLink();
logger.info(link.getName());
return new NewsChecker(link, commandUtil, logger, null, -1);
String branch = properties.getProperty("git.branch");
String build = properties.getProperty("git.build.number");
int buildNumber = -1;
if (build != null) {
buildNumber = Integer.parseInt(build);
}
return new NewsChecker(link, commandUtil, logger, branch, buildNumber);
}
@Provides

View File

@@ -173,7 +173,7 @@ public class NewsChecker {
return;
}
String fullDatabaseName = Constants.NEWS_PROJECT_NAME + link.getName();
String fullDatabaseName = Constants.NEWS_PROJECT_NAME + '/' + link.getName();
if (!fullDatabaseName.equals(item.getProject())) {
return;
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Floodgate
*/
package org.geysermc.floodgate.util;
import java.util.Properties;
public class GitProperties {
private final Properties properties;
public GitProperties() {
properties = Utils.readProperties("git.properties");
}
public Properties getProperties() {
return properties;
}
public Object get(Object key) {
return properties.get(key);
}
public String getProperty(String key) {
return properties.getProperty(key);
}
public String getProperty(String key, String defaultValue) {
return properties.getProperty(key, defaultValue);
}
public Object getOrDefault(Object key, Object defaultValue) {
return properties.getOrDefault(key, defaultValue);
}
}

View File

@@ -39,6 +39,7 @@ import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.regex.Pattern;
@@ -84,6 +85,16 @@ public class Utils {
return new BufferedReader(reader);
}
public static Properties readProperties(String resourceFile) {
Properties properties = new Properties();
try (InputStream is = Utils.class.getClassLoader().getResourceAsStream(resourceFile)) {
properties.load(is);
} catch (IOException e) {
e.printStackTrace();
}
return properties;
}
public static String getLocale(Locale locale) {
return locale.getLanguage() + "_" + locale.getCountry();
}

35
pom.xml
View File

@@ -98,6 +98,41 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>4.0.0</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
<format>properties</format>
<failOnNoGitDirectory>false</failOnNoGitDirectory>
<failOnUnableToExtractRepoInfo>false</failOnUnableToExtractRepoInfo>
<runOnlyOnce>false</runOnlyOnce>
<verbose>true</verbose>
<skipPoms>false</skipPoms>
<excludeProperties>
<excludeProperty>git.user.*</excludeProperty>
<excludeProperty>git.*.user.*</excludeProperty>
<excludeProperty>git.closest.*</excludeProperty>
<excludeProperty>git.commit.id.describe</excludeProperty>
<excludeProperty>git.commit.id.describe-short</excludeProperty>
<excludeProperty>git.commit.message.short</excludeProperty>
</excludeProperties>
<commitIdGenerationMode>flat</commitIdGenerationMode>
<gitDescribe>
<always>true</always>
</gitDescribe>
</configuration>
</plugin>
</plugins>
</build>