Update for latest version of Plex

This commit is contained in:
Telesphoreo 2023-08-28 19:02:46 -05:00
parent 492c6bd8eb
commit 21ee54cf98
No known key found for this signature in database
GPG Key ID: 9D1991811E093C02
12 changed files with 28 additions and 179 deletions

View File

@ -5,7 +5,7 @@ plugins {
}
group = "dev.plex"
version = "1.3"
version = "1.4-SNAPSHOT"
description = "Module-HTTPD"
repositories {
@ -31,7 +31,7 @@ dependencies {
implementation("org.projectlombok:lombok:1.18.28")
annotationProcessor("org.projectlombok:lombok:1.18.28")
implementation("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")
implementation("dev.plex:server:1.3")
implementation("dev.plex:server:1.4-SNAPSHOT")
implementation("org.json:json:20230618")
implementation("org.reflections:reflections:0.10.2")
implementation("org.eclipse.jetty:jetty-server:11.0.15")

Binary file not shown.

View File

@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

5
gradlew vendored
View File

@ -130,10 +130,13 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi
# Increase the maximum file descriptors if we can.

View File

@ -5,7 +5,6 @@ import dev.plex.config.ModuleConfig;
import dev.plex.module.PlexModule;
import dev.plex.request.AbstractServlet;
import dev.plex.request.SchematicUploadServlet;
import dev.plex.request.impl.AdminsEndpoint;
import dev.plex.request.impl.IndefBansEndpoint;
import dev.plex.request.impl.IndexEndpoint;
import dev.plex.request.impl.ListEndpoint;
@ -57,7 +56,7 @@ public class HTTPDModule extends PlexModule
{
moduleConfig.load();
PlexLog.debug("HTTPD Module Port: {0}", moduleConfig.getInt("server.port"));
if ((!Bukkit.getPluginManager().isPluginEnabled("Vault") || !setupPermissions()) && getPlex().getSystem().equalsIgnoreCase("permissions"))
if ((!Bukkit.getPluginManager().isPluginEnabled("Vault") || !setupPermissions()))
{
throw new RuntimeException("Plex-HTTPD requires the 'Vault' plugin as well as a Permissions plugin that hooks into 'Vault'. We recommend LuckPerms!");
}
@ -74,7 +73,6 @@ public class HTTPDModule extends PlexModule
connector.setHost(moduleConfig.getString("server.bind-address"));
connector.setPort(moduleConfig.getInt("server.port"));
new AdminsEndpoint();
new IndefBansEndpoint();
new IndexEndpoint();
new ListEndpoint();

View File

@ -1,10 +1,8 @@
package dev.plex.request;
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.util.PlexLog;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
@ -39,17 +37,6 @@ public class SchematicUploadServlet extends HttpServlet
response.getWriter().println(schematicUploadBadHTML("Couldn't load your IP Address: " + request.getRemoteAddr() + ". Have you joined the server before?"));
return;
}
if (Plex.get().getSystem().equalsIgnoreCase("ranks"))
{
PlexLog.debug("Plex-HTTPD using ranks check");
if (!plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN))
{
response.getWriter().println(schematicUploadBadHTML("You must be an admin or above to upload schematics."));
return;
}
}
else if (Plex.get().getSystem().equalsIgnoreCase("permissions"))
{
PlexLog.debug("Plex-HTTPD using permissions check");
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(plexPlayer.getUuid());
if (!HTTPDModule.getPermissions().playerHas(null, offlinePlayer, "plex.httpd.schematics.upload"))
@ -57,7 +44,6 @@ public class SchematicUploadServlet extends HttpServlet
response.getWriter().println(schematicUploadBadHTML("You do not have permission to upload schematics."));
return;
}
}
File worldeditFolder = HTTPDModule.getWorldeditFolder();
if (worldeditFolder == null)
{

View File

@ -1,93 +0,0 @@
package dev.plex.request.impl;
import com.google.gson.Gson;
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.request.MappingHeaders;
import dev.plex.util.PlexLog;
import dev.plex.util.adapter.ZonedDateTimeAdapter;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.time.ZonedDateTime;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
public class AdminsEndpoint extends AbstractServlet
{
private static final Gson GSON =
new GsonBuilder()
.registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeAdapter())
.setPrettyPrinting()
.create();
private List<PlexPlayer> getAuthenticatedResponse(List<PlexPlayer> admins)
{
return admins
.stream().peek(plexPlayer ->
{
plexPlayer.setPunishments(null);
plexPlayer.setNotes(null);
plexPlayer.setPermissions(null);
plexPlayer.setCommandSpy(false);
plexPlayer.setVanished(false);
}).toList();
}
private List<PlexPlayer> getUnauthenticatedResponse(List<PlexPlayer> admins)
{
return getAuthenticatedResponse(admins).stream().peek(plexPlayer ->
plexPlayer.setIps(null)).toList();
}
@GetMapping(endpoint = "/api/admins/")
@MappingHeaders(headers = "content-type;application/json")
public String getAdmins(HttpServletRequest request, HttpServletResponse response)
{
String ipAddress = request.getRemoteAddr();
if (ipAddress == null)
{
return adminsHTML("An IP address could not be detected. Please ensure you are connecting using IPv4.");
}
final PlexPlayer player = DataUtils.getPlayerByIP(ipAddress);
final List<PlexPlayer> admins = Plex.get().getAdminList().getAllAdminPlayers();
if (player == null)
{
// This likely means they've never joined the server before. That's okay. We can just not return IPs.
return GSON.toJson(getUnauthenticatedResponse(admins));
}
if (Plex.get().getSystem().equalsIgnoreCase("ranks"))
{
PlexLog.debug("Plex-HTTPD using ranks check");
if (!player.getRankFromString().isAtLeast(Rank.ADMIN))
{
// Don't return IPs either if the person is not an Admin or above.
return GSON.toJson(getUnauthenticatedResponse(admins));
}
}
else if (Plex.get().getSystem().equalsIgnoreCase("permissions"))
{
PlexLog.debug("Plex-HTTPD using permissions check");
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(player.getUuid());
if (!HTTPDModule.getPermissions().playerHas(null, offlinePlayer, "plex.httpd.admins.access"))
{
// If the person doesn't have permission, don't return IPs
return GSON.toJson(getUnauthenticatedResponse(admins));
}
}
return GSON.toJson(getAuthenticatedResponse(admins));
}
private String adminsHTML(String message)
{
String file = readFile(this.getClass().getResourceAsStream("/httpd/admins.html"));
file = file.replace("${MESSAGE}", message);
return file;
}
}

