Files
TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_players.java
Video 2698cbf46d Too much shit to list in the commit name
- Removes ancient unused code
- General code cleanup in some places
- Rewrites a few components to use Adventure (testing needed)
- Rewrites a few commands to use more modern Java features like Streams
- Fixes oversight where vanishing still worked by names and not UUIDs
- Removes unused Pterodactyl integration
- Removes AutoEject's IP range banning functionality
- Does some minor cleanup to HTTPD's list & players modules
- Fixes ages-old bug in the AntiSpam that caused it to falsely mute players
2022-11-17 01:34:45 -07:00

60 lines
2.2 KiB
Java

package me.totalfreedom.totalfreedommod.httpd.module;
import com.google.gson.Gson;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.entity.HumanEntity;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Module_players extends HTTPDModule
{
private static final Gson gson = new Gson();
public Module_players(NanoHTTPD.HTTPSession session)
{
super(session);
}
@Override
public NanoHTTPD.Response getResponse()
{
final Map<String, List<String>> responseMap = new HashMap<>();
final List<String> admins = new ArrayList<>();
final List<String> senioradmins = new ArrayList<>();
plugin.al.getActiveAdmins().stream().filter(admin -> admin.getName() != null).forEach(admin ->
{
switch (admin.getRank())
{
case ADMIN -> admins.add(admin.getName());
case SENIOR_ADMIN -> senioradmins.add(admin.getName());
default ->
{
// Do nothing, keeps Codacy quiet
}
}
});
responseMap.put("players", server.getOnlinePlayers().stream().filter(player ->
!plugin.al.isVanished(player.getUniqueId())).map(HumanEntity::getName).toList());
responseMap.put("masterbuilders", plugin.pl.getMasterBuilderNames());
responseMap.put("admins", admins);
responseMap.put("senioradmins", senioradmins);
responseMap.put("developers", FUtil.DEVELOPER_NAMES);
responseMap.put("assistantexecutives", ConfigEntry.SERVER_ASSISTANT_EXECUTIVES.getStringList());
responseMap.put("executives", ConfigEntry.SERVER_EXECUTIVES.getStringList());
final NanoHTTPD.Response response = new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, NanoHTTPD.MIME_JSON,
gson.toJson(responseMap));
response.addHeader("Access-Control-Allow-Origin", "*");
return response;
}
}