mirror of
https://github.com/plexusorg/Module-HTTPD.git
synced 2024-12-22 17:27:37 +00:00
Add a list module
This commit is contained in:
parent
f41d09d7bf
commit
98f974b634
@ -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);
|
||||
|
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 New Issue
Block a user