Bukkit Plugin Interface between PHP and Bukkit

Discussion in 'Plugin Development' started by DJ We$t, Jan 25, 2012.

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

    DJ We$t

    Hey Guys,

    I`m new to Plugin Development for Bukkit and I`m not the best in Java but I`m tryin`to write a plugin for our Minecraft Server runnin` Bukkit.
    My plugin should be an interface between our website and bukkit itself.
    So far so good I started writin` and testin`but there are so things I don`t understand.
    My plugin starts a socket and with that socket I read on streams and write on streams.
    Writing into the bukkit console via stream is no problem but reading is.

    Maybe you could help me catch the problem here is my code so far:

    The Server class
    Code:
    /*
    * The Server Class
    * handles Sockets
    */
    package gfm.ll.bcom;
     
    import java.io.IOException;
    import java.net.ServerSocket;
    import java.net.Socket;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import org.bukkit.Server;
     
    /**
    *
    * @author LL
    */
    public class BukkitCommandServer extends Thread {
     
    boolean socket_active;
    Server bukkit;
    String port;
    BukkitCommandResponder response;
    BukkitCommandInterpreter interprete;
     
     
    BukkitCommandServer(Server server, String port) {
    this.bukkit = server;
    this.port = port;
    }
     
    @Override
    public void run() {
    socket_active = true;
     
    try {
    ServerSocket server = new ServerSocket(Integer.parseInt(port));
    System.out.println("BCOM: Socket activated on port: "+port);
    while(true) {
    Socket socket = server.accept();
    //response = new BukkitCommandResponder(socket);
    interprete = new BukkitCommandInterpreter(socket);
    }
    } catch (IOException ex) {
    Logger.getLogger(BukkitCommandServer.class.getName()).log(Level.SEVERE, null, ex);
    }
    }
    }
    
    Writing on the stream and receiving it in php
    Code:
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package gfm.ll.bcom;
     
    import java.io.BufferedWriter;
    import java.io.IOException;
    import java.i:confused:utputStreamWriter;
    import java.net.Socket;
    import java.util.logging.Level;
    import java.util.logging.Logger;
     
    /**
    *
    * @author LL
    */
    public class BukkitCommandResponder {
     
    public BukkitCommandResponder(Socket socket) {
     
    BufferedWriter output = null;
     
    try {
    output = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
    output.write("Hello World!");
    output.close();
    } catch (IOException ex) {
    Logger.getLogger(BukkitCommandInterpreter.class.getName()).log(Level.SEVERE, null, ex);
    }
    }
    }
    
    The Class for reading on stream
    Code:
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package gfm.ll.bcom;
     
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.Socket;
    import java.util.logging.Level;
    import java.util.logging.Logger;
     
    /**
    *
    * @author LL
    */
    public class BukkitCommandInterpreter {
     
    BukkitCommandInterpreter(Socket socket) {
    BufferedReader input = null;
    try {
    input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
     
    StringBuilder interprete = new StringBuilder();
    String line = null;
     
    while ((line = input.readLine()) != null) {
    interprete.append(line);
    System.out.println("BCOM: "+interprete);
    }
    } catch (IOException ex) {
    Logger.getLogger(BukkitCommandInterpreter.class.getName()).log(Level.SEVERE, null, ex);
    }
    }
    }
     
    
    Nobody any idea ?
     
  2. Offline

    DJ We$t

    Nobody who could help me ? -.-
     
Thread Status:
Not open for further replies.

Share This Page