Skip to content

Commit

Permalink
Don't look up git properties for news handler in development
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy committed Jun 15, 2021
1 parent 469421c commit 096c707
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
38 changes: 26 additions & 12 deletions connector/src/main/java/org/geysermc/connector/GeyserConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,20 @@ private GeyserConnector(PlatformType platformType, GeyserBootstrap bootstrap) {

String branch = "unknown";
int buildNumber = -1;
try {
Properties gitProperties = new Properties();
gitProperties.load(FileUtils.getResource("git.properties"));
branch = gitProperties.getProperty("git.branch");
String build = gitProperties.getProperty("git.build.number");
if (build != null) {
buildNumber = Integer.parseInt(build);
if (this.isProductionEnvironment()) {
try {
Properties gitProperties = new Properties();
gitProperties.load(FileUtils.getResource("git.properties"));
branch = gitProperties.getProperty("git.branch");
String build = gitProperties.getProperty("git.build.number");
if (build != null) {
buildNumber = Integer.parseInt(build);
}
} catch (Throwable e) {
logger.error("Failed to read git.properties", e);
}
} catch (Throwable e) {
logger.error("Failed to read git.properties", e);
} else {
logger.debug("Not getting git properties for the news handler as we are in a development environment.");
}
newsHandler = new NewsHandler(branch, buildNumber);

Expand Down Expand Up @@ -526,17 +530,27 @@ public TimeSyncer getTimeSyncer() {
return timeSyncer;
}

/**
* Returns false if this Geyser instance is running in an IDE. This only needs to be used in cases where files
* expected to be in a jarfile are not present.
*
* @return true if the version number is not 'DEV'.
*/
public boolean isProductionEnvironment() {
//noinspection ConstantConditions - changes in production
return !"DEV".equals(GeyserConnector.VERSION);
}

/**
* Whether to use XML reflections in the jar or manually find the reflections.
* Will return true if the version number is not 'DEV' and the platform is not Fabric.
* Will return true and the platform is not Fabric.
* On Fabric - it complains about being unable to create a default XMLReader.
* On other platforms this should only be true in compiled jars.
*
* @return whether to use XML reflections
*/
public boolean useXmlReflections() {
//noinspection ConstantConditions
return !this.getPlatformType().equals(PlatformType.FABRIC) && !"DEV".equals(GeyserConnector.VERSION);
return !this.getPlatformType().equals(PlatformType.FABRIC) && isProductionEnvironment();
}

public static GeyserConnector getInstance() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

package org.geysermc.connector.command.defaults;

import com.github.steveice10.mc.protocol.MinecraftConstants;
import com.nukkitx.protocol.bedrock.BedrockPacketCodec;
import org.geysermc.common.PlatformType;
import org.geysermc.connector.GeyserConnector;
Expand Down Expand Up @@ -67,8 +66,7 @@ public void execute(GeyserSession session, CommandSender sender, String[] args)
sender.sendMessage(LanguageUtils.getPlayerLocaleString("geyser.commands.version.version", sender.getLocale(), GeyserConnector.NAME, GeyserConnector.VERSION, GeyserConnector.MINECRAFT_VERSION, bedrockVersions));

// Disable update checking in dev mode and for players in Geyser Standalone
//noinspection ConstantConditions - changes in production
if (!GeyserConnector.VERSION.equals("DEV") && !(!sender.isConsole() && connector.getPlatformType() == PlatformType.STANDALONE)) {
if (GeyserConnector.getInstance().isProductionEnvironment() && !(!sender.isConsole() && connector.getPlatformType() == PlatformType.STANDALONE)) {
sender.sendMessage(LanguageUtils.getPlayerLocaleString("geyser.commands.version.checking", sender.getLocale()));
try {
Properties gitProp = new Properties();
Expand Down

0 comments on commit 096c707

Please sign in to comment.