From 7622f73a748de2168961b8420ec2fc8842b310e8 Mon Sep 17 00:00:00 2001 From: creeper123123321 <7974274+creeper123123321@users.noreply.github.com> Date: Fri, 21 Oct 2022 06:11:18 -0300 Subject: [PATCH] Remove ncr warn (#206) * Remove warning for NoChatReports, fix typo The warning is due to an old vulnerability of NCR * fix some space issue --- .editorconfig | 4 + .../provider/AbstractFabricPlatform.java | 304 +++++++++--------- 2 files changed, 154 insertions(+), 154 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..1042551 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,4 @@ +root = true + +[*.java] +indent_style = space \ No newline at end of file diff --git a/src/main/java/com/viaversion/fabric/common/provider/AbstractFabricPlatform.java b/src/main/java/com/viaversion/fabric/common/provider/AbstractFabricPlatform.java index f3edb9b..1ccff20 100644 --- a/src/main/java/com/viaversion/fabric/common/provider/AbstractFabricPlatform.java +++ b/src/main/java/com/viaversion/fabric/common/provider/AbstractFabricPlatform.java @@ -38,187 +38,183 @@ import java.util.concurrent.TimeUnit; import java.util.logging.Logger; public abstract class AbstractFabricPlatform implements ViaPlatform { - private final Logger logger = new JLoggerToLog4j(LogManager.getLogger("ViaVersion")); - private FabricViaConfig config; - private File dataFolder; - private final ViaAPI api; + private final Logger logger = new JLoggerToLog4j(LogManager.getLogger("ViaVersion")); + private FabricViaConfig config; + private File dataFolder; + private final ViaAPI api; - { - api = new FabricViaAPI(); - } + { + api = new FabricViaAPI(); + } - public void init() { - // We'll use it early for ViaInjector - installNativeVersionProvider(); - Path configDir = FabricLoader.getInstance().getConfigDir().resolve("ViaFabric"); - dataFolder = configDir.toFile(); - config = new FabricViaConfig(configDir.resolve("viaversion.yml").toFile()); - } + public void init() { + // We'll use it early for ViaInjector + installNativeVersionProvider(); + Path configDir = FabricLoader.getInstance().getConfigDir().resolve("ViaFabric"); + dataFolder = configDir.toFile(); + config = new FabricViaConfig(configDir.resolve("viaversion.yml").toFile()); + } - protected abstract void installNativeVersionProvider(); + protected abstract void installNativeVersionProvider(); - protected abstract ExecutorService asyncService(); + protected abstract ExecutorService asyncService(); - protected abstract EventLoop eventLoop(); + protected abstract EventLoop eventLoop(); - protected FutureTaskId runEventLoop(Runnable runnable) { - return new FutureTaskId(eventLoop().submit(runnable).addListener(errorLogger())); - } + protected FutureTaskId runEventLoop(Runnable runnable) { + return new FutureTaskId(eventLoop().submit(runnable).addListener(errorLogger())); + } - @Override - public FutureTaskId runAsync(Runnable runnable) { - return new FutureTaskId(CompletableFuture.runAsync(runnable, asyncService()) - .exceptionally(throwable -> { - if (!(throwable instanceof CancellationException)) { - throwable.printStackTrace(); - } - return null; - })); - } + @Override + public FutureTaskId runAsync(Runnable runnable) { + return new FutureTaskId(CompletableFuture.runAsync(runnable, asyncService()) + .exceptionally(throwable -> { + if (!(throwable instanceof CancellationException)) { + throwable.printStackTrace(); + } + return null; + })); + } - @Override - public FutureTaskId runSync(Runnable runnable, long ticks) { - // ViaVersion seems to not need to run delayed tasks on main thread - return new FutureTaskId(eventLoop() - .schedule(() -> runSync(runnable), ticks * 50, TimeUnit.MILLISECONDS) - .addListener(errorLogger()) - ); - } + @Override + public FutureTaskId runSync(Runnable runnable, long ticks) { + // ViaVersion seems to not need to run delayed tasks on main thread + return new FutureTaskId(eventLoop() + .schedule(() -> runSync(runnable), ticks * 50, TimeUnit.MILLISECONDS) + .addListener(errorLogger()) + ); + } - @Override - public FutureTaskId runRepeatingSync(Runnable runnable, long ticks) { - // ViaVersion seems to not need to run repeating tasks on main thread - return new FutureTaskId(eventLoop() - .scheduleAtFixedRate(() -> runSync(runnable), 0, ticks * 50, TimeUnit.MILLISECONDS) - .addListener(errorLogger()) - ); - } + @Override + public FutureTaskId runRepeatingSync(Runnable runnable, long ticks) { + // ViaVersion seems to not need to run repeating tasks on main thread + return new FutureTaskId(eventLoop() + .scheduleAtFixedRate(() -> runSync(runnable), 0, ticks * 50, TimeUnit.MILLISECONDS) + .addListener(errorLogger()) + ); + } - protected > GenericFutureListener errorLogger() { - return future -> { - if (!future.isCancelled() && future.cause() != null) { - future.cause().printStackTrace(); - } - }; - } + protected > GenericFutureListener errorLogger() { + return future -> { + if (!future.isCancelled() && future.cause() != null) { + future.cause().printStackTrace(); + } + }; + } - @Override - public boolean isProxy() { - // We kinda of have all server versions - return FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT; - } + @Override + public boolean isProxy() { + // We kinda of have all server versions + return FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT; + } - @Override - public void onReload() { - } + @Override + public void onReload() { + } - @Override - public Logger getLogger() { - return logger; - } + @Override + public Logger getLogger() { + return logger; + } - @Override - public ViaVersionConfig getConf() { - return config; - } + @Override + public ViaVersionConfig getConf() { + return config; + } - @Override - public ViaAPI getApi() { - return api; - } + @Override + public ViaAPI getApi() { + return api; + } - @Override - public File getDataFolder() { - return dataFolder; - } + @Override + public File getDataFolder() { + return dataFolder; + } - @Override - public String getPluginVersion() { - return FabricLoader.getInstance().getModContainer("viaversion").map(ModContainer::getMetadata) - .map(ModMetadata::getVersion).map(Version::getFriendlyString).orElse("UNKNOWN"); - } + @Override + public String getPluginVersion() { + return FabricLoader.getInstance().getModContainer("viaversion").map(ModContainer::getMetadata) + .map(ModMetadata::getVersion).map(Version::getFriendlyString).orElse("UNKNOWN"); + } - @Override - public String getPlatformName() { - return "ViaFabric"; - } + @Override + public String getPlatformName() { + return "ViaFabric"; + } - @Override - public String getPlatformVersion() { - return FabricLoader.getInstance().getModContainer("viafabric") - .get().getMetadata().getVersion().getFriendlyString(); - } + @Override + public String getPlatformVersion() { + return FabricLoader.getInstance().getModContainer("viafabric") + .get().getMetadata().getVersion().getFriendlyString(); + } - @Override - public boolean isPluginEnabled() { - return true; - } + @Override + public boolean isPluginEnabled() { + return true; + } - @Override - public ConfigurationProvider getConfigurationProvider() { - return config; - } + @Override + public ConfigurationProvider getConfigurationProvider() { + return config; + } - @Override - public boolean isOldClientsAllowed() { - return true; - } + @Override + public boolean isOldClientsAllowed() { + return true; + } - @Override - public JsonObject getDump() { - JsonObject platformSpecific = new JsonObject(); - JsonArray mods = new JsonArray(); - FabricLoader.getInstance().getAllMods().stream().map((mod) -> { - JsonObject jsonMod = new JsonObject(); - jsonMod.addProperty("id", mod.getMetadata().getId()); - jsonMod.addProperty("name", mod.getMetadata().getName()); - jsonMod.addProperty("version", mod.getMetadata().getVersion().getFriendlyString()); - JsonArray authors = new JsonArray(); - mod.getMetadata().getAuthors().stream().map(it -> { - JsonObject info = new JsonObject(); - JsonObject contact = new JsonObject(); - it.getContact().asMap().entrySet() - .forEach(c -> contact.addProperty(c.getKey(), c.getValue())); - if (contact.size() != 0) { - info.add("contact", contact); - } - info.addProperty("name", it.getName()); + @Override + public JsonObject getDump() { + JsonObject platformSpecific = new JsonObject(); + JsonArray mods = new JsonArray(); + FabricLoader.getInstance().getAllMods().stream().map((mod) -> { + JsonObject jsonMod = new JsonObject(); + jsonMod.addProperty("id", mod.getMetadata().getId()); + jsonMod.addProperty("name", mod.getMetadata().getName()); + jsonMod.addProperty("version", mod.getMetadata().getVersion().getFriendlyString()); + JsonArray authors = new JsonArray(); + mod.getMetadata().getAuthors().stream().map(it -> { + JsonObject info = new JsonObject(); + JsonObject contact = new JsonObject(); + it.getContact().asMap().entrySet() + .forEach(c -> contact.addProperty(c.getKey(), c.getValue())); + if (contact.size() != 0) { + info.add("contact", contact); + } + info.addProperty("name", it.getName()); - return info; - }).forEach(authors::add); - jsonMod.add("authors", authors); + return info; + }).forEach(authors::add); + jsonMod.add("authors", authors); - return jsonMod; - }).forEach(mods::add); + return jsonMod; + }).forEach(mods::add); - platformSpecific.add("mods", mods); - NativeVersionProvider ver = Via.getManager().getProviders().get(NativeVersionProvider.class); - if (ver != null) { - platformSpecific.addProperty("native version", ver.getNativeServerVersion()); - } - return platformSpecific; - } + platformSpecific.add("mods", mods); + NativeVersionProvider ver = Via.getManager().getProviders().get(NativeVersionProvider.class); + if (ver != null) { + platformSpecific.addProperty("native version", ver.getNativeServerVersion()); + } + return platformSpecific; + } - @Override - public final Collection getUnsupportedSoftwareClasses() { - List list = new ArrayList<>(ViaPlatform.super.getUnsupportedSoftwareClasses()); - list.add(new UnsupportedPlugin.Builder().name("gaslight/guardian").reason(UnsupportedSoftwareReasons.SELF_INCRIMINATION) - .addPlugin("guardian").addPlugin("gaslight").build()); - list.add(new UnsupportedPlugin.Builder().name("NoChatReports").reason(UnsupportedSoftwareReasons.NCR) - .addPlugin("nochatreports").build()); - return Collections.unmodifiableList(list); - } + @Override + public final Collection getUnsupportedSoftwareClasses() { + List list = new ArrayList<>(ViaPlatform.super.getUnsupportedSoftwareClasses()); + list.add(new UnsupportedPlugin.Builder().name("gaslight/guardian").reason(UnsupportedSoftwareReasons.SELF_INCRIMINATION) + .addPlugin("guardian").addPlugin("gaslight").build()); + return Collections.unmodifiableList(list); + } - @Override - public final boolean hasPlugin(String name) { - return FabricLoader.getInstance().isModLoaded(name); - } + @Override + public final boolean hasPlugin(String name) { + return FabricLoader.getInstance().isModLoaded(name); + } - private static final class UnsupportedSoftwareReasons { - - private static final String SELF_INCRIMINATION = "By using these kind of mods, at best you create fishy context or silly reports, " + - "at worst you end up incrimating yourself when writing messages or reporting another player."; - private static final String NCR = "Due to a history of breaking message formatting and creating other issues related to chat handling " + - "(some still present), we suggest you find alternatives to this mod."; - } + private static final class UnsupportedSoftwareReasons { + private static final String SELF_INCRIMINATION = "By using these proof-of-concept TESTING mods, " + + "at best you create fishy context or silly reports, " + + "at worst you end up incriminating yourself when writing messages or reporting another player."; + } }