use of com.easterlyn.user.AutoUser in project Easterlyn by Easterlyn.
the class ListCommand method list.
@CommandAlias("list|ls")
@Description("{@@sink.module.list.description}")
@CommandPermission("easterlyn.command.list")
@Syntax("")
@CommandCompletion("")
public void list(BukkitCommandIssuer issuer) {
Player sender = issuer.getPlayer();
UserRank[] ranks = UserRank.values();
Multimap<String, User> groupedUsers = HashMultimap.create();
int total = 0;
for (Player player : Bukkit.getOnlinePlayers()) {
if (sender != null && !sender.canSee(player)) {
continue;
}
++total;
for (int i = ranks.length - 1; i >= 0; --i) {
UserRank rank = ranks[i];
if (i == 0 || player.hasPermission(rank.getPermission())) {
groupedUsers.put(rank.getFriendlyName(), core.getUserManager().getUser(player.getUniqueId()));
break;
}
}
}
if (ThreadLocalRandom.current().nextDouble() < .001) {
Map<String, String> easterEgg = new HashMap<>();
easterEgg.put("name", "Herobrine");
easterEgg.put("color", ChatColor.BLACK.toString());
groupedUsers.put(UserRank.MEMBER.getFriendlyName(), new AutoUser(core, easterEgg));
}
issuer.sendInfo(MessageKey.of("sink.module.list.header"), "{value}", String.valueOf(total), "{max}", String.valueOf(Bukkit.getMaxPlayers()));
for (int i = ranks.length - 1; i >= 0; --i) {
String groupName = ranks[i].getFriendlyName();
if (i > 0 && groupName.equals(ranks[i - 1].getFriendlyName()) || !groupedUsers.containsKey(groupName)) {
continue;
}
Collection<User> users = groupedUsers.get(groupName);
List<BaseComponent> components = new ArrayList<>(users.size() * 2 + 2);
TextComponent component = new TextComponent(groupName);
component.setColor(ranks[i].getColor());
components.add(component);
component = new TextComponent(": ");
component.setColor(ChatColor.YELLOW);
components.add(component);
TextComponent separator = new TextComponent(", ");
separator.setColor(ChatColor.YELLOW);
users.forEach(user -> {
components.add(user.getMention());
components.add(separator);
});
components.remove(components.size() - 1);
issuer.getIssuer().spigot().sendMessage(components.toArray(new BaseComponent[0]));
}
}
use of com.easterlyn.user.AutoUser in project Easterlyn by Easterlyn.
the class MessageCommand method sendMessage.
@CommandAlias("message|msg|m|whisper|w|pm|tell|t")
@Description("{@@chat.commands.message.description}")
@CommandPermission("easterlyn.command.message")
@Syntax("<recipient> <message>")
@CommandCompletion("@player")
public void sendMessage(BukkitCommandIssuer sender, @Flags(CoreContexts.ONLINE) User target, String message) {
User issuer;
if (sender.isPlayer()) {
issuer = core.getUserManager().getUser(sender.getUniqueId());
} else {
Map<String, String> userData = new HashMap<>();
userData.put("name", sender.getIssuer().getName());
issuer = new AutoUser(core, userData);
// For the purpose of allowing replies to console, set target's reply target.
replies.put(target.getUniqueId(), issuer);
}
replies.put(issuer.getUniqueId(), target);
Channel channel = chat.getChannels().get("pm");
if (channel == null) {
ReportableEvent.call("Channel #pm not set up when executing /message!");
core.getLocaleManager().sendMessage(sender.getIssuer(), "chat.commands.message.error.pm_channel");
return;
}
List<UUID> recipients = new ArrayList<>();
if (!(issuer instanceof AutoUser)) {
recipients.add(issuer.getUniqueId());
}
if (!(target instanceof AutoUser)) {
recipients.add(target.getUniqueId());
}
new UserChatEvent(issuer, channel, target.getDisplayName() + ": " + message).send(recipients);
}
use of com.easterlyn.user.AutoUser in project Easterlyn by Easterlyn.
the class ChannelManagementListener method onUserCreate.
@EventHandler
public void onUserCreate(UserCreationEvent event) {
RegisteredServiceProvider<EasterlynCore> easterlynProvider = chat.getServer().getServicesManager().getRegistration(EasterlynCore.class);
if (easterlynProvider != null) {
ConfigurationSection userSection = chat.getConfig().getConfigurationSection("auto_user");
Map<String, String> userData = new HashMap<>();
if (userSection != null) {
userSection.getKeys(false).forEach(key -> userData.put(key, userSection.getString(key)));
}
Player player = event.getUser().getPlayer();
if (player != null && !player.hasPlayedBefore()) {
// TODO lang?
new UserChatEvent(new AutoUser(easterlynProvider.getProvider(), userData), EasterlynChat.DEFAULT, event.getUser().getDisplayName() + " is new! Please welcome them.");
}
}
addMainChannel(event.getUser(), null);
}
use of com.easterlyn.user.AutoUser in project Easterlyn by Easterlyn.
the class UserChatEvent method send.
public void send(Collection<UUID> additionalRecipients) {
Bukkit.getPluginManager().callEvent(this);
if (this.isCancelled()) {
return;
}
TextComponent channelElement = new TextComponent();
TextComponent[] channelHover = new TextComponent[] { new TextComponent("/join "), new TextComponent(channel.getDisplayName()) };
channelHover[0].setColor(Colors.COMMAND);
channelHover[1].setColor(Colors.CHANNEL);
channelElement.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(channelHover)));
channelElement.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + channel.getDisplayName()));
TextComponent channelName = new TextComponent(channel.getDisplayName());
channelName.setColor((channel.isOwner(getUser()) ? Colors.CHANNEL_OWNER : channel.isModerator(getUser()) ? Colors.CHANNEL_MODERATOR : Colors.CHANNEL_MEMBER));
TextComponent nameElement = new TextComponent(thirdPerson ? "> " : " <");
TextComponent userElement = getUser().getMention();
nameElement.setHoverEvent(userElement.getHoverEvent());
nameElement.setClickEvent(userElement.getClickEvent());
TextComponent nameText = new TextComponent(userElement.getText().substring(1));
nameText.setColor(userElement.getColor());
nameElement.addExtra(nameText);
nameElement.addExtra(new TextComponent(thirdPerson ? " " : "> "));
Collection<TextComponent> messageComponents;
Player player = getUser().getPlayer();
if (player == null) {
messageComponents = StringUtil.toJSON(message);
} else {
messageComponents = StringUtil.toJSON(message, Collections.singleton(new StaticQuoteConsumer(PLAYER_ITEMS) {
@Override
public void addComponents(@NotNull ParsedText components, @NotNull Supplier<Matcher> matcherSupplier) {
Matcher matcher = matcherSupplier.get();
int slot;
try {
slot = Integer.parseInt(matcher.group(1));
} catch (NumberFormatException e) {
components.addText(matcher.group());
return;
}
if (slot < 0 || slot >= player.getInventory().getSize()) {
components.addText(matcher.group());
return;
}
ItemStack item = player.getInventory().getItem(slot);
if (item == null) {
item = ItemUtil.AIR;
}
components.addComponent(ItemUtil.getItemComponent(item));
}
}));
}
Stream.concat(additionalRecipients.stream(), channel.getMembers().stream()).distinct().map(uuid -> getUser().getPlugin().getUserManager().getUser(uuid)).forEach(user -> {
boolean highlight = false;
// Copy and convert TextComponents from parsed message
List<TextComponent> highlightedComponents = new LinkedList<>();
for (TextComponent textComponent : messageComponents) {
String text = textComponent.getText();
Matcher matcher = getHighlightPattern(user).matcher(text);
int previousMatch = 0;
while (matcher.find()) {
highlight = true;
if (matcher.start() > 0) {
TextComponent start = new TextComponent(textComponent);
start.setText(text.substring(previousMatch, matcher.start()));
highlightedComponents.add(start);
}
TextComponent mention = user.getMention();
mention.setColor(Colors.HIGHLIGHT);
highlightedComponents.add(mention);
// Set previous match to end of group 1 so next will pick up group 2 if it exists.
previousMatch = matcher.end(1);
}
if (previousMatch == 0) {
// No matches, no need to modify component for user.
highlightedComponents.add(textComponent);
continue;
}
if (previousMatch == text.length()) {
// Last match coincided with the end of the text.
continue;
}
TextComponent end = new TextComponent(textComponent);
end.setText(text.substring(previousMatch));
highlightedComponents.add(end);
}
TextComponent finalMessage = new TextComponent();
// Set text a nice relaxing grey if not focused or explicitly set
finalMessage.setColor(channel.getName().equals("pm") || channel.getName().equals(user.getStorage().getString(EasterlynChat.USER_CURRENT)) ? ChatColor.WHITE : ChatColor.GRAY);
TextComponent channelBrace;
if (highlight) {
channelBrace = new TextComponent("!!");
channelBrace.setColor(Colors.HIGHLIGHT);
} else {
channelBrace = new TextComponent("[");
}
BaseComponent finalChannel = channelElement.duplicate();
finalChannel.addExtra(channelBrace);
finalChannel.addExtra(channelName);
if (!highlight) {
channelBrace = new TextComponent("]");
}
finalChannel.addExtra(channelBrace);
finalMessage.addExtra(finalChannel);
finalMessage.addExtra(nameElement);
for (TextComponent component : highlightedComponents) {
finalMessage.addExtra(component);
}
user.sendMessage(getUser() instanceof AutoUser ? null : getUser().getUniqueId(), finalMessage);
});
Bukkit.getConsoleSender().sendMessage(ChatColor.stripColor(String.format("[%1$s]" + (thirdPerson ? "> %2$s " : " <%2$s> ") + "%3$s", channel.getDisplayName(), getUser().getDisplayName(), message)));
}
Aggregations