mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-06-12 22:03:53 +00:00
I'm tired of seeing prs that make small code reformats so im doing a commit to fix it all at once
This commit is contained in:
@ -18,7 +18,7 @@ public class AMP extends FreedomService
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
if(!plugin.config.getBoolean(ConfigEntry.AMP_ENABLED))
|
||||
if (!plugin.config.getBoolean(ConfigEntry.AMP_ENABLED))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -41,7 +41,8 @@ public class AMP extends FreedomService
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
protected void onStop()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package me.totalfreedom.totalfreedommod.amp;
|
||||
|
||||
public enum AMPEndpoints
|
||||
{
|
||||
LOGIN("/API/Core/Login" , "{username:\"%s\", password:\"%s\", token:\"\", rememberMe:false}"),
|
||||
LOGIN("/API/Core/Login", "{username:\"%s\", password:\"%s\", token:\"\", rememberMe:false}"),
|
||||
RESTART("/API/Core/Restart", "{SESSIONID:\"%s\"}");
|
||||
|
||||
private final String text;
|
||||
@ -20,6 +20,7 @@ public enum AMPEndpoints
|
||||
{
|
||||
return text;
|
||||
}
|
||||
|
||||
public String getParameters()
|
||||
{
|
||||
return parameters;
|
||||
|
@ -22,7 +22,10 @@ public class AMPManager
|
||||
|
||||
public AMPManager(TotalFreedomMod plugin, String url, String username, String password)
|
||||
{
|
||||
this.plugin = plugin; this.url = url; this.username = username; this.password = password;
|
||||
this.plugin = plugin;
|
||||
this.url = url;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public void connectAsync(final LoginCallback callback)
|
||||
@ -38,7 +41,7 @@ public class AMPManager
|
||||
try
|
||||
{
|
||||
LoginResult resp = new Gson().fromJson(postRequestToEndpoint(apiEndpoint, body), LoginResult.class);
|
||||
if(!resp.getSuccess())
|
||||
if (!resp.getSuccess())
|
||||
{
|
||||
FLog.severe("AMP login unsuccessful. Check if login details are correct.");
|
||||
sessionID = "";
|
||||
@ -48,7 +51,7 @@ public class AMPManager
|
||||
sessionID = resp.getSessionID();
|
||||
callback.loginDone(true);
|
||||
}
|
||||
catch(IOException ex)
|
||||
catch (IOException ex)
|
||||
{
|
||||
FLog.severe("Could not login to AMP. Check if URL is correct. Stacktrace: " + ex.getMessage());
|
||||
sessionID = "";
|
||||
@ -71,7 +74,7 @@ public class AMPManager
|
||||
try
|
||||
{
|
||||
String resp = postRequestToEndpoint(apiEndpoint, body);
|
||||
if(resp.contains("Unauthorized Access"))
|
||||
if (resp.contains("Unauthorized Access"))
|
||||
{
|
||||
//try connecting one more time
|
||||
LoginCallback callback = new LoginCallback()
|
||||
@ -79,7 +82,7 @@ public class AMPManager
|
||||
@Override
|
||||
public void loginDone(boolean success)
|
||||
{
|
||||
if(!success)
|
||||
if (!success)
|
||||
{
|
||||
FLog.severe("Failed to connect to AMP. Did the panel go down? Were panel user details changed/deleted? Check for more info above. Connection was successful when plugin started, but unsuccessful now." +
|
||||
" Using server.shutdown() instead.");
|
||||
@ -89,7 +92,7 @@ public class AMPManager
|
||||
try
|
||||
{
|
||||
String response = postRequestToEndpoint(apiEndpoint, body);
|
||||
if(response.contains("Unauthorized Access"))
|
||||
if (response.contains("Unauthorized Access"))
|
||||
{
|
||||
FLog.severe("Contact a developer. Panel gives Session ID but trying to use it gives a no perms error. The panel user set in config doesn't" +
|
||||
" have perms to restart server. Using server.shutdown() instead. ");
|
||||
@ -107,7 +110,7 @@ public class AMPManager
|
||||
plugin.amp.ampManager.connectAsync(callback);
|
||||
}
|
||||
}
|
||||
catch(IOException ex)
|
||||
catch (IOException ex)
|
||||
{
|
||||
FLog.severe("Could not restart. Using server.shutdown() instead. Stacktrace: " + ex.getMessage());
|
||||
plugin.getServer().shutdown();
|
||||
@ -120,7 +123,7 @@ public class AMPManager
|
||||
private String postRequestToEndpoint(String endpoint, String body) throws IOException
|
||||
{
|
||||
URL url = new URL(endpoint);
|
||||
if(endpoint.startsWith("https://"))
|
||||
if (endpoint.startsWith("https://"))
|
||||
{
|
||||
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("POST");
|
||||
@ -157,7 +160,8 @@ public class AMPManager
|
||||
String inputLine;
|
||||
StringBuffer response = new StringBuffer();
|
||||
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
while ((inputLine = in.readLine()) != null)
|
||||
{
|
||||
response.append(inputLine);
|
||||
}
|
||||
in.close();
|
||||
|
Reference in New Issue
Block a user