Solved config cant be found

Lego12

New member
Aug 9, 2023
5
1
1
I use Intelliji btw

|||error|||
[17:23:49 INFO]: [Spawn] Enabling Spawn v1.0-SNAPSHOT
[17:23:49 ERROR]: Error occurred while enabling Spawn v1.0-SNAPSHOT (Is it up to date?)
java.lang.IllegalArgumentException: The embedded resource 'config.yml' cannot be found in plugins\Spawn-1.0-SNAPSHOT.jar
at org.bukkit.plugin.java.JavaPlugin.saveResource(JavaPlugin.java:209) ~[paper-api-1.20.1-R0.1-SNAPSHOT.jar:?]
at org.bukkit.plugin.java.JavaPlugin.saveDefaultConfig(JavaPlugin.java:196) ~[paper-api-1.20.1-R0.1-SNAPSHOT.jar:?]
at me.lego12.spawn.Main.onEnable(Main.java:12) ~[Spawn-1.0-SNAPSHOT.jar:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:281) ~[paper-api-1.20.1-R0.1-SNAPSHOT.jar:?]
at io.papermc.paper.plugin.manager.PaperPluginInstanceManager.enablePlugin(PaperPluginInstanceManager.java:189) ~[paper-1.20.1.jar:git-Paper-108]
at io.papermc.paper.plugin.manager.PaperPluginManagerImpl.enablePlugin(PaperPluginManagerImpl.java:104) ~[paper-1.20.1.jar:git-Paper-108]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:507) ~[paper-api-1.20.1-R0.1-SNAPSHOT.jar:?]
at org.bukkit.craftbukkit.v1_20_R1.CraftServer.enablePlugin(CraftServer.java:640) ~[paper-1.20.1.jar:git-Paper-108]
at org.bukkit.craftbukkit.v1_20_R1.CraftServer.enablePlugins(CraftServer.java:551) ~[paper-1.20.1.jar:git-Paper-108]
at net.minecraft.server.MinecraftServer.loadWorld0(MinecraftServer.java:636) ~[paper-1.20.1.jar:git-Paper-108]
at net.minecraft.server.MinecraftServer.loadLevel(MinecraftServer.java:435) ~[paper-1.20.1.jar:git-Paper-108]
at net.minecraft.server.dedicated.DedicatedServer.initServer(DedicatedServer.java:308) ~[paper-1.20.1.jar:git-Paper-108]
at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1101) ~[paper-1.20.1.jar:git-Paper-108]
at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:318) ~[paper-1.20.1.jar:git-Paper-108]
at java.lang.Thread.run(Thread.java:1623) ~[?:?]
[17:23:49 INFO]: [Spawn] Disabling Spawn v1.0-SNAPSHOT
[17:23:49 INFO]: [Spawn] [STDOUT] Failed to load Spawn Plugin!
|||error|||

me.lego12.spawn.Main
JavaScript:
package me.lego12.spawn;

import me.lego12.spawn.Commands.SetSpawnCommand;
import me.lego12.spawn.Commands.SpawnCommand;
import org.bukkit.plugin.java.JavaPlugin;

public class Main extends JavaPlugin {

    @Override
    public void onEnable() {
        //config.yml
        saveDefaultConfig();
        getConfig().options().copyDefaults();
        saveConfig();

        getCommand("setspawn").setExecutor(new SetSpawnCommand(this));
        getCommand("spawn").setExecutor(new SpawnCommand(this));

    }
    public void onDisable(){
        System.out.println("Failed to load Spawn Plugin!");
    }

}

me.lego12.spawn.Commands.SpawnCommand
JavaScript:
package me.lego12.spawn.Commands;

