mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-30 10:05:59 +00:00
Use NanoHTTPD instead, more stable.
This commit is contained in:
parent
7a6cc55640
commit
dfb6df63c8
1364
src/me/StevenLawson/TotalFreedomMod/HTTPD/NanoHTTPD.java
Normal file
1364
src/me/StevenLawson/TotalFreedomMod/HTTPD/NanoHTTPD.java
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,63 @@
|
||||
package me.StevenLawson.TotalFreedomMod.HTTPD;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
||||
|
||||
public class TFM_HTTPDManager
|
||||
{
|
||||
public static final int PORT = 28966;
|
||||
//
|
||||
private final TFM_HTTPD httpd = new TFM_HTTPD(PORT);
|
||||
|
||||
private TFM_HTTPDManager()
|
||||
{
|
||||
}
|
||||
|
||||
public void start()
|
||||
{
|
||||
try
|
||||
{
|
||||
httpd.start();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
TFM_Log.severe(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void stop()
|
||||
{
|
||||
httpd.stop();
|
||||
}
|
||||
|
||||
private static class TFM_HTTPD extends NanoHTTPD
|
||||
{
|
||||
public TFM_HTTPD(int port)
|
||||
{
|
||||
super(port);
|
||||
}
|
||||
|
||||
public TFM_HTTPD(String hostname, int port)
|
||||
{
|
||||
super(hostname, port);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response serve(String uri, Method method, Map<String, String> headers, Map<String, String> parms, Map<String, String> files)
|
||||
{
|
||||
return new Response("<p>OK - " + new Date().toString() + "</p>");
|
||||
}
|
||||
}
|
||||
|
||||
public static TFM_HTTPDManager getInstance()
|
||||
{
|
||||
return TFM_HTTPDManagerHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class TFM_HTTPDManagerHolder
|
||||
{
|
||||
private static final TFM_HTTPDManager INSTANCE = new TFM_HTTPDManager();
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import me.StevenLawson.TotalFreedomMod.Commands.TFM_Command;
|
||||
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader;
|
||||
import me.StevenLawson.TotalFreedomMod.HTTPD.TFM_HTTPDManager;
|
||||
import me.StevenLawson.TotalFreedomMod.Listener.*;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
||||
@ -172,6 +173,8 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
}
|
||||
}.runTaskLater(plugin, 20L);
|
||||
|
||||
TFM_HTTPDManager.getInstance().start();
|
||||
|
||||
TFM_Log.info("Plugin enabled.");
|
||||
}
|
||||
|
||||
@ -180,6 +183,8 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
{
|
||||
server.getScheduler().cancelTasks(plugin);
|
||||
|
||||
TFM_HTTPDManager.getInstance().stop();
|
||||
|
||||
TFM_Log.info("Plugin disabled.");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user