Add a list module

This commit is contained in:
Telesphoreo 2022-04-02 16:34:29 -05:00
parent f41d09d7bf
commit 98f974b634
2 changed files with 27 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import dev.plex.config.ModuleConfig;
import dev.plex.module.PlexModule;
import dev.plex.request.impl.AdminsEndpoint;
import dev.plex.request.impl.IndefBansEndpoint;
import dev.plex.request.impl.ListEndpoint;
import dev.plex.util.PlexLog;
import java.util.concurrent.atomic.AtomicReference;
import lombok.Getter;
@ -60,6 +61,7 @@ public class HTTPDModule extends PlexModule
new AdminsEndpoint();
new IndefBansEndpoint();
new ListEndpoint();
server.setConnectors(new Connector[]{connector});
server.setHandler(context);

View File

@ -0,0 +1,25 @@
package dev.plex.request.impl;
import com.google.gson.GsonBuilder;
import dev.plex.request.AbstractServlet;
import dev.plex.request.GetMapping;
import jakarta.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class ListEndpoint extends AbstractServlet
{
List<String> players = new ArrayList<>();
@GetMapping(endpoint = "/api/list/")
public String getOnlinePlayers(HttpServletRequest request)
{
for (Player player : Bukkit.getOnlinePlayers())
{
players.add(player.getName());
}
return new GsonBuilder().setPrettyPrinting().create().toJson(players.stream().toList());
}
}