import me.lego12.spawn.Main;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class SpawnCommand implements CommandExecutor {

    private final Main plugin;

    public SpawnCommand(Main plugin) {
        this.plugin = plugin;
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {

        if (sender instanceof Player p){


            Location location = plugin.getConfig().getLocation("spawn");

            if (location != null){

                p.teleport(location);

                p.sendMessage("You have been teleported to spawn!");

            }else{
                p.sendMessage("Seems like there isn't a spawn point set, lol");
            }
        }

        return true;
    }
}

me.lego12.spawn.Commands.SetSpawnCommand
JavaScript:
package me.lego12.spawn.Commands;

import me.lego12.spawn.Main;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class SetSpawnCommand implements CommandExecutor {

    private final Main plugin;

    public SetSpawnCommand(Main plugin){

        this.plugin = plugin;
    }



    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {

        if (sender instanceof Player p){


            Location location = p.getLocation();

            //save the location
            plugin.getConfig().set("spawn", location);

            plugin.saveConfig();

            p.sendMessage("Spawn location set!");
        }


        return true;
    }
}

pom.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>me.Lego12</groupId>
    <artifactId>Spawn</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>Spawn</name>

    <properties>
        <java.version>20</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <createDependencyReducedPom>false</createDependencyReducedPom>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>

    <repositories>
        <repository>
            <id>papermc-repo</id>
            <url>https://repo.papermc.io/repository/maven-public/</url>
        </repository>
        <repository>
            <id>sonatype</id>
            <url>https://oss.sonatype.org/content/groups/public/</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>io.papermc.paper</groupId>
            <artifactId>paper-api</artifactId>
            <version>1.20.1-R0.1-SNAPSHOT</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
</project>




Resources:
config.yml
plugin.yml
 
Last edited:
Solution
if i'm not wrong you havn't created the folder of the plugin.
make sure to execute this before the config file creation in the code:

Java:
        if (!getDataFolder().exists()){
            getLogger().info("Creating "+ getDataFolder() +" main directory ");
            getDataFolder().mkdir();
            //creating main plugin directory if not exists
            saveDefaultConfig();
            // then saving the config
        }

Happy to help :)

Machine Maker

Paper Developer
Staff member
Dec 17, 2021
132
6
19
18
California
Check to make sure the config.yml file is in the jar file. You can just unzip the jar and see for yourself. If it isn't, you probably need to configure maven to copy it over.
 

MkdirGit

New member
Jul 2, 2023
10
2
1
3
Israel
if i'm not wrong you havn't created the folder of the plugin.
make sure to execute this before the config file creation in the code:

Java:
        if (!getDataFolder().exists()){
            getLogger().info("Creating "+ getDataFolder() +" main directory ");
            getDataFolder().mkdir();
            //creating main plugin directory if not exists
            saveDefaultConfig();
            // then saving the config
        }

Happy to help :)
 
  • Like
Reactions: Lego12
Solution

Lego12

New member
Aug 9, 2023
5
1
1
if i'm not wrong you havn't created the folder of the plugin.
make sure to execute this before the config file creation in the code:

Java:
        if (!getDataFolder().exists()){
            getLogger().info("Creating "+ getDataFolder() +" main directory ");
            getDataFolder().mkdir();
            //creating main plugin directory if not exists
            saveDefaultConfig();
            // then saving the config
        }

Happy to help :)
I ran it again testing out a different plugin and there where not any errors.

tested out the commands:
works perfectly!
 

electronicboy

Administrator
Staff member
Dec 11, 2021
231
10
40
28
That error is purely a "this file does not exist in the jar"; stop your server, do mvn clean package and then copy the plugin jar over, heck, open it with winrar or 7zip or whatever and see that the "config.yml" is in there
 

Lego12

New member
Aug 9, 2023
5
1
1
if i'm not wrong you havn't created the folder of the plugin.
make sure to execute this before the config file creation in the code:

Java:
        if (!getDataFolder().exists()){
            getLogger().info("Creating "+ getDataFolder() +" main directory ");
            getDataFolder().mkdir();
            //creating main plugin directory if not exists
            saveDefaultConfig();
            // then saving the config
        }

Happy to help :)
I think I see what you meen, after running it I noticed a new folder, next time ill create a folder with the plugin!
 
  • Haha
Reactions: MkdirGit