Search in sources :

Example 21 with Tuple

use of org.spongepowered.api.util.Tuple in project Nucleus by NucleusPowered.

the class ChatListener method createReplacements.

private static Map<String, Tuple<String[], Function<String, String>>> createReplacements() {
    Map<String, Tuple<String[], Function<String, String>>> t = new HashMap<>();
    MessageProvider mp = Nucleus.getNucleus().getMessageProvider();
    BiFunction<String, String, String> fss = (key, s) -> s.replaceAll("[&]+[" + key.toLowerCase() + key.toUpperCase() + "]", "");
    NameUtil.getColours().forEach((key, value) -> {
        t.put("&" + key, Tuple.of(new String[] { prefix + "colour." + value.getName(), prefix + "color." + value.getName() }, s -> fss.apply(key.toString(), s)));
        permissionToDesc.put(prefix + "colour." + value.getName(), mp.getMessageWithFormat("permission.chat.colourspec", value.getName().toLowerCase(), key.toString()));
        permissionToDesc.put(prefix + "color." + value.getName(), mp.getMessageWithFormat("permission.chat.colorspec", value.getName().toLowerCase(), key.toString()));
    });
    NameUtil.getStyleKeys().entrySet().stream().filter(x -> x.getKey() != 'k').forEach((k) -> {
        t.put("&" + k.getKey(), Tuple.of(new String[] { prefix + "style." + k.getValue().toLowerCase() }, s -> fss.apply(k.getKey().toString(), s)));
        permissionToDesc.put(prefix + "style." + k.getValue().toLowerCase(), mp.getMessageWithFormat("permission.chat.stylespec", k.getValue().toLowerCase(), k.getKey().toString()));
    });
    t.put("&k", Tuple.of(new String[] { prefix + "magic" }, s -> s.replaceAll("[&]+[kK]", "")));
    return t;
}
Also used : Arrays(java.util.Arrays) NameUtil(io.github.nucleuspowered.nucleus.NameUtil) BiFunction(java.util.function.BiFunction) PermissionInformation(io.github.nucleuspowered.nucleus.internal.permissions.PermissionInformation) TextParsingUtils(io.github.nucleuspowered.nucleus.internal.text.TextParsingUtils) HashMap(java.util.HashMap) ChatConfigAdapter(io.github.nucleuspowered.nucleus.modules.chat.config.ChatConfigAdapter) Function(java.util.function.Function) PermissionRegistry(io.github.nucleuspowered.nucleus.internal.PermissionRegistry) ChatTemplateConfig(io.github.nucleuspowered.nucleus.modules.chat.config.ChatTemplateConfig) TemplateUtil(io.github.nucleuspowered.nucleus.modules.chat.util.TemplateUtil) Text(org.spongepowered.api.text.Text) NucleusNoFormatChannel(io.github.nucleuspowered.nucleus.api.chat.NucleusNoFormatChannel) Order(org.spongepowered.api.event.Order) Map(java.util.Map) SuggestedLevel(io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel) ListenerBase(io.github.nucleuspowered.nucleus.internal.ListenerBase) Util(io.github.nucleuspowered.nucleus.Util) NucleusMessageTokenService(io.github.nucleuspowered.nucleus.api.service.NucleusMessageTokenService) Subject(org.spongepowered.api.service.permission.Subject) ChatModule(io.github.nucleuspowered.nucleus.modules.chat.ChatModule) Nucleus(io.github.nucleuspowered.nucleus.Nucleus) EventContexts(io.github.nucleuspowered.nucleus.api.EventContexts) Tuple(org.spongepowered.api.util.Tuple) Maps(com.google.common.collect.Maps) Reloadable(io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable) TextSerializers(org.spongepowered.api.text.serializer.TextSerializers) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) MessageChannelEvent(org.spongepowered.api.event.message.MessageChannelEvent) ChatConfig(io.github.nucleuspowered.nucleus.modules.chat.config.ChatConfig) Player(org.spongepowered.api.entity.living.player.Player) MessageEvent(org.spongepowered.api.event.message.MessageEvent) Pattern(java.util.regex.Pattern) Listener(org.spongepowered.api.event.Listener) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) HashMap(java.util.HashMap) Tuple(org.spongepowered.api.util.Tuple)

Example 22 with Tuple

use of org.spongepowered.api.util.Tuple in project Nucleus by NucleusPowered.

the class AFKHandler method setAfk.

