mirror of
https://github.com/plexusorg/Module-HTTPD.git
synced 2024-12-22 16:04:59 +00:00
Add a list module
This commit is contained in:
parent
f41d09d7bf
commit
98f974b634
2 changed files with 27 additions and 0 deletions
|
@ -4,6 +4,7 @@ import dev.plex.config.ModuleConfig;
|
||||||
import dev.plex.module.PlexModule;
|
import dev.plex.module.PlexModule;
|
||||||
import dev.plex.request.impl.AdminsEndpoint;
|
import dev.plex.request.impl.AdminsEndpoint;
|
||||||
import dev.plex.request.impl.IndefBansEndpoint;
|
import dev.plex.request.impl.IndefBansEndpoint;
|
||||||
|
import dev.plex.request.impl.ListEndpoint;
|
||||||
import dev.plex.util.PlexLog;
|
import dev.plex.util.PlexLog;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
@ -60,6 +61,7 @@ public class HTTPDModule extends PlexModule
|
||||||
|
|
||||||
new AdminsEndpoint();
|
new AdminsEndpoint();
|
||||||
new IndefBansEndpoint();
|
new IndefBansEndpoint();
|
||||||
|
new ListEndpoint();
|
||||||
|
|
||||||
server.setConnectors(new Connector[]{connector});
|
server.setConnectors(new Connector[]{connector});
|
||||||
server.setHandler(context);
|
server.setHandler(context);
|
||||||
|
|
25
src/main/java/dev/plex/request/impl/ListEndpoint.java
Normal file
25
src/main/java/dev/plex/request/impl/ListEndpoint.java
Normal 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());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue