Search in sources :

Example 6 with User

use of com.easterlyn.user.User in project Easterlyn by Easterlyn.

the class PVPKeepInventory method onPlayerDeath.

@EventHandler(ignoreCancelled = true)
public void onPlayerDeath(PlayerDeathEvent event) {
    RegisteredServiceProvider<EasterlynCore> easterlynProvider = Bukkit.getServer().getServicesManager().getRegistration(EasterlynCore.class);
    if (easterlynProvider == null) {
        return;
    }
    User user = easterlynProvider.getProvider().getUserManager().getUser(event.getEntity().getUniqueId());
    Object object = user.getTemporaryStorage().get(key);
    if (!(object instanceof Long)) {
        return;
    }
    long timestamp = (long) object;
    if (timestamp < System.currentTimeMillis() - 6000L) {
        return;
    }
    event.setDroppedExp(ExperienceUtil.getExp(event.getEntity()));
    int dropped = ExperienceUtil.getExp(event.getEntity()) / 10;
    if (dropped > 30) {
        dropped = 30;
    }
    event.setDroppedExp(dropped);
    ExperienceUtil.changeExp(event.getEntity(), -dropped);
    event.setKeepLevel(true);
    event.setKeepInventory(true);
    event.getDrops().clear();
}
Also used : User(com.easterlyn.user.User) EasterlynCore(com.easterlyn.EasterlynCore) EventHandler(org.bukkit.event.EventHandler)

Example 7 with User

use of com.easterlyn.user.User 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]));
    }
}
Also used : UserRank(com.easterlyn.user.UserRank) TextComponent(net.md_5.bungee.api.chat.TextComponent) Player(org.bukkit.entity.Player) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) AutoUser(com.easterlyn.user.AutoUser) User(com.easterlyn.user.User) HashMap(java.util.HashMap) AutoUser(com.easterlyn.user.AutoUser) ArrayList(java.util.ArrayList) Description(co.aikar.commands.annotation.Description) CommandCompletion(co.aikar.commands.annotation.CommandCompletion) Syntax(co.aikar.commands.annotation.Syntax) CommandPermission(co.aikar.commands.annotation.CommandPermission) CommandAlias(co.aikar.commands.annotation.CommandAlias)

Example 8 with User

use of com.easterlyn.user.User in project Easterlyn by Easterlyn.

the class BottleExperience method onPlayerItemConsume.

@EventHandler(ignoreCancelled = true)
public void onPlayerItemConsume(PlayerItemConsumeEvent event) {
    RegisteredServiceProvider<EasterlynCore> easterlynProvider = Bukkit.getServer().getServicesManager().getRegistration(EasterlynCore.class);
    if (easterlynProvider == null) {
        return;
    }
    User user = easterlynProvider.getProvider().getUserManager().getUser(event.getPlayer().getUniqueId());
    user.getTemporaryStorage().put(keyBottleCreate, System.currentTimeMillis() + 2000);
}
Also used : User(com.easterlyn.user.User) EasterlynCore(com.easterlyn.EasterlynCore) EventHandler(org.bukkit.event.EventHandler)

Example 9 with User

use of com.easterlyn.user.User in project Easterlyn by Easterlyn.

the class MessageCommand method sendMessage.

@CommandAlias("reply|r")
@Description("{@@chat.commands.reply.description}")
@CommandPermission("easterlyn.command.message")
@Syntax("<message>")
@CommandCompletion("")
public void sendMessage(@Flags(CoreContexts.SELF) BukkitCommandIssuer sender, String message) {
    User target = replies.get(sender.getUniqueId());
    if (target == null) {
        core.getLocaleManager().sendMessage(sender.getIssuer(), "chat.commands.reply.error.no_target");
        return;
    }
    sendMessage(sender, target, message);
}
Also used : User(com.easterlyn.user.User) AutoUser(com.easterlyn.user.AutoUser) Description(co.aikar.commands.annotation.Description) CommandCompletion(co.aikar.commands.annotation.CommandCompletion) Syntax(co.aikar.commands.annotation.Syntax) CommandPermission(co.aikar.commands.annotation.CommandPermission) CommandAlias(co.aikar.commands.annotation.CommandAlias)

Example 10 with User

use of com.easterlyn.user.User 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);
}
Also used : User(com.easterlyn.user.User) AutoUser(com.easterlyn.user.AutoUser) HashMap(java.util.HashMap) UserChatEvent(com.easterlyn.chat.event.UserChatEvent) AutoUser(com.easterlyn.user.AutoUser) Channel(com.easterlyn.chat.channel.Channel) ArrayList(java.util.ArrayList) UUID(java.util.UUID) Description(co.aikar.commands.annotation.Description) CommandCompletion(co.aikar.commands.annotation.CommandCompletion) Syntax(co.aikar.commands.annotation.Syntax) CommandPermission(co.aikar.commands.annotation.CommandPermission) CommandAlias(co.aikar.commands.annotation.CommandAlias)

Aggregations

User (com.easterlyn.user.User)22 EasterlynCore (com.easterlyn.EasterlynCore)12 Player (org.bukkit.entity.Player)12 EventHandler (org.bukkit.event.EventHandler)11 Channel (com.easterlyn.chat.channel.Channel)7 AutoUser (com.easterlyn.user.AutoUser)7 TextComponent (net.md_5.bungee.api.chat.TextComponent)6 StringUtil (com.easterlyn.util.StringUtil)5 List (java.util.List)5 BaseComponent (net.md_5.bungee.api.chat.BaseComponent)5 Nullable (org.jetbrains.annotations.Nullable)5 EasterlynChat (com.easterlyn.EasterlynChat)4 UserChatEvent (com.easterlyn.chat.event.UserChatEvent)4 Collection (java.util.Collection)4 Collections (java.util.Collections)4 Date (java.util.Date)4 UUID (java.util.UUID)4 Collectors (java.util.stream.Collectors)4 NotNull (org.jetbrains.annotations.NotNull)4 CommandAlias (co.aikar.commands.annotation.CommandAlias)3