mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-02-05 23:11:56 +01:00
Registered plan json command
This commit is contained in:
parent
01fb4c7d84
commit
ea73dec439
@ -89,6 +89,7 @@ public class PlanCommand {
|
||||
.subcommand(playerCommand())
|
||||
.subcommand(playersCommand())
|
||||
.subcommand(networkCommand())
|
||||
.subcommand(jsonCommand())
|
||||
|
||||
.subcommand(registerCommand())
|
||||
.subcommand(unregisterCommand())
|
||||
@ -102,7 +103,7 @@ public class PlanCommand {
|
||||
.subcommand(disableCommand())
|
||||
.subcommand(databaseCommand())
|
||||
|
||||
.subcommand(export())
|
||||
.subcommand(exportCommand())
|
||||
.exceptionHandler(this::handleException)
|
||||
.build();
|
||||
}
|
||||
@ -259,7 +260,7 @@ public class PlanCommand {
|
||||
.subcommand(moveCommand())
|
||||
.subcommand(clearCommand())
|
||||
.subcommand(removeCommand())
|
||||
.subcommand(uninstalled())
|
||||
.subcommand(uninstalledCommand())
|
||||
.inDepthDescription("Use different database subcommands to change the data in some way")
|
||||
.build();
|
||||
}
|
||||
@ -321,7 +322,7 @@ public class PlanCommand {
|
||||
.build();
|
||||
}
|
||||
|
||||
private Subcommand uninstalled() {
|
||||
private Subcommand uninstalledCommand() {
|
||||
return Subcommand.builder()
|
||||
.aliases("uninstalled")
|
||||
.requirePermission("plan.data.uninstalled")
|
||||
@ -332,7 +333,7 @@ public class PlanCommand {
|
||||
.build();
|
||||
}
|
||||
|
||||
private Subcommand export() {
|
||||
private Subcommand exportCommand() {
|
||||
return Subcommand.builder()
|
||||
.aliases("export")
|
||||
.requirePermission("plan.data.export")
|
||||
@ -342,4 +343,16 @@ public class PlanCommand {
|
||||
.onCommand(dataUtilityCommands::onExport)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Subcommand jsonCommand() {
|
||||
return Subcommand.builder()
|
||||
.aliases("json")
|
||||
.requirePermission("plan.json.self")
|
||||
.requiredArgument("name/uuid", "Name or UUID of a player")
|
||||
.description("View json of Player's raw data.")
|
||||
.inDepthDescription("Allows you to download a player's data in json format. All of it.")
|
||||
.onCommand(linkCommands::onJson)
|
||||
.build();
|
||||
}
|
||||
}
|
@ -224,4 +224,26 @@ public class LinkCommands {
|
||||
.send();
|
||||
}
|
||||
|
||||
public void onJson(CMDSender sender, Arguments arguments) {
|
||||
String identifier = arguments.concatenate(" ");
|
||||
UUID playerUUID = identifiers.getPlayerUUID(identifier);
|
||||
UUID senderUUID = sender.getUUID().orElse(null);
|
||||
if (playerUUID == null) playerUUID = senderUUID;
|
||||
if (playerUUID == null) {
|
||||
throw new IllegalArgumentException("Player '" + identifier + "' was not found, they have no UUID.");
|
||||
}
|
||||
|
||||
String playerName = dbSystem.getDatabase().query(UserIdentifierQueries.fetchPlayerNameOf(playerUUID))
|
||||
.orElseThrow(() -> new IllegalArgumentException("Player '" + identifier + "' was not found in the database."));
|
||||
|
||||
if (sender.hasPermission("plan.json.other") || playerUUID.equals(senderUUID)) {
|
||||
String address = getAddress(sender) + "/player/" + Html.encodeToURL(playerName) + "/raw";
|
||||
sender.buildMessage()
|
||||
.addPart(colors.getMainColor() + "Player json: ")
|
||||
.apply(builder -> linkTo(builder, sender, address))
|
||||
.send();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Insufficient permissions: You can not view other player's json.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,93 +0,0 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan.commands.subcommands.manage;
|
||||
|
||||
import com.djrapitops.plan.delivery.rendering.html.Html;
|
||||
import com.djrapitops.plan.delivery.webserver.Addresses;
|
||||
import com.djrapitops.plan.processing.Processing;
|
||||
import com.djrapitops.plan.settings.Permissions;
|
||||
import com.djrapitops.plan.settings.locale.Locale;
|
||||
import com.djrapitops.plan.settings.locale.lang.CmdHelpLang;
|
||||
import com.djrapitops.plan.settings.locale.lang.CommandLang;
|
||||
import com.djrapitops.plan.settings.locale.lang.DeepHelpLang;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.CommandUtils;
|
||||
import com.djrapitops.plugin.command.Sender;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* This manage subcommand is used to remove a single player's data from the
|
||||
* database.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class ManageRawDataCommand extends CommandNode {
|
||||
|
||||
private final Locale locale;
|
||||
private final Addresses addresses;
|
||||
private final Processing processing;
|
||||
|
||||
@Inject
|
||||
public ManageRawDataCommand(
|
||||
Locale locale,
|
||||
Addresses addresses,
|
||||
Processing processing
|
||||
) {
|
||||
super("raw", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS);
|
||||
|
||||
this.locale = locale;
|
||||
this.addresses = addresses;
|
||||
this.processing = processing;
|
||||
|
||||
setArguments("<player>");
|
||||
setShortHelp(locale.getString(CmdHelpLang.MANAGE_RAW_DATA));
|
||||
setInDepthHelp(locale.getArray(DeepHelpLang.MANAGE_RAW_DATA));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||
Verify.isTrue(args.length >= 1,
|
||||
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
|
||||
|
||||
processing.submitNonCritical(() -> {
|
||||
String playerName = MiscUtils.getPlayerName(args, sender, Permissions.MANAGE);
|
||||
|
||||
sender.sendMessage(locale.getString(CommandLang.HEADER_INSPECT, playerName));
|
||||
// Link
|
||||
String address = addresses.getMainAddress().orElseGet(() -> {
|
||||
sender.sendMessage(locale.getString(CommandLang.NO_ADDRESS_NOTIFY));
|
||||
return addresses.getFallbackLocalhostAddress();
|
||||
});
|
||||
String url = address + "/player/" + Html.encodeToURL(playerName) + "/raw";
|
||||
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
|
||||
boolean console = !CommandUtils.isPlayer(sender);
|
||||
if (console) {
|
||||
sender.sendMessage(linkPrefix + url);
|
||||
} else {
|
||||
sender.sendMessage(linkPrefix);
|
||||
sender.sendLink(" ", locale.getString(CommandLang.LINK_CLICK_ME), url);
|
||||
}
|
||||
|
||||
sender.sendMessage(">");
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user