mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-07-02 12:56:40 +00:00
Removal of Lombok
Lombok implementation removal. I have also gone through and replaced things with inline methods and variables, lambdas, and simplified loops down, removed unnecessary guard clauses, and overall cleaned up every single class. This took a long time, please do remember to follow proper naming conventions, don't include unnecessary guard clauses, follow exception rules and comment rules, and please PLEASE remember to use the DIAMOND OPERATOR rather than just inferring RAW TYPES!!! Thank you!!
This commit is contained in:
@ -12,6 +12,7 @@ import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.Response;
|
||||
import me.totalfreedom.totalfreedommod.httpd.module.HTTPDModule;
|
||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_activitylog;
|
||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_admins;
|
||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_bans;
|
||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_file;
|
||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_help;
|
||||
@ -23,7 +24,6 @@ import me.totalfreedom.totalfreedommod.httpd.module.Module_logs;
|
||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_players;
|
||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_punishments;
|
||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_schematic;
|
||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_admins;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
@ -32,12 +32,50 @@ import org.apache.commons.lang.exception.ExceptionUtils;
|
||||
public class HTTPDaemon extends FreedomService
|
||||
{
|
||||
|
||||
private static final Pattern EXT_REGEX = Pattern.compile("\\.([^.\\s]+)$");
|
||||
public static String MIME_DEFAULT_BINARY = "application/octet-stream";
|
||||
private static final Pattern EXT_REGEX = Pattern.compile("\\.([^\\.\\s]+)$");
|
||||
//
|
||||
public int port;
|
||||
private HTTPD httpd;
|
||||
public Map<String, ModuleExecutable> modules = new HashMap<>();
|
||||
private HTTPD httpd;
|
||||
|
||||
public static Response serveFileBasic(File file)
|
||||
{
|
||||
Response response = null;
|
||||
|
||||
if (file != null && file.exists())
|
||||
{
|
||||
try
|
||||
{
|
||||
String mimetype = null;
|
||||
|
||||
Matcher matcher = EXT_REGEX.matcher(file.getCanonicalPath());
|
||||
if (matcher.find())
|
||||
{
|
||||
mimetype = Module_file.MIME_TYPES.get(matcher.group(1));
|
||||
}
|
||||
|
||||
if (mimetype == null || mimetype.trim().isEmpty())
|
||||
{
|
||||
mimetype = MIME_DEFAULT_BINARY;
|
||||
}
|
||||
|
||||
// Some browsers like firefox download the file for text/yaml mime types
|
||||
if (FilenameUtils.getExtension(file.getName()).equals("yml"))
|
||||
{
|
||||
mimetype = NanoHTTPD.MIME_PLAINTEXT;
|
||||
}
|
||||
|
||||
response = new Response(Response.Status.OK, mimetype, new FileInputStream(file));
|
||||
response.addHeader("Content-Length", "" + file.length());
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
@ -141,42 +179,4 @@ public class HTTPDaemon extends FreedomService
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Response serveFileBasic(File file)
|
||||
{
|
||||
Response response = null;
|
||||
|
||||
if (file != null && file.exists())
|
||||
{
|
||||
try
|
||||
{
|
||||
String mimetype = null;
|
||||
|
||||
Matcher matcher = EXT_REGEX.matcher(file.getCanonicalPath());
|
||||
if (matcher.find())
|
||||
{
|
||||
mimetype = Module_file.MIME_TYPES.get(matcher.group(1));
|
||||
}
|
||||
|
||||
if (mimetype == null || mimetype.trim().isEmpty())
|
||||
{
|
||||
mimetype = MIME_DEFAULT_BINARY;
|
||||
}
|
||||
|
||||
// Some browsers like firefox download the file for text/yaml mime types
|
||||
if (FilenameUtils.getExtension(file.getName()).equals("yml"))
|
||||
{
|
||||
mimetype = NanoHTTPD.MIME_PLAINTEXT;
|
||||
}
|
||||
|
||||
response = new Response(Response.Status.OK, mimetype, new FileInputStream(file));
|
||||
response.addHeader("Content-Length", "" + file.length());
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user