Solved Could not pass event PlayerQuitEvent to...

Discussion in 'Plugin Development' started by ShadX, Dec 7, 2018.

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

    ShadX

    Because the CustomNPCs mod isn't an opensource project I've tried to make a plugin which transfers playerdata(active quests, companions, faction points, etc) from localhost(first server) to second server making it smth like multi-server. When player moves to another server he will se all his quests from another server. Same plugin with another settings placed on second server.

    For transfer operations via SFTP I used JSch library: API
    Example was taken from here: SOverflow

    Craftbukkit core: 1.7.10-R0.1

    My coding experience is ~1month, so... The error is explained in thread title :\
    At least I tried... xD

    Server Console:
    Code:
    > [23:08:42 ERROR]: Could not pass event PlayerQuitEvent to QuestSync v0.0.1
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:338) ~[JavaPluginLoader$1.class:1.7.10-1614.58]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[RegisteredListener.class:1.7.10-1614.58]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:507) [SimplePluginManager.class:1.7.10-1614.58]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:492) [SimplePluginManager.class:1.7.10-1614.58]
    at net.minecraft.server.management.ServerConfigurationManager.disconnect(ServerConfigurationManager.java:441) [oi.class:?]
    at net.minecraft.network.NetHandlerPlayServer.func_147231_a(NetHandlerPlayServer.java:953) [nh.class:?]
    at net.minecraft.network.NetworkSystem.func_151269_c(NetworkSystem.java:174) [nc.class:?]
    at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:1023) [MinecraftServer.class:?]
    at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:432) [lt.class:?]
    at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:841) [MinecraftServer.class:?]
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:693) [MinecraftServer.class:?]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_181]
    Caused by: java.lang.NoClassDefFoundError: com/jcraft/jsch/JSchException
    at shadx.main.CommandHandler.onQuit(CommandHandler.java:30) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_181]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_181]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_181]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_181]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:334) ~[JavaPluginLoader$1.class:1.7.10-1614.58]
    ... 11 more

    CommandHandler.java:
    Code:
    package shadx.main;
    
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    
    public class CommandHandler implements Listener {
    
        private static String playerUUID = "";
      
        private QuestSync qs;
    
        public CommandHandler(QuestSync main) {
            this.qs = main;
        }
    
        @EventHandler
        public void onJoin(PlayerJoinEvent e){
    //Is empty rn
        }
    
        @EventHandler
        public void onQuit(PlayerQuitEvent e){
            Player p = e.getPlayer();
            playerUUID = p.getUniqueId().toString();
            qs.log.info("PLAYER FOUND: " + playerUUID); //Just for note
            SFTP.upload();
        }
    
        public static String getUUID() {
            return playerUUID;
        }
      
        public static String getPath() {
            return ("/world/customnpcs/playerdata/" + playerUUID + ".json");
        }
      
    }
    
    SFTP.java:
    Code:
    package shadx.main;
    
    import com.jcraft.jsch.*;
    
    
    public class SFTP {
      
    //host, user and password data filled with my hidden credentials :p
    
        private final static String HOST  = "##";
        private final static int PORT = 2022;
    
        public final static String USER = "##";
        private final static String SECONDPASS = "##";
    
        public static void upload(){
            Session session = null;
            Channel channel = null;
            try {
                JSch ssh = new JSch();
                //ssh.setKnownHosts();
                session = ssh.getSession(USER, HOST, PORT);
                session.setPassword(PASS);
                session.connect();
                channel = session.openChannel("sftp");
                channel.connect();
                ChannelSftp sftp = (ChannelSftp) channel;
                sftp.put(CommandHandler.getPath(), CommandHandler.getPath());
            } catch (JSchException e) {
                e.printStackTrace();
            } catch (SftpException e) {
                e.printStackTrace();
            } finally {
                if (channel != null) {
                    channel.disconnect();
                }
                if (session != null) {
                    session.disconnect();
                }
            }
        }
    }
     
    Last edited: Dec 7, 2018
  2. Offline

    Zombie_Striker

    This error is stating that it could not find the class "com.jcraft.jsch.JSchException". Make sure you have the correct imports and that the server running this code has access to that API.
     
    ShadX likes this.
  3. Offline

    ShadX

    Ahh.. Srry, I forgot that I added JSch as external lib :oops:

    Not fixed. :c

    I've tried to configure Java Build Path adding jcsh.jar from /lib/jsch.jar
    http://prntscr.com/lsc641

    The .classpath has <classpathentry kind="lib" path="lib/jsch-0.1.55.jar"/> but it's still not working.
    Server are still pointing that it couldn't find "com.jcraft.jsch.JSchException"

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited: Dec 8, 2018
  4. @ShadX

    Could you post the .jar file of your plug-in? I can open it up and see whether or not the missing class is actually there.
     
    ShadX likes this.
  5. Offline

    ShadX

    Fixed it 5 mins ago. Thank y'all guys!
    I just moved JSch lib to server root/plugins/libs/Jsch-0.1.55.jar

    And changed manifest Class-path to:
    Class-Path: libs/jsch-0.1.55.jar
     
    Last edited: Dec 9, 2018
Thread Status:
Not open for further replies.

Share This Page