feat: code
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package online.mineroo.common.request;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import online.mineroo.common.NetworkServiceInterface;
|
||||
@@ -168,6 +170,27 @@ public class ManagementRequest {
|
||||
});
|
||||
}
|
||||
|
||||
public CompletableFuture<Boolean> reportPlayers(List<Map<String, String>> players) {
|
||||
String path = "/server/management/report-online-players";
|
||||
|
||||
JsonObject json = new JsonObject();
|
||||
JsonArray array = new JsonArray();
|
||||
for (Map<String, String> player : players) {
|
||||
JsonObject obj = new JsonObject();
|
||||
obj.addProperty("name", player.get("name"));
|
||||
obj.addProperty("uuid", player.get("uuid"));
|
||||
array.add(obj);
|
||||
}
|
||||
json.add("players", array);
|
||||
|
||||
return networkService.postData(path, json)
|
||||
.thenApply(response -> { return true; })
|
||||
.exceptionally(e -> {
|
||||
logger.warn("Mineroo Report: Failed to report player list", e);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the MOTD token received from the API.
|
||||
*
|
||||
|
||||
@@ -8,6 +8,7 @@ public class Config {
|
||||
private final ProxySection proxy;
|
||||
private final TestSection test;
|
||||
private final CurrenciesSection currencies;
|
||||
private final PrivacySection privacy;
|
||||
|
||||
public Config(FileConfiguration config) {
|
||||
this.test = new TestSection(config);
|
||||
@@ -15,6 +16,7 @@ public class Config {
|
||||
this.server = new ServerSection(config);
|
||||
this.player = new PlayersSection(config);
|
||||
this.currencies = new CurrenciesSection(config);
|
||||
this.privacy = new PrivacySection(config);
|
||||
}
|
||||
|
||||
public TestSection getTest() {
|
||||
@@ -37,11 +39,15 @@ public class Config {
|
||||
return currencies;
|
||||
}
|
||||
|
||||
public PrivacySection getPrivacy() {
|
||||
return privacy;
|
||||
}
|
||||
|
||||
public static class TestSection {
|
||||
private final String apiHostname;
|
||||
|
||||
public TestSection(FileConfiguration config) {
|
||||
this.apiHostname = config.getString("test.api_hostname", "https://oapi.mineroo.online");
|
||||
this.apiHostname = config.getString("test.api-hostname", "https://oapi.mineroo.online");
|
||||
}
|
||||
|
||||
public String getApiHostname() {
|
||||
@@ -53,7 +59,7 @@ public class Config {
|
||||
private final boolean useVelocity;
|
||||
|
||||
public ProxySection(FileConfiguration config) {
|
||||
this.useVelocity = config.getBoolean("proxy.use_velocity", false);
|
||||
this.useVelocity = config.getBoolean("proxy.use-velocity", false);
|
||||
}
|
||||
|
||||
public boolean isUseVelocity() {
|
||||
@@ -67,7 +73,7 @@ public class Config {
|
||||
private final ServerBindSection bind;
|
||||
|
||||
public ServerSection(FileConfiguration config) {
|
||||
this.serverName = config.getString("server.serverName", "");
|
||||
this.serverName = config.getString("server.name", "");
|
||||
this.description = config.getString("server.description", "A minecraft server");
|
||||
this.bind = new ServerBindSection(
|
||||
config.getString("server.bind.address", ""),
|
||||
@@ -119,10 +125,7 @@ public class Config {
|
||||
private final PlayerBindSection bind;
|
||||
|
||||
public PlayersSection(FileConfiguration config) {
|
||||
this.bind = new PlayerBindSection(
|
||||
config.getBoolean("players.bind.required", false),
|
||||
config.getBoolean("players.bind.share_player_info", true)
|
||||
);
|
||||
this.bind = new PlayerBindSection(config.getBoolean("players.bind.required", false));
|
||||
}
|
||||
|
||||
public PlayerBindSection getPlayerBind() {
|
||||
@@ -132,25 +135,20 @@ public class Config {
|
||||
|
||||
public static class PlayerBindSection {
|
||||
private final boolean required;
|
||||
private final boolean sharePlayerInfo;
|
||||
|
||||
public PlayerBindSection(boolean required, boolean sharePlayerInfo) {
|
||||
public PlayerBindSection(boolean required) {
|
||||
this.required = required;
|
||||
this.sharePlayerInfo = sharePlayerInfo;
|
||||
}
|
||||
|
||||
public boolean isRequired() {
|
||||
return required;
|
||||
}
|
||||
|
||||
public boolean isSharePlayerInfo() {
|
||||
return sharePlayerInfo;
|
||||
}
|
||||
}
|
||||
|
||||
public static class CurrenciesSection {
|
||||
private final boolean enable;
|
||||
private final String primary;
|
||||
|
||||
public CurrenciesSection(FileConfiguration config) {
|
||||
this.enable = config.getBoolean("currencies.enable", true);
|
||||
this.primary = config.getString("currencies.primary", "money");
|
||||
@@ -164,4 +162,16 @@ public class Config {
|
||||
return primary;
|
||||
}
|
||||
}
|
||||
|
||||
public static class PrivacySection {
|
||||
private final boolean showOnlinePlayers;
|
||||
|
||||
public PrivacySection(FileConfiguration config) {
|
||||
this.showOnlinePlayers = config.getBoolean("privacy.show-online-players", false);
|
||||
}
|
||||
|
||||
public boolean isShowOnlinePlayers() {
|
||||
return showOnlinePlayers;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,9 +12,11 @@ import online.mineroo.paper.expansions.MinerooExpansion;
|
||||
import online.mineroo.paper.listeners.BindListener;
|
||||
import online.mineroo.paper.listeners.PlayerBindListener;
|
||||
import online.mineroo.paper.listeners.PlayerCurrencyListener;
|
||||
import online.mineroo.paper.tasks.ReportPlayersTask;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
public class MinerooCore extends JavaPlugin implements Listener {
|
||||
private MessageManager messageManager;
|
||||
@@ -69,6 +71,12 @@ public class MinerooCore extends JavaPlugin implements Listener {
|
||||
} else {
|
||||
getLogger().warning("❌ Vault not found! Economy features will be disabled.");
|
||||
}
|
||||
|
||||
if (config.getPrivacy().isShowOnlinePlayers()) {
|
||||
BukkitScheduler scheduler = getServer().getScheduler();
|
||||
long period = 20L * 90;
|
||||
scheduler.runTaskTimer(this, new ReportPlayersTask(this, scheduler), 20L * 30, period);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package online.mineroo.paper.tasks;
|
||||
|
||||
import java.util.Map;
|
||||
import online.mineroo.paper.MinerooCore;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
public class ReportPlayersTask implements Runnable {
|
||||
private final MinerooCore plugin;
|
||||
private final BukkitScheduler scheduler;
|
||||
|
||||
public ReportPlayersTask(MinerooCore plugin, BukkitScheduler scheduler) {
|
||||
this.plugin = plugin;
|
||||
this.scheduler = scheduler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
scheduler.runTask(plugin, () -> {
|
||||
var players =
|
||||
plugin.getServer()
|
||||
.getOnlinePlayers()
|
||||
.stream()
|
||||
.map(
|
||||
player
|
||||
-> Map.of("name", player.getName(), "uuid", player.getUniqueId().toString())
|
||||
)
|
||||
.toList();
|
||||
|
||||
var client = plugin.getRequestClient();
|
||||
|
||||
scheduler.runTaskAsynchronously(plugin, () -> client.management().reportPlayers(players));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
proxy:
|
||||
use_velocity: false
|
||||
use-velocity: false
|
||||
|
||||
server:
|
||||
# Only for `bind server` commands
|
||||
serverName: ""
|
||||
name: ""
|
||||
description: "A minecraft server"
|
||||
|
||||
# Only for `bind server` commands
|
||||
@@ -25,9 +25,5 @@ players:
|
||||
# > server will kick all mineroo unknown player
|
||||
required: false
|
||||
|
||||
# Share player information on mineroo
|
||||
#
|
||||
# !WARNING
|
||||
# > when you open this, player's info can be display on mineroo server status page.
|
||||
# > unless the player already turn on the stealth or private mode.
|
||||
share_player_info: true,
|
||||
privacy:
|
||||
show-online-players: true
|
||||
|
||||
Reference in New Issue
Block a user