Remove ncr warn (#206)

* Remove warning for NoChatReports, fix typo
The warning is due to an old vulnerability of NCR

* fix some space issue
This commit is contained in:
creeper123123321 2022-10-21 06:11:18 -03:00 committed by GitHub
parent 8e61509140
commit 7622f73a74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 154 additions and 154 deletions

4
.editorconfig Normal file
View File

@ -0,0 +1,4 @@
root = true
[*.java]
indent_style = space

View File

@ -38,187 +38,183 @@ import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
public abstract class AbstractFabricPlatform implements ViaPlatform<UUID> {
private final Logger logger = new JLoggerToLog4j(LogManager.getLogger("ViaVersion"));
private FabricViaConfig config;
private File dataFolder;
private final ViaAPI<UUID> api;
private final Logger logger = new JLoggerToLog4j(LogManager.getLogger("ViaVersion"));
private FabricViaConfig config;
private File dataFolder;
private final ViaAPI<UUID> 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 <T extends Future<?>> GenericFutureListener<T> errorLogger() {
return future -> {
if (!future.isCancelled() && future.cause() != null) {
future.cause().printStackTrace();
}
};
}
protected <T extends Future<?>> GenericFutureListener<T> 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<UUID> getApi() {
return api;
}
@Override
public ViaAPI<UUID> 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<UnsupportedSoftware> getUnsupportedSoftwareClasses() {
List<UnsupportedSoftware> 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<UnsupportedSoftware> getUnsupportedSoftwareClasses() {
List<UnsupportedSoftware> 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.";
}
}