2022-04-02 20:51:14 +00:00
|
|
|
package dev.plex.request.impl;
|
|
|
|
|
|
|
|
import com.google.gson.GsonBuilder;
|
|
|
|
import dev.plex.HTTPDModule;
|
|
|
|
import dev.plex.Plex;
|
|
|
|
import dev.plex.cache.DataUtils;
|
|
|
|
import dev.plex.player.PlexPlayer;
|
|
|
|
import dev.plex.rank.enums.Rank;
|
|
|
|
import dev.plex.request.AbstractServlet;
|
|
|
|
import dev.plex.request.GetMapping;
|
|
|
|
import dev.plex.util.PlexLog;
|
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
2022-04-17 23:21:44 +00:00
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
2022-04-02 20:51:14 +00:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.OfflinePlayer;
|
|
|
|
|
|
|
|
public class IndefBansEndpoint extends AbstractServlet
|
|
|
|
{
|
2022-04-15 18:55:40 +00:00
|
|
|
private static final String TITLE = "Indefinite Bans - Plex HTTPD";
|
|
|
|
|
2022-04-02 20:51:14 +00:00
|
|
|
@GetMapping(endpoint = "/api/indefbans/")
|
2022-04-17 23:21:44 +00:00
|
|
|
public String getBans(HttpServletRequest request, HttpServletResponse response)
|
2022-04-02 20:51:14 +00:00
|
|
|
{
|
2022-04-02 21:50:15 +00:00
|
|
|
String ipAddress = request.getRemoteAddr();
|
2022-04-02 20:51:14 +00:00
|
|
|
if (ipAddress == null)
|
|
|
|
{
|
2022-04-17 21:39:08 +00:00
|
|
|
return indefbansHTML("An IP address could not be detected. Please ensure you are connecting using IPv4.");
|
2022-04-02 20:51:14 +00:00
|
|
|
}
|
|
|
|
final PlexPlayer player = DataUtils.getPlayerByIP(ipAddress);
|
|
|
|
if (player == null)
|
|
|
|
{
|
2022-04-17 21:39:08 +00:00
|
|
|
return indefbansHTML("Couldn't load your IP Address: " + ipAddress + ". Have you joined the server before?");
|
2022-04-02 20:51:14 +00:00
|
|
|
}
|
|
|
|
if (Plex.get().getSystem().equalsIgnoreCase("ranks"))
|
|
|
|
{
|
|
|
|
PlexLog.debug("Plex-HTTPD using ranks check");
|
|
|
|
if (!player.getRankFromString().isAtLeast(Rank.ADMIN))
|
|
|
|
{
|
2022-04-17 21:39:08 +00:00
|
|
|
return indefbansHTML("Not a high enough rank to view this page.");
|
2022-04-02 20:51:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (Plex.get().getSystem().equalsIgnoreCase("permissions"))
|
|
|
|
{
|
|
|
|
PlexLog.debug("Plex-HTTPD using permissions check");
|
2022-04-09 03:20:14 +00:00
|
|
|
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(player.getUuid());
|
2022-04-02 20:51:14 +00:00
|
|
|
if (!HTTPDModule.getPermissions().playerHas(null, offlinePlayer, "plex.httpd.indefbans.access"))
|
|
|
|
{
|
2022-04-17 21:39:08 +00:00
|
|
|
return indefbansHTML("Not enough permissions to view this page.");
|
2022-04-02 20:51:14 +00:00
|
|
|
}
|
|
|
|
}
|
2022-05-30 02:55:03 +00:00
|
|
|
|
|
|
|
response.setHeader("content-type", "application/json");
|
2022-04-17 21:39:08 +00:00
|
|
|
return new GsonBuilder().setPrettyPrinting().create().toJson(Plex.get().getPunishmentManager().getIndefiniteBans().stream().toList());
|
|
|
|
}
|
|
|
|
|
|
|
|
private String indefbansHTML(String message)
|
|
|
|
{
|
|
|
|
String file = readFile(this.getClass().getResourceAsStream("/httpd/indefbans.html"));
|
|
|
|
file = file.replace("${MESSAGE}", message);
|
|
|
|
return file;
|
2022-04-02 20:51:14 +00:00
|
|
|
}
|
|
|
|
}
|