Search in sources :

Example 1 with Component

use of net.kyori.text.Component in project VoxelGamesLibv2 by VoxelGamesLib.

the class HibernatePersistenceProvider method getTop.

@Override
public List<Pair<Component, Double>> getTop(Trackable type, int amount) {
    return session(session -> {
        Query query = session.createQuery("select user.displayName, stat.val from StatInstance stat, UserData user\n" + "where user.uuid = stat.uuid\n" + "and stat.statType = :type\n" + "order by stat.val desc");
        query.setParameter("type", type);
        query.setMaxResults(amount);
        List<Pair<Component, Double>> result = new ArrayList<>();
        // noinspection unchecked
        for (Object[] row : (List<Object[]>) query.getResultList()) {
            result.add(new Pair<>((Component) row[0], (Double) row[1]));
        }
        return result;
    });
}
Also used : Query(org.hibernate.query.Query) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Component(net.kyori.text.Component) Pair(com.voxelgameslib.voxelgameslib.utils.Pair)

Example 2 with Component

use of net.kyori.text.Component in project LuckPerms by lucko.

the class TreeCommand method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
    String selection = ".";
    String player = null;
    if (!args.isEmpty()) {
        selection = args.get(0);
    }
    if (args.size() > 1) {
        player = args.get(1);
    }
    User user;
    if (player != null) {
        UUID u = Uuids.parseNullable(player);
        if (u != null) {
            user = plugin.getUserManager().getIfLoaded(u);
        } else {
            user = plugin.getUserManager().getByUsername(player);
        }
        if (user == null) {
            Message.USER_NOT_ONLINE.send(sender, player);
            return CommandResult.STATE_ERROR;
        }
    } else {
        user = null;
    }
    TreeView view = new TreeView(plugin.getPermissionVault(), selection);
    if (!view.hasData()) {
        Message.TREE_EMPTY.send(sender);
        return CommandResult.FAILURE;
    }
    Message.TREE_UPLOAD_START.send(sender);
    PermissionCache permissionData = user == null ? null : user.getCachedData().getPermissionData(plugin.getContextForUser(user).orElse(plugin.getContextManager().getStaticContexts()));
    String id = view.uploadPasteData(sender, user, permissionData);
    String url = plugin.getConfiguration().get(ConfigKeys.TREE_VIEWER_URL_PATTERN) + "?" + id;
    Message.TREE_URL.send(sender);
    Component message = TextComponent.builder(url).color(TextColor.AQUA).clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, String.valueOf(url))).hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to open the tree view.").color(TextColor.GRAY))).build();
    sender.sendMessage(message);
    return CommandResult.SUCCESS;
}
Also used : HoverEvent(net.kyori.text.event.HoverEvent) User(me.lucko.luckperms.common.model.User) ClickEvent(net.kyori.text.event.ClickEvent) TreeView(me.lucko.luckperms.common.treeview.TreeView) PermissionCache(me.lucko.luckperms.common.caching.type.PermissionCache) UUID(java.util.UUID) TextComponent(net.kyori.text.TextComponent) Component(net.kyori.text.Component)

Example 3 with Component

use of net.kyori.text.Component in project LuckPerms by lucko.

