Skip to content

Commit

Permalink
Changed how post-enable messages work internally + minor other changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim203 committed Jul 11, 2022
1 parent 904c584 commit 41de367
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 171 deletions.
97 changes: 53 additions & 44 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Created by https://www.gitignore.io/api/git,java,maven,eclipse,netbeans,jetbrains+all
# Edit at https://www.gitignore.io/?templates=git,java,maven,eclipse,netbeans,jetbrains+all
# Created by https://www.gitignore.io/api/git,java,gradle,eclipse,netbeans,jetbrains+all
# Edit at https://www.gitignore.io/?templates=git,gradle,maven,eclipse,netbeans,jetbrains+all

### Eclipse ###
.metadata
Expand Down Expand Up @@ -52,22 +52,19 @@ local.properties

# Annotation Processing
.apt_generated/
.apt_generated_test/

# Scala IDE specific (Scala & Java development for Eclipse)
.cache-main
.scala_dependencies
.worksheet

### Eclipse Patch ###
# Eclipse Core
.project

# JDT-specific (Eclipse Java Development Tools)
.classpath

# Annotation Processing
.apt_generated
# Uncomment this line if you wish to ignore the project description file.
# Typically, this file would be tracked if it contains build/dependency configurations:
#.project

### Eclipse Patch ###
# Spring Boot Tooling
.sts4-cache/

### Git ###
Expand Down Expand Up @@ -109,9 +106,10 @@ local.properties

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*

### JetBrains+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
Expand All @@ -121,6 +119,9 @@ hs_err_pid*
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

Expand All @@ -141,11 +142,14 @@ hs_err_pid*
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
.idea/artifacts
.idea/compiler.xml
.idea/jarRepositories.xml
.idea/modules.xml
.idea/*.iml
.idea/modules
*.iml
*.ipr

# CMake
cmake-build-*/
Expand All @@ -168,6 +172,9 @@ atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml

# SonarLint plugin
.idea/sonarlint/

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
Expand All @@ -181,32 +188,13 @@ fabric.properties
.idea/caches/build_file_checksums.ser

### JetBrains+all Patch ###
# Ignores the whole .idea folder and all .iml files
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
# Ignore everything but code style settings and run configurations
# that are supposed to be shared within teams.

.idea/
.idea/*

# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023

*.iml
modules.xml
.idea/misc.xml
*.ipr

# Sonarlint plugin
.idea/sonarlint

### Maven ###
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar
!.idea/codeStyles
!.idea/runConfigurations

### NetBeans ###
**/nbproject/private/
Expand All @@ -218,8 +206,29 @@ dist/
nbdist/
.nb-gradle/

# End of https://www.gitignore.io/api/git,java,maven,eclipse,netbeans,jetbrains+all
gradle/
**/.gradle/
### Gradle ###
.gradle
**/build/
!src/**/build/

# Ignore Gradle GUI config
gradle-app.setting

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Avoid ignore Gradle wrappper properties
!gradle-wrapper.properties

# Cache of project
.gradletasknamecache

# Eclipse Gradle plugin generated files
# Eclipse Core
.project
# JDT-specific (Eclipse Java Development Tools)
.classpath

# End of https://www.gitignore.io/api/git,java,gradle,eclipse,netbeans,jetbrains+all

