diff --git a/.github/workflows/TestCompile.yml b/.github/workflows/TestCompile.yml index 87a2227..2b7369e 100644 --- a/.github/workflows/TestCompile.yml +++ b/.github/workflows/TestCompile.yml @@ -5,7 +5,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - java: [ '21' ] + java: [ '25' ] permissions: actions: write steps: diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index e7b4d80..c46087d 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -1,24 +1,20 @@ \ No newline at end of file diff --git a/.idea/runConfigurations/Run_Multi_Build.xml b/.idea/runConfigurations/Run_Multi_Build.xml deleted file mode 100644 index df134ed..0000000 --- a/.idea/runConfigurations/Run_Multi_Build.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - \ No newline at end of file diff --git a/Common/build.gradle b/Common/build.gradle index 6ca607d..f42b840 100644 --- a/Common/build.gradle +++ b/Common/build.gradle @@ -34,7 +34,7 @@ dependencies { implementation project(":MoseStream") implementation 'org.spongepowered:spongeapi:' + property("SPONGE_VERSION") implementation 'org.jetbrains:annotations:26.0.1' - implementation ('io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT') + implementation 'io.papermc.paper:paper-api:' + property("BUKKIT_VERSION") + '.build.+' testImplementation platform('org.junit:junit-bom:5.10.0') testImplementation 'org.junit.jupiter:junit-jupiter' diff --git a/Common/src/main/java/org/soak/exception/NotImplementedException.java b/Common/src/main/java/org/soak/exception/NotImplementedException.java index 312b84b..34a067b 100644 --- a/Common/src/main/java/org/soak/exception/NotImplementedException.java +++ b/Common/src/main/java/org/soak/exception/NotImplementedException.java @@ -1,20 +1,24 @@ package org.soak.exception; +import org.jetbrains.annotations.NotNull; + import java.lang.reflect.Method; import java.util.Arrays; import java.util.stream.Collectors; public class NotImplementedException extends RuntimeException { - private final Method interfaceMethod; - - public NotImplementedException(Class from, String methodName, Class... parameters) throws NoSuchMethodException { + public NotImplementedException(@NotNull Class from, @NotNull String methodName, @NotNull Class... parameters) throws NoSuchMethodException { this(from.getDeclaredMethod(methodName, parameters)); } - public NotImplementedException(Method interfaceMethod) { + public NotImplementedException(@NotNull Method interfaceMethod) { super("The method is not implemented: " + interfaceMethod.getDeclaringClass().getName() + "." + interfaceMethod.getName() + "(" + Arrays.stream(interfaceMethod.getParameters()).map(parameter -> parameter.getType().getSimpleName() + " " + parameter.getName()).collect(Collectors.joining(", ")) + ")"); - this.interfaceMethod = interfaceMethod; + } + + @Deprecated + public NotImplementedException() { + super("This method is not implemented: " + Thread.currentThread().getStackTrace()[1].toString()); } public static NotImplementedException createByLazy(Object fromObject, String name, Class... parameters) { @@ -38,28 +42,4 @@ public static NotImplementedException createByLazy(Class from, String name, C throw new RuntimeException("Could not create NotImplementedException for " + from.getSimpleName() + "#" + name + "(" + Arrays.stream(parameters).map(parameter -> parameter.getSimpleName() + " arg").collect(Collectors.joining(", ")) + ")", e); } } - - @Deprecated(forRemoval = true) - public static NotImplementedException createByLazy(Class... parameterTypes) { - StackTraceElement stacktrace = Thread.currentThread().getStackTrace()[0]; - String className = stacktrace.getClassName(); - String methodName = stacktrace.getMethodName(); - Class clazz; - try { - clazz = Class.forName(className); - } catch (ClassNotFoundException e) { - throw new RuntimeException("Could not find class when creating NotImplementedException", e); - } - - try { - Method method = clazz.getDeclaredMethod(methodName, parameterTypes); - return new NotImplementedException(method); - } catch (NoSuchMethodException e) { - throw new RuntimeException("Could not find method when creating NotImplementedException: " + methodName + " With " + Arrays.stream(parameterTypes).map(Class::getSimpleName).collect(Collectors.joining(", ")), e); - } - } - - public Method unimplementedMethod() { - return this.interfaceMethod; - } } diff --git a/Common/src/main/java/org/soak/plugin/paper/loader/SoakPluginClassLoader.java b/Common/src/main/java/org/soak/plugin/paper/loader/SoakPluginClassLoader.java index aa8fdca..ae61cca 100644 --- a/Common/src/main/java/org/soak/plugin/paper/loader/SoakPluginClassLoader.java +++ b/Common/src/main/java/org/soak/plugin/paper/loader/SoakPluginClassLoader.java @@ -49,21 +49,25 @@ public SoakPluginClassLoader(PluginProviderContext context) throws MalformedURLE private static URL[] librariesClassLoader(PluginProviderContext context) throws MalformedURLException { PluginMeta meta = context.getConfiguration(); List libraries; - if(meta instanceof SoakPluginMeta spm){ + if (meta instanceof SoakPluginMeta spm) { libraries = spm.getLibraries(); - }else{ - libraries = ((PluginDescriptionFile)meta).getLibraries(); + } else { + libraries = ((PluginDescriptionFile) meta).getLibraries(); } URL extra = context.getPluginSource().toUri().toURL(); List paths = libraries.stream().map(string -> { - String[] split =string.split(":", 3); + String[] split = string.split(":", 3); String group = split[0].replaceAll(Pattern.quote("."), "/"); String id = split[1]; String version = split[2]; return new File("soakLibraries/" + group + "/" + id + "/" + version + "/" + id + "-" + version + ".jar"); }).toList(); - String missing = paths.stream().filter(file -> !file.exists()).map(File::getName).map(n -> n.substring(0, n.length() - 4)).collect(Collectors.joining(", ")); - if(!missing.isBlank()){ + String missing = paths.stream() + .filter(file -> !file.exists()) + .map(File::getName) + .map(n -> n.substring(0, n.length() - 4)) + .collect(Collectors.joining(", ")); + if (!missing.isBlank()) { context.getLogger().error("Not all libraries have loaded, they could be downloading: Missing " + missing); } var stream = paths.stream().filter(File::exists).map(file -> { @@ -77,7 +81,9 @@ private static URL[] librariesClassLoader(PluginProviderContext context) throws } - public static void setupPlugin(JavaPlugin javaPlugin, String loggerName, File pluginFile, File configFile, File dataFolder, Supplier descriptionGetter, Supplier configurationGetter, Supplier loaderGetter) { + public static void setupPlugin(JavaPlugin javaPlugin, String loggerName, File pluginFile, File configFile, + File dataFolder, Supplier descriptionGetter, + Supplier configurationGetter, Supplier loaderGetter) { PluginMeta pDescription = descriptionGetter.get(); SoakPluginMeta pMeta = configurationGetter.get(); var logger = PaperPluginLogger.getLogger(loggerName); @@ -112,7 +118,8 @@ public static void setupPlugin(JavaPlugin javaPlugin, String loggerName, File pl } } - private static void applyValue(String fieldName, JavaPlugin plugin, Object value) throws NoSuchFieldException, IllegalAccessException { + private static void applyValue(String fieldName, JavaPlugin plugin, Object value) + throws NoSuchFieldException, IllegalAccessException { var field = JavaPlugin.class.getDeclaredField(fieldName); field.setAccessible(true); field.set(plugin, value); @@ -135,9 +142,9 @@ private static void copyYaml(YamlConfiguration configuration, File file) throws configuration.addDefaults(defaultConfig); } - public SoakPluginMeta buildMeta(){ + public SoakPluginMeta buildMeta() { var config = getConfiguration(); - if(config instanceof SoakPluginMeta spm) { + if (config instanceof SoakPluginMeta spm) { return spm; } return new SoakPluginMetaBuilder().from(config).build(); @@ -149,12 +156,41 @@ public SoakPluginMeta buildMeta(){ } @Override - public @NotNull Class loadClass(@NotNull String name, boolean resolve, boolean checkGlobal, boolean checkLibs) throws ClassNotFoundException { + public @NotNull Class loadClass(@NotNull String name, boolean resolve, boolean checkGlobal, boolean checkLibs) + throws ClassNotFoundException { //TODO GLOBAL AND LIBS return loadClass(name, resolve); } + @Override + public void init(@NotNull JavaPlugin javaPlugin) { + setupPlugin(javaPlugin, + this.getConfiguration().getName(), + this.context.getPluginSource().toFile(), + new File(this.context.getDataDirectory().toFile(), "config.yml"), + this.context.getDataDirectory().toFile(), + this::getConfiguration, + this::buildMeta, + () -> this); + } + + @Override + public @Nullable JavaPlugin getPlugin() { + var config = this.getConfiguration(); + return SoakManager.getManager() + .getBukkitSoakContainers() + .map(SoakPluginContainer::getBukkitInstance) + .filter(jp -> jp.getPluginMeta().getName().equals(config.getName())) + .findAny() + .orElse(null); + } + + @Override + public @Nullable PluginClassLoaderGroup getGroup() { + return null; + } + @Override protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException { var clazz = super.loadClass(name, resolve); @@ -170,14 +206,9 @@ public Class findClass(String name) throws ClassNotFoundException { return foundGeneratedClass.get(); } - var opOtherClass = SoakManager - .getManager() + var opOtherClass = SoakManager.getManager() .getBukkitSoakContainers() - .flatMap(spc -> SoakManager - .getManager() - .getSoakClassLoader(spc) - .getClasses() - .stream()) + .flatMap(spc -> SoakManager.getManager().getSoakClassLoader(spc).getClasses().stream()) .filter(clazz -> clazz.getTypeName().equals(name)) .findAny(); @@ -189,7 +220,11 @@ public Class findClass(String name) throws ClassNotFoundException { } catch (ClassNotFoundException e) { //allow other class loaders to supply there solution if possible - var opClass = NMSBounceLoader.getLoader().classes().stream().filter(clazz -> clazz.getName().equals(name)).findAny(); + var opClass = NMSBounceLoader.getLoader() + .classes() + .stream() + .filter(clazz -> clazz.getName().equals(name)) + .findAny(); if (opClass.isPresent()) { return opClass.get(); } @@ -202,26 +237,4 @@ public Class findClass(String name) throws ClassNotFoundException { public @NotNull @UnmodifiableView Collection> getClasses() { return Collections.unmodifiableCollection(this.classes); } - - @Override - public void init(@NotNull JavaPlugin javaPlugin) { - setupPlugin(javaPlugin, this.getConfiguration().getName(), this.context.getPluginSource().toFile(), new File(this.context.getDataDirectory().toFile(), "config.yml"), this.context.getDataDirectory().toFile(), this::getConfiguration, this::buildMeta, () -> this); - } - - @Override - public @Nullable JavaPlugin getPlugin() { - var config = this.getConfiguration(); - return SoakManager - .getManager() - .getBukkitSoakContainers() - .map(SoakPluginContainer::getBukkitInstance) - .filter(jp -> jp.getPluginMeta().equals(config)) - .findAny() - .orElse(null); - } - - @Override - public @Nullable PluginClassLoaderGroup getGroup() { - return null; - } } \ No newline at end of file diff --git a/Common/src/main/java/org/soak/utils/CollectionBuilder.java b/Common/src/main/java/org/soak/utils/CollectionBuilder.java new file mode 100644 index 0000000..f9bb309 --- /dev/null +++ b/Common/src/main/java/org/soak/utils/CollectionBuilder.java @@ -0,0 +1,55 @@ +package org.soak.utils; + +import org.jetbrains.annotations.*; + +import java.util.Collection; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collector; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class CollectionBuilder { + + private Stream builder = Stream.empty(); + + @Contract("_ -> this") + public CollectionBuilder add(@UnknownNullability T value){ + builder = Stream.concat(builder, Stream.of(value)); + return this; + } + + @SafeVarargs + @Contract("_ -> this") + public final CollectionBuilder addAll(@NotNull T... value){ + builder = Stream.concat(builder, Stream.of(value)); + return this; + } + + @Contract("_ -> this") + public CollectionBuilder add(@NotNull Collection value){ + builder = Stream.concat(builder, value.stream()); + return this; + } + + @Contract("_ -> this") + public CollectionBuilder add(@NotNull Stream value){ + builder = Stream.concat(builder, value); + return this; + } + + public R collect(Collector collector){ + return builder.collect(collector); + } + + @Unmodifiable + public Map toMap(@NotNull Function toKey, @NotNull Function toResult){ + return this.collect(Collectors.toUnmodifiableMap(toKey, toResult)); + } + + @Unmodifiable + public Map toMapKeyed(@NotNull Function toKey){ + return toMap(toKey, t -> t); + } + +} diff --git a/Common/src/main/java/org/soak/utils/TagHelper.java b/Common/src/main/java/org/soak/utils/TagHelper.java index 181c712..600e429 100644 --- a/Common/src/main/java/org/soak/utils/TagHelper.java +++ b/Common/src/main/java/org/soak/utils/TagHelper.java @@ -8,25 +8,25 @@ import org.spongepowered.api.fluid.FluidTypes; import org.spongepowered.api.item.ItemType; import org.spongepowered.api.item.ItemTypes; -import org.spongepowered.api.tag.Tag; +import org.spongepowered.api.tag.DefaultedTag; import java.util.stream.Stream; public class TagHelper { - public static Stream getBlockTypes(Tag tag) { + public static Stream getBlockTypes(DefaultedTag tag) { return BlockTypes.registry().stream().filter(type -> type.is(tag)); } - public static Stream getItemTypes(Tag tag) { + public static Stream getItemTypes(DefaultedTag tag) { return ItemTypes.registry().stream().filter(type -> type.is(tag)); } - public static Stream> getEntityTypes(Tag> tag) { + public static Stream> getEntityTypes(DefaultedTag> tag) { return EntityTypes.registry().stream().filter(type -> type.is(tag)); } - public static Stream getFluidTypes(Tag tag) { + public static Stream getFluidTypes(DefaultedTag tag) { return FluidTypes.registry().stream().filter(type -> type.is(tag)); } } diff --git a/Launch-Common/build.gradle b/Launch-Common/build.gradle index 09d5e78..575b794 100644 --- a/Launch-Common/build.gradle +++ b/Launch-Common/build.gradle @@ -25,7 +25,7 @@ dependencies { implementation(project(':Common')) implementation 'org.spongepowered:spongeapi:' + property("SPONGE_VERSION") - implementation 'io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT' + implementation 'io.papermc.paper:paper-api:' + property("BUKKIT_VERSION") + '.build.+' testImplementation platform('org.junit:junit-bom:5.10.0') diff --git a/Launch-External/build.gradle b/Launch-External/build.gradle index 6945252..bc179a3 100644 --- a/Launch-External/build.gradle +++ b/Launch-External/build.gradle @@ -33,8 +33,8 @@ dependencies { //implementation 'net.minecraftforge:forgespi:6.0.0' implementation 'commons-lang:commons-lang:2.6' //included with bukkit -> forced onto forge - implementation 'io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT' - implementation 'net.bytebuddy:byte-buddy:1.15.10' + implementation 'io.papermc.paper:paper-api:' + property("BUKKIT_VERSION") + '.build.+' + implementation 'net.bytebuddy:byte-buddy:1.18.8' testImplementation platform('org.junit:junit-bom:5.10.0') testImplementation 'org.junit.jupiter:junit-jupiter' @@ -42,12 +42,12 @@ dependencies { processResources { var soakPropertiesPath = "./build/resources/main/META-INF/soak-info.properties" - var soakPropertiesFile = project.file(soakPropertiesPath).toPath(); + var soakPropertiesFile = project.file(soakPropertiesPath).toPath() if (Files.notExists(soakPropertiesFile)) { Files.createDirectories(soakPropertiesFile.parent) Files.createFile(soakPropertiesFile) } - var writer = new FileWriter(soakPropertiesFile.toFile()); + var writer = new FileWriter(soakPropertiesFile.toFile()) writer.append("Bukkit-Version=" + project.property("BUKKIT_VERSION")) writer.append("\nSoak-Version=" + version) writer.flush() @@ -70,9 +70,8 @@ jar { dependsOn(":MoseStream:jar") dependsOn(":CollectionStream:jar") dependsOn(":Override:jar") - dependsOn(":Launch-External:Neo:jar") - dependsOn(":Launch-External:Lex:jar") - dependsOn(":NMSBounce:jar") + //dependsOn(":Launch-External:Neo:jar") + //dependsOn(":Launch-External:Lex:jar") var fat = configurations.runtimeClasspath.filter { return it.name.startsWith("Launch-Common") @@ -91,7 +90,7 @@ jar { }.collect(element -> { if (element.name.startsWith("paper-api-")) { - return zipTree(element).matching{ + return zipTree(element).matching { exclude("org/bukkit/Material.class") } } @@ -112,8 +111,8 @@ jar { var insertFolders = new String[]{"../Override/build/libs/", "./Neo/build/libs/", "./Lex/build/libs/"} for (var folderPath : insertFolders) { - var folder = project.file(folderPath); - var files = folder.listFiles(); + var folder = project.file(folderPath) + var files = folder.listFiles() if (files != null && files.length != 0) { var file = files[0] @@ -124,7 +123,7 @@ jar { } } - var insertJarFiles = new String[]{"../NMSBounce/build/libs/NMSBounce.jar"} + var insertJarFiles = new String[]{} for (var file : insertJarFiles) { fat.add(files(file)) } @@ -132,7 +131,7 @@ jar { var excludeList = new String[]{"Material.class", "EntityType.class", "org/bukkit/attribute/Attribute.class"} from(fat).exclude { - var name = it.toString(); + var name = it.toString() return excludeList.contains(name) } } diff --git a/Launch-External/src/main/java/org/soak/commands/soak/SoakCommand.java b/Launch-External/src/main/java/org/soak/commands/soak/SoakCommand.java index 61e66ec..e5b91f0 100644 --- a/Launch-External/src/main/java/org/soak/commands/soak/SoakCommand.java +++ b/Launch-External/src/main/java/org/soak/commands/soak/SoakCommand.java @@ -5,19 +5,19 @@ import net.kyori.adventure.text.JoinConfiguration; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextColor; -import org.bukkit.command.PluginCommand; import org.bukkit.plugin.java.JavaPlugin; import org.soak.commands.SoakArguments; -import org.soak.generate.bukkit.AttributeTypeList; import org.soak.generate.bukkit.EntityTypeList; import org.soak.generate.bukkit.MaterialList; import org.soak.plugin.SoakManager; import org.soak.plugin.SoakPlugin; import org.soak.plugin.SoakPluginContainer; +import org.spongepowered.api.Sponge; import org.spongepowered.api.block.BlockType; import org.spongepowered.api.block.BlockTypes; import org.spongepowered.api.command.Command; import org.spongepowered.api.command.CommandResult; +import org.spongepowered.api.command.manager.CommandMapping; import org.spongepowered.api.command.parameter.Parameter; import org.spongepowered.api.item.ItemType; import org.spongepowered.api.item.ItemTypes; @@ -30,30 +30,25 @@ public class SoakCommand { private static Command.Parameterized createCommandsForCommand() { - @SuppressWarnings("deprecation") Parameter.Value pluginParameter = - SoakArguments.soakPlugins( - ((context, pluginContainer) -> !pluginContainer.getBukkitInstance() - .getDescription() - .getCommands() - .isEmpty())).key("plugin").build(); + Parameter.Value pluginParameter = + SoakArguments.soakPlugins(((context, pluginContainer) -> { + var pluginContainerSponge = pluginContainer.getTrueContainer(); + return Sponge.server().commandManager().plugins().contains(pluginContainerSponge); + })).key("plugin").build(); return Command.builder().addParameter(pluginParameter).executor(context -> { SoakPluginContainer pluginContainer = context.requireOne(pluginParameter); - JavaPlugin plugin = pluginContainer.getBukkitInstance(); - //noinspection deprecation - pluginContainer.getBukkitInstance().getDescription().getCommands().keySet().forEach(cmdName -> { - PluginCommand pluginCommand = plugin.getCommand(cmdName); - if (pluginCommand == null) { - //noinspection StringConcatenationArgumentToLogCall - SoakManager.getManager() - .getLogger() - .error("plugin (" + plugin.getName() + ") has " + cmdName + " as a command in it's " + - "plugin" + ".yml yet cannot be found when receiving"); - return; - } - context.sendMessage(Identity.nil(), - Component.text(pluginCommand.getName() + ": " + pluginCommand.getDescription() + - ": " + pluginCommand.getUsage())); - }); + Sponge.server() + .commandManager() + .knownMappings() + .stream() + .filter(mapping -> mapping.plugin().isPresent()) + .filter(mapping -> mapping.plugin() + .orElseThrow() + .metadata() + .id() + .equals(pluginContainer.metadata().id())) + .map(CommandMapping::primaryAlias) + .forEach(command -> context.sendMessage(Identity.nil(), Component.text(command))); return CommandResult.success(); }).build(); } @@ -128,19 +123,6 @@ public static Command.Parameterized createEntityTypeList() { }).build(); } - public static Command.Parameterized createAttributeTypeList() { - return Command.builder().executor(context -> { - AttributeTypeList.values().stream().sorted(Comparator.comparing(Enum::name)).forEach(att -> { - String attributeType = AttributeTypeList.getAttributeType(att) - .key(RegistryTypes.ATTRIBUTE_TYPE) - .formatted(); - var component = Component.text(att.name() + "(AttributeType: " + attributeType + ")"); - context.sendMessage(component); - }); - return CommandResult.success(); - }).build(); - } - public static Command.Parameterized createMaterialItemFind() { var itemParameter = SoakArguments.registry(ItemType.class, "item", @@ -171,7 +153,6 @@ public static Command.Parameterized createSoakCommand() { .addChild(createInfoCommand(), "info") .addChild(createMaterialList(), "material") .addChild(createEntityTypeList(), "entityType", "entity") - .addChild(createAttributeTypeList(), "attributeType", "attribute") .build(); } diff --git a/Launch-External/src/main/java/org/soak/plugin/SoakPlugin.java b/Launch-External/src/main/java/org/soak/plugin/SoakPlugin.java index 7fc2f80..dde038a 100644 --- a/Launch-External/src/main/java/org/soak/plugin/SoakPlugin.java +++ b/Launch-External/src/main/java/org/soak/plugin/SoakPlugin.java @@ -6,7 +6,6 @@ import org.apache.logging.log4j.Logger; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.bukkit.Bukkit; -import org.bukkit.event.EventPriority; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; @@ -18,7 +17,10 @@ import org.soak.data.sponge.PortalCooldownCustomData; import org.soak.data.sponge.SoakKeys; import org.soak.fix.forge.ForgeFixCommons; -import org.soak.generate.bukkit.*; +import org.soak.generate.bukkit.EntityTypeList; +import org.soak.generate.bukkit.InventoryTypeList; +import org.soak.generate.bukkit.MaterialList; +import org.soak.generate.bukkit.SlotTypeList; import org.soak.hook.event.HelpMapListener; import org.soak.io.SoakServerProperties; import org.soak.plugin.external.SoakConfig; @@ -34,23 +36,16 @@ import org.soak.wrapper.v1_21_R2.NMSBounceSoakServer; import org.spongepowered.api.Server; import org.spongepowered.api.Sponge; -import org.spongepowered.api.block.transaction.Operations; import org.spongepowered.api.command.Command; import org.spongepowered.api.data.DataRegistration; import org.spongepowered.api.data.persistence.DataQuery; import org.spongepowered.api.data.persistence.DataStore; -import org.spongepowered.api.entity.living.player.server.ServerPlayer; import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.Order; -import org.spongepowered.api.event.block.ChangeBlockEvent; -import org.spongepowered.api.event.filter.cause.First; import org.spongepowered.api.event.lifecycle.*; import org.spongepowered.api.event.world.LoadWorldEvent; import org.spongepowered.api.item.inventory.ItemStack; import org.spongepowered.api.item.inventory.ItemStackSnapshot; -import org.spongepowered.api.registry.RegistryTypes; -import org.spongepowered.api.tag.BlockTypeTags; -import org.spongepowered.api.world.LocatableBlock; import org.spongepowered.configurate.ConfigurateException; import org.spongepowered.configurate.yaml.YamlConfigurationLoader; import org.spongepowered.plugin.PluginContainer; @@ -82,7 +77,7 @@ public class SoakPlugin implements SoakExternalManager, WrapperManager { private final ConsoleHandler consoleHandler = new ConsoleHandler(); @SuppressWarnings("FieldCanBeLocal") - private final int generatedClassesCount = 5; + private final int generatedClassesCount = 4; private final Collection loadedPlugins = new TreeSet<>((plugin, compare) -> { var opDepends = plugin.metadata() .dependencies() @@ -156,7 +151,7 @@ private void generateClasses(RegisterRegistryValueEvent.EngineScoped eve try { var classLoader = SoakPlugin.class.getClassLoader(); - if(MaterialList.LOADED_CLASS == null) { + if (MaterialList.LOADED_CLASS == null) { var materialList = MaterialList.createMaterialList(); MaterialList.LOADED_CLASS = materialList.load(classLoader, ClassLoadingStrategy.Default.INJECTION) .getLoaded(); @@ -164,32 +159,25 @@ private void generateClasses(RegisterRegistryValueEvent.EngineScoped eve } creatingClass = "EntityType"; - if(EntityTypeList.LOADED_CLASS == null) { + if (EntityTypeList.LOADED_CLASS == null) { var entityTypeList = EntityTypeList.createEntityTypeList(); EntityTypeList.LOADED_CLASS = entityTypeList.load(classLoader, ClassLoadingStrategy.Default.INJECTION) .getLoaded(); generatedClasses.add(EntityTypeList.LOADED_CLASS); } - creatingClass = "Attribute"; - if(AttributeTypeList.LOADED_CLASS == null) { - var attributeList = AttributeTypeList.createEntityTypeList(); - AttributeTypeList.LOADED_CLASS = attributeList.load(classLoader, ClassLoadingStrategy.Default.INJECTION) - .getLoaded(); - generatedClasses.add(AttributeTypeList.LOADED_CLASS); - } - creatingClass = "InventoryType"; - if(InventoryTypeList.LOADED_CLASS == null) { + if (InventoryTypeList.LOADED_CLASS == null) { var inventoryList = InventoryTypeList.createInventoryTypeList(); InventoryTypeList.LOADED_CLASS = inventoryList.load(classLoader, ClassLoadingStrategy.Default.INJECTION) .getLoaded(); generatedClasses.add(InventoryTypeList.LOADED_CLASS); } - if(SlotTypeList.LOADED_CLASS == null) { + if (SlotTypeList.LOADED_CLASS == null) { creatingClass = "SlotType"; - SlotTypeList.LOADED_CLASS = (Class>) Arrays.stream(InventoryTypeList.LOADED_CLASS.getDeclaredClasses()) + SlotTypeList.LOADED_CLASS = + (Class>) Arrays.stream(InventoryTypeList.LOADED_CLASS.getDeclaredClasses()) .filter(clazz -> clazz.getSimpleName().equals("SlotType")) .findFirst() .orElseThrow(); @@ -197,8 +185,7 @@ private void generateClasses(RegisterRegistryValueEvent.EngineScoped eve } } catch (MethodTooLargeException e) { throw new IllegalStateException( - "This is a problem with Bukkit's design: PaperMC seem to be making a fix with its hardfork: Too " + - "many entries in " + creatingClass, + "This is a problem with Bukkit's design: PaperMC seem to be making a fix with its hardfork: Too " + "many entries in " + creatingClass, e); } catch (Exception e) { e.printStackTrace(); @@ -260,12 +247,6 @@ public SoakServerProperties getServerProperties() { return this.serverProperties; } - @Listener - public void registerMapView(LoadWorldEvent event) { - System.out.println("Registering map view"); - RegisterUtils.registerMapView(event.world()); - } - @Override public Collection getBukkitCommands(Plugin plugin) { var pluginContainer = getSoakContainer(plugin); @@ -280,6 +261,18 @@ public boolean shouldMaterialListUseModded() { return this.configuration.shouldMaterialListUseModded(); } + @Listener + public void registerMapView(LoadWorldEvent event) { + System.out.println("Registering map view"); + RegisterUtils.registerMapView(event.world()); + } + + @Listener + public void registerLateCommand(StartedEngineEvent event) { + var server = (SoakServer) Bukkit.getServer(); + server.getCommandMap().registerStored(); + } + @Listener public void registerCommands(RegisterCommandEvent event) { event.register(this.container, SoakCommand.createSoakCommand(), "soak"); @@ -460,7 +453,7 @@ private void loadPlugins(boolean late) { loadingPlugins.forEach(container -> ((AbstractSoakPluginContainer) container).instance() .onPluginsConstructed()); if (late) { - loadingPlugins.forEach(container -> ((AbstractSoakPluginContainer) container).getBukkitInstance().onLoad()); + loadingPlugins.forEach(container -> container.getBukkitInstance().onLoad()); } } diff --git a/Launch-External/src/main/java/org/soak/plugin/loader/common/SpongeJavaPlugin.java b/Launch-External/src/main/java/org/soak/plugin/loader/common/SpongeJavaPlugin.java index c522a38..7a38378 100644 --- a/Launch-External/src/main/java/org/soak/plugin/loader/common/SpongeJavaPlugin.java +++ b/Launch-External/src/main/java/org/soak/plugin/loader/common/SpongeJavaPlugin.java @@ -23,7 +23,6 @@ import java.io.File; import java.io.InputStream; -import java.net.URI; import java.net.URL; import java.util.*; @@ -231,4 +230,9 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command @NotNull String s, @NotNull String[] strings) { return Collections.emptyList(); } + + @Override + public @NotNull String namespace() { + return this.container.metadata().id(); + } } diff --git a/Launch-Internal/build.gradle b/Launch-Internal/build.gradle index 7fa0bbd..e19d3dd 100644 --- a/Launch-Internal/build.gradle +++ b/Launch-Internal/build.gradle @@ -26,9 +26,7 @@ dependencies { implementation project(":Wrapper") implementation 'org.spongepowered:spongeapi:' + property("SPONGE_VERSION") - - implementation 'io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT' - + implementation 'io.papermc.paper:paper-api:' + property("BUKKIT_VERSION") + '.build.+' testImplementation platform('org.junit:junit-bom:5.10.0') testImplementation 'org.junit.jupiter:junit-jupiter' diff --git a/MultiBuild b/MultiBuild deleted file mode 160000 index bd28df3..0000000 --- a/MultiBuild +++ /dev/null @@ -1 +0,0 @@ -Subproject commit bd28df3aef207508c10ec9a56cffa52f036996b5 diff --git a/NMSBounce/build.gradle b/NMSBounce/build.gradle deleted file mode 100644 index ab57f6c..0000000 --- a/NMSBounce/build.gradle +++ /dev/null @@ -1,36 +0,0 @@ -plugins { - id 'java' -} - -group = 'org.soak' -version = '1.21.1.2412221049' - - -repositories { - mavenCentral() - maven { - url "https://repo.papermc.io/repository/maven-public" - } -} - -dependencies { - implementation project(":Wrapper") - implementation 'io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT' - implementation 'org.spongepowered:spongeapi:' + property("SPONGE_VERSION") - - testImplementation platform('org.junit:junit-bom:5.10.0') - testImplementation 'org.junit.jupiter:junit-jupiter' -} - -java { - sourceCompatibility = JavaVersion.VERSION_21; - targetCompatibility = JavaVersion.VERSION_21; -} - -jar { - archiveFileName = "NMSBounce.jar" -} - -test { - useJUnitPlatform() -} \ No newline at end of file diff --git a/NMSBounce/src/main/java/net/minecraft/core/HolderLookup.java b/NMSBounce/src/main/java/net/minecraft/core/HolderLookup.java deleted file mode 100644 index 37c4f3a..0000000 --- a/NMSBounce/src/main/java/net/minecraft/core/HolderLookup.java +++ /dev/null @@ -1,8 +0,0 @@ -package net.minecraft.core; - -public interface HolderLookup { - - interface a { - - } -} diff --git a/NMSBounce/src/main/java/net/minecraft/server/level/WorldServer.java b/NMSBounce/src/main/java/net/minecraft/server/level/WorldServer.java deleted file mode 100644 index 2093c4e..0000000 --- a/NMSBounce/src/main/java/net/minecraft/server/level/WorldServer.java +++ /dev/null @@ -1,7 +0,0 @@ -package net.minecraft.server.level; - -import net.minecraft.world.level.World; - -public class WorldServer extends World { - -} diff --git a/NMSBounce/src/main/java/net/minecraft/world/IInventory.java b/NMSBounce/src/main/java/net/minecraft/world/IInventory.java deleted file mode 100644 index 8c6f414..0000000 --- a/NMSBounce/src/main/java/net/minecraft/world/IInventory.java +++ /dev/null @@ -1,5 +0,0 @@ -package net.minecraft.world; - -public interface IInventory { - -} diff --git a/NMSBounce/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoal.java b/NMSBounce/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoal.java deleted file mode 100644 index 4e11653..0000000 --- a/NMSBounce/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoal.java +++ /dev/null @@ -1,4 +0,0 @@ -package net.minecraft.world.entity.ai.goal; - -public interface PathfinderGoal { -} diff --git a/NMSBounce/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalLookAtPlayer.java b/NMSBounce/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalLookAtPlayer.java deleted file mode 100644 index 9e52c90..0000000 --- a/NMSBounce/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalLookAtPlayer.java +++ /dev/null @@ -1,4 +0,0 @@ -package net.minecraft.world.entity.ai.goal; - -public interface PathfinderGoalLookAtPlayer extends PathfinderGoal{ -} diff --git a/NMSBounce/src/main/java/net/minecraft/world/item/ItemStack.java b/NMSBounce/src/main/java/net/minecraft/world/item/ItemStack.java deleted file mode 100644 index 0f14c92..0000000 --- a/NMSBounce/src/main/java/net/minecraft/world/item/ItemStack.java +++ /dev/null @@ -1,16 +0,0 @@ -package net.minecraft.world.item; - -import org.soak.wrapper.inventory.SoakItemStack; - -public class ItemStack { - - private final SoakItemStack stack; - - public ItemStack(SoakItemStack stack) { - this.stack = stack; - } - - public SoakItemStack getSoak(){ - return this.stack; - } -} diff --git a/NMSBounce/src/main/java/net/minecraft/world/item/trading/IMerchant.java b/NMSBounce/src/main/java/net/minecraft/world/item/trading/IMerchant.java deleted file mode 100644 index 8410db5..0000000 --- a/NMSBounce/src/main/java/net/minecraft/world/item/trading/IMerchant.java +++ /dev/null @@ -1,4 +0,0 @@ -package net.minecraft.world.item.trading; - -public interface IMerchant { -} diff --git a/NMSBounce/src/main/java/net/minecraft/world/level/World.java b/NMSBounce/src/main/java/net/minecraft/world/level/World.java deleted file mode 100644 index 569f4b2..0000000 --- a/NMSBounce/src/main/java/net/minecraft/world/level/World.java +++ /dev/null @@ -1,5 +0,0 @@ -package net.minecraft.world.level; - -public class World { - -} diff --git a/NMSBounce/src/main/java/net/minecraft/world/level/block/entity/TileEntityBrewingStand.java b/NMSBounce/src/main/java/net/minecraft/world/level/block/entity/TileEntityBrewingStand.java deleted file mode 100644 index 9c20640..0000000 --- a/NMSBounce/src/main/java/net/minecraft/world/level/block/entity/TileEntityBrewingStand.java +++ /dev/null @@ -1,5 +0,0 @@ -package net.minecraft.world.level.block.entity; - -public class TileEntityBrewingStand { - -} diff --git a/NMSBounce/src/main/java/net/minecraft/world/level/block/entity/TileEntityDispenser.java b/NMSBounce/src/main/java/net/minecraft/world/level/block/entity/TileEntityDispenser.java deleted file mode 100644 index 258a25f..0000000 --- a/NMSBounce/src/main/java/net/minecraft/world/level/block/entity/TileEntityDispenser.java +++ /dev/null @@ -1,5 +0,0 @@ -package net.minecraft.world.level.block.entity; - -public class TileEntityDispenser { - -} diff --git a/NMSBounce/src/main/java/net/minecraft/world/level/block/entity/TileEntityFurnaceFurnace.java b/NMSBounce/src/main/java/net/minecraft/world/level/block/entity/TileEntityFurnaceFurnace.java deleted file mode 100644 index 10cdb26..0000000 --- a/NMSBounce/src/main/java/net/minecraft/world/level/block/entity/TileEntityFurnaceFurnace.java +++ /dev/null @@ -1,5 +0,0 @@ -package net.minecraft.world.level.block.entity; - -public class TileEntityFurnaceFurnace { - -} diff --git a/NMSBounce/src/main/java/net/minecraft/world/level/block/entity/TileEntityHopper.java b/NMSBounce/src/main/java/net/minecraft/world/level/block/entity/TileEntityHopper.java deleted file mode 100644 index b591230..0000000 --- a/NMSBounce/src/main/java/net/minecraft/world/level/block/entity/TileEntityHopper.java +++ /dev/null @@ -1,5 +0,0 @@ -package net.minecraft.world.level.block.entity; - -public class TileEntityHopper { - -} diff --git a/NMSBounce/src/main/java/net/minecraft/world/level/block/state/properties/IBlockState.java b/NMSBounce/src/main/java/net/minecraft/world/level/block/state/properties/IBlockState.java deleted file mode 100644 index 73d4039..0000000 --- a/NMSBounce/src/main/java/net/minecraft/world/level/block/state/properties/IBlockState.java +++ /dev/null @@ -1,5 +0,0 @@ -package net.minecraft.world.level.block.state.properties; - -public interface IBlockState { - -} diff --git a/NMSBounce/src/main/java/net/minecraft/world/level/chunk/IChunkAccess.java b/NMSBounce/src/main/java/net/minecraft/world/level/chunk/IChunkAccess.java deleted file mode 100644 index e7e6775..0000000 --- a/NMSBounce/src/main/java/net/minecraft/world/level/chunk/IChunkAccess.java +++ /dev/null @@ -1,5 +0,0 @@ -package net.minecraft.world.level.chunk; - -public interface IChunkAccess { - -} diff --git a/NMSBounce/src/main/java/org/bukkit/craftbukkit/v1_21_R1/inventory/CraftItemStack.java b/NMSBounce/src/main/java/org/bukkit/craftbukkit/v1_21_R1/inventory/CraftItemStack.java deleted file mode 100644 index 3b9c53a..0000000 --- a/NMSBounce/src/main/java/org/bukkit/craftbukkit/v1_21_R1/inventory/CraftItemStack.java +++ /dev/null @@ -1,377 +0,0 @@ -package org.bukkit.craftbukkit.v1_21_R1.inventory; - -import io.papermc.paper.inventory.ItemRarity; -import io.papermc.paper.inventory.tooltip.TooltipContext; -import io.papermc.paper.registry.set.RegistryKeySet; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.event.HoverEvent; -import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.material.MaterialData; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.Range; -import org.jetbrains.annotations.Unmodifiable; -import org.soak.wrapper.inventory.SoakItemStack; - -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.Set; -import java.util.function.Consumer; -import java.util.function.UnaryOperator; - -/** - * Wrapper for NMSBounce Itemstack ... a wrapper for SoakItemStack .... a wrapper for Sponge Itemstack - *

- * this is why plugins shouldnt use NMS - */ -public class CraftItemStack extends ItemStack { - - private final @NotNull net.minecraft.world.item.ItemStack handle; - - public CraftItemStack(@NotNull net.minecraft.world.item.ItemStack handle) { - this.handle = handle; - } - - public CraftItemStack() { - this(new net.minecraft.world.item.ItemStack(new SoakItemStack())); - } - - @Override - public @NotNull Material getType() { - return this.handle.getSoak().getType(); - } - - @SuppressWarnings("deprecation") - @Override - @Deprecated - public void setType(@NotNull Material type) { - this.handle.getSoak().setType(type); - } - - @Override - public @NotNull ItemStack withType(@NotNull Material type) { - return this.handle.getSoak().withType(type); - } - - @Override - public int getAmount() { - return this.handle.getSoak().getAmount(); - } - - @Override - public void setAmount(int amount) { - this.handle.getSoak().setAmount(amount); - } - - @SuppressWarnings("removal") - @Override - @Deprecated - public @Nullable MaterialData getData() { - return this.handle.getSoak().getData(); - } - - @SuppressWarnings("removal") - @Override - public void setData(@Nullable MaterialData data) { - this.handle.getSoak().setData(data); - } - - @SuppressWarnings("deprecation") - @Override - @Deprecated - public short getDurability() { - return this.handle.getSoak().getDurability(); - } - - @SuppressWarnings("deprecation") - @Override - public void setDurability(short durability) { - this.handle.getSoak().setDurability(durability); - } - - @Override - public int getMaxStackSize() { - return this.handle.getSoak().getMaxStackSize(); - } - - @Override - public String toString() { - return this.handle.getSoak().toString(); - } - - @SuppressWarnings("EqualsDoesntCheckParameterClass") - @Override - public boolean equals(Object obj) { - return this.handle.getSoak().equals(obj); - } - - @Override - public boolean isSimilar(@Nullable ItemStack stack) { - return this.handle.getSoak().isSimilar(stack); - } - - @Override - public @NotNull ItemStack clone() { - return this.handle.getSoak().clone(); - } - - @Override - public int hashCode() { - return this.handle.getSoak().hashCode(); - } - - @Override - public boolean containsEnchantment(@NotNull Enchantment ench) { - return this.handle.getSoak().containsEnchantment(ench); - } - - @Override - public int getEnchantmentLevel(@NotNull Enchantment ench) { - return this.handle.getSoak().getEnchantmentLevel(ench); - } - - @Override - public @NotNull Map getEnchantments() { - return this.handle.getSoak().getEnchantments(); - } - - @Override - public void addEnchantments(@NotNull Map enchantments) { - this.handle.getSoak().addEnchantments(enchantments); - } - - @Override - public void addEnchantment(@NotNull Enchantment ench, int level) { - this.handle.getSoak().addEnchantment(ench, level); - } - - @Override - public void addUnsafeEnchantments(@NotNull Map enchantments) { - this.handle.getSoak().addUnsafeEnchantments(enchantments); - } - - @Override - public void addUnsafeEnchantment(@NotNull Enchantment ench, int level) { - this.handle.getSoak().addUnsafeEnchantment(ench, level); - } - - @Override - public int removeEnchantment(@NotNull Enchantment ench) { - return this.handle.getSoak().removeEnchantment(ench); - } - - @Override - public void removeEnchantments() { - this.handle.getSoak().removeEnchantments(); - } - - @Override - public @NotNull Map serialize() { - return this.handle.getSoak().serialize(); - } - - @Override - public boolean editMeta(@NotNull Consumer consumer) { - return this.handle.getSoak().editMeta(consumer); - } - - @Override - public boolean editMeta(@NotNull Class metaClass, @NotNull Consumer consumer) { - return this.handle.getSoak().editMeta(metaClass, consumer); - } - - @Override - public ItemMeta getItemMeta() { - return this.handle.getSoak().getItemMeta(); - } - - @Override - public boolean hasItemMeta() { - return this.handle.getSoak().hasItemMeta(); - } - - @Override - public boolean setItemMeta(@Nullable ItemMeta itemMeta) { - return this.handle.getSoak().setItemMeta(itemMeta); - } - - @SuppressWarnings("removal") - @Override - @Deprecated(forRemoval = true) - public @NotNull String getTranslationKey() { - return this.handle.getSoak().getTranslationKey(); - } - - @Override - public @NotNull ItemStack enchantWithLevels(@Range(from = 1L, to = 30L) int levels, boolean allowTreasure, - @NotNull Random random) { - return this.handle.getSoak().enchantWithLevels(levels, allowTreasure, random); - } - - @Override - public @NotNull ItemStack enchantWithLevels(@Range(from = 1L, to = 30L) int levels, - @NotNull RegistryKeySet<@NotNull Enchantment> keySet, - @NotNull Random random) { - return this.handle.getSoak().enchantWithLevels(levels, keySet, random); - } - - @Override - public @NotNull HoverEvent asHoverEvent(@NotNull UnaryOperator op) { - return this.handle.getSoak().asHoverEvent(op); - } - - @Override - public @NotNull Component displayName() { - return this.handle.getSoak().displayName(); - } - - @Override - public @NotNull ItemStack ensureServerConversions() { - return this.handle.getSoak().ensureServerConversions(); - } - - @Override - public byte[] serializeAsBytes() { - return this.handle.getSoak().serializeAsBytes(); - } - - @SuppressWarnings("deprecation") - @Override - public @Nullable String getI18NDisplayName() { - return this.handle.getSoak().getI18NDisplayName(); - } - - @SuppressWarnings("removal") - @Override - @Deprecated(forRemoval = true) - public int getMaxItemUseDuration() { - return this.handle.getSoak().getMaxItemUseDuration(); - } - - @Override - public int getMaxItemUseDuration(@NotNull LivingEntity entity) { - return this.handle.getSoak().getMaxItemUseDuration(entity); - } - - @Override - public @NotNull ItemStack asOne() { - return this.handle.getSoak().asOne(); - } - - @Override - public @NotNull ItemStack asQuantity(int qty) { - return this.handle.getSoak().asQuantity(qty); - } - - @Override - public @NotNull ItemStack add() { - return this.handle.getSoak().add(); - } - - @Override - public @NotNull ItemStack add(int qty) { - return this.handle.getSoak().add(qty); - } - - @Override - public @NotNull ItemStack subtract() { - return this.handle.getSoak().subtract(); - } - - @Override - public @NotNull ItemStack subtract(int qty) { - return this.handle.getSoak().subtract(qty); - } - - @SuppressWarnings("deprecation") - @Override - public @Nullable List getLore() { - return this.handle.getSoak().getLore(); - } - - @SuppressWarnings("deprecation") - @Override - public void setLore(@Nullable List lore) { - this.handle.getSoak().setLore(lore); - } - - @Override - public @Nullable List lore() { - return this.handle.getSoak().lore(); - } - - @Override - public void lore(@Nullable List lore) { - this.handle.getSoak().lore(lore); - } - - @Override - public void addItemFlags(@NotNull ItemFlag... itemFlags) { - this.handle.getSoak().addItemFlags(itemFlags); - } - - @Override - public void removeItemFlags(@NotNull ItemFlag... itemFlags) { - this.handle.getSoak().removeItemFlags(itemFlags); - } - - @Override - public @NotNull Set getItemFlags() { - return this.handle.getSoak().getItemFlags(); - } - - @Override - public boolean hasItemFlag(@NotNull ItemFlag flag) { - return this.handle.getSoak().hasItemFlag(flag); - } - - @Override - public @NotNull String translationKey() { - return this.handle.getSoak().translationKey(); - } - - @SuppressWarnings("removal") - @Override - @Deprecated(forRemoval = true) - public @NotNull ItemRarity getRarity() { - return this.handle.getSoak().getRarity(); - } - - @Override - public boolean isRepairableBy(@NotNull ItemStack repairMaterial) { - return this.handle.getSoak().isRepairableBy(repairMaterial); - } - - @Override - public boolean canRepair(@NotNull ItemStack toBeRepaired) { - return this.handle.getSoak().canRepair(toBeRepaired); - } - - @Override - public @NotNull ItemStack damage(int amount, @NotNull LivingEntity livingEntity) { - return this.handle.getSoak().damage(amount, livingEntity); - } - - @Override - public boolean isEmpty() { - return this.handle.getSoak().isEmpty(); - } - - @Override - public @NotNull @Unmodifiable List computeTooltipLines(@NotNull TooltipContext tooltipContext, - @Nullable Player player) { - return this.handle.getSoak().computeTooltipLines(tooltipContext, player); - } - - @Override - public @NotNull HoverEvent asHoverEvent() { - return this.handle.getSoak().asHoverEvent(); - } -} diff --git a/Override/build.gradle b/Override/build.gradle index dfcb0ca..c93f49b 100644 --- a/Override/build.gradle +++ b/Override/build.gradle @@ -21,7 +21,7 @@ repositories { dependencies { implementation 'org.spongepowered:spongeapi:' + property("SPONGE_VERSION") - implementation 'io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT' + implementation 'io.papermc.paper:paper-api:' + property("BUKKIT_VERSION") + '.build.+' } test { diff --git a/README.md b/README.md index d53684c..8d975d3 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ in short, yes but newer Pore was a Sponge plugin that allowed Bukkit plugins to run on older Sponge versions. Soak is a Sponge plugin that allows Bukkit plugins to run on Sponge API 8+ -Pore ended for a (few reasons)[https://caseif.blog/content/post.php?id=41], here are some +Pore ended for a [few reasons](https://caseif.blog/content/post.php?id=41), here are some ### Sponge has become increasing different to Bukkit @@ -52,14 +52,9 @@ This has lead to more and more plugins using pure Bukkit API code, meaning that With paper's hard fork now in place, the hope is that plugins target Paper's version of the Bukkit-API. PaperMC-API has more methods than the Spigot-API, these methods can be used in place of interacting directly with NMS. -#### NMS Bounce +#### NMS built in mappings -The Soak project has a module called ``NMSBounce``, that allows plugins that do interact with NMS to interact with Sponge -code without any changes. This works as CraftBukkit implementations of Bukkit use Mojang mappings to map the original -vanilla server.jar to human-readable code, but CraftBukkit implementations do not map the changes back. While in -NeoForge, LexForge, Sponge Vanilla and Fabric, they map the changes back. This leaves the package of ``net.minecraft.server`` -open for use. There is a little bit of Java trickery to place Soak files in place of ``net.minecraft.server`` (such as -an isolated classloader) but allows for wrapping NMS calls in Sponge API +Minecraft has started to ship Mojang mappings directly in the Jar, this means that no mappings are needed and that all Mojang implementations will have the same NMS mappings. While there maybe a few exceptions whereby Paper/Forge/etc may modify the original function, but for the most part, if a plugin calls a NMS function, then it should now work ### Many plugins that do work, wont work with Forge mods diff --git a/Wrapper/build.gradle b/Wrapper/build.gradle index 90d53e6..4dabee2 100644 --- a/Wrapper/build.gradle +++ b/Wrapper/build.gradle @@ -19,25 +19,15 @@ repositories { } } -sourceSets { - api21 { - main {} - } - generatedApi21 { - main {} - } -} - dependencies { implementation project(':Common') implementation project(':CollectionStream') implementation project(':MoseStream') - implementation project(':MultiBuild:annotations') implementation 'org.spongepowered:spongeapi:' + property("SPONGE_VERSION") implementation 'org.spongepowered:configurate-jackson:4.1.2' implementation 'org.jetbrains:annotations:26.0.1' implementation 'net.bytebuddy:byte-buddy:1.15.10' - implementation 'io.papermc.paper:paper-api:' + property("BUKKIT_VERSION") + '-R0.1-SNAPSHOT' + implementation 'io.papermc.paper:paper-api:' + property("BUKKIT_VERSION") + '.build.+' testImplementation platform('org.junit:junit-bom:5.10.0') testImplementation 'org.junit.jupiter:junit-jupiter' diff --git a/Wrapper/src/main/java/org/soak/generate/bukkit/AttributeTypeList.java b/Wrapper/src/main/java/org/soak/generate/bukkit/AttributeTypeList.java deleted file mode 100644 index 20ffa2e..0000000 --- a/Wrapper/src/main/java/org/soak/generate/bukkit/AttributeTypeList.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.soak.generate.bukkit; - -import net.bytebuddy.ByteBuddy; -import net.bytebuddy.dynamic.DynamicType; -import org.bukkit.Keyed; -import org.bukkit.Translatable; -import org.spongepowered.api.entity.attribute.type.AttributeType; -import org.spongepowered.api.entity.attribute.type.AttributeTypes; -import org.spongepowered.api.registry.RegistryTypes; - -import java.util.EnumSet; -import java.util.HashSet; - -public class AttributeTypeList { - - public static Class> LOADED_CLASS; - - public static DynamicType.Unloaded> createEntityTypeList() throws Exception { - var attributeIterator = AttributeTypes.registry().stream().iterator(); - var attributes = new HashSet(); - while (attributeIterator.hasNext()) { - var attribute = attributeIterator.next(); - var key = attribute.key(RegistryTypes.ATTRIBUTE_TYPE); - var name = CommonGenerationCode.toName(key); - attributes.add(name); - } - var classCreator = new ByteBuddy().makeEnumeration(attributes).name("org.bukkit.Attribute"); - - return classCreator.implement(Keyed.class, - Translatable.class, - net.kyori.adventure.translation.Translatable.class).make(); - } - - public static > EnumSet values() { - if (LOADED_CLASS == null) { - throw new RuntimeException("EntityTypeList.LOADED_CLASS must be set"); - } - return EnumSet.allOf((Class) LOADED_CLASS); - } - - public static > T value(AttributeType type) { - var enumName = CommonGenerationCode.toName(type.key(RegistryTypes.ATTRIBUTE_TYPE)); - EnumSet values = values(); - return values.stream() - .filter(v -> v.name().equals(enumName)) - .findAny() - .orElseThrow(() -> new RuntimeException("Found AttributeType name of '" + enumName + "' but couldnt " + - "find the enum")); - } - - public static AttributeType getAttributeType(Enum enumEntry) { - return AttributeTypes.registry() - .stream() - .filter(t -> CommonGenerationCode.toName(t.key(RegistryTypes.ATTRIBUTE_TYPE)).equals(enumEntry.name())) - .findAny() - .orElseThrow(() -> new IllegalArgumentException( - "Could not find a registered AttributeType with the enum mapped name of '" + enumEntry.name() + "'")); - } -} diff --git a/Wrapper/src/main/java/org/soak/map/SoakAttributeMap.java b/Wrapper/src/main/java/org/soak/map/SoakAttributeMap.java index 9b1e71a..d6d21cf 100644 --- a/Wrapper/src/main/java/org/soak/map/SoakAttributeMap.java +++ b/Wrapper/src/main/java/org/soak/map/SoakAttributeMap.java @@ -1,23 +1,12 @@ package org.soak.map; -import org.bukkit.attribute.Attribute; -import org.soak.generate.bukkit.AttributeTypeList; import org.spongepowered.api.entity.attribute.AttributeModifier; import org.spongepowered.api.entity.attribute.AttributeOperation; import org.spongepowered.api.entity.attribute.AttributeOperations; -import org.spongepowered.api.entity.attribute.type.AttributeType; import org.spongepowered.api.registry.DefaultedRegistryReference; public class SoakAttributeMap { - public static AttributeType toSponge(Attribute attribute) { - return AttributeTypeList.getAttributeType(attribute); - } - - public static > A toBukkit(AttributeType type) { - return AttributeTypeList.value(type); - } - public static DefaultedRegistryReference toSponge(org.bukkit.attribute.AttributeModifier.Operation operation) { return switch (operation) { case ADD_NUMBER -> AttributeOperations.ADDITION; diff --git a/Wrapper/src/main/java/org/soak/map/SoakBannerMap.java b/Wrapper/src/main/java/org/soak/map/SoakBannerMap.java deleted file mode 100644 index e2727ab..0000000 --- a/Wrapper/src/main/java/org/soak/map/SoakBannerMap.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.soak.map; - -import org.bukkit.block.banner.PatternType; -import org.spongepowered.api.data.type.BannerPatternShape; -import org.spongepowered.api.data.type.BannerPatternShapes; -import org.spongepowered.api.registry.DefaultedRegistryReference; - -public class SoakBannerMap { - - public static PatternType toBukkit(BannerPatternShape shape) { - System.err.println("Love to PatternType ByteBuddy"); - return PatternType.CREEPER; - } - - public static DefaultedRegistryReference toSpongeGetter(PatternType type) { - System.err.println("Love to PatternType ByteBuddy"); - return BannerPatternShapes.CREEPER; - } - - public static BannerPatternShape toSponge(PatternType type) { - return toSpongeGetter(type).get(); - } -} diff --git a/Wrapper/src/main/java/org/soak/map/SoakBiomeMap.java b/Wrapper/src/main/java/org/soak/map/SoakBiomeMap.java deleted file mode 100644 index 4adf8eb..0000000 --- a/Wrapper/src/main/java/org/soak/map/SoakBiomeMap.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.soak.map; - -import org.bukkit.block.Biome; -import org.spongepowered.api.registry.RegistryReference; -import org.spongepowered.api.world.biome.Biomes; - -public class SoakBiomeMap { - - public static Biome toBukkit(org.spongepowered.api.world.biome.Biome sponge) { - System.err.println("Biome requires ByteBuddy attention"); - return Biome.PLAINS; - } - - public static org.spongepowered.api.world.biome.Biome toSponge(Biome biome) { - return toSpongeGetter(biome).get(); - } - - public static RegistryReference toSpongeGetter(Biome bukkit) { - System.err.println("Biome requires ByteBuddy attention"); - return Biomes.PLAINS; - } -} diff --git a/Wrapper/src/main/java/org/soak/map/SoakBlockMap.java b/Wrapper/src/main/java/org/soak/map/SoakBlockMap.java index 899939e..4297357 100644 --- a/Wrapper/src/main/java/org/soak/map/SoakBlockMap.java +++ b/Wrapper/src/main/java/org/soak/map/SoakBlockMap.java @@ -4,22 +4,11 @@ import org.soak.generate.bukkit.MaterialList; import org.spongepowered.api.block.BlockType; -import java.util.Arrays; -import java.util.Optional; - public class SoakBlockMap { + //come on ... remove Material .... please public static Material toBukkit(BlockType type) { return MaterialList.value(type); } - //well done Paper, might just come back to paper because of that change - public static org.bukkit.block.BlockType toBukkitType(BlockType type) { - //doing this way for the time being - return toBukkit(type).asBlockType(); - } - - public static Optional toSponge(Material material) { - return MaterialList.getBlockType(material); - } } diff --git a/Wrapper/src/main/java/org/soak/map/SoakDamageMap.java b/Wrapper/src/main/java/org/soak/map/SoakDamageMap.java deleted file mode 100644 index c80bf3f..0000000 --- a/Wrapper/src/main/java/org/soak/map/SoakDamageMap.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.soak.map; - -import org.spongepowered.api.event.cause.entity.damage.DamageType; - -public class SoakDamageMap { - - public static DamageType toSponge(org.bukkit.damage.DamageType type) { - throw new RuntimeException("Not implemented yet"); - } - - public static org.bukkit.damage.DamageType toBukkit(DamageType type) { - throw new RuntimeException("Not implemented yet"); - } -} diff --git a/Wrapper/src/main/java/org/soak/map/SoakFluidTypeMap.java b/Wrapper/src/main/java/org/soak/map/SoakFluidTypeMap.java deleted file mode 100644 index 1df490a..0000000 --- a/Wrapper/src/main/java/org/soak/map/SoakFluidTypeMap.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.soak.map; - -import org.bukkit.Fluid; -import org.spongepowered.api.fluid.FluidType; -import org.spongepowered.api.fluid.FluidTypes; -import org.spongepowered.api.registry.RegistryTypes; - -public class SoakFluidTypeMap { - - public static Fluid toBukkit(FluidType type) { - if (type.equals(FluidTypes.EMPTY.get())) { - return null; - } - if (type.equals(FluidTypes.FLOWING_LAVA.get())) { - return Fluid.FLOWING_LAVA; - } - if (type.equals(FluidTypes.LAVA.get())) { - return Fluid.LAVA; - } - if (type.equals(FluidTypes.FLOWING_WATER.get())) { - return Fluid.FLOWING_WATER; - } - if (type.equals(FluidTypes.WATER.get())) { - return Fluid.WATER; - } - throw new RuntimeException("No mapping for " + type.key(RegistryTypes.FLUID_TYPE).formatted()); - } - - public static FluidType toSponge(Fluid fluid) { - return switch (fluid) { - case WATER -> FluidTypes.WATER.get(); - case FLOWING_WATER -> FluidTypes.FLOWING_WATER.get(); - case LAVA -> FluidTypes.LAVA.get(); - case FLOWING_LAVA -> FluidTypes.FLOWING_LAVA.get(); - default -> throw new RuntimeException("No mapping found for " + fluid.name()); - }; - } -} diff --git a/Wrapper/src/main/java/org/soak/map/SoakRegistryMap.java b/Wrapper/src/main/java/org/soak/map/SoakRegistryMap.java new file mode 100644 index 0000000..67dbe1a --- /dev/null +++ b/Wrapper/src/main/java/org/soak/map/SoakRegistryMap.java @@ -0,0 +1,125 @@ +package org.soak.map; + +import io.papermc.paper.registry.RegistryAccess; +import io.papermc.paper.registry.RegistryKey; +import org.bukkit.*; +import org.bukkit.attribute.Attribute; +import org.bukkit.block.banner.PatternType; +import org.bukkit.entity.Frog; +import org.bukkit.entity.Wolf; +import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.MenuType; +import org.jetbrains.annotations.NotNull; +import org.spongepowered.api.ResourceKey; +import org.spongepowered.api.block.BlockType; +import org.spongepowered.api.block.BlockTypes; +import org.spongepowered.api.data.type.*; +import org.spongepowered.api.effect.sound.music.MusicDisc; +import org.spongepowered.api.entity.attribute.type.AttributeType; +import org.spongepowered.api.entity.attribute.type.AttributeTypes; +import org.spongepowered.api.event.cause.entity.damage.DamageType; +import org.spongepowered.api.fluid.FluidType; +import org.spongepowered.api.fluid.FluidTypes; +import org.spongepowered.api.item.inventory.ContainerType; +import org.spongepowered.api.item.inventory.equipment.EquipmentType; +import org.spongepowered.api.item.inventory.equipment.EquipmentTypes; +import org.spongepowered.api.registry.DefaultedRegistryType; +import org.spongepowered.api.registry.DefaultedRegistryValue; +import org.spongepowered.api.registry.RegistryTypes; +import org.spongepowered.api.world.biome.Biome; + +public class SoakRegistryMap { + + public static > T toBukkit(Registry bukkitRegistry, + DefaultedRegistryType registryType, K spongeValue) { + return bukkitRegistry.get(SoakResourceKeyMap.mapToBukkit(spongeValue.key(registryType))); + } + + public static > T toBukkit(RegistryKey bukkitRegistryKey, + DefaultedRegistryType registryType, K spongeValue) { + return toBukkit(RegistryAccess.registryAccess().getRegistry(bukkitRegistryKey), registryType, spongeValue); + } + + public static > K toSponge(org.spongepowered.api.registry.Registry registryKey, T value) { + return toSpongeKeyed(registryKey, SoakResourceKeyMap.mapToSponge(value.key())); + } + + public static > K toSpongeKeyed(org.spongepowered.api.registry.Registry registryKey, ResourceKey key) { + return registryKey.findValue(SoakResourceKeyMap.mapToSponge(key)) + .orElseThrow(() -> new RuntimeException("Cannot find '" + key.asMinimalString() + "' from registry: " + registryKey.type() + .root() + .asMinimalString())); + } + + @Deprecated + /* + * Used when paper still uses ``enum`` for registry values + */ public static , K extends DefaultedRegistryValue> K toVanillaSponge(org.spongepowered.api.registry.Registry registryKey, T value) { + return toSpongeKeyed(registryKey, + SoakResourceKeyMap.mapToSponge(NamespacedKey.minecraft(value.name().toLowerCase()))); + } + + public static AttributeType toSponge(@NotNull Attribute attribute) { + return toSponge(AttributeTypes.registry(), attribute); + } + + public static BlockType toSpongeBlock(Material material) { + return toSponge(material.asBlockType()); + } + + public static BlockType toSponge(org.bukkit.block.BlockType type) { + return toSponge(BlockTypes.registry(), type); + } + + public static EquipmentType toSponge(@NotNull EquipmentSlot equipmentSlot) { + return toVanillaSponge(EquipmentTypes.registry(), equipmentSlot); + } + + public static MenuType toBukkit(ContainerType containerType) { + return toBukkit(Registry.MENU, RegistryTypes.CONTAINER_TYPE, containerType); + } + + public static @NotNull org.bukkit.block.Biome toBukkit(Biome spongeBiome) { + return toBukkit(RegistryKey.BIOME, RegistryTypes.BIOME, spongeBiome); + } + + public static FluidType toSponge(@NotNull Fluid item) { + return toSponge(FluidTypes.registry(), item); + } + + public static Fluid toBukkit(FluidType fluidType) { + return toBukkit(Registry.FLUID, RegistryTypes.FLUID_TYPE, fluidType); + } + + public static PatternType toBukkit(BannerPatternShape bannerPatternShape) { + return toBukkit(RegistryKey.BANNER_PATTERN, RegistryTypes.BANNER_PATTERN_SHAPE, bannerPatternShape); + } + + public static org.bukkit.damage.DamageType toBukkit(DamageType damageType) { + return toBukkit(RegistryKey.DAMAGE_TYPE, RegistryTypes.DAMAGE_TYPE, damageType); + } + + public static JukeboxSong toBukkit(MusicDisc musicDisc) { + return toBukkit(RegistryKey.JUKEBOX_SONG, RegistryTypes.MUSIC_DISC, musicDisc); + } + + public static org.bukkit.block.BlockType toBukkit(BlockType blockType) { + return toBukkit(RegistryKey.BLOCK, RegistryTypes.BLOCK_TYPE, blockType); + } + + public static Art toBukkit(ArtType artType) { + return toBukkit(Registry.ART, RegistryTypes.ART_TYPE, artType); + } + + public static MusicInstrument toBukkit(InstrumentType instrumentType) { + return toBukkit(RegistryKey.INSTRUMENT, RegistryTypes.INSTRUMENT_TYPE, instrumentType); + } + + public static Wolf.Variant toBukkit(WolfVariant wolfVariant) { + return toBukkit(RegistryKey.WOLF_VARIANT, RegistryTypes.WOLF_VARIANT, wolfVariant); + } + + public static Frog.Variant toBukkit(FrogType frogType) { + return toBukkit(RegistryKey.FROG_VARIANT, RegistryTypes.FROG_TYPE, frogType); + } +} diff --git a/Wrapper/src/main/java/org/soak/map/SoakSoundMap.java b/Wrapper/src/main/java/org/soak/map/SoakSoundMap.java index 752e312..b9e32ae 100644 --- a/Wrapper/src/main/java/org/soak/map/SoakSoundMap.java +++ b/Wrapper/src/main/java/org/soak/map/SoakSoundMap.java @@ -2,6 +2,7 @@ import net.kyori.adventure.key.Key; import org.bukkit.JukeboxSong; +import org.bukkit.Registry; import org.bukkit.Sound; import org.bukkit.SoundCategory; import org.checkerframework.checker.nullness.qual.NonNull; @@ -18,23 +19,4 @@ public static net.kyori.adventure.sound.Sound.Source toAdventure(SoundCategory c } return net.kyori.adventure.sound.Sound.Source.valueOf(category.name()); } - - public static @NonNull Key toAdventure(Sound sound) { - return sound.key(); - } - - public static SoundType toSponge(String name) { - var key = ResourceKey.minecraft(name); - return SoundTypes.registry() - .findValue(key) - .orElseThrow(() -> new RuntimeException("No direct soundtype mapping for " + key.formatted())); - } - - public static JukeboxSong toBukkit(MusicDisc disc) { - throw new RuntimeException("Not implemented yet"); - } - - public static MusicDisc toSponge(JukeboxSong song) { - throw new RuntimeException("Not implemented yet"); - } } diff --git a/Wrapper/src/main/java/org/soak/map/SoakSpawnReasonMap.java b/Wrapper/src/main/java/org/soak/map/SoakSpawnReasonMap.java index 03573a9..16f8d1a 100644 --- a/Wrapper/src/main/java/org/soak/map/SoakSpawnReasonMap.java +++ b/Wrapper/src/main/java/org/soak/map/SoakSpawnReasonMap.java @@ -6,7 +6,6 @@ import org.spongepowered.api.event.cause.entity.SpawnType; import org.spongepowered.api.event.cause.entity.SpawnTypes; import org.spongepowered.api.item.ItemTypes; -import org.spongepowered.api.registry.DefaultedRegistryReference; import org.spongepowered.api.registry.RegistryTypes; import java.util.Map; @@ -43,20 +42,4 @@ public static CreatureSpawnEvent.SpawnReason toBukkit(SpawnType type, Cause caus .orElseThrow(() -> new RuntimeException("Unknown spawn type and cause combo")); } - public static DefaultedRegistryReference toSponge(CreatureSpawnEvent.SpawnReason reason) { - return switch (reason) { - case BEEHIVE, SPAWNER, TRIAL_SPAWNER -> SpawnTypes.MOB_SPAWNER; - case EGG, SPAWNER_EGG -> SpawnTypes.SPAWN_EGG; - case BREEDING, OCELOT_BABY -> SpawnTypes.BREEDING; - case BUILD_IRONGOLEM, BUILD_SNOWMAN, BUILD_WITHER, SILVERFISH_BLOCK -> SpawnTypes.BLOCK_SPAWNING; - case ENCHANTMENT, OMINOUS_ITEM_SPAWNER, DEFAULT, POTION_EFFECT -> SpawnTypes.WORLD_SPAWNER; - case COMMAND, MOUNT, CURED, TRAP, RAID, CUSTOM, DROWNED, DUPLICATION, ENDER_PEARL, FROZEN, INFECTION, - JOCKEY, LIGHTNING, METAMORPHOSIS, NATURAL, NETHER_PORTAL, PATROL, PIGLIN_ZOMBIFIED, REINFORCEMENTS, - SHEARED, SHOULDER_ENTITY, SLIME_SPLIT, SPELL, VILLAGE_DEFENSE, VILLAGE_INVASION -> SpawnTypes.CUSTOM; - case DISPENSE_EGG -> SpawnTypes.DISPENSE; - case EXPLOSION -> SpawnTypes.TNT_IGNITE; - case CHUNK_GEN -> SpawnTypes.CHUNK_LOAD; - }; - } - } diff --git a/Wrapper/src/main/java/org/soak/map/SoakStructureMap.java b/Wrapper/src/main/java/org/soak/map/SoakStructureMap.java index 96cd228..9acf845 100644 --- a/Wrapper/src/main/java/org/soak/map/SoakStructureMap.java +++ b/Wrapper/src/main/java/org/soak/map/SoakStructureMap.java @@ -37,7 +37,7 @@ public static org.bukkit.generator.structure.Structure toBukkit(Structure struct public static org.bukkit.generator.structure.StructureType toBukkit(StructureType structure) { - NamespacedKey namespace = SoakResourceKeyMap.mapToBukkit(structure.key(RegistryTypes.STRUCTURE)); + NamespacedKey namespace = SoakResourceKeyMap.mapToBukkit(structure.key(RegistryTypes.STRUCTURE_TYPE)); Collection fakeReg = FakeRegistryHelper.getFields(org.bukkit.generator.structure.StructureType.class, org.bukkit.generator.structure.StructureType.class); var opConstant = fakeReg.stream().filter(Objects::nonNull).filter(str -> str.getKey().equals(namespace)).findAny(); //orElseGet should only be used on the register diff --git a/Wrapper/src/main/java/org/soak/map/event/entity/player/combat/SoakPlayerDeathEvent.java b/Wrapper/src/main/java/org/soak/map/event/entity/player/combat/SoakPlayerDeathEvent.java index 9790b34..47320b3 100644 --- a/Wrapper/src/main/java/org/soak/map/event/entity/player/combat/SoakPlayerDeathEvent.java +++ b/Wrapper/src/main/java/org/soak/map/event/entity/player/combat/SoakPlayerDeathEvent.java @@ -58,7 +58,7 @@ public void handle(DropItemEvent.Destruct event) throws Exception { .map(SoakItemStackMap::toBukkit) .collect(Collectors.toList()); //TODO -> find exp - var bukkitEvent = new PlayerDeathEvent(entity, bukkitDamageSource, items, 0, this.deathMessage); + var bukkitEvent = new PlayerDeathEvent(entity, bukkitDamageSource, items, 0, this.deathMessage, false); fireEvent(bukkitEvent); //TODO -> spawn the player back in if event is cancelled //TODO -> cancel/change the message diff --git a/Wrapper/src/main/java/org/soak/map/item/SoakRecipeMap.java b/Wrapper/src/main/java/org/soak/map/item/SoakRecipeMap.java index f91d5ce..e010935 100644 --- a/Wrapper/src/main/java/org/soak/map/item/SoakRecipeMap.java +++ b/Wrapper/src/main/java/org/soak/map/item/SoakRecipeMap.java @@ -14,6 +14,7 @@ import org.spongepowered.api.item.recipe.single.StoneCutterRecipe; import org.spongepowered.api.registry.RegistryTypes; +import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -23,9 +24,10 @@ public class SoakRecipeMap { public static Recipe toBukkit(org.spongepowered.api.item.recipe.Recipe recipe) { NamespacedKey key = SoakResourceKeyMap.mapToBukkit(recipe.type().key(RegistryTypes.RECIPE_TYPE)); var result = SoakItemStackMap.toBukkit(recipe.exemplaryResult()); - List inputs = recipe.ingredients(); + List inputs = new ArrayList<>(); if (recipe instanceof CookingRecipe cooking) { + inputs.add(cooking.ingredient()); var input = SoakItemStackMap.toBukkit(cooking.ingredient().displayedItems().getFirst().type()); if (cooking.type().equals(RecipeTypes.SMELTING.get())) { return new FurnaceRecipe(key, @@ -57,7 +59,8 @@ public static Recipe toBukkit(org.spongepowered.api.item.recipe.Recipe recipe } } if (recipe instanceof StoneCutterRecipe stoneCutterRecipe) { - var input = SoakItemStackMap.toBukkit(stoneCutterRecipe.ingredients().getFirst().displayedItems().getFirst().type()); + inputs.add(stoneCutterRecipe.ingredient()); + var input = SoakItemStackMap.toBukkit(stoneCutterRecipe.ingredient().displayedItems().getFirst().type()); return new StonecuttingRecipe(key, result, input); } @@ -67,6 +70,7 @@ public static Recipe toBukkit(org.spongepowered.api.item.recipe.Recipe recipe if (recipe instanceof ShapedCraftingRecipe shapedCrafting) { + inputs.addAll(shapedCrafting.ingredients()); var shaped = new ShapedRecipe(key, result); int i = 0; Map characterMap = new LinkedHashMap<>(); @@ -90,7 +94,8 @@ public static Recipe toBukkit(org.spongepowered.api.item.recipe.Recipe recipe return shaped; } - if (recipe instanceof ShapelessCraftingRecipe) { + if (recipe instanceof ShapelessCraftingRecipe shapelessCrafting) { + inputs = shapelessCrafting.ingredients(); var shapeless = new ShapelessRecipe(key, result); inputs.stream() .map(Ingredient::displayedItems) @@ -100,7 +105,7 @@ public static Recipe toBukkit(org.spongepowered.api.item.recipe.Recipe recipe .forEach(shapeless::addIngredient); return shapeless; } - throw new RuntimeException("Unknown mapping for recipetype " + recipe.type() + throw new RuntimeException("Unknown mapping for recipe type " + recipe.type() .key(RegistryTypes.RECIPE_TYPE) .formatted() + ": " + recipe.getClass().getName()); } diff --git a/Wrapper/src/main/java/org/soak/utils/RegisterUtils.java b/Wrapper/src/main/java/org/soak/utils/RegisterUtils.java index 8b9db0d..d03e89c 100644 --- a/Wrapper/src/main/java/org/soak/utils/RegisterUtils.java +++ b/Wrapper/src/main/java/org/soak/utils/RegisterUtils.java @@ -25,10 +25,12 @@ public static void registerMapViews() { } public static void registerMapView(ServerWorld world) { - var mapInfo = Sponge.server() - .mapStorage() - .createNewMapInfo() - .orElseThrow(() -> new IllegalStateException("Cannot create MapView")); + var opMapInfo = Sponge.server().mapStorage().createNewMapInfo(); + if (opMapInfo.isEmpty()) { + System.err.println("Couldnt create map view for " + world.key() + ". Did event cancel it?"); + return; + } + var mapInfo = opMapInfo.get(); mapInfo.offer(Keys.MAP_WORLD, world.key()); mapInfo.offer(Keys.MAP_TRACKS_PLAYERS, true); } diff --git a/Wrapper/src/main/java/org/soak/wrapper/SoakFluidTag.java b/Wrapper/src/main/java/org/soak/wrapper/SoakFluidTag.java index e3c0ba3..15d6833 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/SoakFluidTag.java +++ b/Wrapper/src/main/java/org/soak/wrapper/SoakFluidTag.java @@ -4,7 +4,7 @@ import org.bukkit.NamespacedKey; import org.bukkit.Tag; import org.jetbrains.annotations.NotNull; -import org.soak.map.SoakFluidTypeMap; +import org.soak.map.SoakRegistryMap; import org.soak.map.SoakResourceKeyMap; import org.soak.utils.TagHelper; import org.spongepowered.api.fluid.FluidType; @@ -14,20 +14,20 @@ public class SoakFluidTag implements Tag { - private final org.spongepowered.api.tag.Tag tag; + private final org.spongepowered.api.tag.DefaultedTag tag; - public SoakFluidTag(org.spongepowered.api.tag.Tag tag) { + public SoakFluidTag(org.spongepowered.api.tag.DefaultedTag tag) { this.tag = tag; } @Override public boolean isTagged(@NotNull Fluid item) { - return SoakFluidTypeMap.toSponge(item).is(this.tag); + return SoakRegistryMap.toSponge(item).is(this.tag); } @Override public @NotNull Set getValues() { - return TagHelper.getFluidTypes(this.tag).map(SoakFluidTypeMap::toBukkit).collect(Collectors.toSet()); + return TagHelper.getFluidTypes(this.tag).map(SoakRegistryMap::toBukkit).collect(Collectors.toSet()); } @Override diff --git a/Wrapper/src/main/java/org/soak/wrapper/SoakInternalApiBridge.java b/Wrapper/src/main/java/org/soak/wrapper/SoakInternalApiBridge.java new file mode 100644 index 0000000..45f18d2 --- /dev/null +++ b/Wrapper/src/main/java/org/soak/wrapper/SoakInternalApiBridge.java @@ -0,0 +1,88 @@ +package org.soak.wrapper; + +import com.destroystokyo.paper.SkinParts; +import io.papermc.paper.InternalAPIBridge; +import io.papermc.paper.command.brigadier.CommandSourceStack; +import io.papermc.paper.datacomponent.item.ResolvableProfile; +import io.papermc.paper.entity.poi.PoiType; +import io.papermc.paper.world.damagesource.CombatEntry; +import io.papermc.paper.world.damagesource.FallLocationType; +import net.kyori.adventure.text.Component; +import org.bukkit.GameRule; +import org.bukkit.block.Biome; +import org.bukkit.damage.DamageEffect; +import org.bukkit.damage.DamageSource; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Pose; +import org.jspecify.annotations.Nullable; +import org.soak.exception.NotImplementedException; +import org.soak.utils.Singleton; +import org.soak.wrapper.block.SoakLegacyCustomBiome; + +import java.util.Set; +import java.util.function.Function; +import java.util.function.Predicate; + +public class SoakInternalApiBridge implements InternalAPIBridge { + + private final Singleton biome = new Singleton(SoakLegacyCustomBiome::new); + + @Override + public DamageEffect getDamageEffect(String key) { + throw NotImplementedException.createByLazy(this, "getDamageEffect", String.class); + } + + @Override + public PoiType.Occupancy createOccupancy(String enumNameEntry) { + throw NotImplementedException.createByLazy(this, "createOccupancy", String.class); + } + + @Override + public Biome constructLegacyCustomBiome() { + return biome.get(); + } + + @Override + public CombatEntry createCombatEntry(LivingEntity entity, DamageSource damageSource, float damage) { + throw NotImplementedException.createByLazy(this, "createCombatEntry", LivingEntity.class); + } + + @Override + public CombatEntry createCombatEntry(DamageSource damageSource, float damage, + @Nullable FallLocationType fallLocationType, float fallDistance) { + throw NotImplementedException.createByLazy(this, "createCombatEntry", DamageSource.class); + } + + @Override + public Predicate restricted(Predicate predicate) { + throw NotImplementedException.createByLazy(this, "restricted", Predicate.class); + } + + @Override + public ResolvableProfile defaultMannequinProfile() { + throw NotImplementedException.createByLazy(this, "defaultMannequinProfile"); + } + + @Override + public SkinParts.Mutable allSkinParts() { + throw NotImplementedException.createByLazy(this, "allSkinParts"); + } + + @Override + public Component defaultMannequinDescription() { + throw NotImplementedException.createByLazy(this, "defaultMannequinDescription"); + } + + @Override + public GameRule legacyGameRuleBridge(GameRule rule, + Function fromLegacyToModern, + Function toLegacyFromModern, + Class legacyClass) { + throw NotImplementedException.createByLazy(this, "legacyGameRuleBridge", GameRule.class); + } + + @Override + public Set validMannequinPoses() { + throw NotImplementedException.createByLazy(this, "validMannequinPoses"); + } +} diff --git a/Wrapper/src/main/java/org/soak/wrapper/SoakOfflinePlayer.java b/Wrapper/src/main/java/org/soak/wrapper/SoakOfflinePlayer.java index 815b963..136f340 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/SoakOfflinePlayer.java +++ b/Wrapper/src/main/java/org/soak/wrapper/SoakOfflinePlayer.java @@ -15,6 +15,7 @@ import org.spongepowered.api.Sponge; import org.spongepowered.api.data.Keys; import org.spongepowered.api.entity.living.player.User; +import org.spongepowered.api.profile.GameProfile; import org.spongepowered.api.service.ban.Ban; import java.time.*; @@ -40,6 +41,10 @@ public SoakOfflinePlayer(@NotNull CompletableFuture futureUser) { futureUser.thenAccept(user -> this.user = user); } + public SoakOfflinePlayer(GameProfile gameProfile) { + this(Sponge.server().userManager().load(gameProfile).thenApply(optionalUser -> optionalUser.orElseThrow(() -> new RuntimeException("Cannot load user of " + gameProfile.uuid() + " but was found in cache")))); + } + public @NotNull User spongeUser() { LocalTime startTime = null; while (this.user == null) { @@ -169,38 +174,43 @@ public long getLastSeen() { return respawnLocation.asLocation().map(SoakLocationMap::toBukkit).orElse(null); } + @Override + public @org.jspecify.annotations.Nullable Location getRespawnLocation(boolean loadLocationAndValidate) { + throw NotImplementedException.createByLazy(this, "getRespawnLocation", boolean.class); + } + @Override public void incrementStatistic(@NotNull Statistic arg0, @NotNull Material arg1, int arg2) { throw NotImplementedException.createByLazy(OfflinePlayer.class, - "incrementStatistic", - Statistic.class, - Material.class, - int.class); + "incrementStatistic", + Statistic.class, + Material.class, + int.class); } @Override public void incrementStatistic(@NotNull Statistic arg0, @NotNull Material arg1) { throw NotImplementedException.createByLazy(OfflinePlayer.class, - "incrementStatistic", - Statistic.class, - Material.class); + "incrementStatistic", + Statistic.class, + Material.class); } @Override public void incrementStatistic(@NotNull Statistic arg0, @NotNull EntityType arg1) { throw NotImplementedException.createByLazy(OfflinePlayer.class, - "incrementStatistic", - Statistic.class, - EntityType.class); + "incrementStatistic", + Statistic.class, + EntityType.class); } @Override public void incrementStatistic(@NotNull Statistic arg0, @NotNull EntityType arg1, int arg2) { throw NotImplementedException.createByLazy(OfflinePlayer.class, - "incrementStatistic", - Statistic.class, - EntityType.class, - int.class); + "incrementStatistic", + Statistic.class, + EntityType.class, + int.class); } @Override @@ -211,9 +221,9 @@ public void incrementStatistic(@NotNull Statistic arg0) { @Override public void incrementStatistic(@NotNull Statistic arg0, int arg1) { throw NotImplementedException.createByLazy(OfflinePlayer.class, - "incrementStatistic", - Statistic.class, - int.class); + "incrementStatistic", + Statistic.class, + int.class); } @Override @@ -224,52 +234,52 @@ public void decrementStatistic(@NotNull Statistic arg0) { @Override public void decrementStatistic(@NotNull Statistic arg0, @NotNull Material arg1, int arg2) { throw NotImplementedException.createByLazy(OfflinePlayer.class, - "decrementStatistic", - Statistic.class, - Material.class, - int.class); + "decrementStatistic", + Statistic.class, + Material.class, + int.class); } @Override public void decrementStatistic(@NotNull Statistic arg0, @NotNull EntityType arg1) { throw NotImplementedException.createByLazy(OfflinePlayer.class, - "decrementStatistic", - Statistic.class, - EntityType.class); + "decrementStatistic", + Statistic.class, + EntityType.class); } @Override public void decrementStatistic(@NotNull Statistic arg0, @NotNull EntityType arg1, int arg2) { throw NotImplementedException.createByLazy(OfflinePlayer.class, - "decrementStatistic", - Statistic.class, - EntityType.class, - int.class); + "decrementStatistic", + Statistic.class, + EntityType.class, + int.class); } @Override public void decrementStatistic(@NotNull Statistic arg0, int arg1) { throw NotImplementedException.createByLazy(OfflinePlayer.class, - "decrementStatistic", - Statistic.class, - int.class); + "decrementStatistic", + Statistic.class, + int.class); } @Override public void decrementStatistic(@NotNull Statistic arg0, @NotNull Material arg1) { throw NotImplementedException.createByLazy(OfflinePlayer.class, - "decrementStatistic", - Statistic.class, - Material.class); + "decrementStatistic", + Statistic.class, + Material.class); } @Override public void setStatistic(@NotNull Statistic arg0, @NotNull EntityType arg1, int arg2) { throw NotImplementedException.createByLazy(OfflinePlayer.class, - "setStatistic", - Statistic.class, - EntityType.class, - int.class); + "setStatistic", + Statistic.class, + EntityType.class, + int.class); } @Override @@ -299,18 +309,18 @@ public void setStatistic(@NotNull Statistic arg0, int arg1) { @Override public void setStatistic(@NotNull Statistic arg0, @NotNull Material arg1, int arg2) { throw NotImplementedException.createByLazy(OfflinePlayer.class, - "setStatistic", - Statistic.class, - Material.class, - int.class); + "setStatistic", + Statistic.class, + Material.class, + int.class); } @Override public int getStatistic(@NotNull Statistic arg0, @NotNull Material arg1) { throw NotImplementedException.createByLazy(OfflinePlayer.class, - "getStatistic", - Statistic.class, - Material.class); + "getStatistic", + Statistic.class, + Material.class); } @Override @@ -321,9 +331,9 @@ public int getStatistic(@NotNull Statistic arg0) { @Override public int getStatistic(@NotNull Statistic arg0, @NotNull EntityType arg1) { throw NotImplementedException.createByLazy(OfflinePlayer.class, - "getStatistic", - Statistic.class, - EntityType.class); + "getStatistic", + Statistic.class, + EntityType.class); } @Override diff --git a/Wrapper/src/main/java/org/soak/wrapper/SoakRegistry.java b/Wrapper/src/main/java/org/soak/wrapper/SoakRegistry.java deleted file mode 100644 index 57e2a44..0000000 --- a/Wrapper/src/main/java/org/soak/wrapper/SoakRegistry.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.soak.wrapper; - -import org.bukkit.Keyed; -import org.bukkit.NamespacedKey; -import org.bukkit.Registry; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.soak.map.SoakResourceKeyMap; -import org.spongepowered.api.registry.DefaultedRegistryType; -import org.spongepowered.api.registry.RegistryEntry; - -import java.util.Iterator; -import java.util.function.Function; -import java.util.stream.Stream; - -public class SoakRegistry implements Registry
{ - - private final DefaultedRegistryType registryType; - private final Function map; - private final Class
bukkitType; - - public SoakRegistry(DefaultedRegistryType registryType, Class
bukkitType, Function function) { - this.registryType = registryType; - this.map = function; - this.bukkitType = bukkitType; - } - - public Class
bukkitType() { - return this.bukkitType; - } - - @Override - public @Nullable BR get(@NotNull NamespacedKey namespacedKey) { - return registryType.get().findEntry(SoakResourceKeyMap.mapToSponge(namespacedKey)).map(RegistryEntry::value).map(map).orElse(null); - } - - @Override - public @NotNull BR getOrThrow(@NotNull NamespacedKey namespacedKey) { - return stream().filter(br -> br.getKey().equals(namespacedKey)).findAny().orElseThrow(); - } - - @Override - public @NotNull Stream
stream() { - return registryType.get().stream().map(map); - } - - @Override - public @NotNull Iterator
iterator() { - return stream().iterator(); - } -} diff --git a/Wrapper/src/main/java/org/soak/wrapper/SoakServer.java b/Wrapper/src/main/java/org/soak/wrapper/SoakServer.java index ea7931b..64c6ec1 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/SoakServer.java +++ b/Wrapper/src/main/java/org/soak/wrapper/SoakServer.java @@ -3,15 +3,11 @@ import com.destroystokyo.paper.MaterialSetTag; import com.destroystokyo.paper.entity.ai.MobGoals; import com.destroystokyo.paper.profile.PlayerProfile; -import io.papermc.paper.ban.BanListType; +import io.papermc.paper.configuration.ServerConfiguration; import io.papermc.paper.datapack.DatapackManager; -import io.papermc.paper.math.Position; import io.papermc.paper.tag.EntitySetTag; import io.papermc.paper.threadedregions.scheduler.AsyncScheduler; -import io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler; -import io.papermc.paper.threadedregions.scheduler.RegionScheduler; import net.kyori.adventure.audience.Audience; -import net.kyori.adventure.key.Key; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; @@ -26,12 +22,9 @@ import org.bukkit.entity.*; import org.bukkit.event.inventory.InventoryType; import org.bukkit.generator.ChunkGenerator; -import org.bukkit.generator.structure.Structure; import org.bukkit.inventory.*; import org.bukkit.loot.LootTable; -import org.bukkit.map.MapCursor; import org.bukkit.map.MapView; -import org.bukkit.packs.DataPackManager; import org.bukkit.packs.ResourcePack; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.ServicesManager; @@ -51,16 +44,15 @@ import org.soak.exception.NotImplementedException; import org.soak.map.*; import org.soak.map.item.SoakItemStackMap; -import org.soak.map.item.SoakRecipeMap; import org.soak.plugin.SoakExternalManager; import org.soak.plugin.SoakManager; import org.soak.utils.*; import org.soak.utils.log.CustomLoggerFormat; import org.soak.wrapper.block.data.SoakBlockData; import org.soak.wrapper.command.SoakCommandMap; +import org.soak.wrapper.command.SoakCommandSender; import org.soak.wrapper.command.SoakConsoleCommandSender; import org.soak.wrapper.entity.living.human.SoakPlayer; -import org.soak.wrapper.entity.living.human.user.SoakLoadingUser; import org.soak.wrapper.help.SoakHelpMap; import org.soak.wrapper.inventory.SoakInventory; import org.soak.wrapper.inventory.SoakItemFactory; @@ -68,8 +60,13 @@ import org.soak.wrapper.plugin.SoakPluginManager; import org.soak.wrapper.plugin.messaging.SoakMessenger; import org.soak.wrapper.profile.SoakPlayerProfile; +import org.soak.wrapper.registry.ISoakRegistry; +import org.soak.wrapper.registry.SoakRegistry; import org.soak.wrapper.scheduler.SoakBukkitScheduler; -import org.soak.wrapper.world.SoakWorld; +import org.soak.wrapper.server.ServerSplitBan; +import org.soak.wrapper.server.ServerSplitItem; +import org.soak.wrapper.server.ServerSplitRegion; +import org.soak.wrapper.server.ServerSplitWorld; import org.spongepowered.api.ResourceKey; import org.spongepowered.api.Sponge; import org.spongepowered.api.block.BlockState; @@ -88,16 +85,15 @@ import org.spongepowered.api.tag.FluidTypeTags; import org.spongepowered.api.tag.ItemTypeTags; import org.spongepowered.api.world.DefaultWorldKeys; -import org.spongepowered.api.world.server.ServerWorld; import java.awt.image.BufferedImage; import java.io.File; -import java.io.IOException; import java.lang.reflect.Modifier; import java.lang.reflect.ParameterizedType; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.UnknownHostException; +import java.nio.file.Path; import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; @@ -113,7 +109,7 @@ Maybe worth splitting this out into their own managers and then using this class to redirect the call to its respected manager. */ -public abstract class SoakServer implements Server { +public class SoakServer implements Server, ServerSplitRegion, ServerSplitBan, ServerSplitWorld, ServerSplitItem { private final Supplier serverSupplier; private final Singleton messenger = @@ -124,17 +120,10 @@ public abstract class SoakServer implements Server { private final Singleton itemFactory = new Singleton<>(SoakItemFactory::new); private final Singleton scheduler = new Singleton<>(SoakBukkitScheduler::new); private final Singleton servicesManager = new Singleton<>(SimpleServicesManager::new); - private final Singleton commandMap = new Singleton<>(SoakCommandMap::new); + private final SoakCommandMap commandMapNonDeclared = new SoakCommandMap(); private final Singleton helpMap = new Singleton<>(SoakHelpMap::new); - private final Singleton> structureReg = new Singleton<>( - () -> new SoakRegistry<>(RegistryTypes.STRUCTURE, Structure.class, t -> null)); - private final Singleton> structureTypeReg = new Singleton<>( - () -> new SoakRegistry<>(RegistryTypes.STRUCTURE_TYPE, - org.bukkit.generator.structure.StructureType.class, - t -> null)); private final Singleton simplePluginManagerWrapper = new Singleton<>(() -> { - var pm = new SimplePluginManager(this, commandMap.get()); + var pm = new SimplePluginManager(this, commandMapNonDeclared); pm.paperPluginManager = pluginManager.get(); return pm; }); @@ -146,19 +135,24 @@ public abstract class SoakServer implements Server { .filter(field -> Registry.class.isAssignableFrom(field.getType())) .map(field -> { try { - var reg = (Registry) field.get(null); - return reg; + return (Registry) field.get(null); } catch (IllegalAccessException e) { throw new RuntimeException(e); } }) .filter(Objects::nonNull) - .filter(reg -> !(reg instanceof SoakRegistry)) + .filter(reg -> !(reg instanceof SoakRegistry)) .collect(Collectors.toMap(reg -> { - if (reg instanceof Registry.SimpleRegistry simpleReg) { + if (reg instanceof Registry.SimpleRegistry simpleReg) { var first = simpleReg.iterator().next(); return first.getClass(); } + if (reg instanceof ISoakRegistry soakRegistry) { + var key = soakRegistry.key(); + if (key instanceof Class clazz) { + return clazz; + } + } var generic = (ParameterizedType) reg.getClass().getGenericInterfaces()[0]; return (Class) generic.getActualTypeArguments()[0]; }, reg -> reg))); @@ -176,357 +170,16 @@ public SoakServer(Supplier serverSupplier) { this.serverSupplier = serverSupplier; } - @Override - public boolean isAcceptingTransfers() { - throw NotImplementedException.createByLazy(Server.class, "isAcceptingTransfers"); - } - - @Override - public boolean isOwnedByCurrentRegion(@NotNull World world, @NotNull Position position) { - return isOwnedByCurrentRegion(position.toLocation(world)); - } - - @Override - public boolean isOwnedByCurrentRegion(@NotNull World world, @NotNull Position position, int squareRadiusChecks) { - return isOwnedByCurrentRegion(position.toLocation(world), squareRadiusChecks); - } - - @Override - public boolean isOwnedByCurrentRegion(@NotNull Location location) { - return isOwnedByCurrentRegion(location, 1); - } - - @Override - public boolean isOwnedByCurrentRegion(@NotNull Location location, int squareRadiusChunks) { - var chunk = location.getChunk(); - return isOwnedByCurrentRegion(location.getWorld(), chunk.getX(), chunk.getZ(), squareRadiusChunks); - } - - @Override - public boolean isOwnedByCurrentRegion(@NotNull World world, int chunkX, int chunkZ) { - return isOwnedByCurrentRegion(world, chunkX, chunkZ, 1); - } - - @Override - public boolean isOwnedByCurrentRegion(@NotNull World world, int chunkX, int chunkZ, int squareRadiusChunks) { - throw NotImplementedException.createByLazy(Server.class, - "isOwnedByCurrentRegion", - World.class, - int.class, - int.class, - int.class); - } - - @Override - public boolean isOwnedByCurrentRegion(@NotNull Entity entity) { - return isOwnedByCurrentRegion(entity.getLocation()); - } - - @Override - public @NotNull RegionScheduler getRegionScheduler() { - throw NotImplementedException.createByLazy(Server.class, "getRegionScheduler"); - } - - @Override - public @NotNull AsyncScheduler getAsyncScheduler() { - throw NotImplementedException.createByLazy(Server.class, "getAsyncScheduler"); - } - - @Override - public @NotNull GlobalRegionScheduler getGlobalRegionScheduler() { - throw NotImplementedException.createByLazy(Server.class, "getGlobalRegionScheduler"); - } - - @Override - public void banIP(@NotNull InetAddress inetAddress) { - throw NotImplementedException.createByLazy(Server.class, "banIP", InetAddress.class); - } - - @Override - public void unbanIP(@NotNull InetAddress inetAddress) { - throw NotImplementedException.createByLazy(Server.class, "unbanIP", InetAddress.class); - } - - @Override - public , E> @NotNull B getBanList(@NotNull BanListType banListType) { - throw NotImplementedException.createByLazy(Server.class, "getBanList", BanListType.class); - } - - @Override - public @NotNull EntityFactory getEntityFactory() { - throw NotImplementedException.createByLazy(Server.class, "getEntityFactory"); - } - - @Override - public @NotNull ServerLinks getServerLinks() { - throw NotImplementedException.createByLazy(Server.class, "getServerLinks"); - } - - @Override - public @NotNull ItemStack craftItem(@NotNull ItemStack[] itemStacks, @NotNull World world) { - throw NotImplementedException.createByLazy(Server.class, "craftItem", ItemStack[].class, World.class); - } - - @Override - public @NotNull ItemCraftResult craftItemResult(@NotNull ItemStack[] itemStacks, @NotNull World world, - @NotNull Player player) { - throw NotImplementedException.createByLazy(Server.class, - "craftItemResult", - ItemStack[].class, - World.class, - Player.class); - } - - @Override - public @NotNull ItemCraftResult craftItemResult(@NotNull ItemStack[] itemStacks, @NotNull World world) { - throw NotImplementedException.createByLazy(Server.class, "craftItemResult", ItemStack[].class, World.class); - } - - @Override - public void updateResources() { - throw NotImplementedException.createByLazy(Server.class, "updateResources"); - } - - @Override - public void updateRecipes() { - throw NotImplementedException.createByLazy(Server.class, "updateRecipes"); - } - - @Override - public boolean removeRecipe(@NotNull NamespacedKey namespacedKey, boolean b) { - throw NotImplementedException.createByLazy(Server.class, "removeRecipe", NamespacedKey.class, boolean.class); - } - - @Override - public @Nullable ItemStack createExplorerMap(@NotNull World world, @NotNull Location location, - @NotNull org.bukkit.generator.structure.StructureType structureType, - @NotNull MapCursor.Type type, int i, boolean b) { - Bukkit bukkit; - throw NotImplementedException.createByLazy(Server.class, - "createExplorerMap", - World.class, - Location.class, - org.bukkit.generator.structure.StructureType.class, - MapCursor.Type.class, - int.class, - boolean.class); - } - public org.spongepowered.api.Server spongeServer() { return this.serverSupplier.get(); } - @Override - public @Nullable Recipe getRecipe(@NotNull NamespacedKey namespacedKey) { - throw NotImplementedException.createByLazy(Server.class, "getRecipe", NamespacedKey.class); - } - - @Override - public @NotNull List getRecipesFor(@NotNull ItemStack itemStack) { - throw NotImplementedException.createByLazy(Server.class, "getRecipesFor", ItemStack.class); - } - - @Override - public boolean unloadWorld(@NotNull String name, boolean save) { - var world = getWorld(name); - if (world == null) { - return false; - } - return unloadWorld(world, save); - } - - @Override - public @Nullable World getWorld(@NotNull Key key) { - var namespace = SoakResourceKeyMap.mapToSponge(key); - if (namespace == null) { - return null; - } - return Sponge.server() - .worldManager() - .worlds() - .stream() - .filter(world -> world.key().equals(namespace)) - .findAny() - .map(world -> SoakManager.getManager().getMemoryStore().get(world)) - .orElse(null); - } - - @Override - public @Nullable World getWorld(@NotNull String s) { - return Sponge.server() - .worldManager() - .worlds() - .stream() - .filter(world -> world.key().value().equalsIgnoreCase(s)) - .findAny() - .map(world -> SoakManager.getManager().getMemoryStore().get(world)) - .orElse(null); - } - - @Override - public @Nullable World getWorld(@NotNull UUID uuid) { - var worldManager = Sponge.server().worldManager(); - return worldManager.worldKey(uuid) - .flatMap(worldManager::world) - .map(world -> SoakManager.getManager().getMemoryStore().get(world)) - .orElse(null); - } - - @Override - public @Nullable ResourcePack getServerResourcePack() { - throw NotImplementedException.createByLazy(Server.class, "getServerResourcePack"); - } - - @Override - public boolean isLoggingIPs() { - throw NotImplementedException.createByLazy(Server.class, "isLoggingIPs"); - } - - @Override - public @NotNull ServerTickManager getServerTickManager() { - throw NotImplementedException.createByLazy(Server.class, "getServerTickManager"); - } - - @Override - public @NotNull Iterable> getTags(@NotNull String registry, @NotNull Class clazz) { - throw NotImplementedException.createByLazy(Server.class, "getTags", String.class, Class.class); - } - - @Override - public Tag getTag(@NotNull String registry, @NotNull NamespacedKey tag, - @NotNull Class clazz) { - ResourceKey key = SoakResourceKeyMap.mapToSponge(tag); - boolean classMatch = clazz.getName().equals(Material.class.getName()); - if (classMatch && registry.equals(Tag.REGISTRY_BLOCKS)) { - var opTag = FakeRegistryHelper.>getFields(BlockTypeTags.class, - org.spongepowered.api.tag.Tag.class) - .stream() - .filter(spongeTag -> spongeTag.key().equals(key)) - .findAny(); - if (opTag.isPresent()) { - //noinspection unchecked - return (Tag) (Object) new MaterialSetTag(tag, - TagHelper.getBlockTypes(opTag.get()) - .map(SoakBlockMap::toBukkit) - .collect(Collectors.toList())); - } - } - if (classMatch && registry.equals(Tag.REGISTRY_ITEMS)) { - var opTag = FakeRegistryHelper.>getFields(ItemTypeTags.class, - org.spongepowered.api.tag.Tag.class) - .stream() - .filter(spongeTag -> spongeTag.key().equals(key)) - .findAny(); - if (opTag.isPresent()) { - //noinspection unchecked - return (Tag) (Object) new MaterialSetTag(tag, - TagHelper.getItemTypes(opTag.get()) - .map(SoakItemStackMap::toBukkit) - .collect(Collectors.toList())); - } - } - if (clazz.getName().equals(EntityType.class.getName()) && registry.equals(Tag.REGISTRY_ENTITY_TYPES)) { - var opTag = - FakeRegistryHelper.>>getFields( - EntityTypeTags.class, - org.spongepowered.api.tag.Tag.class) - .stream() - .filter(spongeTag -> spongeTag.key().equals(key)) - .findAny(); - if (opTag.isPresent()) { - //noinspection unchecked - return (Tag) (Object) new EntitySetTag(tag, - TagHelper.getEntityTypes(opTag.get()) - .map(SoakEntityMap::toBukkit) - .collect(Collectors.toList())); - } - } - - - //overrides - if (registry.equals(Tag.REGISTRY_ITEMS) && tag.asString().equals("minecraft:coral_blocks")) { - //noinspection unchecked - return (Tag) (Object) new MaterialSetTag(tag, - ItemTypes.registry() - .stream() - .filter(item -> item.key(RegistryTypes.ITEM_TYPE) - .value() - .contains("coral_blocks")) - .map(SoakItemStackMap::toBukkit) - .collect(Collectors.toList())); - } - - if (registry.equals(Tag.REGISTRY_BLOCKS) && tag.asString().equals("minecraft:wool_carpets")) { - Set itemTypes = TagHelper.getBlockTypes(BlockTypeTags.WOOL_CARPETS) - .map(SoakBlockMap::toBukkit) - .collect(Collectors.toSet()); - //noinspection unchecked - return (Tag) (Object) new MaterialSetTag(tag, itemTypes); - } - - if (registry.equals(Tag.REGISTRY_ITEMS) && tag.asString().equals("minecraft:wool_carpets")) { - Set itemTypes = TagHelper.getItemTypes(ItemTypeTags.WOOL_CARPETS) - .map(SoakItemStackMap::toBukkit) - .collect(Collectors.toSet()); - //noinspection unchecked - return (Tag) (Object) new MaterialSetTag(tag, itemTypes); - - } - - if (registry.equals(Tag.REGISTRY_FLUIDS) && tag.asString().equals("minecraft:water")) { - //noinspection unchecked - return (Tag) (Object) new SoakFluidTag(FluidTypeTags.WATER); - } - - if (registry.equals(Tag.REGISTRY_FLUIDS) && tag.asString().equals("minecraft:lava")) { - //noinspection unchecked - return (Tag) (Object) new SoakFluidTag(FluidTypeTags.LAVA); - } - - if (registry.equals(Tag.REGISTRY_ITEMS) && tag.asString().equals("minecraft:crops")) { - var items = ItemTypes.registry() - .stream() - .filter(item -> org.spongepowered.api.item.inventory.ItemStack.of(item) - .get(Keys.REPLENISHED_FOOD) - .isPresent()) - .map(SoakItemStackMap::toBukkit) - .collect(Collectors.toSet()); - //noinspection unchecked - return (Tag) (Object) new MaterialSetTag(tag, items); - } - if (registry.equals(Tag.REGISTRY_ITEMS) && tag.asString().equals("minecraft:furnace_materials")) { - var items = ItemTypes.registry() - .stream() - .filter(item -> org.spongepowered.api.item.inventory.ItemStack.of(item) - .get(Keys.MAX_COOK_TIME) - .isPresent()) - .map(SoakItemStackMap::toBukkit) - .collect(Collectors.toSet()); - //noinspection unchecked - return (Tag) (Object) new MaterialSetTag(tag, items); - } - SoakManager.getManager() - .getLogger() - .warn("No tag found of registry: '" + registry + "' Type: " + clazz.getSimpleName() + " id: " + tag.asString()); - return null; - } - public void syncCommands() { //Craftbukkit public method to reregister all commands and apply to all players as well as register to brig var commandManager = this.spongeServer().commandManager(); this.spongeServer().streamOnlinePlayers().forEach(commandManager::updateCommandTreeForPlayer); } - @Override - public @NotNull Server.Spigot spigot() { - return new SoakSpigotServer(); - } - - @Override - public @NotNull File getWorldContainer() { - throw NotImplementedException.createByLazy(Server.class, "getWorldContainer"); - } - @Override public @NotNull File getPluginsFolder() { return new File("org/soak/generate/bukkit/plugins"); @@ -568,6 +221,9 @@ public void syncCommands() { .orElseThrow(() -> new RuntimeException( "No value found for last joined on a online player")))) .buildList(); + } @Override + public @NotNull AsyncScheduler getAsyncScheduler() { + throw NotImplementedException.createByLazy(Server.class, "getAsyncScheduler"); } @Override @@ -596,6 +252,9 @@ public int getViewDistance() { @Override public int getSimulationDistance() { throw NotImplementedException.createByLazy(Server.class, "getSimulationDistance"); + } @Override + public boolean isGlobalTickThread() { + throw NotImplementedException.createByLazy(this, "isGlobalTickThread"); } @Override @@ -631,6 +290,14 @@ public boolean getAllowNether() { return this.spongeServer().worldManager().world(DefaultWorldKeys.THE_NETHER).isPresent(); } + @Override + public boolean isLoggingIPs() { + throw NotImplementedException.createByLazy(Server.class, "isLoggingIPs"); + } @Override + public boolean isPaused() { + throw NotImplementedException.createByLazy(this, "isPaused"); + } + @Override public @NotNull List getInitialEnabledPacks() { throw NotImplementedException.createByLazy(Server.class, "getInitialEnabledPacks"); @@ -642,8 +309,13 @@ public boolean getAllowNether() { } @Override - public @NotNull DataPackManager getDataPackManager() { - throw NotImplementedException.createByLazy(Server.class, "getDataPackManager"); + public @NotNull ServerTickManager getServerTickManager() { + throw NotImplementedException.createByLazy(Server.class, "getServerTickManager"); + } + + @Override + public @Nullable ResourcePack getServerResourcePack() { + throw NotImplementedException.createByLazy(Server.class, "getServerResourcePack"); } @Override @@ -659,6 +331,9 @@ public boolean getAllowNether() { @Override public @NotNull String getResourcePackPrompt() { throw NotImplementedException.createByLazy(Server.class, "getResourcePackPrompt"); + } @Override + public void allowPausing(@NotNull Plugin plugin, boolean value) { + throw NotImplementedException.createByLazy(this, "allowPausing", Plugin.class, boolean.class); } @Override @@ -666,6 +341,11 @@ public boolean isResourcePackRequired() { throw NotImplementedException.createByLazy(Server.class, "isResourcePackRequired"); } + @Override + public boolean hasWhitelist() { + return this.spongeServer().isWhitelistEnabled(); + } + @Override public void setWhitelist(boolean value) { throw NotImplementedException.createByLazy(SoakServer.class, "setWhitelist", boolean.class); @@ -746,6 +426,9 @@ public int getTicksPerMonsterSpawns() { @Override public int getTicksPerWaterSpawns() { throw NotImplementedException.createByLazy(SoakServer.class, "getTicksPerWaterSpawns"); + } @Override + public @NotNull Iterable> getTags(@NotNull String registry, @NotNull Class clazz) { + throw NotImplementedException.createByLazy(Server.class, "getTags", String.class, Class.class); } @Override @@ -768,6 +451,15 @@ public int getTicksPerSpawns(@NotNull SpawnCategory spawnCategory) { throw NotImplementedException.createByLazy(Server.class, "getTicksPerSpawns", SpawnCategory.class); } + @Override + public @Nullable Player getPlayer(@NotNull String s) { + return Sponge.server() + .player(s) + .map(player -> SoakManager.getManager().getMemoryStore().get(player)) + .orElse(null); + + } + @Override public @Nullable Player getPlayerExact(@NotNull String name) { return this.getOnlinePlayers().stream().filter(player -> player.getName().equals(name)).findAny().orElse(null); @@ -785,96 +477,157 @@ public int getTicksPerSpawns(@NotNull SpawnCategory spawnCategory) { .filter(player -> player.getName().toLowerCase().startsWith(name.toLowerCase())) .map(player -> (Player) player) .toList(); - } - - @Override - public @Nullable UUID getPlayerUniqueId(@NotNull String playerName) { - Player player = getPlayerExact(playerName); - if (player == null) { - return null; + } @Override + public Tag getTag(@NotNull String registry, @NotNull NamespacedKey tag, + @NotNull Class clazz) { + ResourceKey key = SoakResourceKeyMap.mapToSponge(tag); + boolean classMatch = clazz.getName().equals(Material.class.getName()); + if (classMatch && registry.equals(Tag.REGISTRY_BLOCKS)) { + var opTag = + FakeRegistryHelper.>getFields(BlockTypeTags.class, + org.spongepowered.api.tag.DefaultedTag.class) + .stream() + .filter(spongeTag -> spongeTag.key().equals(key)) + .findAny(); + if (opTag.isPresent()) { + //noinspection unchecked + return (Tag) new MaterialSetTag(tag, + TagHelper.getBlockTypes(opTag.get()) + .map(SoakBlockMap::toBukkit) + .collect(Collectors.toList())); + } + } + if (classMatch && registry.equals(Tag.REGISTRY_ITEMS)) { + var opTag = + FakeRegistryHelper.>getFields(ItemTypeTags.class, + org.spongepowered.api.tag.DefaultedTag.class) + .stream() + .filter(spongeTag -> spongeTag.key().equals(key)) + .findAny(); + if (opTag.isPresent()) { + //noinspection unchecked + return (Tag) new MaterialSetTag(tag, + TagHelper.getItemTypes(opTag.get()) + .map(SoakItemStackMap::toBukkit) + .collect(Collectors.toList())); + } + } + if (clazz.getName().equals(EntityType.class.getName()) && registry.equals(Tag.REGISTRY_ENTITY_TYPES)) { + var opTag = + FakeRegistryHelper.>>getFields( + EntityTypeTags.class, + org.spongepowered.api.tag.DefaultedTag.class) + .stream() + .filter(spongeTag -> spongeTag.key().equals(key)) + .findAny(); + if (opTag.isPresent()) { + //noinspection unchecked + return (Tag) new EntitySetTag(tag, + TagHelper.getEntityTypes(opTag.get()) + .map(SoakEntityMap::toBukkit) + .collect(Collectors.toList())); + } } - return player.getUniqueId(); - } - @Override - public @Nullable Player getPlayer(@NotNull UUID uuid) { - return Sponge.server() - .player(uuid) - .map(player -> SoakManager.getManager().getMemoryStore().get(player)) - .orElse(null); - } - @Override - public @Nullable Player getPlayer(@NotNull String s) { - return Sponge.server() - .player(s) - .map(player -> SoakManager.getManager().getMemoryStore().get(player)) - .orElse(null); + //overrides + if (registry.equals(Tag.REGISTRY_ITEMS) && tag.asString().equals("minecraft:coral_blocks")) { + //noinspection unchecked + return (Tag) new MaterialSetTag(tag, + ItemTypes.registry() + .stream() + .filter(item -> item.key(RegistryTypes.ITEM_TYPE) + .value() + .contains("coral_blocks")) + .map(SoakItemStackMap::toBukkit) + .collect(Collectors.toList())); + } - } + if (registry.equals(Tag.REGISTRY_BLOCKS) && tag.asString().equals("minecraft:wool_carpets")) { + Set itemTypes = TagHelper.getBlockTypes(BlockTypeTags.WOOL_CARPETS) + .map(SoakBlockMap::toBukkit) + .collect(Collectors.toSet()); + //noinspection unchecked + return (Tag) new MaterialSetTag(tag, itemTypes); + } - public @NotNull SoakPluginManager getSoakPluginManager() { - return this.pluginManager.get(); - } + if (registry.equals(Tag.REGISTRY_ITEMS) && tag.asString().equals("minecraft:wool_carpets")) { + Set itemTypes = TagHelper.getItemTypes(ItemTypeTags.WOOL_CARPETS) + .map(SoakItemStackMap::toBukkit) + .collect(Collectors.toSet()); + //noinspection unchecked + return (Tag) new MaterialSetTag(tag, itemTypes); - @Override - public @NotNull SimplePluginManager getPluginManager() { - return this.simplePluginManagerWrapper.get(); - } + } - @Override - public @NotNull BukkitScheduler getScheduler() { - return this.scheduler.get(); - } + if (registry.equals(Tag.REGISTRY_FLUIDS) && tag.asString().equals("minecraft:water")) { + //noinspection unchecked + return (Tag) new SoakFluidTag(FluidTypeTags.WATER); + } - @Override - public @NotNull ServicesManager getServicesManager() { - return this.servicesManager.get(); + if (registry.equals(Tag.REGISTRY_FLUIDS) && tag.asString().equals("minecraft:lava")) { + //noinspection unchecked + return (Tag) new SoakFluidTag(FluidTypeTags.LAVA); + } + + if (registry.equals(Tag.REGISTRY_ITEMS) && tag.asString().equals("minecraft:crops")) { + var items = ItemTypes.registry() + .stream() + .filter(item -> org.spongepowered.api.item.inventory.ItemStack.of(item) + .get(Keys.REPLENISHED_FOOD) + .isPresent()) + .map(SoakItemStackMap::toBukkit) + .collect(Collectors.toSet()); + //noinspection unchecked + return (Tag) new MaterialSetTag(tag, items); + } + if (registry.equals(Tag.REGISTRY_ITEMS) && tag.asString().equals("minecraft:furnace_materials")) { + var items = ItemTypes.registry() + .stream() + .filter(item -> org.spongepowered.api.item.inventory.ItemStack.of(item) + .get(Keys.MAX_COOK_TIME) + .isPresent()) + .map(SoakItemStackMap::toBukkit) + .collect(Collectors.toSet()); + //noinspection unchecked + return (Tag) new MaterialSetTag(tag, items); + } + SoakManager.getManager() + .getLogger() + .warn("No tag found of registry: '" + registry + "' Type: " + clazz.getSimpleName() + " id: " + tag.asString()); + return null; } @Override - public @NotNull List getWorlds() { - var builder = CollectionStreamBuilder.builder() - .collection(this.spongeServer().worldManager().worlds()) - .basicMap(world -> (World) SoakManager.getManager().getMemoryStore().get(world)); - return ListMappingUtils.fromStream(builder, - () -> this.spongeServer().worldManager().worlds().stream(), - (spongeWorld, soakWorld) -> ((SoakWorld) soakWorld).sponge() - .equals(spongeWorld), - Comparator.comparing(world -> world.key().formatted())).buildList(); + public @Nullable Player getPlayer(@NotNull UUID uuid) { + return Sponge.server() + .player(uuid) + .map(player -> SoakManager.getManager().getMemoryStore().get(player)) + .orElse(null); } @Override - public boolean isTickingWorlds() { - throw NotImplementedException.createByLazy(Server.class, "isTickingWorlds"); + public @Nullable UUID getPlayerUniqueId(@NotNull String playerName) { + Player player = getPlayerExact(playerName); + if (player == null) { + return null; + } + return player.getUniqueId(); } @Override - public @Nullable World createWorld(@NotNull WorldCreator creator) { - throw NotImplementedException.createByLazy(SoakServer.class, "createWorld", WorldCreator.class); + public @NotNull SimplePluginManager getPluginManager() { + return this.simplePluginManagerWrapper.get(); } @Override - public boolean unloadWorld(@NotNull World world, boolean save) { - var spongeWorld = ((SoakWorld) world).sponge(); - if (save) { - try { - spongeWorld.save(); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - var worldManager = this.spongeServer().worldManager(); - try { - return worldManager.unloadWorld(spongeWorld).get(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } + public @NotNull BukkitScheduler getScheduler() { + return this.scheduler.get(); } @Override - public @NotNull WorldBorder createWorldBorder() { - throw NotImplementedException.createByLazy(Server.class, "createWorldBorder"); + public @NotNull ServicesManager getServicesManager() { + return this.servicesManager.get(); } @Override @@ -910,6 +663,9 @@ public boolean unloadWorld(@NotNull World world, boolean save) { World.class, Location.class, StructureType.class); + } @Override + public @NotNull Server.Spigot spigot() { + return new SoakSpigotServer(); } @Override @@ -938,6 +694,16 @@ public void reloadData() { throw NotImplementedException.createByLazy(SoakServer.class, "reloadData"); } + @Override + public void updateResources() { + throw NotImplementedException.createByLazy(Server.class, "updateResources"); + } + + @Override + public @NotNull java.util.logging.Logger getLogger() { + return this.logger; + } + @Override public @Nullable PluginCommand getPluginCommand(@NotNull String name) { PluginCommand pluginCommand = SoakManager.getManager() @@ -968,117 +734,107 @@ public void reloadData() { @Override public void savePlayers() { throw NotImplementedException.createByLazy(SoakServer.class, "savePlayers"); + } @Override + public void restart() { + throw NotImplementedException.createByLazy(this, "restart"); } @Override public boolean dispatchCommand(@NotNull CommandSender sender, @NotNull String commandLine) throws CommandException { - throw NotImplementedException.createByLazy(SoakServer.class, - "dispatchCommand", - CommandSender.class, - String.class); - } - - @Override - public boolean addRecipe(@Nullable Recipe recipe) { - return addRecipe(recipe, false); - } - - @Override - public boolean addRecipe(@Nullable Recipe recipe, boolean resendRecipes) { - throw NotImplementedException.createByLazy(SoakServer.class, "addRecipe", Recipe.class, boolean.class); + var soakSender = (SoakCommandSender) sender; + try { + var result = Sponge.server() + .commandManager() + .process(soakSender.getSubject(), soakSender.getAudience(), commandLine); + return result.isSuccess(); + } catch (org.spongepowered.api.command.exception.CommandException e) { + throw new CommandException(e.getMessage(), e); + } } @Override - public @Nullable Recipe getCraftingRecipe(@NotNull ItemStack[] itemStacks, @NotNull World world) { - throw NotImplementedException.createByLazy(Server.class, "getCraftingRecipe", ItemStack.class, World.class); + public @NotNull Map getCommandAliases() { + return Sponge.server() + .commandManager() + .knownMappings() + .stream() + .collect(Collectors.toMap(t -> t.primaryAlias(), t -> t.allAliases().toArray(String[]::new))); } @Override - public @NotNull ItemStack craftItem(@NotNull ItemStack[] itemStacks, @NotNull World world, @NotNull Player player) { - throw NotImplementedException.createByLazy(Server.class, - "craftItem", - ItemStack.class, - World.class, - Player.class); + public int getSpawnRadius() { + return SoakManager.getManager().getServerProperties().spawnProtection().orElse(); } @Override - public @NotNull Iterator recipeIterator() { - return Sponge.server().recipeManager().all().stream().map(recipe -> { - try { - return SoakRecipeMap.toBukkit(recipe); - } catch (RuntimeException e) { - e.printStackTrace(); - return null; - } - }).filter(Objects::nonNull).iterator(); + public void setSpawnRadius(int value) { + SoakManager.getManager().getServerProperties().spawnProtection().setMemoryValue(value); } @Override - public void clearRecipes() { - throw NotImplementedException.createByLazy(SoakServer.class, "clearRecipes"); + public boolean shouldSendChatPreviews() { + throw NotImplementedException.createByLazy(Server.class, "shouldSendChatPreviews"); } @Override - public void resetRecipes() { - throw NotImplementedException.createByLazy(SoakServer.class, "resetRecipes"); + public boolean isEnforcingSecureProfiles() { + throw NotImplementedException.createByLazy(Server.class, "isEnforcingSecureProfiles"); } @Override - public boolean removeRecipe(@NotNull NamespacedKey key) { - throw NotImplementedException.createByLazy(Server.class, "removeRecipe", NamespacedKey.class); + public boolean isAcceptingTransfers() { + throw NotImplementedException.createByLazy(Server.class, "isAcceptingTransfers"); } @Override - public @NotNull Map getCommandAliases() { - throw NotImplementedException.createByLazy(SoakServer.class, "getCommandAliases", Map.class); - } - - public ServerWorld defaultWorld() { - return this.spongeServer() - .worldManager() - .world(DefaultWorldKeys.DEFAULT) - .orElseThrow(() -> new RuntimeException("default world is not loaded")); + public boolean getHideOnlinePlayers() { + throw NotImplementedException.createByLazy(Server.class, "getHideOnlinePlayers"); } @Override - public int getSpawnRadius() { - return SoakManager.getManager().getServerProperties().spawnProtection().orElse(); + public boolean getOnlineMode() { + return this.spongeServer().isOnlineModeEnabled(); } @Override - public void setSpawnRadius(int value) { - SoakManager.getManager().getServerProperties().spawnProtection().setMemoryValue(value); + public @NotNull ServerConfiguration getServerConfig() { + throw NotImplementedException.createByLazy(this, "getServerConfig"); } @Override - public boolean shouldSendChatPreviews() { - throw NotImplementedException.createByLazy(Server.class, "shouldSendChatPreviews"); + public boolean getAllowFlight() { + throw NotImplementedException.createByLazy(SoakServer.class, "getAllowFlight"); } @Override - public boolean isEnforcingSecureProfiles() { - throw NotImplementedException.createByLazy(Server.class, "isEnforcingSecureProfiles"); + public boolean isHardcore() { + return this.spongeServer().isHardcoreModeEnabled(); } @Override - public boolean getHideOnlinePlayers() { - throw NotImplementedException.createByLazy(Server.class, "getHideOnlinePlayers"); + public void shutdown() { + this.spongeServer().shutdown(); } + @Deprecated @Override - public boolean getOnlineMode() { - return this.spongeServer().isOnlineModeEnabled(); + public int broadcast(@NotNull String arg0, @NotNull String arg1) { + return broadcast(SoakMessageMap.toComponent(arg0), arg1); } @Override - public boolean getAllowFlight() { - throw NotImplementedException.createByLazy(SoakServer.class, "getAllowFlight"); + public int broadcast(@NotNull Component message) { + Audience audience = this.spongeServer().broadcastAudience(); + AtomicInteger count = new AtomicInteger(); + audience.forEachAudience((au) -> count.set(count.get() + 1)); + audience.sendMessage(message); + return count.get(); } @Override - public boolean isHardcore() { - return this.spongeServer().isHardcoreModeEnabled(); + public int broadcast(@NotNull Component message, @NotNull String from) { + var newComponent = Component.text("[" + from + "] ").color(NamedTextColor.GOLD).append(message); + return broadcast(newComponent); } @Override @@ -1220,6 +976,11 @@ public void setDefaultGameMode(@NotNull GameMode arg0) { throw NotImplementedException.createByLazy(Server.class, "setDefaultGameMode", GameMode.class); } + @Override + public boolean forcesDefaultGameMode() { + throw NotImplementedException.createByLazy(this, "forcesDefaultGameMode"); + } + @Override public @NotNull ConsoleCommandSender getConsoleSender() { return new SoakConsoleCommandSender(); @@ -1230,9 +991,19 @@ public void setDefaultGameMode(@NotNull GameMode arg0) { throw NotImplementedException.createByLazy(Server.class, "createCommandSender", Consumer.class); } + @Override + public @NotNull File getWorldContainer() { + throw NotImplementedException.createByLazy(Server.class, "getWorldContainer"); + } + + @Override + public @NotNull Path getLevelDirectory() { + throw NotImplementedException.createByLazy(Server.class, "getLevelDirectory"); + } + @Override public OfflinePlayer[] getOfflinePlayers() { - return Sponge.server().userManager().streamAll().map(SoakLoadingUser::new).toArray(OfflinePlayer[]::new); + return Sponge.server().userManager().streamAll().map(SoakOfflinePlayer::new).toArray(OfflinePlayer[]::new); } @Override @@ -1279,23 +1050,17 @@ public OfflinePlayer[] getOfflinePlayers() { return createChestInventory(arg0, arg1, arg2); } - private Inventory createChestInventory(InventoryHolder holder, int size, @Nullable Component title) { - int rows = (size / 9); - var containerType = InventoryHelper.toChestContainerType(rows); - var plugin = GeneralHelper.fromStackTrace(); - var inventory = ViewableInventory.builder().type(containerType).completeStructure().plugin(plugin).build(); - //TODO holder - var bukkitInv = new SoakInventory<>(inventory); - bukkitInv.setRequestedTitle(title); - return bukkitInv; - } - @Deprecated @Override public @NotNull Inventory createInventory(InventoryHolder arg0, int arg1, @NotNull String arg2) { return createInventory(arg0, arg1, SoakMessageMap.toComponent(arg2)); } + @Override + public @NotNull Merchant createMerchant(Component arg0) { + throw NotImplementedException.createByLazy(Server.class, "createMerchant", Component.class); + } + @Deprecated @Override public @NotNull Merchant createMerchant(String arg0) { @@ -1308,8 +1073,8 @@ public int getMaxChainedNeighborUpdates() { } @Override - public @NotNull Merchant createMerchant(Component arg0) { - throw NotImplementedException.createByLazy(Server.class, "createMerchant", Component.class); + public @NotNull Merchant createMerchant() { + throw NotImplementedException.createByLazy(this, "createMerchant"); } @Override @@ -1352,14 +1117,19 @@ public boolean isPrimaryThread() { return this.spongeServer().onMainThread(); } + @Override + public @NotNull Component motd() { + return this.spongeServer().motd(); + } + @Override public void motd(@NotNull Component component) { throw NotImplementedException.createByLazy(Server.class, "motd", Component.class); } @Override - public @NotNull Component motd() { - return this.spongeServer().motd(); + public Component shutdownMessage() { + throw NotImplementedException.createByLazy(Server.class, "shutdownMessage"); } @Deprecated @@ -1374,8 +1144,8 @@ public void setMotd(@NotNull String s) { } @Override - public Component shutdownMessage() { - throw NotImplementedException.createByLazy(Server.class, "shutdownMessage"); + public @NotNull ServerLinks getServerLinks() { + throw NotImplementedException.createByLazy(Server.class, "getServerLinks"); } @Deprecated @@ -1394,6 +1164,11 @@ public String getShutdownMessage() { return this.itemFactory.get(); } + @Override + public @NotNull EntityFactory getEntityFactory() { + throw NotImplementedException.createByLazy(Server.class, "getEntityFactory"); + } + @Override public @NotNull ScoreboardManager getScoreboardManager() { throw NotImplementedException.createByLazy(Server.class, "getScoreboardManager"); @@ -1409,21 +1184,82 @@ public CachedServerIcon getServerIcon() { throw NotImplementedException.createByLazy(Server.class, "getServerIcon"); } + @Override + public @NotNull CachedServerIcon loadServerIcon(@NotNull File arg0) { + throw NotImplementedException.createByLazy(Server.class, "loadServerIcon", File.class); + } + @Override public @NotNull CachedServerIcon loadServerIcon(@NotNull BufferedImage arg0) { throw NotImplementedException.createByLazy(Server.class, "loadServerIcon", BufferedImage.class); } + public @NotNull SoakPluginManager getSoakPluginManager() { + return this.pluginManager.get(); + } + + private Inventory createChestInventory(InventoryHolder holder, int size, @Nullable Component title) { + int rows = (size / 9); + var containerType = InventoryHelper.toChestContainerType(rows); + var plugin = GeneralHelper.fromStackTrace(); + var inventory = ViewableInventory.builder().type(containerType).completeStructure().plugin(plugin).build(); + //TODO holder + var bukkitInv = new SoakInventory<>(inventory); + bukkitInv.setRequestedTitle(title); + return bukkitInv; + } + @Override - public @NotNull CachedServerIcon loadServerIcon(@NotNull File arg0) { - throw NotImplementedException.createByLazy(Server.class, "loadServerIcon", File.class); + public @NotNull Iterable audiences() { + return this.spongeServer().audiences(); + } + + @Override + public void sendPluginMessage(@NotNull Plugin source, @NotNull String channel, byte[] message) { + throw NotImplementedException.createByLazy(Server.class, + "sendPluginMessage", + Plugin.class, + String.class, + byte[].class); + } + + @Override + public @NotNull Set getListeningPluginChannels() { + throw NotImplementedException.createByLazy(Server.class, "getListeningPluginChannels"); } + + + + + + + + + + + + + + + + @Override public int getIdleTimeout() { throw NotImplementedException.createByLazy(Server.class, "getIdleTimeout"); } + @Override + public int getPauseWhenEmptyTime() { + throw NotImplementedException.createByLazy(this, "getPauseWhenEmptyTime"); + } + + @Override + public void setPauseWhenEmptyTime(int seconds) { + throw NotImplementedException.createByLazy(this, "setPauseWhenEmptyTime", int.class); + } + + @Override public void setIdleTimeout(int arg0) { throw NotImplementedException.createByLazy(Server.class, "setIdleTimeout", int.class); @@ -1493,7 +1329,7 @@ public double getAverageTickTime() { @Override public @NotNull SoakCommandMap getCommandMap() { - return this.commandMap.get(); + return this.commandMapNonDeclared; } @Override @@ -1530,10 +1366,7 @@ public Advancement getAdvancement(@NotNull NamespacedKey arg0) { return createBlockData(material); } if (s.startsWith("[")) { - s = SoakBlockMap.toSponge(material) - .orElseThrow(() -> new IllegalStateException("Item cannot be converted to BlockState")) - .key(RegistryTypes.BLOCK_TYPE) - .formatted() + s; + s = SoakRegistryMap.toSpongeBlock(material).key(RegistryTypes.BLOCK_TYPE).formatted() + s; } var blockState = BlockState.fromString(s); return new SoakBlockData(blockState); @@ -1567,12 +1400,6 @@ public LootTable getLootTable(@NotNull NamespacedKey arg0) { @Override public @Nullable Registry getRegistry(@NotNull Class aClass) { - if (aClass.isAssignableFrom(Structure.class)) { - return (Registry) structureReg.get(); - } - if (aClass.isAssignableFrom(org.bukkit.generator.structure.StructureType.class)) { - return (Registry) structureTypeReg.get(); - } return (Registry) this.registries.get().get(aClass); } @@ -1696,15 +1523,6 @@ public boolean isStopping() { throw NotImplementedException.createByLazy(Server.class, "getPotionBrewer"); } - @Override - public boolean hasWhitelist() { - return this.spongeServer().isWhitelistEnabled(); - } - - @Override - public void shutdown() { - this.spongeServer().shutdown(); - } @Deprecated @Override @@ -1712,48 +1530,5 @@ public void shutdown() { return this.unsafeValues.get(); } - @Override - public @NotNull java.util.logging.Logger getLogger() { - return this.logger; - } - - @Deprecated - @Override - public int broadcast(@NotNull String arg0, @NotNull String arg1) { - return broadcast(SoakMessageMap.toComponent(arg0), arg1); - } - - @Override - public int broadcast(@NotNull Component message, @NotNull String from) { - var newComponent = Component.text("[" + from + "] ").color(NamedTextColor.GOLD).append(message); - return broadcast(newComponent); - } - - @Override - public int broadcast(@NotNull Component message) { - Audience audience = this.spongeServer().broadcastAudience(); - AtomicInteger count = new AtomicInteger(); - audience.forEachAudience((au) -> count.set(count.get() + 1)); - audience.sendMessage(message); - return count.get(); - } - - @Override - public @NotNull Iterable audiences() { - return this.spongeServer().audiences(); - } - - @Override - public void sendPluginMessage(@NotNull Plugin source, @NotNull String channel, byte[] message) { - throw NotImplementedException.createByLazy(Server.class, - "sendPluginMessage", - Plugin.class, - String.class, - byte[].class); - } - @Override - public @NotNull Set getListeningPluginChannels() { - throw NotImplementedException.createByLazy(Server.class, "getListeningPluginChannels"); - } } diff --git a/Wrapper/src/main/java/org/soak/wrapper/SoakUnsafeValues.java b/Wrapper/src/main/java/org/soak/wrapper/SoakUnsafeValues.java index dd17ac8..9431a4f 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/SoakUnsafeValues.java +++ b/Wrapper/src/main/java/org/soak/wrapper/SoakUnsafeValues.java @@ -2,11 +2,13 @@ import com.google.common.collect.Multimap; import com.google.gson.JsonObject; +import io.papermc.paper.entity.EntitySerializationFlag; import io.papermc.paper.inventory.tooltip.TooltipContext; import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager; -import io.papermc.paper.registry.tag.Tag; -import io.papermc.paper.registry.tag.TagKey; +import io.papermc.paper.registry.RegistryAccess; +import io.papermc.paper.registry.RegistryKey; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.flattener.ComponentFlattener; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; @@ -20,7 +22,6 @@ import org.bukkit.attribute.AttributeModifier; import org.bukkit.block.data.BlockData; import org.bukkit.command.CommandSender; -import org.bukkit.damage.DamageEffect; import org.bukkit.damage.DamageSource; import org.bukkit.damage.DamageType; import org.bukkit.entity.Entity; @@ -35,9 +36,9 @@ import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.potion.PotionType; -import org.checkerframework.checker.units.qual.N; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jspecify.annotations.NonNull; import org.soak.exception.NotImplementedException; import org.soak.generate.bukkit.MaterialList; import org.soak.map.item.SoakItemStackMap; @@ -93,16 +94,11 @@ public LegacyComponentSerializer legacyComponentSerializer() { public Component resolveWithContext(Component component, CommandSender commandSender, Entity entity, boolean b) throws IOException { throw NotImplementedException.createByLazy(UnsafeValues.class, - "resolveWithContext", - Component.class, - CommandSender.class, - Entity.class, - boolean.class); - } - - @Override - public void reportTimings() { - throw NotImplementedException.createByLazy(UnsafeValues.class, "reportTimings"); + "resolveWithContext", + Component.class, + CommandSender.class, + Entity.class, + boolean.class); } @Override @@ -220,9 +216,9 @@ public byte[] processClass(PluginDescriptionFile arg0, String arg1, byte[] arg2) @Override public Advancement loadAdvancement(NamespacedKey arg0, String arg1) { throw NotImplementedException.createByLazy(UnsafeValues.class, - "loadAdvancement", - NamespacedKey.class, - String.class); + "loadAdvancement", + NamespacedKey.class, + String.class); } @Override @@ -234,9 +230,9 @@ public boolean removeAdvancement(NamespacedKey arg0) { public Multimap getDefaultAttributeModifiers(Material material, EquipmentSlot equipmentSlot) { throw NotImplementedException.createByLazy(UnsafeValues.class, - "getDefaultAttributeModifiers", - Material.class, - EquipmentSlot.class); + "getDefaultAttributeModifiers", + Material.class, + EquipmentSlot.class); } @Override @@ -254,11 +250,6 @@ public String getItemTranslationKey(Material material) { throw NotImplementedException.createByLazy(UnsafeValues.class, "getItemTranslationKey", Material.class); } - @Override - public String getTimingsServerName() { - throw NotImplementedException.createByLazy(UnsafeValues.class, "getTimingsServerName"); - } - @Override public byte[] serializeItem(ItemStack arg0) { throw NotImplementedException.createByLazy(UnsafeValues.class, "serializeItem", ItemStack.class); @@ -284,13 +275,23 @@ public byte[] serializeEntity(Entity entity) { throw NotImplementedException.createByLazy(UnsafeValues.class, "serializeEntity", Entity.class); } + @Override + public byte @NotNull [] serializeEntity(@NotNull Entity entity, @NonNull @NotNull EntitySerializationFlag... serializationFlags) { + return new byte[0]; + } + @Override public Entity deserializeEntity(byte[] bytes, World world, boolean b) { throw NotImplementedException.createByLazy(UnsafeValues.class, - "deserializeEntity", - byte.class, - World.class, - boolean.class); + "deserializeEntity", + byte.class, + World.class, + boolean.class); + } + + @Override + public @NotNull Entity deserializeEntity(byte @NotNull [] data, @NotNull World world, boolean preserveUUID, boolean preservePassengers) { + return null; } @Override @@ -308,11 +309,6 @@ public PotionType.InternalPotionData getInternalPotionData(NamespacedKey namespa throw NotImplementedException.createByLazy(UnsafeValues.class, "getInternalPotionData", NamespacedKey.class); } - @Override - public @Nullable DamageEffect getDamageEffect(@NotNull String s) { - throw NotImplementedException.createByLazy(UnsafeValues.class, "getDamageEffect", String.class); - } - @Override @NotNull public DamageSource.Builder createDamageSourceBuilder(@NotNull DamageType damageType) { @@ -325,8 +321,8 @@ public String get(Class aClass, String s) { } @Override - public B get(Registry registry, NamespacedKey namespacedKey) { - throw NotImplementedException.createByLazy(UnsafeValues.class, "get", Registry.class, NamespacedKey.class); + public @org.jspecify.annotations.Nullable B get(RegistryKey registry, NamespacedKey key) { + return RegistryAccess.registryAccess().getRegistry(registry).get(key); } @Override @@ -347,9 +343,9 @@ public int nextEntityId() { @Override public boolean isValidRepairItemStack(@NotNull ItemStack arg0, @NotNull ItemStack arg1) { throw NotImplementedException.createByLazy(UnsafeValues.class, - "isValidRepairItemStack", - ItemStack.class, - ItemStack.class); + "isValidRepairItemStack", + ItemStack.class, + ItemStack.class); } @Override @@ -360,36 +356,36 @@ public int getProtocolVersion() { @Override public boolean hasDefaultEntityAttributes(@NotNull NamespacedKey namespacedKey) { throw NotImplementedException.createByLazy(UnsafeValues.class, - "hasDefaultEntityAttributes", - NamespacedKey.class); + "hasDefaultEntityAttributes", + NamespacedKey.class); } @Override public @NotNull Attributable getDefaultEntityAttributes(@NotNull NamespacedKey namespacedKey) { throw NotImplementedException.createByLazy(UnsafeValues.class, - "getDefaultEntityAttributes", - NamespacedKey.class); + "getDefaultEntityAttributes", + NamespacedKey.class); } @Override public @NotNull NamespacedKey getBiomeKey(RegionAccessor regionAccessor, int i, int i1, int i2) { throw NotImplementedException.createByLazy(UnsafeValues.class, - "setBiomeKey", - RegionAccessor.class, - int.class, - int.class, - int.class); + "setBiomeKey", + RegionAccessor.class, + int.class, + int.class, + int.class); } @Override public void setBiomeKey(RegionAccessor regionAccessor, int i, int i1, int i2, NamespacedKey namespacedKey) { throw NotImplementedException.createByLazy(UnsafeValues.class, - "setBiomeKey", - RegionAccessor.class, - int.class, - int.class, - int.class, - NamespacedKey.class); + "setBiomeKey", + RegionAccessor.class, + int.class, + int.class, + int.class, + NamespacedKey.class); } @Override @@ -400,16 +396,14 @@ public String getStatisticCriteriaKey(@NotNull Statistic statistic) { @Override public @Nullable Color getSpawnEggLayerColor(EntityType entityType, int i) { throw NotImplementedException.createByLazy(UnsafeValues.class, - "getSpawnEggLayerColor", - EntityType.class, - int.class); + "getSpawnEggLayerColor", + EntityType.class, + int.class); } @Override public LifecycleEventManager<@NotNull Plugin> createPluginLifecycleEventManager(JavaPlugin javaPlugin, BooleanSupplier booleanSupplier) { - boolean test = booleanSupplier.getAsBoolean(); - //TODO work this one out, not on javadocs return new SoakLifecycleEventManager<>(); } @@ -418,20 +412,30 @@ public String getStatisticCriteriaKey(@NotNull Statistic statistic) { @NotNull TooltipContext tooltipContext, @Nullable Player player) { throw NotImplementedException.createByLazy(UnsafeValues.class, - "computeTooltipLines", - ItemStack.class, - TooltipContext.class, - Player.class); + "computeTooltipLines", + ItemStack.class, + TooltipContext.class, + Player.class); } @Override - public @Nullable
Tag<@NotNull A> getTag(@NotNull TagKey tagKey) { - throw NotImplementedException.createByLazy(UnsafeValues.class, "getTag", TagKey.class); + public ItemStack createEmptyStack() { + return new SoakItemStack(); } @Override - public ItemStack createEmptyStack() { - return new SoakItemStack(); + public @NotNull Map serializeStack(ItemStack itemStack) { + throw NotImplementedException.createByLazy(this, "serializeStack", ItemStack.class); + } + + @Override + public @NotNull ItemStack deserializeStack(@NotNull Map args) { + throw NotImplementedException.createByLazy(this, "deserializeStack", Map.class); + } + + @Override + public @NotNull ItemStack deserializeItemHover(HoverEvent.@NotNull ShowItem itemHover) { + throw NotImplementedException.createByLazy(this, "deserializeItemHover", HoverEvent.ShowItem.class); } @Override diff --git a/Wrapper/src/main/java/org/soak/wrapper/SoakWorldBorder.java b/Wrapper/src/main/java/org/soak/wrapper/SoakWorldBorder.java index 775977d..ecadf91 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/SoakWorldBorder.java +++ b/Wrapper/src/main/java/org/soak/wrapper/SoakWorldBorder.java @@ -1,11 +1,14 @@ package org.soak.wrapper; +import net.kyori.adventure.util.Ticks; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.WorldBorder; +import org.checkerframework.checker.index.qual.NonNegative; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Range; import org.soak.exception.NotImplementedException; import org.soak.wrapper.world.SoakWorld; import org.spongepowered.api.world.server.ServerWorld; @@ -19,8 +22,8 @@ //why isnt this in the world package Bukkit???? public class SoakWorldBorder implements WorldBorder { - private @NotNull org.spongepowered.api.world.border.WorldBorder sponge; private final @Nullable World world; + private @NotNull org.spongepowered.api.world.border.WorldBorder sponge; public SoakWorldBorder(@NotNull org.spongepowered.api.world.border.WorldBorder sponge, @Nullable World world) { this.sponge = sponge; @@ -69,6 +72,12 @@ public void setSize(double size) { setSize(size, 0); } + @Override + public void changeSize(double newSize, @Range(from = 0L, to = 2147483647L) long ticks) { + update(t -> t.timeToTargetDiameter(Ticks.duration(ticks)).targetDiameter(newSize).initialDiameter(this.sponge.diameter())); + + } + @Override public void setSize(double size, long seconds) { setSize(size, TimeUnit.SECONDS, seconds); @@ -126,6 +135,16 @@ public void setWarningTime(int i) { update(builder -> builder.warningTime(Duration.of(i, TimeUnit.SECONDS.toChronoUnit()))); } + @Override + public @NonNegative int getWarningTimeTicks() { + return 0; + } + + @Override + public void setWarningTimeTicks(@NonNegative int ticks) { + + } + @Override public int getWarningDistance() { return this.sponge.warningDistance(); @@ -153,9 +172,9 @@ public boolean isInside(@NotNull Location location) { //this doesnt work with default world border var worldBorderCenter = new Location(location.getWorld(), - this.sponge.center().x(), - location.getY(), - this.sponge.center().y()); + this.sponge.center().x(), + location.getY(), + this.sponge.center().y()); var distance = location.distance(worldBorderCenter); var radius = this.sponge.safeZone() / 2; return radius <= distance; diff --git a/Wrapper/src/main/java/org/soak/wrapper/block/AbstractBlock.java b/Wrapper/src/main/java/org/soak/wrapper/block/AbstractBlock.java index 7226da2..1572cf2 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/block/AbstractBlock.java +++ b/Wrapper/src/main/java/org/soak/wrapper/block/AbstractBlock.java @@ -9,6 +9,7 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import org.soak.WrapperManager; +import org.soak.exception.NotImplementedException; import org.soak.map.SoakBlockMap; import org.soak.map.SoakDirectionMap; import org.soak.map.item.SoakItemStackMap; @@ -47,6 +48,11 @@ public ServerLocation spongeLocation() { return world.location(spongePosition()); } + @Override + public boolean isSuffocating() { + throw NotImplementedException.createByLazy(Block.class, "block"); + } + @Override public @NotNull String translationKey() { return this.getTranslationKey(); diff --git a/Wrapper/src/main/java/org/soak/wrapper/block/SoakBiome.java b/Wrapper/src/main/java/org/soak/wrapper/block/SoakBiome.java new file mode 100644 index 0000000..89f03f4 --- /dev/null +++ b/Wrapper/src/main/java/org/soak/wrapper/block/SoakBiome.java @@ -0,0 +1,37 @@ +package org.soak.wrapper.block; + +import org.bukkit.NamespacedKey; +import org.bukkit.block.Biome; +import org.jetbrains.annotations.NotNull; +import org.jspecify.annotations.NonNull; +import org.soak.map.SoakResourceKeyMap; +import org.spongepowered.api.registry.RegistryTypes; + +public class SoakBiome implements Biome { + + private final org.spongepowered.api.world.biome.Biome biome; + + public SoakBiome(org.spongepowered.api.world.biome.Biome biome) { + this.biome = biome; + } + + @Override + public @NotNull NamespacedKey getKey() { + return SoakResourceKeyMap.mapToBukkit(this.biome.key(RegistryTypes.BIOME)); + } + + @Override + public int compareTo(@NonNull Biome other) { + return getKey().compareTo(other.getKey()); + } + + @Override + public @NotNull String name() { + return this.getKey().value().toUpperCase(); + } + + @Override + public int ordinal() { + return RegistryTypes.BIOME.get().stream().toList().indexOf(this.biome); + } +} diff --git a/Wrapper/src/main/java/org/soak/wrapper/block/SoakBlock.java b/Wrapper/src/main/java/org/soak/wrapper/block/SoakBlock.java index d61f890..52cf022 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/block/SoakBlock.java +++ b/Wrapper/src/main/java/org/soak/wrapper/block/SoakBlock.java @@ -20,6 +20,7 @@ import org.soak.WrapperManager; import org.soak.exception.NotImplementedException; import org.soak.map.SoakBlockMap; +import org.soak.map.SoakRegistryMap; import org.soak.map.item.SoakItemStackMap; import org.soak.plugin.SoakManager; import org.soak.wrapper.block.data.CommonBlockData; @@ -99,8 +100,7 @@ public void setBlockData(@NotNull BlockData arg0, boolean arg1) { @Override public void setType(@NotNull Material arg0, boolean arg1) { - var blockType = SoakBlockMap.toSponge(arg0) - .orElseThrow(() -> new RuntimeException(arg0.name() + " is not a block")); + var blockType = SoakRegistryMap.toSpongeBlock(arg0); var blockChangeFlag = arg1 ? BlockChangeFlags.ALL : BlockChangeFlags.NOTIFY_CLIENTS; this.block.setBlockType(blockType, blockChangeFlag); } @@ -173,10 +173,15 @@ public boolean breakNaturally(@NotNull ItemStack arg0, boolean arg1) { @Override public boolean breakNaturally(@NotNull ItemStack itemStack, boolean b, boolean b1) { throw NotImplementedException.createByLazy(Block.class, - "breakNaturally", - ItemStack.class, - boolean.class, - boolean.class); + "breakNaturally", + ItemStack.class, + boolean.class, + boolean.class); + } + + @Override + public boolean breakNaturally(@NotNull ItemStack tool, boolean triggerEffect, boolean dropExperience, boolean forceEffect) { + throw NotImplementedException.createByLazy(Block.class, "block", ItemStack.class, boolean.class, boolean.class, boolean.class); } @Override @@ -268,11 +273,11 @@ public String getTranslationKey() { public RayTraceResult rayTrace(@NotNull Location arg0, @NotNull Vector arg1, double arg2, @NotNull FluidCollisionMode arg3) { throw NotImplementedException.createByLazy(Block.class, - "rayTrace", - Location.class, - Vector.class, - double.class, - FluidCollisionMode.class); + "rayTrace", + Location.class, + Vector.class, + double.class, + FluidCollisionMode.class); } @Override diff --git a/Wrapper/src/main/java/org/soak/wrapper/block/SoakBlockSnapshot.java b/Wrapper/src/main/java/org/soak/wrapper/block/SoakBlockSnapshot.java index a49a548..f179e64 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/block/SoakBlockSnapshot.java +++ b/Wrapper/src/main/java/org/soak/wrapper/block/SoakBlockSnapshot.java @@ -237,6 +237,11 @@ public boolean breakNaturally(@NotNull ItemStack itemStack, boolean b, boolean b boolean.class); } + @Override + public boolean breakNaturally(@NotNull ItemStack tool, boolean triggerEffect, boolean dropExperience, boolean forceEffect) { + throw NotImplementedException.createByLazy(Block.class, "breakNaturally", ItemStack.class, boolean.class, boolean.class, boolean.class); + } + @Override public boolean isPassable() { throw NotImplementedException.createByLazy(Block.class, "isPassable"); diff --git a/Wrapper/src/main/java/org/soak/wrapper/block/SoakLegacyCustomBiome.java b/Wrapper/src/main/java/org/soak/wrapper/block/SoakLegacyCustomBiome.java new file mode 100644 index 0000000..672b15e --- /dev/null +++ b/Wrapper/src/main/java/org/soak/wrapper/block/SoakLegacyCustomBiome.java @@ -0,0 +1,32 @@ +package org.soak.wrapper.block; + +import org.bukkit.NamespacedKey; +import org.bukkit.block.Biome; +import org.jetbrains.annotations.NotNull; +import org.jspecify.annotations.NonNull; + +public class SoakLegacyCustomBiome implements Biome { + + @Override + public @NotNull NamespacedKey getKey() { + return NamespacedKey.fromString("soak:custom_legacy_biome"); + } + + @Override + public int compareTo(@NonNull Biome other) { + if (other instanceof SoakLegacyCustomBiome) { + return 0; + } + return -1; + } + + @Override + public @NotNull String name() { + return "CUSTOM"; + } + + @Override + public int ordinal() { + return -1; + } +} diff --git a/Wrapper/src/main/java/org/soak/wrapper/block/data/AbstractBlockData.java b/Wrapper/src/main/java/org/soak/wrapper/block/data/AbstractBlockData.java index df7c30b..f0199eb 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/block/data/AbstractBlockData.java +++ b/Wrapper/src/main/java/org/soak/wrapper/block/data/AbstractBlockData.java @@ -45,6 +45,11 @@ public static CommonBlockData internalCreateBlockData(BlockState state) { } } + @Override + public boolean isReplaceable() { + return this.sponge().get(Keys.IS_REPLACEABLE).orElse(false); + } + @Override public @NotNull VoxelShape getCollisionShape(@NotNull Location location) { throw NotImplementedException.createByLazy(BlockData.class, "getCollisionShape", Location.class); @@ -112,9 +117,9 @@ public boolean isSupported(@NotNull Location location) { @Override public boolean isFaceSturdy(@NotNull BlockFace blockFace, @NotNull BlockSupport blockSupport) { throw NotImplementedException.createByLazy(BlockData.class, - "isFaceSturdy", - BlockFace.class, - BlockSupport.class); + "isFaceSturdy", + BlockFace.class, + BlockSupport.class); } @Override diff --git a/Wrapper/src/main/java/org/soak/wrapper/block/data/type/SoakBed.java b/Wrapper/src/main/java/org/soak/wrapper/block/data/type/SoakBed.java index 32683b1..88e358c 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/block/data/type/SoakBed.java +++ b/Wrapper/src/main/java/org/soak/wrapper/block/data/type/SoakBed.java @@ -49,4 +49,5 @@ public void setOccupied(boolean b) { public @NotNull AbstractBlockData clone() { return new SoakBed(this.sponge()); } + } diff --git a/Wrapper/src/main/java/org/soak/wrapper/block/state/AbstractBlockState.java b/Wrapper/src/main/java/org/soak/wrapper/block/state/AbstractBlockState.java index 7c2de05..7f984b5 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/block/state/AbstractBlockState.java +++ b/Wrapper/src/main/java/org/soak/wrapper/block/state/AbstractBlockState.java @@ -52,6 +52,13 @@ public AbstractBlockState(@Nullable ServerLocation location, @NotNull org.sponge this.state = state; } + public static AbstractBlockState wrap(@Nullable ServerLocation location, org.spongepowered.api.block.BlockState state, boolean isSnapshot) { + if (state.type().is(BlockTypeTags.ALL_SIGNS)) { + return new SignBlockState(location, state, isSnapshot); + } + return new BasicBlockState(location, state); + } + public @NotNull org.spongepowered.api.block.BlockState spongeState() { return this.state; } @@ -67,13 +74,6 @@ public Optional spongeEntity() { return this.location.blockEntity(); } - public static AbstractBlockState wrap(@Nullable ServerLocation location, org.spongepowered.api.block.BlockState state, boolean isSnapshot) { - if (state.type().is(BlockTypeTags.ALL_SIGNS)) { - return new SignBlockState(location, state, isSnapshot); - } - return new BasicBlockState(location, state); - } - protected abstract AbstractBlockState createCopy(@Nullable ServerLocation location, @NotNull org.spongepowered.api.block.BlockState state); protected abstract void onPostApply(@NotNull ServerLocation location); @@ -228,7 +228,7 @@ public void setRawData(byte b) { @Override public boolean isPlaced() { - if(this.location == null){ + if (this.location == null) { return false; } return this.location.block().type().equals(this.state.type()); @@ -266,4 +266,9 @@ public boolean hasMetadata(@NotNull String metadataKey) { public void removeMetadata(@NotNull String metadataKey, @NotNull Plugin owningPlugin) { throw NotImplementedException.createByLazy(AbstractBlockState.class, "metadataKey", String.class, Plugin.class); } + + @Override + public boolean isSuffocating() { + throw NotImplementedException.createByLazy(AbstractBlockState.class, "isSuffocating"); + } } diff --git a/Wrapper/src/main/java/org/soak/wrapper/block/state/DispenserBlockState.java b/Wrapper/src/main/java/org/soak/wrapper/block/state/DispenserBlockState.java index 913f14f..d79ecea 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/block/state/DispenserBlockState.java +++ b/Wrapper/src/main/java/org/soak/wrapper/block/state/DispenserBlockState.java @@ -3,6 +3,7 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.block.Dispenser; +import org.bukkit.inventory.ItemStack; import org.bukkit.projectiles.BlockProjectileSource; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -105,6 +106,11 @@ public void setLock(@Nullable String s) { this.lockedToken.set(s); } + @Override + public void setLockItem(@Nullable ItemStack key) { +throw NotImplementedException.createByLazy(Dispenser.class, "setLockItem", ItemStack.class); + } + @Override protected AbstractBlockState createCopy(@Nullable ServerLocation location, @NotNull BlockState state) { return new DispenserBlockState(location, state, this.isSnapshot(), this.customName, this.lockedToken); diff --git a/Wrapper/src/main/java/org/soak/wrapper/command/SoakCommandMap.java b/Wrapper/src/main/java/org/soak/wrapper/command/SoakCommandMap.java index 244199c..4aef041 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/command/SoakCommandMap.java +++ b/Wrapper/src/main/java/org/soak/wrapper/command/SoakCommandMap.java @@ -8,17 +8,23 @@ import org.soak.command.BukkitRawCommand; import org.soak.plugin.SoakManager; import org.soak.utils.GeneralHelper; +import org.soak.wrapper.plugin.SoakPluginManager; import org.spongepowered.api.Sponge; +import org.spongepowered.plugin.PluginContainer; -import java.util.Collections; +import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.Objects; public class SoakCommandMap extends SimpleCommandMap { + private final Collection registerLater = new ArrayList<>(); + private final boolean canAcceptCommands; public SoakCommandMap() { super(Bukkit.getServer(), new HashMap<>()); + canAcceptCommands = true; } @Override @@ -26,15 +32,45 @@ public boolean register(@NotNull String label, @NotNull String fallbackPrefix, @ return registerCommand(command, fallbackPrefix, label); } + public void registerStored() { + var rawRegister = Sponge.server() + .commandManager() + .registrar(org.spongepowered.api.command.Command.Raw.class) + .orElseThrow(() -> new RuntimeException("Cannot register late commands")); + this.registerLater.forEach(r -> rawRegister.register(r.container, r.cmd, r.name, r.aliases)); + } + private boolean registerCommand(@NotNull Command command, @NotNull String fallback, @Nullable String label) { + if(!this.canAcceptCommands){ + return false; + } this.knownCommands.put(Objects.requireNonNullElseGet(label, command::getLabel), command); boolean result = command.register(this); - - var rawRegister = Sponge.server().commandManager().registrar(org.spongepowered.api.command.Command.Raw.class).orElseThrow(() -> new RuntimeException("Cannot register late command of '" + label + "'")); - var plugin = GeneralHelper.fromStackTrace(); - var soakPlugin = SoakManager.getManager().getSoakContainer(plugin).orElseThrow(() -> new RuntimeException("Cannot get the soakPlugin from '" + plugin.metadata().id() + "'")); + var plugin = fallback.equals("bukkit") ? SoakManager.getManager().getOwnContainer() : GeneralHelper.fromStackTrace(); + var soakPlugin = SoakManager.getManager() + .getSoakContainer(plugin) + .orElseThrow(() -> new RuntimeException("Cannot get the soakPlugin from '" + plugin.metadata() + .id() + "'")); var bukkitRawWrapper = new BukkitRawCommand(soakPlugin, command); - rawRegister.register(plugin, bukkitRawWrapper, command.getName(), command.getAliases().toArray(String[]::new)); + if (Sponge.isServerAvailable()) { + var rawRegister = Sponge.server() + .commandManager() + .registrar(org.spongepowered.api.command.Command.Raw.class) + .orElseThrow(() -> new RuntimeException("Cannot register late command of '" + label + "'")); + rawRegister.register(plugin, + bukkitRawWrapper, + command.getName(), + command.getAliases().toArray(String[]::new)); + } else { + registerLater.add(new SpongeRawCommand(plugin, + bukkitRawWrapper, + command.getName(), + command.getAliases().toArray(String[]::new))); + } return result; } + + record SpongeRawCommand(PluginContainer container, BukkitRawCommand cmd, String name, String[] aliases) { + + } } diff --git a/Wrapper/src/main/java/org/soak/wrapper/entity/AbstractEntity.java b/Wrapper/src/main/java/org/soak/wrapper/entity/AbstractEntity.java index 0788d00..517623e 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/entity/AbstractEntity.java +++ b/Wrapper/src/main/java/org/soak/wrapper/entity/AbstractEntity.java @@ -1,9 +1,12 @@ package org.soak.wrapper.entity; +import io.papermc.paper.datacomponent.DataComponentType; +import io.papermc.paper.entity.LookAnchor; import io.papermc.paper.entity.TeleportFlag; import io.papermc.paper.threadedregions.scheduler.EntityScheduler; import net.kyori.adventure.audience.Audience; import net.kyori.adventure.text.Component; +import net.kyori.adventure.util.TriState; import org.bukkit.*; import org.bukkit.block.BlockFace; import org.bukkit.block.PistonMoveReaction; @@ -11,6 +14,7 @@ import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.inventory.ItemStack; import org.bukkit.metadata.MetadataValue; import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.plugin.Plugin; @@ -69,7 +73,7 @@ public AbstractEntity(Subject subject, Audience audience, E entity) { private static SoakEntity wrapEntity(SE entity) { EntityTypeMappingEntry entityTypeMapping = (EntityTypeMappingEntry) EntityTypeList.getEntityTypeMapping( - entity.type()); + entity.type()); if (!entityTypeMapping.isFinal()) { entityTypeMapping.updateWithSoakClass((Class) entity.getClass()); } @@ -78,13 +82,53 @@ private static AbstractLivingEntity wrap(E living) { - return (AbstractLivingEntity) (Object) wrapEntity(living); + return wrapEntity(living); } public static AbstractEntity wrap(E entity) { return wrapEntity(entity); } + @Override + public @org.jspecify.annotations.Nullable T getData(DataComponentType.Valued type) { + throw NotImplementedException.createByLazy(Player.class, "getData", DataComponentType.Valued.class); + } + + @Override + public @org.jspecify.annotations.Nullable T getDataOrDefault(DataComponentType.Valued type, @org.jspecify.annotations.Nullable T fallback) { + throw NotImplementedException.createByLazy(Player.class, "getDataOrDefault", DataComponentType.Valued.class, Object.class); + } + + @Override + public boolean hasData(DataComponentType type) { + throw NotImplementedException.createByLazy(Player.class, "hasData", DataComponentType.class); + } + + @Override + public boolean isTrackedBy(@NotNull Player player) { + throw NotImplementedException.createByLazy(Player.class, "isTrackedBy", Player.class); + } + + @Override + public void lookAt(double v, double v1, double v2, @NotNull LookAnchor lookAnchor) { + throw NotImplementedException.createByLazy(Player.class, + "lookAt", + double.class, + double.class, + double.class, + LookAnchor.class); + } + + @Override + public @NotNull ItemStack getPickItemStack() { + throw NotImplementedException.createByLazy(HumanEntity.class, "getPickItemStack"); + } + + @Override + public @NotNull TriState getVisualFire() { + throw NotImplementedException.createByLazy(HumanEntity.class, "getVisualFire"); + } + public E spongeEntity() { return this.entity; } @@ -153,9 +197,9 @@ public boolean isEmpty() { @Override public @NotNull Location getLocation() { var loc = new Location(this.getWorld(), - this.entity.position().x(), - this.entity.position().y(), - this.entity.position().z()); + this.entity.position().x(), + this.entity.position().y(), + this.entity.position().z()); var spongeRotation = this.entity.rotation(); loc.setPitch((float) spongeRotation.x()); loc.setYaw((float) spongeRotation.y()); @@ -223,6 +267,11 @@ public boolean isVisualFire() { throw NotImplementedException.createByLazy(Entity.class, "isVisualFire"); } + @Override + public void setVisualFire(@NotNull TriState fire) { + throw NotImplementedException.createByLazy(HumanEntity.class, "setVisualFire", TriState.class); + } + @Override public void setVisualFire(boolean b) { throw NotImplementedException.createByLazy(Entity.class, "setVisualFire", boolean.class); @@ -317,9 +366,9 @@ public boolean isUnderWater() { @Override public boolean spawnAt(@NotNull Location location, @NotNull CreatureSpawnEvent.SpawnReason spawnReason) { throw NotImplementedException.createByLazy(Entity.class, - "spawnAt", - Location.class, - CreatureSpawnEvent.SpawnReason.class); + "spawnAt", + Location.class, + CreatureSpawnEvent.SpawnReason.class); } @@ -398,10 +447,10 @@ public boolean isInWater() { var thisLocation = getLocation(); var near = this.getWorld().getNearbyEntities(thisLocation, x, y, z); return ListMappingUtils.fromStream(CollectionStreamBuilder.builder().collection(near).basicMap(t -> t), - near::stream, - Object::equals, - Comparator.comparingDouble(entity -> entity.getLocation() - .distanceSquared(thisLocation))).buildList(); + near::stream, + Object::equals, + Comparator.comparingDouble(entity -> entity.getLocation() + .distanceSquared(thisLocation))).buildList(); } @Override diff --git a/Wrapper/src/main/java/org/soak/wrapper/entity/living/AbstractLivingEntity.java b/Wrapper/src/main/java/org/soak/wrapper/entity/living/AbstractLivingEntity.java index 6599e2d..211cce1 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/entity/living/AbstractLivingEntity.java +++ b/Wrapper/src/main/java/org/soak/wrapper/entity/living/AbstractLivingEntity.java @@ -2,12 +2,13 @@ import com.destroystokyo.paper.block.TargetBlockInfo; import com.destroystokyo.paper.entity.TargetEntityInfo; +import io.papermc.paper.datacomponent.DataComponentType; +import io.papermc.paper.entity.LookAnchor; +import io.papermc.paper.world.damagesource.CombatTracker; import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.key.Key; import net.kyori.adventure.util.TriState; -import org.bukkit.FluidCollisionMode; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Sound; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.damage.DamageSource; @@ -26,7 +27,7 @@ import org.jetbrains.annotations.Range; import org.soak.Constants; import org.soak.exception.NotImplementedException; -import org.soak.map.SoakBlockMap; +import org.soak.map.SoakRegistryMap; import org.soak.plugin.SoakManager; import org.soak.utils.GeneralHelper; import org.soak.wrapper.block.SoakBlock; @@ -55,6 +56,37 @@ public AbstractLivingEntity(Subject subject, Audience audience, E entity) { super(subject, audience, entity); } + @Override + public void kill(DamageSource damageSource) { + var soakSource = (SoakDamageSource) damageSource; + this.spongeEntity().damage(Integer.MAX_VALUE, soakSource.spongeSource()); + } + + @Override + public @NotNull Key getWaypointStyle() { + throw NotImplementedException.createByLazy(Player.class, "getWaypointStyle"); + } + + @Override + public void setWaypointStyle(@Nullable Key key) { + throw NotImplementedException.createByLazy(Player.class, "setWaypointStyle", Key.class); + } + + @Override + public @Nullable Color getWaypointColor() { + throw NotImplementedException.createByLazy(Player.class, "getWaypointColor"); + } + + @Override + public void setWaypointColor(@Nullable Color color) { + throw NotImplementedException.createByLazy(Player.class, "setWaypointColor", Color.class); + } + + @Override + public @NotNull CombatTracker getCombatTracker() { + throw NotImplementedException.createByLazy(Player.class, "getCombatTracker"); + } + @Override public boolean canUseEquipmentSlot(@NotNull EquipmentSlot equipmentSlot) { throw NotImplementedException.createByLazy(LivingEntity.class, "canUseEquipmentSlot", EquipmentSlot.class); @@ -164,10 +196,10 @@ public boolean canBreatheUnderwater() { @Override public void knockback(double v, double v1, double v2) { throw NotImplementedException.createByLazy(LivingEntity.class, - "knockback", - double.class, - double.class, - double.class); + "knockback", + double.class, + double.class, + double.class); } @Override @@ -178,9 +210,9 @@ public void broadcastSlotBreak(@NotNull EquipmentSlot equipmentSlot) { @Override public void broadcastSlotBreak(@NotNull EquipmentSlot equipmentSlot, @NotNull Collection collection) { throw NotImplementedException.createByLazy(LivingEntity.class, - "broadcastSlotBreak", - EquipmentSlot.class, - Collection.class); + "broadcastSlotBreak", + EquipmentSlot.class, + Collection.class); } @Override @@ -191,9 +223,9 @@ public void broadcastSlotBreak(@NotNull EquipmentSlot equipmentSlot, @NotNull Co @Override public void damageItemStack(@NotNull EquipmentSlot equipmentSlot, int i) { throw NotImplementedException.createByLazy(LivingEntity.class, - "damageItemStack", - EquipmentSlot.class, - int.class); + "damageItemStack", + EquipmentSlot.class, + int.class); } @Override @@ -224,9 +256,9 @@ public RayTraceResult rayTraceBlocks(double arg0) { @Override public RayTraceResult rayTraceBlocks(double arg0, @NotNull FluidCollisionMode arg1) { throw NotImplementedException.createByLazy(LivingEntity.class, - "rayTraceBlocks", - double.class, - FluidCollisionMode.class); + "rayTraceBlocks", + double.class, + FluidCollisionMode.class); } @Override @@ -243,9 +275,9 @@ public TargetEntityInfo getTargetEntityInfo(int arg0, boolean arg1) { @Override public void playPickupItemAnimation(@NotNull Item arg0, int arg1) { throw NotImplementedException.createByLazy(LivingEntity.class, - "playPickupItemAnimation", - Item.class, - int.class); + "playPickupItemAnimation", + Item.class, + int.class); } @Override @@ -284,8 +316,7 @@ public double getEyeHeight(boolean ignorePose) { return false; } return transparent.stream() - .map(mat -> SoakBlockMap.toSponge(mat) - .orElseThrow(() -> new RuntimeException(mat.name() + " is not a block"))) + .map(SoakRegistryMap::toSpongeBlock) .anyMatch(type -> type.equals(locatableBlock.blockState().type())); })) .limit(maxDistance) @@ -293,34 +324,34 @@ public double getEyeHeight(boolean ignorePose) { return opBlock.flatMap(block -> block.selectedObject().location().onServer()) .map(SoakBlock::new) .orElseGet(() -> new SoakBlock((ServerWorld) this.spongeEntity().world(), - this.spongeEntity().eyePosition().get().toInt())); + this.spongeEntity().eyePosition().get().toInt())); } @Override @Deprecated public @Nullable Block getTargetBlock(int maxDistance, @NotNull TargetBlockInfo.FluidMode fluidMode) { throw NotImplementedException.createByLazy(LivingEntity.class, - "getTargetBlockExact", - int.class, - FluidCollisionMode.class); + "getTargetBlockExact", + int.class, + FluidCollisionMode.class); } @Override @Deprecated public @Nullable BlockFace getTargetBlockFace(int maxDistance, @NotNull TargetBlockInfo.FluidMode fluidMode) { throw NotImplementedException.createByLazy(LivingEntity.class, - "getTargetBlockFace", - int.class, - TargetBlockInfo.FluidMode.class); + "getTargetBlockFace", + int.class, + TargetBlockInfo.FluidMode.class); } @Override @Deprecated public @Nullable TargetBlockInfo getTargetBlockInfo(int maxDistance, @NotNull TargetBlockInfo.FluidMode fluidMode) { throw NotImplementedException.createByLazy(LivingEntity.class, - "getTargetBlockInfo", - int.class, - TargetBlockInfo.FluidMode.class); + "getTargetBlockInfo", + int.class, + TargetBlockInfo.FluidMode.class); } @Override @@ -331,9 +362,9 @@ public Block getTargetBlockExact(int arg0) { @Override public @Nullable Block getTargetBlockExact(int maxDistance, @NotNull FluidCollisionMode fluidCollisionMode) { throw NotImplementedException.createByLazy(LivingEntity.class, - "getTargetBlockExact", - int.class, - FluidCollisionMode.class); + "getTargetBlockExact", + int.class, + FluidCollisionMode.class); } @Override @@ -426,8 +457,8 @@ public void setNoDamageTicks(int arg0) { SoakManager.getManager() .getLogger() .warn(badPlugin.metadata() - .id() + " attempted to set minecraft data off thread. This should not be done. Moving " + - "action to main thread"); + .id() + " attempted to set minecraft data off thread. This should not be done. Moving " + + "action to main thread"); Sponge.server().scheduler().executor(badPlugin).submit(() -> setNoDamageTicks(arg0)); } @@ -455,9 +486,9 @@ public void setKiller(Player arg0) { @Override public boolean addPotionEffect(@NotNull PotionEffect arg0, boolean arg1) { throw NotImplementedException.createByLazy(LivingEntity.class, - "addPotionEffect", - PotionEffect.class, - boolean.class); + "addPotionEffect", + PotionEffect.class, + boolean.class); } @Override diff --git a/Wrapper/src/main/java/org/soak/wrapper/entity/living/AbstractMob.java b/Wrapper/src/main/java/org/soak/wrapper/entity/living/AbstractMob.java index 565bbad..aa70165 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/entity/living/AbstractMob.java +++ b/Wrapper/src/main/java/org/soak/wrapper/entity/living/AbstractMob.java @@ -2,6 +2,7 @@ import com.destroystokyo.paper.entity.Pathfinder; import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.util.TriState; import org.bukkit.Location; import org.bukkit.Sound; import org.bukkit.entity.Entity; @@ -25,6 +26,21 @@ public AbstractMob(Subject subject, Audience audience, E entity) { super(subject, audience, entity); } + @Override + public boolean shouldDespawnInPeaceful() { + throw NotImplementedException.createByLazy(Mob.class, "shouldDespawnInPeaceful"); + } + + @Override + public void setDespawnInPeacefulOverride(TriState state) { + throw NotImplementedException.createByLazy(Mob.class, "setDespawnInReacefulOverride", TriState.class); + } + + @Override + public TriState getDespawnInPeacefulOverride() { + throw NotImplementedException.createByLazy(Mob.class, "getSpawnInPeacefulOverride"); + } + @Override public @NotNull Pathfinder getPathfinder() { throw NotImplementedException.createByLazy(Mob.class, "getPathfinder"); diff --git a/Wrapper/src/main/java/org/soak/wrapper/entity/living/human/AbstractHumanBase.java b/Wrapper/src/main/java/org/soak/wrapper/entity/living/human/AbstractHumanBase.java index 6ad12ec..3fd0e06 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/entity/living/human/AbstractHumanBase.java +++ b/Wrapper/src/main/java/org/soak/wrapper/entity/living/human/AbstractHumanBase.java @@ -1,27 +1,31 @@ package org.soak.wrapper.entity.living.human; +import io.papermc.paper.datacomponent.DataComponentType; +import io.papermc.paper.entity.LookAnchor; +import io.papermc.paper.world.damagesource.CombatTracker; import net.kyori.adventure.audience.Audience; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.NamespacedKey; +import net.kyori.adventure.key.Key; +import net.kyori.adventure.util.TriState; +import org.bukkit.*; import org.bukkit.block.Sign; import org.bukkit.block.sign.Side; +import org.bukkit.damage.DamageSource; import org.bukkit.entity.*; import org.bukkit.inventory.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.soak.exception.NotImplementedException; import org.soak.map.SoakGameModeMap; +import org.soak.map.SoakRegistryMap; +import org.soak.wrapper.damage.SoakDamageSource; import org.soak.wrapper.entity.living.AbstractLivingEntity; import org.spongepowered.api.data.Keys; import org.spongepowered.api.entity.living.Humanoid; -import org.spongepowered.api.item.inventory.equipment.EquipmentTypes; -import org.spongepowered.api.registry.RegistryTypes; import org.spongepowered.api.service.permission.Subject; import java.util.Collection; import java.util.Set; +import java.util.function.Consumer; public abstract class AbstractHumanBase extends AbstractLivingEntity implements HumanEntity { @@ -29,23 +33,64 @@ public AbstractHumanBase(Subject subject, Audience audience, E entity) { super(subject, audience, entity); } + @Override + public @org.jspecify.annotations.Nullable Item dropItem(int slot, int amount, boolean throwRandomly, @org.jspecify.annotations.Nullable Consumer entityOperation) { + throw NotImplementedException.createByLazy(HumanEntity.class, "dropItem", int.class, int.class, boolean.class, Consumer.class); + } + + @Override + public @org.jspecify.annotations.Nullable Item dropItem(EquipmentSlot slot, int amount, boolean throwRandomly, @org.jspecify.annotations.Nullable Consumer entityOperation) { + throw NotImplementedException.createByLazy(HumanEntity.class, "dropItem", EquipmentSlot.class, int.class, boolean.class, Consumer.class); + } + + @Override + public @org.jspecify.annotations.Nullable Item dropItem(ItemStack itemStack, boolean throwRandomly, @org.jspecify.annotations.Nullable Consumer entityOperation) { + throw NotImplementedException.createByLazy(HumanEntity.class, "dropItem", ItemStack.class, boolean.class, Consumer.class); + } + + @Override + public boolean hasCooldown(ItemStack item) { + throw NotImplementedException.createByLazy(HumanEntity.class, "hasCooldown", ItemStack.class); + } + + @Override + public int getCooldown(ItemStack item) { + throw NotImplementedException.createByLazy(HumanEntity.class, "getCooldown", ItemStack.class); + } + + @Override + public void setCooldown(ItemStack item, int ticks) { + throw NotImplementedException.createByLazy(HumanEntity.class, "setCooldown", ItemStack.class, int.class); + } + + @Override + public int getCooldown(Key key) { + throw NotImplementedException.createByLazy(HumanEntity.class, "getCooldown", Key.class); + } + + @Override + public void setCooldown(Key key, int ticks) { + throw NotImplementedException.createByLazy(HumanEntity.class, "setCooldown", Key.class, int.class); + } + + @Override + public @org.jspecify.annotations.Nullable Location getPotentialRespawnLocation() { + throw NotImplementedException.createByLazy(HumanEntity.class, "getPotentialRespawnLocation"); + } + + @Override public void startRiptideAttack(int i, float v, @Nullable ItemStack itemStack) { throw NotImplementedException.createByLazy(HumanEntity.class, - "startRiptideAttack", - int.class, - float.class, - ItemStack.class); + "startRiptideAttack", + int.class, + float.class, + ItemStack.class); } @Override public boolean canUseEquipmentSlot(@NotNull EquipmentSlot equipmentSlot) { - var equipmentType = EquipmentTypes.registry() - .stream() - .filter(type -> equipmentSlot.name().equalsIgnoreCase(type.key(RegistryTypes.EQUIPMENT_TYPE).value())) - .findAny() - .orElseThrow(); - //TODO move to map + var equipmentType = SoakRegistryMap.toSponge(equipmentSlot); return this.entity.canEquip(equipmentType); } @@ -104,9 +149,9 @@ public void setShoulderEntityLeft(Entity arg0) { @Override public boolean setWindowProperty(InventoryView.@NotNull Property arg0, int arg1) { throw NotImplementedException.createByLazy(HumanEntity.class, - "setWindowProperty", - InventoryView.Property.class, - int.class); + "setWindowProperty", + InventoryView.Property.class, + int.class); } @Override @@ -142,9 +187,9 @@ public InventoryView openAnvil(Location arg0, boolean arg1) { @Override public InventoryView openCartographyTable(Location arg0, boolean arg1) { throw NotImplementedException.createByLazy(HumanEntity.class, - "openCartographyTable", - Location.class, - boolean.class); + "openCartographyTable", + Location.class, + boolean.class); } @Override @@ -160,9 +205,9 @@ public InventoryView openLoom(Location arg0, boolean arg1) { @Override public InventoryView openSmithingTable(Location arg0, boolean arg1) { throw NotImplementedException.createByLazy(HumanEntity.class, - "openSmithingTable", - Location.class, - boolean.class); + "openSmithingTable", + Location.class, + boolean.class); } @Override diff --git a/Wrapper/src/main/java/org/soak/wrapper/entity/living/human/SoakPlayer.java b/Wrapper/src/main/java/org/soak/wrapper/entity/living/human/SoakPlayer.java index 7574dcf..e01c09c 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/entity/living/human/SoakPlayer.java +++ b/Wrapper/src/main/java/org/soak/wrapper/entity/living/human/SoakPlayer.java @@ -3,7 +3,9 @@ import com.destroystokyo.paper.ClientOption; import com.destroystokyo.paper.Title; import com.destroystokyo.paper.profile.PlayerProfile; +import io.papermc.paper.connection.PlayerGameConnection; import io.papermc.paper.entity.LookAnchor; +import io.papermc.paper.entity.PlayerGiveResult; import io.papermc.paper.math.Position; import net.kyori.adventure.bossbar.BossBar; import net.kyori.adventure.text.Component; @@ -41,9 +43,9 @@ import org.soak.wrapper.block.data.SoakBlockData; import org.soak.wrapper.block.state.AbstractBlockState; import org.soak.wrapper.inventory.SoakInventory; +import org.soak.wrapper.inventory.carrier.SoakPlayerInventory; import org.soak.wrapper.inventory.view.AbstractInventoryView; import org.soak.wrapper.inventory.view.SoakOpeningInventoryView; -import org.soak.wrapper.inventory.carrier.SoakPlayerInventory; import org.soak.wrapper.world.SoakWorld; import org.spongepowered.api.Sponge; import org.spongepowered.api.data.Keys; @@ -55,7 +57,6 @@ import org.spongepowered.api.service.ban.BanTypes; import org.spongepowered.api.statistic.Statistics; import org.spongepowered.api.util.RespawnLocation; -import org.spongepowered.math.vector.Vector3d; import java.net.InetAddress; import java.net.InetSocketAddress; @@ -118,7 +119,7 @@ public boolean discoverRecipe(@NotNull NamespacedKey key) { SoakInventory soakInv = (SoakInventory) inventory; try { return openInventory(soakInv.sponge(), - soakInv.requestedTitle().orElse(null)).map(AbstractInventoryView::wrap).orElse(null); + soakInv.requestedTitle().orElse(null)).map(AbstractInventoryView::wrap).orElse(null); } catch (UnsupportedOperationException ex) { Sponge.server() .scheduler() @@ -358,10 +359,10 @@ public void setStatistic(@NotNull Statistic statistic, int value) { @Override public void setStatistic(@NotNull Statistic arg0, @NotNull Material arg1, int arg2) { throw NotImplementedException.createByLazy(OfflinePlayer.class, - "setStatistic", - Statistic.class, - Material.class, - int.class); + "setStatistic", + Statistic.class, + Material.class, + int.class); } private Optional> statistic(Statistic statistic, @@ -374,13 +375,13 @@ private Optional> sta .filter(entry -> entry.getKey() .criterion() .orElseThrow() - .key(RegistryTypes.STATISTIC) + .key(RegistryTypes.CRITERION) .equals(spongeKey)) .filter(entry -> entry.getKey() instanceof org.spongepowered.api.statistic.Statistic.TypeInstance) .filter(entry -> { var typedStatistic = ((org.spongepowered.api.statistic.Statistic.TypeInstance) entry.getKey()).type(); - if (SoakBlockMap.toSponge(material).map(typedStatistic::equals).orElse(false)) { + if (SoakRegistryMap.toSpongeBlock(material).equals(typedStatistic)) { return true; } return SoakItemStackMap.toSponge(material).map(typedStatistic::equals).orElse(false); @@ -402,7 +403,7 @@ private Optional> sta .filter(entry -> entry.getKey() .criterion() .orElseThrow() - .key(RegistryTypes.STATISTIC) + .key(RegistryTypes.CRITERION) .equals(spongeKey)) .findAny(); } @@ -423,7 +424,7 @@ public Optional> stat .filter(entry -> entry.getKey() .criterion() .orElseThrow() - .key(RegistryTypes.STATISTIC) + .key(RegistryTypes.CRITERION) .equals(spongeKey)) .filter(entry -> entry.getKey() instanceof org.spongepowered.api.statistic.Statistic.TypeInstance) .filter(entry -> ((org.spongepowered.api.statistic.Statistic.TypeInstance) entry.getKey()).type() @@ -533,10 +534,10 @@ public void setResourcePack(@NotNull String arg0, byte[] arg1) { @Override public void setResourcePack(@NotNull String s, byte[] bytes, @Nullable String s1) { throw NotImplementedException.createByLazy(Player.class, - "setResourcePack", - String.class, - byte.class, - String.class); + "setResourcePack", + String.class, + byte.class, + String.class); } @Override @@ -552,22 +553,22 @@ public void setResourcePack(@NotNull String s, byte[] bytes, @Nullable String s1 @Override public void setResourcePack(@NotNull String s, byte @Nullable [] bytes, @Nullable Component component, boolean b) { throw NotImplementedException.createByLazy(Player.class, - "setResourcePack", - String.class, - byte.class, - Component.class, - boolean.class); + "setResourcePack", + String.class, + byte.class, + Component.class, + boolean.class); } @Override public void setResourcePack(@NotNull UUID uuid, @NotNull String s, byte[] bytes, @Nullable String s1, boolean b) { throw NotImplementedException.createByLazy(Player.class, - "setResourcePack", - UUID.class, - String.class, - byte[].class, - String.class, - boolean.class); + "setResourcePack", + UUID.class, + String.class, + byte[].class, + String.class, + boolean.class); } @@ -575,12 +576,12 @@ public void setResourcePack(@NotNull UUID uuid, @NotNull String s, byte[] bytes, public void setResourcePack(@NotNull UUID uuid, @NotNull String s, byte @Nullable [] bytes, @Nullable Component component, boolean b) { throw NotImplementedException.createByLazy(Player.class, - "setResourcePack", - UUID.class, - String.class, - byte[].class, - Component.class, - boolean.class); + "setResourcePack", + UUID.class, + String.class, + byte[].class, + Component.class, + boolean.class); } @@ -597,11 +598,11 @@ public void setResourcePack(@NotNull String s, @NotNull String s1, boolean b) { @Override public void setResourcePack(@NotNull String s, @NotNull String s1, boolean b, @Nullable Component component) { throw NotImplementedException.createByLazy(Player.class, - "setResourcePack", - String.class, - String.class, - boolean.class, - Component.class); + "setResourcePack", + String.class, + String.class, + boolean.class, + Component.class); } @Deprecated @@ -653,10 +654,10 @@ public void setHealthScale(double arg0) { @Override public void sendHealthUpdate(double v, int i, float v1) { throw NotImplementedException.createByLazy(Player.class, - "sendHealthUpdate", - double.class, - int.class, - float.class); + "sendHealthUpdate", + double.class, + int.class, + float.class); } @Override @@ -683,196 +684,196 @@ public void resetTitle() { public void spawnParticle(@NotNull Particle arg0, @NotNull Location arg1, int arg2, double arg3, double arg4, double arg5) { throw NotImplementedException.createByLazy(Player.class, - "spawnParticle", - Particle.class, - Location.class, - int.class, - double.class, - double.class, - double.class); + "spawnParticle", + Particle.class, + Location.class, + int.class, + double.class, + double.class, + double.class); } @Override public void spawnParticle(@NotNull Particle arg0, double arg1, double arg2, double arg3, int arg4, double arg5, double arg6, double arg7) { throw NotImplementedException.createByLazy(Player.class, - "spawnParticle", - Particle.class, - double.class, - double.class, - double.class, - int.class, - double.class, - double.class, - double.class); + "spawnParticle", + Particle.class, + double.class, + double.class, + double.class, + int.class, + double.class, + double.class, + double.class); } @Override public void spawnParticle(@NotNull Particle arg0, @NotNull Location arg1, int arg2, double arg3, double arg4, double arg5, Object arg6) { throw NotImplementedException.createByLazy(Player.class, - "spawnParticle", - Particle.class, - Location.class, - int.class, - double.class, - double.class, - double.class, - Object.class); + "spawnParticle", + Particle.class, + Location.class, + int.class, + double.class, + double.class, + double.class, + Object.class); } @Override public void spawnParticle(@NotNull Particle arg0, double arg1, double arg2, double arg3, int arg4, double arg5, double arg6, double arg7, Object arg8) { throw NotImplementedException.createByLazy(Player.class, - "spawnParticle", - Particle.class, - double.class, - double.class, - double.class, - int.class, - double.class, - double.class, - double.class, - Object.class); + "spawnParticle", + Particle.class, + double.class, + double.class, + double.class, + int.class, + double.class, + double.class, + double.class, + Object.class); } @Override public void spawnParticle(@NotNull Particle arg0, @NotNull Location arg1, int arg2, double arg3, double arg4, double arg5, double arg6) { throw NotImplementedException.createByLazy(Player.class, - "spawnParticle", - Particle.class, - Location.class, - int.class, - double.class, - double.class, - double.class, - double.class); + "spawnParticle", + Particle.class, + Location.class, + int.class, + double.class, + double.class, + double.class, + double.class); } @Override public void spawnParticle(@NotNull Particle arg0, double arg1, double arg2, double arg3, int arg4, double arg5, double arg6, double arg7, double arg8) { throw NotImplementedException.createByLazy(Player.class, - "spawnParticle", - Particle.class, - double.class, - double.class, - double.class, - int.class, - double.class, - double.class, - double.class, - double.class); + "spawnParticle", + Particle.class, + double.class, + double.class, + double.class, + int.class, + double.class, + double.class, + double.class, + double.class); } @Override public void spawnParticle(@NotNull Particle particle, @NotNull Location location, int i, double v, double v1, double v2, double v3, @Nullable T t, boolean b) { throw NotImplementedException.createByLazy(Player.class, - "spawnParticle", - Particle.class, - Location.class, - int.class, - double.class, - double.class, - double.class, - double.class, - Object.class, - boolean.class); + "spawnParticle", + Particle.class, + Location.class, + int.class, + double.class, + double.class, + double.class, + double.class, + Object.class, + boolean.class); } @Override public void spawnParticle(@NotNull Particle particle, double v, double v1, double v2, int i, double v3, double v4, double v5, double v6, @Nullable T t, boolean b) { throw NotImplementedException.createByLazy(Player.class, - "spawnParticle", - Particle.class, - double.class, - double.class, - double.class, - int.class, - double.class, - double.class, - double.class, - double.class, - Object.class, - boolean.class); + "spawnParticle", + Particle.class, + double.class, + double.class, + double.class, + int.class, + double.class, + double.class, + double.class, + double.class, + Object.class, + boolean.class); } @Override public void spawnParticle(@NotNull Particle arg0, @NotNull Location arg1, int arg2, double arg3, double arg4, double arg5, double arg6, Object arg7) { throw NotImplementedException.createByLazy(Player.class, - "spawnParticle", - Particle.class, - Location.class, - int.class, - double.class, - double.class, - double.class, - double.class, - Object.class); + "spawnParticle", + Particle.class, + Location.class, + int.class, + double.class, + double.class, + double.class, + double.class, + Object.class); } @Override public void spawnParticle(@NotNull Particle arg0, double arg1, double arg2, double arg3, int arg4, double arg5, double arg6, double arg7, double arg8, Object arg9) { throw NotImplementedException.createByLazy(Player.class, - "spawnParticle", - Particle.class, - double.class, - double.class, - double.class, - int.class, - double.class, - double.class, - double.class, - double.class, - Object.class); + "spawnParticle", + Particle.class, + double.class, + double.class, + double.class, + int.class, + double.class, + double.class, + double.class, + double.class, + Object.class); } @Override public void spawnParticle(@NotNull Particle arg0, @NotNull Location arg1, int arg2) { throw NotImplementedException.createByLazy(Player.class, - "spawnParticle", - Particle.class, - Location.class, - int.class); + "spawnParticle", + Particle.class, + Location.class, + int.class); } @Override public void spawnParticle(@NotNull Particle arg0, double arg1, double arg2, double arg3, int arg4, Object arg5) { throw NotImplementedException.createByLazy(Player.class, - "spawnParticle", - Particle.class, - double.class, - double.class, - double.class, - int.class, - Object.class); + "spawnParticle", + Particle.class, + double.class, + double.class, + double.class, + int.class, + Object.class); } @Override public void spawnParticle(@NotNull Particle arg0, @NotNull Location arg1, int arg2, Object arg3) { throw NotImplementedException.createByLazy(Player.class, - "spawnParticle", - Particle.class, - Location.class, - int.class, - Object.class); + "spawnParticle", + Particle.class, + Location.class, + int.class, + Object.class); } @Override public void spawnParticle(@NotNull Particle arg0, double arg1, double arg2, double arg3, int arg4) { throw NotImplementedException.createByLazy(Player.class, - "spawnParticle", - Particle.class, - double.class, - double.class, - double.class, - int.class); + "spawnParticle", + Particle.class, + double.class, + double.class, + double.class, + int.class); } @Override @@ -961,6 +962,11 @@ public void openSign(@NotNull Sign sign, @NotNull Side side) { throw NotImplementedException.createByLazy(Player.class, "openSign", Sign.class, Side.class); } + @Override + public void openVirtualSign(Position block, Side side) { + throw NotImplementedException.createByLazy(Player.class, "openVirtualSign", Position.class, Side.class); + } + @Override public void showDemoScreen() { throw NotImplementedException.createByLazy(Player.class, "showDemoScreen"); @@ -991,12 +997,12 @@ public boolean hasResourcePack() { @Override public void addResourcePack(@NotNull UUID uuid, @NotNull String s, byte[] bytes, @Nullable String s1, boolean b) { throw NotImplementedException.createByLazy(Player.class, - "addResourcePack", - UUID.class, - String.class, - byte[].class, - String.class, - boolean.class); + "addResourcePack", + UUID.class, + String.class, + byte[].class, + String.class, + boolean.class); } @Override @@ -1072,23 +1078,13 @@ public String getClientBrandName() { throw NotImplementedException.createByLazy(Player.class, "getClientBrandName"); } - @Override - public void lookAt(double v, double v1, double v2, @NotNull LookAnchor lookAnchor) { - throw NotImplementedException.createByLazy(Player.class, - "lookAt", - double.class, - double.class, - double.class, - LookAnchor.class); - } - @Override public void lookAt(@NotNull Entity entity, @NotNull LookAnchor lookAnchor, @NotNull LookAnchor lookAnchor1) { throw NotImplementedException.createByLazy(Player.class, - "lookAt", - Entity.class, - LookAnchor.class, - LookAnchor.class); + "lookAt", + Entity.class, + LookAnchor.class, + LookAnchor.class); } @Override @@ -1178,6 +1174,26 @@ public void sendEntityEffect(@NotNull EntityEffect entityEffect, @NotNull Entity throw NotImplementedException.createByLazy(Player.class, "sendEntityEffect", EntityEffect.class, Entity.class); } + @Override + public PlayerGiveResult give(Collection items, boolean dropIfFull) { + return null; + } + + @Override + public int getDeathScreenScore() { + return 0; + } + + @Override + public void setDeathScreenScore(int score) { + + } + + @Override + public PlayerGameConnection getConnection() { + return null; + } + @Override public void giveExp(int arg0, boolean arg1) { throw NotImplementedException.createByLazy(Player.class, "giveExp", int.class, boolean.class); @@ -1215,6 +1231,16 @@ public void setPlayerListName(String arg0) { throw NotImplementedException.createByLazy(Player.class, "setPlayerListName", String.class); } + @Override + public int getPlayerListOrder() { + throw NotImplementedException.createByLazy(Player.class, "getPlayerListOrder"); + } + + @Override + public void setPlayerListOrder(int order) { + throw NotImplementedException.createByLazy(Player.class, "setPlayerListOrder", int.class); + } + @Deprecated @Override public String getPlayerListHeader() { @@ -1243,27 +1269,27 @@ public void setPlayerListFooter(String arg0) { @Override public void setPlayerListHeaderFooter(BaseComponent[] arg0, BaseComponent[] arg1) { throw NotImplementedException.createByLazy(Player.class, - "setPlayerListHeaderFooter", - BaseComponent[].class, - BaseComponent[].class); + "setPlayerListHeaderFooter", + BaseComponent[].class, + BaseComponent[].class); } @Deprecated @Override public void setPlayerListHeaderFooter(String arg0, String arg1) { throw NotImplementedException.createByLazy(Player.class, - "setPlayerListHeaderFooter", - String.class, - String.class); + "setPlayerListHeaderFooter", + String.class, + String.class); } @Deprecated @Override public void setPlayerListHeaderFooter(BaseComponent arg0, BaseComponent arg1) { throw NotImplementedException.createByLazy(Player.class, - "setPlayerListHeaderFooter", - BaseComponent.class, - BaseComponent.class); + "setPlayerListHeaderFooter", + BaseComponent.class, + BaseComponent.class); } @Override @@ -1300,9 +1326,9 @@ public void abandonConversation(@NotNull Conversation conversation) { @Override public void abandonConversation(@NotNull Conversation conversation, @NotNull ConversationAbandonedEvent details) { throw NotImplementedException.createByLazy(Player.class, - "abandonConversation", - Conversation.class, - ConversationAbandonedEvent.class); + "abandonConversation", + Conversation.class, + ConversationAbandonedEvent.class); } @Override @@ -1331,22 +1357,22 @@ public void kick(Component arg0, @NotNull PlayerKickEvent.Cause arg1) { public > @Nullable E ban(@Nullable String s, @Nullable Date date, @Nullable String s1, boolean b) { throw NotImplementedException.createByLazy(Player.class, - "ban", - String.class, - Date.class, - String.class, - boolean.class); + "ban", + String.class, + Date.class, + String.class, + boolean.class); } @Override public > @Nullable E ban(@Nullable String s, @Nullable Instant instant, @Nullable String s1, boolean b) { throw NotImplementedException.createByLazy(Player.class, - "ban", - String.class, - Instant.class, - String.class, - boolean.class); + "ban", + String.class, + Instant.class, + String.class, + boolean.class); } @@ -1355,22 +1381,22 @@ public void kick(Component arg0, @NotNull PlayerKickEvent.Cause arg1) { @Nullable Duration duration, @Nullable String s1, boolean b) { throw NotImplementedException.createByLazy(Player.class, - "ban", - String.class, - Duration.class, - String.class, - boolean.class); + "ban", + String.class, + Duration.class, + String.class, + boolean.class); } @Override public @Nullable BanEntry banIp(@Nullable String s, @Nullable Date date, @Nullable String s1, boolean b) { throw NotImplementedException.createByLazy(Player.class, - "ban", - String.class, - Date.class, - String.class, - boolean.class); + "ban", + String.class, + Date.class, + String.class, + boolean.class); } @@ -1378,22 +1404,22 @@ public void kick(Component arg0, @NotNull PlayerKickEvent.Cause arg1) { public @Nullable BanEntry banIp(@Nullable String s, @Nullable Instant instant, @Nullable String s1, boolean b) { throw NotImplementedException.createByLazy(Player.class, - "ban", - String.class, - Instant.class, - String.class, - boolean.class); + "ban", + String.class, + Instant.class, + String.class, + boolean.class); } @Override public @Nullable BanEntry banIp(@Nullable String s, @Nullable Duration duration, @Nullable String s1 , boolean b) { throw NotImplementedException.createByLazy(Player.class, - "ban", - String.class, - Duration.class, - String.class, - boolean.class); + "ban", + String.class, + Duration.class, + String.class, + boolean.class); } @Override @@ -1476,6 +1502,12 @@ public void setBedSpawnLocation(@Nullable Location location) { throw NotImplementedException.createByLazy(Player.class, "getRespawnLocation"); } + @Override + public @org.jspecify.annotations.Nullable Location getRespawnLocation(boolean loadLocationAndValidate) { + throw NotImplementedException.createByLazy(Player.class, "getRespawnLocation", boolean.class); + + } + @Override public void setRespawnLocation(@Nullable Location location) { throw NotImplementedException.createByLazy(Player.class, "setRespawnLocation", Location.class); @@ -1486,6 +1518,16 @@ public void setRespawnLocation(@Nullable Location location, boolean b) { throw NotImplementedException.createByLazy(Player.class, "setRespawnLocation", Location.class, boolean.class); } + @Override + public Collection getEnderPearls() { + throw NotImplementedException.createByLazy(Player.class, "getEnderPearls"); + } + + @Override + public Input getCurrentInput() { + throw NotImplementedException.createByLazy(Player.class, "getCurrentInput"); + } + @Override public void setBedSpawnLocation(@Nullable Location location, boolean force) { var world = (SoakWorld) (location == null ? this.getWorld() : location.getWorld()); @@ -1508,75 +1550,72 @@ public void playNote(@NotNull Location arg0, byte arg1, byte arg2) { @Override public void playNote(@NotNull Location arg0, @NotNull Instrument arg1, @NotNull Note arg2) { throw NotImplementedException.createByLazy(Player.class, - "playNote", - Location.class, - Instrument.class, - Note.class); + "playNote", + Location.class, + Instrument.class, + Note.class); } @Override public void playSound(@NotNull Location arg0, @NotNull Sound arg1, float arg2, float arg3) { throw NotImplementedException.createByLazy(Player.class, - "playSound", - Location.class, - Sound.class, - float.class, - float.class); + "playSound", + Location.class, + Sound.class, + float.class, + float.class); } @Override public void playSound(@NotNull Location arg0, @NotNull String arg1, @NotNull SoundCategory arg2, float arg3, float arg4) { - var soundType = SoakSoundMap.toSponge(arg1); - var soundSource = SoakSoundMap.toAdventure(arg2); - var sound = net.kyori.adventure.sound.Sound.sound(soundType, soundSource, arg3, arg4); - this.spongeEntity().playSound(sound, new Vector3d(arg0.getX(), arg0.getY(), arg0.getZ())); + throw NotImplementedException.createByLazy(Player.class, "playSound", Location.class, String.class, SoundCategory.class, float.class, float.class); } @Override public void playSound(@NotNull Location location, @NotNull Sound sound, @NotNull SoundCategory soundCategory, float v, float v1, long l) { throw NotImplementedException.createByLazy(Player.class, - "playSound", - Location.class, - Sound.class, - SoundCategory.class, - float.class, - float.class, - long.class); + "playSound", + Location.class, + Sound.class, + SoundCategory.class, + float.class, + float.class, + long.class); } @Override public void playSound(@NotNull Location location, @NotNull String s, @NotNull SoundCategory soundCategory, float v, float v1, long l) { throw NotImplementedException.createByLazy(Player.class, - "playSound", - Location.class, - String.class, - SoundCategory.class, - float.class, - float.class, - long.class); + "playSound", + Location.class, + String.class, + SoundCategory.class, + float.class, + float.class, + long.class); } @Override public void playSound(@NotNull Entity entity, @NotNull Sound sound, float v, float v1) { throw NotImplementedException.createByLazy(Player.class, - "playSound", - Entity.class, - Sound.class, - float.class, - float.class); + "playSound", + Entity.class, + Sound.class, + float.class, + float.class); } @Override public void playSound(@NotNull Entity entity, @NotNull String s, float v, float v1) { throw NotImplementedException.createByLazy(Player.class, - "playSound", - Entity.class, - String.class, - float.class, - float.class); + "playSound", + Entity.class, + String.class, + float.class, + float.class); } @@ -1584,12 +1623,12 @@ public void playSound(@NotNull Entity entity, @NotNull String s, float v, float public void playSound(@NotNull Entity entity, @NotNull Sound sound, @NotNull SoundCategory soundCategory, float v , float v1) { throw NotImplementedException.createByLazy(Player.class, - "playSound", - Entity.class, - Sound.class, - SoundCategory.class, - float.class, - float.class); + "playSound", + Entity.class, + Sound.class, + SoundCategory.class, + float.class, + float.class); } @@ -1597,60 +1636,60 @@ public void playSound(@NotNull Entity entity, @NotNull Sound sound, @NotNull Sou public void playSound(@NotNull Entity entity, @NotNull String s, @NotNull SoundCategory soundCategory, float v, float v1) { throw NotImplementedException.createByLazy(Player.class, - "playSound", - Entity.class, - String.class, - SoundCategory.class, - float.class, - float.class); + "playSound", + Entity.class, + String.class, + SoundCategory.class, + float.class, + float.class); } @Override public void playSound(@NotNull Entity entity, @NotNull Sound sound, @NotNull SoundCategory soundCategory, float v , float v1, long l) { throw NotImplementedException.createByLazy(Player.class, - "playSound", - Entity.class, - Sound.class, - SoundCategory.class, - float.class, - float.class, - long.class); + "playSound", + Entity.class, + Sound.class, + SoundCategory.class, + float.class, + float.class, + long.class); } @Override public void playSound(@NotNull Entity entity, @NotNull String s, @NotNull SoundCategory soundCategory, float v, float v1, long l) { throw NotImplementedException.createByLazy(Player.class, - "playSound", - Entity.class, - String.class, - SoundCategory.class, - float.class, - float.class, - long.class); + "playSound", + Entity.class, + String.class, + SoundCategory.class, + float.class, + float.class, + long.class); } @Override public void playSound(@NotNull Location arg0, @NotNull String arg1, float arg2, float arg3) { throw NotImplementedException.createByLazy(Player.class, - "playSound", - Location.class, - String.class, - float.class, - float.class); + "playSound", + Location.class, + String.class, + float.class, + float.class); } @Override public void playSound(@NotNull Location arg0, @NotNull Sound arg1, @NotNull SoundCategory arg2, float arg3, float arg4) { throw NotImplementedException.createByLazy(Player.class, - "playSound", - Location.class, - Sound.class, - SoundCategory.class, - float.class, - float.class); + "playSound", + Location.class, + Sound.class, + SoundCategory.class, + float.class, + float.class); } @Override @@ -1698,10 +1737,10 @@ public boolean breakBlock(@NotNull Block block) { @Override public void playEffect(@NotNull Location arg0, @NotNull Effect arg1, Object arg2) { throw NotImplementedException.createByLazy(Player.class, - "playEffect", - Location.class, - Effect.class, - Object.class); + "playEffect", + Location.class, + Effect.class, + Object.class); } @Override @@ -1709,9 +1748,9 @@ public void sendBlockChange(@NotNull Location atPosition, @NotNull BlockData dat SoakBlockData soakData = (SoakBlockData) data; this.spongeEntity() .sendBlockChange(atPosition.getBlockX(), - atPosition.getBlockY(), - atPosition.getBlockZ(), - soakData.sponge()); + atPosition.getBlockY(), + atPosition.getBlockZ(), + soakData.sponge()); } @Override @@ -1735,10 +1774,10 @@ public void sendBlockChanges(@NotNull Collection collection, boolean @Override public void sendBlockChange(@NotNull Location arg0, @NotNull Material arg1, byte arg2) { throw NotImplementedException.createByLazy(Player.class, - "sendBlockChange", - Location.class, - Material.class, - byte.class); + "sendBlockChange", + Location.class, + Material.class, + byte.class); } @Override @@ -1762,10 +1801,10 @@ public void sendMultiBlockChange(@NotNull Map map @Override public void sendBlockDamage(@NotNull Location location, float v, @NotNull Entity entity) { throw NotImplementedException.createByLazy(Player.class, - "sendBlockDamage", - Location.class, - float.class, - Entity.class); + "sendBlockDamage", + Location.class, + float.class, + Entity.class); } @@ -1778,10 +1817,10 @@ public void sendBlockDamage(@NotNull Location location, float v, int i) { public void sendEquipmentChange(@NotNull LivingEntity livingEntity, @NotNull EquipmentSlot equipmentSlot, @Nullable ItemStack itemStack) { throw NotImplementedException.createByLazy(Player.class, - "sendEquipmentChange", - LivingEntity.class, - EquipmentSlot.class, - ItemStack.class); + "sendEquipmentChange", + LivingEntity.class, + EquipmentSlot.class, + ItemStack.class); } @@ -1796,22 +1835,22 @@ public void sendSignChange(@NotNull Location location, @Nullable List> @Nullable E ban(@Nullable String s, @Nullable Date date, @Nullable String s1) { - throw NotImplementedException.createByLazy(OfflinePlayer.class, "ban", String.class, Date.class, String.class); - } - - @Override - public > @Nullable E ban(@Nullable String s, @Nullable Instant instant, @Nullable String s1) { - throw NotImplementedException.createByLazy(OfflinePlayer.class, "ban", String.class, Instant.class, String.class); - } - - @Override - public > @Nullable E ban(@Nullable String s, @Nullable Duration duration, @Nullable String s1) { - throw NotImplementedException.createByLazy(OfflinePlayer.class, "ban", String.class, Duration.class, String.class); - } - - @Override - public @Nullable String getName() { - return user.name(); - } - - @Override - public @NotNull UUID getUniqueId() { - return user.uniqueId(); - } - - @Override - public @NotNull PlayerProfile getPlayerProfile() { - return new SoakPlayerProfile(user.profile(), true); - } - - @Override - public boolean isBanned() { - throw NotImplementedException.createByLazy(OfflinePlayer.class, "isBanned"); - } - - @Override - public boolean isWhitelisted() { - throw NotImplementedException.createByLazy(OfflinePlayer.class, "isWhitelisted"); - } - - @Override - public void setWhitelisted(boolean b) { - throw NotImplementedException.createByLazy(OfflinePlayer.class, "isWhitelisted", boolean.class); - } - - @Override - public @Nullable Player getPlayer() { - return user.player().map(player -> SoakManager.getManager().getMemoryStore().get(player)).orElse(null); - } - - @Override - public long getFirstPlayed() { - return user.get(Keys.FIRST_DATE_JOINED).map(Instant::getNano).orElse(0); - } - - @Override - public long getLastPlayed() { - return user.get(Keys.LAST_DATE_JOINED).map(Instant::getNano).orElse(0); - } - - @Override - public boolean hasPlayedBefore() { - return user.get(Keys.FIRST_DATE_JOINED).isPresent(); - } - - @Override - public @Nullable Location getBedSpawnLocation() { - return user - .get(Keys.RESPAWN_LOCATIONS) - .map(map -> map.get(user.worldKey())) - .flatMap(RespawnLocation::asLocation) - .map(SoakLocationMap::toBukkit) - .orElse(null); - } - - @Override - public long getLastLogin() { - return this.getLastPlayed(); - } - - @Override - public long getLastSeen() { - return this.getLastPlayed(); - } - - @Override - public void incrementStatistic(@NotNull Statistic statistic) throws IllegalArgumentException { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, "incrementStatistic", Statistic.class); - } - - @Override - public void decrementStatistic(@NotNull Statistic statistic) throws IllegalArgumentException { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, "decrementStatistic", Statistic.class); - - } - - @Override - public void incrementStatistic(@NotNull Statistic statistic, int i) throws IllegalArgumentException { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, "incrementStatistic", Statistic.class, int.class); - - } - - @Override - public void decrementStatistic(@NotNull Statistic statistic, int i) throws IllegalArgumentException { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, "decrementStatistic", Statistic.class, int.class); - - } - - @Override - public void setStatistic(@NotNull Statistic statistic, int i) throws IllegalArgumentException { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, "setStatistic", Statistic.class, int.class); - } - - @Override - public int getStatistic(@NotNull Statistic statistic) throws IllegalArgumentException { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, "getStatistic", Statistic.class); - } - - @Override - public void incrementStatistic(@NotNull Statistic statistic, @NotNull Material material) throws IllegalArgumentException { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, "incrementStatistic", Statistic.class, Material.class); - } - - @Override - public void decrementStatistic(@NotNull Statistic statistic, @NotNull Material material) throws IllegalArgumentException { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, "decrementStatistic", Statistic.class, Material.class); - } - - @Override - public int getStatistic(@NotNull Statistic statistic, @NotNull Material material) throws IllegalArgumentException { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, "getStatistic", Statistic.class, Material.class); - } - - @Override - public void incrementStatistic(@NotNull Statistic statistic, @NotNull Material material, int i) throws IllegalArgumentException { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, "incrementStatistic", Statistic.class, Material.class, int.class); - } - - @Override - public void decrementStatistic(@NotNull Statistic statistic, @NotNull Material material, int i) throws IllegalArgumentException { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, "decrementStatistic", Statistic.class, Material.class, int.class); - } - - @Override - public void setStatistic(@NotNull Statistic statistic, @NotNull Material material, int i) throws IllegalArgumentException { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, "setStatistic", Statistic.class, Material.class, int.class); - } - - @Override - public void incrementStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType) throws IllegalArgumentException { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, "incrementStatistic", Statistic.class, EntityType.class); - - } - - @Override - public void decrementStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType) throws IllegalArgumentException { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, "decrementStatistic", Statistic.class, EntityType.class); - } - - @Override - public int getStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType) throws IllegalArgumentException { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, "getStatistic", Statistic.class, EntityType.class); - } - - @Override - public void incrementStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType, int i) throws IllegalArgumentException { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, "incrementStatistic", Statistic.class, EntityType.class, int.class); - } - - @Override - public void decrementStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType, int i) { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, "decrementStatistic", Statistic.class); - } - - @Override - public void setStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType, int i) { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, "setStatistic", Statistic.class, EntityType.class, int.class); - } - - @Override - public @Nullable Location getLastDeathLocation() { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, "getLastDeathLocation"); - } - - @Override - public @NotNull Map serialize() { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, "serialize"); - } - - @Override - public boolean isOp() { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, "isOp"); - } - - @Override - public void setOp(boolean b) { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, "setOp", boolean.class); - } -} diff --git a/Wrapper/src/main/java/org/soak/wrapper/entity/living/human/user/SoakLoadingUser.java b/Wrapper/src/main/java/org/soak/wrapper/entity/living/human/user/SoakLoadingUser.java deleted file mode 100644 index d55fe98..0000000 --- a/Wrapper/src/main/java/org/soak/wrapper/entity/living/human/user/SoakLoadingUser.java +++ /dev/null @@ -1,338 +0,0 @@ -package org.soak.wrapper.entity.living.human.user; - -import com.destroystokyo.paper.profile.PlayerProfile; -import io.papermc.paper.persistence.PersistentDataContainerView; -import org.bukkit.*; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.soak.WrapperManager; -import org.soak.exception.NotImplementedException; -import org.soak.plugin.SoakManager; -import org.soak.wrapper.profile.SoakPlayerProfile; -import org.spongepowered.api.Sponge; -import org.spongepowered.api.profile.GameProfile; - -import java.time.Duration; -import java.time.Instant; -import java.util.Date; -import java.util.Map; -import java.util.UUID; -import java.util.function.Function; - -@Deprecated(forRemoval = true) -public class SoakLoadingUser implements OfflinePlayer { - - private final GameProfile profile; - private @Nullable SoakLoadedUser loaded; - - public SoakLoadingUser(@NotNull GameProfile profile) { - this.profile = profile; - Sponge.server() - .userManager() - .loadOrCreate(profile.uuid()) - .thenAccept(user -> loaded = new SoakLoadedUser(user)); - } - - private T checkLoadedSimple(Function run, T value) { - return checkLoaded(run, profile -> value); - } - - private T checkLoaded(Function run, Function elser) { - if (this.loaded == null) { - return elser.apply(this.profile); - } - return run.apply(this.loaded); - } - - @Override - public boolean isOnline() { - return checkLoadedSimple(SoakLoadedUser::isOnline, false); - } - - @Override - public boolean isConnected() { - throw NotImplementedException.createByLazy(OfflinePlayer.class, "isConnected"); - } - - @Override - public @Nullable String getName() { - return profile.name().orElse(null); - } - - @Override - public @NotNull UUID getUniqueId() { - return profile.uniqueId(); - } - - @Override - public @NotNull PlayerProfile getPlayerProfile() { - return new SoakPlayerProfile(this.profile, true); - } - - @Override - public boolean isBanned() { - throw NotImplementedException.createByLazy(OfflinePlayer.class, "isBanned"); - } - - @Override - public > @Nullable E ban(@Nullable String s, @Nullable Date date, - @Nullable String s1) { - throw NotImplementedException.createByLazy(OfflinePlayer.class, "ban", String.class, Date.class, String.class); - } - - @Override - public > @Nullable E ban(@Nullable String s, @Nullable Instant instant, - @Nullable String s1) { - throw NotImplementedException.createByLazy(OfflinePlayer.class, - "ban", - String.class, - Instant.class, - String.class); - } - - @Override - public > @Nullable E ban(@Nullable String s, - @Nullable Duration duration, - @Nullable String s1) { - throw NotImplementedException.createByLazy(OfflinePlayer.class, - "ban", - String.class, - Duration.class, - String.class); - } - - @Override - public boolean isWhitelisted() { - throw NotImplementedException.createByLazy(OfflinePlayer.class, "isWhitelisted"); - } - - @Override - public void setWhitelisted(boolean b) { - throw NotImplementedException.createByLazy(OfflinePlayer.class, "isWhitelisted", boolean.class); - } - - @Override - public @Nullable Player getPlayer() { - return Sponge.server() - .onlinePlayers() - .stream() - .filter(player -> player.profile().equals(this.profile)) - .findAny() - .map(player -> SoakManager.getManager().getMemoryStore().get(player)) - .orElse(null); - } - - @Override - public long getFirstPlayed() { - return checkLoadedSimple(SoakLoadedUser::getFirstPlayed, 0L); - } - - @Override - public long getLastPlayed() { - return checkLoadedSimple(SoakLoadedUser::getLastPlayed, 0L); - } - - @Override - public boolean hasPlayedBefore() { - return checkLoadedSimple(SoakLoadedUser::hasPlayedBefore, false); - } - - @Override - public @Nullable Location getBedSpawnLocation() { - return checkLoadedSimple(SoakLoadedUser::getBedSpawnLocation, null); - } - - @Override - public long getLastLogin() { - return this.getLastPlayed(); - } - - @Override - public long getLastSeen() { - return this.getLastPlayed(); - } - - @Override - public @Nullable Location getRespawnLocation() { - throw NotImplementedException.createByLazy(OfflinePlayer.class, "getRespawnLocation"); - } - - @Override - public void incrementStatistic(@NotNull Statistic statistic) throws IllegalArgumentException { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, "incrementStatistic", Statistic.class); - } - - @Override - public void decrementStatistic(@NotNull Statistic statistic) throws IllegalArgumentException { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, "decrementStatistic", Statistic.class); - - } - - @Override - public void incrementStatistic(@NotNull Statistic statistic, int i) throws IllegalArgumentException { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, - "incrementStatistic", - Statistic.class, - int.class); - - } - - @Override - public void decrementStatistic(@NotNull Statistic statistic, int i) throws IllegalArgumentException { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, - "decrementStatistic", - Statistic.class, - int.class); - - } - - @Override - public void setStatistic(@NotNull Statistic statistic, int i) throws IllegalArgumentException { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, "setStatistic", Statistic.class, int.class); - } - - @Override - public int getStatistic(@NotNull Statistic statistic) throws IllegalArgumentException { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, "getStatistic", Statistic.class); - } - - @Override - public void incrementStatistic(@NotNull Statistic statistic, @NotNull Material material) - throws IllegalArgumentException { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, - "incrementStatistic", - Statistic.class, - Material.class); - } - - @Override - public void decrementStatistic(@NotNull Statistic statistic, @NotNull Material material) - throws IllegalArgumentException { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, - "decrementStatistic", - Statistic.class, - Material.class); - } - - @Override - public int getStatistic(@NotNull Statistic statistic, @NotNull Material material) throws IllegalArgumentException { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, - "getStatistic", - Statistic.class, - Material.class); - } - - @Override - public void incrementStatistic(@NotNull Statistic statistic, @NotNull Material material, int i) - throws IllegalArgumentException { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, - "incrementStatistic", - Statistic.class, - Material.class, - int.class); - } - - @Override - public void decrementStatistic(@NotNull Statistic statistic, @NotNull Material material, int i) - throws IllegalArgumentException { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, - "decrementStatistic", - Statistic.class, - Material.class, - int.class); - } - - @Override - public void setStatistic(@NotNull Statistic statistic, @NotNull Material material, int i) - throws IllegalArgumentException { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, - "setStatistic", - Statistic.class, - Material.class, - int.class); - } - - @Override - public void incrementStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType) - throws IllegalArgumentException { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, - "incrementStatistic", - Statistic.class, - EntityType.class); - - } - - @Override - public void decrementStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType) - throws IllegalArgumentException { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, - "decrementStatistic", - Statistic.class, - EntityType.class); - } - - @Override - public int getStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType) - throws IllegalArgumentException { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, - "getStatistic", - Statistic.class, - EntityType.class); - } - - @Override - public void incrementStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType, int i) - throws IllegalArgumentException { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, - "incrementStatistic", - Statistic.class, - EntityType.class, - int.class); - } - - @Override - public void decrementStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType, int i) { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, "decrementStatistic", Statistic.class); - } - - @Override - public void setStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType, int i) { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, - "setStatistic", - Statistic.class, - EntityType.class, - int.class); - } - - @Override - public @Nullable Location getLastDeathLocation() { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, "getLastDeathLocation"); - } - - @Override - public @Nullable Location getLocation() { - throw NotImplementedException.createByLazy(OfflinePlayer.class, "getLocation"); - } - - @Override - public @NotNull PersistentDataContainerView getPersistentDataContainer() { - throw NotImplementedException.createByLazy(OfflinePlayer.class, "getPersistentDataContainer"); - } - - @Override - public @NotNull Map serialize() { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, "serialize"); - } - - @Override - public boolean isOp() { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, "isOp"); - } - - @Override - public void setOp(boolean b) { - throw NotImplementedException.createByLazy(SoakLoadedUser.class, "setOp", boolean.class); - } -} diff --git a/Wrapper/src/main/java/org/soak/wrapper/inventory/SoakItemTypeTyped.java b/Wrapper/src/main/java/org/soak/wrapper/inventory/SoakItemTypeTyped.java index 6f095e0..1a78a4a 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/inventory/SoakItemTypeTyped.java +++ b/Wrapper/src/main/java/org/soak/wrapper/inventory/SoakItemTypeTyped.java @@ -1,6 +1,7 @@ package org.soak.wrapper.inventory; import com.google.common.collect.Multimap; +import io.papermc.paper.datacomponent.DataComponentType; import net.kyori.adventure.text.TranslatableComponent; import org.bukkit.Material; import org.bukkit.NamespacedKey; @@ -22,6 +23,7 @@ import org.spongepowered.api.tag.ItemTypeTags; import java.lang.reflect.InvocationTargetException; +import java.util.Set; import java.util.function.Consumer; public class SoakItemTypeTyped implements ItemType.Typed { @@ -88,6 +90,11 @@ public boolean isFuel() { throw NotImplementedException.createByLazy(ItemType.class, "isFuel"); } + @Override + public int getBurnDuration() { + return this.type.get(Keys.BURN_TIME).orElse(-1); + } + @Override public boolean isCompostable() { throw NotImplementedException.createByLazy(ItemType.class, "isCompostable"); @@ -139,6 +146,21 @@ public boolean isEnabledByFeature(@NotNull World world) { throw NotImplementedException.createByLazy(ItemType.class, "ItemRarity"); } + @Override + public @org.jspecify.annotations.Nullable T getDefaultData(DataComponentType.Valued type) { + throw NotImplementedException.createByLazy(this, "getDefaultData", DataComponentType.Valued.class); + } + + @Override + public boolean hasDefaultData(DataComponentType type) { + throw NotImplementedException.createByLazy(this, "hasDefaultData", DataComponentType.class); + } + + @Override + public @Unmodifiable Set getDefaultDataTypes() { + throw NotImplementedException.createByLazy(this, "getDefaultDataTypes"); + } + @Override public @NotNull ItemStack createItemStack() { return createItemStack(1); diff --git a/Wrapper/src/main/java/org/soak/wrapper/inventory/SoakMenuType.java b/Wrapper/src/main/java/org/soak/wrapper/inventory/SoakMenuType.java index c10fb9a..53cad8f 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/inventory/SoakMenuType.java +++ b/Wrapper/src/main/java/org/soak/wrapper/inventory/SoakMenuType.java @@ -1,24 +1,24 @@ package org.soak.wrapper.inventory; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.NamespacedKey; import org.bukkit.entity.HumanEntity; import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.MenuType; +import org.bukkit.inventory.view.builder.InventoryViewBuilder; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.soak.exception.NotImplementedException; import org.soak.map.SoakMessageMap; import org.soak.map.SoakResourceKeyMap; import org.soak.utils.GeneralHelper; import org.soak.wrapper.entity.living.human.SoakPlayer; import org.soak.wrapper.inventory.view.AbstractInventoryView; -import org.spongepowered.api.item.inventory.Container; import org.spongepowered.api.item.inventory.ContainerType; import org.spongepowered.api.item.inventory.type.ViewableInventory; import org.spongepowered.api.registry.RegistryTypes; -public class SoakMenuType implements MenuType.Typed { +public class SoakMenuType> implements MenuType.Typed { private final ContainerType type; private final @Nullable Class typeClass; @@ -46,16 +46,19 @@ public SoakMenuType(ContainerType type, @Nullable Class typeClass) { return (View) AbstractInventoryView.wrap(container); } - @NotNull @Override - public Typed typed() { + public Typed> typed() { return new SoakMenuType<>(this.type); } - @NotNull @Override - public Typed typed(@NotNull Class aClass) throws IllegalArgumentException { - return new SoakMenuType<>(this.type, aClass); + public > Typed typed(Class viewClass) throws IllegalArgumentException { + return new SoakMenuType<>(this.type, viewClass); + } + + @Override + public Builder builder() { + throw NotImplementedException.createByLazy(MenuType.Typed.class, "builder"); } @Override diff --git a/Wrapper/src/main/java/org/soak/wrapper/inventory/meta/AbstractItemMeta.java b/Wrapper/src/main/java/org/soak/wrapper/inventory/meta/AbstractItemMeta.java index 1c0f5de..75e8c0d 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/inventory/meta/AbstractItemMeta.java +++ b/Wrapper/src/main/java/org/soak/wrapper/inventory/meta/AbstractItemMeta.java @@ -3,29 +3,29 @@ import com.destroystokyo.paper.Namespaced; import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; +import io.papermc.paper.registry.set.RegistryKeySet; import net.kyori.adventure.text.Component; import net.md_5.bungee.api.chat.BaseComponent; import org.bukkit.Material; +import org.bukkit.NamespacedKey; +import org.bukkit.Tag; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeModifier; +import org.bukkit.damage.DamageType; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemRarity; import org.bukkit.inventory.meta.Damageable; import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.components.FoodComponent; -import org.bukkit.inventory.meta.components.JukeboxPlayableComponent; -import org.bukkit.inventory.meta.components.ToolComponent; +import org.bukkit.inventory.meta.components.*; import org.bukkit.inventory.meta.tags.CustomItemTagContainer; import org.bukkit.persistence.PersistentDataContainer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.mose.collection.stream.builder.CollectionStreamBuilder; import org.soak.exception.NotImplementedException; -import org.soak.map.SoakAttributeMap; -import org.soak.map.SoakBlockMap; -import org.soak.map.SoakMessageMap; +import org.soak.map.*; import org.soak.map.item.SoakEnchantmentTypeMap; import org.soak.map.item.SoakItemFlagMap; import org.soak.map.item.SoakItemStackMap; @@ -48,7 +48,6 @@ import org.spongepowered.api.item.inventory.ItemStackSnapshot; import org.spongepowered.api.item.inventory.equipment.EquipmentType; import org.spongepowered.api.registry.RegistryTypes; -import org.spongepowered.api.util.Ticks; import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; @@ -65,12 +64,180 @@ protected AbstractItemMeta(ItemStackLike container) { } /* - Required for ConfigurationSerializable - */ + Required for ConfigurationSerializable + */ public static ItemMeta deserialize(Map values) { return ItemMetaSerializer.deserialize(values); } + @Override + public boolean hasCustomName() { + return container.get(Keys.CUSTOM_NAME).isPresent(); + } + + @Override + public @Nullable Component customName() { + return container.get(Keys.CUSTOM_NAME).orElse(null); + } + + @Override + public void customName(@Nullable Component customName) { + this.set(Keys.CUSTOM_NAME, customName); + } + + @Override + public @NotNull CustomModelDataComponent getCustomModelDataComponent() { + throw new NotImplementedException(); + } + + @Override + public void setCustomModelDataComponent(@Nullable CustomModelDataComponent customModelData) { + throw new NotImplementedException(); + + } + + @Override + public boolean hasCustomModelDataComponent() { + throw new NotImplementedException(); + } + + @Override + public boolean hasEnchantable() { + throw new NotImplementedException(); + + } + + @Override + public int getEnchantable() { + throw new NotImplementedException(); + + } + + @Override + public void setEnchantable(@Nullable Integer enchantable) { + throw new NotImplementedException(); + + } + + @Override + public boolean hasTooltipStyle() { + return this.container.get(Keys.TOOLTIP_STYLE).isPresent(); + } + + @Override + public @Nullable NamespacedKey getTooltipStyle() { + return this.container.get(Keys.TOOLTIP_STYLE).map(SoakResourceKeyMap::mapToBukkit).orElse(null); + } + + @Override + public void setTooltipStyle(@Nullable NamespacedKey tooltipStyle) { + if (tooltipStyle == null) { + this.remove(Keys.TOOLTIP_STYLE); + return; + } + this.set(Keys.TOOLTIP_STYLE, SoakResourceKeyMap.mapToSponge(tooltipStyle)); + } + + @Override + public boolean hasItemModel() { + return this.container.get(Keys.MODEL).isPresent(); + } + + @Override + public @Nullable NamespacedKey getItemModel() { + return this.container.get(Keys.MODEL).map(SoakResourceKeyMap::mapToBukkit).orElse(null); + } + + @Override + public void setItemModel(@Nullable NamespacedKey itemModel) { + if (itemModel == null) { + this.remove(Keys.MODEL); + return; + } + this.set(Keys.MODEL, SoakResourceKeyMap.mapToSponge(itemModel)); + } + + @Override + public boolean isGlider() { + throw NotImplementedException.createByLazy(ItemMeta.class, "isGlider"); + } + + @Override + public void setGlider(boolean glider) { +throw NotImplementedException.createByLazy(ItemMeta.class, "setGlider", boolean.class); + } + + @Override + public boolean hasDamageResistant() { + throw NotImplementedException.createByLazy(ItemMeta.class, "hasDamageResistant"); + } + + @Override + public @Nullable Tag getDamageResistant() { + throw NotImplementedException.createByLazy(ItemMeta.class, "getDamageResisant"); + } + + @Override + public void setDamageResistant(@Nullable Tag tag) { +throw NotImplementedException.createByLazy(ItemMeta.class, "setDamageResistant", Tag.class); + } + + @Override + public @Nullable RegistryKeySet getDamageResistantTypes() { + throw new NotImplementedException(); + } + + @Override + public void setDamageResistantTypes(@Nullable RegistryKeySet types) { + throw new NotImplementedException(); + } + + @Override + public boolean hasUseRemainder() { + throw new NotImplementedException(); + + } + + @Override + public org.bukkit.inventory.@Nullable ItemStack getUseRemainder() { + throw new NotImplementedException(); + } + + @Override + public void setUseRemainder(org.bukkit.inventory.@Nullable ItemStack remainder) { + throw new NotImplementedException(); + } + + @Override + public boolean hasUseCooldown() { + return this.container.get(Keys.COOLDOWN).isPresent(); + } + + @Override + public @NotNull UseCooldownComponent getUseCooldown() { + throw new NotImplementedException(); + } + + @Override + public void setUseCooldown(@Nullable UseCooldownComponent cooldown) { + throw new NotImplementedException(); + } + + @Override + public boolean hasEquippable() { + throw new NotImplementedException(); + } + + @Override + public @NotNull EquippableComponent getEquippable() { + throw new NotImplementedException(); + } + + @Override + public void setEquippable(@Nullable EquippableComponent equippable) { + throw new NotImplementedException(); + } + public boolean isSnapshot() { return this.container instanceof ItemStackSnapshot; } @@ -229,8 +396,8 @@ public void setDisplayName(@Nullable String name) { @Override public void setDisplayNameComponent(@Nullable BaseComponent[] component) { throw NotImplementedException.createByLazy(AbstractItemMeta.class, - "setDisplayNameComponent", - BaseComponent.class); + "setDisplayNameComponent", + BaseComponent.class); } @Override @@ -303,24 +470,18 @@ public void setLoreComponents(@Nullable List lore) { @Override public boolean hasCustomModelData() { - return this.container.get(Keys.CUSTOM_MODEL_DATA).isPresent(); + throw NotImplementedException.createByLazy(ItemMeta.class, "hasCustomModelData", List.class); } @Override public int getCustomModelData() { - return this.container.get(Keys.CUSTOM_MODEL_DATA).orElse(-1); + throw NotImplementedException.createByLazy(ItemMeta.class, "getCustomModelData", List.class); + } @Override public void setCustomModelData(@Nullable Integer data) { - if (this.container instanceof ItemStackSnapshot) { - return; //not supported on snapshot -> maybe a issue - } - if (data == null) { - this.remove(Keys.CUSTOM_MODEL_DATA); - return; - } - this.set(Keys.CUSTOM_MODEL_DATA, data); + throw NotImplementedException.createByLazy(ItemMeta.class, "setCustomModelData", List.class); } @Override @@ -352,16 +513,16 @@ public int getEnchantLevel(@NotNull Enchantment ench) { public @NotNull Map getEnchants() { List spongeEnchantments = this.container.get(Keys.APPLIED_ENCHANTMENTS) - .orElse(new LinkedList<>()); + .orElse(new LinkedList<>()); return spongeEnchantments.stream() .collect(Collectors.toMap(ench -> SoakEnchantmentTypeMap.toBukkit(ench.type()), - org.spongepowered.api.item.enchantment.Enchantment::level)); + org.spongepowered.api.item.enchantment.Enchantment::level)); } @Override public boolean addEnchant(@NotNull Enchantment ench, int level, boolean ignoreLevelRestriction) { var enchantment = org.spongepowered.api.item.enchantment.Enchantment.of(SoakEnchantmentTypeMap.toSponge(ench), - level); + level); return modifyEnchantments(enchantments -> { enchantments.add(enchantment); return enchantments; @@ -373,8 +534,8 @@ private boolean modifyEnchantments(Function appliedEnchantments = this.container.get(Keys.APPLIED_ENCHANTMENTS) - .map(LinkedList::new) - .orElse(new LinkedList<>()); + .map(LinkedList::new) + .orElse(new LinkedList<>()); List appliedChanges = apply.apply(appliedEnchantments); this.setList(Keys.APPLIED_ENCHANTMENTS, appliedChanges); @@ -480,7 +641,7 @@ public void setAttributeModifiers(@Nullable Multimap getCanDestroy() { @Deprecated public void setCanDestroy(Set canDestroy) { setSet(Keys.BREAKABLE_BLOCK_TYPES, - canDestroy.stream() - .map(SoakBlockMap::toSponge) - .filter(Optional::isPresent) - .map(Optional::get) - .collect(Collectors.toSet())); + canDestroy.stream() + .map(SoakRegistryMap::toSpongeBlock) + .collect(Collectors.toSet())); } @Override @@ -547,11 +706,9 @@ public Set getCanPlaceOn() { @Override public void setCanPlaceOn(Set canPlaceOn) { setSet(Keys.PLACEABLE_BLOCK_TYPES, - canPlaceOn.stream() - .map(SoakBlockMap::toSponge) - .filter(Optional::isPresent) - .map(Optional::get) - .collect(Collectors.toSet())); + canPlaceOn.stream() + .map(SoakRegistryMap::toSpongeBlock) + .collect(Collectors.toSet())); } @Override @@ -776,11 +933,11 @@ public void setFood(@Nullable FoodComponent foodComponent) { return; } set(Keys.CAN_ALWAYS_EAT, foodComponent.canAlwaysEat()); - set(Keys.FOOD_CONVERTS_TO, + /*set(Keys.FOOD_CONVERTS_TO, foodComponent.getUsingConvertsTo() == null ? null : SoakItemStackMap.toSponge(foodComponent.getUsingConvertsTo())); - set(Keys.EATING_TIME, Ticks.of((long) foodComponent.getEatSeconds() * 20)); + set(Keys.EATING_TIME, Ticks.of((long) foodComponent.getEatSeconds() * 20));*/ set(Keys.SATURATION, (double) foodComponent.getSaturation()); } @@ -821,8 +978,8 @@ public boolean hasJukeboxPlayable() { @Override public void setJukeboxPlayable(@Nullable JukeboxPlayableComponent jukeboxPlayableComponent) { throw NotImplementedException.createByLazy(ItemMeta.class, - "setJukeboxPlayable", - JukeboxPlayableComponent.class); + "setJukeboxPlayable", + JukeboxPlayableComponent.class); } @Override diff --git a/Wrapper/src/main/java/org/soak/wrapper/inventory/meta/SoakPotionItemMeta.java b/Wrapper/src/main/java/org/soak/wrapper/inventory/meta/SoakPotionItemMeta.java index 11c1509..034c99a 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/inventory/meta/SoakPotionItemMeta.java +++ b/Wrapper/src/main/java/org/soak/wrapper/inventory/meta/SoakPotionItemMeta.java @@ -8,6 +8,7 @@ import org.bukkit.potion.PotionType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Unmodifiable; import org.soak.exception.NotImplementedException; import org.soak.map.SoakColourMap; import org.soak.map.item.SoakPotionEffectMap; @@ -70,6 +71,11 @@ public boolean hasCustomEffects() { .collect(Collectors.toList()); } + @Override + public @NotNull @Unmodifiable List getAllEffects() { + return this.container.get(Keys.POTION_EFFECTS).orElse(List.of()).stream().map(SoakPotionEffectMap::toBukkit).toList(); + } + private boolean modifyEffect(Function, List> function) { var list = this.container.get(Keys.POTION_EFFECTS).orElse(new LinkedList<>()); list = function.apply(list); @@ -130,6 +136,26 @@ public void setColor(@Nullable Color color) { set(Keys.COLOR, SoakColourMap.toSponge(color)); } + @Override + public @NotNull Color computeEffectiveColor() { + throw NotImplementedException.createByLazy(this, "computeEffectiveColor"); + } + + @Override + public boolean hasCustomPotionName() { + throw NotImplementedException.createByLazy(this, "hasCustomPotionName"); + } + + @Override + public @Nullable String getCustomPotionName() { + throw NotImplementedException.createByLazy(this, "getCustomPotionName"); + } + + @Override + public void setCustomPotionName(@Nullable String name) { + throw NotImplementedException.createByLazy(this, "setCustomPotionName", String.class); + } + @Override public @NotNull SoakPotionItemMeta clone() { return new SoakPotionItemMeta(this.container); diff --git a/Wrapper/src/main/java/org/soak/wrapper/inventory/meta/food/SoakFoodComponent.java b/Wrapper/src/main/java/org/soak/wrapper/inventory/meta/food/SoakFoodComponent.java index 9360737..dcfbc4d 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/inventory/meta/food/SoakFoodComponent.java +++ b/Wrapper/src/main/java/org/soak/wrapper/inventory/meta/food/SoakFoodComponent.java @@ -52,41 +52,6 @@ public void setCanAlwaysEat(boolean b) { this.meta.set(Keys.CAN_ALWAYS_EAT, b); } - @Override - public float getEatSeconds() { - return this.meta.sponge().get(Keys.EATING_TIME).map(ticks -> ticks.ticks() / 20.0).orElse(0.0).floatValue(); - } - - @Override - public void setEatSeconds(float v) { - this.meta.set(Keys.EATING_TIME, Ticks.of((long) v * 20)); - } - - @Override - public @Nullable ItemStack getUsingConvertsTo() { - return this.meta.sponge().get(Keys.FOOD_CONVERTS_TO).map(SoakItemStackMap::toBukkit).orElse(null); - } - - @Override - public void setUsingConvertsTo(@Nullable ItemStack itemStack) { - this.meta.set(Keys.FOOD_CONVERTS_TO, itemStack == null ? null : SoakItemStackMap.toSponge(itemStack)); - } - - @Override - public @NotNull List getEffects() { - throw NotImplementedException.createByLazy(FoodComponent.class, "getEffects"); - } - - @Override - public void setEffects(@NotNull List list) { - throw NotImplementedException.createByLazy(FoodComponent.class, "setEffects", List.class); - } - - @Override - public @NotNull FoodEffect addEffect(@NotNull PotionEffect potionEffect, float v) { - throw NotImplementedException.createByLazy(FoodComponent.class, "addEffect", PotionEffect.class, float.class); - } - @Override public @NotNull Map serialize() { throw NotImplementedException.createByLazy(FoodComponent.class, "serialize"); diff --git a/Wrapper/src/main/java/org/soak/wrapper/inventory/meta/tool/SoakToolComponent.java b/Wrapper/src/main/java/org/soak/wrapper/inventory/meta/tool/SoakToolComponent.java index 82a13be..a814c80 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/inventory/meta/tool/SoakToolComponent.java +++ b/Wrapper/src/main/java/org/soak/wrapper/inventory/meta/tool/SoakToolComponent.java @@ -7,6 +7,7 @@ import org.jetbrains.annotations.Nullable; import org.soak.exception.NotImplementedException; import org.soak.map.SoakBlockMap; +import org.soak.map.SoakRegistryMap; import org.soak.utils.ListMappingUtils; import org.soak.wrapper.inventory.meta.AbstractItemMeta; import org.spongepowered.api.data.Keys; @@ -67,7 +68,7 @@ public void setRules(@NotNull List list) { @Override public @NotNull ToolRule addRule(@NotNull Collection collection, @Nullable Float aFloat, @Nullable Boolean aBoolean) { - var spongeBlocks = collection.stream().map(material -> SoakBlockMap.toSponge(material).orElseThrow()).toList(); + var spongeBlocks = collection.stream().map(SoakRegistryMap::toSpongeBlock).toList(); var spongeToolRule = org.spongepowered.api.data.type.ToolRule.forBlocks(spongeBlocks, aFloat == null ? null : diff --git a/Wrapper/src/main/java/org/soak/wrapper/inventory/meta/tool/SoakToolRule.java b/Wrapper/src/main/java/org/soak/wrapper/inventory/meta/tool/SoakToolRule.java index 382a9c9..fa8b24c 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/inventory/meta/tool/SoakToolRule.java +++ b/Wrapper/src/main/java/org/soak/wrapper/inventory/meta/tool/SoakToolRule.java @@ -7,6 +7,7 @@ import org.jetbrains.annotations.Nullable; import org.soak.exception.NotImplementedException; import org.soak.map.SoakBlockMap; +import org.soak.map.SoakRegistryMap; import org.soak.wrapper.inventory.meta.AbstractItemMeta; import org.spongepowered.api.data.Keys; import org.spongepowered.api.data.type.ToolRule; @@ -40,7 +41,7 @@ public void setBlocks(@NotNull Material material) { @Override public void setBlocks(@NotNull Collection collection) { - var blockTypes = collection.stream().map(SoakBlockMap::toSponge).map(Optional::orElseThrow).collect(Collectors.toList()); + var blockTypes = collection.stream().map(SoakRegistryMap::toSpongeBlock).collect(Collectors.toList()); var newToolRule = ToolRule.forBlocks(blockTypes, rule.speed().orElse(null), rule.drops().orElse(null)); var toolRules = new ArrayList<>(this.item.sponge().get(Keys.TOOL_RULES).orElse(Collections.emptyList())); toolRules.remove(this.rule); diff --git a/Wrapper/src/main/java/org/soak/wrapper/inventory/view/AbstractInventoryView.java b/Wrapper/src/main/java/org/soak/wrapper/inventory/view/AbstractInventoryView.java index ae5761c..dbf6995 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/inventory/view/AbstractInventoryView.java +++ b/Wrapper/src/main/java/org/soak/wrapper/inventory/view/AbstractInventoryView.java @@ -8,11 +8,13 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.MenuType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.soak.WrapperManager; import org.soak.exception.NotImplementedException; import org.soak.map.SoakMessageMap; +import org.soak.map.SoakRegistryMap; import org.soak.map.item.SoakItemStackMap; import org.soak.map.item.inventory.SoakInventoryMap; import org.soak.plugin.SoakManager; @@ -130,6 +132,11 @@ public InventoryType.SlotType getSlotType(int i) { return SoakInventoryMap.toBukkit(spongeContainer.slot(i).orElseThrow(() -> new IndexOutOfBoundsException("'" + i + "' is out of bounds"))); } + @Override + public void open() { + throw NotImplementedException.createByLazy(this, "open"); + } + @Override public void close() { var spongePlayer = this.spongeContainer.viewer(); @@ -186,6 +193,11 @@ public void setTitle(@NotNull String s) { this.spongeContainer.currentMenu().ifPresent(menu -> menu.setTitle(LegacyComponentSerializer.legacySection().deserialize(s))); } + @Override + public @Nullable MenuType getMenuType() { + return this.spongeContainer.type().map(SoakRegistryMap::toBukkit).orElse(null); + } + @Override public @NotNull String getOriginalTitle() { throw NotImplementedException.createByLazy(InventoryView.class, "getOriginalTitle"); diff --git a/Wrapper/src/main/java/org/soak/wrapper/inventory/view/SoakOpeningInventoryView.java b/Wrapper/src/main/java/org/soak/wrapper/inventory/view/SoakOpeningInventoryView.java index 802d846..d3c8025 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/inventory/view/SoakOpeningInventoryView.java +++ b/Wrapper/src/main/java/org/soak/wrapper/inventory/view/SoakOpeningInventoryView.java @@ -4,6 +4,7 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.MenuType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.soak.exception.NotImplementedException; @@ -81,6 +82,11 @@ public InventoryType.SlotType getSlotType(int i) { throw NotImplementedException.createByLazy(InventoryView.class, "getSlotType", int.class); } + @Override + public void open() { + throw NotImplementedException.createByLazy(this, "open"); + } + @Override public void close() { if (this.player.getOpenInventory().getTopInventory().equals(this.top)) { @@ -98,9 +104,9 @@ public int countSlots() { @Deprecated(forRemoval = true) public boolean setProperty(@NotNull InventoryView.Property property, int i) { throw NotImplementedException.createByLazy(InventoryView.class, - "setProperty", - InventoryView.Property.class, - int.class); + "setProperty", + InventoryView.Property.class, + int.class); } @@ -114,6 +120,11 @@ public void setTitle(@NotNull String s) { this.title = s; } + @Override + public @Nullable MenuType getMenuType() { + return this.top.getType().getMenuType(); + } + @Override public @NotNull String getOriginalTitle() { throw NotImplementedException.createByLazy(InventoryView.class, "getOriginalTitle"); diff --git a/Wrapper/src/main/java/org/soak/wrapper/persistence/AbstractPersistentData.java b/Wrapper/src/main/java/org/soak/wrapper/persistence/AbstractPersistentData.java index 85874be..a1fbad3 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/persistence/AbstractPersistentData.java +++ b/Wrapper/src/main/java/org/soak/wrapper/persistence/AbstractPersistentData.java @@ -28,6 +28,11 @@ public DH getHolder() { return this.holder; } + @Override + public int getSize() { + return this.holder.getValues().size(); + } + @Override public BukkitPersistentData wrapper() { return this.holder.get(SoakKeys.BUKKIT_DATA).orElseGet(BukkitPersistentData::new); diff --git a/Wrapper/src/main/java/org/soak/wrapper/persistence/FakePersistentDataContainer.java b/Wrapper/src/main/java/org/soak/wrapper/persistence/FakePersistentDataContainer.java index 011de85..41bd51d 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/persistence/FakePersistentDataContainer.java +++ b/Wrapper/src/main/java/org/soak/wrapper/persistence/FakePersistentDataContainer.java @@ -95,6 +95,11 @@ public byte[] serializeToBytes() throws IOException { throw NotImplementedException.createByLazy(PersistentDataContainer.class, "serializeToBytes"); } + @Override + public int getSize() { + return data.toMap().size(); + } + private Optional getOptional(NamespacedKey bukkitKey, PersistentDataType bukkitType) { var key = SoakResourceKeyMap.mapToSponge(bukkitKey); var type = SoakPersistentDataMap.toSoak(bukkitType); diff --git a/Wrapper/src/main/java/org/soak/wrapper/plugin/SoakPluginManager.java b/Wrapper/src/main/java/org/soak/wrapper/plugin/SoakPluginManager.java index 1c1a10f..3ff1427 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/plugin/SoakPluginManager.java +++ b/Wrapper/src/main/java/org/soak/wrapper/plugin/SoakPluginManager.java @@ -117,8 +117,8 @@ public boolean isPluginEnabled(@Nullable Plugin plugin) { } @Override - public void registerInterface(@NotNull Class loader) throws IllegalArgumentException { - throw NotImplementedException.createByLazy(Class.class); + public void registerInterface(@NotNull Class loader) { + throw NotImplementedException.createByLazy(this, "registerInterface", Class.class); } @Override @@ -316,17 +316,17 @@ public void recalculatePermissionDefaults(@NotNull Permission perm) { @Override public void subscribeToPermission(@NotNull String permission, @NotNull Permissible permissible) { throw NotImplementedException.createByLazy(SoakPluginManager.class, - "subscribeFromPermission", - String.class, - Permissible.class); + "subscribeFromPermission", + String.class, + Permissible.class); } @Override public void unsubscribeFromPermission(@NotNull String permission, @NotNull Permissible permissible) { throw NotImplementedException.createByLazy(SoakPluginManager.class, - "unsubscribeFromPermission", - String.class, - Permissible.class); + "unsubscribeFromPermission", + String.class, + Permissible.class); } @Override @@ -346,24 +346,24 @@ public void unsubscribeFromPermission(@NotNull String permission, @NotNull Permi @Override public void subscribeToDefaultPerms(boolean op, @NotNull Permissible permissible) { throw NotImplementedException.createByLazy(SoakPluginManager.class, - "subscribeToDefaultPerms", - boolean.class, - Permissible.class); + "subscribeToDefaultPerms", + boolean.class, + Permissible.class); } @Override public void unsubscribeFromDefaultPerms(boolean op, @NotNull Permissible permissible) { throw NotImplementedException.createByLazy(SoakPluginManager.class, - "unsubscribeFromDefaultPerms", - boolean.class, - Permissible.class); + "unsubscribeFromDefaultPerms", + boolean.class, + Permissible.class); } @Override public @NotNull Set getDefaultPermSubscriptions(boolean op) { throw NotImplementedException.createByLazy(SoakPluginManager.class, - "getDefaultPermSubscriptions", - boolean.class); + "getDefaultPermSubscriptions", + boolean.class); } @Override @@ -393,16 +393,16 @@ public boolean useTimings() { @Override public boolean isTransitiveDependency(PluginMeta pluginMeta, PluginMeta pluginMeta1) { throw NotImplementedException.createByLazy(PluginManager.class, - "isTransitiveDependency", - PluginMeta.class, - PluginMeta.class); + "isTransitiveDependency", + PluginMeta.class, + PluginMeta.class); } @Override public void overridePermissionManager(@NotNull Plugin plugin, @Nullable PermissionManager permissionManager) { throw NotImplementedException.createByLazy(PluginManager.class, - "isTransitiveDependency", - Plugin.class, - PermissionManager.class); + "isTransitiveDependency", + Plugin.class, + PermissionManager.class); } } diff --git a/Wrapper/src/main/java/org/soak/wrapper/registry/ISoakRegistry.java b/Wrapper/src/main/java/org/soak/wrapper/registry/ISoakRegistry.java index 746f72d..48be770 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/registry/ISoakRegistry.java +++ b/Wrapper/src/main/java/org/soak/wrapper/registry/ISoakRegistry.java @@ -4,7 +4,14 @@ import org.bukkit.Keyed; import org.bukkit.Registry; -public interface ISoakRegistry extends Registry { +public interface ISoakRegistry extends Registry { - RegistryKey key(); + K key(); + + interface Key extends ISoakRegistry> { + } + + interface Legacy extends ISoakRegistry> { + + } } diff --git a/Wrapper/src/main/java/org/soak/wrapper/registry/SoakInvalidRegistry.java b/Wrapper/src/main/java/org/soak/wrapper/registry/SoakInvalidRegistry.java index 2dc2305..9386e34 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/registry/SoakInvalidRegistry.java +++ b/Wrapper/src/main/java/org/soak/wrapper/registry/SoakInvalidRegistry.java @@ -1,21 +1,46 @@ package org.soak.wrapper.registry; import io.papermc.paper.registry.RegistryKey; +import io.papermc.paper.registry.tag.Tag; +import io.papermc.paper.registry.tag.TagKey; import org.bukkit.Keyed; import org.bukkit.NamespacedKey; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collection; import java.util.Iterator; +import java.util.List; import java.util.stream.Stream; -public record SoakInvalidRegistry(RegistryKey key) implements ISoakRegistry { +@Deprecated +public record SoakInvalidRegistry(RegistryKey key) implements ISoakRegistry.Key { @Override public @Nullable B get(@NotNull NamespacedKey namespacedKey) { return null; } + @Override + public @org.jspecify.annotations.Nullable NamespacedKey getKey(B value) { + return null; + } + + @Override + public boolean hasTag(TagKey key) { + return false; + } + + @Override + public Tag getTag(TagKey key) { + return null; + } + + @Override + public Collection> getTags() { + return List.of(); + } + @Override public @NotNull B getOrThrow(@NotNull NamespacedKey namespacedKey) { throw new IllegalArgumentException("Registry is not enabled"); @@ -26,6 +51,16 @@ public record SoakInvalidRegistry(RegistryKey key) implement return Stream.empty(); } + @Override + public Stream keyStream() { + return Stream.empty(); + } + + @Override + public int size() { + return 0; + } + @Override public @NotNull Iterator iterator() { return stream().iterator(); diff --git a/Wrapper/src/main/java/org/soak/wrapper/registry/SoakLegacyRegistry.java b/Wrapper/src/main/java/org/soak/wrapper/registry/SoakLegacyRegistry.java new file mode 100644 index 0000000..0ad181b --- /dev/null +++ b/Wrapper/src/main/java/org/soak/wrapper/registry/SoakLegacyRegistry.java @@ -0,0 +1,22 @@ +package org.soak.wrapper.registry; + +import org.bukkit.Keyed; +import org.spongepowered.api.registry.Registry; + +import java.util.function.Function; +import java.util.function.Supplier; +import java.util.stream.Stream; + +public class SoakLegacyRegistry extends SoakRegistry> + implements ISoakRegistry.Legacy { + + SoakLegacyRegistry(Class key, Supplier> supplier, Function, + Stream> to) { + super(key, supplier, to); + } + + static SoakLegacyRegistry legacy(Class key, + Supplier> supplier, Function map) { + return new SoakLegacyRegistry<>(key, supplier, (Registry reg) -> reg.stream().map(map)); + } +} diff --git a/Wrapper/src/main/java/org/soak/wrapper/registry/SoakRegistry.java b/Wrapper/src/main/java/org/soak/wrapper/registry/SoakRegistry.java index 7722eec..d290621 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/registry/SoakRegistry.java +++ b/Wrapper/src/main/java/org/soak/wrapper/registry/SoakRegistry.java @@ -1,34 +1,36 @@ package org.soak.wrapper.registry; -import io.papermc.paper.registry.RegistryKey; +import io.papermc.paper.registry.tag.Tag; +import io.papermc.paper.registry.tag.TagKey; import org.bukkit.Keyed; import org.bukkit.NamespacedKey; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.soak.exception.NotImplementedException; import org.spongepowered.api.registry.Registry; +import java.util.Collection; import java.util.Iterator; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Stream; -public class SoakRegistry implements ISoakRegistry { +public abstract class SoakRegistry implements ISoakRegistry { private final Function, Stream> to; private final Supplier> reg; - private final RegistryKey bukkitKey; + private final K bukkitKey; + private final Map cachedValue = new ConcurrentHashMap<>(); - SoakRegistry(RegistryKey key, Supplier> supplier, Function, Stream> to) { + SoakRegistry(K key, Supplier> supplier, Function, Stream> to) { this.to = to; this.reg = supplier; this.bukkitKey = key; } - static SoakRegistry simple(RegistryKey
key, Supplier> supplier, Function map) { - return new SoakRegistry<>(key, supplier, reg -> reg.stream().map(map)); - } - - public RegistryKey key() { + public K key() { return this.bukkitKey; } @@ -37,14 +39,54 @@ public RegistryKey key() { return stream().filter(key -> key.getKey().equals(namespacedKey)).findAny().orElse(null); } + @Override + public @org.jspecify.annotations.Nullable NamespacedKey getKey(R value) { + return value.getKey(); + } + + @Override + public boolean hasTag(TagKey key) { + throw new NotImplementedException(); + } + + @Override + public Tag getTag(TagKey key) { + throw new NotImplementedException(); + } + + @Override + public Collection> getTags() { + throw new NotImplementedException(); + } + @Override public @NotNull R getOrThrow(@NotNull NamespacedKey namespacedKey) { - return stream().filter(key -> key.getKey().equals(namespacedKey)).findAny().orElseThrow(() -> new IllegalArgumentException("Could not find the value with the key: " + namespacedKey.asString())); + return stream().filter(key -> key.getKey().equals(namespacedKey)) + .findAny() + .orElseThrow(() -> new IllegalArgumentException("Could not find the value with the key: " + namespacedKey.asString())); } @Override public @NotNull Stream stream() { - return this.to.apply(this.reg.get()); + var cachedStream = this.cachedValue.values().stream(); + var mainStream = this.to.apply(this.reg.get()).filter(bukkitValue -> { + var key = bukkitValue.getKey(); + return !this.cachedValue.containsKey(key); + }).peek(bukkitValue -> { + var key = bukkitValue.getKey(); + this.cachedValue.put(key, bukkitValue); + }); + return Stream.concat(cachedStream, mainStream); + } + + @Override + public Stream keyStream() { + return stream().map(Keyed::getKey); + } + + @Override + public int size() { + return (int) stream().count(); } @NotNull diff --git a/Wrapper/src/main/java/org/soak/wrapper/registry/SoakRegistryAccess.java b/Wrapper/src/main/java/org/soak/wrapper/registry/SoakRegistryAccess.java index eb2d492..142cdff 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/registry/SoakRegistryAccess.java +++ b/Wrapper/src/main/java/org/soak/wrapper/registry/SoakRegistryAccess.java @@ -2,19 +2,23 @@ import io.papermc.paper.registry.RegistryAccess; import io.papermc.paper.registry.RegistryKey; +import org.bukkit.Art; import org.bukkit.Keyed; import org.bukkit.Registry; import org.jetbrains.annotations.NotNull; -import org.soak.wrapper.entity.living.animal.cat.SoakCatType; -import org.soak.wrapper.entity.living.villager.SoakVillagerProfession; -import org.soak.wrapper.entity.living.villager.SoakVillagerType; -import org.soak.wrapper.potion.SoakPotionEffectType; import org.jspecify.annotations.Nullable; -import org.soak.map.*; +import org.soak.map.SoakRegistryMap; +import org.soak.map.SoakStructureMap; import org.soak.map.item.SoakPotionEffectMap; import org.soak.map.item.inventory.SoakEquipmentMap; -import org.soak.wrapper.inventory.SoakMenuType; +import org.soak.utils.CollectionBuilder; +import org.soak.wrapper.block.SoakBiome; import org.soak.wrapper.enchantment.SoakEnchantment; +import org.soak.wrapper.entity.living.animal.cat.SoakCatType; +import org.soak.wrapper.entity.living.villager.SoakVillagerProfession; +import org.soak.wrapper.entity.living.villager.SoakVillagerType; +import org.soak.wrapper.inventory.SoakMenuType; +import org.soak.wrapper.potion.SoakPotionEffectType; import org.spongepowered.api.block.BlockTypes; import org.spongepowered.api.data.type.*; import org.spongepowered.api.effect.potion.PotionEffectTypes; @@ -24,72 +28,61 @@ import org.spongepowered.api.item.inventory.ContainerTypes; import org.spongepowered.api.item.potion.PotionTypes; import org.spongepowered.api.item.recipe.smithing.TrimPatterns; +import org.spongepowered.api.world.biome.Biomes; import org.spongepowered.api.world.generation.structure.StructureTypes; import org.spongepowered.api.world.generation.structure.Structures; import java.util.Map; -import java.util.stream.Collectors; -import java.util.stream.Stream; @SuppressWarnings("NonExtendableApiUsage") public class SoakRegistryAccess implements RegistryAccess { - private final Map, ISoakRegistry> registryMap = - toMap(SoakRegistry.simple(RegistryKey.BANNER_PATTERN, - BannerPatternShapes::registry, - SoakBannerMap::toBukkit), - SoakRegistry.simple(RegistryKey.POTION, - PotionTypes::registry, - SoakPotionEffectMap::toBukkit), - SoakRegistry.simple(RegistryKey.ENCHANTMENT, - EnchantmentTypes::registry, - SoakEnchantment::new), - SoakRegistry.simple(RegistryKey.STRUCTURE, - Structures::registry, - SoakStructureMap::toBukkit), - SoakRegistry.simple(RegistryKey.STRUCTURE_TYPE, - StructureTypes::registry, - SoakStructureMap::toBukkit), - SoakRegistry.simple(RegistryKey.TRIM_MATERIAL, - ArmorMaterials::registry, - SoakEquipmentMap::toBukkit), - SoakRegistry.simple(RegistryKey.TRIM_PATTERN, - TrimPatterns::registry, - SoakEquipmentMap::toBukkit), - SoakRegistry.simple(RegistryKey.DAMAGE_TYPE, - DamageTypes::registry, - SoakDamageMap::toBukkit), - SoakRegistry.simple(RegistryKey.JUKEBOX_SONG, - MusicDiscs::registry, - SoakSoundMap::toBukkit), - SoakRegistry.simple(RegistryKey.BLOCK, - BlockTypes::registry, - SoakBlockMap::toBukkitType), - SoakRegistry.simple(RegistryKey.MENU, - ContainerTypes::registry, - SoakMenuType::new), - SoakRegistry.simple(RegistryKey.MOB_EFFECT, - PotionEffectTypes::registry, - SoakPotionEffectType::new), - SoakRegistry.simple(RegistryKey.CAT_VARIANT, - CatTypes::registry, - SoakCatType::new), - SoakRegistry.simple(RegistryKey.VILLAGER_TYPE, - VillagerTypes::registry, - SoakVillagerType::new), - SoakRegistry.simple(RegistryKey.VILLAGER_PROFESSION, - ProfessionTypes::registry, - SoakVillagerProfession::new), - new SoakInvalidRegistry<>(RegistryKey.WOLF_VARIANT)); + private final Map, ISoakRegistry.Key> registryMap = + new CollectionBuilder>().add( + SoakSimpleRegistry.simple(RegistryKey.BANNER_PATTERN, + BannerPatternShapes::registry, + SoakRegistryMap::toBukkit)) + .add(SoakSimpleRegistry.simple(RegistryKey.POTION, PotionTypes::registry, SoakPotionEffectMap::toBukkit)) + .add(SoakSimpleRegistry.simple(RegistryKey.ENCHANTMENT, EnchantmentTypes::registry, SoakEnchantment::new)) + .add(SoakSimpleRegistry.simple(RegistryKey.STRUCTURE, Structures::registry, SoakStructureMap::toBukkit)) + .add(SoakSimpleRegistry.simple(RegistryKey.STRUCTURE_TYPE, + StructureTypes::registry, + SoakStructureMap::toBukkit)) + .add(SoakSimpleRegistry.simple(RegistryKey.TRIM_MATERIAL, + ArmorMaterials::registry, + SoakEquipmentMap::toBukkit)) + .add(SoakSimpleRegistry.simple(RegistryKey.TRIM_PATTERN, + TrimPatterns::registry, + SoakEquipmentMap::toBukkit)) + .add(SoakSimpleRegistry.simple(RegistryKey.JUKEBOX_SONG, MusicDiscs::registry, SoakRegistryMap::toBukkit)) + .add(SoakSimpleRegistry.simple(RegistryKey.BLOCK, BlockTypes::registry, SoakRegistryMap::toBukkit)) + .add(SoakSimpleRegistry.simple(RegistryKey.MENU, ContainerTypes::registry, SoakMenuType::new)) + .add(SoakSimpleRegistry.simple(RegistryKey.MOB_EFFECT, + PotionEffectTypes::registry, + SoakPotionEffectType::new)) + .add(SoakSimpleRegistry.simple(RegistryKey.CAT_VARIANT, CatTypes::registry, SoakCatType::new)) + .add(SoakSimpleRegistry.simple(RegistryKey.VILLAGER_TYPE, VillagerTypes::registry, SoakVillagerType::new)) + .add(SoakSimpleRegistry.simple(RegistryKey.VILLAGER_PROFESSION, + ProfessionTypes::registry, + SoakVillagerProfession::new)) + .add(SoakSimpleRegistry.simple(RegistryKey.BIOME, Biomes::registry, SoakBiome::new)) + .add(SoakSimpleRegistry.simple(RegistryKey.INSTRUMENT, + InstrumentTypes::registry, + SoakRegistryMap::toBukkit)) + .add(SoakSimpleRegistry.simple(RegistryKey.DAMAGE_TYPE, DamageTypes::registry, SoakRegistryMap::toBukkit)) + .add(SoakSimpleRegistry.simple(RegistryKey.WOLF_VARIANT, WolfVariants::registry, SoakRegistryMap::toBukkit)) + .add(SoakSimpleRegistry.simple(RegistryKey.FROG_VARIANT, FrogTypes::registry, SoakRegistryMap::toBukkit)) + .toMapKeyed(ISoakRegistry::key); - private Map, ISoakRegistry> toMap(ISoakRegistry... registries) { - return Stream.of(registries).collect(Collectors.toMap(ISoakRegistry::key, reg -> reg)); - } + private final Map, ISoakRegistry.Legacy> legacyRegistries = + new CollectionBuilder>().add( + SoakLegacyRegistry.legacy(Art.class, ArtTypes::registry, SoakRegistryMap::toBukkit)) + .toMapKeyed(ISoakRegistry::key); @SuppressWarnings("unchecked") @Override public @Nullable Registry getRegistry(Class aClass) { - return switch (aClass.getCanonicalName()) { + var registry = switch (aClass.getCanonicalName()) { case "org.bukkit.block.banner.PatternType" -> (Registry) getRegistry(RegistryKey.BANNER_PATTERN); case "org.bukkit.enchantments.Enchantment" -> (Registry) getRegistry(RegistryKey.ENCHANTMENT); case "org.bukkit.generator.structure.Structure" -> (Registry) getRegistry(RegistryKey.STRUCTURE); @@ -109,11 +102,14 @@ private Map, ISoakRegistry> toMap(ISoakRegistry... registri case "org.bukkit.map.MapCursor.Type" -> (Registry) getRegistry(RegistryKey.MAP_DECORATION_TYPE); case "org.bukkit.GameEvent" -> (Registry) getRegistry(RegistryKey.GAME_EVENT); case "org.bukkit.inventory.MenuType" -> (Registry) getRegistry(RegistryKey.MENU); - default -> { - System.err.println("Unknown registry for class: " + aClass.getCanonicalName()); - yield null; - } + case "org.bukkit.block.Biome" -> (Registry) getRegistry(RegistryKey.BIOME); + case "org.bukkit.MusicInstrument" -> (Registry) getRegistry(RegistryKey.INSTRUMENT); + default -> getLegacyRegistry(aClass); }; + if(registry == null){ + System.err.println("Unknown registry for class: " + aClass.getCanonicalName()); + } + return registry; } @SuppressWarnings("unchecked") @@ -121,4 +117,8 @@ private Map, ISoakRegistry> toMap(ISoakRegistry... registri public @NotNull Registry getRegistry(@NotNull RegistryKey registryKey) { return (Registry) registryMap.get(registryKey); } + + private @Nullable Registry getLegacyRegistry(Class clazz) { + return (Registry) legacyRegistries.get(clazz); + } } diff --git a/Wrapper/src/main/java/org/soak/wrapper/registry/SoakSimpleRegistry.java b/Wrapper/src/main/java/org/soak/wrapper/registry/SoakSimpleRegistry.java new file mode 100644 index 0000000..89f6f0d --- /dev/null +++ b/Wrapper/src/main/java/org/soak/wrapper/registry/SoakSimpleRegistry.java @@ -0,0 +1,23 @@ +package org.soak.wrapper.registry; + +import io.papermc.paper.registry.RegistryKey; +import org.bukkit.Keyed; +import org.spongepowered.api.registry.Registry; + +import java.util.function.Function; +import java.util.function.Supplier; +import java.util.stream.Stream; + +public class SoakSimpleRegistry extends SoakRegistry> + implements ISoakRegistry.Key { + + SoakSimpleRegistry(RegistryKey key, Supplier> supplier, Function, + Stream> to) { + super(key, supplier, to); + } + + static SoakSimpleRegistry simple(RegistryKey key, + Supplier> supplier, Function map) { + return new SoakSimpleRegistry<>(key, supplier, (Registry reg) -> reg.stream().map(map)); + } +} diff --git a/Wrapper/src/main/java/org/soak/wrapper/server/ServerSplitBan.java b/Wrapper/src/main/java/org/soak/wrapper/server/ServerSplitBan.java new file mode 100644 index 0000000..cf9f3b8 --- /dev/null +++ b/Wrapper/src/main/java/org/soak/wrapper/server/ServerSplitBan.java @@ -0,0 +1,27 @@ +package org.soak.wrapper.server; + +import io.papermc.paper.ban.BanListType; +import org.bukkit.BanList; +import org.bukkit.Server; +import org.jetbrains.annotations.NotNull; +import org.soak.exception.NotImplementedException; + +import java.net.InetAddress; + +public interface ServerSplitBan extends Server { + + @Override + default void banIP(@NotNull InetAddress inetAddress) { + throw NotImplementedException.createByLazy(Server.class, "banIP", InetAddress.class); + } + + @Override + default void unbanIP(@NotNull InetAddress inetAddress) { + throw NotImplementedException.createByLazy(Server.class, "unbanIP", InetAddress.class); + } + + @Override + default , E> @NotNull B getBanList(@NotNull BanListType banListType) { + throw NotImplementedException.createByLazy(Server.class, "getBanList", BanListType.class); + } +} diff --git a/Wrapper/src/main/java/org/soak/wrapper/server/ServerSplitBase.java b/Wrapper/src/main/java/org/soak/wrapper/server/ServerSplitBase.java new file mode 100644 index 0000000..042b11a --- /dev/null +++ b/Wrapper/src/main/java/org/soak/wrapper/server/ServerSplitBase.java @@ -0,0 +1,9 @@ +package org.soak.wrapper.server; + +import org.bukkit.Server; + +interface ServerSplitBase extends Server { + + org.spongepowered.api.Server spongeServer(); + +} diff --git a/Wrapper/src/main/java/org/soak/wrapper/server/ServerSplitItem.java b/Wrapper/src/main/java/org/soak/wrapper/server/ServerSplitItem.java new file mode 100644 index 0000000..39216be --- /dev/null +++ b/Wrapper/src/main/java/org/soak/wrapper/server/ServerSplitItem.java @@ -0,0 +1,131 @@ +package org.soak.wrapper.server; + +import org.bukkit.Location; +import org.bukkit.NamespacedKey; +import org.bukkit.Server; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemCraftResult; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.Recipe; +import org.bukkit.map.MapCursor; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.soak.exception.NotImplementedException; +import org.soak.map.item.SoakRecipeMap; +import org.soak.wrapper.SoakServer; +import org.spongepowered.api.Sponge; + +import java.util.Iterator; +import java.util.List; +import java.util.Objects; + +public interface ServerSplitItem extends Server { + + @Override + default @Nullable Recipe getRecipe(@NotNull NamespacedKey namespacedKey) { + throw NotImplementedException.createByLazy(Server.class, "getRecipe", NamespacedKey.class); + } + + @Override + default @NotNull List getRecipesFor(@NotNull ItemStack itemStack) { + throw NotImplementedException.createByLazy(Server.class, "getRecipesFor", ItemStack.class); + } + + @Override + default void updateRecipes() { + throw NotImplementedException.createByLazy(Server.class, "updateRecipes"); + } + + @Override + default boolean removeRecipe(@NotNull NamespacedKey namespacedKey, boolean b) { + throw NotImplementedException.createByLazy(Server.class, "removeRecipe", NamespacedKey.class, boolean.class); + } + + @Override + default @NotNull ItemStack craftItem(@NotNull ItemStack[] itemStacks, @NotNull World world) { + throw NotImplementedException.createByLazy(Server.class, "craftItem", ItemStack[].class, World.class); + } + + @Override + default @NotNull ItemCraftResult craftItemResult(@NotNull ItemStack[] itemStacks, @NotNull World world, + @NotNull Player player) { + throw NotImplementedException.createByLazy(Server.class, + "craftItemResult", + ItemStack[].class, + World.class, + Player.class); + } + + @Override + default @NotNull ItemCraftResult craftItemResult(@NotNull ItemStack[] itemStacks, @NotNull World world) { + throw NotImplementedException.createByLazy(Server.class, "craftItemResult", ItemStack[].class, World.class); + } + + @Override + default @Nullable ItemStack createExplorerMap(@NotNull World world, @NotNull Location location, + @NotNull org.bukkit.generator.structure.StructureType structureType, + @NotNull MapCursor.Type type, int i, boolean b) { + throw NotImplementedException.createByLazy(Server.class, + "createExplorerMap", + World.class, + Location.class, + org.bukkit.generator.structure.StructureType.class, + MapCursor.Type.class, + int.class, + boolean.class); + } + + @Override + default boolean addRecipe(@Nullable Recipe recipe) { + return addRecipe(recipe, false); + } + + @Override + default boolean addRecipe(@Nullable Recipe recipe, boolean resendRecipes) { + throw NotImplementedException.createByLazy(SoakServer.class, "addRecipe", Recipe.class, boolean.class); + } + + @Override + default @Nullable Recipe getCraftingRecipe(@NotNull ItemStack[] itemStacks, @NotNull World world) { + throw NotImplementedException.createByLazy(Server.class, "getCraftingRecipe", ItemStack.class, World.class); + } + + @Override + default @NotNull ItemStack craftItem(@NotNull ItemStack[] itemStacks, @NotNull World world, @NotNull Player player) { + throw NotImplementedException.createByLazy(Server.class, + "craftItem", + ItemStack.class, + World.class, + Player.class); + } + + + @Override + default @NotNull Iterator recipeIterator() { + return Sponge.server().recipeManager().all().stream().map(recipe -> { + try { + return SoakRecipeMap.toBukkit(recipe); + } catch (RuntimeException e) { + e.printStackTrace(); + return null; + } + }).filter(Objects::nonNull).iterator(); + } + + @Override + default void clearRecipes() { + throw NotImplementedException.createByLazy(SoakServer.class, "clearRecipes"); + } + + @Override + default void resetRecipes() { + throw NotImplementedException.createByLazy(SoakServer.class, "resetRecipes"); + } + + @Override + default boolean removeRecipe(@NotNull NamespacedKey key) { + throw NotImplementedException.createByLazy(Server.class, "removeRecipe", NamespacedKey.class); + } + +} diff --git a/Wrapper/src/main/java/org/soak/wrapper/server/ServerSplitRegion.java b/Wrapper/src/main/java/org/soak/wrapper/server/ServerSplitRegion.java new file mode 100644 index 0000000..53a9562 --- /dev/null +++ b/Wrapper/src/main/java/org/soak/wrapper/server/ServerSplitRegion.java @@ -0,0 +1,70 @@ +package org.soak.wrapper.server; + +import io.papermc.paper.math.Position; +import io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler; +import io.papermc.paper.threadedregions.scheduler.RegionScheduler; +import org.bukkit.Location; +import org.bukkit.Server; +import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.jetbrains.annotations.NotNull; +import org.soak.exception.NotImplementedException; + +public interface ServerSplitRegion extends Server { + + @Override + default @NotNull GlobalRegionScheduler getGlobalRegionScheduler() { + throw NotImplementedException.createByLazy(Server.class, "getGlobalRegionScheduler"); + } + + @Override + default boolean isOwnedByCurrentRegion(@NotNull World world, int minChunkX, int minChunkZ, int maxChunkX, int maxChunkZ) { + throw NotImplementedException.createByLazy(this, "isOwnedByCurrentRegion", World.class); + } + + @Override + default boolean isOwnedByCurrentRegion(@NotNull World world, @NotNull Position position) { + return isOwnedByCurrentRegion(position.toLocation(world)); + } + + @Override + default boolean isOwnedByCurrentRegion(@NotNull World world, @NotNull Position position, int squareRadiusChecks) { + return isOwnedByCurrentRegion(position.toLocation(world), squareRadiusChecks); + } + + @Override + default boolean isOwnedByCurrentRegion(@NotNull Location location) { + return isOwnedByCurrentRegion(location, 1); + } + + @Override + default boolean isOwnedByCurrentRegion(@NotNull Location location, int squareRadiusChunks) { + var chunk = location.getChunk(); + return isOwnedByCurrentRegion(location.getWorld(), chunk.getX(), chunk.getZ(), squareRadiusChunks); + } + + @Override + default boolean isOwnedByCurrentRegion(@NotNull World world, int chunkX, int chunkZ) { + return isOwnedByCurrentRegion(world, chunkX, chunkZ, 1); + } + + @Override + default boolean isOwnedByCurrentRegion(@NotNull World world, int chunkX, int chunkZ, int squareRadiusChunks) { + throw NotImplementedException.createByLazy(Server.class, + "isOwnedByCurrentRegion", + World.class, + int.class, + int.class, + int.class); + } + + @Override + default boolean isOwnedByCurrentRegion(@NotNull Entity entity) { + return isOwnedByCurrentRegion(entity.getLocation()); + } + + @Override + default @NotNull RegionScheduler getRegionScheduler() { + throw NotImplementedException.createByLazy(Server.class, "getRegionScheduler"); + } +} diff --git a/Wrapper/src/main/java/org/soak/wrapper/server/ServerSplitWorld.java b/Wrapper/src/main/java/org/soak/wrapper/server/ServerSplitWorld.java new file mode 100644 index 0000000..4fcc0a5 --- /dev/null +++ b/Wrapper/src/main/java/org/soak/wrapper/server/ServerSplitWorld.java @@ -0,0 +1,137 @@ +package org.soak.wrapper.server; + +import net.kyori.adventure.key.Key; +import org.bukkit.Server; +import org.bukkit.World; +import org.bukkit.WorldBorder; +import org.bukkit.WorldCreator; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.mose.collection.stream.builder.CollectionStreamBuilder; +import org.soak.WrapperManager; +import org.soak.exception.NotImplementedException; +import org.soak.map.SoakResourceKeyMap; +import org.soak.plugin.SoakManager; +import org.soak.utils.ListMappingUtils; +import org.soak.wrapper.SoakServer; +import org.soak.wrapper.world.SoakWorld; +import org.spongepowered.api.Sponge; +import org.spongepowered.api.world.DefaultWorldKeys; +import org.spongepowered.api.world.server.ServerWorld; + +import java.io.IOException; +import java.util.Comparator; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.ExecutionException; + +public interface ServerSplitWorld extends ServerSplitBase { + + @Override + default boolean unloadWorld(@NotNull String name, boolean save) { + var world = getWorld(name); + if (world == null) { + return false; + } + return unloadWorld(world, save); + } + + @Override + default @Nullable World getWorld(@NotNull Key key) { + var namespace = SoakResourceKeyMap.mapToSponge(key); + if (namespace == null) { + return null; + } + return Sponge.server() + .worldManager() + .worlds() + .stream() + .filter(world -> world.key().equals(namespace)) + .findAny() + .map(world -> SoakManager.getManager().getMemoryStore().get(world)) + .orElse(null); + } + + @Override + default @Nullable World getWorld(@NotNull String s) { + return Sponge.server() + .worldManager() + .worlds() + .stream() + .filter(world -> world.key().value().equalsIgnoreCase(s)) + .findAny() + .map(world -> SoakManager.getManager().getMemoryStore().get(world)) + .orElse(null); + } + + @Override + default @Nullable World getWorld(@NotNull UUID uuid) { + var worldManager = Sponge.server().worldManager(); + return worldManager.worldKey(uuid) + .flatMap(worldManager::world) + .map(world -> SoakManager.getManager().getMemoryStore().get(world)) + .orElse(null); + } + + @Override + default @NotNull World getRespawnWorld() { + throw NotImplementedException.createByLazy(this, "getRespawnWorld"); + } + + @Override + default void setRespawnWorld(@NotNull World world) { + throw NotImplementedException.createByLazy(this, "setRespawnWorld", World.class); + } + + @Override + default @NotNull List getWorlds() { + var builder = CollectionStreamBuilder.builder() + .collection(this.spongeServer().worldManager().worlds()) + .basicMap(world -> (World) SoakManager.getManager().getMemoryStore().get(world)); + return ListMappingUtils.fromStream(builder, + () -> this.spongeServer().worldManager().worlds().stream(), + (spongeWorld, soakWorld) -> ((SoakWorld) soakWorld).sponge() + .equals(spongeWorld), + Comparator.comparing(world -> world.key().formatted())).buildList(); + } + + @Override + default boolean isTickingWorlds() { + throw NotImplementedException.createByLazy(Server.class, "isTickingWorlds"); + } + + @Override + default @Nullable World createWorld(@NotNull WorldCreator creator) { + throw NotImplementedException.createByLazy(SoakServer.class, "createWorld", WorldCreator.class); + } + + @Override + default boolean unloadWorld(@NotNull World world, boolean save) { + var spongeWorld = ((SoakWorld) world).sponge(); + if (save) { + try { + spongeWorld.save(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + var worldManager = this.spongeServer().worldManager(); + try { + return worldManager.unloadWorld(spongeWorld).get(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + } + + @Override + default @NotNull WorldBorder createWorldBorder() { + throw NotImplementedException.createByLazy(Server.class, "createWorldBorder"); + } + + default ServerWorld defaultWorld() { + return this.spongeServer() + .worldManager() + .world(DefaultWorldKeys.DEFAULT) + .orElseThrow(() -> new RuntimeException("default world is not loaded")); + } +} diff --git a/Wrapper/src/main/java/org/soak/wrapper/v1_21_R2/NMSBounceSoakServer.java b/Wrapper/src/main/java/org/soak/wrapper/v1_21_R2/NMSBounceSoakServer.java index 582b5a5..1413edf 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/v1_21_R2/NMSBounceSoakServer.java +++ b/Wrapper/src/main/java/org/soak/wrapper/v1_21_R2/NMSBounceSoakServer.java @@ -1,5 +1,6 @@ package org.soak.wrapper.v1_21_R2; +import org.bukkit.command.CommandMap; import org.soak.annotation.UsesNms; import org.soak.exception.NMSUsageException; import org.soak.wrapper.SoakServer; @@ -9,13 +10,17 @@ public class NMSBounceSoakServer extends SoakServer { + public final CommandMap commandMap; //some plugins use reflection to get this + public NMSBounceSoakServer(Supplier serverSupplier) { super(serverSupplier); + this.commandMap = this.getCommandMap(); } @UsesNms() public Object getHandle() { - //returns dedicatedPlayerList -> Maybe able to fake it for those that use only reflection and dont check the name + //returns dedicatedPlayerList -> Maybe able to fake it for those that use only reflection and dont check the + // name throw new NMSUsageException(org.bukkit.Server.class.getSimpleName(), "getHandle"); } } diff --git a/Wrapper/src/main/java/org/soak/wrapper/world/SoakWorld.java b/Wrapper/src/main/java/org/soak/wrapper/world/SoakWorld.java index 61bfb57..1dd7296 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/world/SoakWorld.java +++ b/Wrapper/src/main/java/org/soak/wrapper/world/SoakWorld.java @@ -1,7 +1,10 @@ package org.soak.wrapper.world; import io.papermc.paper.block.fluid.FluidData; +import io.papermc.paper.entity.poi.PoiSearchResult; +import io.papermc.paper.entity.poi.PoiType; import io.papermc.paper.math.Position; +import io.papermc.paper.raytracing.PositionedRayTraceConfigurationBuilder; import io.papermc.paper.world.MoonPhase; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import org.bukkit.*; @@ -24,6 +27,7 @@ import org.bukkit.plugin.Plugin; import org.bukkit.util.*; import org.bukkit.util.Vector; +import org.checkerframework.checker.index.qual.Positive; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.mose.collection.stream.builder.CollectionStreamBuilder; @@ -54,6 +58,7 @@ import org.spongepowered.math.vector.Vector3i; import java.io.File; +import java.nio.file.Path; import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; @@ -208,10 +213,10 @@ public int getHighestBlockYAt(@NotNull Location arg0, @NotNull HeightMap arg1) { @Override public int getHighestBlockYAt(int arg0, int arg1, @NotNull HeightMap arg2) { throw NotImplementedException.createByLazy(World.class, - "getHighestBlockYAt", - int.class, - int.class, - HeightMap.class); + "getHighestBlockYAt", + int.class, + int.class, + HeightMap.class); } @Override @@ -227,10 +232,10 @@ public int getHighestBlockYAt(int arg0, int arg1, @NotNull HeightMap arg2) { @Override public @NotNull Block getHighestBlockAt(int arg0, int arg1, @NotNull HeightMap arg2) { throw NotImplementedException.createByLazy(World.class, - "getHighestBlockAt", - int.class, - int.class, - HeightMap.class); + "getHighestBlockAt", + int.class, + int.class, + HeightMap.class); } @Override @@ -273,11 +278,11 @@ public boolean isChunkGenerated(int arg0, int arg1) { @Override public @NotNull CompletableFuture getChunkAtAsync(int x, int z, boolean gen, boolean urgent) { throw NotImplementedException.createByLazy(World.class, - "getChunkAtAsync", - int.class, - int.class, - boolean.class, - boolean.class); + "getChunkAtAsync", + int.class, + int.class, + boolean.class, + boolean.class); } @Override @@ -296,7 +301,7 @@ public boolean isChunkGenerated(int arg0, int arg1) { var spongeBoundingBox = SoakBoundingBoxMap.toSponge(boundingBox); Predicate spongePredicate = (entity) -> predicate == null || predicate.test( - AbstractEntity.wrap(entity)); + AbstractEntity.wrap(entity)); var spongeCollection = this.sponge().entities(spongeBoundingBox, spongePredicate); return CollectionStreamBuilder.builder() .collection(spongeCollection) @@ -310,93 +315,93 @@ public boolean isChunkGenerated(int arg0, int arg1) { .collection(this.world.players()) .basicMap(player -> (Player) SoakManager.getManager().getMemoryStore().get(player)); return ListMappingUtils.fromStream(builder, - () -> this.world.players().stream(), - (spongePlayer, soakPlayer) -> ((SoakPlayer) soakPlayer).spongeEntity() - .equals(spongePlayer), - Comparator.comparing(spongePlayer -> spongePlayer.get(Keys.LAST_DATE_JOINED) - .orElseThrow(() -> new RuntimeException( - "No value found for last joined on a online player")))) + () -> this.world.players().stream(), + (spongePlayer, soakPlayer) -> ((SoakPlayer) soakPlayer).spongeEntity() + .equals(spongePlayer), + Comparator.comparing(spongePlayer -> spongePlayer.get(Keys.LAST_DATE_JOINED) + .orElseThrow(() -> new RuntimeException( + "No value found for last joined on a online player")))) .buildList(); } @Override public boolean createExplosion(Entity arg0, @NotNull Location arg1, float arg2, boolean arg3, boolean arg4) { throw NotImplementedException.createByLazy(World.class, - "createExplosion", - Entity.class, - Location.class, - float.class, - boolean.class, - boolean.class); + "createExplosion", + Entity.class, + Location.class, + float.class, + boolean.class, + boolean.class); } @Override public boolean createExplosion(double arg0, double arg1, double arg2, float arg3) { throw NotImplementedException.createByLazy(World.class, - "createExplosion", - double.class, - double.class, - double.class, - float.class); + "createExplosion", + double.class, + double.class, + double.class, + float.class); } @Override public boolean createExplosion(@NotNull Location arg0, float arg1, boolean arg2) { throw NotImplementedException.createByLazy(World.class, - "createExplosion", - Location.class, - float.class, - boolean.class); + "createExplosion", + Location.class, + float.class, + boolean.class); } @Override public boolean createExplosion(@Nullable Entity entity, @NotNull Location location, float v, boolean b, boolean b1, boolean b2) { throw NotImplementedException.createByLazy(World.class, - "setVoidDamageAmount", - Entity.class, - Location.class, - float.class, - boolean.class, - boolean.class, - boolean.class); + "setVoidDamageAmount", + Entity.class, + Location.class, + float.class, + boolean.class, + boolean.class, + boolean.class); } @Override public boolean createExplosion(double arg0, double arg1, double arg2, float arg3, boolean arg4, boolean arg5) { throw NotImplementedException.createByLazy(World.class, - "createExplosion", - double.class, - double.class, - double.class, - float.class, - boolean.class, - boolean.class); + "createExplosion", + double.class, + double.class, + double.class, + float.class, + boolean.class, + boolean.class); } @Override public boolean createExplosion(double arg0, double arg1, double arg2, float arg3, boolean arg4) { throw NotImplementedException.createByLazy(World.class, - "createExplosion", - double.class, - double.class, - double.class, - float.class, - boolean.class); + "createExplosion", + double.class, + double.class, + double.class, + float.class, + boolean.class); } @Override public boolean createExplosion(double arg0, double arg1, double arg2, float arg3, boolean arg4, boolean arg5, Entity arg6) { throw NotImplementedException.createByLazy(World.class, - "createExplosion", - double.class, - double.class, - double.class, - float.class, - boolean.class, - boolean.class, - Entity.class); + "createExplosion", + double.class, + double.class, + double.class, + float.class, + boolean.class, + boolean.class, + Entity.class); } @Override @@ -407,22 +412,22 @@ public boolean createExplosion(@NotNull Location arg0, float arg1) { @Override public boolean createExplosion(@NotNull Location arg0, float arg1, boolean arg2, boolean arg3, Entity arg4) { throw NotImplementedException.createByLazy(World.class, - "createExplosion", - Location.class, - float.class, - boolean.class, - boolean.class, - Entity.class); + "createExplosion", + Location.class, + float.class, + boolean.class, + boolean.class, + Entity.class); } @Override public boolean createExplosion(@NotNull Location arg0, float arg1, boolean arg2, boolean arg3) { throw NotImplementedException.createByLazy(World.class, - "createExplosion", - Location.class, - float.class, - boolean.class, - boolean.class); + "createExplosion", + Location.class, + float.class, + boolean.class, + boolean.class); } @Override @@ -443,7 +448,7 @@ public boolean createExplosion(@NotNull Location arg0, float arg1, boolean arg2, .orElseThrow(() -> new RuntimeException("EntityType could not be found for class " + aClass.getName())); var spongeEntity = this.sponge() .createEntity(SoakEntityMap.toSponge(bukkitType), - new Vector3d(location.getX(), location.getY(), location.getZ())); + new Vector3d(location.getX(), location.getY(), location.getZ())); @SuppressWarnings("unchecked") var bukkitEntity = (T) AbstractEntity.wrap(spongeEntity); if (consumer != null) { consumer.accept(bukkitEntity); @@ -457,11 +462,11 @@ public boolean createExplosion(@NotNull Location arg0, float arg1, boolean arg2, java.util.function.@Nullable Consumer consumer) throws IllegalArgumentException { throw NotImplementedException.createByLazy(World.class, - "spawn", - Location.class, - Class.class, - boolean.class, - java.util.function.Consumer.class); + "spawn", + Location.class, + Class.class, + boolean.class, + java.util.function.Consumer.class); } @@ -470,199 +475,199 @@ public void spawnParticle(@NotNull Particle arg0, List arg1, Player arg2, double int arg6, double arg7, double arg8, double arg9, double arg10, Object arg11, boolean arg12) { throw NotImplementedException.createByLazy(World.class, - "spawnParticle", - Particle.class, - List.class, - Player.class, - double.class, - double.class, - double.class, - int.class, - double.class, - double.class, - double.class, - double.class, - Object.class, - boolean.class); + "spawnParticle", + Particle.class, + List.class, + Player.class, + double.class, + double.class, + double.class, + int.class, + double.class, + double.class, + double.class, + double.class, + Object.class, + boolean.class); } @Override public void spawnParticle(@NotNull Particle arg0, @NotNull Location arg1, int arg2, double arg3, double arg4, double arg5, double arg6, Object arg7, boolean arg8) { throw NotImplementedException.createByLazy(World.class, - "spawnParticle", - Particle.class, - Location.class, - int.class, - double.class, - double.class, - double.class, - double.class, - Object.class, - boolean.class); + "spawnParticle", + Particle.class, + Location.class, + int.class, + double.class, + double.class, + double.class, + double.class, + Object.class, + boolean.class); } @Override public void spawnParticle(@NotNull Particle arg0, @NotNull Location arg1, int arg2) { throw NotImplementedException.createByLazy(World.class, - "spawnParticle", - Particle.class, - Location.class, - int.class); + "spawnParticle", + Particle.class, + Location.class, + int.class); } @Override public void spawnParticle(@NotNull Particle arg0, @NotNull Location arg1, int arg2, double arg3, double arg4, double arg5) { throw NotImplementedException.createByLazy(World.class, - "spawnParticle", - Particle.class, - Location.class, - int.class, - double.class, - double.class, - double.class); + "spawnParticle", + Particle.class, + Location.class, + int.class, + double.class, + double.class, + double.class); } @Override public void spawnParticle(@NotNull Particle arg0, double arg1, double arg2, double arg3, int arg4, double arg5, double arg6, double arg7) { throw NotImplementedException.createByLazy(World.class, - "spawnParticle", - Particle.class, - double.class, - double.class, - double.class, - int.class, - double.class, - double.class, - double.class); + "spawnParticle", + Particle.class, + double.class, + double.class, + double.class, + int.class, + double.class, + double.class, + double.class); } @Override public void spawnParticle(@NotNull Particle arg0, @NotNull Location arg1, int arg2, double arg3, double arg4, double arg5, Object arg6) { throw NotImplementedException.createByLazy(World.class, - "spawnParticle", - Particle.class, - Location.class, - int.class, - double.class, - double.class, - double.class, - Object.class); + "spawnParticle", + Particle.class, + Location.class, + int.class, + double.class, + double.class, + double.class, + Object.class); } @Override public void spawnParticle(@NotNull Particle arg0, double arg1, double arg2, double arg3, int arg4, Object arg5) { throw NotImplementedException.createByLazy(World.class, - "spawnParticle", - Particle.class, - double.class, - double.class, - double.class, - int.class, - Object.class); + "spawnParticle", + Particle.class, + double.class, + double.class, + double.class, + int.class, + Object.class); } @Override public void spawnParticle(@NotNull Particle arg0, @NotNull Location arg1, int arg2, Object arg3) { throw NotImplementedException.createByLazy(World.class, - "spawnParticle", - Particle.class, - Location.class, - int.class, - Object.class); + "spawnParticle", + Particle.class, + Location.class, + int.class, + Object.class); } @Override public void spawnParticle(@NotNull Particle arg0, double arg1, double arg2, double arg3, int arg4) { throw NotImplementedException.createByLazy(World.class, - "spawnParticle", - Particle.class, - double.class, - double.class, - double.class, - int.class); + "spawnParticle", + Particle.class, + double.class, + double.class, + double.class, + int.class); } @Override public void spawnParticle(@NotNull Particle arg0, double arg1, double arg2, double arg3, int arg4, double arg5, double arg6, double arg7, double arg8) { throw NotImplementedException.createByLazy(World.class, - "spawnParticle", - Particle.class, - double.class, - double.class, - double.class, - int.class, - double.class, - double.class, - double.class, - double.class); + "spawnParticle", + Particle.class, + double.class, + double.class, + double.class, + int.class, + double.class, + double.class, + double.class, + double.class); } @Override public void spawnParticle(@NotNull Particle arg0, @NotNull Location arg1, int arg2, double arg3, double arg4, double arg5, double arg6, Object arg7) { throw NotImplementedException.createByLazy(World.class, - "spawnParticle", - Particle.class, - Location.class, - int.class, - double.class, - double.class, - double.class, - double.class, - Object.class); + "spawnParticle", + Particle.class, + Location.class, + int.class, + double.class, + double.class, + double.class, + double.class, + Object.class); } @Override public void spawnParticle(@NotNull Particle arg0, double arg1, double arg2, double arg3, int arg4, double arg5, double arg6, double arg7, Object arg8) { throw NotImplementedException.createByLazy(World.class, - "spawnParticle", - Particle.class, - double.class, - double.class, - double.class, - int.class, - double.class, - double.class, - double.class, - Object.class); + "spawnParticle", + Particle.class, + double.class, + double.class, + double.class, + int.class, + double.class, + double.class, + double.class, + Object.class); } @Override public void spawnParticle(@NotNull Particle arg0, @NotNull Location arg1, int arg2, double arg3, double arg4, double arg5, double arg6) { throw NotImplementedException.createByLazy(World.class, - "spawnParticle", - Particle.class, - Location.class, - int.class, - double.class, - double.class, - double.class, - double.class); + "spawnParticle", + Particle.class, + Location.class, + int.class, + double.class, + double.class, + double.class, + double.class); } @Override public void spawnParticle(@NotNull Particle arg0, double arg1, double arg2, double arg3, int arg4, double arg5, double arg6, double arg7, double arg8, Object arg9, boolean arg10) { throw NotImplementedException.createByLazy(World.class, - "spawnParticle", - Particle.class, - double.class, - double.class, - double.class, - int.class, - double.class, - double.class, - double.class, - double.class, - Object.class, - boolean.class); + "spawnParticle", + Particle.class, + double.class, + double.class, + double.class, + int.class, + double.class, + double.class, + double.class, + double.class, + Object.class, + boolean.class); } @Override @@ -768,10 +773,10 @@ public boolean isChunkForceLoaded(int arg0, int arg1) { @Override public void setChunkForceLoaded(int arg0, int arg1, boolean arg2) { throw NotImplementedException.createByLazy(World.class, - "setChunkForceLoaded", - int.class, - int.class, - boolean.class); + "setChunkForceLoaded", + int.class, + int.class, + boolean.class); } @Override @@ -782,19 +787,19 @@ public void setChunkForceLoaded(int arg0, int arg1, boolean arg2) { @Override public boolean addPluginChunkTicket(int arg0, int arg1, @NotNull Plugin arg2) { throw NotImplementedException.createByLazy(World.class, - "addPluginChunkTicket", - int.class, - int.class, - Plugin.class); + "addPluginChunkTicket", + int.class, + int.class, + Plugin.class); } @Override public boolean removePluginChunkTicket(int arg0, int arg1, @NotNull Plugin arg2) { throw NotImplementedException.createByLazy(World.class, - "removePluginChunkTicket", - int.class, - int.class, - Plugin.class); + "removePluginChunkTicket", + int.class, + int.class, + Plugin.class); } @Override @@ -826,10 +831,10 @@ public void removePluginChunkTickets(@NotNull Plugin arg0) { public @NotNull Item dropItem(@NotNull Location location, @NotNull ItemStack itemStack, java.util.function.@Nullable Consumer consumer) { throw NotImplementedException.createByLazy(World.class, - "dropItem", - Location.class, - ItemStack.class, - java.util.function.Consumer.class); + "dropItem", + Location.class, + ItemStack.class, + java.util.function.Consumer.class); } @Override @@ -841,10 +846,10 @@ public void removePluginChunkTickets(@NotNull Plugin arg0) { public @NotNull Item dropItemNaturally(@NotNull Location location, @NotNull ItemStack itemStack, java.util.function.@Nullable Consumer consumer) { throw NotImplementedException.createByLazy(World.class, - "dropItemNaturally", - Location.class, - ItemStack.class, - Consumer.class); + "dropItemNaturally", + Location.class, + ItemStack.class, + Consumer.class); } @@ -852,31 +857,31 @@ public void removePluginChunkTickets(@NotNull Plugin arg0) { public @NotNull T spawnArrow(@NotNull Location location, @NotNull Vector direction, float speed, float spread, @NotNull Class clazz) { throw NotImplementedException.createByLazy(World.class, - "spawnArrow", - Location.class, - Vector.class, - float.class, - float.class, - Class.class); + "spawnArrow", + Location.class, + Vector.class, + float.class, + float.class, + Class.class); } @Override public @NotNull Arrow spawnArrow(@NotNull Location arg0, @NotNull Vector arg1, float arg2, float arg3) { throw NotImplementedException.createByLazy(World.class, - "spawnArrow", - Location.class, - Vector.class, - float.class, - float.class); + "spawnArrow", + Location.class, + Vector.class, + float.class, + float.class); } @Override public boolean generateTree(@NotNull Location arg0, @NotNull TreeType arg1, @NotNull BlockChangeDelegate arg2) { throw NotImplementedException.createByLazy(World.class, - "generateTree", - Location.class, - TreeType.class, - BlockChangeDelegate.class); + "generateTree", + Location.class, + TreeType.class, + BlockChangeDelegate.class); } @Override @@ -895,10 +900,10 @@ public boolean generateTree(@NotNull Location arg0, @NotNull TreeType arg1) { @Override public @NotNull Entity spawnEntity(@NotNull Location location, @NotNull EntityType entityType, boolean b) { throw NotImplementedException.createByLazy(World.class, - "spawnEntity", - Location.class, - EntityType.class, - boolean.class); + "spawnEntity", + Location.class, + EntityType.class, + boolean.class); } @Override @@ -933,17 +938,17 @@ private LightningStrike strikeLightning(Location location, Consumer List generateEntityList(Function, Stream> filter) { Supplier> spongeEntities = () -> filter.apply(this.world.entities() - .stream()); + .stream()); var collectionBuilder = CollectionStreamBuilder.builder() .stream(spongeEntities) .basicMap(spongeEntity -> (T) AbstractEntity.wrap(spongeEntity)); return ListMappingUtils.fromStream(collectionBuilder, - () -> this.world.entities() - .stream() - .map(e -> (org.spongepowered.api.entity.Entity) e), - (spongeEntity, soakEntity) -> ((AbstractEntity) soakEntity).spongeEntity() - .equals(spongeEntity), - Comparator.comparing(entity -> entity.uniqueId().toString())).buildList(); + () -> this.world.entities() + .stream() + .map(e -> (org.spongepowered.api.entity.Entity) e), + (spongeEntity, soakEntity) -> ((AbstractEntity) soakEntity).spongeEntity() + .equals(spongeEntity), + Comparator.comparing(entity -> entity.uniqueId().toString())).buildList(); } private List generateEntityListAdvanced(Function, Stream> advancedMap) { @@ -952,12 +957,12 @@ private List generateEntityListAdvanced(Function t); var collectionBuilder = CollectionStreamBuilder.builder().stream(spongeEntities).map(advancedMap); return ListMappingUtils.fromStream(collectionBuilder, - () -> this.world.entities() - .stream() - .map(e -> (org.spongepowered.api.entity.Entity) e), - (spongeEntity, soakEntity) -> ((AbstractEntity) soakEntity).spongeEntity() - .equals(spongeEntity), - Comparator.comparing(entity -> entity.uniqueId().toString())).buildList(); + () -> this.world.entities() + .stream() + .map(e -> (org.spongepowered.api.entity.Entity) e), + (spongeEntity, soakEntity) -> ((AbstractEntity) soakEntity).spongeEntity() + .equals(spongeEntity), + Comparator.comparing(entity -> entity.uniqueId().toString())).buildList(); } @Override @@ -993,9 +998,20 @@ private List generateEntityListAdvanced(Function entity)); } + @Override + public void getChunkAtAsync(int x, int z, boolean gen, boolean urgent, java.util.function.@NotNull Consumer cb) { + throw NotImplementedException.createByLazy(World.class, "getChunkAtAsync", int.class, int.class, boolean.class, boolean.class, + java.util.function.Consumer.class); + } + + @Override + public void getChunksAtAsync(int minX, int minZ, int maxX, int maxZ, boolean urgent, @NotNull Runnable cb) { + throw NotImplementedException.createByLazy(World.class, "getChunksAtAsync", int.class, int.class, int.class, int.class, boolean.class, Runnable.class); + } + @Override public @NotNull T createEntity(@NotNull Location location, @NotNull Class aClass) { - throw NotImplementedException.createByLazy(SoakWorld.class, "createEntity", Location.class, Class.class); + throw NotImplementedException.createByLazy(World.class, "createEntity", Location.class, Class.class); } @Override @@ -1007,86 +1023,86 @@ public Entity getEntity(@NotNull UUID arg0) { public @NotNull Collection getNearbyEntities(@NotNull Location location, double v, double v1, double v2, @Nullable Predicate predicate) { throw NotImplementedException.createByLazy(World.class, - "getNearbyEntities", - Location.class, - double.class, - double.class, - double.class, - Predicate.class); + "getNearbyEntities", + Location.class, + double.class, + double.class, + double.class, + Predicate.class); } @Override public RayTraceResult rayTraceEntities(@NotNull Location arg0, @NotNull Vector arg1, double arg2) { throw NotImplementedException.createByLazy(World.class, - "rayTraceEntities", - Location.class, - Vector.class, - double.class); + "rayTraceEntities", + Location.class, + Vector.class, + double.class); } @Override public RayTraceResult rayTraceEntities(@NotNull Location arg0, @NotNull Vector arg1, double arg2, double arg3, Predicate arg4) { throw NotImplementedException.createByLazy(World.class, - "rayTraceEntities", - Location.class, - Vector.class, - double.class, - double.class, - Predicate.class); + "rayTraceEntities", + Location.class, + Vector.class, + double.class, + double.class, + Predicate.class); } @Override public RayTraceResult rayTraceEntities(@NotNull Location arg0, @NotNull Vector arg1, double arg2, Predicate arg3) { throw NotImplementedException.createByLazy(World.class, - "rayTraceEntities", - Location.class, - Vector.class, - double.class, - Predicate.class); + "rayTraceEntities", + Location.class, + Vector.class, + double.class, + Predicate.class); } @Override public RayTraceResult rayTraceEntities(@NotNull Location arg0, @NotNull Vector arg1, double arg2, double arg3) { throw NotImplementedException.createByLazy(World.class, - "rayTraceEntities", - Location.class, - Vector.class, - double.class, - double.class); + "rayTraceEntities", + Location.class, + Vector.class, + double.class, + double.class); } @Override public @Nullable RayTraceResult rayTraceEntities(@NotNull Position position, @NotNull Vector vector, double v, double v1, @Nullable Predicate predicate) { throw NotImplementedException.createByLazy(World.class, - "rayTraceEntities", - Position.class, - Vector.class, - double.class, - double.class, - Predicate.class); + "rayTraceEntities", + Position.class, + Vector.class, + double.class, + double.class, + Predicate.class); } @Override public RayTraceResult rayTraceBlocks(@NotNull Location arg0, @NotNull Vector arg1, double arg2) { throw NotImplementedException.createByLazy(World.class, - "rayTraceBlocks", - Location.class, - Vector.class, - double.class); + "rayTraceBlocks", + Location.class, + Vector.class, + double.class); } @Override public RayTraceResult rayTraceBlocks(@NotNull Location arg0, @NotNull Vector arg1, double arg2, @NotNull FluidCollisionMode arg3, boolean arg4) { throw NotImplementedException.createByLazy(World.class, - "rayTraceBlocks", - Location.class, - Vector.class, - double.class, - FluidCollisionMode.class, - boolean.class); + "rayTraceBlocks", + Location.class, + Vector.class, + double.class, + FluidCollisionMode.class, + boolean.class); } @Override @@ -1094,13 +1110,13 @@ public RayTraceResult rayTraceBlocks(@NotNull Location arg0, @NotNull Vector arg @NotNull FluidCollisionMode fluidCollisionMode, boolean b, @Nullable Predicate predicate) { throw NotImplementedException.createByLazy(World.class, - "rayTraceBlocks", - Position.class, - Vector.class, - double.class, - FluidCollisionMode.class, - boolean.class, - Predicate.class); + "rayTraceBlocks", + Position.class, + Vector.class, + double.class, + FluidCollisionMode.class, + boolean.class, + Predicate.class); } @Override @@ -1109,40 +1125,45 @@ public RayTraceResult rayTraceBlocks(@NotNull Location arg0, @NotNull Vector arg @Nullable Predicate predicate, @Nullable Predicate predicate1) { throw NotImplementedException.createByLazy(World.class, - "rayTrace", - Position.class, - Vector.class, - double.class, - FluidCollisionMode.class, - boolean.class, - double.class, - Predicate.class, - Predicate.class); + "rayTrace", + Position.class, + Vector.class, + double.class, + FluidCollisionMode.class, + boolean.class, + double.class, + Predicate.class, + Predicate.class); + } + + @Override + public @Nullable RayTraceResult rayTrace(java.util.function.@NotNull Consumer builderConsumer) { + return null; } @Override public RayTraceResult rayTraceBlocks(@NotNull Location arg0, @NotNull Vector arg1, double arg2, @NotNull FluidCollisionMode arg3) { throw NotImplementedException.createByLazy(World.class, - "rayTraceBlocks", - Location.class, - Vector.class, - double.class, - FluidCollisionMode.class); + "rayTraceBlocks", + Location.class, + Vector.class, + double.class, + FluidCollisionMode.class); } @Override public RayTraceResult rayTrace(@NotNull Location arg0, @NotNull Vector arg1, double arg2, @NotNull FluidCollisionMode arg3, boolean arg4, double arg5, Predicate arg6) { throw NotImplementedException.createByLazy(World.class, - "rayTrace", - Location.class, - Vector.class, - double.class, - FluidCollisionMode.class, - boolean.class, - double.class, - Predicate.class); + "rayTrace", + Location.class, + Vector.class, + double.class, + FluidCollisionMode.class, + boolean.class, + double.class, + Predicate.class); } @Override @@ -1169,11 +1190,11 @@ public boolean setSpawnLocation(int arg0, int arg1, int arg2) { @Override public boolean setSpawnLocation(int arg0, int arg1, int arg2, float arg3) { throw NotImplementedException.createByLazy(World.class, - "setSpawnLocation", - int.class, - int.class, - int.class, - float.class); + "setSpawnLocation", + int.class, + int.class, + int.class, + float.class); } @Override @@ -1293,12 +1314,12 @@ public ChunkGenerator getGenerator() { java.util.function.@Nullable Consumer consumer) throws IllegalArgumentException { throw NotImplementedException.createByLazy(World.class, - "spawn", - Location.class, - Class.class, - CreatureSpawnEvent.SpawnReason.class, - boolean.class, - java.util.function.Consumer.class); + "spawn", + Location.class, + Class.class, + CreatureSpawnEvent.SpawnReason.class, + boolean.class, + java.util.function.Consumer.class); } @Override @@ -1310,19 +1331,19 @@ public ChunkGenerator getGenerator() { @Deprecated public @NotNull FallingBlock spawnFallingBlock(@NotNull Location arg0, @NotNull MaterialData arg1) { throw NotImplementedException.createByLazy(World.class, - "spawnFallingBlock", - Location.class, - MaterialData.class); + "spawnFallingBlock", + Location.class, + MaterialData.class); } @Deprecated @Override public @NotNull FallingBlock spawnFallingBlock(@NotNull Location arg0, @NotNull Material arg1, byte arg2) { throw NotImplementedException.createByLazy(World.class, - "spawnFallingBlock", - Location.class, - Material.class, - byte.class); + "spawnFallingBlock", + Location.class, + Material.class, + byte.class); } @Override @@ -1333,40 +1354,40 @@ public void playEffect(@NotNull Location arg0, @NotNull Effect arg1, int arg2) { @Override public void playEffect(@NotNull Location arg0, @NotNull Effect arg1, Object arg2, int arg3) { throw NotImplementedException.createByLazy(World.class, - "playEffect", - Location.class, - Effect.class, - Object.class, - int.class); + "playEffect", + Location.class, + Effect.class, + Object.class, + int.class); } @Override public void playEffect(@NotNull Location arg0, @NotNull Effect arg1, Object arg2) { throw NotImplementedException.createByLazy(World.class, - "playEffect", - Location.class, - Effect.class, - Object.class); + "playEffect", + Location.class, + Effect.class, + Object.class); } @Override public void playEffect(@NotNull Location arg0, @NotNull Effect arg1, int arg2, int arg3) { throw NotImplementedException.createByLazy(World.class, - "playEffect", - Location.class, - Effect.class, - int.class, - int.class); + "playEffect", + Location.class, + Effect.class, + int.class, + int.class); } @Override public @NotNull ChunkSnapshot getEmptyChunkSnapshot(int arg0, int arg1, boolean arg2, boolean arg3) { throw NotImplementedException.createByLazy(World.class, - "getEmptyChunkSnapshot", - int.class, - int.class, - boolean.class, - boolean.class); + "getEmptyChunkSnapshot", + int.class, + int.class, + boolean.class, + boolean.class); } @Override @@ -1413,11 +1434,11 @@ public void setBiome(@NotNull Location location, @NotNull Biome biome) { @Override public void setBiome(int arg0, int arg1, int arg2, @NotNull Biome arg3) { throw NotImplementedException.createByLazy(World.class, - "setBiome", - int.class, - int.class, - int.class, - Biome.class); + "setBiome", + int.class, + int.class, + int.class, + Biome.class); } @Override @@ -1464,11 +1485,11 @@ public void setBlockData(@NotNull Location location, @NotNull BlockData blockDat @Override public void setBlockData(int i, int i1, int i2, @NotNull BlockData blockData) { throw NotImplementedException.createByLazy(World.class, - "setBlockData", - int.class, - int.class, - int.class, - BlockData.class); + "setBlockData", + int.class, + int.class, + int.class, + BlockData.class); } @Override @@ -1479,43 +1500,43 @@ public void setType(@NotNull Location location, @NotNull Material material) { @Override public void setType(int i, int i1, int i2, @NotNull Material material) { throw NotImplementedException.createByLazy(World.class, - "setType", - int.class, - int.class, - int.class, - Material.class); + "setType", + int.class, + int.class, + int.class, + Material.class); } @Override public boolean generateTree(@NotNull Location location, @NotNull Random random, @NotNull TreeType treeType) { throw NotImplementedException.createByLazy(World.class, - "generateTree", - Location.class, - Random.class, - TreeType.class); + "generateTree", + Location.class, + Random.class, + TreeType.class); } @Override public boolean generateTree(@NotNull Location location, @NotNull Random random, @NotNull TreeType treeType, java.util.function.@Nullable Consumer consumer) { throw NotImplementedException.createByLazy(World.class, - "generateTree", - Location.class, - Random.class, - TreeType.class, - java.util.function.Consumer.class); + "generateTree", + Location.class, + Random.class, + TreeType.class, + java.util.function.Consumer.class); } @Override public boolean generateTree(@NotNull Location location, @NotNull Random random, @NotNull TreeType treeType, @Nullable Predicate predicate) { throw NotImplementedException.createByLazy(World.class, - "generateTree", - Location.class, - Random.class, - TreeType.class, - Predicate.class); + "generateTree", + Location.class, + Random.class, + TreeType.class, + Predicate.class); } @@ -1607,6 +1628,11 @@ public void setDifficulty(@NotNull Difficulty arg0) { throw NotImplementedException.createByLazy(World.class, "getWorldFolder"); } + @Override + public @NotNull Path getWorldPath() { + return null; + } + @Deprecated @Override public WorldType getWorldType() { @@ -1618,6 +1644,11 @@ public boolean canGenerateStructures() { throw NotImplementedException.createByLazy(World.class, "canGenerateStructures"); } + @Override + public boolean hasBonusChest() { + return false; + } + @Override public boolean isHardcore() { throw NotImplementedException.createByLazy(World.class, "isHardcore"); @@ -1773,102 +1804,102 @@ public void setSpawnLimit(@NotNull SpawnCategory spawnCategory, int i) { @Override public void playNote(@NotNull Location location, @NotNull Instrument instrument, @NotNull Note note) { throw NotImplementedException.createByLazy(World.class, - "playNote", - Location.class, - Instrument.class, - Note.class); + "playNote", + Location.class, + Instrument.class, + Note.class); } @Override public void playSound(@NotNull Location arg0, @NotNull String arg1, float arg2, float arg3) { throw NotImplementedException.createByLazy(World.class, - "playSound", - Location.class, - String.class, - float.class, - float.class); + "playSound", + Location.class, + String.class, + float.class, + float.class); } @Override public void playSound(@NotNull Location arg0, @NotNull Sound arg1, @NotNull SoundCategory arg2, float arg3, float arg4) { throw NotImplementedException.createByLazy(World.class, - "playSound", - Location.class, - Sound.class, - SoundCategory.class, - float.class, - float.class); + "playSound", + Location.class, + Sound.class, + SoundCategory.class, + float.class, + float.class); } @Override public void playSound(@NotNull Location arg0, @NotNull Sound arg1, float arg2, float arg3) { throw NotImplementedException.createByLazy(World.class, - "playSound", - Location.class, - Sound.class, - float.class, - float.class); + "playSound", + Location.class, + Sound.class, + float.class, + float.class); } @Override public void playSound(@NotNull Location arg0, @NotNull String arg1, @NotNull SoundCategory arg2, float arg3, float arg4) { throw NotImplementedException.createByLazy(World.class, - "playSound", - Location.class, - String.class, - SoundCategory.class, - float.class, - float.class); + "playSound", + Location.class, + String.class, + SoundCategory.class, + float.class, + float.class); } @Override public void playSound(@NotNull Location location, @NotNull Sound sound, @NotNull SoundCategory soundCategory, float v, float v1, long l) { throw NotImplementedException.createByLazy(World.class, - "playSound", - Location.class, - Sound.class, - SoundCategory.class, - float.class, - float.class, - long.class); + "playSound", + Location.class, + Sound.class, + SoundCategory.class, + float.class, + float.class, + long.class); } @Override public void playSound(@NotNull Location location, @NotNull String s, @NotNull SoundCategory soundCategory, float v, float v1, long l) { throw NotImplementedException.createByLazy(World.class, - "playSound", - Location.class, - String.class, - SoundCategory.class, - float.class, - float.class, - long.class); + "playSound", + Location.class, + String.class, + SoundCategory.class, + float.class, + float.class, + long.class); } @Override public void playSound(@NotNull Entity entity, @NotNull Sound sound, float v, float v1) { throw NotImplementedException.createByLazy(World.class, - "playSound", - Entity.class, - Sound.class, - float.class, - float.class); + "playSound", + Entity.class, + Sound.class, + float.class, + float.class); } @Override public void playSound(@NotNull Entity entity, @NotNull String s, float v, float v1) { throw NotImplementedException.createByLazy(World.class, - "playSound", - Entity.class, - String.class, - float.class, - float.class); + "playSound", + Entity.class, + String.class, + float.class, + float.class); } @@ -1876,12 +1907,12 @@ public void playSound(@NotNull Entity entity, @NotNull String s, float v, float public void playSound(@NotNull Entity entity, @NotNull Sound sound, @NotNull SoundCategory soundCategory, float v , float v1) { throw NotImplementedException.createByLazy(World.class, - "playSound", - Entity.class, - Sound.class, - SoundCategory.class, - float.class, - float.class); + "playSound", + Entity.class, + Sound.class, + SoundCategory.class, + float.class, + float.class); } @@ -1889,12 +1920,12 @@ public void playSound(@NotNull Entity entity, @NotNull Sound sound, @NotNull Sou public void playSound(@NotNull Entity entity, @NotNull String s, @NotNull SoundCategory soundCategory, float v, float v1) { throw NotImplementedException.createByLazy(World.class, - "playSound", - Entity.class, - String.class, - SoundCategory.class, - float.class, - float.class); + "playSound", + Entity.class, + String.class, + SoundCategory.class, + float.class, + float.class); } @@ -1902,13 +1933,13 @@ public void playSound(@NotNull Entity entity, @NotNull String s, @NotNull SoundC public void playSound(@NotNull Entity entity, @NotNull Sound sound, @NotNull SoundCategory soundCategory, float v , float v1, long l) { throw NotImplementedException.createByLazy(World.class, - "playSound", - Entity.class, - Sound.class, - SoundCategory.class, - float.class, - float.class, - long.class); + "playSound", + Entity.class, + Sound.class, + SoundCategory.class, + float.class, + float.class, + long.class); } @@ -1916,13 +1947,13 @@ public void playSound(@NotNull Entity entity, @NotNull Sound sound, @NotNull Sou public void playSound(@NotNull Entity entity, @NotNull String s, @NotNull SoundCategory soundCategory, float v, float v1, long l) { throw NotImplementedException.createByLazy(World.class, - "playSound", - Entity.class, - String.class, - SoundCategory.class, - float.class, - float.class, - long.class); + "playSound", + Entity.class, + String.class, + SoundCategory.class, + float.class, + float.class, + long.class); } @@ -1972,52 +2003,62 @@ public boolean setGameRule(@NotNull GameRule rule, @NotNull T newValue) { public Location locateNearestStructure(@NotNull Location arg0, @NotNull StructureType arg1, int arg2, boolean arg3) { throw NotImplementedException.createByLazy(World.class, - "locateNearestStructure", - Location.class, - StructureType.class, - int.class, - boolean.class); + "locateNearestStructure", + Location.class, + StructureType.class, + int.class, + boolean.class); } @Override public @Nullable StructureSearchResult locateNearestStructure(@NotNull Location location, org.bukkit.generator.structure.@NotNull StructureType structureType, int i, boolean b) { throw NotImplementedException.createByLazy(World.class, - "locateNearestStructure", - Location.class, - org.bukkit.generator.structure.StructureType.class, - int.class, - boolean.class); + "locateNearestStructure", + Location.class, + org.bukkit.generator.structure.StructureType.class, + int.class, + boolean.class); } @Override public @Nullable StructureSearchResult locateNearestStructure(@NotNull Location location, @NotNull Structure structure, int i, boolean b) { throw NotImplementedException.createByLazy(World.class, - "locateNearestStructure", - Location.class, - Structure.class, - int.class, - boolean.class); + "locateNearestStructure", + Location.class, + Structure.class, + int.class, + boolean.class); } @Override public Location locateNearestBiome(@NotNull Location arg0, @NotNull Biome arg1, int arg2) { throw NotImplementedException.createByLazy(World.class, - "locateNearestBiome", - Location.class, - Biome.class, - int.class); + "locateNearestBiome", + Location.class, + Biome.class, + int.class); } @Override public Location locateNearestBiome(@NotNull Location arg0, @NotNull Biome arg1, int arg2, int arg3) { throw NotImplementedException.createByLazy(World.class, - "locateNearestBiome", - Location.class, - Biome.class, - int.class, - int.class); + "locateNearestBiome", + Location.class, + Biome.class, + int.class, + int.class); + } + + @Override + public @Nullable Location locateNearestPoi(@NotNull Location origin, @NotNull PoiType poiType, @Positive int radius, PoiType.@NotNull Occupancy occupancy) { + return null; + } + + @Override + public @NotNull List locateAllPoiInRange(@NotNull Location origin, @NotNull Predicate poiTypePredicate, @Positive int radius, PoiType.@NotNull Occupancy occupancy) { + return List.of(); } @Override @@ -2075,10 +2116,10 @@ public boolean isFixedTime() { @Override public void sendGameEvent(@Nullable Entity entity, @NotNull GameEvent gameEvent, @NotNull Vector vector) { throw NotImplementedException.createByLazy(World.class, - "sendGameEvent", - Entity.class, - GameEvent.class, - Vector.class); + "sendGameEvent", + Entity.class, + GameEvent.class, + Vector.class); } @@ -2141,10 +2182,10 @@ public void setSendViewDistance(int i) { @Override public @Nullable BiomeSearchResult locateNearestBiome(@NotNull Location location, int i, @NotNull Biome... biomes) { throw NotImplementedException.createByLazy(World.class, - "locateNearestBiome", - Location.class, - int.class, - Biome[].class); + "locateNearestBiome", + Location.class, + int.class, + Biome[].class); } @@ -2152,12 +2193,12 @@ public void setSendViewDistance(int i) { public @Nullable BiomeSearchResult locateNearestBiome(@NotNull Location location, int i, int i1, int i2, @NotNull Biome... biomes) { throw NotImplementedException.createByLazy(World.class, - "locateNearestBiome", - Location.class, - int.class, - int.class, - int.class, - Biome[].class); + "locateNearestBiome", + Location.class, + int.class, + int.class, + int.class, + Biome[].class); } @@ -2210,6 +2251,11 @@ public void save() { throw NotImplementedException.createByLazy(World.class, "save"); } + @Override + public void save(boolean flush) { + + } + @Override public void setMetadata(@NotNull String metadataKey, @NotNull MetadataValue newMetadataValue) { throw NotImplementedException.createByLazy(SoakWorld.class, "setMetadata", String.class, MetadataValue.class); @@ -2233,10 +2279,10 @@ public void removeMetadata(@NotNull String metadataKey, @NotNull Plugin owningPl @Override public void sendPluginMessage(@NotNull Plugin source, @NotNull String channel, byte[] message) { throw NotImplementedException.createByLazy(SoakWorld.class, - "sendPluginMessage", - Plugin.class, - String.class, - byte[].class); + "sendPluginMessage", + Plugin.class, + String.class, + byte[].class); } @Override diff --git a/Wrapper/src/main/java/org/soak/wrapper/world/chunk/SoakChunkSnapshot.java b/Wrapper/src/main/java/org/soak/wrapper/world/chunk/SoakChunkSnapshot.java index c6825e6..740595a 100644 --- a/Wrapper/src/main/java/org/soak/wrapper/world/chunk/SoakChunkSnapshot.java +++ b/Wrapper/src/main/java/org/soak/wrapper/world/chunk/SoakChunkSnapshot.java @@ -1,5 +1,6 @@ package org.soak.wrapper.world.chunk; +import net.kyori.adventure.key.Key; import org.bukkit.ChunkSnapshot; import org.bukkit.Material; import org.bukkit.block.Biome; @@ -7,7 +8,7 @@ import org.jetbrains.annotations.NotNull; import org.soak.WrapperManager; import org.soak.exception.NotImplementedException; -import org.soak.map.SoakBiomeMap; +import org.soak.map.SoakRegistryMap; import org.soak.plugin.SoakManager; import org.spongepowered.api.world.LightTypes; import org.spongepowered.api.world.chunk.ChunkStates; @@ -45,6 +46,11 @@ public int getZ() { return ((ServerWorld) this.chunk.world()).key().value(); } + @Override + public @NotNull Key getWorldKey() { + return ((ServerWorld)this.chunk.world()).key(); + } + @Override public @NotNull Material getBlockType(int x, int y, int z) { return getBlockData(x, y, z).getMaterial(); @@ -89,7 +95,7 @@ public int getHighestBlockYAt(int x, int z) { public @NotNull Biome getBiome(int x, int y, int z) { var minBlock = this.chunk.min(); var spongeBiome = this.chunk.biome(x + minBlock.x(), y, z + minBlock.y()); - return SoakBiomeMap.toBukkit(spongeBiome); + return SoakRegistryMap.toBukkit(spongeBiome); } @Override diff --git a/Wrapper/src/main/resources/META-INF/services/io.papermc.paper.InternalAPIBridge b/Wrapper/src/main/resources/META-INF/services/io.papermc.paper.InternalAPIBridge new file mode 100644 index 0000000..a69d1e9 --- /dev/null +++ b/Wrapper/src/main/resources/META-INF/services/io.papermc.paper.InternalAPIBridge @@ -0,0 +1 @@ +org.soak.wrapper.SoakInternalApiBridge \ No newline at end of file diff --git a/build.gradle b/build.gradle index 1612470..2c8ef11 100644 --- a/build.gradle +++ b/build.gradle @@ -12,8 +12,8 @@ version = project.property("BUKKIT_VERSION") + "." + dateTime.format(DateTimeFor java { toolchain { - targetCompatibility = JavaVersion.VERSION_21 - sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_25 + sourceCompatibility = JavaVersion.VERSION_25 } } @@ -32,5 +32,8 @@ allprojects { maven { url "https://maven.neoforged.net/releases" } + maven { + url "https://repo.spongepowered.org/repository/maven-public/" + } } } \ No newline at end of file diff --git a/build.sh b/build.sh deleted file mode 100644 index 1dc8cf6..0000000 --- a/build.sh +++ /dev/null @@ -1,5 +0,0 @@ -git clone https://github.com/SoakProject/MultiBuild.git - -./gradlew build - -./MultiBuild/gradlew run -p="./MultiBuild/" --args="./../../Wrapper/src 21" \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 69bef07..9673dde 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ -SPONGE_VERSION=12.1.0-SNAPSHOT -BUKKIT_VERSION=1.21.1 -JAVA_VERSION=21 \ No newline at end of file +SPONGE_VERSION=19.0.0-SNAPSHOT +BUKKIT_VERSION=26.1.2 +JAVA_VERSION=25 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index e644113..0000000 Binary files a/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a441313..1a70468 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.0-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/settings.gradle b/settings.gradle index 5231d21..cfa4e8e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -8,20 +8,15 @@ */ rootProject.name = "soak" -include("bukkit-api") -include("VanillaMaterials") include("CollectionStream") include("MoseStream") include 'Wrapper' include 'Launch-Common' include 'Launch-Internal' include 'Launch-External' -include 'Gradle-Annotations' include 'Common' include 'Override' -include 'Launch-External:Neo' +/*include 'Launch-External:Neo' findProject(':Launch-External:Neo')?.name = 'Neo' -include 'NMSBounce' include 'Launch-External:Lex' -findProject(':Launch-External:Lex')?.name = 'Lex' -include 'MultiBuild:annotations' +findProject(':Launch-External:Lex')?.name = 'Lex'*/