the class VerboseCommand method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
    if (args.isEmpty()) {
        sendUsage(sender, label);
        return CommandResult.INVALID_ARGS;
    }
    String mode = args.get(0).toLowerCase();
    if (mode.equals("on") || mode.equals("true") || mode.equals("record")) {
        List<String> filters = new ArrayList<>();
        if (args.size() != 1) {
            filters.addAll(args.subList(1, args.size()));
        }
        String filter = filters.isEmpty() ? "" : filters.stream().collect(Collectors.joining(" "));
        VerboseFilter parsedFilter;
        try {
            parsedFilter = VerboseFilter.parse(filter);
        } catch (InvalidFilterException e) {
            e.printStackTrace();
            Message.VERBOSE_INVALID_FILTER.send(sender, filter);
            return CommandResult.FAILURE;
        }
        boolean notify = !mode.equals("record");
        plugin.getVerboseHandler().registerListener(sender, parsedFilter, notify);
        if (notify) {
            if (!filter.equals("")) {
                Message.VERBOSE_ON_QUERY.send(sender, filter);
            } else {
                Message.VERBOSE_ON.send(sender);
            }
        } else {
            if (!filter.equals("")) {
                Message.VERBOSE_RECORDING_ON_QUERY.send(sender, filter);
            } else {
                Message.VERBOSE_RECORDING_ON.send(sender);
            }
        }
        return CommandResult.SUCCESS;
    }
    if (mode.equals("off") || mode.equals("false") || mode.equals("paste") || mode.equals("upload")) {
        VerboseListener listener = plugin.getVerboseHandler().unregisterListener(sender.getUuid());
        if (mode.equals("paste") || mode.equals("upload")) {
            if (listener == null) {
                Message.VERBOSE_OFF.send(sender);
            } else {
                Message.VERBOSE_UPLOAD_START.send(sender);
                String id = listener.uploadPasteData();
                String url = plugin.getConfiguration().get(ConfigKeys.VERBOSE_VIEWER_URL_PATTERN) + "?" + id;
                Message.VERBOSE_RESULTS_URL.send(sender);
                Component message = TextComponent.builder(url).color(TextColor.AQUA).clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, String.valueOf(url))).hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to open the results page.").color(TextColor.GRAY))).build();
                sender.sendMessage(message);
                return CommandResult.SUCCESS;
            }
        } else {
            Message.VERBOSE_OFF.send(sender);
        }
        return CommandResult.SUCCESS;
    }
    sendUsage(sender, label);
    return CommandResult.INVALID_ARGS;
}
Also used : HoverEvent(net.kyori.text.event.HoverEvent) InvalidFilterException(me.lucko.luckperms.common.verbose.InvalidFilterException) ClickEvent(net.kyori.text.event.ClickEvent) ArrayList(java.util.ArrayList) VerboseListener(me.lucko.luckperms.common.verbose.VerboseListener) TextComponent(net.kyori.text.TextComponent) Component(net.kyori.text.Component) VerboseFilter(me.lucko.luckperms.common.verbose.VerboseFilter)

Example 4 with Component

use of net.kyori.text.Component in project LuckPerms by lucko.

the class DebugCommand method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
    Message.DEBUG_START.send(sender);
    StringBuilder sb = new StringBuilder();
    sb.append("LuckPerms Debug Output\n\n\n");
    BiConsumer<String, JObject> builder = (name, content) -> {
        sb.append("-- ").append(name).append(" --\n");
        sb.append(GSON.toJson(content.toJson()));
        sb.append("\n\n");
    };
    builder.accept("platform.json", getPlatformData(plugin));
    builder.accept("storage.json", getStorageData(plugin));
    builder.accept("context.json", getContextData(plugin));
    builder.accept("players.json", getPlayersData(plugin));
    Pastebin.Paste paste = StandardPastebin.HASTEBIN.postPlain(sb.toString());
    Message.DEBUG_URL.send(sender);
    Component message = TextComponent.builder(paste.url()).color(TextColor.AQUA).clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, String.valueOf(paste.url()))).hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to open the debugging data.").color(TextColor.GRAY))).build();
    sender.sendMessage(message);
    return CommandResult.SUCCESS;
}
Also used : LookupSetting(me.lucko.luckperms.api.LookupSetting) PermissionProcessor(me.lucko.luckperms.common.processors.PermissionProcessor) Contexts(me.lucko.luckperms.api.Contexts) MetaStackElement(me.lucko.luckperms.api.metastacking.MetaStackElement) LocaleManager(me.lucko.luckperms.common.locale.LocaleManager) SingleCommand(me.lucko.luckperms.common.command.abstraction.SingleCommand) HoverEvent(net.kyori.text.event.HoverEvent) GsonBuilder(com.google.gson.GsonBuilder) CommandSpec(me.lucko.luckperms.common.locale.command.CommandSpec) TextColor(net.kyori.text.format.TextColor) Gson(com.google.gson.Gson) ClickEvent(net.kyori.text.event.ClickEvent) Map(java.util.Map) Message(me.lucko.luckperms.common.locale.message.Message) BiConsumer(java.util.function.BiConsumer) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) JObject(me.lucko.luckperms.common.utils.gson.JObject) Pastebin(me.lucko.luckperms.common.web.Pastebin) ProxiedContextCalculator(me.lucko.luckperms.common.contexts.ProxiedContextCalculator) Collection(java.util.Collection) PermissionCache(me.lucko.luckperms.common.caching.type.PermissionCache) Set(java.util.Set) Sender(me.lucko.luckperms.common.sender.Sender) UUID(java.util.UUID) StaticContextCalculator(me.lucko.luckperms.api.context.StaticContextCalculator) ContextSetJsonSerializer(me.lucko.luckperms.common.contexts.ContextSetJsonSerializer) TextComponent(net.kyori.text.TextComponent) JArray(me.lucko.luckperms.common.utils.gson.JArray) Collectors(java.util.stream.Collectors) CommandResult(me.lucko.luckperms.common.command.CommandResult) StandardPastebin(me.lucko.luckperms.common.web.StandardPastebin) MetaContexts(me.lucko.luckperms.api.caching.MetaContexts) MetaCache(me.lucko.luckperms.common.caching.type.MetaCache) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) List(java.util.List) Component(net.kyori.text.Component) MetaStackDefinition(me.lucko.luckperms.api.metastacking.MetaStackDefinition) ContextCalculator(me.lucko.luckperms.api.context.ContextCalculator) User(me.lucko.luckperms.common.model.User) Predicates(me.lucko.luckperms.common.utils.Predicates) HoverEvent(net.kyori.text.event.HoverEvent) ClickEvent(net.kyori.text.event.ClickEvent) JObject(me.lucko.luckperms.common.utils.gson.JObject) TextComponent(net.kyori.text.TextComponent) Component(net.kyori.text.Component) Pastebin(me.lucko.luckperms.common.web.Pastebin) StandardPastebin(me.lucko.luckperms.common.web.StandardPastebin)

