mirror of
https://github.com/plexusorg/Module-HTTPD.git
synced 2026-06-05 17:46:53 +00:00
work in progress
This commit is contained in:
@@ -22,13 +22,15 @@ import org.bukkit.OfflinePlayer;
|
||||
|
||||
public class PunishmentsEndpoint extends AbstractServlet
|
||||
{
|
||||
private static final String TITLE = "Punishments - Plex HTTPD";
|
||||
|
||||
@GetMapping(endpoint = "/api/punishments/")
|
||||
public String getPunishments(HttpServletRequest request)
|
||||
{
|
||||
String ipAddress = request.getRemoteAddr();
|
||||
if (ipAddress == null)
|
||||
{
|
||||
return "An IP address could not be detected. Please ensure you are connecting using IPv4.";
|
||||
return createBasicHTML(TITLE, "An IP address could not be detected. Please ensure you are connecting using IPv4.");
|
||||
}
|
||||
if (request.getPathInfo() == null)
|
||||
{
|
||||
@@ -65,16 +67,16 @@ public class PunishmentsEndpoint extends AbstractServlet
|
||||
final PlexPlayer player = DataUtils.getPlayerByIP(ipAddress);
|
||||
if (punishedPlayer == null)
|
||||
{
|
||||
return "This player has never joined the server before.";
|
||||
return createBasicHTML(TITLE, "This player has never joined the server before.");
|
||||
}
|
||||
if (punishedPlayer.getPunishments().isEmpty())
|
||||
{
|
||||
return "This player has been a good boy. They have no punishments!";
|
||||
return createBasicHTML(TITLE, "This player has been a good boy. They have no punishments!");
|
||||
}
|
||||
if (player == null)
|
||||
{
|
||||
// If the player is null, give it to them without the IPs
|
||||
return new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer()).setPrettyPrinting().create().toJson(punishedPlayer.getPunishments().stream().peek(punishment -> punishment.setIp("")).toList());
|
||||
return createJSONHTML(TITLE, new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer()).setPrettyPrinting().create().toJson(punishedPlayer.getPunishments().stream().peek(punishment -> punishment.setIp("")).toList()));
|
||||
}
|
||||
if (Plex.get().getSystem().equalsIgnoreCase("ranks"))
|
||||
{
|
||||
@@ -82,7 +84,7 @@ public class PunishmentsEndpoint extends AbstractServlet
|
||||
if (!player.getRankFromString().isAtLeast(Rank.ADMIN))
|
||||
{
|
||||
// Don't return IPs either if the person is not an Admin or above.
|
||||
return new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer()).setPrettyPrinting().create().toJson(punishedPlayer.getPunishments().stream().peek(punishment -> punishment.setIp("")).toList());
|
||||
return createJSONHTML(TITLE, new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer()).setPrettyPrinting().create().toJson(punishedPlayer.getPunishments().stream().peek(punishment -> punishment.setIp("")).toList()));
|
||||
}
|
||||
}
|
||||
else if (Plex.get().getSystem().equalsIgnoreCase("permissions"))
|
||||
@@ -92,9 +94,9 @@ public class PunishmentsEndpoint extends AbstractServlet
|
||||
if (!HTTPDModule.getPermissions().playerHas(null, offlinePlayer, "plex.httpd.punishments.access"))
|
||||
{
|
||||
// If the person doesn't have permission, don't return IPs
|
||||
return new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer()).setPrettyPrinting().create().toJson(punishedPlayer.getPunishments().stream().peek(punishment -> punishment.setIp("")).toList());
|
||||
return createJSONHTML(TITLE, new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer()).setPrettyPrinting().create().toJson(punishedPlayer.getPunishments().stream().peek(punishment -> punishment.setIp("")).toList()));
|
||||
}
|
||||
}
|
||||
return new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer()).setPrettyPrinting().create().toJson(punishedPlayer.getPunishments().stream().toList());
|
||||
return createJSONHTML(TITLE, new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer()).setPrettyPrinting().create().toJson(punishedPlayer.getPunishments().stream().toList()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user