Search in sources :

Example 21 with User

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

the class BottleExperience method onPlayerInteract.

@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        if (BlockUtil.hasRightClickFunction(event)) {
            return;
        }
    } else if (event.getAction() != Action.RIGHT_CLICK_AIR) {
        return;
    }
    if (event.getPlayer().isSneaking()) {
        return;
    }
    ItemStack held = ItemUtil.getHeldItem(event);
    if (held.getType() != Material.GLASS_BOTTLE) {
        return;
    }
    RegisteredServiceProvider<EasterlynCore> easterlynProvider = Bukkit.getServer().getServicesManager().getRegistration(EasterlynCore.class);
    if (easterlynProvider == null) {
        return;
    }
    Player player = event.getPlayer();
    User user = easterlynProvider.getProvider().getUserManager().getUser(player.getUniqueId());
    Object cooldown = user.getTemporaryStorage().get(keyBottleCreate);
    if (cooldown instanceof Long && (Long) cooldown >= System.currentTimeMillis()) {
        return;
    }
    int exp = ExperienceUtil.getExp(player);
    if (exp >= 11) {
        ExperienceUtil.changeExp(player, -11);
        ItemUtil.setHeldItem(player.getInventory(), event.getHand() == EquipmentSlot.HAND, ItemUtil.decrement(held, 1));
        player.getWorld().dropItem(player.getLocation(), new ItemStack(Material.EXPERIENCE_BOTTLE, 1)).setPickupDelay(0);
        user.getTemporaryStorage().put(keyBottleThrow, System.currentTimeMillis() + 2000);
        event.setUseItemInHand(Event.Result.DENY);
    }
}
Also used : Player(org.bukkit.entity.Player) User(com.easterlyn.user.User) EasterlynCore(com.easterlyn.EasterlynCore) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 22 with User

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

the class BottleExperience method onProjectileLaunch.

@EventHandler(ignoreCancelled = true)
public void onProjectileLaunch(ProjectileLaunchEvent event) {
    if (!(event.getEntity() instanceof ThrownExpBottle) || !(event.getEntity().getShooter() instanceof Player)) {
        return;
    }
    RegisteredServiceProvider<EasterlynCore> easterlynProvider = Bukkit.getServer().getServicesManager().getRegistration(EasterlynCore.class);
    if (easterlynProvider == null) {
        return;
    }
    User user = easterlynProvider.getProvider().getUserManager().getUser(((Player) event.getEntity().getShooter()).getUniqueId());
    Object cooldown = user.getTemporaryStorage().get(keyBottleThrow);
    if (cooldown instanceof Long && (Long) cooldown >= System.currentTimeMillis()) {
        event.setCancelled(true);
    }
}
Also used : Player(org.bukkit.entity.Player) User(com.easterlyn.user.User) EasterlynCore(com.easterlyn.EasterlynCore) ThrownExpBottle(org.bukkit.entity.ThrownExpBottle) EventHandler(org.bukkit.event.EventHandler)

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