-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix loading as an extension and config refactor
- Loading branch information
Showing
9 changed files
with
425 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 26 additions & 84 deletions
110
src/main/java/com/rtm516/FloodgatePlaceholders/Config.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,111 +1,53 @@ | ||
package com.rtm516.FloodgatePlaceholders; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; | ||
import lombok.Getter; | ||
public interface Config { | ||
boolean isSpecificDeviceDescriptors(); | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
DevicePlaceholders getDevice(); | ||
|
||
@Getter | ||
public class Config { | ||
@JsonProperty(value = "specific-device-descriptors") | ||
private boolean specificDeviceDescriptors; | ||
GenericPlaceholders getLocale(); | ||
|
||
@JsonProperty(value = "device") | ||
private DevicePlaceholders device; | ||
GenericPlaceholders getVersion(); | ||
|
||
@JsonProperty(value = "locale") | ||
private GenericPlaceholders locale; | ||
GenericPlaceholders getXboxUsername(); | ||
|
||
@JsonProperty(value = "version") | ||
private GenericPlaceholders version; | ||
GenericPlaceholders getXboxXuid(); | ||
|
||
@JsonProperty(value = "xbox-username") | ||
private GenericPlaceholders xboxUsername; | ||
interface DevicePlaceholders { | ||
String getJava(); | ||
|
||
@JsonProperty(value = "xbox-xuid") | ||
private GenericPlaceholders xboxXuid; | ||
String getGeneric(); | ||
|
||
@Getter | ||
public static class DevicePlaceholders { | ||
@JsonProperty("java") | ||
private String java; | ||
String getUnknown(); | ||
|
||
@JsonProperty("generic") | ||
private String generic; | ||
String getGoogle(); | ||
|
||
@JsonProperty("unknown") | ||
private String unknown; | ||
String getIOS(); | ||
|
||
@JsonProperty("google") | ||
private String google; | ||
String getOSX(); | ||
|
||
@JsonProperty("ios") | ||
private String iOS; | ||
String getAmazon(); | ||
|
||
@JsonProperty("osx") | ||
private String OSX; | ||
String getGearVR(); | ||
|
||
@JsonProperty("amazon") | ||
private String amazon; | ||
String getHololens(); | ||
|
||
@JsonProperty("gearvr") | ||
private String gearVR; | ||
String getUwp(); | ||
|
||
@JsonProperty("hololens") | ||
private String hololens; | ||
String getWin32(); | ||
|
||
@JsonProperty("uwp") | ||
private String uwp; | ||
String getDedicated(); | ||
|
||
@JsonProperty("win32") | ||
private String win32; | ||
String getPs4(); | ||
|
||
@JsonProperty("dedicated") | ||
private String dedicated; | ||
String getNX(); | ||
|
||
@JsonProperty("ps4") | ||
private String ps4; | ||
|
||
@JsonProperty("nx") | ||
private String NX; | ||
|
||
@JsonProperty("xbox") | ||
private String xbox; | ||
String getXbox(); | ||
} | ||
|
||
@Getter | ||
public static class GenericPlaceholders { | ||
@JsonProperty("found") | ||
private String found; | ||
|
||
@JsonProperty("none") | ||
private String none; | ||
} | ||
interface GenericPlaceholders { | ||
String getFound(); | ||
|
||
public static Config load(Logger logger, Path configPath) { | ||
Config config = null; | ||
try { | ||
try { | ||
if (!configPath.toFile().exists()) | ||
Files.copy(Config.class.getClassLoader().getResourceAsStream("config.yml"), configPath); | ||
} catch (Exception e) { | ||
logger.log(Level.SEVERE, "Error while creating config.yml", e); | ||
} | ||
|
||
config = new ObjectMapper(new YAMLFactory()).readValue(Files.readAllBytes(configPath), Config.class); | ||
} catch (Exception e) { | ||
logger.log(Level.SEVERE, "Error while loading config.yml", e); | ||
} | ||
|
||
if (config == null) { | ||
throw new RuntimeException("Failed to load config file! Try to delete the data folder of FloodgatePlaceholders"); | ||
} | ||
|
||
return config; | ||
String getNone(); | ||
} | ||
} |
146 changes: 146 additions & 0 deletions
146
src/main/java/com/rtm516/FloodgatePlaceholders/ExpansionConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
package com.rtm516.FloodgatePlaceholders; | ||
|
||
public class ExpansionConfig implements Config { | ||
private Placeholder expansion; | ||
|
||
public ExpansionConfig(Placeholder expansion) { | ||
this.expansion = expansion; | ||
} | ||
|
||
@Override | ||
public boolean isSpecificDeviceDescriptors() { | ||
return (Boolean) expansion.get("specific-device-descriptors", true); | ||
} | ||
|
||
@Override | ||
public DevicePlaceholders getDevice() { | ||
return new ExpansionDevicePlaceholders(this, "device"); | ||
} | ||
|
||
@Override | ||
public GenericPlaceholders getLocale() { | ||
return new ExpansionGenericPlaceholders(this, "locale"); | ||
} | ||
|
||
@Override | ||
public GenericPlaceholders getVersion() { | ||
return new ExpansionGenericPlaceholders(this, "version"); | ||
} | ||
|
||
@Override | ||
public GenericPlaceholders getXboxUsername() { | ||
return new ExpansionGenericPlaceholders(this, "xbox-username"); | ||
} | ||
|
||
@Override | ||
public GenericPlaceholders getXboxXuid() { | ||
return new ExpansionGenericPlaceholders(this, "xbox-xuid"); | ||
} | ||
|
||
private class ExpansionDevicePlaceholders implements DevicePlaceholders { | ||
|
||
private final ExpansionConfig config; | ||
private final String parent; | ||
|
||
public ExpansionDevicePlaceholders(ExpansionConfig config, String parent) { | ||
this.config = config; | ||
this.parent = parent; | ||
} | ||
|
||
@Override | ||
public String getJava() { | ||
return config.expansion.getString(parent + ".java", ""); | ||
} | ||
|
||
@Override | ||
public String getGeneric() { | ||
return config.expansion.getString(parent + ".generic", ""); | ||
} | ||
|
||
@Override | ||
public String getUnknown() { | ||
return config.expansion.getString(parent + ".unknown", ""); | ||
} | ||
|
||
@Override | ||
public String getGoogle() { | ||
return config.expansion.getString(parent + ".google", ""); | ||
} | ||
|
||
@Override | ||
public String getIOS() { | ||
return config.expansion.getString(parent + ".ios", ""); | ||
} | ||
|
||
@Override | ||
public String getOSX() { | ||
return config.expansion.getString(parent + ".osx", ""); | ||
} | ||
|
||
@Override | ||
public String getAmazon() { | ||
return config.expansion.getString(parent + ".fireos", ""); | ||
} | ||
|
||
@Override | ||
public String getGearVR() { | ||
return config.expansion.getString(parent + ".gearvr", ""); | ||
} | ||
|
||
@Override | ||
public String getHololens() { | ||
return config.expansion.getString(parent + ".hololens", ""); | ||
} | ||
|
||
@Override | ||
public String getUwp() { | ||
return config.expansion.getString(parent + ".uwp", ""); | ||
} | ||
|
||
@Override | ||
public String getWin32() { | ||
return config.expansion.getString(parent + ".win32", ""); | ||
} | ||
|
||
@Override | ||
public String getDedicated() { | ||
return config.expansion.getString(parent + ".dedicated", ""); | ||
} | ||
|
||
@Override | ||
public String getPs4() { | ||
return config.expansion.getString(parent + ".ps4", ""); | ||
} | ||
|
||
@Override | ||
public String getNX() { | ||
return config.expansion.getString(parent + ".nx", ""); | ||
} | ||
|
||
@Override | ||
public String getXbox() { | ||
return config.expansion.getString(parent + ".xbox", ""); | ||
} | ||
} | ||
|
||
private static class ExpansionGenericPlaceholders implements GenericPlaceholders { | ||
|
||
private final ExpansionConfig config; | ||
private final String parent; | ||
|
||
public ExpansionGenericPlaceholders(ExpansionConfig config, String parent) { | ||
this.config = config; | ||
this.parent = parent; | ||
} | ||
|
||
@Override | ||
public String getFound() { | ||
return config.expansion.getString(parent + ".found", ""); | ||
} | ||
|
||
@Override | ||
public String getNone() { | ||
return config.expansion.getString(parent + ".none", ""); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.