21w41a + fix #157

This commit is contained in:
creeper123123321 2021-10-17 10:31:04 -03:00
parent a2693aafce
commit 2a5ba15209
8 changed files with 163 additions and 136 deletions

View File

@ -22,7 +22,7 @@ plugins {
} }
def ENV = System.getenv() def ENV = System.getenv()
def vvVer = "4.1.0-21w40a-SNAPSHOT" def vvVer = "4.1.0-21w41a-SNAPSHOT"
def yamlVer = "1.29" def yamlVer = "1.29"
description = "Client-side and server-side ViaVersion implementation for Fabric" description = "Client-side and server-side ViaVersion implementation for Fabric"

View File

@ -31,157 +31,160 @@ import java.util.concurrent.TimeUnit;
import java.util.logging.Logger; import java.util.logging.Logger;
public abstract class AbstractFabricPlatform implements ViaPlatform<UUID> { public abstract class AbstractFabricPlatform implements ViaPlatform<UUID> {
private final Logger logger = new JLoggerToLog4j(LogManager.getLogger("ViaVersion")); private final Logger logger = new JLoggerToLog4j(LogManager.getLogger("ViaVersion"));
private final FabricViaConfig config; private FabricViaConfig config;
private final File dataFolder; private File dataFolder;
private final ViaAPI<UUID> api; private final ViaAPI<UUID> api;
{ {
Path configDir = FabricLoader.getInstance().getConfigDir().resolve("ViaFabric"); api = new FabricViaAPI();
config = new FabricViaConfig(configDir.resolve("viaversion.yml").toFile()); }
dataFolder = configDir.toFile();
api = new FabricViaAPI();
}
protected abstract ExecutorService asyncService(); public void init() {
Path configDir = FabricLoader.getInstance().getConfigDir().resolve("ViaFabric");
dataFolder = configDir.toFile();
config = new FabricViaConfig(configDir.resolve("viaversion.yml").toFile());
}
protected abstract EventLoop eventLoop(); protected abstract ExecutorService asyncService();
protected FutureTaskId runEventLoop(Runnable runnable) { protected abstract EventLoop eventLoop();
return new FutureTaskId(eventLoop().submit(runnable).addListener(errorLogger()));
}
@Override protected FutureTaskId runEventLoop(Runnable runnable) {
public FutureTaskId runAsync(Runnable runnable) { return new FutureTaskId(eventLoop().submit(runnable).addListener(errorLogger()));
return new FutureTaskId(CompletableFuture.runAsync(runnable, asyncService()) }
.exceptionally(throwable -> {
if (!(throwable instanceof CancellationException)) {
throwable.printStackTrace();
}
return null;
}));
}
@Override @Override
public FutureTaskId runSync(Runnable runnable, long ticks) { public FutureTaskId runAsync(Runnable runnable) {
// ViaVersion seems to not need to run delayed tasks on main thread return new FutureTaskId(CompletableFuture.runAsync(runnable, asyncService())
return new FutureTaskId(eventLoop() .exceptionally(throwable -> {
.schedule(() -> runSync(runnable), ticks * 50, TimeUnit.MILLISECONDS) if (!(throwable instanceof CancellationException)) {
.addListener(errorLogger()) throwable.printStackTrace();
); }
} return null;
}));
}
@Override @Override
public FutureTaskId runRepeatingSync(Runnable runnable, long ticks) { public FutureTaskId runSync(Runnable runnable, long ticks) {
// ViaVersion seems to not need to run repeating tasks on main thread // ViaVersion seems to not need to run delayed tasks on main thread
return new FutureTaskId(eventLoop() return new FutureTaskId(eventLoop()
.scheduleAtFixedRate(() -> runSync(runnable), 0, ticks * 50, TimeUnit.MILLISECONDS) .schedule(() -> runSync(runnable), ticks * 50, TimeUnit.MILLISECONDS)
.addListener(errorLogger()) .addListener(errorLogger())
); );
} }
protected <T extends Future<?>> GenericFutureListener<T> errorLogger() { @Override
return future -> { public FutureTaskId runRepeatingSync(Runnable runnable, long ticks) {
if (!future.isCancelled() && future.cause() != null) { // ViaVersion seems to not need to run repeating tasks on main thread
future.cause().printStackTrace(); return new FutureTaskId(eventLoop()
} .scheduleAtFixedRate(() -> runSync(runnable), 0, ticks * 50, TimeUnit.MILLISECONDS)
}; .addListener(errorLogger())
} );
}
@Override protected <T extends Future<?>> GenericFutureListener<T> errorLogger() {
public boolean isProxy() { return future -> {
// We kinda of have all server versions if (!future.isCancelled() && future.cause() != null) {
return true; future.cause().printStackTrace();
} }
};
}
@Override @Override
public void onReload() { public boolean isProxy() {
} // We kinda of have all server versions
return true;
}
@Override @Override
public Logger getLogger() { public void onReload() {
return logger; }
}
@Override @Override
public ViaVersionConfig getConf() { public Logger getLogger() {
return config; return logger;
} }
@Override @Override
public ViaAPI<UUID> getApi() { public ViaVersionConfig getConf() {
return api; return config;
} }
@Override @Override
public File getDataFolder() { public ViaAPI<UUID> getApi() {
return dataFolder; return api;
} }
@Override @Override
public String getPluginVersion() { public File getDataFolder() {
return FabricLoader.getInstance().getModContainer("viaversion").map(ModContainer::getMetadata) return dataFolder;
.map(ModMetadata::getVersion).map(Version::getFriendlyString).orElse("UNKNOWN"); }
}
@Override @Override
public String getPlatformName() { public String getPluginVersion() {
return "ViaFabric"; return FabricLoader.getInstance().getModContainer("viaversion").map(ModContainer::getMetadata)
} .map(ModMetadata::getVersion).map(Version::getFriendlyString).orElse("UNKNOWN");
}
@Override @Override
public String getPlatformVersion() { public String getPlatformName() {
return FabricLoader.getInstance().getModContainer("viafabric") return "ViaFabric";
.get().getMetadata().getVersion().getFriendlyString(); }
}
@Override @Override
public boolean isPluginEnabled() { public String getPlatformVersion() {
return true; return FabricLoader.getInstance().getModContainer("viafabric")
} .get().getMetadata().getVersion().getFriendlyString();
}
@Override @Override
public ConfigurationProvider getConfigurationProvider() { public boolean isPluginEnabled() {
return config; return true;
} }
@Override @Override
public boolean isOldClientsAllowed() { public ConfigurationProvider getConfigurationProvider() {
return true; return config;
} }
@Override @Override
public JsonObject getDump() { public boolean isOldClientsAllowed() {
JsonObject platformSpecific = new JsonObject(); return true;
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; @Override
}).forEach(authors::add); public JsonObject getDump() {
jsonMod.add("authors", authors); 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 jsonMod; return info;
}).forEach(mods::add); }).forEach(authors::add);
jsonMod.add("authors", authors);
platformSpecific.add("mods", mods); return jsonMod;
NativeVersionProvider ver = Via.getManager().getProviders().get(NativeVersionProvider.class); }).forEach(mods::add);
if (ver != null) {
platformSpecific.addProperty("native version", ver.getServerProtocolVersion()); platformSpecific.add("mods", mods);
} NativeVersionProvider ver = Via.getManager().getProviders().get(NativeVersionProvider.class);
return platformSpecific; if (ver != null) {
} platformSpecific.addProperty("native version", ver.getServerProtocolVersion());
}
return platformSpecific;
}
} }