View File

@ -5,7 +5,6 @@ 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;
@ -31,23 +30,12 @@ public class IndefBansEndpoint extends AbstractServlet
{
return indefbansHTML("Couldn't load your IP Address: " + ipAddress + ". Have you joined the server before?");
}
if (Plex.get().getSystem().equalsIgnoreCase("ranks"))
{
PlexLog.debug("Plex-HTTPD using ranks check");
if (!player.getRankFromString().isAtLeast(Rank.ADMIN))
{
return indefbansHTML("Not a high enough rank to view this page.");
}
}
else if (Plex.get().getSystem().equalsIgnoreCase("permissions"))
{
PlexLog.debug("Plex-HTTPD using permissions check");
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(player.getUuid());
if (!HTTPDModule.getPermissions().playerHas(null, offlinePlayer, "plex.httpd.indefbans.access"))
{
return indefbansHTML("Not enough permissions to view this page.");
}
}
response.setHeader("content-type", "application/json");
return new GsonBuilder().setPrettyPrinting().create().toJson(Plex.get().getPunishmentManager().getIndefiniteBans().stream().toList());

View File

@ -2,19 +2,15 @@ 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 dev.plex.util.adapter.ZonedDateTimeAdapter;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.time.ZonedDateTime;
import java.util.UUID;
import jakarta.servlet.http.HttpServletResponse;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
@ -60,25 +56,12 @@ public class PunishmentsEndpoint extends AbstractServlet
// If the player is null, give it to them without the IPs
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeAdapter()).setPrettyPrinting().create().toJson(punishedPlayer.getPunishments().stream().peek(punishment -> punishment.setIp("")).toList());
}
if (Plex.get().getSystem().equalsIgnoreCase("ranks"))
{
PlexLog.debug("Plex-HTTPD using ranks check");
if (!player.getRankFromString().isAtLeast(Rank.ADMIN))
{
// Don't return IPs either if the person is not an Admin or above.
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeAdapter()).setPrettyPrinting().create().toJson(punishedPlayer.getPunishments().stream().peek(punishment -> punishment.setIp("")).toList());
}
}
else if (Plex.get().getSystem().equalsIgnoreCase("permissions"))
{
PlexLog.debug("Plex-HTTPD using permissions check");
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(player.getUuid());
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(ZonedDateTime.class, new ZonedDateTimeAdapter()).setPrettyPrinting().create().toJson(punishedPlayer.getPunishments().stream().peek(punishment -> punishment.setIp("")).toList());
}
}
response.setHeader("content-type", "application/json");
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeAdapter()).setPrettyPrinting().create().toJson(punishedPlayer.getPunishments().stream().toList());

View File

@ -1,10 +1,8 @@
package dev.plex.request.impl;
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;
@ -28,23 +26,12 @@ public class SchematicUploadEndpoint extends AbstractServlet
{
return schematicsHTML("Couldn't load your IP Address: " + ipAddress + ". Have you joined the server before?");
}
if (Plex.get().getSystem().equalsIgnoreCase("ranks"))
{
PlexLog.debug("Plex-HTTPD using ranks check");
if (!player.getRankFromString().isAtLeast(Rank.ADMIN))
{
return schematicsHTML("You must be an admin or above to upload schematics.");
}
}
else if (Plex.get().getSystem().equalsIgnoreCase("permissions"))
{
PlexLog.debug("Plex-HTTPD using permissions check");
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(player.getUuid());
if (!HTTPDModule.getPermissions().playerHas(null, offlinePlayer, "plex.httpd.schematics.upload"))
{
return schematicsHTML("You do not have permission to upload schematics.");
}
}
return readFile(this.getClass().getResourceAsStream("/httpd/schematic_upload.html"));
}

View File

@ -1,4 +0,0 @@
Admins
ADMINS
<h2>Admins</h2>
<h5 class="alert alert-danger mb-3 w-auto p-3" role="alert"><b>Error:</b> ${MESSAGE}</h5>

View File

@ -1,4 +1,4 @@
name: Module-HTTPD
version: 1.3
version: 1.4-SNAPSHOT
description: HTTPD server for Plex
main: dev.plex.HTTPDModule