Search in sources :

Example 16 with EasterlynCore

use of com.easterlyn.EasterlynCore 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 17 with EasterlynCore

use of com.easterlyn.EasterlynCore 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

EasterlynCore (com.easterlyn.EasterlynCore)17 User (com.easterlyn.user.User)11 Player (org.bukkit.entity.Player)11 EventHandler (org.bukkit.event.EventHandler)9 UserChatEvent (com.easterlyn.chat.event.UserChatEvent)5 AutoUser (com.easterlyn.user.AutoUser)4 NotNull (org.jetbrains.annotations.NotNull)4 Nullable (org.jetbrains.annotations.Nullable)4 EasterlynChat (com.easterlyn.EasterlynChat)3 Channel (com.easterlyn.chat.channel.Channel)3 StringUtil (com.easterlyn.util.StringUtil)3 Collections (java.util.Collections)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 Collectors (java.util.stream.Collectors)3 UserCreationEvent (com.easterlyn.event.UserCreationEvent)2 BlockUpdateManager (com.easterlyn.util.BlockUpdateManager)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2