Search in sources :

Example 1 with HasPlayer

use of me.lexikiq.HasPlayer in project Nexus by ProjectEdenGG.

the class AbstractTaskMenu method scheduleInvClose.

// todo: use for more tasks
public void scheduleInvClose(HasPlayer _player) {
    Player player = _player.getPlayer();
    Minigamer minigamer = PlayerManager.get(player);
    // don't schedule if match just ended
    if (!minigamer.isPlaying(Sabotage.class))
        return;
    Match.MatchTasks tasks = minigamer.getMatch().getTasks();
    if (closeInvTasks.containsKey(player.getUniqueId()))
        tasks.cancel(closeInvTasks.remove(player.getUniqueId()));
    closeInvTasks.put(player.getUniqueId(), tasks.wait(20, () -> {
        player.sendMessage(Sabotage.COMPLETED_TASK_TEXT);
        player.closeInventory();
    }));
}
Also used : HasPlayer(me.lexikiq.HasPlayer) Player(org.bukkit.entity.Player) Minigamer(gg.projecteden.nexus.features.minigames.models.Minigamer) Sabotage(gg.projecteden.nexus.features.minigames.mechanics.Sabotage) Match(gg.projecteden.nexus.features.minigames.models.Match)

Example 2 with HasPlayer

use of me.lexikiq.HasPlayer in project Nexus by ProjectEdenGG.

the class WorldGuardFlagUtils method hasBypass.

/**
 * Tests if a player bypasses world guard flags
 * @param player player
 * @return if the player bypasses world guard flags
 */
public static boolean hasBypass(@NotNull HasPlayer player) {
    Validate.notNull(player, "Player cannot be null");
    Player _player = player.getPlayer();
    return WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(WorldGuardPlugin.inst().wrapPlayer(_player), BukkitAdapter.adapt(_player.getWorld()));
}
Also used : OptionalPlayer(me.lexikiq.OptionalPlayer) Player(org.bukkit.entity.Player) HasPlayer(me.lexikiq.HasPlayer) LocalPlayer(com.sk89q.worldguard.LocalPlayer)

Example 3 with HasPlayer

use of me.lexikiq.HasPlayer in project Nexus by ProjectEdenGG.

the class LocationUtils method lookAt.

/**
 * Sets a player's pitch and yaw to look at the provided location.
 */
public static void lookAt(HasPlayer hasPlayer, Location lookAt) {
    Player player = hasPlayer.getPlayer();
    Vector direction = player.getEyeLocation().toVector().subtract(lookAt.add(0.5, 0.5, 0.5).toVector()).normalize();
    double x = direction.getX();
    double y = direction.getY();
    double z = direction.getZ();
    // Now change the angle
    Location changed = player.getLocation().clone();
    changed.setYaw(180 - toDegree(Math.atan2(x, z)));
    changed.setPitch(90 - toDegree(Math.acos(y)));
    player.teleport(changed);
}
Also used : Player(org.bukkit.entity.Player) HasPlayer(me.lexikiq.HasPlayer) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 4 with HasPlayer

use of me.lexikiq.HasPlayer in project Nexus by ProjectEdenGG.

the class BlockUtils method getBlockStandingOn.

/*
	Doesnt work:

	fences
	gates
	walls
	sea pickles
	pot
	hanging on all vines
	in a cobweb
	on a ladder (and on top)
	end rods
	trapdoors (uses the block underneath)
	carpet (uses the block underneath)
	scaffolding
	lily pads
	composter (inside)
	skulls (on floor & wall)
	in water & lava
	snow layers (all levels, layers=1 & 2, uses the block underneath)
	 */
public static Block getBlockStandingOn(HasPlayer hasPlayer) {
    Player player = hasPlayer.getPlayer();
    Location below = player.getLocation().add(0, -.25, 0);
    Block block = below.getBlock();
    if (block.getType().isSolid())
        return block;
    List<BlockFace> priority = new HashMap<BlockFace, Double>() {

        {
            put(BlockFace.NORTH, below.getZ() - Math.floor(below.getZ()));
            put(BlockFace.EAST, Math.abs(below.getX() - Math.ceil(below.getX())));
            put(BlockFace.SOUTH, Math.abs(below.getZ() - Math.ceil(below.getZ())));
            put(BlockFace.WEST, below.getX() - Math.floor(below.getX()));
        }
    }.entrySet().stream().filter(direction -> direction.getValue() < .3).sorted(Map.Entry.comparingByValue()).map(Map.Entry::getKey).limit(2).collect(Collectors.toList());
    if (priority.size() == 2)
        priority.add(getBlockFaceBetween(priority.get(0), priority.get(1)));
    for (BlockFace blockFace : priority) {
        Block relative = block.getRelative(blockFace);
        if (relative.getType().isSolid())
            return relative;
    }
    return null;
}
Also used : OptionalPlayer(me.lexikiq.OptionalPlayer) Player(org.bukkit.entity.Player) HasPlayer(me.lexikiq.HasPlayer) BlockFace(org.bukkit.block.BlockFace) Block(org.bukkit.block.Block) FallingBlock(org.bukkit.entity.FallingBlock) Location(org.bukkit.Location)

Example 5 with HasPlayer

use of me.lexikiq.HasPlayer in project Nexus by ProjectEdenGG.

the class BearFair21Restrictions method onItemFrameBreak.

@EventHandler(priority = EventPriority.HIGHEST)
public void onItemFrameBreak(EntityDamageByEntityEvent event) {
    if (BearFair21.isNotAtBearFair(event.getEntity()))
        return;
    EntityType breakType = event.getEntityType();
    if (!breakType.equals(EntityType.ITEM_FRAME) && !breakType.equals(EntityType.PAINTING))
        return;
    Entity damager = event.getDamager();
    if (!(damager instanceof Player) && !(damager instanceof Projectile))
        return;
    if (damager instanceof Projectile) {
        Entity shooter = (Entity) ((Projectile) damager).getShooter();
        if (shooter instanceof Player) {
            if (WorldGuardFlagUtils.hasBypass((HasPlayer) shooter))
                return;
        }
    } else {
        if (WorldGuardFlagUtils.hasBypass((HasPlayer) damager))
            return;
    }
    event.setCancelled(true);
}
Also used : EntityType(org.bukkit.entity.EntityType) Entity(org.bukkit.entity.Entity) HasPlayer(me.lexikiq.HasPlayer) Player(org.bukkit.entity.Player) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Aggregations

HasPlayer (me.lexikiq.HasPlayer)7 Player (org.bukkit.entity.Player)7 OptionalPlayer (me.lexikiq.OptionalPlayer)2 Location (org.bukkit.Location)2 Vector (org.bukkit.util.Vector)2 LocalSession (com.sk89q.worldedit.LocalSession)1 BukkitPlayer (com.sk89q.worldedit.bukkit.BukkitPlayer)1 LocalPlayer (com.sk89q.worldguard.LocalPlayer)1 Sabotage (gg.projecteden.nexus.features.minigames.mechanics.Sabotage)1 Match (gg.projecteden.nexus.features.minigames.models.Match)1 Minigamer (gg.projecteden.nexus.features.minigames.models.Minigamer)1 Block (org.bukkit.block.Block)1 BlockFace (org.bukkit.block.BlockFace)1 Entity (org.bukkit.entity.Entity)1 EntityType (org.bukkit.entity.EntityType)1 FallingBlock (org.bukkit.entity.FallingBlock)1 Projectile (org.bukkit.entity.Projectile)1 EventHandler (org.bukkit.event.EventHandler)1