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