Allow the URL to be configured via plugins/Caminus/config.yml
This commit is contained in:
parent
07278e50d7
commit
52fa187d91
@ -22,16 +22,24 @@ import java.io.InputStreamReader;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerListener;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
|
||||
public class JoinListener extends PlayerListener {
|
||||
Logger log = Logger.getLogger("Caminus.Join");
|
||||
private String m_url;
|
||||
|
||||
public JoinListener() {
|
||||
}
|
||||
|
||||
public void setURL(String url) {
|
||||
m_url = url;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException, MalformedURLException {
|
||||
JoinListener listener = new JoinListener();
|
||||
if (listener.isUserAuthed(args[0]))
|
||||
@ -53,14 +61,12 @@ public class JoinListener extends PlayerListener {
|
||||
}
|
||||
|
||||
public boolean isUserAuthed(String user) throws IOException, MalformedURLException {
|
||||
URL authServer = new URL("http://dev.camin.us/api/validate/"+user);
|
||||
URLConnection conn = authServer.openConnection();
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
boolean ret;
|
||||
if (in.readLine().equals("false"))
|
||||
ret = false;
|
||||
ret = true;
|
||||
in.close();
|
||||
return ret;
|
||||
URL authServer = new URL(m_url+user);
|
||||
log.info("Authing "+user+" against "+authServer);
|
||||
HttpURLConnection conn = (HttpURLConnection)authServer.openConnection();
|
||||
int code = conn.getResponseCode();
|
||||
if (code >= 200 && code <= 300)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ package us.camin;
|
||||
along with Caminus. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
@ -28,6 +28,7 @@ import java.util.logging.Logger;
|
||||
public class Plugin extends JavaPlugin {
|
||||
|
||||
Logger log = Logger.getLogger("Caminus");//Define your logger
|
||||
private JoinListener m_listener;
|
||||
|
||||
public void onDisable() {
|
||||
log.info("[Caminus] Plugin disabled");
|
||||
@ -37,6 +38,11 @@ public class Plugin extends JavaPlugin {
|
||||
log.info("[Caminus] Plugin enabled");
|
||||
|
||||
PluginManager pm = this.getServer().getPluginManager();
|
||||
pm.registerEvent(Event.Type.PLAYER_LOGIN, new JoinListener(), Event.Priority.Normal, this);
|
||||
m_listener = new JoinListener();
|
||||
Configuration conf = getConfig();
|
||||
conf.addDefault("url", "http://camin.us/api/validate/");
|
||||
String url = conf.getString("url");
|
||||
m_listener.setURL(url);
|
||||
pm.registerEvent(Event.Type.PLAYER_LOGIN, m_listener, Event.Priority.Normal, this);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user