mirror of
https://github.com/plexusorg/Module-HTTPD.git
synced 2024-11-24 12:45:00 +00:00
Add UI to punishments page
This commit is contained in:
parent
52a4264192
commit
a229e8f470
@ -35,6 +35,7 @@ public class HTTPDModule extends PlexModule
|
||||
@Override
|
||||
public void load()
|
||||
{
|
||||
//moduleConfig = new ModuleConfig(this, this.getClass().getClassLoader().getResource("settings.yml").getFile());
|
||||
moduleConfig = new ModuleConfig(this, "settings.yml");
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,9 @@ import dev.plex.request.GetMapping;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.adapter.LocalDateTimeSerializer;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
@ -29,16 +32,62 @@ public class PunishmentsEndpoint extends AbstractServlet
|
||||
}
|
||||
if (request.getPathInfo() == null)
|
||||
{
|
||||
return "Please specify the UUID of the player you would like to check.\nExample: /api/punishments/<uuid>";
|
||||
}
|
||||
/*StringBuilder contentBuilder = new StringBuilder();
|
||||
PlexLog.log(this.getClass().getClassLoader().getResource("punishments.html").getPath());
|
||||
try
|
||||
{
|
||||
UUID uuid = UUID.fromString(request.getPathInfo().replace("/", ""));
|
||||
final PlexPlayer punishedPlayer = DataUtils.getPlayer(uuid);
|
||||
BufferedReader in = new BufferedReader(new FileReader(this.getClass().getClassLoader().getResource("punishments.html").getFile().replace("!", "")));
|
||||
String str;
|
||||
while ((str = in.readLine()) != null)
|
||||
{
|
||||
contentBuilder.append(str);
|
||||
}
|
||||
in.close();
|
||||
}
|
||||
catch (IOException ignored)
|
||||
{
|
||||
}
|
||||
return contentBuilder.toString();*/
|
||||
return """
|
||||
<!DOCTYPE html>
|
||||
<body>
|
||||
<div style="text-align: center;">
|
||||
<h2 style="font-family:Helvetica">Enter the UUID or username of the player you want to check</h2>
|
||||
<input id="test" type="text" autofocus>
|
||||
<button type="button" onclick="redirect()">Submit</button>
|
||||
|
||||
<script>
|
||||
function redirect() {
|
||||
var url = document.getElementById('test').value
|
||||
window.location = "punishments/" + url
|
||||
}
|
||||
</script>
|
||||
</div>
|
||||
</body>
|
||||
</html>""";
|
||||
}
|
||||
UUID pathUUID;
|
||||
String pathPlexPlayer;
|
||||
PlexPlayer punishedPlayer;
|
||||
try
|
||||
{
|
||||
pathUUID = UUID.fromString(request.getPathInfo().replace("/", ""));
|
||||
punishedPlayer = DataUtils.getPlayer(pathUUID);
|
||||
}
|
||||
catch (java.lang.IllegalArgumentException ignored)
|
||||
{
|
||||
pathPlexPlayer = request.getPathInfo().replace("/", "");
|
||||
punishedPlayer = DataUtils.getPlayer(pathPlexPlayer);
|
||||
}
|
||||
|
||||
final PlexPlayer player = DataUtils.getPlayerByIP(ipAddress);
|
||||
if (punishedPlayer == null)
|
||||
{
|
||||
return "This player has never joined the server before.";
|
||||
}
|
||||
if (punishedPlayer.getPunishments().isEmpty())
|
||||
{
|
||||
return "This player has been a good boy. They have no punishments! Or they've never been on the server before. Take your pick.";
|
||||
return "This player has been a good boy. They have no punishments!";
|
||||
}
|
||||
if (player == null)
|
||||
{
|
||||
@ -66,9 +115,4 @@ public class PunishmentsEndpoint extends AbstractServlet
|
||||
}
|
||||
return new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer()).setPrettyPrinting().create().toJson(punishedPlayer.getPunishments().stream().toList());
|
||||
}
|
||||
catch (java.lang.IllegalArgumentException ignored)
|
||||
{
|
||||
return "Invalid UUID";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
16
src/main/resources/punishments.html
Normal file
16
src/main/resources/punishments.html
Normal file
@ -0,0 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<body>
|
||||
<div style="text-align: center;">
|
||||
<h2 style="font-family:Helvetica">Enter the UUID or username of the player you want to check</h2>
|
||||
<input id="test" type="text" autofocus>
|
||||
<button type="button" onclick="redirect()">Submit</button>
|
||||
|
||||
<script>
|
||||
function redirect() {
|
||||
var url = document.getElementById('test').value
|
||||
window.location = "punishments/" + url
|
||||
}
|
||||
</script>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user