Example 5 with Component

use of net.kyori.text.Component in project LuckPerms by lucko.

the class HolderEditor method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T holder, List<String> args, String label) {
    if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), holder)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    Message.EDITOR_START.send(sender);
    // form the payload data
    JsonObject payload = WebEditor.formPayload(Collections.singletonList(holder), sender, label, plugin);
    // upload the payload data to gist
    String pasteId = StandardPastebin.BYTEBIN.postJson(payload, true).id();
    if (pasteId == null) {
        Message.EDITOR_UPLOAD_FAILURE.send(sender);
        return CommandResult.STATE_ERROR;
    }
    // form a url for the editor
    String url = plugin.getConfiguration().get(ConfigKeys.WEB_EDITOR_URL_PATTERN) + "?" + pasteId;
    Message.EDITOR_URL.send(sender);
    Component message = TextComponent.builder(url).color(TextColor.AQUA).clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url)).hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to open the editor.").color(TextColor.GRAY))).build();
    sender.sendMessage(message);
    return CommandResult.SUCCESS;
}
Also used : HoverEvent(net.kyori.text.event.HoverEvent) ClickEvent(net.kyori.text.event.ClickEvent) JsonObject(com.google.gson.JsonObject) TextComponent(net.kyori.text.TextComponent) Component(net.kyori.text.Component)

Aggregations

Component (net.kyori.text.Component)7 TextComponent (net.kyori.text.TextComponent)6 ClickEvent (net.kyori.text.event.ClickEvent)5 HoverEvent (net.kyori.text.event.HoverEvent)5 ArrayList (java.util.ArrayList)3 List (java.util.List)3 JsonObject (com.google.gson.JsonObject)2 Map (java.util.Map)2 UUID (java.util.UUID)2 PermissionCache (me.lucko.luckperms.common.caching.type.PermissionCache)2 CommandResult (me.lucko.luckperms.common.command.CommandResult)2 SingleCommand (me.lucko.luckperms.common.command.abstraction.SingleCommand)2 CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)2 LocaleManager (me.lucko.luckperms.common.locale.LocaleManager)2 CommandSpec (me.lucko.luckperms.common.locale.command.CommandSpec)2 Message (me.lucko.luckperms.common.locale.message.Message)2 User (me.lucko.luckperms.common.model.User)2 LuckPermsPlugin (me.lucko.luckperms.common.plugin.LuckPermsPlugin)2 Sender (me.lucko.luckperms.common.sender.Sender)2 PacketType (com.comphenix.protocol.PacketType)1