Added a few more config options. This is probably not the best use of json, lol

This commit is contained in:
Sollace 2019-01-27 21:34:02 +02:00
parent cf40acc049
commit e044b5b5bd
2 changed files with 67 additions and 12 deletions

View file

@ -17,7 +17,7 @@ import com.google.gson.stream.JsonWriter;
public class UConfig {
private static UConfig instance;
private static UConfig instance = new UConfig();
private static final Gson gson = new GsonBuilder()
.excludeFieldsWithoutExposeAnnotation()
@ -51,13 +51,59 @@ public class UConfig {
private File file;
@Expose(deserialize = false)
private final String speciesWhiteListComment =
"A whitelist of races permitted on the server. " +
"Races added to this list can be used by anyone, whilst any ones left off are not permitted. " +
"An empty list disables whitelisting entirely.";
@Expose
private final List<Race> speciesWhiteList = Lists.newArrayList();
@Expose(deserialize = false)
private final String preferredRaceComment =
"The default preferred race. " +
"This is the race a client requests when first joining a game. " +
"It is the default used both when Mine Little Pony is not installed and when they respond with a human race.";
@Expose
private Race preferredRace = Race.HUMAN;
@Expose(deserialize = false)
private final String ignoreMineLPComment =
"If true Mine Little Pony will not be considered when determining the race to use. " +
"The result will always be what is set by this config file.";
@Expose
private boolean ignoreMineLP = false;
public List<Race> getSpeciesWhiteList() {
return speciesWhiteList;
}
public boolean ignoresMineLittlePony() {
return ignoreMineLP;
}
public void setIgnoreMineLittlePony(boolean value) {
if (value != ignoreMineLP) {
ignoreMineLP = value;
save();
}
}
public void setPreferredRace(Race race) {
if (preferredRace != race) {
preferredRace = race;
save();
}
}
public Race getPrefferedRace() {
if (preferredRace == null) {
setPreferredRace(Race.HUMAN);
}
return preferredRace;
}
public void save() {
if (file.exists()) {
file.delete();

View file

@ -111,11 +111,17 @@ public class Unicopia implements IGuiHandler {
@SideOnly(Side.CLIENT)
private static Race getclientPlayerRace() {
if (Minecraft.getMinecraft().player != null && MineLP.modIsActive()) {
return Race.fromPonyRace(IPony.forPlayer(Minecraft.getMinecraft().player).getRace(false));
if (!UConfig.getInstance().ignoresMineLittlePony()
&& Minecraft.getMinecraft().player != null
&& MineLP.modIsActive()) {
Race race = Race.fromPonyRace(IPony.forPlayer(Minecraft.getMinecraft().player).getRace(false));
if (!race.isDefault()) {
return race;
}
}
return Race.HUMAN;
return UConfig.getInstance().getPrefferedRace();
}
@EventHandler
@ -137,6 +143,7 @@ public class Unicopia implements IGuiHandler {
FBS.init();
NetworkRegistry.INSTANCE.registerGuiHandler(this, this);
clientPlayerRace = getclientPlayerRace();
}
@EventHandler
@ -189,15 +196,17 @@ public class Unicopia implements IGuiHandler {
@SideOnly(Side.CLIENT)
@SubscribeEvent
public static void onGameTick(TickEvent.ClientTickEvent event) {
Race newRace = getclientPlayerRace();
if (newRace != clientPlayerRace && Minecraft.getMinecraft().player != null) {
clientPlayerRace = newRace;
channel.send(new MsgRequestCapabilities(Minecraft.getMinecraft().player, clientPlayerRace), Target.SERVER);
}
if (event.phase == Phase.END) {
if (Minecraft.getMinecraft().player != null) {
Race newRace = getclientPlayerRace();
if (newRace != clientPlayerRace) {
clientPlayerRace = newRace;
channel.send(new MsgRequestCapabilities(Minecraft.getMinecraft().player, clientPlayerRace), Target.SERVER);
}
}
Keyboard.getKeyHandler().onKeyInput();
}
}