Skip to content

Commit

Permalink
Touchups
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy committed Dec 8, 2021
1 parent c9fb69e commit ea1d8ff
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public final class GeyserSkinManager extends Plugin {

@Override
public void onEnable() {
new Configuration(this.getDataFolder().toPath());
boolean floodgatePresent = FloodgateUtil.isFloodgatePresent(getLogger()::warning);
Configuration config = Configuration.create(this.getDataFolder().toPath());
boolean floodgatePresent = FloodgateUtil.isFloodgatePresent(config, getLogger()::warning);
this.listener = new BungeecordSkinEventListener(this, !floodgatePresent);
getProxy().getPluginManager().registerListener(this, this.listener);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,35 @@
package com.github.camotoy.geyserskinmanager.common;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

import java.io.*;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;

public class Configuration {

public Configuration(Path dataDirectory) {
createConfig(dataDirectory);
// Read config and boolean.
try {
final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
ConfigurationJackson config = mapper.readValue(new File(dataDirectory + "\\" + "config.yml"), ConfigurationJackson.class);
if (config.getForceShowSkins()) {
FloodgateUtil.setForceSkin(true);
}
} catch (IOException e) {
e.printStackTrace();
}
public Configuration() {
// Empty for Jackson usage
}

/**
* Load GeyserSkinManager config
*
* @param path The config's directory
* @param dataDirectory The config's directory
*/
private void createConfig(Path path) {
File folder = path.toFile();
public static Configuration create(Path dataDirectory) {
File folder = dataDirectory.toFile();
File file = new File(folder, "config.yml");

if (!file.exists()) {
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
try (InputStream input = getClass().getResourceAsStream("/" + file.getName())) {
try (InputStream input = Configuration.class.getResourceAsStream("/" + file.getName())) {
if (input != null) {
Files.copy(input, file.toPath());
} else {
Expand All @@ -46,5 +39,20 @@ private void createConfig(Path path) {
exception.printStackTrace();
}
}

// Read config
try {
final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
return mapper.readValue(dataDirectory.resolve("config.yml").toFile(), Configuration.class);
} catch (IOException e) {
throw new RuntimeException("Cannot create GeyserSkinManager config!", e);
}
}

@JsonProperty("force-show-skins")
private boolean forceShowSkins;

public boolean getForceShowSkins() {
return forceShowSkins;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
import java.util.function.Consumer;

public final class FloodgateUtil {
private static boolean forceSkin;

/**
* @return true if Floodgate is present on the server.
*/
public static boolean isFloodgatePresent(Consumer<String> warnFunction) {

public static boolean isFloodgatePresent(Configuration config, Consumer<String> warnFunction) {
boolean floodgatePresent = false;
if (!(forceSkin)) {
if (!config.getForceShowSkins()) {
try {
// Should Floodgate be present, don't bother
Class.forName("org.geysermc.floodgate.api.FloodgateApi");
Expand All @@ -24,13 +22,9 @@ public static boolean isFloodgatePresent(Consumer<String> warnFunction) {
} catch (Exception ignored) {
}
} else {
warnFunction.accept("ForceShowSkins active, Floodgate check is bypassed!");
warnFunction.accept("ForceShowSkins active through config; Floodgate check is bypassed!");
}

return floodgatePresent;
}

public static void setForceSkin(boolean forceSkin) {
FloodgateUtil.forceSkin = forceSkin;
}
}
3 changes: 3 additions & 0 deletions common/src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# GeyserSkinManager by Camotoy

# Whether to override any Floodgate detection and always show skins.
# This is not recommended - Floodgate has skin support built-in,
# or you can use https://modrinth.com/mod/bedrockskinutility/ alongside this mod to show skins, capes, and geometry.
force-show-skins: false
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public final class GeyserSkinManager extends JavaPlugin {

@Override
public void onEnable() {
new Configuration(this.getDataFolder().toPath());
boolean floodgatePresent = FloodgateUtil.isFloodgatePresent(getLogger()::warning);
Configuration config = Configuration.create(this.getDataFolder().toPath());
boolean floodgatePresent = FloodgateUtil.isFloodgatePresent(config, getLogger()::warning);
boolean bungeeCordMode = Bukkit.getPluginManager().getPlugin("Geyser-Spigot") == null;

if (!bungeeCordMode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,22 @@
dependencies = {@Dependency(id = "geyser")}
)
public class GeyserSkinManager {

private final ProxyServer server;
private final Path dataDirectory;

@Inject
private Logger logger;

@Inject
public GeyserSkinManager(ProxyServer server, @DataDirectory final Path folder) {
this.server = server;
public GeyserSkinManager(ProxyServer server, @DataDirectory final Path folder) {
this.server = server;
this.dataDirectory = folder;
}

@Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) {
new Configuration(this.dataDirectory);
boolean floodgatePresent = FloodgateUtil.isFloodgatePresent(getLogger()::warn);
Configuration config = Configuration.create(this.dataDirectory);
boolean floodgatePresent = FloodgateUtil.isFloodgatePresent(config, getLogger()::warn);
server.getEventManager().register(this, new VelocitySkinEventListener(server, this, dataDirectory, logger, !floodgatePresent));
}

Expand Down

0 comments on commit ea1d8ff

Please sign in to comment.