/core/src/main/resources/languages/
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ public enum LinkRequestResult {
* An unknown error encountered while creating / verifying the link request.
*/
UNKNOWN_ERROR,
/**
* @deprecated this result isn't used. Instead the link code is returned
*/
REQUEST_CREATED,
/**
* The specified bedrock username is already linked to a Java account.
*/
Expand Down
12 changes: 6 additions & 6 deletions core/src/main/java/org/geysermc/floodgate/FloodgatePlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,21 @@
import org.geysermc.floodgate.api.handshake.HandshakeHandlers;
import org.geysermc.floodgate.api.inject.PlatformInjector;
import org.geysermc.floodgate.api.link.PlayerLink;
import org.geysermc.floodgate.api.logger.FloodgateLogger;
import org.geysermc.floodgate.api.packet.PacketHandlers;
import org.geysermc.floodgate.config.FloodgateConfig;
import org.geysermc.floodgate.event.PostEnableEvent;
import org.geysermc.floodgate.event.ShutdownEvent;
import org.geysermc.floodgate.link.PlayerLinkLoader;
import org.geysermc.floodgate.module.PostInitializeModule;
import org.geysermc.floodgate.news.NewsChecker;
import org.geysermc.floodgate.util.Metrics;
import org.geysermc.floodgate.util.PrefixCheckTask;
import org.geysermc.floodgate.util.PostEnableMessages;

public class FloodgatePlatform {
private static final UUID KEY = UUID.randomUUID();
@Inject private FloodgateApi api;
@Inject private PlatformInjector injector;

@Inject private FloodgateLogger logger;

@Inject private FloodgateConfig config;
@Inject private Injector guice;

Expand All @@ -77,9 +75,11 @@ public void enable(Module... postInitializeModules) throws RuntimeException {

this.guice = guice.createChildInjector(new PostInitializeModule(postInitializeModules));

PrefixCheckTask.checkAndExecuteDelayed(config, logger);

//todo add some kind of auto-load, as this looks kinda weird
guice.getInstance(PostEnableMessages.class);
guice.getInstance(Metrics.class);

guice.getInstance(PubSubSupport.class).publish(new PostEnableEvent());
}

public void disable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
@Getter
@RequiredArgsConstructor
public final class ConfigLoader {
private final Path dataFolder;
private final Path dataDirectory;
private final Class<? extends FloodgateConfig> configClass;

private final KeyProducer keyProducer;
Expand All @@ -62,7 +62,7 @@ public <T extends FloodgateConfig> T load() {

ConfigUtilities utilities =
ConfigUtilities.builder()
.fileCodec(PathFileCodec.of(dataFolder))
.fileCodec(PathFileCodec.of(dataDirectory))
.configFile("config.yml")
.templateReader(ResourceTemplateReader.of(getClass()))
.template(templateFile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,17 @@ public class FloodgateConfig implements GenericPostInitializeCallback<ConfigLoad
private boolean debug;
private int configVersion;


private Key key;
private String rawUsernamePrefix;

public boolean isProxy() {
return this instanceof ProxyFloodgateConfig;
}

@Override
public CallbackResult postInitialize(ConfigLoader loader) {
Path keyPath = loader.getDataFolder().resolve(getKeyFileName());
Path keyPath = loader.getDataDirectory().resolve(getKeyFileName());

// don't assume that the key always exists with the existence of a config
if (!Files.exists(keyPath)) {
Expand All @@ -74,6 +76,14 @@ public CallbackResult postInitialize(ConfigLoader loader) {
} catch (IOException exception) {
return CallbackResult.failed(exception.getMessage());
}

rawUsernamePrefix = usernamePrefix;

// Java usernames can't be longer than 16 chars
if (usernamePrefix.length() >= 16) {
usernamePrefix = ".";
}

return CallbackResult.ok();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2019-2022 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.event;

public class PostEnableEvent {
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@
import com.google.common.base.Joiner;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Locale;
Expand Down Expand Up @@ -117,21 +113,11 @@ public boolean loadLocale(String locale) {
return true;
}

InputStream localeStream = LanguageManager.class.getClassLoader().getResourceAsStream(
"languages/texts/" + formatLocale + ".properties");
Properties properties =
Utils.readProperties("languages/texts/" + formatLocale + ".properties");

// load the locale
if (localeStream != null) {
Properties localeProp = new Properties();

try (Reader reader = new InputStreamReader(localeStream, StandardCharsets.UTF_8)) {
localeProp.load(reader);
} catch (Exception e) {
throw new AssertionError("Failed to load Floodgate locale", e);
}

// insert the locale into the mappings
localeMappings.put(formatLocale, localeProp);
if (properties != null) {
localeMappings.put(formatLocale, properties);
return true;
}

Expand Down
Loading

0 comments on commit 41de367

Please sign in to comment.