use of com.djrapitops.plan.commands.use.Arguments in project Plan by plan-player-analytics.
the class LinkCommands method onJson.
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(locale.getString(CommandLang.FAIL_PLAYER_NOT_FOUND, identifier));
}
if (sender.hasPermission(Permissions.JSON_OTHER) || playerUUID.equals(senderUUID)) {
String address = getAddress(sender) + "/player/" + playerUUID + "/raw";
sender.buildMessage().addPart(colors.getMainColor() + locale.getString(CommandLang.LINK_JSON)).apply(builder -> linkTo(builder, sender, address)).send();
} else {
throw new IllegalArgumentException(locale.getString(CommandLang.FAIL_NO_PERMISSION) + " (" + Permissions.JSON_OTHER.get() + ')');
}
}
use of com.djrapitops.plan.commands.use.Arguments in project Plan by plan-player-analytics.
the class LinkCommands method onPlayerCommand.
/**
* 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(locale.getString(CommandLang.FAIL_PLAYER_NOT_FOUND, identifier));
}
if (sender.hasPermission(Permissions.PLAYER_OTHER) || playerUUID.equals(senderUUID)) {
String address = getAddress(sender) + "/player/" + playerUUID;
sender.buildMessage().addPart(colors.getMainColor() + locale.getString(CommandLang.LINK_PLAYER)).apply(builder -> linkTo(builder, sender, address)).send();
} else {
throw new IllegalArgumentException(locale.getString(CommandLang.FAIL_NO_PERMISSION) + " (" + Permissions.PLAYER_OTHER.get() + ')');
}
}
use of com.djrapitops.plan.commands.use.Arguments in project Plan by plan-player-analytics.
the class RegistrationCommands method registerUsingLegacy.
public void registerUsingLegacy(CMDSender sender, Arguments arguments) {
String password = arguments.get(0).orElseThrow(() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ARGS, 1, "<password>")));
String passwordHash = PassEncryptUtil.createHash(password);
int permissionLevel = arguments.getInteger(2).filter(// argument only allowed with register other permission
arg -> sender.hasPermission(Permissions.REGISTER_OTHER)).orElseGet(() -> getPermissionLevel(sender));
Optional<UUID> senderUUID = sender.getUUID();
Optional<String> senderName = sender.getPlayerName();
if (senderUUID.isPresent() && senderName.isPresent()) {
String playerName = senderName.get();
UUID linkedToUUID = senderUUID.get();
String username = arguments.get(1).orElse(playerName);
registerUser(new User(username, playerName, linkedToUUID, passwordHash, permissionLevel, Collections.emptyList()), sender, permissionLevel);
} else {
String username = arguments.get(1).orElseThrow(() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ARGS, 3, "<password> <name> <level>")));
registerUser(new User(username, "console", null, passwordHash, permissionLevel, Collections.emptyList()), sender, permissionLevel);
}
}
use of com.djrapitops.plan.commands.use.Arguments in project Plan by plan-player-analytics.
the class NukkitPlaceholderRegistrar method register.
public void register() {
PlaceholderAPI api = PlaceholderAPI.getInstance();
placeholders.getPlaceholders().forEach((name, loader) -> api.builder(name, Serializable.class).visitorLoader(options -> {
try {
return loader.apply(getPlayer(options.getPlayer()), getPlaceholderParameterValues(options.getParameters()));
} catch (Exception e) {
errorLogger.warn(e, ErrorContext.builder().related("Registering PlaceholderAPI").build());
return null;
}
}).build());
placeholders.getStaticPlaceholders().forEach((name, loader) -> api.builder(name, Serializable.class).loader(options -> {
try {
return loader.apply(new Arguments(getPlaceholderParameterValues(options.getParameters())));
} catch (Exception e) {
errorLogger.warn(e, ErrorContext.builder().related("Registering PlaceholderAPI").build());
return null;
}
}).build());
}
use of com.djrapitops.plan.commands.use.Arguments in project Plan by plan-player-analytics.
the class LinkCommands method onServerCommand.
/**
* 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) {
Server server;
String identifier = arguments.concatenate(" ");
if (arguments.isEmpty()) {
server = serverInfo.getServer();
} else {
server = dbSystem.getDatabase().query(ServerQueries.fetchServerMatchingIdentifier(identifier)).filter(s -> !s.isProxy()).orElseThrow(() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_SERVER_NOT_FOUND, identifier)));
}
String address = getAddress(sender) + "/server/" + Html.encodeToURL(server.getName());
sender.buildMessage().addPart(colors.getMainColor() + locale.getString(CommandLang.LINK_SERVER)).apply(builder -> linkTo(builder, sender, address)).send();
}
Aggregations