No idea what the error is

Discussion in 'Plugin Development' started by vortex25565, Mar 17, 2014.

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

    vortex25565

    Hello! I am trying to code a plugin that Instantly respawns a player (the respawn screen doesn't show up)

    Heres my code:

    Code:java
    1. package me.vortex.instantrespawn;
    2.  
    3. import java.lang.reflect.Field;
    4. import java.lang.reflect.Method;
    5.  
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.entity.PlayerDeathEvent;
    10. import org.bukkit.plugin.Plugin;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12. import org.bukkit.scheduler.BukkitRunnable;
    13.  
    14. public class main extends JavaPlugin implements Listener {
    15.  
    16. @Override
    17. public void onDisable (){
    18.  
    19. }
    20.  
    21. @Override
    22. public void onEnable (){
    23.  
    24. }
    25.  
    26. private final Plugin plugin;
    27.  
    28. public main( Plugin plugin )
    29. {
    30. this.plugin = plugin;
    31. Bukkit.getPluginManager().registerEvents(this , plugin);
    32. }
    33.  
    34. @EventHandler
    35. public void onPlayerDeath(final PlayerDeathEvent e)
    36. {
    37. new BukkitRunnable()
    38. {
    39. public void run()
    40. {
    41. try
    42. {
    43. Object nmsPlayer = e.getEntity().getClass().getMethod("getHandle").invoke(e.getEntity());
    44. Object con = nmsPlayer.getClass().getDeclaredField("playerConnection").get(nmsPlayer);
    45.  
    46. Class< ? > EntityPlayer = Class.forName(nmsPlayer.getClass().getPackage().getName() + ".EntityPlayer");
    47.  
    48. Field minecraftServer = con.getClass().getDeclaredField("minecraftServer");
    49. minecraftServer.setAccessible(true);
    50. Object mcserver = minecraftServer.get(con);
    51.  
    52. Object playerlist = mcserver.getClass().getDeclaredMethod("getPlayerList").invoke(mcserver);
    53. Method moveToWorld = playerlist.getClass().getMethod("moveToWorld" , EntityPlayer , int.class , boolean.class);
    54. moveToWorld.invoke(playerlist , nmsPlayer , 0 , false);
    55. }
    56. catch (Exception ex)
    57. {
    58. ex.printStackTrace();
    59. }
    60. }
    61. }.runTaskLater(plugin , 2);
    62.  
    63. }
    64. }



    And my plugin.yml

    name: InstantRespawn
    version: 1.0
    main: me.vortex.instantrespawn.main
    description: A plugin that instantly respawns you!

    Can someone please tell me what I am doing wrong?
     
  2. Offline

    TheCodex6825

    You forgot to call main in onEnable (btw everything in main can be moved to onEnable instead of putting it in another method.) By not calling main, your event never gets registered.
     
  3. Offline

    skullboneslayer

    Where is your error coming from / can i see your plugin.yml
     
  4. Offline

    vortex25565

    The plugin.yml is already posted...
     
  5. Offline

    AoH_Ruthless

    vortex25565 skullboneslayer
    It has nothing to do with the plugin.yml

    That is your main class .. Your constructor is just getting your main class. You can replace plugin with this.

    Code:
    private final Plugin plugin;
     
        public main( Plugin plugin )
        {
            this.plugin = plugin;
            Bukkit.getPluginManager().registerEvents(this , plugin);
        }
    Remove that above code, and register the events in your onEnable.
    http://wiki.bukkit.org/Event_API_Reference
     
  6. Offline

    vortex25565

    Replaced it, and got a error


    23:09:24 [SEVERE] Could not load 'plugins\InstantRespawn.jar' in folder 'plugins
    '
    org.bukkit.plugin.InvalidPluginException: java.lang.NoSuchMethodException: me.vo
    rtex.instantrespawn.main.<init>()
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:184)
    at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.
    java:305)
    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager
    .java:230)
    at org.bukkit.craftbukkit.v1_6_R3.CraftServer.loadPlugins(CraftServer.ja
    va:241)
    at org.bukkit.craftbukkit.v1_6_R3.CraftServer.<init>(CraftServer.java:21
    9)
    at net.minecraft.server.v1_6_R3.PlayerList.<init>(PlayerList.java:56)
    at net.minecraft.server.v1_6_R3.DedicatedPlayerList.<init>(SourceFile:11
    )
    at net.minecraft.server.v1_6_R3.DedicatedServer.init(DedicatedServer.jav
    a:107)
    at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java
    :393)
    at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:5
    83)
    Caused by: java.lang.NoSuchMethodException: me.vortex.instantrespawn.main.<init>
    ()
    at java.lang.Class.getConstructor0(Unknown Source)
    at java.lang.Class.getConstructor(Unknown Source)
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:176)
    ... 9 more
     
Thread Status:
Not open for further replies.

Share This Page