View File

@ -57,11 +57,15 @@ public class ViaFabric implements ModInitializer {
@Override @Override
public void onInitialize() { public void onInitialize() {
FabricPlatform platform = new FabricPlatform();
Via.init(ViaManagerImpl.builder() Via.init(ViaManagerImpl.builder()
.injector(new FabricInjector()) .injector(new FabricInjector())
.loader(new VFLoader()) .loader(new VFLoader())
.commandHandler(new VRCommandHandler()) .commandHandler(new VRCommandHandler())
.platform(new FabricPlatform()).build()); .platform(platform).build());
platform.init();
FabricLoader.getInstance().getModContainer("viabackwards").ifPresent(mod -> MappingDataLoader.enableMappingsCache()); FabricLoader.getInstance().getModContainer("viabackwards").ifPresent(mod -> MappingDataLoader.enableMappingsCache());

View File

@ -57,11 +57,15 @@ public class ViaFabric implements ModInitializer {
@Override @Override
public void onInitialize() { public void onInitialize() {
FabricPlatform platform = new FabricPlatform();
Via.init(ViaManagerImpl.builder() Via.init(ViaManagerImpl.builder()
.injector(new FabricInjector()) .injector(new FabricInjector())
.loader(new VFLoader()) .loader(new VFLoader())
.commandHandler(new VRCommandHandler()) .commandHandler(new VRCommandHandler())
.platform(new FabricPlatform()).build()); .platform(platform).build());
platform.init();
FabricLoader.getInstance().getModContainer("viabackwards").ifPresent(mod -> MappingDataLoader.enableMappingsCache()); FabricLoader.getInstance().getModContainer("viabackwards").ifPresent(mod -> MappingDataLoader.enableMappingsCache());

View File

@ -59,11 +59,15 @@ public class ViaFabric implements ModInitializer {
@Override @Override
public void onInitialize() { public void onInitialize() {
FabricPlatform platform = new FabricPlatform();
Via.init(ViaManagerImpl.builder() Via.init(ViaManagerImpl.builder()
.injector(new FabricInjector()) .injector(new FabricInjector())
.loader(new VFLoader()) .loader(new VFLoader())
.commandHandler(new VRCommandHandler()) .commandHandler(new VRCommandHandler())
.platform(new FabricPlatform()).build()); .platform(platform).build());
platform.init();
FabricLoader.getInstance().getModContainer("viabackwards").ifPresent(mod -> MappingDataLoader.enableMappingsCache()); FabricLoader.getInstance().getModContainer("viabackwards").ifPresent(mod -> MappingDataLoader.enableMappingsCache());

View File

@ -59,11 +59,15 @@ public class ViaFabric implements ModInitializer {
@Override @Override
public void onInitialize() { public void onInitialize() {
FabricPlatform platform = new FabricPlatform();
Via.init(ViaManagerImpl.builder() Via.init(ViaManagerImpl.builder()
.injector(new FabricInjector()) .injector(new FabricInjector())
.loader(new VFLoader()) .loader(new VFLoader())
.commandHandler(new VRCommandHandler()) .commandHandler(new VRCommandHandler())
.platform(new FabricPlatform()).build()); .platform(platform).build());
platform.init();
FabricLoader.getInstance().getModContainer("viabackwards").ifPresent(mod -> MappingDataLoader.enableMappingsCache()); FabricLoader.getInstance().getModContainer("viabackwards").ifPresent(mod -> MappingDataLoader.enableMappingsCache());

View File

@ -59,11 +59,15 @@ public class ViaFabric implements ModInitializer {
@Override @Override
public void onInitialize() { public void onInitialize() {
FabricPlatform platform = new FabricPlatform();
Via.init(ViaManagerImpl.builder() Via.init(ViaManagerImpl.builder()
.injector(new FabricInjector()) .injector(new FabricInjector())
.loader(new VFLoader()) .loader(new VFLoader())
.commandHandler(new VRCommandHandler()) .commandHandler(new VRCommandHandler())
.platform(new FabricPlatform()).build()); .platform(platform).build());
platform.init();
FabricLoader.getInstance().getModContainer("viabackwards").ifPresent(mod -> MappingDataLoader.enableMappingsCache()); FabricLoader.getInstance().getModContainer("viabackwards").ifPresent(mod -> MappingDataLoader.enableMappingsCache());

View File

@ -43,11 +43,15 @@ public class ViaFabric implements ModInitializer {
@Override @Override
public void onInitialize() { public void onInitialize() {
FabricPlatform platform = new FabricPlatform();
Via.init(ViaManagerImpl.builder() Via.init(ViaManagerImpl.builder()
.injector(new FabricInjector()) .injector(new FabricInjector())
.loader(new VFLoader()) .loader(new VFLoader())
.commandHandler(new VRCommandHandler()) .commandHandler(new VRCommandHandler())
.platform(new FabricPlatform()).build()); .platform(platform).build());
platform.init();
FabricLoader.getInstance().getModContainer("viabackwards").ifPresent(mod -> MappingDataLoader.enableMappingsCache()); FabricLoader.getInstance().getModContainer("viabackwards").ifPresent(mod -> MappingDataLoader.enableMappingsCache());