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;
}
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;
}
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)));
}
Aggregations