mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-29 04:27:53 +01:00
Removed currently reimplemented commands
This commit is contained in:
parent
c91d4f410b
commit
53e1539da9
@ -16,7 +16,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.commands.use;
|
package com.djrapitops.plan.commands.use;
|
||||||
|
|
||||||
import com.djrapitops.plan.commands.Arguments;
|
|
||||||
import com.djrapitops.plugin.task.AbsRunnable;
|
import com.djrapitops.plugin.task.AbsRunnable;
|
||||||
import com.djrapitops.plugin.task.RunnableFactory;
|
import com.djrapitops.plugin.task.RunnableFactory;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
|
@ -42,13 +42,8 @@ import javax.inject.Singleton;
|
|||||||
public class OldPlanCommand extends TreeCmdNode {
|
public class OldPlanCommand extends TreeCmdNode {
|
||||||
|
|
||||||
private final PlanConfig config;
|
private final PlanConfig config;
|
||||||
private final InspectCommand inspectCommand;
|
|
||||||
private final QInspectCommand qInspectCommand;
|
private final QInspectCommand qInspectCommand;
|
||||||
private final SearchCommand searchCommand;
|
private final SearchCommand searchCommand;
|
||||||
private final ListPlayersCommand listPlayersCommand;
|
|
||||||
private final AnalyzeCommand analyzeCommand;
|
|
||||||
private final NetworkCommand networkCommand;
|
|
||||||
private final ListServersCommand listServersCommand;
|
|
||||||
private final Lazy<WebUserCommand> webUserCommand;
|
private final Lazy<WebUserCommand> webUserCommand;
|
||||||
private final RegisterCommand registerCommand;
|
private final RegisterCommand registerCommand;
|
||||||
private final UnregisterCommand unregisterCommand;
|
private final UnregisterCommand unregisterCommand;
|
||||||
@ -65,13 +60,8 @@ public class OldPlanCommand extends TreeCmdNode {
|
|||||||
Locale locale,
|
Locale locale,
|
||||||
PlanConfig config,
|
PlanConfig config,
|
||||||
// Group 1
|
// Group 1
|
||||||
InspectCommand inspectCommand,
|
|
||||||
QInspectCommand qInspectCommand,
|
QInspectCommand qInspectCommand,
|
||||||
SearchCommand searchCommand,
|
SearchCommand searchCommand,
|
||||||
ListPlayersCommand listPlayersCommand,
|
|
||||||
AnalyzeCommand analyzeCommand,
|
|
||||||
NetworkCommand networkCommand,
|
|
||||||
ListServersCommand listServersCommand,
|
|
||||||
// Group 2
|
// Group 2
|
||||||
Lazy<WebUserCommand> webUserCommand,
|
Lazy<WebUserCommand> webUserCommand,
|
||||||
RegisterCommand registerCommand,
|
RegisterCommand registerCommand,
|
||||||
@ -88,13 +78,8 @@ public class OldPlanCommand extends TreeCmdNode {
|
|||||||
commandsRegistered = false;
|
commandsRegistered = false;
|
||||||
|
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.inspectCommand = inspectCommand;
|
|
||||||
this.qInspectCommand = qInspectCommand;
|
this.qInspectCommand = qInspectCommand;
|
||||||
this.searchCommand = searchCommand;
|
this.searchCommand = searchCommand;
|
||||||
this.listPlayersCommand = listPlayersCommand;
|
|
||||||
this.analyzeCommand = analyzeCommand;
|
|
||||||
this.networkCommand = networkCommand;
|
|
||||||
this.listServersCommand = listServersCommand;
|
|
||||||
this.webUserCommand = webUserCommand;
|
this.webUserCommand = webUserCommand;
|
||||||
this.registerCommand = registerCommand;
|
this.registerCommand = registerCommand;
|
||||||
this.infoCommand = infoCommand;
|
this.infoCommand = infoCommand;
|
||||||
@ -114,13 +99,8 @@ public class OldPlanCommand extends TreeCmdNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CommandNode[] analyticsGroup = {
|
CommandNode[] analyticsGroup = {
|
||||||
inspectCommand,
|
|
||||||
qInspectCommand,
|
qInspectCommand,
|
||||||
searchCommand,
|
searchCommand
|
||||||
listPlayersCommand,
|
|
||||||
analyzeCommand,
|
|
||||||
networkCommand,
|
|
||||||
listServersCommand
|
|
||||||
};
|
};
|
||||||
CommandNode[] webGroup = {
|
CommandNode[] webGroup = {
|
||||||
webUserCommand.get(),
|
webUserCommand.get(),
|
||||||
|
@ -17,11 +17,15 @@
|
|||||||
package com.djrapitops.plan.commands;
|
package com.djrapitops.plan.commands;
|
||||||
|
|
||||||
import com.djrapitops.plan.commands.subcommands.LinkCommands;
|
import com.djrapitops.plan.commands.subcommands.LinkCommands;
|
||||||
|
import com.djrapitops.plan.commands.use.Arguments;
|
||||||
import com.djrapitops.plan.commands.use.CMDSender;
|
import com.djrapitops.plan.commands.use.CMDSender;
|
||||||
import com.djrapitops.plan.commands.use.CommandWithSubcommands;
|
import com.djrapitops.plan.commands.use.CommandWithSubcommands;
|
||||||
import com.djrapitops.plan.commands.use.Subcommand;
|
import com.djrapitops.plan.commands.use.Subcommand;
|
||||||
import com.djrapitops.plan.settings.locale.Locale;
|
import com.djrapitops.plan.settings.locale.Locale;
|
||||||
|
import com.djrapitops.plan.utilities.logging.ErrorContext;
|
||||||
|
import com.djrapitops.plan.utilities.logging.ErrorLogger;
|
||||||
import com.djrapitops.plugin.command.ColorScheme;
|
import com.djrapitops.plugin.command.ColorScheme;
|
||||||
|
import com.djrapitops.plugin.logging.L;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
@ -34,23 +38,26 @@ public class PlanCommand {
|
|||||||
private final Locale locale;
|
private final Locale locale;
|
||||||
private final ColorScheme colors;
|
private final ColorScheme colors;
|
||||||
private final LinkCommands linkCommands;
|
private final LinkCommands linkCommands;
|
||||||
|
private final ErrorLogger errorLogger;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public PlanCommand(
|
public PlanCommand(
|
||||||
Locale locale,
|
Locale locale,
|
||||||
ColorScheme colors,
|
ColorScheme colors,
|
||||||
LinkCommands linkCommands
|
LinkCommands linkCommands,
|
||||||
|
ErrorLogger errorLogger
|
||||||
) {
|
) {
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
this.colors = colors;
|
this.colors = colors;
|
||||||
this.linkCommands = linkCommands;
|
this.linkCommands = linkCommands;
|
||||||
|
this.errorLogger = errorLogger;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleException(RuntimeException error, CMDSender sender) {
|
private void handleException(RuntimeException error, CMDSender sender, Arguments arguments) {
|
||||||
if (error instanceof IllegalArgumentException) {
|
if (error instanceof IllegalArgumentException) {
|
||||||
sender.send("§c" + error.getMessage());
|
sender.send("§c" + error.getMessage());
|
||||||
} else {
|
} else {
|
||||||
throw error;
|
errorLogger.log(L.WARN, error, ErrorContext.builder().related(sender, arguments).build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,9 +42,6 @@ import javax.inject.Singleton;
|
|||||||
@Singleton
|
@Singleton
|
||||||
public class PlanProxyCommand extends TreeCmdNode {
|
public class PlanProxyCommand extends TreeCmdNode {
|
||||||
|
|
||||||
private final NetworkCommand networkCommand;
|
|
||||||
private final ListServersCommand listServersCommand;
|
|
||||||
private final ListPlayersCommand listPlayersCommand;
|
|
||||||
private final RegisterCommand registerCommand;
|
private final RegisterCommand registerCommand;
|
||||||
private final UnregisterCommand unregisterCommand;
|
private final UnregisterCommand unregisterCommand;
|
||||||
private final Lazy<WebUserCommand> webUserCommand;
|
private final Lazy<WebUserCommand> webUserCommand;
|
||||||
@ -61,9 +58,6 @@ public class PlanProxyCommand extends TreeCmdNode {
|
|||||||
ColorScheme colorScheme,
|
ColorScheme colorScheme,
|
||||||
Locale locale,
|
Locale locale,
|
||||||
// Group 1
|
// Group 1
|
||||||
NetworkCommand networkCommand,
|
|
||||||
ListServersCommand listServersCommand,
|
|
||||||
ListPlayersCommand listPlayersCommand,
|
|
||||||
// Group 2
|
// Group 2
|
||||||
RegisterCommand registerCommand,
|
RegisterCommand registerCommand,
|
||||||
UnregisterCommand unregisterCommand,
|
UnregisterCommand unregisterCommand,
|
||||||
@ -80,9 +74,6 @@ public class PlanProxyCommand extends TreeCmdNode {
|
|||||||
|
|
||||||
commandsRegistered = false;
|
commandsRegistered = false;
|
||||||
|
|
||||||
this.networkCommand = networkCommand;
|
|
||||||
this.listServersCommand = listServersCommand;
|
|
||||||
this.listPlayersCommand = listPlayersCommand;
|
|
||||||
this.registerCommand = registerCommand;
|
this.registerCommand = registerCommand;
|
||||||
this.webUserCommand = webUserCommand;
|
this.webUserCommand = webUserCommand;
|
||||||
this.rawDataCommand = rawDataCommand;
|
this.rawDataCommand = rawDataCommand;
|
||||||
@ -100,9 +91,9 @@ public class PlanProxyCommand extends TreeCmdNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CommandNode[] analyticsGroup = {
|
CommandNode[] analyticsGroup = {
|
||||||
networkCommand,
|
// networkCommand,
|
||||||
listServersCommand,
|
// listPlayersCommand,
|
||||||
listPlayersCommand
|
// list servers
|
||||||
};
|
};
|
||||||
CommandNode[] webGroup = {
|
CommandNode[] webGroup = {
|
||||||
registerCommand,
|
registerCommand,
|
||||||
|
@ -1,162 +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;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.delivery.export.Exporter;
|
|
||||||
import com.djrapitops.plan.delivery.rendering.html.Html;
|
|
||||||
import com.djrapitops.plan.delivery.webserver.Addresses;
|
|
||||||
import com.djrapitops.plan.delivery.webserver.WebServer;
|
|
||||||
import com.djrapitops.plan.exceptions.ExportException;
|
|
||||||
import com.djrapitops.plan.exceptions.database.DBOpException;
|
|
||||||
import com.djrapitops.plan.identification.Server;
|
|
||||||
import com.djrapitops.plan.identification.ServerInfo;
|
|
||||||
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.storage.database.DBSystem;
|
|
||||||
import com.djrapitops.plan.storage.database.Database;
|
|
||||||
import com.djrapitops.plan.storage.database.queries.objects.ServerQueries;
|
|
||||||
import com.djrapitops.plan.storage.database.queries.objects.WebUserQueries;
|
|
||||||
import com.djrapitops.plan.utilities.logging.ErrorLogger;
|
|
||||||
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.logging.L;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This SubCommand is used to run the analysis and access the /server link.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class AnalyzeCommand extends CommandNode {
|
|
||||||
|
|
||||||
private final Locale locale;
|
|
||||||
private final Processing processing;
|
|
||||||
private final Exporter exporter;
|
|
||||||
private final Addresses addresses;
|
|
||||||
private final ServerInfo serverInfo;
|
|
||||||
private final WebServer webServer;
|
|
||||||
private final DBSystem dbSystem;
|
|
||||||
private final ErrorLogger errorLogger;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public AnalyzeCommand(
|
|
||||||
Locale locale,
|
|
||||||
Processing processing,
|
|
||||||
Exporter exporter,
|
|
||||||
Addresses addresses,
|
|
||||||
ServerInfo serverInfo,
|
|
||||||
WebServer webServer,
|
|
||||||
DBSystem dbSystem,
|
|
||||||
ErrorLogger errorLogger
|
|
||||||
) {
|
|
||||||
super("analyze|analyse|analysis|a", Permissions.ANALYZE.getPermission(), CommandType.CONSOLE);
|
|
||||||
|
|
||||||
this.locale = locale;
|
|
||||||
this.processing = processing;
|
|
||||||
this.exporter = exporter;
|
|
||||||
this.addresses = addresses;
|
|
||||||
this.serverInfo = serverInfo;
|
|
||||||
this.webServer = webServer;
|
|
||||||
this.dbSystem = dbSystem;
|
|
||||||
this.errorLogger = errorLogger;
|
|
||||||
|
|
||||||
setShortHelp(locale.getString(CmdHelpLang.ANALYZE));
|
|
||||||
setInDepthHelp(locale.getArray(DeepHelpLang.ANALYZE));
|
|
||||||
setArguments("[server/id]");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
|
||||||
Database database = dbSystem.getDatabase();
|
|
||||||
Database.State dbState = database.getState();
|
|
||||||
if (dbState != Database.State.OPEN) {
|
|
||||||
sender.sendMessage(locale.getString(CommandLang.FAIL_DATABASE_NOT_OPEN, dbState.name()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
processing.submitNonCritical(() -> {
|
|
||||||
try {
|
|
||||||
Server server = getServer(args);
|
|
||||||
sendWebUserNotificationIfNecessary(sender);
|
|
||||||
exporter.exportServerPage(server);
|
|
||||||
sendLink(server, sender);
|
|
||||||
} catch (DBOpException | ExportException e) {
|
|
||||||
sender.sendMessage("§cError occurred: " + e.toString());
|
|
||||||
errorLogger.log(L.ERROR, this.getClass(), e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sendLink(Server server, Sender sender) {
|
|
||||||
String target = "/server/" + Html.encodeToURL(server.getName());
|
|
||||||
String address = addresses.getMainAddress().orElseGet(() -> {
|
|
||||||
sender.sendMessage(locale.getString(CommandLang.NO_ADDRESS_NOTIFY));
|
|
||||||
return addresses.getFallbackLocalhostAddress();
|
|
||||||
});
|
|
||||||
String url = address + target;
|
|
||||||
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
|
|
||||||
sender.sendMessage(locale.getString(CommandLang.HEADER_ANALYSIS));
|
|
||||||
// Link
|
|
||||||
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(">");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sendWebUserNotificationIfNecessary(Sender sender) {
|
|
||||||
if (webServer.isAuthRequired() &&
|
|
||||||
CommandUtils.isPlayer(sender) &&
|
|
||||||
!dbSystem.getDatabase().query(WebUserQueries.fetchUserLinkedTo(sender.getName())).isPresent()) {
|
|
||||||
sender.sendMessage("§e" + locale.getString(CommandLang.NO_WEB_USER_NOTIFY));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Server getServer(String[] args) {
|
|
||||||
return getGivenIdentifier(args)
|
|
||||||
.flatMap(serverIdentifier -> dbSystem.getDatabase()
|
|
||||||
.query(ServerQueries.fetchServerMatchingIdentifier(serverIdentifier))
|
|
||||||
).filter(server -> !server.isProxy())
|
|
||||||
.orElseGet(serverInfo::getServer);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Optional<String> getGivenIdentifier(String[] args) {
|
|
||||||
if (args.length < 1) {
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
StringBuilder idBuilder = new StringBuilder(args[0]);
|
|
||||||
if (args.length > 1) {
|
|
||||||
for (int i = 1; i < args.length; i++) {
|
|
||||||
idBuilder.append(" ").append(args[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Optional.of(idBuilder.toString());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,156 +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;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.delivery.rendering.html.Html;
|
|
||||||
import com.djrapitops.plan.delivery.webserver.Addresses;
|
|
||||||
import com.djrapitops.plan.delivery.webserver.WebServer;
|
|
||||||
import com.djrapitops.plan.exceptions.database.DBOpException;
|
|
||||||
import com.djrapitops.plan.identification.UUIDUtility;
|
|
||||||
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.storage.database.DBSystem;
|
|
||||||
import com.djrapitops.plan.storage.database.Database;
|
|
||||||
import com.djrapitops.plan.storage.database.queries.PlayerFetchQueries;
|
|
||||||
import com.djrapitops.plan.storage.database.queries.objects.WebUserQueries;
|
|
||||||
import com.djrapitops.plan.utilities.MiscUtils;
|
|
||||||
import com.djrapitops.plan.utilities.logging.ErrorLogger;
|
|
||||||
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.logging.L;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This command is used to refresh Inspect page and display link.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
public class InspectCommand extends CommandNode {
|
|
||||||
|
|
||||||
private final Locale locale;
|
|
||||||
private final DBSystem dbSystem;
|
|
||||||
private final WebServer webServer;
|
|
||||||
private final Addresses addresses;
|
|
||||||
private final Processing processing;
|
|
||||||
private final UUIDUtility uuidUtility;
|
|
||||||
private final ErrorLogger errorLogger;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public InspectCommand(
|
|
||||||
Locale locale,
|
|
||||||
Addresses addresses,
|
|
||||||
Processing processing,
|
|
||||||
DBSystem dbSystem,
|
|
||||||
WebServer webServer,
|
|
||||||
UUIDUtility uuidUtility,
|
|
||||||
ErrorLogger errorLogger
|
|
||||||
) {
|
|
||||||
super("inspect", Permissions.INSPECT.getPermission(), CommandType.PLAYER_OR_ARGS);
|
|
||||||
this.addresses = addresses;
|
|
||||||
this.processing = processing;
|
|
||||||
setArguments("<player>");
|
|
||||||
|
|
||||||
this.locale = locale;
|
|
||||||
this.dbSystem = dbSystem;
|
|
||||||
this.webServer = webServer;
|
|
||||||
this.uuidUtility = uuidUtility;
|
|
||||||
this.errorLogger = errorLogger;
|
|
||||||
|
|
||||||
setShortHelp(locale.getString(CmdHelpLang.INSPECT));
|
|
||||||
setInDepthHelp(locale.getArray(DeepHelpLang.INSPECT));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
|
||||||
String playerName = MiscUtils.getPlayerName(args, sender);
|
|
||||||
|
|
||||||
if (playerName == null) {
|
|
||||||
sender.sendMessage(locale.getString(CommandLang.FAIL_NO_PERMISSION));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Database.State dbState = dbSystem.getDatabase().getState();
|
|
||||||
if (dbState != Database.State.OPEN) {
|
|
||||||
sender.sendMessage(locale.getString(CommandLang.FAIL_DATABASE_NOT_OPEN, dbState.name()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
runInspectTask(playerName, sender);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void runInspectTask(String playerName, Sender sender) {
|
|
||||||
processing.submitNonCritical(() -> {
|
|
||||||
try {
|
|
||||||
UUID playerUUID = uuidUtility.getUUIDOf(playerName);
|
|
||||||
if (playerUUID == null) {
|
|
||||||
sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_VALID));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!dbSystem.getDatabase().query(PlayerFetchQueries.isPlayerRegistered(playerUUID))) {
|
|
||||||
sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_KNOWN));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
checkWebUserAndNotify(sender);
|
|
||||||
this.sendInspectMsg(sender, playerName);
|
|
||||||
} catch (DBOpException e) {
|
|
||||||
sender.sendMessage("§eDatabase exception occurred: " + e.getMessage());
|
|
||||||
errorLogger.log(L.ERROR, this.getClass(), e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkWebUserAndNotify(Sender sender) {
|
|
||||||
if (CommandUtils.isPlayer(sender) && webServer.isAuthRequired()) {
|
|
||||||
boolean senderHasWebUser = dbSystem.getDatabase().query(WebUserQueries.fetchUserLinkedTo(sender.getName())).isPresent();
|
|
||||||
|
|
||||||
if (!senderHasWebUser) {
|
|
||||||
sender.sendMessage("§e" + locale.getString(CommandLang.NO_WEB_USER_NOTIFY));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sendInspectMsg(Sender sender, String playerName) {
|
|
||||||
sender.sendMessage(locale.getString(CommandLang.HEADER_INSPECT, playerName));
|
|
||||||
|
|
||||||
String address = addresses.getMainAddress().orElseGet(() -> {
|
|
||||||
sender.sendMessage(locale.getString(CommandLang.NO_ADDRESS_NOTIFY));
|
|
||||||
return addresses.getFallbackLocalhostAddress();
|
|
||||||
});
|
|
||||||
String url = address + "/player/" + Html.encodeToURL(playerName);
|
|
||||||
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(">");
|
|
||||||
}
|
|
||||||
}
|
|
@ -16,8 +16,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.commands.subcommands;
|
package com.djrapitops.plan.commands.subcommands;
|
||||||
|
|
||||||
import com.djrapitops.plan.commands.Arguments;
|
import com.djrapitops.plan.commands.use.Arguments;
|
||||||
import com.djrapitops.plan.commands.use.CMDSender;
|
import com.djrapitops.plan.commands.use.CMDSender;
|
||||||
|
import com.djrapitops.plan.commands.use.MessageBuilder;
|
||||||
import com.djrapitops.plan.delivery.rendering.html.Html;
|
import com.djrapitops.plan.delivery.rendering.html.Html;
|
||||||
import com.djrapitops.plan.delivery.webserver.Addresses;
|
import com.djrapitops.plan.delivery.webserver.Addresses;
|
||||||
import com.djrapitops.plan.identification.Identifiers;
|
import com.djrapitops.plan.identification.Identifiers;
|
||||||
@ -26,6 +27,7 @@ import com.djrapitops.plan.identification.ServerInfo;
|
|||||||
import com.djrapitops.plan.settings.locale.Locale;
|
import com.djrapitops.plan.settings.locale.Locale;
|
||||||
import com.djrapitops.plan.settings.locale.lang.CommandLang;
|
import com.djrapitops.plan.settings.locale.lang.CommandLang;
|
||||||
import com.djrapitops.plan.storage.database.DBSystem;
|
import com.djrapitops.plan.storage.database.DBSystem;
|
||||||
|
import com.djrapitops.plan.storage.database.Database;
|
||||||
import com.djrapitops.plan.storage.database.queries.objects.ServerQueries;
|
import com.djrapitops.plan.storage.database.queries.objects.ServerQueries;
|
||||||
import com.djrapitops.plan.storage.database.queries.objects.UserIdentifierQueries;
|
import com.djrapitops.plan.storage.database.queries.objects.UserIdentifierQueries;
|
||||||
import com.djrapitops.plugin.command.ColorScheme;
|
import com.djrapitops.plugin.command.ColorScheme;
|
||||||
@ -34,6 +36,11 @@ import javax.inject.Inject;
|
|||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of commands that send a link to the command sender.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class LinkCommands {
|
public class LinkCommands {
|
||||||
|
|
||||||
@ -68,6 +75,21 @@ public class LinkCommands {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private MessageBuilder linkTo(MessageBuilder builder, CMDSender sender, String address) {
|
||||||
|
if (sender.isPlayer()) {
|
||||||
|
builder.addPart(colors.getTertiaryColor() + "§l[Link]").link(address).hover(address);
|
||||||
|
} else {
|
||||||
|
builder.addPart(colors.getTertiaryColor() + address);
|
||||||
|
}
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of server subcommand, used to get link to server page.
|
||||||
|
*
|
||||||
|
* @param sender Sender of command.
|
||||||
|
* @param arguments Given arguments.
|
||||||
|
*/
|
||||||
public void onServerCommand(CMDSender sender, Arguments arguments) {
|
public void onServerCommand(CMDSender sender, Arguments arguments) {
|
||||||
Server server;
|
Server server;
|
||||||
String identifier = arguments.concatenate(" ");
|
String identifier = arguments.concatenate(" ");
|
||||||
@ -80,59 +102,21 @@ public class LinkCommands {
|
|||||||
.orElseThrow(() -> new IllegalArgumentException("Server '" + identifier + "' was not found from the database."));
|
.orElseThrow(() -> new IllegalArgumentException("Server '" + identifier + "' was not found from the database."));
|
||||||
}
|
}
|
||||||
|
|
||||||
String address = getAddress(sender);
|
String address = getAddress(sender) + "/server/" + Html.encodeToURL(server.getName());
|
||||||
String target = "/server/" + Html.encodeToURL(server.getName());
|
|
||||||
sender.buildMessage()
|
sender.buildMessage()
|
||||||
.addPart(colors.getMainColor() + "View server page: ")
|
.addPart(colors.getMainColor() + "View server page: ")
|
||||||
.addPart(colors.getTertiaryColor() + "§l[Link]").link(address + target).hover(address + target)
|
.apply(builder -> linkTo(builder, sender, address))
|
||||||
.send();
|
.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPlayerCommand(CMDSender sender, Arguments arguments) {
|
/**
|
||||||
String identifier = arguments.concatenate(" ");
|
* Implementation of servers subcommand, used to list servers.
|
||||||
UUID playerUUID = identifiers.getPlayerUUID(identifier);
|
*
|
||||||
UUID senderUUID = sender.getUUID().orElse(null);
|
* @param sender Sender of command.
|
||||||
if (playerUUID == null) playerUUID = senderUUID;
|
* @param arguments Given arguments.
|
||||||
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.player.other") || playerUUID.equals(senderUUID)) {
|
|
||||||
String address = getAddress(sender);
|
|
||||||
String target = "/player/" + Html.encodeToURL(playerName);
|
|
||||||
sender.buildMessage()
|
|
||||||
.addPart(colors.getMainColor() + "View player page: ")
|
|
||||||
.addPart(colors.getTertiaryColor() + "§l[Link]").link(address + target).hover(address + target)
|
|
||||||
.send();
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("Insufficient permissions: You can not view other player's pages.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPlayersCommand(CMDSender sender, Arguments arguments) {
|
|
||||||
String address = getAddress(sender);
|
|
||||||
String target = "/players";
|
|
||||||
sender.buildMessage()
|
|
||||||
.addPart(colors.getMainColor() + "View players page: ")
|
|
||||||
.addPart(colors.getTertiaryColor() + "§l[Link]").link(address + target).hover(address + target)
|
|
||||||
.send();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onNetworkCommand(CMDSender sender, Arguments arguments) {
|
|
||||||
String address = getAddress(sender);
|
|
||||||
String target = "/network";
|
|
||||||
sender.buildMessage()
|
|
||||||
.addPart(colors.getMainColor() + "View network page: ")
|
|
||||||
.addPart(colors.getTertiaryColor() + "§l[Link]").link(address + target).hover(address + target)
|
|
||||||
.send();
|
|
||||||
dbSystem.getDatabase().query(ServerQueries.fetchProxyServerInformation())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException("Server is not connected to a network. The link redirects to server page."));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onServersCommand(CMDSender sender, Arguments arguments) {
|
public void onServersCommand(CMDSender sender, Arguments arguments) {
|
||||||
|
ensureDatabaseIsOpen();
|
||||||
String m = colors.getMainColor();
|
String m = colors.getMainColor();
|
||||||
String s = colors.getSecondaryColor();
|
String s = colors.getSecondaryColor();
|
||||||
String t = colors.getTertiaryColor();
|
String t = colors.getTertiaryColor();
|
||||||
@ -148,4 +132,71 @@ public class LinkCommands {
|
|||||||
t + "id:name:uuid\n" + serversListed, ":"))
|
t + "id:name:uuid\n" + serversListed, ":"))
|
||||||
.send();
|
.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ensureDatabaseIsOpen() {
|
||||||
|
Database.State dbState = dbSystem.getDatabase().getState();
|
||||||
|
if (dbState != Database.State.OPEN) {
|
||||||
|
throw new IllegalArgumentException(locale.getString(CommandLang.FAIL_DATABASE_NOT_OPEN, dbState.name()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of player command, used to get link to player page.
|
||||||
|
*
|
||||||
|
* @param sender Sender of command.
|
||||||
|
* @param arguments Given arguments.
|
||||||
|
*/
|
||||||
|
public void onPlayerCommand(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.player.other") || playerUUID.equals(senderUUID)) {
|
||||||
|
String address = getAddress(sender) + "/player/" + Html.encodeToURL(playerName);
|
||||||
|
sender.buildMessage()
|
||||||
|
.addPart(colors.getMainColor() + "View player page: ")
|
||||||
|
.apply(builder -> linkTo(builder, sender, address))
|
||||||
|
.send();
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Insufficient permissions: You can not view other player's pages.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of players subcommand, used to get link to players page.
|
||||||
|
*
|
||||||
|
* @param sender Sender of command
|
||||||
|
* @param arguments Only present to fulfill Subcommand#onCommand requirements.
|
||||||
|
*/
|
||||||
|
public void onPlayersCommand(CMDSender sender, Arguments arguments) {
|
||||||
|
String address = getAddress(sender) + "/players";
|
||||||
|
sender.buildMessage()
|
||||||
|
.addPart(colors.getMainColor() + "View players page: ")
|
||||||
|
.apply(builder -> linkTo(builder, sender, address))
|
||||||
|
.send();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of network subcommand, used to get link to network page.
|
||||||
|
*
|
||||||
|
* @param sender Sender of command
|
||||||
|
* @param arguments Only present to fulfill Subcommand#onCommand requirements.
|
||||||
|
*/
|
||||||
|
public void onNetworkCommand(CMDSender sender, Arguments arguments) {
|
||||||
|
String address = getAddress(sender) + "/network";
|
||||||
|
sender.buildMessage()
|
||||||
|
.addPart(colors.getMainColor() + "View network page: ")
|
||||||
|
.apply(builder -> linkTo(builder, sender, address))
|
||||||
|
.send();
|
||||||
|
dbSystem.getDatabase().query(ServerQueries.fetchProxyServerInformation())
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException("Server is not connected to a network. The link redirects to server page."));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,84 +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;
|
|
||||||
|
|
||||||
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.plugin.command.CommandNode;
|
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
|
||||||
import com.djrapitops.plugin.command.CommandUtils;
|
|
||||||
import com.djrapitops.plugin.command.Sender;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Command used to display url to the player list page.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
public class ListPlayersCommand extends CommandNode {
|
|
||||||
|
|
||||||
private final Locale locale;
|
|
||||||
private final Addresses addresses;
|
|
||||||
private final Processing processing;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public ListPlayersCommand(
|
|
||||||
Locale locale,
|
|
||||||
Addresses addresses,
|
|
||||||
Processing processing
|
|
||||||
) {
|
|
||||||
super("players|pl|playerlist|list", Permissions.INSPECT_OTHER.getPermission(), CommandType.CONSOLE);
|
|
||||||
|
|
||||||
this.locale = locale;
|
|
||||||
this.addresses = addresses;
|
|
||||||
this.processing = processing;
|
|
||||||
|
|
||||||
setShortHelp(locale.getString(CmdHelpLang.PLAYERS));
|
|
||||||
setInDepthHelp(locale.getArray(DeepHelpLang.PLAYERS));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
|
||||||
processing.submitNonCritical(() -> sendListMsg(sender));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sendListMsg(Sender sender) {
|
|
||||||
sender.sendMessage(locale.getString(CommandLang.HEADER_PLAYERS));
|
|
||||||
|
|
||||||
// Link
|
|
||||||
String address = addresses.getMainAddress().orElseGet(() -> {
|
|
||||||
sender.sendMessage(locale.getString(CommandLang.NO_ADDRESS_NOTIFY));
|
|
||||||
return addresses.getFallbackLocalhostAddress();
|
|
||||||
});
|
|
||||||
String url = address + "/players";
|
|
||||||
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(">");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,105 +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;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.delivery.formatting.Formatter;
|
|
||||||
import com.djrapitops.plan.exceptions.database.DBOpException;
|
|
||||||
import com.djrapitops.plan.identification.Server;
|
|
||||||
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.storage.database.DBSystem;
|
|
||||||
import com.djrapitops.plan.storage.database.Database;
|
|
||||||
import com.djrapitops.plan.storage.database.queries.objects.ServerQueries;
|
|
||||||
import com.djrapitops.plan.utilities.logging.ErrorLogger;
|
|
||||||
import com.djrapitops.plugin.command.ColorScheme;
|
|
||||||
import com.djrapitops.plugin.command.CommandNode;
|
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
|
||||||
import com.djrapitops.plugin.command.Sender;
|
|
||||||
import com.djrapitops.plugin.logging.L;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This SubCommand is used to list all servers found in the database.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
public class ListServersCommand extends CommandNode {
|
|
||||||
|
|
||||||
private final Locale locale;
|
|
||||||
private final ColorScheme colorScheme;
|
|
||||||
private final DBSystem dbSystem;
|
|
||||||
private final ErrorLogger errorLogger;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public ListServersCommand(
|
|
||||||
Locale locale,
|
|
||||||
ColorScheme colorScheme,
|
|
||||||
DBSystem dbSystem,
|
|
||||||
ErrorLogger errorLogger
|
|
||||||
) {
|
|
||||||
super("servers|serverlist|listservers|sl|ls", Permissions.MANAGE.getPermission(), CommandType.CONSOLE);
|
|
||||||
|
|
||||||
this.locale = locale;
|
|
||||||
this.colorScheme = colorScheme;
|
|
||||||
this.dbSystem = dbSystem;
|
|
||||||
this.errorLogger = errorLogger;
|
|
||||||
|
|
||||||
setShortHelp(locale.getString(CmdHelpLang.SERVERS));
|
|
||||||
setInDepthHelp(locale.getArray(DeepHelpLang.SERVERS));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
|
||||||
Database.State dbState = dbSystem.getDatabase().getState();
|
|
||||||
if (dbState != Database.State.OPEN) {
|
|
||||||
sender.sendMessage(locale.getString(CommandLang.FAIL_DATABASE_NOT_OPEN, dbState.name()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String sCol = colorScheme.getSecondaryColor();
|
|
||||||
String tCol = colorScheme.getTertiaryColor();
|
|
||||||
Formatter<Server> serverFormatter = serverLister(sCol, tCol);
|
|
||||||
try {
|
|
||||||
sender.sendMessage(locale.getString(CommandLang.HEADER_SERVERS));
|
|
||||||
sendServers(sender, serverFormatter);
|
|
||||||
sender.sendMessage(">");
|
|
||||||
} catch (DBOpException e) {
|
|
||||||
sender.sendMessage("§cDatabase Exception occurred.");
|
|
||||||
errorLogger.log(L.WARN, this.getClass(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sendServers(Sender sender, Formatter<Server> serverFormatter) {
|
|
||||||
List<Server> servers = new ArrayList<>(dbSystem.getDatabase().query(ServerQueries.fetchPlanServerInformation()).values());
|
|
||||||
Collections.sort(servers);
|
|
||||||
for (Server server : servers) {
|
|
||||||
sender.sendMessage(serverFormatter.apply(server));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Formatter<Server> serverLister(String tertiaryColor, String secondaryColor) {
|
|
||||||
return server -> " " + tertiaryColor + server.getId() + secondaryColor + " : " + server.getName() + " : " + server.getWebAddress();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,84 +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;
|
|
||||||
|
|
||||||
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.plugin.command.CommandNode;
|
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
|
||||||
import com.djrapitops.plugin.command.CommandUtils;
|
|
||||||
import com.djrapitops.plugin.command.Sender;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Command used to display url to the network page.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
public class NetworkCommand extends CommandNode {
|
|
||||||
|
|
||||||
private final Locale locale;
|
|
||||||
private final Addresses addresses;
|
|
||||||
private final Processing processing;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public NetworkCommand(
|
|
||||||
Locale locale,
|
|
||||||
Addresses addresses,
|
|
||||||
Processing processing
|
|
||||||
) {
|
|
||||||
super("network|n|netw", Permissions.ANALYZE.getPermission(), CommandType.CONSOLE);
|
|
||||||
|
|
||||||
this.locale = locale;
|
|
||||||
this.addresses = addresses;
|
|
||||||
this.processing = processing;
|
|
||||||
|
|
||||||
setShortHelp(locale.getString(CmdHelpLang.NETWORK));
|
|
||||||
setInDepthHelp(locale.getArray(DeepHelpLang.NETWORK));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
|
||||||
processing.submitNonCritical(() -> sendNetworkMsg(sender));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sendNetworkMsg(Sender sender) {
|
|
||||||
sender.sendMessage(locale.getString(CommandLang.HEADER_NETWORK));
|
|
||||||
|
|
||||||
// Link
|
|
||||||
String address = addresses.getMainAddress().orElseGet(() -> {
|
|
||||||
sender.sendMessage(locale.getString(CommandLang.NO_ADDRESS_NOTIFY));
|
|
||||||
return addresses.getFallbackLocalhostAddress();
|
|
||||||
});
|
|
||||||
String url = address + "/network";
|
|
||||||
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(">");
|
|
||||||
}
|
|
||||||
}
|
|
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.commands.subcommands;
|
package com.djrapitops.plan.commands.subcommands;
|
||||||
|
|
||||||
import com.djrapitops.plan.commands.Arguments;
|
import com.djrapitops.plan.commands.use.Arguments;
|
||||||
import com.djrapitops.plan.delivery.domain.auth.User;
|
import com.djrapitops.plan.delivery.domain.auth.User;
|
||||||
import com.djrapitops.plan.delivery.webserver.Addresses;
|
import com.djrapitops.plan.delivery.webserver.Addresses;
|
||||||
import com.djrapitops.plan.delivery.webserver.auth.FailReason;
|
import com.djrapitops.plan.delivery.webserver.auth.FailReason;
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.commands.subcommands;
|
package com.djrapitops.plan.commands.subcommands;
|
||||||
|
|
||||||
import com.djrapitops.plan.commands.Arguments;
|
import com.djrapitops.plan.commands.use.Arguments;
|
||||||
import com.djrapitops.plan.delivery.domain.auth.User;
|
import com.djrapitops.plan.delivery.domain.auth.User;
|
||||||
import com.djrapitops.plan.delivery.webserver.auth.FailReason;
|
import com.djrapitops.plan.delivery.webserver.auth.FailReason;
|
||||||
import com.djrapitops.plan.identification.UUIDUtility;
|
import com.djrapitops.plan.identification.UUIDUtility;
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.commands;
|
package com.djrapitops.plan.commands.use;
|
||||||
|
|
||||||
import org.apache.commons.text.TextStringBuilder;
|
import org.apache.commons.text.TextStringBuilder;
|
||||||
|
|
||||||
@ -79,4 +79,11 @@ public class Arguments {
|
|||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return args.isEmpty();
|
return args.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Arguments{" +
|
||||||
|
"args=" + args +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
@ -40,6 +40,10 @@ public interface CMDSender {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default boolean isPlayer() {
|
||||||
|
return getPlayerName().isPresent();
|
||||||
|
}
|
||||||
|
|
||||||
Optional<UUID> getUUID();
|
Optional<UUID> getUUID();
|
||||||
|
|
||||||
void send(String message);
|
void send(String message);
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.commands.use;
|
package com.djrapitops.plan.commands.use;
|
||||||
|
|
||||||
import com.djrapitops.plan.commands.Arguments;
|
import com.djrapitops.plan.utilities.java.TriConsumer;
|
||||||
import com.djrapitops.plugin.command.ColorScheme;
|
import com.djrapitops.plugin.command.ColorScheme;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -31,7 +31,7 @@ public class CommandWithSubcommands extends Subcommand {
|
|||||||
|
|
||||||
private final List<Subcommand> subcommands;
|
private final List<Subcommand> subcommands;
|
||||||
private BiConsumer<CMDSender, Arguments> fallback;
|
private BiConsumer<CMDSender, Arguments> fallback;
|
||||||
private BiConsumer<RuntimeException, CMDSender> exceptionHandler;
|
private TriConsumer<RuntimeException, CMDSender, Arguments> exceptionHandler;
|
||||||
private ColorScheme colors;
|
private ColorScheme colors;
|
||||||
|
|
||||||
private CommandWithSubcommands() {
|
private CommandWithSubcommands() {
|
||||||
@ -61,7 +61,7 @@ public class CommandWithSubcommands extends Subcommand {
|
|||||||
try {
|
try {
|
||||||
executeCommand(sender, arguments);
|
executeCommand(sender, arguments);
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
exceptionHandler.accept(e, sender);
|
exceptionHandler.accept(e, sender, arguments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +151,7 @@ public class CommandWithSubcommands extends Subcommand {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder exceptionHandler(BiConsumer<RuntimeException, CMDSender> exceptionHandler) {
|
public Builder exceptionHandler(TriConsumer<RuntimeException, CMDSender, Arguments> exceptionHandler) {
|
||||||
command.exceptionHandler = exceptionHandler;
|
command.exceptionHandler = exceptionHandler;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -166,7 +166,7 @@ public class CommandWithSubcommands extends Subcommand {
|
|||||||
onTabComplete(command::onTabComplete);
|
onTabComplete(command::onTabComplete);
|
||||||
super.build();
|
super.build();
|
||||||
if (command.fallback == null) fallback(command::onHelp);
|
if (command.fallback == null) fallback(command::onHelp);
|
||||||
if (command.exceptionHandler == null) exceptionHandler((error, sender) -> {throw error;});
|
if (command.exceptionHandler == null) exceptionHandler((error, sender, arguments) -> {throw error;});
|
||||||
if (command.colors == null) colorScheme(new ColorScheme("§2", "§7", "§f"));
|
if (command.colors == null) colorScheme(new ColorScheme("§2", "§7", "§f"));
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.commands.use;
|
package com.djrapitops.plan.commands.use;
|
||||||
|
|
||||||
import com.djrapitops.plan.commands.Arguments;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.commands.use;
|
package com.djrapitops.plan.commands.use;
|
||||||
|
|
||||||
import com.djrapitops.plan.commands.Arguments;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* 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.utilities.java;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Functional interface for three arguments, similar to BiConsumer.
|
||||||
|
*
|
||||||
|
* @param <T> Type of first argument
|
||||||
|
* @param <V> Type of second argument
|
||||||
|
* @param <K> Type of third argument.
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
public interface TriConsumer<T, V, K> {
|
||||||
|
|
||||||
|
void accept(T t, V v, K k);
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user