my spawn plugin didn't work

Discussion in 'Plugin Development' started by Konya42, Jan 23, 2022.

Thread Status:
Not open for further replies.
  1. Offline

    Konya42

    Ana.java
    Code:
    package lobi;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Ana extends JavaPlugin implements Listener{
    
        public void onEnable() {
            this.getCommand("dogmayeriyap").setExecutor(new Komut());
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
        }
        @EventHandler
        public void katilma(PlayerJoinEvent e) {
            Player oyuncu = e.getPlayer();
            if(this.getConfig().isSet("Lobi")) {
                int x = this.getConfig().getInt("x");
                int y = this.getConfig().getInt("y");
                int z = this.getConfig().getInt("z");
                int yaw = this.getConfig().getInt("yaw");
                int pitch = this.getConfig().getInt("pitch");
                World Dunya = (World) this.getConfig().get("Dunya");
                Location lokasyon = new Location(Dunya,x,y,z,yaw,pitch);
                oyuncu.teleport(lokasyon);
            }
        }
    }
    
    Komut.java
    Code:
    package lobi;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.Plugin;
    
    public class Komut implements CommandExecutor{
    
        Plugin ana = Ana.getPlugin(Ana.class);
        @Override
        public boolean onCommand(CommandSender arg0, Command arg1, String arg2, String[] arg3) {
            Player oyuncu = (Player) arg0;
            if (arg0 instanceof Player) {
                ana.getConfig().set("Lobi","Olusturuldu");
                ana.getConfig().set("x",oyuncu.getLocation().getBlockX());
                ana.getConfig().set("y",oyuncu.getLocation().getBlockY());
                ana.getConfig().set("z",oyuncu.getLocation().getBlockZ());
                ana.getConfig().set("yaw",oyuncu.getLocation().getYaw());
                ana.getConfig().set("pitch",oyuncu.getLocation().getPitch());
                ana.getConfig().set("Dunya",oyuncu.getLocation().getWorld());
                ana.saveConfig();
            }
          
            return true;
        }
    
    }
    plugin.yml
    Code:
    name: SpawnTurkceEklentisi
    main: lobi.Ana
    version: 1.0
    api-version: 1.16
    commands:
      dogmayeriyap:
        usage: /<command>
    Code:
    org.bukkit.plugin.InvalidDescriptionException: Invalid plugin.yml
            at org.bukkit.plugin.java.JavaPluginLoader.getPluginDescription(JavaPluginLoader.java:178) ~[patched_1.16.5.jar:git-Paper-790]
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:160) ~[patched_1.16.5.jar:git-Paper-790]
            at org.bukkit.craftbukkit.v1_16_R3.CraftServer.loadPlugins(CraftServer.java:393) ~[patched_1.16.5.jar:git-Paper-790]
            at org.bukkit.craftbukkit.v1_16_R3.CraftServer.reload(CraftServer.java:963) ~[patched_1.16.5.jar:git-Paper-790]
            at org.bukkit.Bukkit.reload(Bukkit.java:726) ~[patched_1.16.5.jar:git-Paper-790]
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:54) ~[patched_1.16.5.jar:git-Paper-790]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:159) ~[patched_1.16.5.jar:git-Paper-790]
            at org.bukkit.craftbukkit.v1_16_R3.CraftServer.dispatchCommand(CraftServer.java:826) ~[patched_1.16.5.jar:git-Paper-790]
            at org.bukkit.craftbukkit.v1_16_R3.CraftServer.dispatchServerCommand(CraftServer.java:788) ~[patched_1.16.5.jar:git-Paper-790]
            at net.minecraft.server.v1_16_R3.DedicatedServer.handleCommandQueue(DedicatedServer.java:470) ~[patched_1.16.5.jar:git-Paper-790]
            at net.minecraft.server.v1_16_R3.DedicatedServer.b(DedicatedServer.java:437) ~[patched_1.16.5.jar:git-Paper-790]
            at net.minecraft.server.v1_16_R3.MinecraftServer.a(MinecraftServer.java:1347) ~[patched_1.16.5.jar:git-Paper-790]
            at net.minecraft.server.v1_16_R3.MinecraftServer.w(MinecraftServer.java:1135) ~[patched_1.16.5.jar:git-Paper-790]
            at net.minecraft.server.v1_16_R3.MinecraftServer.lambda$a$0(MinecraftServer.java:291) ~[patched_1.16.5.jar:git-Paper-790]
            at java.lang.Thread.run(Thread.java:831) [?:?]
    Caused by: java.io.FileNotFoundException: Jar does not contain plugin.yml
            ... 15 more
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jan 23, 2022
  2. Offline

    timtower Administrator Administrator Moderator

    @Konya42 Caused by: java.io.FileNotFoundException: Jar does not contain plugin.yml

    What is in that jar?
     
  3. Offline

    Konya42

    what i exported has this in it
     
  4. Offline

    timtower Administrator Administrator Moderator

  5. Offline

    pixelrider2000

     
  6. Offline

    Smeary_Subset

    Make sure the plugin.yml is directly under your src folder, not under any packages within the src folder
     
  7. Offline

    Strahan

    You don't need to do any of this manual serialization:
    Code:
    int x = this.getConfig().getInt("x");
    int y = this.getConfig().getInt("y");
    int z = this.getConfig().getInt("z");
    int yaw = this.getConfig().getInt("yaw");
    int pitch = this.getConfig().getInt("pitch");
    World Dunya = (World) this.getConfig().get("Dunya");
    Location lokasyon = new Location(Dunya,x,y,z,yaw,pitch);
    Location implements ConfigurationSerializable, so all you needs must do is:
    Code:
    Location lokasyon = getConfig().getLocation("whatever.path");
    if (lokasyon == null) return;
    
    oyuncu.teleport(lokasyon);
    Obviously, one needs to save a Location as well. Even if you wanted to continue to manually serialize, you should never do:
    Code:
    World Dunya = (World) this.getConfig().get("Dunya");
    Location lokasyon = new Location(Dunya,x,y,z,yaw,pitch);
    First, unlike Location World does not implement ConfigurationSerializable, so when you try to write it out it'll either crash or will not write what you expect. You need to save the name of the world. Second, even assuming it would let you write the world, you should never blind cast. You need to check if it IS a World before casting (but it cannot be, just to be clear). If you had saved the name of the world, you'd getWorld() using that name but you also must null check after using getWorld() before using it to ensure it retrieved it correctly.

    Also, it should be World dunya not World Dunya to follow Java conventions and the use of "this" is superfluous; this is used when you have a conflict and you need to be refer specifically to the instance. That's not the case here, so all of those "this" usages are unnecessary.

    PS I just noticed you also do:
    Code:
    Player oyuncu = (Player) arg0;
    if (arg0 instanceof Player) {
    It's good you know to do the instanceof check, but the whole point of that is to ensure arg0 IS a Player before casting it thus. You are checking it after, so it would still crash if arg0 isn't a player.

    ...and those var names suck, lol. Make proper names. It won't break anything, but it comes back to Java conventions and writing non-crappy code.
     
Thread Status:
Not open for further replies.

Share This Page