public boolean setAfk(Player player, Cause cause, boolean force) {
    if (!player.isOnline()) {
        return false;
    }
    UUID uuid = player.getUniqueId();
    AFKData a = data.compute(uuid, ((u, afkData) -> afkData == null ? new AFKData(u) : afkData));
    if (force) {
        a.isKnownAfk = false;
    } else if (a.isKnownAfk) {
        return false;
    }
    if (a.canGoAfk()) {
        // Don't accident undo setting AFK, remove any activity from the list.
        synchronized (lock) {
            activity.remove(uuid);
        }
        Tuple<Text, MessageChannel> ttmc = getAFKMessage(player, true);
        AFKEvents.To event = new AFKEvents.To(player, ttmc.getFirst(), ttmc.getSecond(), cause);
        Sponge.getEventManager().post(event);
        actionEvent(event, "command.afk.to.vanish");
        a.isKnownAfk = true;
        return true;
    }
    return false;
}
Also used : AFKConfig(io.github.nucleuspowered.nucleus.modules.afk.config.AFKConfig) ChatTypes(org.spongepowered.api.text.chat.ChatTypes) Keys(org.spongepowered.api.data.key.Keys) TextRepresentable(org.spongepowered.api.text.TextRepresentable) NoExceptionAutoClosable(io.github.nucleuspowered.nucleus.api.util.NoExceptionAutoClosable) NucleusPlugin(io.github.nucleuspowered.nucleus.NucleusPlugin) Multimap(com.google.common.collect.Multimap) HashMultimap(com.google.common.collect.HashMultimap) Lists(com.google.common.collect.Lists) Text(org.spongepowered.api.text.Text) Duration(java.time.Duration) Map(java.util.Map) Task(org.spongepowered.api.scheduler.Task) Util(io.github.nucleuspowered.nucleus.Util) NucleusAFKService(io.github.nucleuspowered.nucleus.api.service.NucleusAFKService) ServiceChangeListener(io.github.nucleuspowered.nucleus.internal.permissions.ServiceChangeListener) PluginContainer(org.spongepowered.api.plugin.PluginContainer) AFKConfigAdapter(io.github.nucleuspowered.nucleus.modules.afk.config.AFKConfigAdapter) CommandPermissionHandler(io.github.nucleuspowered.nucleus.internal.CommandPermissionHandler) Nucleus(io.github.nucleuspowered.nucleus.Nucleus) User(org.spongepowered.api.entity.living.player.User) CauseStackHelper(io.github.nucleuspowered.nucleus.util.CauseStackHelper) Sponge(org.spongepowered.api.Sponge) Set(java.util.Set) Tuple(org.spongepowered.api.util.Tuple) UUID(java.util.UUID) Instant(java.time.Instant) GuardedBy(javax.annotation.concurrent.GuardedBy) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) AFKCommand(io.github.nucleuspowered.nucleus.modules.afk.commands.AFKCommand) Reloadable(io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable) Cause(org.spongepowered.api.event.cause.Cause) List(java.util.List) MessageChannel(org.spongepowered.api.text.channel.MessageChannel) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) Player(org.spongepowered.api.entity.living.player.Player) NucleusTextTemplateImpl(io.github.nucleuspowered.nucleus.internal.text.NucleusTextTemplateImpl) AFKEvents(io.github.nucleuspowered.nucleus.modules.afk.events.AFKEvents) MessageChannel(org.spongepowered.api.text.channel.MessageChannel) Text(org.spongepowered.api.text.Text) UUID(java.util.UUID) AFKEvents(io.github.nucleuspowered.nucleus.modules.afk.events.AFKEvents)

Example 23 with Tuple

use of org.spongepowered.api.util.Tuple in project Nucleus by NucleusPowered.

the class SetCategoryCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    String warpName = args.<Warp>getOne(warpKey).get().getName();
    if (args.hasAny("r")) {
        // Remove the category.
        if (handler.setWarpCategory(warpName, null)) {
            src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.category.removed", warpName));
            return CommandResult.success();
        }
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.category.noremove", warpName));
    }
    Optional<Tuple<String, Boolean>> categoryOp = args.getOne(categoryKey);
    if (!categoryOp.isPresent()) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.category.required"));
    }
    Tuple<String, Boolean> category = categoryOp.get();
    if (!args.hasAny("n") && !category.getSecond()) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.category.requirenew", category.getFirst()).toBuilder().onClick(TextActions.runCommand("/warp setcategory -n " + warpName + " " + category.getFirst())).build());
        return CommandResult.empty();
    }
    // Add the category.
    if (handler.setWarpCategory(warpName, category.getFirst())) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.category.added", category.getFirst(), warpName));
        return CommandResult.success();
    }
    WarpCategory c = handler.getWarpCategoryOrDefault(category.getFirst());
    throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithTextFormat("command.warp.category.couldnotadd", c.getDisplayName(), Text.of(warpName)));
}
Also used : Warp(io.github.nucleuspowered.nucleus.api.nucleusdata.Warp) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) Tuple(org.spongepowered.api.util.Tuple) WarpCategory(io.github.nucleuspowered.nucleus.api.nucleusdata.WarpCategory)

Aggregations

Tuple (org.spongepowered.api.util.Tuple)23 List (java.util.List)9 Map (java.util.Map)8 ArrayList (java.util.ArrayList)7 Optional (java.util.Optional)7 Type (org.objectweb.asm.Type)7 IOException (java.io.IOException)6 Collectors (java.util.stream.Collectors)6 Text (org.spongepowered.api.text.Text)5 Vector3d (com.flowpowered.math.vector.Vector3d)3 Nucleus (io.github.nucleuspowered.nucleus.Nucleus)3 HashMap (java.util.HashMap)3 Set (java.util.Set)3 Label (org.objectweb.asm.Label)3 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2 TypeToken (com.google.common.reflect.TypeToken)2 Util (io.github.nucleuspowered.nucleus.Util)2 Reloadable (io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable)2 File (java.io.File)2