org.bukkit.event.entity.EntityToggleGlideEvent Java Examples

The following examples show how to use org.bukkit.event.entity.EntityToggleGlideEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CustomElytraPlayerToggleGlide.java    From AdditionsAPI with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onCustomElytraPlayerGlideLowest(CustomElytraPlayerToggleGlideEvent customEvent) {
	if (customEvent.isCancelled())
		return;

	CustomItem cItem = customEvent.getCustomItem();

	if (!(cItem.getPermissions() instanceof ElytraPermissions))
		return;
	ElytraPermissions perm = (ElytraPermissions) cItem.getPermissions();

	EntityToggleGlideEvent event = customEvent.getEntityToggleGlideEvent();

	if (event.getEntity().getType().equals(EntityType.PLAYER)
			&& !PermissionUtils.allowedAction((Player) event.getEntity(), perm.getType(), perm.getFlight()))
		event.setCancelled(true);
}
 
Example #2
Source File: EntityListenerOnePointNine.java    From WorldGuardExtraFlagsPlugin with MIT License 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onEntityToggleGlideEvent(EntityToggleGlideEvent event)
{
	Entity entity = event.getEntity();
	if (entity instanceof Player)
	{
		Player player = (Player)entity;
		
		ApplicableRegionSet regions = this.plugin.getWorldGuardCommunicator().getRegionContainer().createQuery().getApplicableRegions(player.getLocation());

		ForcedState state = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.GLIDE);
		if (state != ForcedState.ALLOW)
		{
			event.setCancelled(true);
			
			player.setGliding(state == ForcedState.FORCE);
			
			if (state == ForcedState.DENY)
			{
				player.teleport(player.getLocation());
			}
		}
	}
}
 
Example #3
Source File: ListenerElytra.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority= EventPriority.HIGH, ignoreCancelled=true)
public void onToggleGlide(EntityToggleGlideEvent e) {
    if(!e.isGliding()) return;

    FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml");
    if(!config.getBoolean("items.prevent-elytra")) return;

    Entity entity = e.getEntity();
    if(!(entity instanceof Player)) return;

    Player player = (Player) entity;
    ICombatManager combatManager = this.plugin.getCombatManager();
    if(!combatManager.isInCombat(player)) return;

    e.setCancelled(true);
    player.setGliding(false);

    String message = this.plugin.getLanguageMessageColoredWithPrefix("cheat-prevention.elytra.no-gliding");
    this.plugin.sendMessage(player, message);
}
 
Example #4
Source File: EntityToggleGlide.java    From AdditionsAPI with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onEntityToggleGlide(EntityToggleGlideEvent event) {
	if (event.getEntityType() != EntityType.PLAYER)
		return;
	PlayerInventory inv = ((Player) event.getEntity()).getInventory();
	if (inv.getChestplate() == null)
		return;
	ItemStack elytra = inv.getChestplate();
	if (!AdditionsAPI.isCustomItem(elytra)
			|| new CustomItemStack(elytra).getCustomItem().getItemType() != ItemType.ELYTRA)
		return;
	Bukkit.getServer().getPluginManager()
			.callEvent(new CustomElytraPlayerToggleGlideEvent(event, new CustomItemStack(elytra)));
}
 
Example #5
Source File: CustomElytraPlayerToggleGlideEvent.java    From AdditionsAPI with MIT License 4 votes vote down vote up
public CustomElytraPlayerToggleGlideEvent(EntityToggleGlideEvent event, CustomItemStack cStack) {
	super(cStack);
	this.entityToggleGlideEvent = event;
}
 
Example #6
Source File: CustomElytraPlayerToggleGlideEvent.java    From AdditionsAPI with MIT License 4 votes vote down vote up
public EntityToggleGlideEvent getEntityToggleGlideEvent() {
	return entityToggleGlideEvent;
}
 
Example #7
Source File: EntityToggleGlideListener.java    From ViaVersion with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void entityToggleGlide(EntityToggleGlideEvent event) {
    if (!(event.getEntity() instanceof Player)) return;

    Player player = (Player) event.getEntity();
    if (!isOnPipe(player)) return;

    // Cancelling can only be done by updating the player's metadata
    if (event.isGliding() && event.isCancelled()) {
        PacketWrapper packet = new PacketWrapper(0x44, null, getUserConnection(player));
        try {
            packet.write(Type.VAR_INT, player.getEntityId());

            byte bitmask = 0;
            // Collect other metadata for the mitmask
            if (player.getFireTicks() > 0) {
                bitmask |= 0x01;
            }
            if (player.isSneaking()) {
                bitmask |= 0x02;
            }
            // 0x04 is unused
            if (player.isSprinting()) {
                bitmask |= 0x08;
            }
            if (swimmingMethodExists && player.isSwimming()) {
                bitmask |= 0x10;
            }
            if (player.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
                bitmask |= 0x20;
            }
            if (player.isGlowing()) {
                bitmask |= 0x40;
            }

            // leave 0x80 as 0 to stop gliding
            packet.write(Types1_14.METADATA_LIST, Arrays.asList(new Metadata(0, MetaType1_14.Byte, bitmask)));
            packet.send(Protocol1_15To1_14_4.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
Example #8
Source File: DistanceTravelledToggleGlideListener.java    From Statz with GNU General Public License v3.0 3 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onMove(final EntityToggleGlideEvent event) {

	if (!(event.getEntity() instanceof Player)) return;
	
	// Get player
	final Player player = (Player) event.getEntity();

	StatzUtil.isGliding.put(player.getUniqueId(), event.isGliding());
}